void CGameClient::OnNewSnapshot() { m_NewTick = true; // clear out the invalid pointers mem_zero(&g_GameClient.m_Snap, sizeof(g_GameClient.m_Snap)); m_Snap.m_LocalClientID = -1; // secure snapshot { int Num = Client()->SnapNumItems(IClient::SNAP_CURRENT); for(int Index = 0; Index < Num; Index++) { IClient::CSnapItem Item; void *pData = Client()->SnapGetItem(IClient::SNAP_CURRENT, Index, &Item); if(m_NetObjHandler.ValidateObj(Item.m_Type, pData, Item.m_DataSize) != 0) { if(g_Config.m_Debug) { char aBuf[256]; str_format(aBuf, sizeof(aBuf), "invalidated index=%d type=%d (%s) size=%d id=%d", Index, Item.m_Type, m_NetObjHandler.GetObjName(Item.m_Type), Item.m_DataSize, Item.m_ID); Console()->Print(IConsole::OUTPUT_LEVEL_DEBUG, "game", aBuf); } Client()->SnapInvalidateItem(IClient::SNAP_CURRENT, Index); } } } ProcessEvents(); if(g_Config.m_DbgStress) { if((Client()->GameTick()%100) == 0) { char aMessage[64]; int MsgLen = rand()%(sizeof(aMessage)-1); for(int i = 0; i < MsgLen; i++) aMessage[i] = 'a'+(rand()%('z'-'a')); aMessage[MsgLen] = 0; CNetMsg_Cl_Say Msg; Msg.m_Team = rand()&1; Msg.m_pMessage = aMessage; Client()->SendPackMsg(&Msg, MSGFLAG_VITAL); } } // go trough all the items in the snapshot and gather the info we want { m_Snap.m_aTeamSize[TEAM_RED] = m_Snap.m_aTeamSize[TEAM_BLUE] = 0; int Num = Client()->SnapNumItems(IClient::SNAP_CURRENT); for(int i = 0; i < Num; i++) { IClient::CSnapItem Item; const void *pData = Client()->SnapGetItem(IClient::SNAP_CURRENT, i, &Item); if(Item.m_Type == NETOBJTYPE_CLIENTINFO) { const CNetObj_ClientInfo *pInfo = (const CNetObj_ClientInfo *)pData; int ClientID = Item.m_ID; IntsToStr(&pInfo->m_Name0, 4, m_aClients[ClientID].m_aName); IntsToStr(&pInfo->m_Clan0, 3, m_aClients[ClientID].m_aClan); m_aClients[ClientID].m_Country = pInfo->m_Country; IntsToStr(&pInfo->m_Skin0, 6, m_aClients[ClientID].m_aSkinName); m_aClients[ClientID].m_UseCustomColor = pInfo->m_UseCustomColor; m_aClients[ClientID].m_ColorBody = pInfo->m_ColorBody; m_aClients[ClientID].m_ColorFeet = pInfo->m_ColorFeet; // prepare the info if(m_aClients[ClientID].m_aSkinName[0] == 'x' || m_aClients[ClientID].m_aSkinName[1] == '_') str_copy(m_aClients[ClientID].m_aSkinName, "default", 64); m_aClients[ClientID].m_SkinInfo.m_ColorBody = m_pSkins->GetColorV4(m_aClients[ClientID].m_ColorBody); m_aClients[ClientID].m_SkinInfo.m_ColorFeet = m_pSkins->GetColorV4(m_aClients[ClientID].m_ColorFeet); m_aClients[ClientID].m_SkinInfo.m_Size = 64; // find new skin m_aClients[ClientID].m_SkinID = g_GameClient.m_pSkins->Find(m_aClients[ClientID].m_aSkinName); if(m_aClients[ClientID].m_SkinID < 0) { m_aClients[ClientID].m_SkinID = g_GameClient.m_pSkins->Find("default"); if(m_aClients[ClientID].m_SkinID < 0) m_aClients[ClientID].m_SkinID = 0; } if(m_aClients[ClientID].m_UseCustomColor) m_aClients[ClientID].m_SkinInfo.m_Texture = g_GameClient.m_pSkins->Get(m_aClients[ClientID].m_SkinID)->m_ColorTexture; else { m_aClients[ClientID].m_SkinInfo.m_Texture = g_GameClient.m_pSkins->Get(m_aClients[ClientID].m_SkinID)->m_OrgTexture; m_aClients[ClientID].m_SkinInfo.m_ColorBody = vec4(1,1,1,1); m_aClients[ClientID].m_SkinInfo.m_ColorFeet = vec4(1,1,1,1); } m_aClients[ClientID].UpdateRenderInfo(); } else if(Item.m_Type == NETOBJTYPE_PLAYERINFO) { const CNetObj_PlayerInfo *pInfo = (const CNetObj_PlayerInfo *)pData; m_aClients[pInfo->m_ClientID].m_Team = pInfo->m_Team; m_aClients[pInfo->m_ClientID].m_Active = true; m_Snap.m_paPlayerInfos[pInfo->m_ClientID] = pInfo; m_Snap.m_NumPlayers++; if(pInfo->m_Local) { m_Snap.m_LocalClientID = Item.m_ID; m_Snap.m_pLocalInfo = pInfo; if(pInfo->m_Team == TEAM_SPECTATORS) { m_Snap.m_SpecInfo.m_Active = true; m_Snap.m_SpecInfo.m_SpectatorID = SPEC_FREEVIEW; } } // calculate team-balance if(pInfo->m_Team != TEAM_SPECTATORS) m_Snap.m_aTeamSize[pInfo->m_Team]++; } else if(Item.m_Type == NETOBJTYPE_CHARACTER) { const void *pOld = Client()->SnapFindItem(IClient::SNAP_PREV, NETOBJTYPE_CHARACTER, Item.m_ID); m_Snap.m_aCharacters[Item.m_ID].m_Cur = *((const CNetObj_Character *)pData); if(pOld) { m_Snap.m_aCharacters[Item.m_ID].m_Active = true; m_Snap.m_aCharacters[Item.m_ID].m_Prev = *((const CNetObj_Character *)pOld); if(m_Snap.m_aCharacters[Item.m_ID].m_Prev.m_Tick) Evolve(&m_Snap.m_aCharacters[Item.m_ID].m_Prev, Client()->PrevGameTick()); if(m_Snap.m_aCharacters[Item.m_ID].m_Cur.m_Tick) Evolve(&m_Snap.m_aCharacters[Item.m_ID].m_Cur, Client()->GameTick()); } } else if(Item.m_Type == NETOBJTYPE_SPECTATORINFO) { m_Snap.m_pSpectatorInfo = (const CNetObj_SpectatorInfo *)pData; m_Snap.m_pPrevSpectatorInfo = (const CNetObj_SpectatorInfo *)Client()->SnapFindItem(IClient::SNAP_PREV, NETOBJTYPE_SPECTATORINFO, Item.m_ID); m_Snap.m_SpecInfo.m_SpectatorID = m_Snap.m_pSpectatorInfo->m_SpectatorID; } else if(Item.m_Type == NETOBJTYPE_GAMEINFO) { static bool s_GameOver = 0; m_Snap.m_pGameInfoObj = (const CNetObj_GameInfo *)pData; if(!s_GameOver && m_Snap.m_pGameInfoObj->m_GameStateFlags&GAMESTATEFLAG_GAMEOVER) OnGameOver(); else if(s_GameOver && !(m_Snap.m_pGameInfoObj->m_GameStateFlags&GAMESTATEFLAG_GAMEOVER)) OnStartGame(); s_GameOver = m_Snap.m_pGameInfoObj->m_GameStateFlags&GAMESTATEFLAG_GAMEOVER; } else if(Item.m_Type == NETOBJTYPE_GAMEDATA) { m_Snap.m_pGameDataObj = (const CNetObj_GameData *)pData; m_Snap.m_GameDataSnapID = Item.m_ID; if(m_Snap.m_pGameDataObj->m_FlagCarrierRed == FLAG_TAKEN) { if(m_FlagDropTick[TEAM_RED] == 0) m_FlagDropTick[TEAM_RED] = Client()->GameTick(); } else if(m_FlagDropTick[TEAM_RED] != 0) m_FlagDropTick[TEAM_RED] = 0; if(m_Snap.m_pGameDataObj->m_FlagCarrierBlue == FLAG_TAKEN) { if(m_FlagDropTick[TEAM_BLUE] == 0) m_FlagDropTick[TEAM_BLUE] = Client()->GameTick(); } else if(m_FlagDropTick[TEAM_BLUE] != 0) m_FlagDropTick[TEAM_BLUE] = 0; } else if(Item.m_Type == NETOBJTYPE_FLAG) m_Snap.m_paFlags[Item.m_ID%2] = (const CNetObj_Flag *)pData; } } // setup local pointers if(m_Snap.m_LocalClientID >= 0) { CSnapState::CCharacterInfo *c = &m_Snap.m_aCharacters[m_Snap.m_LocalClientID]; if(c->m_Active) { m_Snap.m_pLocalCharacter = &c->m_Cur; m_Snap.m_pLocalPrevCharacter = &c->m_Prev; m_LocalCharacterPos = vec2(m_Snap.m_pLocalCharacter->m_X, m_Snap.m_pLocalCharacter->m_Y); } else if(Client()->SnapFindItem(IClient::SNAP_PREV, NETOBJTYPE_CHARACTER, m_Snap.m_LocalClientID)) { // player died m_pControls->OnPlayerDeath(); } } else { m_Snap.m_SpecInfo.m_Active = true; if(Client()->State() == IClient::STATE_DEMOPLAYBACK && DemoPlayer()->GetDemoType() == IDemoPlayer::DEMOTYPE_SERVER && m_DemoSpecID != SPEC_FREEVIEW && m_Snap.m_aCharacters[m_DemoSpecID].m_Active) m_Snap.m_SpecInfo.m_SpectatorID = m_DemoSpecID; else m_Snap.m_SpecInfo.m_SpectatorID = SPEC_FREEVIEW; } // clear out unneeded client data for(int i = 0; i < MAX_CLIENTS; ++i) { if(!m_Snap.m_paPlayerInfos[i] && m_aClients[i].m_Active) m_aClients[i].Reset(); } // update friend state for(int i = 0; i < MAX_CLIENTS; ++i) { if(i == m_Snap.m_LocalClientID || !m_Snap.m_paPlayerInfos[i] || !Friends()->IsFriend(m_aClients[i].m_aName, m_aClients[i].m_aClan, true)) m_aClients[i].m_Friend = false; else m_aClients[i].m_Friend = true; } // sort player infos by score mem_copy(m_Snap.m_paInfoByScore, m_Snap.m_paPlayerInfos, sizeof(m_Snap.m_paInfoByScore)); for(int k = 0; k < MAX_CLIENTS-1; k++) // ffs, bubblesort { for(int i = 0; i < MAX_CLIENTS-k-1; i++) { if(m_Snap.m_paInfoByScore[i+1] && (!m_Snap.m_paInfoByScore[i] || m_Snap.m_paInfoByScore[i]->m_Score < m_Snap.m_paInfoByScore[i+1]->m_Score)) { const CNetObj_PlayerInfo *pTmp = m_Snap.m_paInfoByScore[i]; m_Snap.m_paInfoByScore[i] = m_Snap.m_paInfoByScore[i+1]; m_Snap.m_paInfoByScore[i+1] = pTmp; } } } // sort player infos by team int Teams[3] = { TEAM_RED, TEAM_BLUE, TEAM_SPECTATORS }; int Index = 0; for(int Team = 0; Team < 3; ++Team) { for(int i = 0; i < MAX_CLIENTS && Index < MAX_CLIENTS; ++i) { if(m_Snap.m_paPlayerInfos[i] && m_Snap.m_paPlayerInfos[i]->m_Team == Teams[Team]) m_Snap.m_paInfoByTeam[Index++] = m_Snap.m_paPlayerInfos[i]; } } CTuningParams StandardTuning; CServerInfo CurrentServerInfo; Client()->GetServerInfo(&CurrentServerInfo); if(CurrentServerInfo.m_aGameType[0] != '0') { if(str_comp(CurrentServerInfo.m_aGameType, "DM") != 0 && str_comp(CurrentServerInfo.m_aGameType, "TDM") != 0 && str_comp(CurrentServerInfo.m_aGameType, "CTF") != 0) m_ServerMode = SERVERMODE_MOD; else if(mem_comp(&StandardTuning, &m_Tuning, sizeof(CTuningParams)) == 0) m_ServerMode = SERVERMODE_PURE; else m_ServerMode = SERVERMODE_PUREMOD; } // add tuning to demo if(DemoRecorder()->IsRecording() && mem_comp(&StandardTuning, &m_Tuning, sizeof(CTuningParams)) != 0) { CMsgPacker Msg(NETMSGTYPE_SV_TUNEPARAMS); int *pParams = (int *)&m_Tuning; for(unsigned i = 0; i < sizeof(m_Tuning)/sizeof(int); i++) Msg.AddInt(pParams[i]); Client()->SendMsg(&Msg, MSGFLAG_RECORD|MSGFLAG_NOSEND); } if(!m_DDRaceMsgSent && m_Snap.m_pLocalInfo) { CNetMsg_Cl_IsDDRace Msg; Client()->SendPackMsg(&Msg, MSGFLAG_VITAL); m_DDRaceMsgSent = true; } if(m_ShowOthers == -1 || (m_ShowOthers != -1 && m_ShowOthers != g_Config.m_ClShowOthers)) { // no need to send, default settings //if(!(m_ShowOthers == -1 && g_Config.m_ClShowOthers)) { CNetMsg_Cl_ShowOthers Msg; Msg.m_Show = g_Config.m_ClShowOthers; Client()->SendPackMsg(&Msg, MSGFLAG_VITAL); } // update state m_ShowOthers = g_Config.m_ClShowOthers; } }
void Grid::Loop( ) { CubeReader cr; std::vector< std::string > vOutput = stack.getCube(); cubeUnedited = vOutput; cube = cr( vOutput ); Fetcher f( cube ); for ( auto& x : cube ) { size_t c = x.find( ";" ); x.erase( c, std::string::npos ); std::cout << x << std::endl; } //gp.setCube( stack.getCube() ); gp.setCube( cube ); std::vector< std::string > vst; for ( int i = 0; i < ppl.vTexts.size(); i++ ) alldecks.push_back( vst ); while (rWin.isOpen()) { sf::Event event; while (rWin.pollEvent(event)) { if (event.type == sf::Event::Closed) { rWin.close();isRunning=0; exit(0); } } if (!End) { gp.getimgs( ); checkRow(); for (int i = 0; i < gp.vRects.size(); i++) { if ( gp.vRects[i].contains ( sf::Mouse::getPosition( rWin ) ) && !sf::Keyboard::isKeyPressed( sf::Keyboard::LAlt ) && stack.whosTurn == stack.ID ) { std::vector<int> Ints; //d::cout << i ; Ints = Friends(i,0); for (int j = 0; j < Ints.size(); j++) { gp.vShapes[ Ints[ j ] ].setFillColor(sf::Color::Red); } if ( sf::Keyboard::isKeyPressed( sf::Keyboard::LControl ) ) { std::cout << std::endl << gp.cube[ i ] << std::endl; } if ( sf::Keyboard::isKeyPressed(sf::Keyboard::Space) && shootclock.getElapsedTime().asSeconds() > 0.5 ) { preShoot(Ints);break; } if (i == 8 || i == 7 || i == 6) break; i = Ints.back() + 1; } gp.vShapes[i].setFillColor(sf::Color(255,255,255,255)); } for (int i = 0; i < gp.vRects.size(); i++) { if ( gp.vRects[i].contains( sf::Mouse::getPosition( rWin ) ) && sf::Keyboard::isKeyPressed( sf::Keyboard::LAlt ) && stack.whosTurn == stack.ID ) { std::vector<int> Ints; Ints = Friends(i,1); for (int j = 0; j < Ints.size(); j++) { gp.vShapes[ Ints[ j ] ].setFillColor(sf::Color::Red); } if (sf::Keyboard::isKeyPressed(sf::Keyboard::Space)) { preShoot(Ints);break; } if (sf::Keyboard::isKeyPressed(sf::Keyboard::LControl)) { for (int ii = 0; ii < Ints.size(); ii++) { ///std::cout << rCards[Ints.at(ii)].Name << std::endl; } } i = Ints.back() + 1; } //gp.vShapes[i].setFillColor(sf::Color(255,255,255,255)); } if (sf::Mouse::isButtonPressed(sf::Mouse::Middle) || sf::Keyboard::isKeyPressed(sf::Keyboard::Z)) { for (int i = 0; i < gp.vRects.size(); i++) { if ( gp.vRects[ i ].contains( sf::Mouse::getPosition( rWin ) ) ) { zoom.setTexture( gp.vShapes[ i ].getTexture(), true ); zoom.setSize(sf::Vector2f(500,700)); zoomclock.restart(); } } } } rWin.clear( ); //if (zoomclock.getElapsedTime().asSeconds() < 0.02)rWin.draw(zoom); if ( !End ) { for ( auto x : gp.vShapes ) rWin.draw( x ); for ( auto x : gp.vTexts ) rWin.draw( x ); //rWin.draw( gp.) ppl.draw( rWin ); if (zoomclock.getElapsedTime().asSeconds() < 0.02)rWin.draw(zoom); } if ( End ) rWin.draw( txtEnd ); rWin.display(); } }
void Grid::GridLoop(){ ResizeSprites(25); while (isRunning) { sf::Texture r1; r1.loadFromFile("img/" + rCards[3].Name + ".jpg"); sf::RectangleShape rr;rr.setTexture(&rCards[3].CardTexture); //rr.setSize(sf::Vector2f(59,50)); //rr.setFillColor(sf::Color::Red); sf::Event event; while (rWin.pollEvent(event)) { if (event.type == sf::Event::Closed) {rWin.close();isRunning=0;} if (event.type == sf::Event::TextEntered && chat.isWriting) { if (event.text.unicode < 128) if (!sf::Keyboard::isKeyPressed(sf::Keyboard::BackSpace)) chat.strFocus.push_back(static_cast<wchar_t>(event.text.unicode)); else if (chat.strFocus.size() > 0) chat.strFocus.erase(chat.strFocus.size() - 1,1); ; } if (sf::Keyboard::isKeyPressed(sf::Keyboard::Escape) && chat.isWriting) { chat.Escaped(); } if (sf::Keyboard::isKeyPressed(sf::Keyboard::Return) && chat.isWriting) { chat.Escaped(); } rWin.clear(sf::Color::Black); for (int i = 0; i < 9; i++) { ///rWin.draw(rCards[i].CardSprite); rWin.draw(rCards[i].Shape); } for (int i = 0; i < iRect.size(); i++) { if (iRect[i].contains(sf::Mouse::getPosition(rWin)) && !sf::Keyboard::isKeyPressed(sf::Keyboard::LAlt) && !chat.isWriting) { std::vector<int> Ints; Ints = Friends(i,0); for (int j = 0; j < Ints.size(); j++) { rCards[Ints[j]].Shape.setFillColor(sf::Color::Red); } if (sf::Keyboard::isKeyPressed(sf::Keyboard::Space)) {Shoot(Ints);break;} if (sf::Keyboard::isKeyPressed(sf::Keyboard::LControl)) { for (int ii = 0; ii < Ints.size(); ii++) { std::cout << rCards[Ints.at(ii)].Name << std::endl; } } i = Ints.back() + 1; } rCards[i].Shape.setFillColor(sf::Color(255,255,255,255)); } for (int i = 0; i < iRect.size(); i++){ if (iRect[i].contains(sf::Mouse::getPosition(rWin)) && sf::Keyboard::isKeyPressed(sf::Keyboard::LAlt) && !chat.isWriting) { std::vector<int> Ints; Ints = Friends(i,1); for (int j = 0; j < Ints.size(); j++) { rCards[Ints[j]].Shape.setFillColor(sf::Color::Red); } if (sf::Keyboard::isKeyPressed(sf::Keyboard::Space)) Shoot(Ints); if (sf::Keyboard::isKeyPressed(sf::Keyboard::LControl)) { for (int ii = 0; ii < Ints.size(); ii++) { std::cout << rCards[Ints.at(ii)].Name << std::endl; } } i = Ints.back() + 1; } //rCards[i].Shape.setFillColor(sf::Color(255,255,255,255)); } if (sf::Mouse::isButtonPressed(sf::Mouse::Left)) { } if (sf::Keyboard::isKeyPressed(sf::Keyboard::P) && sf::Keyboard::isKeyPressed(sf::Keyboard::LAlt)) { for (auto i : plr.Cards) std::cout << i << std::endl; } rWin.draw(rr); srv.Loop(); chat.Loop(); rWin.display(); }}}
void CGameClient::OnMessage(int MsgId, CUnpacker *pUnpacker) { Client()->RecordGameMessage(true); // special messages if(MsgId == NETMSGTYPE_SV_TUNEPARAMS && Client()->State() != IClient::STATE_DEMOPLAYBACK) { Client()->RecordGameMessage(false); // unpack the new tuning CTuningParams NewTuning; int *pParams = (int *)&NewTuning; for(unsigned i = 0; i < sizeof(CTuningParams)/sizeof(int); i++) pParams[i] = pUnpacker->GetInt(); // check for unpacking errors if(pUnpacker->Error()) return; m_ServerMode = SERVERMODE_PURE; // apply new tuning m_Tuning = NewTuning; return; } else if(MsgId == NETMSGTYPE_SV_VOTEOPTIONLISTADD) { int NumOptions = pUnpacker->GetInt(); for(int i = 0; i < NumOptions; i++) { const char *pDescription = pUnpacker->GetString(CUnpacker::SANITIZE_CC); if(pUnpacker->Error()) return; m_pVoting->AddOption(pDescription); } } else if(MsgId == NETMSGTYPE_SV_GAMEMSG) { int GameMsgID = pUnpacker->GetInt(); int aParaI[3]; int NumParaI = 0; // get paras switch(gs_GameMsgList[GameMsgID].m_ParaType) { case PARA_III: aParaI[NumParaI++] = pUnpacker->GetInt(); case PARA_II: aParaI[NumParaI++] = pUnpacker->GetInt(); case PARA_I: aParaI[NumParaI++] = pUnpacker->GetInt(); } // check for unpacking errors if(pUnpacker->Error()) return; // handle special messages static char aBuf[256]; if(gs_GameMsgList[GameMsgID].m_Action == DO_SPECIAL) { switch(GameMsgID) { case GAMEMSG_CTF_DROP: if(m_SuppressEvents) return; m_pSounds->Enqueue(CSounds::CHN_GLOBAL, SOUND_CTF_DROP); break; case GAMEMSG_CTF_RETURN: if(m_SuppressEvents) return; m_pSounds->Enqueue(CSounds::CHN_GLOBAL, SOUND_CTF_RETURN); break; case GAMEMSG_TEAM_BALANCE_VICTIM: str_format(aBuf, sizeof(aBuf), Localize(gs_GameMsgList[GameMsgID].m_pText), GetTeamName(aParaI[0], m_GameInfo.m_GameFlags&GAMEFLAG_TEAMS)); m_pBroadcast->DoBroadcast(aBuf); break; case GAMEMSG_CTF_GRAB: if(m_SuppressEvents) return; if(m_LocalClientID != -1 && (m_aClients[m_LocalClientID].m_Team != aParaI[0] || (m_Snap.m_SpecInfo.m_Active && ((m_Snap.m_SpecInfo.m_SpectatorID != -1 && m_aClients[m_Snap.m_SpecInfo.m_SpectatorID].m_Team != aParaI[0]) || (m_Snap.m_SpecInfo.m_SpecMode == SPEC_FLAGRED && aParaI[0] != TEAM_RED) || (m_Snap.m_SpecInfo.m_SpecMode == SPEC_FLAGBLUE && aParaI[0] != TEAM_BLUE))))) m_pSounds->Enqueue(CSounds::CHN_GLOBAL, SOUND_CTF_GRAB_PL); else m_pSounds->Enqueue(CSounds::CHN_GLOBAL, SOUND_CTF_GRAB_EN); break; case GAMEMSG_CTF_CAPTURE: m_pSounds->Enqueue(CSounds::CHN_GLOBAL, SOUND_CTF_CAPTURE); int ClientID = clamp(aParaI[1], 0, MAX_CLIENTS - 1); if(aParaI[2] <= 60*Client()->GameTickSpeed()) str_format(aBuf, sizeof(aBuf), Localize("The %s flag was captured by '%2d: %s' (%.2f seconds)"), aParaI[0] ? Localize("blue") : Localize("red"), ClientID, g_Config.m_ClShowsocial ? m_aClients[ClientID].m_aName : "", aParaI[2]/(float)Client()->GameTickSpeed()); else str_format(aBuf, sizeof(aBuf), Localize("The %s flag was captured by '%2d: %s'"), aParaI[0] ? Localize("blue") : Localize("red"), ClientID, g_Config.m_ClShowsocial ? m_aClients[ClientID].m_aName : ""); m_pChat->AddLine(-1, 0, aBuf); } return; } // build message const char *pText = ""; if(NumParaI == 0) pText = Localize(gs_GameMsgList[GameMsgID].m_pText); else { if(NumParaI == 1) str_format(aBuf, sizeof(aBuf), Localize(gs_GameMsgList[GameMsgID].m_pText), aParaI[0]); else if(NumParaI == 2) str_format(aBuf, sizeof(aBuf), Localize(gs_GameMsgList[GameMsgID].m_pText), aParaI[0], aParaI[1]); else if(NumParaI == 3) str_format(aBuf, sizeof(aBuf), Localize(gs_GameMsgList[GameMsgID].m_pText), aParaI[0], aParaI[1], aParaI[2]); pText = aBuf; } // handle message switch(gs_GameMsgList[GameMsgID].m_Action) { case DO_CHAT: m_pChat->AddLine(-1, 0, pText); break; case DO_BROADCAST: m_pBroadcast->DoBroadcast(pText); } } void *pRawMsg = m_NetObjHandler.SecureUnpackMsg(MsgId, pUnpacker); if(!pRawMsg) { char aBuf[256]; str_format(aBuf, sizeof(aBuf), "dropped weird message '%s' (%d), failed on '%s'", m_NetObjHandler.GetMsgName(MsgId), MsgId, m_NetObjHandler.FailedMsgOn()); Console()->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "client", aBuf); return; } // TODO: this should be done smarter for(int i = 0; i < m_All.m_Num; i++) m_All.m_paComponents[i]->OnMessage(MsgId, pRawMsg); if(MsgId == NETMSGTYPE_SV_CLIENTINFO && Client()->State() != IClient::STATE_DEMOPLAYBACK) { Client()->RecordGameMessage(false); CNetMsg_Sv_ClientInfo *pMsg = (CNetMsg_Sv_ClientInfo *)pRawMsg; if(pMsg->m_Local) { if(m_LocalClientID != -1) { if(g_Config.m_Debug) Console()->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "client", "invalid local clientinfo"); return; } m_LocalClientID = pMsg->m_ClientID; } else { if(m_aClients[pMsg->m_ClientID].m_Active) { if(g_Config.m_Debug) Console()->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "client", "invalid clientinfo"); return; } if(m_LocalClientID != -1) { DoEnterMessage(pMsg->m_pName, pMsg->m_ClientID, pMsg->m_Team); if(m_pDemoRecorder->IsRecording()) { CNetMsg_De_ClientEnter Msg; Msg.m_pName = pMsg->m_pName; Msg.m_ClientID = pMsg->m_ClientID; Msg.m_Team = pMsg->m_Team; Client()->SendPackMsg(&Msg, MSGFLAG_NOSEND|MSGFLAG_RECORD); } } } m_aClients[pMsg->m_ClientID].m_Active = true; m_aClients[pMsg->m_ClientID].m_Team = pMsg->m_Team; str_copy(m_aClients[pMsg->m_ClientID].m_aName, pMsg->m_pName, sizeof(m_aClients[pMsg->m_ClientID].m_aName)); str_copy(m_aClients[pMsg->m_ClientID].m_aClan, pMsg->m_pClan, sizeof(m_aClients[pMsg->m_ClientID].m_aClan)); m_aClients[pMsg->m_ClientID].m_Country = pMsg->m_Country; for(int i = 0; i < 6; i++) { str_copy(m_aClients[pMsg->m_ClientID].m_aaSkinPartNames[i], pMsg->m_apSkinPartNames[i], 24); m_aClients[pMsg->m_ClientID].m_aUseCustomColors[i] = pMsg->m_aUseCustomColors[i]; m_aClients[pMsg->m_ClientID].m_aSkinPartColors[i] = pMsg->m_aSkinPartColors[i]; } // update friend state m_aClients[pMsg->m_ClientID].m_Friend = Friends()->IsFriend(m_aClients[pMsg->m_ClientID].m_aName, m_aClients[pMsg->m_ClientID].m_aClan, true); m_aClients[pMsg->m_ClientID].UpdateRenderInfo(this, true); m_GameInfo.m_NumPlayers++; // calculate team-balance if(m_aClients[pMsg->m_ClientID].m_Team != TEAM_SPECTATORS) m_GameInfo.m_aTeamSize[m_aClients[pMsg->m_ClientID].m_Team]++; } else if(MsgId == NETMSGTYPE_SV_CLIENTDROP && Client()->State() != IClient::STATE_DEMOPLAYBACK) { Client()->RecordGameMessage(false); CNetMsg_Sv_ClientDrop *pMsg = (CNetMsg_Sv_ClientDrop *)pRawMsg; if(m_LocalClientID == pMsg->m_ClientID || !m_aClients[pMsg->m_ClientID].m_Active) { if(g_Config.m_Debug) Console()->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "client", "invalid clientdrop"); return; } DoLeaveMessage(m_aClients[pMsg->m_ClientID].m_aName, pMsg->m_ClientID, pMsg->m_pReason); CNetMsg_De_ClientLeave Msg; Msg.m_pName = m_aClients[pMsg->m_ClientID].m_aName; Msg.m_ClientID = pMsg->m_ClientID; Msg.m_pReason = pMsg->m_pReason; Client()->SendPackMsg(&Msg, MSGFLAG_NOSEND|MSGFLAG_RECORD); m_GameInfo.m_NumPlayers--; // calculate team-balance if(m_aClients[pMsg->m_ClientID].m_Team != TEAM_SPECTATORS) m_GameInfo.m_aTeamSize[m_aClients[pMsg->m_ClientID].m_Team]--; m_aClients[pMsg->m_ClientID].Reset(this); } else if(MsgId == NETMSGTYPE_SV_GAMEINFO && Client()->State() != IClient::STATE_DEMOPLAYBACK) { Client()->RecordGameMessage(false); CNetMsg_Sv_GameInfo *pMsg = (CNetMsg_Sv_GameInfo *)pRawMsg; m_GameInfo.m_GameFlags = pMsg->m_GameFlags; m_GameInfo.m_ScoreLimit = pMsg->m_ScoreLimit; m_GameInfo.m_TimeLimit = pMsg->m_TimeLimit; m_GameInfo.m_MatchNum = pMsg->m_MatchNum; m_GameInfo.m_MatchCurrent = pMsg->m_MatchCurrent; } else if(MsgId == NETMSGTYPE_SV_SERVERSETTINGS && Client()->State() != IClient::STATE_DEMOPLAYBACK) { Client()->RecordGameMessage(false); CNetMsg_Sv_ServerSettings *pMsg = (CNetMsg_Sv_ServerSettings *)pRawMsg; if(!m_ServerSettings.m_TeamLock && pMsg->m_TeamLock) m_pChat->AddLine(-1, 0, Localize("Teams were locked")); else if(m_ServerSettings.m_TeamLock && !pMsg->m_TeamLock) m_pChat->AddLine(-1, 0, Localize("Teams were unlocked")); m_ServerSettings.m_KickVote = pMsg->m_KickVote; m_ServerSettings.m_KickMin = pMsg->m_KickMin; m_ServerSettings.m_SpecVote = pMsg->m_SpecVote; m_ServerSettings.m_TeamLock = pMsg->m_TeamLock; m_ServerSettings.m_TeamBalance = pMsg->m_TeamBalance; m_ServerSettings.m_PlayerSlots = pMsg->m_PlayerSlots; } else if(MsgId == NETMSGTYPE_SV_TEAM) { CNetMsg_Sv_Team *pMsg = (CNetMsg_Sv_Team *)pRawMsg; if(Client()->State() != IClient::STATE_DEMOPLAYBACK) { // calculate team-balance if(m_aClients[pMsg->m_ClientID].m_Team != TEAM_SPECTATORS) m_GameInfo.m_aTeamSize[m_aClients[pMsg->m_ClientID].m_Team]--; m_aClients[pMsg->m_ClientID].m_Team = pMsg->m_Team; if(m_aClients[pMsg->m_ClientID].m_Team != TEAM_SPECTATORS) m_GameInfo.m_aTeamSize[m_aClients[pMsg->m_ClientID].m_Team]++; m_aClients[pMsg->m_ClientID].UpdateRenderInfo(this, false); if(pMsg->m_ClientID == m_LocalClientID) m_TeamCooldownTick = pMsg->m_CooldownTick; } if(pMsg->m_Silent == 0) { DoTeamChangeMessage(m_aClients[pMsg->m_ClientID].m_aName, pMsg->m_ClientID, pMsg->m_Team); } } else if(MsgId == NETMSGTYPE_SV_READYTOENTER) { Client()->EnterGame(); } else if (MsgId == NETMSGTYPE_SV_EMOTICON) { CNetMsg_Sv_Emoticon *pMsg = (CNetMsg_Sv_Emoticon *)pRawMsg; // apply m_aClients[pMsg->m_ClientID].m_Emoticon = pMsg->m_Emoticon; m_aClients[pMsg->m_ClientID].m_EmoticonStart = Client()->GameTick(); } else if(MsgId == NETMSGTYPE_DE_CLIENTENTER && Client()->State() == IClient::STATE_DEMOPLAYBACK) { CNetMsg_De_ClientEnter *pMsg = (CNetMsg_De_ClientEnter *)pRawMsg; DoEnterMessage(pMsg->m_pName, pMsg->m_ClientID, pMsg->m_Team); } else if(MsgId == NETMSGTYPE_DE_CLIENTLEAVE && Client()->State() == IClient::STATE_DEMOPLAYBACK) { CNetMsg_De_ClientLeave *pMsg = (CNetMsg_De_ClientLeave *)pRawMsg; DoLeaveMessage(pMsg->m_pName, pMsg->m_ClientID, pMsg->m_pReason); } }
void TestFriends() { int r[5][2] = {{1,2},{2,3},{4,5},{1,3},{2,4}}; cout<<"N个朋友圈?"<<Friends(5, 5, r)<<endl; }