Zappy Server
C++ game server: world, rules, scheduler, network
Loading...
Searching...
No Matches
Args.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <ostream>
4#include <string>
5#include <vector>
6
18 int port;
19 int width;
20 int height;
21 std::vector<std::string> teamNames;
23 int freq;
24 unsigned int seed;
25
26 friend std::ostream& operator<<(std::ostream& os, const ServerConfig& c)
27 {
28 os << "Server configuration:\n"
29 << " Port : " << c.port << "\n"
30 << " Map : " << c.width << "x" << c.height << "\n"
31 << " Clients : " << c.clientsNb << " per team\n"
32 << " Freq : " << c.freq << " Hz\n"
33 << " Seed : " << c.seed << "\n"
34 << " Teams : ";
35 for (size_t i = 0; i < c.teamNames.size(); ++i) {
36 if (i) os << ", ";
37 os << c.teamNames[i];
38 }
39 return os;
40 }
41};
42
43class Args {
44 public:
45 Args(int argc, char** argv);
46
51 bool isValid() const;
52
57 bool isHelpRequested() const;
58
63 int exitCode() const;
64
69 ServerConfig getConfig() const;
70
71 private:
73
74 static constexpr int SUCCESS = 0;
75 static constexpr int ERROR = 84;
76
77 ServerConfig config = {-1, -1, -1, {}, 10, 100, 0};
79};
Definition Args.hpp:43
int exitCode() const
Gets the exit code for the application.
Definition Args.cpp:93
static constexpr int SUCCESS
Definition Args.hpp:74
ServerConfig config
Definition Args.hpp:77
ParseResult result
Definition Args.hpp:78
ServerConfig getConfig() const
Gets the configuration for the server application.
Definition Args.cpp:91
static constexpr int ERROR
Definition Args.hpp:75
bool isHelpRequested() const
Checks if the help flag was provided in the arguments.
Definition Args.cpp:90
ParseResult
Definition Args.hpp:72
bool isValid() const
Checks if the parsed arguments are valid and if the application should run.
Definition Args.cpp:89
Represents the configuration for the server application, described by:
Definition Args.hpp:17
int height
Definition Args.hpp:20
int clientsNb
Definition Args.hpp:22
std::vector< std::string > teamNames
Definition Args.hpp:21
friend std::ostream & operator<<(std::ostream &os, const ServerConfig &c)
Definition Args.hpp:26
int width
Definition Args.hpp:19
unsigned int seed
Definition Args.hpp:24