Major cleanup of client code, extracting various functionality

This commit is contained in:
mdiluzio 2015-01-04 13:09:37 +00:00
parent 3ed25cd37f
commit 1c97177956
5 changed files with 161 additions and 100 deletions

View file

@ -18,6 +18,9 @@
#define TTRTS_HANDSHAKE_FORMAT "player %u name %s"
//======================================================================================================================
// Structs for net management
// Struct for net client info
struct ClientInfo
{
@ -26,6 +29,10 @@ struct ClientInfo
player_t player;
};
//======================================================================================================================
// Server side function
// Get the address of a local server
sockaddr_in GetLocalServerAddress();
@ -52,9 +59,24 @@ void TryBindSocket(int sockfd, const sockaddr_in &serv_addr);
// Perform the server side handshake with a client
void PerformServerHandshake(const ClientInfo &client, const std::string &game);
//======================================================================================================================
// Client side functions
// Connect to the host, returns new socket for communication
int ConnectToHostServer(const std::string &hostname, sockaddr_in &serv_addr);
// Perform the client side handshake with the server
void PerformClientHandshake(int sockfd, unsigned int &player, std::string &gameNameString);
// Wait for gamestate message from host
std::string WaitForGamestateMessage(int sockfd);
// Send orders to the server
int SendOrdersToServer(int sockfd, const std::string &orders);
//======================================================================================================================
// Error functions
// For local fatal errors
inline void fatal_error(const char *msg)
{
@ -69,4 +91,8 @@ inline void fatal_perror(const char *msg)
exit(1);
}
//======================================================================================================================
// Other functions
int OutputGameEnd( CTTRTSGame& game );
#endif