From 548e9969b2a99da3c823772c0adc9e9bb3b8bcf4 Mon Sep 17 00:00:00 2001 From: Learath Date: Sat, 2 Mar 2019 13:50:33 +0300 Subject: [PATCH] Add colors for authed players. Deprecates #1299 --- datasrc/network.py | 12 ++++++++++++ src/engine/server.h | 8 +------- src/engine/server/server.cpp | 18 +++++++++--------- src/game/client/components/scoreboard.cpp | 21 +++++++++++++++++---- src/game/client/gameclient.cpp | 2 ++ src/game/client/gameclient.h | 6 ++++-- src/game/server/gamecontext.cpp | 4 ++-- src/game/server/gamecontroller.cpp | 2 +- src/game/server/player.cpp | 6 ++++++ src/test/teehistorian.cpp | 6 +++--- 10 files changed, 57 insertions(+), 28 deletions(-) diff --git a/datasrc/network.py b/datasrc/network.py index 95906c468..3177ccb23 100644 --- a/datasrc/network.py +++ b/datasrc/network.py @@ -32,6 +32,14 @@ enum SPEC_FREEVIEW=-1, SPEC_FOLLOW=-2, }; + +enum +{ + AUTHED_NO=0, + AUTHED_HELPER, + AUTHED_MOD, + AUTHED_ADMIN, +}; ''' RawSource = ''' @@ -194,6 +202,10 @@ Objects = [ NetIntAny("m_Test"), ]), + NetObjectEx("AuthInfo", "auth-info@netobj.ddnet.tw", [ + NetIntRange("m_AuthLevel", "AUTHED_NO", "AUTHED_ADMIN"), + ]), + ## Events NetEvent("Common", [ diff --git a/src/engine/server.h b/src/engine/server.h index d2832ba41..2c9c6c0d2 100644 --- a/src/engine/server.h +++ b/src/engine/server.h @@ -153,13 +153,7 @@ public: virtual void SnapSetStaticsize(int ItemType, int Size) = 0; - enum - { - AUTHED_NO=0, - AUTHED_HELPER, - AUTHED_MOD, - AUTHED_ADMIN, - + enum { RCON_CID_SERV=-1, RCON_CID_VOTE=-2, }; diff --git a/src/engine/server/server.cpp b/src/engine/server/server.cpp index 1fc79cf72..b9b7ff571 100644 --- a/src/engine/server/server.cpp +++ b/src/engine/server/server.cpp @@ -176,7 +176,7 @@ int CServerBan::BanExt(T *pBanPool, const typename T::CDataType *pData, int Seco if(Server()->m_aClients[i].m_State == CServer::CClient::STATE_EMPTY) continue; - if(Server()->m_aClients[i].m_Authed != CServer::AUTHED_NO && NetMatch(pData, Server()->m_NetServer.ClientAddr(i))) + if(Server()->m_aClients[i].m_Authed != AUTHED_NO && NetMatch(pData, Server()->m_NetServer.ClientAddr(i))) { Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "net_ban", "ban error (command denied)"); return -1; @@ -2125,7 +2125,7 @@ void CServer::StatusImpl(IConsole::IResult *pResult, void *pUser, bool DnsblBlac char aAddrStr[NETADDR_MAXSTRSIZE]; CServer *pThis = static_cast(pUser); - bool CanSeeAddress = pThis->m_aClients[pResult->m_ClientID].m_Authed > CServer::AUTHED_MOD; + bool CanSeeAddress = pThis->m_aClients[pResult->m_ClientID].m_Authed > AUTHED_MOD; for(int i = 0; i < MAX_CLIENTS; i++) { @@ -2137,9 +2137,9 @@ void CServer::StatusImpl(IConsole::IResult *pResult, void *pUser, bool DnsblBlac net_addr_str(pThis->m_NetServer.ClientAddr(i), aAddrStr, sizeof(aAddrStr), true); if(pThis->m_aClients[i].m_State == CClient::STATE_INGAME) { - const char *pAuthStr = pThis->m_aClients[i].m_Authed == CServer::AUTHED_ADMIN ? "(Admin)" : - pThis->m_aClients[i].m_Authed == CServer::AUTHED_MOD ? "(Mod)" : - pThis->m_aClients[i].m_Authed == CServer::AUTHED_HELPER ? "(Helper)" : ""; + const char *pAuthStr = pThis->m_aClients[i].m_Authed == AUTHED_ADMIN ? "(Admin)" : + pThis->m_aClients[i].m_Authed == AUTHED_MOD ? "(Mod)" : + pThis->m_aClients[i].m_Authed == AUTHED_HELPER ? "(Helper)" : ""; char aAuthStr[128]; aAuthStr[0] = '\0'; if(pThis->m_aClients[i].m_AuthKey >= 0) @@ -2178,11 +2178,11 @@ static int GetAuthLevel(const char *pLevel) { int Level = -1; if(!str_comp_nocase(pLevel, "admin")) - Level = CServer::AUTHED_ADMIN; + Level = AUTHED_ADMIN; else if(!str_comp_nocase_num(pLevel, "mod", 3)) - Level = CServer::AUTHED_MOD; + Level = AUTHED_MOD; else if(!str_comp_nocase(pLevel, "helper")) - Level = CServer::AUTHED_HELPER; + Level = AUTHED_HELPER; return Level; } @@ -3052,7 +3052,7 @@ bool CServer::SetTimedOut(int ClientID, int OrigID) return false; } DelClientCallback(OrigID, "Timeout Protection used", this); - m_aClients[ClientID].m_Authed = IServer::AUTHED_NO; + m_aClients[ClientID].m_Authed = AUTHED_NO; return true; } diff --git a/src/game/client/components/scoreboard.cpp b/src/game/client/components/scoreboard.cpp index cc35ce4a6..daacd9b1d 100644 --- a/src/game/client/components/scoreboard.cpp +++ b/src/game/client/components/scoreboard.cpp @@ -444,13 +444,25 @@ void CScoreboard::RenderScoreboard(float x, float y, float w, int Team, const ch // name TextRender()->SetCursor(&Cursor, NameOffset, y + (LineHeight - FontSize) / 2.f, FontSize, TEXTFLAG_RENDER|TEXTFLAG_STOP_AT_END); + switch(m_pClient->m_aClients[pInfo->m_ClientID].m_AuthLevel) { + case AUTHED_HELPER: + TextRender()->TextColor(0.5f, 0.0f, 0.5f, 1.0f); + break; + case AUTHED_MOD: + TextRender()->TextColor(0.2f, 0.2f, 0.8f, 1.0f); + break; + case AUTHED_ADMIN: + TextRender()->TextColor(0.0f, 1.0f, 0.0f, 1.0f); + break; + case AUTHED_NO: + default: + ; + } + if(g_Config.m_ClShowIDs) { char aId[64] = ""; - if (pInfo->m_ClientID >= 10) - str_format(aId, sizeof(aId),"%d: ", pInfo->m_ClientID); - else - str_format(aId, sizeof(aId)," %d: ", pInfo->m_ClientID); + str_format(aId, sizeof(aId)," %2d: ", pInfo->m_ClientID); str_append(aId, m_pClient->m_aClients[pInfo->m_ClientID].m_aName,sizeof(aId)); Cursor.m_LineWidth = NameLength+8; TextRender()->TextEx(&Cursor, aId, -1); @@ -460,6 +472,7 @@ void CScoreboard::RenderScoreboard(float x, float y, float w, int Team, const ch Cursor.m_LineWidth = NameLength; TextRender()->TextEx(&Cursor, m_pClient->m_aClients[pInfo->m_ClientID].m_aName, -1); } + TextRender()->TextColor(1.0f, 1.0f, 1.0f, 1.0f); // clan tw = TextRender()->TextWidth(0, FontSize, m_pClient->m_aClients[pInfo->m_ClientID].m_aClan, -1); diff --git a/src/game/client/gameclient.cpp b/src/game/client/gameclient.cpp index 7b309c54b..97617dc8e 100644 --- a/src/game/client/gameclient.cpp +++ b/src/game/client/gameclient.cpp @@ -1187,6 +1187,8 @@ void CGameClient::OnNewSnapshot() } else if(Item.m_Type == NETOBJTYPE_FLAG) m_Snap.m_paFlags[Item.m_ID%2] = (const CNetObj_Flag *)pData; + else if(Item.m_Type == NETOBJTYPE_AUTHINFO) + m_aClients[Item.m_ID].m_AuthLevel = ((const CNetObj_AuthInfo *)pData)->m_AuthLevel; } } diff --git a/src/game/client/gameclient.h b/src/game/client/gameclient.h index d0b20ff22..6c0d0ac47 100644 --- a/src/game/client/gameclient.h +++ b/src/game/client/gameclient.h @@ -252,6 +252,8 @@ public: bool m_Friend; bool m_Foe; + int m_AuthLevel; + void UpdateRenderInfo(); void Reset(); @@ -267,7 +269,7 @@ public: int m_IngameTicks; int m_JoinTick; bool m_Active; - + public: CClientStats(); @@ -283,7 +285,7 @@ public: int m_FlagCaptures; void Reset(); - + bool IsActive() const { return m_Active; } void JoinGame(int Tick) { m_Active = true; m_JoinTick = Tick; }; void JoinSpec(int Tick) { m_Active = false; m_IngameTicks += Tick - m_JoinTick; }; diff --git a/src/game/server/gamecontext.cpp b/src/game/server/gamecontext.cpp index c8b65de91..81e3a5d2e 100644 --- a/src/game/server/gamecontext.cpp +++ b/src/game/server/gamecontext.cpp @@ -1333,7 +1333,7 @@ void CGameContext::OnMessage(int MsgID, CUnpacker *pUnpacker, int ClientID) int Authed = Server()->GetAuthedState(ClientID); if(Authed) - Console()->SetAccessLevel(Authed == IServer::AUTHED_ADMIN ? IConsole::ACCESS_LEVEL_ADMIN : Authed == IServer::AUTHED_MOD ? IConsole::ACCESS_LEVEL_MOD : IConsole::ACCESS_LEVEL_HELPER); + Console()->SetAccessLevel(Authed == AUTHED_ADMIN ? IConsole::ACCESS_LEVEL_ADMIN : Authed == AUTHED_MOD ? IConsole::ACCESS_LEVEL_MOD : IConsole::ACCESS_LEVEL_HELPER); else Console()->SetAccessLevel(IConsole::ACCESS_LEVEL_USER); Console()->SetPrintOutputLevel(m_ChatPrintCBIndex, 0); @@ -1479,7 +1479,7 @@ void CGameContext::OnMessage(int MsgID, CUnpacker *pUnpacker, int ClientID) if(!pOption) { - if(Authed != IServer::AUTHED_ADMIN) // allow admins to call any vote they want + if(Authed != AUTHED_ADMIN) // allow admins to call any vote they want { str_format(aChatmsg, sizeof(aChatmsg), "'%s' isn't an option on this server", pMsg->m_Value); SendChatTarget(ClientID, aChatmsg); diff --git a/src/game/server/gamecontroller.cpp b/src/game/server/gamecontroller.cpp index a9e6d2c54..79e247e4d 100644 --- a/src/game/server/gamecontroller.cpp +++ b/src/game/server/gamecontroller.cpp @@ -698,7 +698,7 @@ void IGameController::Tick() break; } #endif - if(GameServer()->m_apPlayers[i] && GameServer()->m_apPlayers[i]->GetTeam() != TEAM_SPECTATORS && Server()->GetAuthedState(i) == IServer::AUTHED_NO) + if(GameServer()->m_apPlayers[i] && GameServer()->m_apPlayers[i]->GetTeam() != TEAM_SPECTATORS && Server()->GetAuthedState(i) == AUTHED_NO) { if(Server()->Tick() > GameServer()->m_apPlayers[i]->m_LastActionTick+g_Config.m_SvInactiveKickTime*Server()->TickSpeed()*60) { diff --git a/src/game/server/player.cpp b/src/game/server/player.cpp index d18024c29..0aa8ce961 100644 --- a/src/game/server/player.cpp +++ b/src/game/server/player.cpp @@ -328,6 +328,12 @@ void CPlayer::Snap(int SnappingClient) pPlayerInfo->m_Score = -9999; else pPlayerInfo->m_Score = abs(m_Score) * -1; + + CNetObj_AuthInfo *pAuthInfo = static_cast(Server()->SnapNewItem(NETOBJTYPE_AUTHINFO, id, sizeof(CNetObj_AuthInfo))); + if(!pAuthInfo) + return; + + pAuthInfo->m_AuthLevel = Server()->GetAuthedState(id); } void CPlayer::FakeSnap() diff --git a/src/test/teehistorian.cpp b/src/test/teehistorian.cpp index 4a2c87d2d..8079eddaa 100644 --- a/src/test/teehistorian.cpp +++ b/src/test/teehistorian.cpp @@ -352,9 +352,9 @@ TEST_F(TeeHistorian, Auth) 0x01, 0x40, // FINISH }; - m_TH.RecordAuthInitial(0, IServer::AUTHED_ADMIN, "default_admin"); - m_TH.RecordAuthLogin(1, IServer::AUTHED_MOD, "foobar"); - m_TH.RecordAuthLogin(2, IServer::AUTHED_HELPER, "help"); + m_TH.RecordAuthInitial(0, AUTHED_ADMIN, "default_admin"); + m_TH.RecordAuthLogin(1, AUTHED_MOD, "foobar"); + m_TH.RecordAuthLogin(2, AUTHED_HELPER, "help"); m_TH.RecordAuthLogout(1); Finish(); Expect(EXPECTED, sizeof(EXPECTED));