SQCSimulator2023/SQCSim-srv/server.h

65 lines
1.2 KiB
C
Raw Normal View History

2023-09-24 11:07:03 -04:00
#ifndef SERVER_H__
#define SERVER_H__
2023-09-24 08:45:40 -04:00
2023-12-07 13:05:52 -05:00
#include <cstdlib>
2023-09-24 08:45:40 -04:00
#include <fstream>
#include <vector>
2023-09-28 09:15:39 -04:00
#include <set>
2023-09-24 08:45:40 -04:00
#include <string>
2023-11-06 13:56:12 -05:00
#include <unordered_map>
2023-09-24 08:45:40 -04:00
#include "../SQCSim-common/world.h"
2023-09-27 11:24:41 -04:00
#include "../SQCSim-common/netprotocol.h"
2023-09-24 08:45:40 -04:00
#include "define.h"
2023-09-24 11:07:03 -04:00
#include "connection.h"
2023-09-24 08:45:40 -04:00
2023-10-25 12:16:14 -04:00
using namespace netprot;
2023-09-24 08:45:40 -04:00
class Server {
public:
2023-10-27 09:51:40 -04:00
enum LOG_DEST: unsigned char { CONSOLE, LOGFILE, LOG_LAST };
Server(LOG_DEST log = LOG_DEST::CONSOLE);
2023-09-24 08:45:40 -04:00
~Server();
int Init();
int Ready();
void Run();
2023-12-09 12:02:04 -05:00
void Cleanup();
void DeInit();
bool NewGameRequested() const;
2023-09-24 08:45:40 -04:00
private:
2023-10-27 09:51:40 -04:00
2023-09-24 08:45:40 -04:00
#ifdef _WIN32
WSADATA m_wsaData;
#endif
SOCKET m_sock_udp = 0,
m_sock_tcp = 0;
2023-10-27 09:51:40 -04:00
LOG_DEST m_log;
2023-09-24 08:45:40 -04:00
std::ofstream m_logfile;
2023-09-24 11:07:03 -04:00
2023-10-27 09:51:40 -04:00
Buffer m_buf;
2023-12-05 06:25:48 -05:00
std::unordered_map<uint64_t, Player*> m_players;
std::unordered_map<uint64_t, Connection*> m_conns;
2023-11-06 13:56:12 -05:00
std::unordered_map<Timestamp, Chat> m_chatlog;
2023-12-18 13:29:38 -05:00
std::unordered_map<uint64_t, Booster*> m_boosters;
2023-09-28 09:15:39 -04:00
std::vector<uint64_t> m_ids;
2023-10-27 09:51:40 -04:00
GameInfo m_game;
2023-09-28 09:15:39 -04:00
2023-11-06 17:59:57 -05:00
World* m_world = nullptr;
2023-12-09 12:02:04 -05:00
bool m_exit = true;
2023-09-24 08:45:40 -04:00
2023-12-18 13:29:38 -05:00
int64_t m_boostcount = -1;
std::string LogTimestamp();
2023-09-24 08:45:40 -04:00
void Log(std::string str, bool is_error, bool is_fatal);
2023-09-28 09:15:39 -04:00
void buildIdList(size_t size);
2023-10-27 09:51:40 -04:00
uint64_t getUniqueId();
2023-12-06 11:16:39 -05:00
std::string getDeathMessage(std::string username, std::string killer) const;
2023-09-28 09:15:39 -04:00
2023-09-24 08:45:40 -04:00
};
2023-09-28 09:15:39 -04:00
2023-09-24 08:45:40 -04:00
#endif