int DFSRndNumGenerator::revisit_node(DFSRndNumGenerator::SearchState *state, int local_current_pos, int bound, const Filter *filter, const string *) { int rv = state->value(); if (filter) { if (rv >= bound) { state->dump(""); dumpCurrentState(bound, ""); cout << "rv = " << rv << ", bound = " << bound << std::endl; assert(0); } filter->filter(rv); ERROR_GUARD(-1); assert(current_pos_ < CGOptions::max_exhaustive_depth()); } seq_->add_number(rv, bound, local_current_pos); return rv; }
// used to handle message from a ClientConnection // those message can be // 'SYSTEM_REGISTER <CONSUMER | PROVIDER> #Game [Game]' --> no answer // 'SYSTEM_REQUEST_GAME GameKind' // 'SYSTEM_REQUEST_GAME_REFUSED ErrorMessage' // 'SYSTEM_REQUEST_GAME_ACCEPTED GameId #Consumer [Consumer]' // 'SYSTEM_JOIN_GAME GameId' // 'SYSTEM_LEAVE_GAME GameId' // '<gameId> MESSAGE' void ConnectionManager::handleMessage( ClientConnectionPtr connection, const std::string& message ) { // log the message AsyncLogger::getInstance()->log( "RECEIVE FROM (" + connection->getLogin() + ") : " + message ); // explode the message to be able to check the kind std::vector< std::string > messageParts; if ( StringUtils::explode( message, ' ', messageParts, 2 ) == 2 ) { if ( messageParts[ 0 ] == SYSTEM_REGISTER ) { registerConnection( connection, messageParts[ 1 ] ); dumpCurrentState(); } else if ( messageParts[ 0 ] == SYSTEM_REQUEST_GAME ) { requestGame( connection, messageParts[ 1 ] ); dumpCurrentState(); } else if ( messageParts[ 0 ] == SYSTEM_REQUEST_GAME_LIST ) { requestGameList( connection, messageParts[ 1 ] ); } else if ( messageParts[ 0 ] == SYSTEM_JOIN_OR_REQUEST_GAME ) { joinOrRequestGame( connection, messageParts[ 1 ] ); dumpCurrentState(); } else if ( messageParts[ 0 ] == SYSTEM_JOIN_GAME ) { joinGame( connection, messageParts[ 1 ] ); dumpCurrentState(); } else if ( messageParts[ 0 ] == SYSTEM_LEAVE_GAME ) { leaveGame( connection, messageParts[ 1 ] ); dumpCurrentState(); } else if ( messageParts[ 0 ] == SYSTEM_GAME_CREATION_REFUSED ) { // get the relevant information std::vector< std::string > messageInformation; StringUtils::explode( messageParts[ 1 ], ' ', messageInformation, 2 ); // and close the game closeGame( connection, messageInformation[ 0 ], messageInformation[ 1 ] ); dumpCurrentState(); } else if ( messageParts[ 0 ] == GAME_MESSAGE ) { // get the relevant information std::vector< std::string > messageInformation; StringUtils::explode( messageParts[ 1 ], ' ', messageInformation, 2 ); // and forward the message (gameId, message) handleGameMessage( connection, messageInformation[ 0 ], message ); } } }
void ConnectionManager::closeConnection( ClientConnectionPtr connection ) { std::set< std::string > gameToCloseList; // find all the game related to this connection for ( GameMap::iterator itGame = games.begin(); itGame != games.end(); ) { // get the current game Game* game = itGame->second; // check the contains status if ( game->contains( connection ) == true ) { // remove the connection from the game if ( game->remove( connection ) == true ) { // if the connection was the provider, close the game gameToCloseList.insert( game->getId() ); delete game; itGame = games.erase( itGame ); continue; } else if ( game->getClients().size() == 0 ) { // if there is no more players gameToCloseList.insert( game->getId() ); delete game; itGame = games.erase( itGame ); continue; } } // go to the next game itGame++; } // check if there is some game to close if ( gameToCloseList.size() > 0 ) { // create the close message std::string closeMessage( GAME_MESSAGE + " " + CLOSE_MESSAGE + " " ); size_t i = 0; for ( std::set< std::string >::const_iterator it = gameToCloseList.begin(); it != gameToCloseList.end(); it++ ) { closeMessage += *it; if ( i++ < gameToCloseList.size() - 1 ) { closeMessage += "|"; } } closeMessage += " Client close its connection and end the game" ; // and send it to everyone for ( ClientList::const_iterator itClient = connections.begin(); itClient != connections.end(); itClient++ ) { (*itClient)->sendMessage( closeMessage ); } } // remove the connection from the client aggregat for ( ClientAggregat::iterator itAgg = consumerByGame.begin(); itAgg != consumerByGame.end(); ) { for ( ClientList::iterator itClient = itAgg->second.begin(); itClient != itAgg->second.end(); itClient++ ) { // check the client if ( *itClient == connection ) { // remove it itAgg->second.erase( itClient ); // and break as there is only one occurence of client per game break; } } // check if there is still some client for the game if ( itAgg->second.size() == 0 ) { itAgg = consumerByGame.erase( itAgg ); continue; } // and next game itAgg++; } // remove the connection from the provider aggregat for ( ClientAggregat::iterator itAgg = providerByGame.begin(); itAgg != providerByGame.end(); ) { for ( ClientList::iterator itClient = itAgg->second.begin(); itClient != itAgg->second.end(); itClient++ ) { // check the client if ( *itClient == connection ) { // remove it itAgg->second.erase( itClient ); // and break as there is only one occurence of client per game break; } } // check if there is still some client for the game if ( itAgg->second.size() == 0 ) { itAgg = providerByGame.erase( itAgg ); continue; } // and next game itAgg++; } // remove the connections from the list connections.erase( connection ); dumpCurrentState(); }