Argentum Online - Servidor
server_exceptions.h
1 #ifndef SERVER_EXCEPTIONS_H
2 #define SERVER_EXCEPTIONS_H
3 
4 #include <cstring>
5 #include <stdexcept>
6 #include <string>
7 
8 class ClientDisconnectedException : public std::exception {
9  private:
10  char err_msg[100];
11 
12  public:
13  ClientDisconnectedException(ClientId client_id) {
14  std::string str =
15  "The client: " + std::to_string(client_id) + " has disconnected.";
16  std::strncpy(err_msg, str.c_str(), 100);
17  err_msg[99] = '\0';
18  }
19  ClientDisconnectedException(std::string name) {
20  std::string str = "The client: " + name + " has disconnected.";
21  std::strncpy(err_msg, str.c_str(), 100);
22  err_msg[99] = '\0';
23  }
25 
26  const char* what() const noexcept override {
27  return err_msg;
28  }
29 };
30 
31 class DuplicatedPlayerException : public std::exception {
32  private:
33  char err_msg[100];
34 
35  public:
36  DuplicatedPlayerException(std::string name) {
37  std::string str = "The player: " + name + " is already connected!";
38  std::strncpy(err_msg, str.c_str(), 100);
39  err_msg[99] = '\0';
40  }
42 
43  const char* what() const noexcept override {
44  return err_msg;
45  }
46 };
47 
48 #endif // SERVER_EXCEPTIONS_H
DuplicatedPlayerException
Definition: server_exceptions.h:31
ClientDisconnectedException
Definition: server_exceptions.h:8