cleaned up updating the friend state

This commit is contained in:
oy 2012-08-03 18:46:33 +02:00
parent 8971497029
commit b1d28c5740
5 changed files with 22 additions and 12 deletions

View file

@ -2355,11 +2355,11 @@ int main(int argc, const char **argv) // ignore_convention
// register all console commands
pClient->RegisterCommands();
pKernel->RequestInterface<IGameClient>()->OnConsoleInit();
// init client's interfaces
pClient->InitInterfaces();
pKernel->RequestInterface<IGameClient>()->OnConsoleInit();
// execute config file
pConsole->ExecuteFile("settings.cfg");

View file

@ -37,7 +37,7 @@ void CFriends::Init()
if(pConsole)
{
pConsole->Register("add_friend", "ss", CFGFLAG_CLIENT, ConAddFriend, this, "Add a friend");
pConsole->Register("remove_Friend", "ss", CFGFLAG_CLIENT, ConRemoveFriend, this, "Remove a friend");
pConsole->Register("remove_friend", "ss", CFGFLAG_CLIENT, ConRemoveFriend, this, "Remove a friend");
}
}

View file

@ -196,6 +196,8 @@ void CMenus::RenderPlayers(CUIRect MainView)
m_pClient->Friends()->RemoveFriend(m_pClient->m_aClients[Index].m_aName, m_pClient->m_aClients[Index].m_aClan);
else
m_pClient->Friends()->AddFriend(m_pClient->m_aClients[Index].m_aName, m_pClient->m_aClients[Index].m_aClan);
m_pClient->m_aClients[Index].m_Friend ^= 1;
}
}

View file

@ -193,6 +193,8 @@ void CGameClient::OnConsoleInit()
Console()->Register("kill", "", CFGFLAG_CLIENT, ConKill, this, "Kill yourself");
Console()->Register("ready_change", "", CFGFLAG_CLIENT, ConReadyChange, this, "Change ready state");
Console()->Chain("add_friend", ConchainFriendUpdate, this);
Console()->Chain("remove_friend", ConchainFriendUpdate, this);
for(int i = 0; i < m_All.m_Num; i++)
m_All.m_paComponents[i]->m_pClient = this;
@ -542,6 +544,8 @@ void CGameClient::OnMessage(int MsgId, CUnpacker *pUnpacker)
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(true);
}
@ -896,15 +900,6 @@ void CGameClient::OnNewSnapshot()
m_Snap.m_SpecInfo.m_SpectatorID = SPEC_FREEVIEW;
}
// update friend state
for(int i = 0; i < MAX_CLIENTS; ++i)
{
if(i == 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
for(int k = 0; k < MAX_CLIENTS-1; k++) // ffs, bubblesort
{
@ -1185,6 +1180,7 @@ void CGameClient::CClientData::Reset()
m_EmoticonStart = -1;
m_Active = false;
m_ChatIgnore = false;
m_Friend = false;
for(int p = 0; p < NUM_SKINPARTS; p++)
{
m_SkinPartIDs[p] = 0;
@ -1243,6 +1239,17 @@ void CGameClient::ConReadyChange(IConsole::IResult *pResult, void *pUserData)
((CGameClient*)pUserData)->SendReadyChange();
}
void CGameClient::ConchainFriendUpdate(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData)
{
pfnCallback(pResult, pCallbackUserData);
CGameClient *pClient = static_cast<CGameClient *>(pUserData);
for(int i = 0; i < MAX_CLIENTS; ++i)
{
if(pClient->m_aClients[i].m_Active)
pClient->m_aClients[i].m_Friend = pClient->Friends()->IsFriend(pClient->m_aClients[i].m_aName, pClient->m_aClients[i].m_aClan, true);
}
}
IGameClient *CreateGameClient()
{
return &g_GameClient;

View file

@ -59,6 +59,7 @@ class CGameClient : public IGameClient
static void ConTeam(IConsole::IResult *pResult, void *pUserData);
static void ConKill(IConsole::IResult *pResult, void *pUserData);
static void ConReadyChange(IConsole::IResult *pResult, void *pUserData);
static void ConchainFriendUpdate(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData);
public:
IKernel *Kernel() { return IInterface::Kernel(); }