diff options
author | truelight <truelight@openttd.org> | 2004-12-22 18:56:52 +0000 |
---|---|---|
committer | truelight <truelight@openttd.org> | 2004-12-22 18:56:52 +0000 |
commit | d66adc937da88a590621a6f6eead31b167d6b64c (patch) | |
tree | 74abfeb2224cb4741f9ff826c51fb123373fb918 | |
parent | 90b2b2144b9ef9ebd4ec30bf905ef7239e004891 (diff) | |
download | openttd-d66adc937da88a590621a6f6eead31b167d6b64c.tar.xz |
(svn r1228) -Add: [Network] When a server normally shuts down, it removed itself
from the server-list
-rw-r--r-- | console_cmds.c | 4 | ||||
-rw-r--r-- | network.c | 2 | ||||
-rw-r--r-- | network_udp.c | 42 | ||||
-rw-r--r-- | network_udp.h | 1 |
4 files changed, 46 insertions, 3 deletions
diff --git a/console_cmds.c b/console_cmds.c index e412aa0fd..e513af4ba 100644 --- a/console_cmds.c +++ b/console_cmds.c @@ -780,8 +780,10 @@ DEF_CONSOLE_CMD(ConSet) { if (argc == 3) { if (strcmp(argv[2], "on") == 0 || atoi(argv[2]) == 1) _network_advertise = true; - else + else { + NetworkUDPRemoveAdvertise(); _network_advertise = false; + } IConsolePrintF(_iconsole_color_warning, "Server-advertise changed to '%s'", (_network_advertise)?"on":"off"); } else { IConsolePrintF(_iconsole_color_default, "Current server-advertise is '%s'", (_network_advertise)?"on":"off"); @@ -1002,6 +1002,8 @@ void NetworkDisconnect(void) } } + NetworkUDPRemoveAdvertise(); + DeleteWindowById(WC_NETWORK_STATUS_WINDOW, 0); NetworkClose(); diff --git a/network_udp.c b/network_udp.c index 31541b632..5f66df6e4 100644 --- a/network_udp.c +++ b/network_udp.c @@ -24,6 +24,7 @@ typedef enum { PACKET_UDP_MASTER_ACK_REGISTER, // Packet indicating registration has succedeed PACKET_UDP_CLIENT_GET_LIST, // Request for serverlist from master server PACKET_UDP_MASTER_RESPONSE_LIST, // Response from master server with server ip's + port's + PACKET_UDP_SERVER_UNREGISTER, // Request to be removed from the server-list PACKET_UDP_END } PacketUDPType; @@ -246,7 +247,11 @@ DEF_UDP_RECEIVE_COMMAND(PACKET_UDP_MASTER_RESPONSE_LIST) { DEF_UDP_RECEIVE_COMMAND(PACKET_UDP_MASTER_ACK_REGISTER) { _network_advertise_retries = 0; - DEBUG(net, 2)("[NET] We are advertised on the master-server!"); + DEBUG(net, 2)("[NET][UDP] We are advertised on the master-server!"); + + if (!_network_advertise) + /* We are advertised, but we don't want to! */ + NetworkUDPRemoveAdvertise(); } @@ -261,7 +266,8 @@ static NetworkUDPPacket* const _network_udp_packet[] = { NULL, RECEIVE_COMMAND(PACKET_UDP_MASTER_ACK_REGISTER), NULL, - RECEIVE_COMMAND(PACKET_UDP_MASTER_RESPONSE_LIST) + RECEIVE_COMMAND(PACKET_UDP_MASTER_RESPONSE_LIST), + NULL }; @@ -517,6 +523,38 @@ NetworkGameList *NetworkUDPQueryServer(const byte* host, unsigned short port) return item; } +/* Remove our advertise from the master-server */ +void NetworkUDPRemoveAdvertise(void) +{ + struct sockaddr_in out_addr; + Packet *p; + + /* Check if we are advertising */ + if (!_networking || !_network_server || !_network_udp_server || !_network_advertise) + return; + + /* check for socket */ + if (_udp_master_socket == INVALID_SOCKET) + if (!NetworkUDPListen(&_udp_master_socket, 0, 0, false)) + return; + + DEBUG(net, 2)("[NET][UDP] Removing advertise.."); + + /* Find somewhere to send */ + out_addr.sin_family = AF_INET; + out_addr.sin_port = htons(NETWORK_MASTER_SERVER_PORT); + out_addr.sin_addr.s_addr = NetworkResolveHost(NETWORK_MASTER_SERVER_HOST); + + /* Send the packet */ + p = NetworkSend_Init(PACKET_UDP_SERVER_UNREGISTER); + /* Packet is: Version, server_port */ + NetworkSend_uint8(p, NETWORK_MASTER_SERVER_VERSION); + NetworkSend_uint16(p, _network_server_port); + NetworkSendUDP_Packet(_udp_master_socket, p, &out_addr); + + free(p); +} + /* Register us to the master server This function checks if it needs to send an advertise */ void NetworkUDPAdvertise(void) diff --git a/network_udp.h b/network_udp.h index 43ca8f999..ad0e79844 100644 --- a/network_udp.h +++ b/network_udp.h @@ -8,5 +8,6 @@ void NetworkUDPSearchGame(void); void NetworkUDPQueryMasterServer(void); NetworkGameList *NetworkUDPQueryServer(const byte* host, unsigned short port); void NetworkUDPAdvertise(void); +void NetworkUDPRemoveAdvertise(void); #endif /* NETWORK_LAN_H */ |