bool ServerConnectDaemon::inConnectQueue( PlayerID &new_player_id ) { ConnectQueueElement connect_request; unsigned long iterator; bool completed; connect_queue.resetIterator( &iterator ); connect_request = connect_queue.incIterator( &iterator, &completed ); while( completed == false ) { if ( connect_request.new_player_id.getNetworkID() == new_player_id.getNetworkID() ) { return( true ); } connect_request = connect_queue.incIterator( &iterator, &completed ); } if ( (connection_state != _connect_state_idle) && (connect_player_id.getNetworkID() == new_player_id.getNetworkID() ) ) return( true ); return( false ); }
void PlayerInterface::setKill( const PlayerID &by_player, const PlayerID &on_player, unsigned short unit_type ) { assert( (by_player.getIndex() < max_players) && (on_player.getIndex() < max_players) ); player_lists[ by_player.getIndex() ].incKills( unit_type ); player_lists[ on_player.getIndex() ].incLosses( unit_type ); }
void PlayerInterface::setAlliance( const PlayerID& by_player, const PlayerID& with_player ) { assert( (by_player.getIndex() < max_players) && (with_player.getIndex() < max_players) ); *(alliance_matrix + (with_player.getIndex() * max_players) + by_player.getIndex() ) = true; //*(alliance_matrix + (by_player.getIndex() * max_players) + with_player.getIndex() ) = true; }
int32_t Register::InitProfile(int32_t uid) { int32_t ret = 0; PPlayerId init_id; init_id.set_uid(uid); init_id.set_zone_id(_req.zone_id()); __BEGIN_PROC__ PlayerID id; id.Init(init_id); bool exist; _p_profile = PlayerDataMgr::getInstance().Add(id, exist); if(NULL == _p_profile) { LOG_ERROR(_ctx, "alloc profile failed"); ret = -1; break; } else if(exist) { LOG_ERROR(_ctx, "profile exist. %s", id.ToString().c_str()); ret = -1; break; } time_t now = YAC_TimeProvider::getInstance()->getNow(); //玩家id PPlayerId *player_id = _p_profile->mutable_player_id(); player_id->set_uid(uid); player_id->set_zone_id(_req.zone_id()); //账户充值消费信息 PAccount *account = _p_profile->mutable_account(); account->set_history_total(0); account->set_balance(0); account->set_last_recharge_time(0); account->set_last_consume_time(0); //游戏内代币 PTokenMoney *token_money = _p_profile->mutable_token_money(); token_money->set_gold(0); //玩家基础信息 PBaseInfo *base_info = _p_profile->mutable_base_info(); base_info->set_name(_req.name()); base_info->set_register_time(now); base_info->set_login_time(now); base_info->set_gender(0); __END_PROC__ return ret; }
bool PlayerInterface::isAllied( const PlayerID& player, const PlayerID& with_player ) { bool val; assert( (player.getIndex() < max_players) && (with_player.getIndex() < max_players) ); val = *(alliance_matrix + (with_player.getIndex() * max_players) + player.getIndex() ); return( val ); }
/*!\brief Adding a player to the game. // // \param player The new player to be added to the game. // \return void */ void Game::addPlayer( PlayerID player ) { player->newGame(); for( Iterator other=players_.begin(); other!=players_.end(); ++other ) { other->introduce ( player ); player->introduce( other->player_ ); } players_.push_back( ControlledPlayer( player ) ); }
void Register::SetProfile(int32_t uid) { //初始化账号信息 PReginfo reginfo; InitReginfo(reginfo, uid); string reginfo_key = REGINFOPREFIX + _req.account(); string reginfo_value = reginfo.SerializeAsString(); //初始化profile InitProfile(uid); PPlayerId *player_id = _p_profile->mutable_player_id(); //string profile_key = PROFILEPREFIX + I2S(player_id->uid()) + "_" + I2S(player_id->zone_id()); string profile_key = CommFunc::getProfileKey(player_id->uid(), player_id->zone_id()); string profile_value = _p_profile->SerializeAsString(); auto got_reply = [&](Command<string>& c) { if(c.ok()) { _pkg_head.ret = RET_OK; PProfile *rsp_profile = _rsp.mutable_profile(); *rsp_profile = *_p_profile; //给客户端回包,流程结束 Send2Client(_pkg_head, _rsp); } else { PPlayerId *player_id = _p_profile->mutable_player_id(); PlayerID id; id.Init(*player_id); PlayerDataMgr::getInstance().Del(id); LOG_ERROR(_ctx, "SetProfile failed. cmd:%s status:%d", c.cmd().c_str(), c.status()); //给客户端回包,流程结束 _pkg_head.ret = RET_REDIS_ERR_SET; Send2Client(_pkg_head, _rsp); } }; ServerEnv::getInstance().getRdx().command<string>({"MSET", reginfo_key, reginfo_value, profile_key, profile_value}, got_reply); }
void PlayerInterface::disconnectPlayerCleanup( PlayerID &player_id ) { PlayerAllianceUpdate allie_update; unsigned short player_index; unsigned short disconnect_player_index; disconnect_player_index = player_id.getIndex(); for ( player_index = 0; player_index < max_players; player_index++ ) { if ( isAllied( disconnect_player_index, player_index ) == true ) { allie_update.set( disconnect_player_index, player_index, _player_break_alliance ); SERVER->sendMessage( &allie_update, sizeof( PlayerAllianceUpdate ), 0 ); } if ( isAllied( player_index, disconnect_player_index ) == true ) { allie_update.set( player_index, disconnect_player_index, _player_break_alliance ); SERVER->sendMessage( &allie_update, sizeof( PlayerAllianceUpdate ), 0 ); } } // ** for player_lists[ disconnect_player_index ].setStatus( _player_state_free ); PlayerState *player_state = getPlayerState( player_id ); PlayerStateSync player_state_update(player_state->getNetworkPlayerState()); SERVER->sendMessage( &player_state_update, sizeof( PlayerStateSync ), 0 ); }
void PlayerInterface::startPlayerStateSync( const PlayerID &connect_player ) { player_sync_index = 0; player_sync_connect_player_index = connect_player.getIndex(); player_sync_connect_id = connect_player; player_sync_timer.changeRate( 4 ); message_encoder.resetEncoder(); }
bool ServerConnectDaemon::inConnectQueue( PlayerID &new_player_id ) { std::list<ConnectQueueElement>::iterator i; for(i = connect_queue.begin(); i != connect_queue.end(); ++i) { const ConnectQueueElement& connect_request = *i; if ( connect_request.new_player_id.getNetworkID() == new_player_id.getNetworkID() ) { return true; } } if ( (connection_state != connect_state_idle) && (connect_player_id.getNetworkID() == new_player_id.getNetworkID() ) ) return true; return false; }
int NetworkServerUnix::sendMessage(const PlayerID& player_id, NetMessage* message, size_t size, int flags) { #ifdef NETWORKDEBUG LOG( ( "SEND >> Class: %d ID: %d", message->message_class, message->message_id ) ); #endif message->size = size; try { serversocket->sendMessage(player_id.getNetworkID(), (char *) message, message->size, ! (flags & _network_send_no_guarantee)); } catch(Exception e) { LOG ( ("Network send error when sending to client %d.", player_id.getNetworkID()) ); //return -1; } NetworkState::incPacketsSent(message->size); return 0; }
void PlayerInterface::spawnPlayer( const PlayerID &player, const iXY &location ) { unsigned short player_index; player_index = player.getIndex(); assert( player_index < max_players ); if ( player_lists[ player_index ].getStatus() != _player_state_free ) { UnitInterface::spawnPlayerUnits( location, player, player_lists[ player_index ].unit_config ); } // ** if _player_state_active }
bool PlayerInterface::testRulePlayerRespawn( bool *completed, PlayerState **player_state ) { PlayerID player; if ( respawn_rule_player_index == max_players ) { respawn_rule_player_index = 0; *completed = true; return( false ); } else { *completed = false; } player = player_lists[ respawn_rule_player_index ].getPlayerID(); if ( player_lists[ respawn_rule_player_index ].getStatus() == _player_state_active ) if ( UnitInterface::getUnitCount( player.getIndex() ) == 0 ) { *player_state = &player_lists[ respawn_rule_player_index ]; respawn_rule_player_index++; return( true ); } respawn_rule_player_index++; return( false ); }
bool ServerConnectDaemon::disconnectClient( PlayerID player_id ) { SERVER->shutdownClientTransport(player_id.getNetworkID()); SERVER->removeClientFromSendList(player_id); ObjectiveInterface::disownPlayerObjectives(player_id.getIndex()); UnitInterface::destroyPlayerUnits(player_id.getIndex()); PlayerInterface::disconnectPlayerCleanup( player_id ); for(std::list<ConnectQueueElement>::iterator i = connect_queue.begin(); i != connect_queue.end(); /*nothing */) { if(i->new_player_id == player_id) { i = connect_queue.erase(i); continue; } ++i; } if(connect_player_id == player_id) { connection_state = connect_state_idle; } return true; }
// ****************************************************************** void GameManager::spawnPlayer( const PlayerID &player ) { sound->stopTankIdle(); // ** Get a new spawn point and spawn the player ** iXY spawn_point = MapInterface::getFreeSpawnPoint(); PlayerInterface::spawnPlayer( player, spawn_point ); //** Change the location of the view camera to the spawn point ** iXY world_loc; MapInterface::mapXYtoPointXY( spawn_point, &world_loc ); if ( PlayerInterface::getLocalPlayerIndex() == player.getIndex() ) { WorldViewInterface::setCameraPosition( world_loc ); } else { SystemSetPlayerView set_view(world_loc.x, world_loc.y); SERVER->sendMessage(player, &set_view, sizeof(SystemSetPlayerView)); } sound->playTankIdle(); }
void NetworkServerUnix::shutdownClientTransport(const PlayerID &client_id) { assert(serversocket != 0); serversocket->removeClient(client_id.getNetworkID()); }
void LightweightDatabaseServer::Update(RakPeerInterface *peer) { RakNetTime time=0; DatabaseTable *databaseTable; DataStructures::Page<unsigned, DataStructures::Table::Row*, _TABLE_BPLUS_TREE_ORDER> *cur; unsigned i,j; DataStructures::Table::Row* row; DataStructures::List<unsigned> removeList; PlayerID playerId; // periodic ping if removing system that do not respond to pings. for (i=0; i < database.Size(); i++) { databaseTable=database[i]; if (databaseTable->removeRowOnPingFailure) { // Reading the time is slow - only do it once if necessary. if (time==0) time = RakNet::GetTime(); if (databaseTable->nextRowPingCheck < time) { databaseTable->nextRowPingCheck=time+1000+(randomMT()%1000); DataStructures::BPlusTree<unsigned, DataStructures::Table::Row*, _TABLE_BPLUS_TREE_ORDER> &rows = databaseTable->table.GetRows(); cur = rows.GetListHead(); while (cur) { // Mark dropped entities for (j=0; j < (unsigned)cur->size; j++) { row = cur->data[j]; if (time - row->cells[databaseTable->lastPingResponseColumnIndex]->i > DROP_SERVER_INTERVAL) removeList.Insert(cur->keys[j]); } cur=cur->next; } // Remove dropped entities for (j=0; j < removeList.Size(); j++) databaseTable->table.RemoveRow(removeList[i]); removeList.Clear(true); cur = rows.GetListHead(); // Ping remaining entities if they are not connected. If they are connected just increase the ping interval. while (cur) { for (j=0; j < (unsigned)cur->size; j++) { row = cur->data[j]; if (row->cells[databaseTable->nextPingSendColumnIndex]->i < (int) time) { row->cells[databaseTable->systemIdColumnIndex]->Get((char*)&playerId, 0); if (peer->GetIndexFromPlayerID(playerId)==-1) { peer->Ping(playerId.ToString(false), playerId.port, false); } else { // Consider the fact that they are connected to be a ping response row->cells[databaseTable->lastPingResponseColumnIndex]->i=time; } row->cells[databaseTable->nextPingSendColumnIndex]->i=time+SEND_PING_INTERVAL+(randomMT()%1000); } } cur=cur->next; } } } } }