|
|
|
@ -71,19 +71,19 @@ void NetworkUDPSocketHandler::CloseSocket()
|
|
|
|
|
* @param all send the packet using all sockets that can send it
|
|
|
|
|
* @param broadcast whether to send a broadcast message
|
|
|
|
|
*/
|
|
|
|
|
void NetworkUDPSocketHandler::SendPacket(Packet *p, NetworkAddress *recv, bool all, bool broadcast)
|
|
|
|
|
void NetworkUDPSocketHandler::SendPacket(Packet &p, NetworkAddress &recv, bool all, bool broadcast)
|
|
|
|
|
{
|
|
|
|
|
if (this->sockets.empty()) this->Listen();
|
|
|
|
|
|
|
|
|
|
for (auto &s : this->sockets) {
|
|
|
|
|
/* Make a local copy because if we resolve it we cannot
|
|
|
|
|
* easily unresolve it so we can resolve it later again. */
|
|
|
|
|
NetworkAddress send(*recv);
|
|
|
|
|
NetworkAddress send(recv);
|
|
|
|
|
|
|
|
|
|
/* Not the same type */
|
|
|
|
|
if (!send.IsFamily(s.second.GetAddress()->ss_family)) continue;
|
|
|
|
|
|
|
|
|
|
p->PrepareToSend();
|
|
|
|
|
p.PrepareToSend();
|
|
|
|
|
|
|
|
|
|
if (broadcast) {
|
|
|
|
|
/* Enable broadcast */
|
|
|
|
@ -94,7 +94,7 @@ void NetworkUDPSocketHandler::SendPacket(Packet *p, NetworkAddress *recv, bool a
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Send the buffer */
|
|
|
|
|
ssize_t res = p->TransferOut<int>(sendto, s.first, 0, (const struct sockaddr *)send.GetAddress(), send.GetAddressLength());
|
|
|
|
|
ssize_t res = p.TransferOut<int>(sendto, s.first, 0, (const struct sockaddr *)send.GetAddress(), send.GetAddressLength());
|
|
|
|
|
Debug(net, 7, "sendto({})", send.GetAddressAsString());
|
|
|
|
|
|
|
|
|
|
/* Check for any errors, but ignore it otherwise */
|
|
|
|
@ -140,7 +140,7 @@ void NetworkUDPSocketHandler::ReceivePackets()
|
|
|
|
|
p.PrepareToRead();
|
|
|
|
|
|
|
|
|
|
/* Handle the packet */
|
|
|
|
|
this->HandleUDPPacket(&p, &address);
|
|
|
|
|
this->HandleUDPPacket(p, address);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -150,14 +150,14 @@ void NetworkUDPSocketHandler::ReceivePackets()
|
|
|
|
|
* @param p the received packet
|
|
|
|
|
* @param client_addr the sender of the packet
|
|
|
|
|
*/
|
|
|
|
|
void NetworkUDPSocketHandler::HandleUDPPacket(Packet *p, NetworkAddress *client_addr)
|
|
|
|
|
void NetworkUDPSocketHandler::HandleUDPPacket(Packet &p, NetworkAddress &client_addr)
|
|
|
|
|
{
|
|
|
|
|
PacketUDPType type;
|
|
|
|
|
|
|
|
|
|
/* New packet == new client, which has not quit yet */
|
|
|
|
|
this->Reopen();
|
|
|
|
|
|
|
|
|
|
type = (PacketUDPType)p->Recv_uint8();
|
|
|
|
|
type = (PacketUDPType)p.Recv_uint8();
|
|
|
|
|
|
|
|
|
|
switch (this->HasClientQuit() ? PACKET_UDP_END : type) {
|
|
|
|
|
case PACKET_UDP_CLIENT_FIND_SERVER: this->Receive_CLIENT_FIND_SERVER(p, client_addr); break;
|
|
|
|
@ -165,9 +165,9 @@ void NetworkUDPSocketHandler::HandleUDPPacket(Packet *p, NetworkAddress *client_
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
if (this->HasClientQuit()) {
|
|
|
|
|
Debug(net, 0, "[udp] Received invalid packet type {} from {}", type, client_addr->GetAddressAsString());
|
|
|
|
|
Debug(net, 0, "[udp] Received invalid packet type {} from {}", type, client_addr.GetAddressAsString());
|
|
|
|
|
} else {
|
|
|
|
|
Debug(net, 0, "[udp] Received illegal packet from {}", client_addr->GetAddressAsString());
|
|
|
|
|
Debug(net, 0, "[udp] Received illegal packet from {}", client_addr.GetAddressAsString());
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
@ -178,10 +178,10 @@ void NetworkUDPSocketHandler::HandleUDPPacket(Packet *p, NetworkAddress *client_
|
|
|
|
|
* @param type The received packet type.
|
|
|
|
|
* @param client_addr The address we received the packet from.
|
|
|
|
|
*/
|
|
|
|
|
void NetworkUDPSocketHandler::ReceiveInvalidPacket(PacketUDPType type, NetworkAddress *client_addr)
|
|
|
|
|
void NetworkUDPSocketHandler::ReceiveInvalidPacket(PacketUDPType type, NetworkAddress &client_addr)
|
|
|
|
|
{
|
|
|
|
|
Debug(net, 0, "[udp] Received packet type {} on wrong port from {}", type, client_addr->GetAddressAsString());
|
|
|
|
|
Debug(net, 0, "[udp] Received packet type {} on wrong port from {}", type, client_addr.GetAddressAsString());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NetworkUDPSocketHandler::Receive_CLIENT_FIND_SERVER(Packet *, NetworkAddress *client_addr) { this->ReceiveInvalidPacket(PACKET_UDP_CLIENT_FIND_SERVER, client_addr); }
|
|
|
|
|
void NetworkUDPSocketHandler::Receive_SERVER_RESPONSE(Packet *, NetworkAddress *client_addr) { this->ReceiveInvalidPacket(PACKET_UDP_SERVER_RESPONSE, client_addr); }
|
|
|
|
|
void NetworkUDPSocketHandler::Receive_CLIENT_FIND_SERVER(Packet &, NetworkAddress &client_addr) { this->ReceiveInvalidPacket(PACKET_UDP_CLIENT_FIND_SERVER, client_addr); }
|
|
|
|
|
void NetworkUDPSocketHandler::Receive_SERVER_RESPONSE(Packet &, NetworkAddress &client_addr) { this->ReceiveInvalidPacket(PACKET_UDP_SERVER_RESPONSE, client_addr); }
|
|
|
|
|