MCPcopy Create free account
hub / github.com/ddnet/ddnet / OnNetMsgRconAuth

Method OnNetMsgRconAuth

src/engine/server/server.cpp:2064–2158  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2062}
2063
2064void CServer::OnNetMsgRconAuth(int ClientId, const char *pName, const char *pPw, bool SendRconCmds)
2065{
2066 int AuthLevel = -1;
2067 int KeySlot = -1;
2068
2069 if(!pName[0])
2070 {
2071 if(m_AuthManager.CheckKey((KeySlot = m_AuthManager.DefaultKey(RoleName::ADMIN)), pPw))
2072 AuthLevel = AUTHED_ADMIN;
2073 else if(m_AuthManager.CheckKey((KeySlot = m_AuthManager.DefaultKey(RoleName::MODERATOR)), pPw))
2074 AuthLevel = AUTHED_MOD;
2075 else if(m_AuthManager.CheckKey((KeySlot = m_AuthManager.DefaultKey(RoleName::HELPER)), pPw))
2076 AuthLevel = AUTHED_HELPER;
2077 }
2078 else
2079 {
2080 KeySlot = m_AuthManager.FindKey(pName);
2081 if(m_AuthManager.CheckKey(KeySlot, pPw))
2082 AuthLevel = m_AuthManager.KeyLevel(KeySlot);
2083 }
2084
2085 if(AuthLevel != -1)
2086 {
2087 if(GetAuthedState(ClientId) != AuthLevel)
2088 {
2089 if(!IsSixup(ClientId))
2090 {
2091 CMsgPacker Msgp(NETMSG_RCON_AUTH_STATUS, true);
2092 Msgp.AddInt(1); //authed
2093 Msgp.AddInt(1); //cmdlist
2094 SendMsg(&Msgp, MSGFLAG_VITAL, ClientId);
2095 }
2096 else
2097 {
2098 CMsgPacker Msgp(protocol7::NETMSG_RCON_AUTH_ON, true, true);
2099 SendMsg(&Msgp, MSGFLAG_VITAL, ClientId);
2100 }
2101
2102 m_aClients[ClientId].m_AuthKey = KeySlot;
2103 if(SendRconCmds)
2104 {
2105 m_aClients[ClientId].m_pRconCmdToSend = Console()->FirstCommandInfo(ClientId, CFGFLAG_SERVER);
2106 SendRconCmdGroupStart(ClientId);
2107 if(m_aClients[ClientId].m_pRconCmdToSend == nullptr)
2108 {
2109 SendRconCmdGroupEnd(ClientId);
2110 }
2111 }
2112
2113 const char *pIdent = m_AuthManager.KeyIdent(KeySlot);
2114 switch(AuthLevel)
2115 {
2116 case AUTHED_ADMIN:
2117 {
2118 SendRconLine(ClientId, "Admin authentication successful. Full remote console access granted.");
2119 log_info("server", "ClientId=%d authed with key='%s' (admin)", ClientId, pIdent);
2120 break;
2121 }

Callers

nothing calls this directly

Calls 12

str_formatFunction · 0.85
CheckKeyMethod · 0.80
DefaultKeyMethod · 0.80
FindKeyMethod · 0.80
KeyLevelMethod · 0.80
AddIntMethod · 0.80
FirstCommandInfoMethod · 0.80
KeyIdentMethod · 0.80
OnSetAuthedMethod · 0.80
ConfigFunction · 0.50
DropMethod · 0.45
BanAddrMethod · 0.45

Tested by

no test coverage detected