mirror of
https://github.com/JGRennison/OpenTTD-patches.git
synced 2024-11-11 13:10:45 +00:00
(svn r15984) -Codechange: prepare the UDP receiver to process multiple types of returned server lists.
This commit is contained in:
parent
1cd5ac75ff
commit
10ccad9d3d
@ -58,9 +58,9 @@ const char *NetworkAddress::GetAddressAsString(bool with_family)
|
|||||||
/* 6 = for the : and 5 for the decimal port number */
|
/* 6 = for the : and 5 for the decimal port number */
|
||||||
static char buf[NETWORK_HOSTNAME_LENGTH + 6 + 7];
|
static char buf[NETWORK_HOSTNAME_LENGTH + 6 + 7];
|
||||||
char *p = buf;
|
char *p = buf;
|
||||||
if (this->address.ss_family == AF_INET6) p = strecpy(p, "[", lastof(buf));
|
if (this->GetAddress()->ss_family == AF_INET6) p = strecpy(p, "[", lastof(buf));
|
||||||
p = strecpy(p, this->GetHostname(), lastof(buf));
|
p = strecpy(p, this->GetHostname(), lastof(buf));
|
||||||
if (this->address.ss_family == AF_INET6) p = strecpy(p, "]", lastof(buf));
|
if (this->GetAddress()->ss_family == AF_INET6) p = strecpy(p, "]", lastof(buf));
|
||||||
p += seprintf(p, lastof(buf), ":%d", this->GetPort());
|
p += seprintf(p, lastof(buf), ":%d", this->GetPort());
|
||||||
|
|
||||||
if (with_family) {
|
if (with_family) {
|
||||||
|
@ -90,6 +90,15 @@ enum PacketUDPType {
|
|||||||
PACKET_UDP_END ///< Must ALWAYS be on the end of this list!! (period)
|
PACKET_UDP_END ///< Must ALWAYS be on the end of this list!! (period)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** The types of server lists we can get */
|
||||||
|
enum ServerListType {
|
||||||
|
SLT_IPv4 = 0, ///< Get the IPv4 addresses
|
||||||
|
SLT_IPv6 = 1, ///< Get the IPv6 addresses
|
||||||
|
SLT_AUTODETECT, ///< Autodetect the type based on the connection
|
||||||
|
|
||||||
|
SLT_END = SLT_AUTODETECT ///< End of 'arrays' marker
|
||||||
|
};
|
||||||
|
|
||||||
#define DECLARE_UDP_RECEIVE_COMMAND(type) virtual void NetworkPacketReceive_## type ##_command(Packet *p, NetworkAddress *client_addr)
|
#define DECLARE_UDP_RECEIVE_COMMAND(type) virtual void NetworkPacketReceive_## type ##_command(Packet *p, NetworkAddress *client_addr)
|
||||||
#define DEF_UDP_RECEIVE_COMMAND(cls, type) void cls ##NetworkUDPSocketHandler::NetworkPacketReceive_ ## type ## _command(Packet *p, NetworkAddress *client_addr)
|
#define DEF_UDP_RECEIVE_COMMAND(cls, type) void cls ##NetworkUDPSocketHandler::NetworkPacketReceive_ ## type ## _command(Packet *p, NetworkAddress *client_addr)
|
||||||
|
|
||||||
|
@ -286,12 +286,12 @@ DEF_UDP_RECEIVE_COMMAND(Client, PACKET_UDP_MASTER_RESPONSE_LIST)
|
|||||||
/* packet begins with the protocol version (uint8)
|
/* packet begins with the protocol version (uint8)
|
||||||
* then an uint16 which indicates how many
|
* then an uint16 which indicates how many
|
||||||
* ip:port pairs are in this packet, after that
|
* ip:port pairs are in this packet, after that
|
||||||
* an uint32 (ip) and an uint16 (port) for each pair
|
* an uint32 (ip) and an uint16 (port) for each pair.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
uint8 ver = p->Recv_uint8();
|
ServerListType type = (ServerListType)(p->Recv_uint8() - 1);
|
||||||
|
|
||||||
if (ver == 1) {
|
if (type < SLT_END) {
|
||||||
for (int i = p->Recv_uint16(); i != 0 ; i--) {
|
for (int i = p->Recv_uint16(); i != 0 ; i--) {
|
||||||
uint32 ip = TO_LE32(p->Recv_uint32());
|
uint32 ip = TO_LE32(p->Recv_uint32());
|
||||||
uint16 port = p->Recv_uint16();
|
uint16 port = p->Recv_uint16();
|
||||||
@ -390,6 +390,7 @@ void NetworkUDPQueryMasterServer()
|
|||||||
|
|
||||||
/* packet only contains protocol version */
|
/* packet only contains protocol version */
|
||||||
p.Send_uint8(NETWORK_MASTER_SERVER_VERSION);
|
p.Send_uint8(NETWORK_MASTER_SERVER_VERSION);
|
||||||
|
p.Send_uint8(SLT_AUTODETECT);
|
||||||
|
|
||||||
_udp_client_socket->SendPacket(&p, &out_addr, true);
|
_udp_client_socket->SendPacket(&p, &out_addr, true);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user