R-Type
Networked shoot'em up built on Aegis2D
Loading...
Searching...
No Matches
server_options.hpp
Go to the documentation of this file.
1
3#pragma once
4#include <cstddef>
5#include <cstdint>
6#include <filesystem>
7#include <optional>
8#include <span>
9#include <string>
10#include <string_view>
11#include <variant>
12
13namespace rtype {
14
16inline constexpr std::uint16_t default_tcp_port = 4242;
18inline constexpr std::uint16_t default_udp_port = 4243;
21inline constexpr std::uint32_t default_packet_rate = 300;
23inline constexpr std::uint32_t default_max_rooms = 4;
24
26inline constexpr std::string_view default_scores_file = "scores.json";
27
29inline constexpr std::string_view default_bans_file = "bans.json";
30
32inline constexpr std::string_view server_usage =
33 "usage: r-type_server [--tcp-port <port>] [--udp-port <port>] [--waves <file.json>]\n"
34 " [--max-packet-rate <datagrams per second>] [--compress <bytes>]\n"
35 " [--max-rooms <count>] [--scores <file.json>] [--bans <file.json>]\n"
36 " [--trace <file.json>] [--help] [--version]\n";
37
39enum class ServerCommand : std::uint8_t {
41 Run,
43 Help,
45 Version,
46};
47
53 std::uint16_t tcp_port = default_tcp_port;
55 std::uint16_t udp_port = default_udp_port;
57 std::optional<std::filesystem::path> waves;
62 std::optional<std::size_t> compress_from;
66 std::filesystem::path scores{default_scores_file};
68 std::filesystem::path bans{default_bans_file};
71 std::optional<std::filesystem::path> trace;
72};
73
80[[nodiscard]] std::variant<ServerOptions, std::string>
81parse_server_options(std::span<const std::string_view> args);
82
83} // namespace rtype
R-Type game code, built on the Aegis2D engine.
Definition enemy_scripts.hpp:16
constexpr std::uint32_t default_packet_rate
Datagrams accepted per second from one address when --max-packet-rate is not given; see RateLimits.
Definition server_options.hpp:21
ServerCommand
What the server was asked to do.
Definition server_options.hpp:39
@ Version
Print the version and exit.
@ Help
Print the usage and exit.
@ Run
Start the game and listen on the ports.
constexpr std::string_view default_bans_file
File of the banned addresses, in the folder the server runs from.
Definition server_options.hpp:29
constexpr std::uint16_t default_udp_port
UDP port the server listens on when --udp-port is not given.
Definition server_options.hpp:18
constexpr std::string_view server_usage
Usage line printed by --help and after a command line error.
Definition server_options.hpp:32
constexpr std::uint32_t default_max_rooms
Rooms played at once when --max-rooms is not given; see GameServer.
Definition server_options.hpp:23
constexpr std::uint16_t default_tcp_port
TCP port the server listens on when --tcp-port is not given.
Definition server_options.hpp:16
constexpr std::string_view default_scores_file
File of the best scores, in the folder the server runs from.
Definition server_options.hpp:26
std::variant< ServerOptions, std::string > parse_server_options(std::span< const std::string_view > args)
Reads the command line of r-type_server.
Settings of a server run, read from the command line.
Definition server_options.hpp:49
std::optional< std::filesystem::path > trace
File the timings of every tick are written to when the server stops, in the Chrome trace format (Perf...
Definition server_options.hpp:71
std::uint16_t tcp_port
TCP port of the logins; 0 lets the system pick a free one.
Definition server_options.hpp:53
std::uint32_t max_rooms
Rooms played at once, 1 to 64, tuning::max_players in each.
Definition server_options.hpp:64
std::filesystem::path scores
File of the best scores (Scoreboard).
Definition server_options.hpp:66
ServerCommand command
What to do; the other fields only matter for ServerCommand::Run.
Definition server_options.hpp:51
std::filesystem::path bans
File of the banned addresses (BanList).
Definition server_options.hpp:68
std::uint16_t udp_port
UDP port of the game; 0 lets the system pick a free one.
Definition server_options.hpp:55
std::uint32_t packet_rate
Datagrams accepted per second from one address, 1 to 100000.
Definition server_options.hpp:59
std::optional< std::size_t > compress_from
Size from which snapshots and events are sent compressed with LZ4 when that makes them smaller,...
Definition server_options.hpp:62
std::optional< std::filesystem::path > waves
Waves file to play, or std::nullopt for default_waves_file().
Definition server_options.hpp:57