| 98 | } |
| 99 | |
| 100 | void CEcon::Update() |
| 101 | { |
| 102 | if(!m_Ready) |
| 103 | return; |
| 104 | |
| 105 | m_NetConsole.Update(); |
| 106 | |
| 107 | char aBuf[NET_MAX_PACKETSIZE]; |
| 108 | int ClientId; |
| 109 | |
| 110 | while(m_NetConsole.Recv(aBuf, (int)(sizeof(aBuf)) - 1, &ClientId)) |
| 111 | { |
| 112 | dbg_assert(m_aClients[ClientId].m_State != CClient::STATE_EMPTY, "got message from empty slot"); |
| 113 | if(m_aClients[ClientId].m_State == CClient::STATE_CONNECTED) |
| 114 | { |
| 115 | if(str_comp(aBuf, g_Config.m_EcPassword) == 0) |
| 116 | { |
| 117 | m_aClients[ClientId].m_State = CClient::STATE_AUTHED; |
| 118 | m_NetConsole.Send(ClientId, "Authentication successful. External console access granted."); |
| 119 | |
| 120 | str_format(aBuf, sizeof(aBuf), "cid=%d authed", ClientId); |
| 121 | Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "econ", aBuf); |
| 122 | } |
| 123 | else |
| 124 | { |
| 125 | m_aClients[ClientId].m_AuthTries++; |
| 126 | char aMsg[128]; |
| 127 | str_format(aMsg, sizeof(aMsg), "Wrong password %d/%d.", m_aClients[ClientId].m_AuthTries, MAX_AUTH_TRIES); |
| 128 | m_NetConsole.Send(ClientId, aMsg); |
| 129 | if(m_aClients[ClientId].m_AuthTries >= MAX_AUTH_TRIES) |
| 130 | { |
| 131 | if(!g_Config.m_EcBantime) |
| 132 | m_NetConsole.Drop(ClientId, "Too many authentication tries"); |
| 133 | else |
| 134 | m_NetConsole.NetBan()->BanAddr(m_NetConsole.ClientAddr(ClientId), g_Config.m_EcBantime * 60, "Too many authentication tries", false); |
| 135 | } |
| 136 | } |
| 137 | } |
| 138 | else if(m_aClients[ClientId].m_State == CClient::STATE_AUTHED) |
| 139 | { |
| 140 | char aFormatted[256]; |
| 141 | str_format(aFormatted, sizeof(aFormatted), "cid=%d cmd='%s'", ClientId, aBuf); |
| 142 | Console()->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "server", aFormatted); |
| 143 | m_UserClientId = ClientId; |
| 144 | Console()->ExecuteLine(aBuf, IConsole::CLIENT_ID_UNSPECIFIED); |
| 145 | m_UserClientId = -1; |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | for(int i = 0; i < NET_MAX_CONSOLE_CLIENTS; ++i) |
| 150 | { |
| 151 | if(m_aClients[i].m_State == CClient::STATE_CONNECTED && |
| 152 | time_get() > m_aClients[i].m_TimeConnected + g_Config.m_EcAuthTimeout * time_freq()) |
| 153 | m_NetConsole.Drop(i, "authentication timeout"); |
| 154 | } |
| 155 | } |
| 156 | |
| 157 | void CEcon::Send(int ClientId, const char *pLine) |
nothing calls this directly
no test coverage detected