home *** CD-ROM | disk | FTP | other *** search
- #ifndef __Server_h__
- #define __Server_h__
-
- //#include "SDL/SDL_net.h"
- #include "Client.h"
- #include "PacketHandler.h"
-
- //#define SERVER_MAX_CLIENTS 32
-
- class Server{
- public:
- IPaddress ipAddress;
- UDPsocket socket;
-
- serverinfoPacket_t si;
- Client* clients[16/*NETWORK_MAX_CLIENTS*/];
- Client* localClient;
-
- unsigned long lastPingMillis;
- unsigned long lastPlayerinfoMillis;
- unsigned long lastGamestateMillis;
-
- Server();
- ~Server();
-
- // void displayServerInfo();
-
- bool openPort();
- bool closePort();
-
- bool disconnectAllClients(const char* reason);
- bool disconnectClient(Client* client, const char* reason);
-
- int addClient(Client* client);
- void removeClient(Client* client);
- void checkClientName(char* name, char* newName);
- bool hasFreeSlots();
- Client* getClientByPacket(UDPpacket* packet);
- Client* getClientByName(const char* name);
- void resetClients();
-
- bool sendToClient(Client* client, UDPpacket* packet);
- bool sendToAllClients(UDPpacket* packet);
- bool sendToAllRemoteClients(UDPpacket* packet);
- bool sendToAllOtherRemoteClients(Client* c, UDPpacket* packet);
-
- void sendGamestate();
- void sendPlayerinfo();
- void sendPing();
- void sendClientHurt(char hurtClientId, char hurterClientId, unsigned char amount);
- void sendClientKill(char killedClientId, char killerClientId, char weapon);
- void sendChatMessage(const char* message);
- void sendArenaChange();
-
- void sendPackets();
- void receivePackets();
- void emptyPacketQueue();
-
- void handlePacket(UDPpacket* packet);
- void handlePing(UDPpacket* packet);
- void handleServerinfoRequest(UDPpacket* packet);
- // void handlePlayerinfoRequest(UDPpacket* packet);
- void handleConnectionRequest(UDPpacket* packet);
- void handleDisconnect(UDPpacket* packet);
-
- void handleChatMessage(UDPpacket* packet);
- void handleVoiceMessage(UDPpacket* packet);
- void handleClientstate(UDPpacket* packet);
- void handleClientSpawn(UDPpacket* packet);
- void handleClientKill(UDPpacket* packet);
- void handleShotSpawn(UDPpacket* packet);
- };
-
-
- #endif /* __Server_h__ */
-