2023-09-24 11:07:03 -04:00
|
|
|
#ifndef SERVER_H__
|
|
|
|
#define SERVER_H__
|
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>
|
|
|
|
#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
|
|
|
|
|
|
|
class Server {
|
|
|
|
public:
|
2023-09-24 11:07:03 -04:00
|
|
|
Server(LogDest log = LOG_DEST::CONSOLE);
|
2023-09-24 08:45:40 -04:00
|
|
|
~Server();
|
|
|
|
|
|
|
|
int Init();
|
|
|
|
int Ready();
|
|
|
|
void Run();
|
|
|
|
|
|
|
|
private:
|
|
|
|
#ifdef _WIN32
|
|
|
|
WSADATA m_wsaData;
|
|
|
|
#endif
|
|
|
|
SOCKET m_sock_udp = 0,
|
|
|
|
m_sock_tcp = 0;
|
|
|
|
LogDest m_log;
|
|
|
|
std::ofstream m_logfile;
|
2023-09-24 11:07:03 -04:00
|
|
|
|
2023-09-28 09:15:39 -04:00
|
|
|
std::map<uint64_t, Connection*> m_players;
|
|
|
|
std::map <Timestamp, netprot::Chat> m_chatlog;
|
|
|
|
std::vector<uint64_t> m_ids;
|
|
|
|
netprot::GameInfo m_game;
|
|
|
|
|
2023-09-24 08:45:40 -04:00
|
|
|
World* m_world = nullptr;
|
|
|
|
|
|
|
|
std::string Timestamp();
|
|
|
|
void Log(std::string str, bool is_error, bool is_fatal);
|
2023-09-28 09:15:39 -04:00
|
|
|
void buildIdList(size_t size);
|
|
|
|
|
|
|
|
uint64_t getUniqueId();
|
|
|
|
template <class T> void sendPack(SOCKET sock, T* pack, char** buf, uint32_t* buflen);
|
|
|
|
|
2023-09-24 08:45:40 -04:00
|
|
|
};
|
2023-09-28 09:15:39 -04:00
|
|
|
|
|
|
|
template <class T>
|
|
|
|
void Server::sendPack(SOCKET sock, T* pack, char** buf, uint32_t* buflen) {
|
|
|
|
netprot::Serialize(pack, buf, buflen);
|
|
|
|
send(sock, *buf, *buflen, 0);
|
|
|
|
*buflen = BUFFER_LENGTH;
|
|
|
|
}
|
|
|
|
|
2023-09-24 08:45:40 -04:00
|
|
|
#endif
|