MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / HandleUDPPacket

Method HandleUDPPacket

src/network/core/udp.cpp:159–180  ·  view source on GitHub ↗

* Handle an incoming packets by sending it to the correct function. * @param p the received packet * @param client_addr the sender of the packet */

Source from the content-addressed store, hash-verified

157 * @param client_addr the sender of the packet
158 */
159void NetworkUDPSocketHandler::HandleUDPPacket(Packet &p, NetworkAddress &client_addr)
160{
161 PacketUDPType type;
162
163 /* New packet == new client, which has not quit yet */
164 this->Reopen();
165
166 type = (PacketUDPType)p.Recv_uint8();
167
168 switch (this->HasClientQuit() ? PACKET_UDP_END : type) {
169 case PACKET_UDP_CLIENT_FIND_SERVER: this->Receive_CLIENT_FIND_SERVER(p, client_addr); break;
170 case PACKET_UDP_SERVER_RESPONSE: this->Receive_SERVER_RESPONSE(p, client_addr); break;
171
172 default:
173 if (this->HasClientQuit()) {
174 Debug(net, 0, "[udp] Received invalid packet type {} from {}", type, client_addr.GetAddressAsString());
175 } else {
176 Debug(net, 0, "[udp] Received illegal packet from {}", client_addr.GetAddressAsString());
177 }
178 break;
179 }
180}
181
182/**
183 * Helper for logging receiving invalid packets.

Callers 1

ReceivePacketsMethod · 0.95

Calls 6

ReopenMethod · 0.80
Recv_uint8Method · 0.80
HasClientQuitMethod · 0.80
GetAddressAsStringMethod · 0.80

Tested by

no test coverage detected