Clients now connect and recieve gamestate information

This commit is contained in:
mdiluzio 2015-01-02 17:14:16 +00:00
parent 4285770d52
commit 56e767bb5b
5 changed files with 109 additions and 45 deletions

View file

@ -79,17 +79,13 @@ std::string getGamesDir()
return dir;
}
// =====================================================================================================================
int runFromFilesystem(int argc, char* argv[])
CTTRTSGame GetGameFromFile( const std::string& filename )
{
std::string gamefile = argv[1];
std::string gamefile = filename;
// Default for maps
std::string ttrts_maps_dir = getMapsDir();
// Default for games
std::string ttrts_games_dir = getGamesDir();
// If file path is not local path and file doesn't exist
if( gamefile.find("/") == std::string::npos
&& access( gamefile.c_str(), F_OK ) == -1 )
@ -101,13 +97,11 @@ int runFromFilesystem(int argc, char* argv[])
if( access( gamefile.c_str(), F_OK ) == -1 )
{
std::cerr<<"Error: "<< gamefile <<" file not found"<<std::endl;
return -1;
return CTTRTSGame(0,0);
}
std::ifstream file(gamefile);
std::cout<<"Launching TTRTS with "<<gamefile<<std::endl;
std::string gameDescriptor;
// Reserve the string needed up front
@ -121,15 +115,27 @@ int runFromFilesystem(int argc, char* argv[])
if( gameDescriptor.size() == 0 )
{
std::cerr<<"Error: failed to read in any information from "<<gamefile<<std::endl;
return -1;
return CTTRTSGame(0,0);
}
// Create the game
CTTRTSGame game = GetGameFromString(gameDescriptor);
return GetGameFromString(gameDescriptor);
}
// =====================================================================================================================
int runFromFilesystem(int argc, char* argv[])
{
std::string gamefile = argv[1];
std::cout<<"Launching TTRTS with "<<gamefile<<std::endl;
CTTRTSGame game = GetGameFromFile(gamefile);
// Grab the players involved
auto players = game.GetPlayers();
// Default for games
std::string ttrts_games_dir = getGamesDir();
// Current game directory
std::string gameDir = ttrts_games_dir + game.GetName();