55 lines
1.1 KiB
C++
55 lines
1.1 KiB
C++
#ifndef SERVER_H__
|
|
#define SERVER_H__
|
|
|
|
#include <fstream>
|
|
#include <vector>
|
|
#include <set>
|
|
#include <string>
|
|
#include "../SQCSim-common/world.h"
|
|
#include "../SQCSim-common/netprotocol.h"
|
|
#include "define.h"
|
|
#include "connection.h"
|
|
|
|
class Server {
|
|
public:
|
|
Server(LogDest log = LOG_DEST::CONSOLE);
|
|
~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;
|
|
|
|
std::map<uint64_t, Connection*> m_players;
|
|
std::map <Timestamp, netprot::Chat> m_chatlog;
|
|
std::vector<uint64_t> m_ids;
|
|
netprot::GameInfo m_game;
|
|
|
|
World* m_world = nullptr;
|
|
|
|
std::string Timestamp();
|
|
void Log(std::string str, bool is_error, bool is_fatal);
|
|
void buildIdList(size_t size);
|
|
|
|
uint64_t getUniqueId();
|
|
template <class T> void sendPack(SOCKET sock, T* pack, char** buf, uint32_t* buflen);
|
|
|
|
};
|
|
|
|
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;
|
|
}
|
|
|
|
#endif
|