2022-01-02 19:28:16 -05:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
2022-01-08 18:59:40 -05:00
|
|
|
#include "lib_lua_common.h"
|
|
|
|
#include "UDPbase.h"
|
2022-01-02 19:28:16 -05:00
|
|
|
|
2022-01-08 18:59:40 -05:00
|
|
|
class Server : public UDPbase
|
2022-01-02 19:28:16 -05:00
|
|
|
{
|
2022-01-03 14:48:50 -05:00
|
|
|
SDL_mutex* mProcessPacketMutex;
|
2022-01-08 18:59:40 -05:00
|
|
|
SDL_TimerID mFetchPacketsCallbackTimerID;
|
|
|
|
|
|
|
|
std::vector<TCPsocket> TCPsocks;
|
|
|
|
std::vector<UDPsocket> UDPsocks;
|
|
|
|
UDPpacket** UDPPacketV;
|
|
|
|
SDLNet_SocketSet SocketSet;
|
|
|
|
lua_State *mLuaState;
|
|
|
|
|
2022-01-02 19:28:16 -05:00
|
|
|
public:
|
|
|
|
Server (const char* host, const Uint16 port);
|
2022-01-08 18:59:40 -05:00
|
|
|
~Server (void);
|
|
|
|
|
|
|
|
static Uint32 FetchPacketsCallback (Uint32 interval, void* param);
|
|
|
|
void ProcessPacketHelper (UDPpacket* packet);
|
|
|
|
void RunLua (const std::string& buf);
|
|
|
|
int AllocateApproximateBufferSpace (const int nclients);
|
2022-01-03 14:48:50 -05:00
|
|
|
int Start (void);
|
|
|
|
int Stop (void);
|
|
|
|
int Lock (void)
|
|
|
|
{
|
|
|
|
return SDL_LockMutex (mProcessPacketMutex);
|
|
|
|
}
|
2022-01-08 18:59:40 -05:00
|
|
|
int Unlock (void)
|
2022-01-02 19:28:16 -05:00
|
|
|
{
|
2022-01-03 14:48:50 -05:00
|
|
|
return SDL_UnlockMutex (mProcessPacketMutex);
|
2022-01-02 19:28:16 -05:00
|
|
|
}
|
2022-01-08 18:59:40 -05:00
|
|
|
lua_State* getLuaState(void) const { return mLuaState; }
|
|
|
|
const TCPsocket* getTCPsock (size_t idx) const { return &TCPsocks.at (idx); }
|
|
|
|
const UDPsocket* getUDPsock (size_t idx) const { return &UDPsocks.at (idx); }
|
|
|
|
UDPpacket* getUDPPacketV (size_t idx) const { return UDPPacketV[idx]; }
|
|
|
|
SDLNet_SocketSet getSocketSet (void) const { return SocketSet; }
|
2022-01-02 19:28:16 -05:00
|
|
|
};
|