void net_send_game_init_data(GameNetConnection& net, PlayerData& pd, int seed) { for (int n = 0; n < pd.all_players().size(); n++) { int net_id = pd.all_players()[n].net_id; if (net_id == 0) { continue; // Don't send to self } // Send a version to each player detailing which player entry is theirs // This is a necessary (slight) evil SerializeBuffer& sb = net.grab_buffer( GameNetConnection::PACKET_SERV2CLIENT_INITIALPLAYERDATA); sb.write_int(seed); // Send which index is local player to recipient: sb.write_int(n); std::vector<PlayerDataEntry>& plist = pd.all_players(); sb.write_int(plist.size()); for (int i = 0; i < plist.size(); i++) { PlayerDataEntry& pde = plist[i]; sb.write(pde.player_name); sb.write_int(pde.classtype); sb.write_int(pde.net_id); } net.send_packet(sb, net_id); } }
void net_recv_game_init_data(SerializeBuffer& sb, int sender, GameStateInitData& init_data, PlayerData& pd) { //Write seed sb.read_int(init_data.seed); init_data.seed_set_by_network_message = true; //Read player data int localidx; sb.read_int(localidx); pd.set_local_player_idx(localidx); int playern; sb.read_int(playern); LANARTS_ASSERT(pd.all_players().empty()); for (int i = 0; i < playern; i++) { std::string name; class_id classtype; int net_id; sb.read(name); sb.read_int(classtype); sb.read_int(net_id); pd.register_player(name, NULL, classtype, net_id); } printf("Received init packet: seed = 0x%X, localid = %d, nplayers = %d\n", init_data.seed, localidx, playern); }
static int tolua_PlayerData_PlayerData_setEnergy00(lua_State* tolua_S) { #ifndef TOLUA_RELEASE tolua_Error tolua_err; if ( !tolua_isusertype(tolua_S,1,"PlayerData",0,&tolua_err) || !tolua_isnumber(tolua_S,2,0,&tolua_err) || !tolua_isnoobj(tolua_S,3,&tolua_err) ) goto tolua_lerror; else #endif { PlayerData* self = (PlayerData*) tolua_tousertype(tolua_S,1,0); int _energy = ((int) tolua_tonumber(tolua_S,2,0)); #ifndef TOLUA_RELEASE if (!self) tolua_error(tolua_S,"invalid 'self' in function 'setEnergy'", NULL); #endif { self->setEnergy(_energy); } } return 0; #ifndef TOLUA_RELEASE tolua_lerror: tolua_error(tolua_S,"#ferror in function 'setEnergy'.",&tolua_err); return 0; #endif }
static int tolua_PlayerData_PlayerData_getEnergy00(lua_State* tolua_S) { #ifndef TOLUA_RELEASE tolua_Error tolua_err; if ( !tolua_isusertype(tolua_S,1,"PlayerData",0,&tolua_err) || !tolua_isnoobj(tolua_S,2,&tolua_err) ) goto tolua_lerror; else #endif { PlayerData* self = (PlayerData*) tolua_tousertype(tolua_S,1,0); #ifndef TOLUA_RELEASE if (!self) tolua_error(tolua_S,"invalid 'self' in function 'getEnergy'", NULL); #endif { int tolua_ret = (int) self->getEnergy(); tolua_pushnumber(tolua_S,(lua_Number)tolua_ret); } } return 1; #ifndef TOLUA_RELEASE tolua_lerror: tolua_error(tolua_S,"#ferror in function 'getEnergy'.",&tolua_err); return 0; #endif }
static int tolua_PlayerData_PlayerData_setName00(lua_State* tolua_S) { #ifndef TOLUA_RELEASE tolua_Error tolua_err; if ( !tolua_isusertype(tolua_S,1,"PlayerData",0,&tolua_err) || !tolua_isstring(tolua_S,2,0,&tolua_err) || !tolua_isnoobj(tolua_S,3,&tolua_err) ) goto tolua_lerror; else #endif { PlayerData* self = (PlayerData*) tolua_tousertype(tolua_S,1,0); char* _name = ((char*) tolua_tostring(tolua_S,2,0)); #ifndef TOLUA_RELEASE if (!self) tolua_error(tolua_S,"invalid 'self' in function 'setName'", NULL); #endif { self->setName(_name); } } return 0; #ifndef TOLUA_RELEASE tolua_lerror: tolua_error(tolua_S,"#ferror in function 'setName'.",&tolua_err); return 0; #endif }
static int tolua_PlayerData_PlayerData_getName00(lua_State* tolua_S) { #ifndef TOLUA_RELEASE tolua_Error tolua_err; if ( !tolua_isusertype(tolua_S,1,"PlayerData",0,&tolua_err) || !tolua_isnoobj(tolua_S,2,&tolua_err) ) goto tolua_lerror; else #endif { PlayerData* self = (PlayerData*) tolua_tousertype(tolua_S,1,0); #ifndef TOLUA_RELEASE if (!self) tolua_error(tolua_S,"invalid 'self' in function 'getName'", NULL); #endif { const char* tolua_ret = (const char*) self->getName(); tolua_pushstring(tolua_S,(const char*)tolua_ret); } } return 1; #ifndef TOLUA_RELEASE tolua_lerror: tolua_error(tolua_S,"#ferror in function 'getName'.",&tolua_err); return 0; #endif }
void net_recv_game_init_data(SerializeBuffer& sb, int sender, GameStateInitData& init_data, PlayerData& pd) { //Write seed sb.read(init_data); init_data.received_init_data = true; //Read player data int localidx; sb.read_int(localidx); int playern; sb.read_int(playern); LANARTS_ASSERT(pd.all_players().empty()); for (int i = 0; i < playern; i++) { std::string name; std::string classtype; int net_id; sb.read(name); sb.read(classtype); sb.read_int(net_id); pd.register_player(name, NULL, classtype, LuaValue(), (i == localidx), net_id); } printf( "Received init packet: seed = 0x%X, localid = %d, nplayers = %d, " "frame_action_repeat = %d, regen_level_on_death = %d, network_debug_mode = %d, time_per_step = %f\n", init_data.seed, localidx, playern, init_data.frame_action_repeat, (int) init_data.regen_on_death, (int) init_data.network_debug_mode, init_data.time_per_step); }
PlayerData::PlayerData(const PlayerData &other) : m_uniqueId(other.GetUniqueId()), m_dbId(other.GetDBId()), m_number(other.GetNumber()), m_startCash(other.GetStartCash()), m_guid(other.GetGuid()), m_oldGuid(other.GetOldGuid()), m_name(other.GetName()), m_password(), m_country(other.GetCountry()), m_avatarFile(other.GetAvatarFile()), m_avatarMD5(other.GetAvatarMD5()), m_type(other.GetType()), m_rights(other.GetRights()), m_isGameAdmin(other.IsGameAdmin()), m_netAvatarFile(), m_dataMutex() { }
void NetClient::set_ready(const bool b) { if (!me || !server || ourself == players.end()) return; PlayerData copy = *ourself; copy.ready = (char) b; ENetPacket* pck = copy.create_packet(); enet_peer_send(server, LEMNET_CHANNEL_MAIN, pck); }
void NetClient::set_style_and_spec(const char st, const bool sp) { if (!me || !server || ourself == players.end()) return; PlayerData copy = *ourself; copy.style = st; copy.spec = sp; ENetPacket* pck = copy.create_packet(); enet_peer_send(server, LEMNET_CHANNEL_MAIN, pck); }
// Only the server is concerned with this message void net_recv_connection_affirm(SerializeBuffer& sb, int sender, PlayerData& pd) { std::string name; class_id classtype; sb.read(name); sb.read_int(classtype); printf("connection affirm read\n"); pd.register_player(name, NULL, classtype, sender); printf("now there are %d players\n", (int)pd.all_players().size()); pd.set_local_player_idx(0); }
// Only the server is concerned with this message void net_recv_connection_affirm(SerializeBuffer& sb, int sender, PlayerData& pd) { printf("Recv conn with size=%d\n", sb.size()); std::string name; std::string classtype; sb.read(name); sb.read(classtype); printf("connection affirm read\n"); pd.register_player(name, NULL, classtype, LuaValue(), /* is local player */ false, sender); printf("now there are %d players\n", (int) pd.all_players().size()); }
/** * 'Menu Prototype' was selected. Push a Menu state. * \todo This will eventually be removed entirely, as it is only a programmer convenience right now. */ void MainMenu::MenuPrototypeAction() { PlayerData* playerData = new PlayerData(); playerData->load(SAVE_GAME); /** \todo This is never deleted, causing a memory leak. */ MenuShell* menuShell = new MenuShell(*playerData); HomeMenu* menu = new HomeMenu(executionStack, *menuShell, *playerData); executionStack.pushState(menu); }
X_VOID MainGame::EndBattle(bool win) { //------------打开战斗前的界面 m_nGameRunState = RUNING_IN_GAME; SceneManger::GetSingleton()->EnterScene(SceneManger::EM_SS_MAIN); if(DataPool::GetSingleton()->BattlyType == EM_COPY_SCENE) EventSystem::GetSingleton()->PushEvent(GAME_EVENT_LEVELLIST_SHOW); else if(DataPool::GetSingleton()->BattlyType == EM_SPORT) EventSystem::GetSingleton()->PushEvent(GAME_EVENT_RANKLIST_SHOW); else if(DataPool::GetSingleton()->BattlyType == EM_WOODPVP) { EventSystem::GetSingleton()->PushEvent(GAME_EVENT_BASE_ACTIVITY_SHOW); } else if(DataPool::GetSingleton()->BattlyType == EM_BATTLETYPE_QUJING) { vector<string> str;str.clear(); str.push_back(UtilTools::IntToString(EM_HUSONG_WOOD));// EventSystem::GetSingleton()->PushEvent(GAME_EVENT_CHEESE_SHOW,str); SendLogicPacket::OpenQuJingUi(); EventSystem::GetSingleton()->PushEvent(GAME_EVNET_LVL_ESCORTWOOD_SHOW); } else if(DataPool::GetSingleton()->BattlyType == EM_BATTLETYPE_BLOODBATTLE) { BloodData* pBloodData = DataPool::GetSingleton()->GetBloodData(); if (win) { pBloodData->NextStep(); }else { pBloodData->EnterBloodUi(); } } else EventSystem::GetSingleton()->PushEvent(GAME_EVENT_CHEESE_SHOW); ObjectManager* pManager = DataPool::GetSingleton()->getObjectManager(); PlayerData* pData = pManager->getSelf()->playerData(); if (pData && pData->IsLevelUp()) { pData->resetLevelUp(); EventSystem::GetSingleton()->PushEvent(GAME_EVNET_LVL_UPGRADE_SHOW); } BattleData * pBattle = DataPool::GetSingleton()->GetBattleData(); pBattle->DestroyBattleData(); }
void Phase_Harvest::Tick() { PlayerData* currentPlayerData = GameSceneManager::getInstance()->getCurrentPlayerData(); currentPlayerData->setFood(1); //만약 옥토 타일 위에 턴주의 병사가 있다면 해당 병사 한명당 식량 1 ++해야함. auto characterList = currentPlayerData->getCharacterList(); for (auto iter : *characterList) { if (iter->getCurrentTile()->getTypeOfTile() == TILE_RICH || iter->getCurrentTile()->getTypeOfTile() == TILE_RICH_SIDE) { //currentPlayerData->AddFood(1); EventManager::getInstance()->AddHistory(HistoryEventHarvest::Create(iter)); } } _NextPhaseInfo = PHASE_OCCUPY; }
EquipMenu::EquipMenu(ExecutionStack& executionStack, MenuShell& menuShell, PlayerData& playerData, const std::string& characterName) : MenuState(executionStack, menuShell), playerData(playerData), characterName(characterName) { // Initialize the equipment pane using the character slots. std::vector<EquipSlot*> characterSlots = playerData.getPartyCharacter(characterName)->getEquipment().getSlots(); equipSlots.assign(characterSlots.begin(), characterSlots.end()); EquipPane* equipPane = new EquipPane(equipSlots, equippableItems, menuShell.getDimension()); // The equipment menu will listen for slot selection and item selection equipPane->setModuleSelectListener(this); setMenuPane(equipPane); }
void SinglePlayerScene::setGameData(SingleGameData* game) { m_game = game; m_game->retain(); PlayerData *player = m_game->getPlayer(); if (player->getGender() == GENDER_MALE) { m_framePrefix = "boy1_character/boy1_"; } else { m_framePrefix = "girl1_character/girl1_"; } _labelName->setString(player->getName()); _labelScore->setString("0"); _labelLevel->setString(StringUtils::format("Lvl %d", player->getLevel())); }
MenuShell::MenuShell(PlayerData& playerData) : activeState(NULL) { try { setWidth(GraphicsUtil::getInstance()->getWidth()); setHeight(GraphicsUtil::getInstance()->getHeight()); const gcn::Color menuBackgroundColor(50, 50, 50, 150); const gcn::Rectangle menuAreaRect(0, 0, getWidth() * 0.8 - 5, getHeight() - 10); bg = new gcn::Icon("data/images/menubg.jpg"); selectSound = ResourceLoader::getSound("reselect"); menuTabs = new edwt::TabbedArea(); menuArea = new edwt::Container(); menuArea->setDimension(menuAreaRect); menuArea->setOpaque(false); menuTabs->setDimension(menuAreaRect); menuTabs->setForegroundColor(0xFFFFFF); menuTabs->setBaseColor(menuBackgroundColor); menuTabs->setDimension(menuAreaRect); menuTabs->addTab("Party", menuArea); CharacterList party = playerData.getParty(); for (CharacterList::iterator iter = party.begin(); iter != party.end(); ++iter) { menuTabs->addTab((*iter)->getName(), menuArea); } populateOpsList(); actionsListBox = new edwt::ListBox(listOps); actionsListBox->setBaseColor(0xFFFFFF); actionsListBox->setMinWidth((getWidth() * 0.2) - 10); actionsListBox->setAlignment(edwt::RIGHT); actionsListBox->adjustSize(); actionsListBox->adjustWidth(); actionsListBox->setBackgroundColor(menuBackgroundColor); actionsListBox->setOpaque(false); actionsListBox->setRowPadding(5); actionsListBox->addActionListener(this); actionsListBox->addSelectionListener(this); add(bg); add(menuTabs, getWidth() * 0.2, 5); add(actionsListBox, 5, menuTabs->getTabHeight() + 5); } catch (gcn::Exception& e) { DEBUG(e.getMessage()); } }
void net_recv_player_actions(SerializeBuffer& sb, int sender, PlayerData& pd) { int frame, player_number; sb.read_int(frame); sb.read_int(player_number); PlayerDataEntry& pde = pd.all_players().at(player_number); ActionQueue actions; sb.read_container(actions); pde.action_queue.queue_actions_for_frame(actions, frame); // printf("Receiving %d actions for player %d from %d \n", actions.size(), // player_number, sender); }
SaveGameModule::SaveGameModule(PlayerData& playerData) : playerData(playerData) { setNumberOfColumns(PlayerData::PARTY_SIZE); setHorizontalSpacing(10); setPadding(5, 5, 5, 5); CharacterList party = playerData.getParty(); for(CharacterList::iterator iter = party.begin(); iter != party.end(); ++iter) { edwt::Icon* characterPicture = new edwt::Icon((*iter)->getPortraitPath()); add(characterPicture); characterPortraits.push_back(characterPicture); } adjustContent(); setOpaque(false); addMouseListener(this); }
void RaceView::draw() { if( !bVisible ){ return; } if( mBg ){ gl::color(1,1,1); gl::draw( mBg ); } gl::drawSolidRect( Rectf( 834, 105, 834+260, 105+185 ) ); // big white rect gl::drawSolidRect( Rectf( 60, 133, 1870, 135 ) ); // white line // PLAYER INFO for( int i=0; i<mModel->getNumRacers(); i++){ PlayerData *pd = Model::getInstance()->playerData[i]; mRaceTexts[i]->draw( pd, Vec2f(0, 390 + 102*i) ); } // MAIN TIMER gl::color(0,0,0,1); if( mStateManager->getCurrentRaceState() == RACE_STATE::RACE_RUNNING ){ int elapsedTime = (getElapsedSeconds()*1000.0) - mModel->startTimeMillis; mModel->elapsedRaceTimeMillis = elapsedTime; mTimerFont->drawString( mGlobal->toTimestamp(mModel->elapsedRaceTimeMillis ), Vec2f(867,154) ); }else if( mStateManager->getCurrentRaceState() == RACE_STATE::RACE_COMPLETE ){ mTimerFont->drawString( mGlobal->toTimestamp(mModel->elapsedRaceTimeMillis ), Vec2f(867,154) ); }else { mTimerFont->drawString( mGlobal->toTimestamp(0), Vec2f(867,154) ); } // DIAL gl::color(1,1,1,1); gl::draw( mDial, mDial->getSize() * -0.5 + Vec2f(967, 580) ); // FLAG gl::color(1,1,1,1); if( mFinishFlag && mGlobal->currentRaceType == RACE_TYPE::RACE_TYPE_TIME ){ gl::draw(mFinishFlag, Vec2f(873, 130)); } mStartStop.draw(); if( mLogo ){ gl::color( 1, 1, 1, 1 ); gl::draw( mLogo, Vec2f(1920, 1080) - Vec2f(50,50) - mLogo->getSize() ); } ci::ColorA tmpCol; for( int i=0; i<mModel->getNumRacers(); i++){ PlayerData *pd = Model::getInstance()->playerData[i]; mProgressShader->bind();{ tmpCol = mGlobal->playerColors[i]; mProgressShader->uniform( "baseColor", tmpCol ); mProgressShader->uniform( "leadingEdgePct", (float)pd->getPercent() ); mProgressShader->uniform( "trailingEdgePct", (float)pd->getPercent() - 0.15f ); gl::draw( mVboList[i] ); }mProgressShader->unbind(); } // COUNTDOWN mCountDown->draw(); }
void userInfoUIView::onButtonPur(cocos2d::CCObject * pSender, cocos2d::extension::CCControlEvent pCCControlEvent) { SoundSystem::GetSingleton()->playClickEffect(GAME_CLICK_COMMON); char buffer[512] = {0}; X_INT buyNum = -1; X_INT level = -1; X_INT money =-1; if (DataPool::GetSingleton()) { ObjectManager* pM = DataPool::GetSingleton()->getObjectManager(); if (!pM)return; ObjectSelf* pSelf = pM->getSelf(); if (!pSelf)return; PlayerData* pData = pSelf->playerData(); if (!pData)return; buyNum = pData->GetBuyAcNum(); level = pData->GetLevel(); money = pData->GetGold(); } if (buyNum >=ActionPointBuyNum) { string tip = UtilTools::GET_TEXT_FROM_LANG( 587); if (tip != "") { vector<string> strV;strV.clear(); strV.push_back(tip); EventSystem::GetSingleton()->PushEvent(GAME_EVENT_TIP_UPDATA,strV); } return; } const DataBase* pDataFile = DataBaseSystem::GetSingleton()->GetDataBase(DBC_FILE_BUYACTIONPOINT); if (!pDataFile)return; const stDBC_FILE_BUYACTIONPOINT * m_pTableData =(const stDBC_FILE_BUYACTIONPOINT*)pDataFile->GetFieldsByIndexKey(buyNum+1); if (!m_pTableData)return; if (level<m_pTableData->level) { string tip = UtilTools::GET_TEXT_FROM_LANG( 588); if (tip != "") { vector<string> strV;strV.clear(); strV.push_back(tip); EventSystem::GetSingleton()->PushEvent(GAME_EVENT_TIP_UPDATA,strV); } return; } if (money < m_pTableData->cost) { string tip = UtilTools::GET_TEXT_FROM_LANG(102); if (tip != "") { vector<string> strV;strV.clear(); strV.push_back(tip); EventSystem::GetSingleton()->PushEvent(GAME_EVENT_TIP_UPDATA,strV); } return; } sprintf(buffer,UtilTools::GET_TEXT_FROM_LANG(543),m_pTableData->cost,m_pTableData->addAction); ModalDialogView *dialogPur = ModalDialogView::createDialog( buffer,this); dialogPur->setTag(1000); addChild(dialogPur,10); }
PlayScreen::PlayScreen( sf::Font *font, sf::Vector2u screenSize, PlayerData& playerData ) : mLevel( Level( font, screenSize, playerData.getCurrentLevel() ) ), mIsPaused(false) { mGameModeToSwitchTo = 0; }
int EnemyMovementObject::update(int dt) { if(NpcMovementObject::update(dt) == -1) { return -1; } if(noAttackTimer > 0) { noAttackTimer -= dt; if(noAttackTimer < 0) { noAttackTimer = 0; } } if(noAttackTimer == 0) { Rectangle *thisRect = sprite->getRectWithoutRot(); if(getObjectList() != NULL) { std::list<GameObject*> *spatialList = spatialHashmap->getNearby(this); for(std::list<GameObject*>::iterator it = spatialList->begin(); it != spatialList->end(); ++it) { GameObject *gameObject = *it; if(gameObject->gameObjectInstance->gameObject->type != GameObjectClass::INIMIGO && gameObject->gameObjectInstance->gameObject->type != GameObjectClass::ITEM) { Rectangle *objectRect = gameObject->sprite->getRectWithoutRot(); if(!gameObject->isInvincible() && gameObject->position->z == 0 && objectRect->intersectsWith(thisRect)) { int dmg = gameObject->addDamage(this, this->gameObjectInstance->gameObject->atacaEncostaPersonagemDano); if(dmg != 0) { gameObject->setInvincibility(1000); } } delete objectRect; } } delete spatialList; } delete thisRect; } if(attackTimer/1000.0f > (float)this->gameObjectInstance->gameObject->tempoAtaque) { if(this->gameObjectInstance->gameObject->atiraItemMagiaDirecaoPersonagem) { ObjectFunctions *objectFunctions = ObjectFunctions::getInstance(); GameData *gameData = GameData::getInstance(); PlayerData *playerData = PlayerData::getInstance(); GameObjectClass *throwed; throwed = gameData->searchGameObjectById(this->gameObjectInstance->gameObject->atiraItemMagiaDirecaoPersonagemIdItem); if(playerData->getPlayer() != NULL) { objectFunctions->throwObject(this, throwed, 2, Vector2(*playerData->getPlayer()->position), 0); } } if(this->gameObjectInstance->gameObject->atiraItemMaginaDirecaoEstiver) { ObjectFunctions *objectFunctions = ObjectFunctions::getInstance(); GameData *gameData = GameData::getInstance(); GameObjectClass *throwed; throwed = gameData->searchGameObjectById(this->gameObjectInstance->gameObject->atiraItemMaginaDirecaoEstiverIdItem); objectFunctions->throwObject(this, throwed, 2, 0); } attackTimer = 0; } attackTimer += dt; }
void NetClient::calc() { ENetEvent event; if (me && server) while (enet_host_service(me, &event, 0) > 0) { char type = (event.type == ENET_EVENT_TYPE_RECEIVE) ? (char) event.packet->data[0] : LEMNET_NOTHING; if (event.type == ENET_EVENT_TYPE_CONNECT) { // Server shall check if protocols and versions match. send_welcome_data(); } else if (event.type == ENET_EVENT_TYPE_DISCONNECT) { exit = true; } else if (type == LEMNET_DISCON_SILENT) { exit = true; } else if (type == LEMNET_WELCOME_DATA) { // The server sends out packets of this sort, but that only // happens to inform clients before 2009 Oct 25 of their very // old version. The server will probably stop that in some // months, and until then we simply ignore these. } else if (type == LEMNET_YOU_TOO_OLD || type == LEMNET_YOU_TOO_NEW) { const bool old = (type == LEMNET_YOU_TOO_OLD); if (old) Console::push_back(Language::net_chat_we_too_old); else Console::push_back(Language::net_chat_we_too_new); std::string msg = Language::net_chat_version_yours; msg += Help::version_to_string(gloB->version); msg += Language::net_chat_version_server; msg += Help::version_to_string( get_uint32_from(event.packet->data + 2)); msg += '.'; Console::push_back(msg); if (old) Console::push_back(Language::net_chat_please_download); else Console::push_back(Language::net_chat_server_update); // The server will throw us out. } else if (type == LEMNET_SOMEONE_OLD || type == LEMNET_SOMEONE_NEW) { int who_nr = event.packet->data[1]; PlDatIt who = players.begin(); while (who != players.end() && who->number != who_nr) ++who; if (type == LEMNET_SOMEONE_NEW) { Console::push_back(Language::net_chat_someone_new); Console::push_back(Language::net_chat_server_update); } // There exists someone with that number else if (who != players.end()) { std::string s = who->name + ' ' + Language::net_chat_named_guy_old; Console::push_back(s); } else Console::push_back(Language::net_chat_someone_old); // This is independent from new or old if (who != players.end()) { // reset player players.erase(who); set_nobody_ready(); player_data_change = true; } } else if (type == LEMNET_RECHECK) { send_welcome_data(); } else if (type == LEMNET_ASSIGN_NUMBER) { PlayerData pd(event.packet->data[2], gloB->user_name.c_str()); pd.style = pd.number % (LixEn::STYLE_MAX-1) + 1; if (useR->network_last_style > 0 && useR->network_last_style < LixEn::STYLE_MAX) pd.style = static_cast <char> (useR->network_last_style); // The lobby saves the style to useR->... players.clear(); players.push_back(pd); ourself = players.begin(); ENetPacket* p = pd.create_packet(); enet_peer_send(server, LEMNET_CHANNEL_MAIN, p); } else if (type == LEMNET_ROOM_DATA) { rooms.clear(); for (int room = 0; room < NETWORK_ROOMS_MAX; ++room) if (event.packet->data[2 + room] > 0) { RoomData rd; rd.number = room; rd.members = event.packet->data[2 + room]; rooms.insert(rd); } room_data_change = true; } else if (type == LEMNET_ROOM_CHANGE) { // Throw out all people other than us, because we'll soon receive // LEMNET_PLAYER_BEFORE packets for everyone in the new room. PlayerData temp_ourself = *ourself; players.clear(); players.push_back(temp_ourself); ourself = players.begin(); const char target_room = event.packet->data[2]; if (ourself->room == -1) Console::push_back(Language::net_chat_we_connected); else if (target_room == 0) Console::push_back(Language::net_chat_we_in_lobby); else { std::ostringstream message; message << Language::net_chat_we_in_room << (int) target_room << Language::net_chat_we_in_room_2; Console::push_back(message.str()); } ourself->room = target_room; } else if (type == LEMNET_PLAYER_DATA || type == LEMNET_PLAYER_BEFORE) { PlayerData pd; pd.read_from(event.packet); PlDatIt known = get_player(pd.number); // A new person has joined if (known == players.end()) { // Insert new data before the first higher data, so that // the players list is still sorted by operator <. PlDatIt insert_here = --players.end(); while (insert_here != --players.begin() && pd < *insert_here) --insert_here; players.insert(++insert_here, pd); set_nobody_ready(); if (type == LEMNET_PLAYER_DATA) { std::ostringstream message; message << pd.name; if (ourself->room == 0) message << Language::net_chat_player_in_lobby; else { message << Language::net_chat_player_in_room; message << (int) ourself->room; message << Language::net_chat_player_in_room_2; } Console::push_back(message.str()); Sound::play_loud(Sound::JOIN); } } else { // Only the information about readiness doesn't set back // all ready states. Everything else does. // snr = set nobody ready bool dont_call_snr = *known == pd; known->ready = !known->ready; // *known will be overwr. anyway dont_call_snr = dont_call_snr || *known == pd; *known = pd; if (!dont_call_snr) set_nobody_ready(); } player_data_change = true; } else if (type == LEMNET_PLAYER_CLEAR || type == LEMNET_PLAYER_OUT_TO) { unsigned nr = event.packet->data[1]; PlDatIt who = get_player(nr); if (who != players.end()) { std::ostringstream message; message << who->name; if (type == LEMNET_PLAYER_CLEAR) { message << Language::net_chat_disconnection; } else { int room = event.packet->data[2]; if (room == 0) { message << Language::net_chat_player_out_lobby; } else { message << Language::net_chat_player_out_room; message << room; message << Language::net_chat_player_out_room_2; } } Console::push_back(message.str()); players.erase(who); player_data_change = true; set_nobody_ready(); } } else if (type == LEMNET_LEVEL_FILE) { set_nobody_ready(); std::istringstream str((char*) event.packet->data + 2); level.load_from_stream(str); level_change = true; PlDatIt who = get_player(event.packet->data[1]); if (who != players.end()) { std::ostringstream msg; msg << who->name << ' ' << Language::net_chat_level_change << ' ' << level.get_name(); Console::push_back(msg.str()); } } else if (type == LEMNET_CHAT_MESSAGE) { std::string message = (const char*) &event.packet->data[2]; Console::push_back(message, true); // true = weiss } else if (type == LEMNET_GAME_START) { // Reset things to make it possible to play multiple games one // after another set_nobody_ready(); replay_data.clear(); permu = Permu(event.packet->data[2],(char*)event.packet->data + 3); // Jetzt aber... auf geht's! game_start = true; updates_change = 0; std::ostringstream start_message; start_message << Language::net_game_start; if (useR->key_chat > 0 && useR->key_chat < KEY_MAX) { start_message << Language::net_game_how_to_chat_1; start_message << Help::scancode_to_string(useR->key_chat); start_message << Language::net_game_how_to_chat_2; } Console::push_back(start_message.str()); } else if (type == LEMNET_GAME_END) { game_end = true; Console::push_back(Language::net_game_end); } else if (type == LEMNET_REPLAY_DATA) { // Only make available if we aren't the sender if (event.packet->data[1] != ourself->number) { ReplayData data; data.read_from(event.packet); replay_data.push_back(data); } } else if (type == LEMNET_UPDATES) { updates_change = get_uint32_from(&event.packet->data[2]); } if (event.type == ENET_EVENT_TYPE_RECEIVE) enet_packet_destroy(event.packet); } }
PlayerData* PlayerData::create(string playerId, string playerName, bool isRecording) { PlayerData *playerData = new PlayerData(playerId, playerName, isRecording); playerData->autorelease(); return playerData; }
bool PlayerData::operator<(const PlayerData &other) const { boost::mutex::scoped_lock lock(m_dataMutex); return m_number < other.GetNumber(); }