sources/network/rconsession.cpp

changeset 83
08bfc3d9d2ae
parent 81
a18aaf460648
child 84
3bd32eec3d57
child 88
08ccaf26cffd
equal deleted inserted replaced
82:895088452014 83:08bfc3d9d2ae
40 m_numAdmins (0), 40 m_numAdmins (0),
41 m_interface (iface) 41 m_interface (iface)
42 { 42 {
43 if (not m_socket.set_blocking (false)) 43 if (not m_socket.set_blocking (false))
44 { 44 {
45 print_to (stderr, "unable to set socket as non-blocking: %1\n", 45 fprintf (stderr, "unable to set socket as non-blocking: %s\n",
46 m_socket.error_string().chars()); 46 m_socket.error_string().chars());
47 exit (EXIT_FAILURE); 47 exit (EXIT_FAILURE);
48 } 48 }
49 } 49 }
50 50
70 { 70 {
71 // Say goodbye to remote 71 // Say goodbye to remote
72 Bytestream packet; 72 Bytestream packet;
73 packet.write_byte (CLRC_DISCONNECT); 73 packet.write_byte (CLRC_DISCONNECT);
74 this->send (packet); 74 this->send (packet);
75 m_interface->print ("Disconnected from %1\n", m_address.to_string (IP_WITH_PORT)); 75 m_interface->print ("Disconnected from %s\n", m_address.to_string (IP_WITH_PORT).chars());
76 m_interface->update_statusbar(); 76 m_interface->update_statusbar();
77 } 77 }
78 78
79 m_state = RCON_DISCONNECTED; 79 m_state = RCON_DISCONNECTED;
80 } 80 }
157 157
158 case SVRC_MESSAGE: 158 case SVRC_MESSAGE:
159 { 159 {
160 String message = packet.read_string(); 160 String message = packet.read_string();
161 message.normalize(); 161 message.normalize();
162 m_interface->print ("%1\n", message); 162 m_interface->print ("%s\n", message.chars());
163 } 163 }
164 break; 164 break;
165 165
166 case SVRC_LOGGEDIN: 166 case SVRC_LOGGEDIN:
167 m_interface->print ("Login successful!\n"); 167 m_interface->print ("Login successful!\n");
177 177
178 for (int i = packet.read_byte(); i > 0; --i) 178 for (int i = packet.read_byte(); i > 0; --i)
179 { 179 {
180 String message = packet.read_string(); 180 String message = packet.read_string();
181 message.normalize(); 181 message.normalize();
182 m_interface->print ("--- %1\n", message); 182 m_interface->print ("--- %s\n", message.chars());
183 } 183 }
184 184
185 m_interface->print ("End of previous messages.\n"); 185 m_interface->print ("End of previous messages.\n");
186 break; 186 break;
187 187
190 break; 190 break;
191 191
192 case SVRC_TOOMANYTABCOMPLETES: 192 case SVRC_TOOMANYTABCOMPLETES:
193 { 193 {
194 unsigned int numCompletions = packet.read_short(); 194 unsigned int numCompletions = packet.read_short();
195 m_interface->print ("%1 completions for '%2'.\n", 195 m_interface->print ("%d completions for '%s'.\n",
196 int (numCompletions), m_lastTabComplete); 196 int (numCompletions), m_lastTabComplete.chars());
197 } 197 }
198 break; 198 break;
199 199
200 case SVRC_TABCOMPLETE: 200 case SVRC_TABCOMPLETE:
201 { 201 {
208 { 208 {
209 m_interface->tab_complete (m_lastTabComplete, completes[0]); 209 m_interface->tab_complete (m_lastTabComplete, completes[0]);
210 } 210 }
211 else if (not completes.is_empty()) 211 else if (not completes.is_empty())
212 { 212 {
213 m_interface->print ("Completions for '%1':\n", m_lastTabComplete); 213 m_interface->print ("Completions for '%s':\n", m_lastTabComplete.chars());
214 214
215 for (int i = 0; i < completes.size(); i += 8) 215 for (int i = 0; i < completes.size(); i += 8)
216 { 216 {
217 Range<int> spliceRange (i, min (i + 8, completes.size() - 1)); 217 Range<int> spliceRange (i, min (i + 8, completes.size() - 1));
218 StringList splice (completes.splice (spliceRange)); 218 StringList splice (completes.splice (spliceRange));
219 m_interface->print ("- %1\n", splice.join (", ")); 219 m_interface->print ("- %s\n", splice.join (", ").chars());
220 } 220 }
221 } 221 }
222 } 222 }
223 break; 223 break;
224 } 224 }
225 } 225 }
226 } 226 }
227 catch (std::exception& e) 227 catch (std::exception& e)
228 { 228 {
229 m_interface->print_warning ("Couldn't process packet: %1\n", e.what()); 229 m_interface->print_warning ("Couldn't process packet: %s\n", e.what());
230 } 230 }
231 } 231 }
232 232
233 void RCONSession::process_server_updates (Bytestream& packet) 233 void RCONSession::process_server_updates (Bytestream& packet)
234 { 234 {
272 272
273 // ------------------------------------------------------------------------------------------------- 273 // -------------------------------------------------------------------------------------------------
274 // 274 //
275 void RCONSession::send_hello() 275 void RCONSession::send_hello()
276 { 276 {
277 m_interface->print ("Connecting to %1...\n", m_address.to_string (IP_WITH_PORT)); 277 m_interface->print ("Connecting to %s...\n", m_address.to_string (IP_WITH_PORT).chars());
278 Bytestream packet; 278 Bytestream packet;
279 packet.write_byte (CLRC_BEGINCONNECTION); 279 packet.write_byte (CLRC_BEGINCONNECTION);
280 packet.write_byte (RCON_PROTOCOL_VERSION); 280 packet.write_byte (RCON_PROTOCOL_VERSION);
281 send (packet); 281 send (packet);
282 bump_last_ping(); 282 bump_last_ping();
373 send (packet); 373 send (packet);
374 bump_last_ping(); 374 bump_last_ping();
375 m_lastTabComplete = part; 375 m_lastTabComplete = part;
376 } 376 }
377 else 377 else
378 m_interface->print ("Server protocol is %1, cannot tab-complete\n", m_serverProtocol); 378 {
379 } 379 m_interface->print ("This server does not support tab-completion\n", m_serverProtocol);
380 }
381 }

mercurial