mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-19 22:48:18 +00:00
cleaned up updating the friend state
This commit is contained in:
parent
8971497029
commit
b1d28c5740
|
@ -2355,11 +2355,11 @@ int main(int argc, const char **argv) // ignore_convention
|
||||||
// register all console commands
|
// register all console commands
|
||||||
pClient->RegisterCommands();
|
pClient->RegisterCommands();
|
||||||
|
|
||||||
pKernel->RequestInterface<IGameClient>()->OnConsoleInit();
|
|
||||||
|
|
||||||
// init client's interfaces
|
// init client's interfaces
|
||||||
pClient->InitInterfaces();
|
pClient->InitInterfaces();
|
||||||
|
|
||||||
|
pKernel->RequestInterface<IGameClient>()->OnConsoleInit();
|
||||||
|
|
||||||
// execute config file
|
// execute config file
|
||||||
pConsole->ExecuteFile("settings.cfg");
|
pConsole->ExecuteFile("settings.cfg");
|
||||||
|
|
||||||
|
|
|
@ -37,7 +37,7 @@ void CFriends::Init()
|
||||||
if(pConsole)
|
if(pConsole)
|
||||||
{
|
{
|
||||||
pConsole->Register("add_friend", "ss", CFGFLAG_CLIENT, ConAddFriend, this, "Add a friend");
|
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");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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);
|
m_pClient->Friends()->RemoveFriend(m_pClient->m_aClients[Index].m_aName, m_pClient->m_aClients[Index].m_aClan);
|
||||||
else
|
else
|
||||||
m_pClient->Friends()->AddFriend(m_pClient->m_aClients[Index].m_aName, m_pClient->m_aClients[Index].m_aClan);
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -193,6 +193,8 @@ void CGameClient::OnConsoleInit()
|
||||||
Console()->Register("kill", "", CFGFLAG_CLIENT, ConKill, this, "Kill yourself");
|
Console()->Register("kill", "", CFGFLAG_CLIENT, ConKill, this, "Kill yourself");
|
||||||
Console()->Register("ready_change", "", CFGFLAG_CLIENT, ConReadyChange, this, "Change ready state");
|
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++)
|
for(int i = 0; i < m_All.m_Num; i++)
|
||||||
m_All.m_paComponents[i]->m_pClient = this;
|
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];
|
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);
|
m_aClients[pMsg->m_ClientID].UpdateRenderInfo(true);
|
||||||
}
|
}
|
||||||
|
@ -896,15 +900,6 @@ void CGameClient::OnNewSnapshot()
|
||||||
m_Snap.m_SpecInfo.m_SpectatorID = SPEC_FREEVIEW;
|
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
|
// sort player infos by score
|
||||||
for(int k = 0; k < MAX_CLIENTS-1; k++) // ffs, bubblesort
|
for(int k = 0; k < MAX_CLIENTS-1; k++) // ffs, bubblesort
|
||||||
{
|
{
|
||||||
|
@ -1185,6 +1180,7 @@ void CGameClient::CClientData::Reset()
|
||||||
m_EmoticonStart = -1;
|
m_EmoticonStart = -1;
|
||||||
m_Active = false;
|
m_Active = false;
|
||||||
m_ChatIgnore = false;
|
m_ChatIgnore = false;
|
||||||
|
m_Friend = false;
|
||||||
for(int p = 0; p < NUM_SKINPARTS; p++)
|
for(int p = 0; p < NUM_SKINPARTS; p++)
|
||||||
{
|
{
|
||||||
m_SkinPartIDs[p] = 0;
|
m_SkinPartIDs[p] = 0;
|
||||||
|
@ -1243,6 +1239,17 @@ void CGameClient::ConReadyChange(IConsole::IResult *pResult, void *pUserData)
|
||||||
((CGameClient*)pUserData)->SendReadyChange();
|
((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()
|
IGameClient *CreateGameClient()
|
||||||
{
|
{
|
||||||
return &g_GameClient;
|
return &g_GameClient;
|
||||||
|
|
|
@ -59,6 +59,7 @@ class CGameClient : public IGameClient
|
||||||
static void ConTeam(IConsole::IResult *pResult, void *pUserData);
|
static void ConTeam(IConsole::IResult *pResult, void *pUserData);
|
||||||
static void ConKill(IConsole::IResult *pResult, void *pUserData);
|
static void ConKill(IConsole::IResult *pResult, void *pUserData);
|
||||||
static void ConReadyChange(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:
|
public:
|
||||||
IKernel *Kernel() { return IInterface::Kernel(); }
|
IKernel *Kernel() { return IInterface::Kernel(); }
|
||||||
|
|
Loading…
Reference in a new issue