sources/network/rconsession.cpp

changeset 31
b5b5a6a96d91
parent 29
e534f2f78196
child 32
ee770597a281
equal deleted inserted replaced
30:21fba5183768 31:b5b5a6a96d91
86 // ------------------------------------------------------------------------------------------------- 86 // -------------------------------------------------------------------------------------------------
87 // 87 //
88 METHOD 88 METHOD
89 RCONSession::tick() -> void 89 RCONSession::tick() -> void
90 { 90 {
91 if (m_state == RCON_DISCONNECTED)
92 return;
93
91 time_t now; 94 time_t now;
92 time (&now); 95 time (&now);
93 96
94 if (m_lastPing < now) 97 if (m_lastPing < now)
95 { 98 {
157 case SVRC_MESSAGE: 160 case SVRC_MESSAGE:
158 { 161 {
159 String message = packet.read_string(); 162 String message = packet.read_string();
160 if (message.ends_with ("\n")) 163 if (message.ends_with ("\n"))
161 message.remove_from_end (1); 164 message.remove_from_end (1);
165
162 print ("%1\n", message); 166 print ("%1\n", message);
163 } 167 }
164 break; 168 break;
165 169
166 case SVRC_LOGGEDIN: 170 case SVRC_LOGGEDIN:
172 176
173 for (int i = packet.read_byte(); i > 0; --i) 177 for (int i = packet.read_byte(); i > 0; --i)
174 process_server_updates (packet); 178 process_server_updates (packet);
175 179
176 print ("Previous messages:\n"); 180 print ("Previous messages:\n");
181
177 for (int i = packet.read_byte(); i > 0; --i) 182 for (int i = packet.read_byte(); i > 0; --i)
178 { 183 {
179 String message = packet.read_string(); 184 String message = packet.read_string();
180 message.normalize(); 185 message.normalize();
181 print ("--- %1\n", message); 186 print ("--- %1\n", message);
182 } 187 }
188
183 print ("End of previous messages.\n"); 189 print ("End of previous messages.\n");
184 break; 190 break;
185 191
186 case SVRC_UPDATE: 192 case SVRC_UPDATE:
187 process_server_updates (packet); 193 process_server_updates (packet);
203 case SVRCU_PLAYERDATA: 209 case SVRCU_PLAYERDATA:
204 { 210 {
205 Vector<String> players; 211 Vector<String> players;
206 for (int i = packet.read_byte(); i > 0; --i) 212 for (int i = packet.read_byte(); i > 0; --i)
207 players << packet.read_string(); 213 players << packet.read_string();
208 print ("Players: %1\n", players);
209 } 214 }
210 break; 215 break;
211 216
212 case SVRCU_ADMINCOUNT: 217 case SVRCU_ADMINCOUNT:
213 m_numAdmins = packet.read_byte(); 218 m_numAdmins = packet.read_byte();
276 // ------------------------------------------------------------------------------------------------- 281 // -------------------------------------------------------------------------------------------------
277 // 282 //
278 STATIC METHOD 283 STATIC METHOD
279 RCONSession::get_session() -> RCONSession* 284 RCONSession::get_session() -> RCONSession*
280 { 285 {
286 if (g_rconSession == nullptr)
287 new_session();
288
281 return g_rconSession; 289 return g_rconSession;
290 }
291
292 // -------------------------------------------------------------------------------------------------
293 //
294 METHOD
295 RCONSession::is_active() const -> bool
296 {
297 return state() != RCON_DISCONNECTED;
282 } 298 }
283 299
284 // ------------------------------------------------------------------------------------------------- 300 // -------------------------------------------------------------------------------------------------
285 // Returns true if the message was successfully sent. 301 // Returns true if the message was successfully sent.
286 // 302 //

mercurial