sources/network/rconsession.cpp

changeset 189
248d0b85cbda
parent 186
9330b93d9946
child 190
90bf9049e5eb
equal deleted inserted replaced
188:5fc32e4b2a8c 189:248d0b85cbda
40 m_state(RCON_DISCONNECTED), 40 m_state(RCON_DISCONNECTED),
41 m_lastPing(0), 41 m_lastPing(0),
42 m_adminCount(0), 42 m_adminCount(0),
43 m_interface(nullptr) 43 m_interface(nullptr)
44 { 44 {
45 if (not m_socket.set_blocking(false)) 45 std::stringstream errors;
46 { 46 if (not m_socket.set_blocking(false, errors))
47 fprintf(stderr, "unable to set socket as non-blocking: %s\n", 47 {
48 m_socket.error_string().data()); 48 fprintf(stderr, "unable to set socket as non-blocking: %s\n", errors.str().data());
49 exit(EXIT_FAILURE); 49 exit(EXIT_FAILURE);
50 } 50 }
51 } 51 }
52 52
53 // ------------------------------------------------------------------------------------------------- 53 // -------------------------------------------------------------------------------------------------
78 m_state = RCON_DISCONNECTED; 78 m_state = RCON_DISCONNECTED;
79 } 79 }
80 80
81 // ------------------------------------------------------------------------------------------------- 81 // -------------------------------------------------------------------------------------------------
82 // 82 //
83 void RCONSession::send(const ByteArray& packet) 83 bool RCONSession::send(const ByteArray& packet)
84 { 84 {
85 m_socket.send(m_address, packet); 85 std::stringstream errors;
86 const bool result = m_socket.send(m_address, packet, errors);
87 if (not result)
88 {
89 this->m_interface->printError("Network error: %s\n", errors.str().data());
90 }
91 return result;
86 } 92 }
87 93
88 // ------------------------------------------------------------------------------------------------- 94 // -------------------------------------------------------------------------------------------------
89 // 95 //
90 void RCONSession::tick() 96 void RCONSession::tick()
110 send({CLRC_PONG}); 116 send({CLRC_PONG});
111 bumpLastPing(); 117 bumpLastPing();
112 } 118 }
113 } 119 }
114 120
115 for (Datagram datagram; m_socket.read(datagram);) 121 std::stringstream errors;
116 { 122 for (net::Datagram datagram; m_socket.read(datagram, errors);)
123 {
124 if (errors.tellp() > 0)
125 {
126 m_interface->printError("Network error: %s\n", errors.str().data());
127 errors = {};
128 }
117 // Only process packets that originate from the game server. 129 // Only process packets that originate from the game server.
118 if (datagram.address == m_address) 130 if (datagram.address == m_address)
119 handlePacket(datagram.message); 131 handlePacket(datagram.message);
120 } 132 }
121 } 133 }
266 } 278 }
267 } 279 }
268 280
269 // ------------------------------------------------------------------------------------------------- 281 // -------------------------------------------------------------------------------------------------
270 // 282 //
271 UDPSocket* RCONSession::getSocket() 283 net::UDPSocket* RCONSession::getSocket()
272 { 284 {
273 return &m_socket; 285 return &m_socket;
274 } 286 }
275 287
276 // ------------------------------------------------------------------------------------------------- 288 // -------------------------------------------------------------------------------------------------
377 bumpLastPing(); 389 bumpLastPing();
378 m_lastTabComplete = part; 390 m_lastTabComplete = part;
379 } 391 }
380 else 392 else
381 { 393 {
382 m_interface->print("This server does not support tab-completion\n", m_serverProtocol); 394 m_interface->print("This server does not support tab-completion\n");
383 } 395 }
384 } 396 }
385 397
386 // ------------------------------------------------------------------------------------------------- 398 // -------------------------------------------------------------------------------------------------
387 // 399 //

mercurial