handmade/include/Server.h

53 lines
1.3 KiB
C
Raw Normal View History

#pragma once
#include <string>
#include <vector>
#include "lib_lua_common.h"
#include "UDPbase.h"
#define DEFAULT_SOCKET_TIMEOUT 10
class Server : public UDPbase
{
SDL_mutex* mProcessPacketMutex;
SDL_TimerID mFetchPacketsCallbackTimerID;
std::vector<TCPsocket> TCPsocks;
std::vector<UDPsocket> UDPsocks;
SDLNet_SocketSet SocketSet;
UDPpacket** packetV;
lua_State *mLuaState;
public:
Server (const char* host, const Uint16 port);
~Server (void);
/*
* error: invalid use of non-static member function Uint32 Server::FetchPacketsCallback(Uint32, void*)
* Don't understand this.
* static keyword fixes it.
*/
static Uint32 FetchPacketsCallback (Uint32 interval, void* param);
void ProcessPacketHelper (UDPpacket* packet);
void RunLua (const std::string& buf);
int AllocateApproximateResources (const int nclients);
int Start (void);
int Stop (void);
void CloseAllSockets (void);
int Lock (void)
{
return SDL_LockMutex (mProcessPacketMutex);
}
int Unlock (void)
{
return SDL_UnlockMutex (mProcessPacketMutex);
}
lua_State* getLuaState(void) { return mLuaState; }
TCPsocket getTCPsock (size_t idx) { return TCPsocks.at (idx); }
UDPsocket getUDPsock (size_t idx) { return UDPsocks.at (idx); }
UDPpacket** getPacketV (void) { return packetV; }
SDLNet_SocketSet getSocketSet (void) { return SocketSet; }
};