Add game name to handshake and formalise handshake format

This commit is contained in:
mdiluzio 2015-01-03 20:04:31 +00:00
parent 61c012370d
commit 1785ce2fc0
5 changed files with 25 additions and 20 deletions

View file

@ -82,22 +82,22 @@ int runClient(int argc, char* argv[])
error("ERROR recieving handshake from server");
std::string handshake(buffer);
std::cout<<"Handshake:"<<handshake<<std::endl;
if ( write(sockfd,handshake.c_str(),handshake.length()) < 0)
if ( write( sockfd, handshake.c_str(), handshake.length()+1 ) < 0 )
error("ERROR sending handshake to server");
size_t pos;
if( (pos = handshake.find("player")) != std::string::npos )
{
std::string player = handshake.substr(pos, handshake.length());
myPlayer = (player_t)atoi(player.c_str());
}
else
{
unsigned int player;
char gameName[64];
if ( sscanf(handshake.c_str(),TTRTS_HANDSHAKE_FORMAT,&player,gameName) < 2 )
error("Handshake failed");
}
std::cout<<"I am player "<< std::to_string((int)myPlayer) << std::endl;
myPlayer = (player_t)player;
std::cout<<"I am player "<<std::to_string((int)myPlayer)<<std::endl;
std::cout<<"Game is "<<gameName<<std::endl;
// Clean out the games dir
CreateAndCleanGameDir(gameName);
while ( n >= 0 )
{