MCPcopy Create free account
hub / github.com/cppla/ServerStatus / Update

Method Update

server/src/server.cpp:82–179  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

80}
81
82void CServer::Update()
83{
84 if(!m_Ready)
85 return;
86
87 m_NetBan.Update();
88 m_Network.Update();
89
90 char aBuf[NET_MAX_PACKETSIZE];
91 int ClientID;
92
93 while(m_Network.Recv(aBuf, (int)(sizeof(aBuf))-1, &ClientID))
94 {
95 dbg_assert(m_aClients[ClientID].m_State != CClient::STATE_EMPTY, "Got message from empty slot.");
96 if(m_aClients[ClientID].m_State == CClient::STATE_CONNECTED)
97 {
98 int ID = -1;
99 char aUsername[128] = {0};
100 char aPassword[128] = {0};
101 const char *pTmp;
102
103 if(!(pTmp = str_find(aBuf, ":"))
104 || (unsigned)(pTmp - aBuf) > sizeof(aUsername) || (unsigned)(str_length(pTmp) - 1) > sizeof(aPassword))
105 {
106 m_Network.NetBan()->BanAddr(m_Network.ClientAddr(ClientID), 60, "You're an idiot, go away.");
107 m_Network.Drop(ClientID, "Fuck off.");
108 return;
109 }
110
111 str_copy(aUsername, aBuf, pTmp - aBuf + 1);
112 str_copy(aPassword, pTmp + 1, sizeof(aPassword));
113 if(!*aUsername || !*aPassword)
114 {
115 m_Network.NetBan()->BanAddr(m_Network.ClientAddr(ClientID), 60, "You're an idiot, go away.");
116 m_Network.Drop(ClientID, "Username and password must not be blank.");
117 return;
118 }
119
120 for(int i = 0; i < NET_MAX_CLIENTS; i++)
121 {
122 if(!Main()->Client(i)->m_Active)
123 continue;
124
125 if(str_comp(Main()->Client(i)->m_aUsername, aUsername) == 0 && str_comp(Main()->Client(i)->m_aPassword, aPassword) == 0)
126 ID = i;
127 }
128
129 if(ID == -1)
130 {
131 m_Network.NetBan()->BanAddr(m_Network.ClientAddr(ClientID), 60, "Wrong username and/or password.");
132 m_Network.Drop(ClientID, "Wrong username and/or password.");
133 }
134 else if(Main()->Client(ID)->m_ClientNetID != -1)
135 {
136 m_Network.Drop(ClientID, "Only one connection per user allowed.");
137 }
138 else
139 {

Callers

nothing calls this directly

Calls 15

str_findFunction · 0.85
str_lengthFunction · 0.85
str_copyFunction · 0.85
str_compFunction · 0.85
time_getFunction · 0.85
dbg_msgFunction · 0.85
time_freqFunction · 0.85
BanAddrMethod · 0.80
ClientAddrMethod · 0.80
DropMethod · 0.80
ClientMethod · 0.80
ConfigMethod · 0.80

Tested by

no test coverage detected