author | rubidium |
Fri, 04 Apr 2008 21:09:28 +0000 | |
changeset 9322 | 0892ea4dea97 |
parent 8766 | c86cfa3a7580 |
child 10230 | bf81856a1101 |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
6447
3b71e57fd22b
(svn r8857) -Documentation: Added some doxygen @file tags, repaired others (the @file tag MUST be found before any line of code, that includes preprocessor directives).
celestar
parents:
6169
diff
changeset
|
3 |
/** |
3b71e57fd22b
(svn r8857) -Documentation: Added some doxygen @file tags, repaired others (the @file tag MUST be found before any line of code, that includes preprocessor directives).
celestar
parents:
6169
diff
changeset
|
4 |
* @file network_udp.cpp This file handles the UDP related communication. |
3b71e57fd22b
(svn r8857) -Documentation: Added some doxygen @file tags, repaired others (the @file tag MUST be found before any line of code, that includes preprocessor directives).
celestar
parents:
6169
diff
changeset
|
5 |
* |
3b71e57fd22b
(svn r8857) -Documentation: Added some doxygen @file tags, repaired others (the @file tag MUST be found before any line of code, that includes preprocessor directives).
celestar
parents:
6169
diff
changeset
|
6 |
* This is the GameServer <-> MasterServer and GameServer <-> GameClient |
3b71e57fd22b
(svn r8857) -Documentation: Added some doxygen @file tags, repaired others (the @file tag MUST be found before any line of code, that includes preprocessor directives).
celestar
parents:
6169
diff
changeset
|
7 |
* communication before the game is being joined. |
3b71e57fd22b
(svn r8857) -Documentation: Added some doxygen @file tags, repaired others (the @file tag MUST be found before any line of code, that includes preprocessor directives).
celestar
parents:
6169
diff
changeset
|
8 |
*/ |
3b71e57fd22b
(svn r8857) -Documentation: Added some doxygen @file tags, repaired others (the @file tag MUST be found before any line of code, that includes preprocessor directives).
celestar
parents:
6169
diff
changeset
|
9 |
|
4826
63b1eb7c966b
(svn r6750) -Codechange: Juggle around some header includes as they're only used when
Darkvater
parents:
4344
diff
changeset
|
10 |
#ifdef ENABLE_NETWORK |
63b1eb7c966b
(svn r6750) -Codechange: Juggle around some header includes as they're only used when
Darkvater
parents:
4344
diff
changeset
|
11 |
|
5720
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
5568
diff
changeset
|
12 |
#include "../stdafx.h" |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
5568
diff
changeset
|
13 |
#include "../debug.h" |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
14 |
#include "network_data.h" |
8636
2b158acb649c
(svn r11702) -Codechange: move all date related stuff to date*.
rubidium
parents:
8635
diff
changeset
|
15 |
#include "../date_func.h" |
8635
3bbb6f87fced
(svn r11701) -Codechange: removal unnecessary inclusions of map.h (and split map.h).
rubidium
parents:
8628
diff
changeset
|
16 |
#include "../map_func.h" |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
17 |
#include "network_gamelist.h" |
764
68b398e2b780
(svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents:
738
diff
changeset
|
18 |
#include "network_udp.h" |
5720
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
5568
diff
changeset
|
19 |
#include "../variables.h" |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
5568
diff
changeset
|
20 |
#include "../newgrf_config.h" |
8628
4e316518420a
(svn r11694) -Codechange: move more endianness related stuff to endian_func.hpp.
rubidium
parents:
8427
diff
changeset
|
21 |
#include "../core/endian_func.hpp" |
8710
52015340050c
(svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents:
8636
diff
changeset
|
22 |
#include "../string_func.h" |
8750
fdd6054e7bae
(svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
8710
diff
changeset
|
23 |
#include "../player_base.h" |
fdd6054e7bae
(svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents:
8710
diff
changeset
|
24 |
#include "../player_func.h" |
8766
c86cfa3a7580
(svn r11834) -Codechange: only include settings_type.h if needed.
rubidium
parents:
8750
diff
changeset
|
25 |
#include "../settings_type.h" |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
26 |
|
5720
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
5568
diff
changeset
|
27 |
#include "core/udp.h" |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
5568
diff
changeset
|
28 |
|
764
68b398e2b780
(svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents:
738
diff
changeset
|
29 |
enum { |
2861
c7e2c8217fed
(svn r3409) - Change the server advertisement interval to use the frame counter instead
peter1138
parents:
2817
diff
changeset
|
30 |
ADVERTISE_NORMAL_INTERVAL = 30000, // interval between advertising in ticks (15 minutes) |
4344
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
31 |
ADVERTISE_RETRY_INTERVAL = 300, // readvertise when no response after this many ticks (9 seconds) |
5d0e40cd67b9
(svn r6045) -Cleanup: align all table-like structures using spaces, i.e. whitespace fixes only except for a few comments to make them uniform for the whole enum/struct.
rubidium
parents:
4326
diff
changeset
|
32 |
ADVERTISE_RETRY_TIMES = 3 // give up readvertising after this much failed retries |
764
68b398e2b780
(svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents:
738
diff
changeset
|
33 |
}; |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
34 |
|
5870
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
35 |
NetworkUDPSocketHandler *_udp_client_socket; ///< udp client socket |
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
36 |
NetworkUDPSocketHandler *_udp_server_socket; ///< udp server socket |
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
37 |
NetworkUDPSocketHandler *_udp_master_socket; ///< udp master socket |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
38 |
|
5870
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
39 |
///*** Communication with the masterserver ***/ |
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
40 |
|
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
41 |
class MasterNetworkUDPSocketHandler : public NetworkUDPSocketHandler { |
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
42 |
protected: |
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
43 |
DECLARE_UDP_RECEIVE_COMMAND(PACKET_UDP_MASTER_ACK_REGISTER); |
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
44 |
public: |
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
45 |
virtual ~MasterNetworkUDPSocketHandler() {} |
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
46 |
}; |
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
47 |
|
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
48 |
DEF_UDP_RECEIVE_COMMAND(Master, PACKET_UDP_MASTER_ACK_REGISTER) |
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
49 |
{ |
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
50 |
_network_advertise_retries = 0; |
7868
25b9aad39e4a
(svn r10736) -Fix: Correct all mispellings of 'successful'.
peter1138
parents:
7827
diff
changeset
|
51 |
DEBUG(net, 2, "[udp] advertising on master server successful"); |
5870
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
52 |
|
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
53 |
/* We are advertised, but we don't want to! */ |
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
54 |
if (!_network_advertise) NetworkUDPRemoveAdvertise(); |
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
55 |
} |
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
56 |
|
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
57 |
///*** Communication with clients (we are server) ***/ |
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
58 |
|
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
59 |
class ServerNetworkUDPSocketHandler : public NetworkUDPSocketHandler { |
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
60 |
protected: |
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
61 |
DECLARE_UDP_RECEIVE_COMMAND(PACKET_UDP_CLIENT_FIND_SERVER); |
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
62 |
DECLARE_UDP_RECEIVE_COMMAND(PACKET_UDP_CLIENT_DETAIL_INFO); |
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
63 |
DECLARE_UDP_RECEIVE_COMMAND(PACKET_UDP_CLIENT_GET_NEWGRFS); |
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
64 |
public: |
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
65 |
virtual ~ServerNetworkUDPSocketHandler() {} |
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
66 |
}; |
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
67 |
|
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
68 |
DEF_UDP_RECEIVE_COMMAND(Server, PACKET_UDP_CLIENT_FIND_SERVER) |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
69 |
{ |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
70 |
// Just a fail-safe.. should never happen |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
71 |
if (!_network_udp_server) |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
72 |
return; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
73 |
|
6149
44aedfd50791
(svn r8521) -Codechange: initial step in converting Packet to a class; make and use constructors and functions related to the reading/saving the packet size.
rubidium
parents:
6112
diff
changeset
|
74 |
Packet packet(PACKET_UDP_SERVER_RESPONSE); |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
75 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
76 |
// Update some game_info |
5720
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
5568
diff
changeset
|
77 |
_network_game_info.game_date = _date; |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
5568
diff
changeset
|
78 |
_network_game_info.map_width = MapSizeX(); |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
5568
diff
changeset
|
79 |
_network_game_info.map_height = MapSizeY(); |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
5568
diff
changeset
|
80 |
_network_game_info.map_set = _opt.landscape; |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
5568
diff
changeset
|
81 |
_network_game_info.companies_on = ActivePlayerCount(); |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
5568
diff
changeset
|
82 |
_network_game_info.spectators_on = NetworkSpectatorCount(); |
cc0ceeafaa55
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
5568
diff
changeset
|
83 |
_network_game_info.grfconfig = _grfconfig; |
5339
7573f179efe8
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5034
diff
changeset
|
84 |
|
6149
44aedfd50791
(svn r8521) -Codechange: initial step in converting Packet to a class; make and use constructors and functions related to the reading/saving the packet size.
rubidium
parents:
6112
diff
changeset
|
85 |
this->Send_NetworkGameInfo(&packet, &_network_game_info); |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
86 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
87 |
// Let the client know that we are here |
6149
44aedfd50791
(svn r8521) -Codechange: initial step in converting Packet to a class; make and use constructors and functions related to the reading/saving the packet size.
rubidium
parents:
6112
diff
changeset
|
88 |
this->SendPacket(&packet, client_addr); |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
89 |
|
5568
75f13d7bfaed
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5341
diff
changeset
|
90 |
DEBUG(net, 2, "[udp] queried from '%s'", inet_ntoa(client_addr->sin_addr)); |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
91 |
} |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
92 |
|
5870
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
93 |
DEF_UDP_RECEIVE_COMMAND(Server, PACKET_UDP_CLIENT_DETAIL_INFO) |
638
a26f83ba23f3
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
94 |
{ |
5875
4a1391019791
(svn r8083) -Codechange: make a NetworkSocketHandler as base for all sockets and move a little of NetworkClientState functionality to the NetworkSocketHandler. Move the rest of the NetworkClientState to the new NetworkTCPSocketHandler class/struct, which is not yet implemented in an object oriented manner. The UDP socket handler now extends the NetworkSocketHandler instead of having a reference to a NetworkClientState.
rubidium
parents:
5870
diff
changeset
|
95 |
NetworkTCPSocketHandler *cs; |
638
a26f83ba23f3
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
96 |
NetworkClientInfo *ci; |
a26f83ba23f3
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
97 |
Player *player; |
a26f83ba23f3
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
98 |
byte current = 0; |
a26f83ba23f3
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
99 |
int i; |
a26f83ba23f3
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
100 |
|
a26f83ba23f3
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
101 |
// Just a fail-safe.. should never happen |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4035
diff
changeset
|
102 |
if (!_network_udp_server) return; |
638
a26f83ba23f3
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
103 |
|
6149
44aedfd50791
(svn r8521) -Codechange: initial step in converting Packet to a class; make and use constructors and functions related to the reading/saving the packet size.
rubidium
parents:
6112
diff
changeset
|
104 |
Packet packet(PACKET_UDP_SERVER_DETAIL_INFO); |
638
a26f83ba23f3
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
105 |
|
a26f83ba23f3
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
106 |
/* Send the amount of active companies */ |
6151
4b5e33f35bbe
(svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents:
6149
diff
changeset
|
107 |
packet.Send_uint8 (NETWORK_COMPANY_INFO_VERSION); |
4b5e33f35bbe
(svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents:
6149
diff
changeset
|
108 |
packet.Send_uint8 (ActivePlayerCount()); |
638
a26f83ba23f3
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
109 |
|
a26f83ba23f3
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
110 |
/* Fetch the latest version of everything */ |
a26f83ba23f3
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
111 |
NetworkPopulateCompanyInfo(); |
a26f83ba23f3
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
112 |
|
a26f83ba23f3
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
113 |
/* Go through all the players */ |
a26f83ba23f3
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
114 |
FOR_ALL_PLAYERS(player) { |
a26f83ba23f3
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
115 |
/* Skip non-active players */ |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4035
diff
changeset
|
116 |
if (!player->is_active) continue; |
638
a26f83ba23f3
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
117 |
|
a26f83ba23f3
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
118 |
current++; |
a26f83ba23f3
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
119 |
|
a26f83ba23f3
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
120 |
/* Send the information */ |
6151
4b5e33f35bbe
(svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents:
6149
diff
changeset
|
121 |
packet.Send_uint8 (current); |
638
a26f83ba23f3
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
122 |
|
6151
4b5e33f35bbe
(svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents:
6149
diff
changeset
|
123 |
packet.Send_string(_network_player_info[player->index].company_name); |
4b5e33f35bbe
(svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents:
6149
diff
changeset
|
124 |
packet.Send_uint32(_network_player_info[player->index].inaugurated_year); |
4b5e33f35bbe
(svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents:
6149
diff
changeset
|
125 |
packet.Send_uint64(_network_player_info[player->index].company_value); |
4b5e33f35bbe
(svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents:
6149
diff
changeset
|
126 |
packet.Send_uint64(_network_player_info[player->index].money); |
4b5e33f35bbe
(svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents:
6149
diff
changeset
|
127 |
packet.Send_uint64(_network_player_info[player->index].income); |
4b5e33f35bbe
(svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents:
6149
diff
changeset
|
128 |
packet.Send_uint16(_network_player_info[player->index].performance); |
638
a26f83ba23f3
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
129 |
|
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4035
diff
changeset
|
130 |
/* Send 1 if there is a passord for the company else send 0 */ |
7544
74528540f256
(svn r10313) -Fix (r8546): value for password "protected" was sent toggled for UDP packets, i.e. unpassworded companies showed up passworded and vice versa.
rubidium
parents:
7530
diff
changeset
|
131 |
packet.Send_bool (!StrEmpty(_network_player_info[player->index].password)); |
1019
6363b8a4273e
(svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents:
1011
diff
changeset
|
132 |
|
638
a26f83ba23f3
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
133 |
for (i = 0; i < NETWORK_VEHICLE_TYPES; i++) |
6151
4b5e33f35bbe
(svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents:
6149
diff
changeset
|
134 |
packet.Send_uint16(_network_player_info[player->index].num_vehicle[i]); |
638
a26f83ba23f3
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
135 |
|
a26f83ba23f3
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
136 |
for (i = 0; i < NETWORK_STATION_TYPES; i++) |
6151
4b5e33f35bbe
(svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents:
6149
diff
changeset
|
137 |
packet.Send_uint16(_network_player_info[player->index].num_station[i]); |
638
a26f83ba23f3
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
138 |
|
a26f83ba23f3
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
139 |
/* Find the clients that are connected to this player */ |
a26f83ba23f3
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
140 |
FOR_ALL_CLIENTS(cs) { |
a26f83ba23f3
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
141 |
ci = DEREF_CLIENT_INFO(cs); |
4878
744717de172e
(svn r6814) -Codechange: For network games ci->client_playas was always p->index + 1. To
Darkvater
parents:
4826
diff
changeset
|
142 |
if (ci->client_playas == player->index) { |
6169
31cdbb4845f1
(svn r8546) -Codechange: add a seperate (wrapper) functions to send/receive booleans.
rubidium
parents:
6167
diff
changeset
|
143 |
packet.Send_bool (true); |
6151
4b5e33f35bbe
(svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents:
6149
diff
changeset
|
144 |
packet.Send_string(ci->client_name); |
4b5e33f35bbe
(svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents:
6149
diff
changeset
|
145 |
packet.Send_string(ci->unique_id); |
4b5e33f35bbe
(svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents:
6149
diff
changeset
|
146 |
packet.Send_uint32(ci->join_date); |
638
a26f83ba23f3
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
147 |
} |
a26f83ba23f3
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
148 |
} |
a26f83ba23f3
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
149 |
/* Also check for the server itself */ |
a26f83ba23f3
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
150 |
ci = NetworkFindClientInfoFromIndex(NETWORK_SERVER_INDEX); |
4878
744717de172e
(svn r6814) -Codechange: For network games ci->client_playas was always p->index + 1. To
Darkvater
parents:
4826
diff
changeset
|
151 |
if (ci->client_playas == player->index) { |
6169
31cdbb4845f1
(svn r8546) -Codechange: add a seperate (wrapper) functions to send/receive booleans.
rubidium
parents:
6167
diff
changeset
|
152 |
packet.Send_bool (true); |
6151
4b5e33f35bbe
(svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents:
6149
diff
changeset
|
153 |
packet.Send_string(ci->client_name); |
4b5e33f35bbe
(svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents:
6149
diff
changeset
|
154 |
packet.Send_string(ci->unique_id); |
4b5e33f35bbe
(svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents:
6149
diff
changeset
|
155 |
packet.Send_uint32(ci->join_date); |
638
a26f83ba23f3
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
156 |
} |
a26f83ba23f3
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
157 |
|
a26f83ba23f3
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
158 |
/* Indicates end of client list */ |
6169
31cdbb4845f1
(svn r8546) -Codechange: add a seperate (wrapper) functions to send/receive booleans.
rubidium
parents:
6167
diff
changeset
|
159 |
packet.Send_bool(false); |
638
a26f83ba23f3
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
160 |
} |
a26f83ba23f3
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
161 |
|
a26f83ba23f3
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
162 |
/* And check if we have any spectators */ |
a26f83ba23f3
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
163 |
FOR_ALL_CLIENTS(cs) { |
a26f83ba23f3
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
164 |
ci = DEREF_CLIENT_INFO(cs); |
4878
744717de172e
(svn r6814) -Codechange: For network games ci->client_playas was always p->index + 1. To
Darkvater
parents:
4826
diff
changeset
|
165 |
if (!IsValidPlayer(ci->client_playas)) { |
6169
31cdbb4845f1
(svn r8546) -Codechange: add a seperate (wrapper) functions to send/receive booleans.
rubidium
parents:
6167
diff
changeset
|
166 |
packet.Send_bool (true); |
6151
4b5e33f35bbe
(svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents:
6149
diff
changeset
|
167 |
packet.Send_string(ci->client_name); |
4b5e33f35bbe
(svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents:
6149
diff
changeset
|
168 |
packet.Send_string(ci->unique_id); |
4b5e33f35bbe
(svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents:
6149
diff
changeset
|
169 |
packet.Send_uint32(ci->join_date); |
638
a26f83ba23f3
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
170 |
} |
a26f83ba23f3
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
171 |
} |
4880
0708f34e3586
(svn r6816) -Codechange: Some coding style, variable localization, const correctness.
Darkvater
parents:
4878
diff
changeset
|
172 |
|
638
a26f83ba23f3
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
173 |
/* Also check for the server itself */ |
a26f83ba23f3
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
174 |
ci = NetworkFindClientInfoFromIndex(NETWORK_SERVER_INDEX); |
4878
744717de172e
(svn r6814) -Codechange: For network games ci->client_playas was always p->index + 1. To
Darkvater
parents:
4826
diff
changeset
|
175 |
if (!IsValidPlayer(ci->client_playas)) { |
6169
31cdbb4845f1
(svn r8546) -Codechange: add a seperate (wrapper) functions to send/receive booleans.
rubidium
parents:
6167
diff
changeset
|
176 |
packet.Send_bool (true); |
6151
4b5e33f35bbe
(svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents:
6149
diff
changeset
|
177 |
packet.Send_string(ci->client_name); |
4b5e33f35bbe
(svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents:
6149
diff
changeset
|
178 |
packet.Send_string(ci->unique_id); |
4b5e33f35bbe
(svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents:
6149
diff
changeset
|
179 |
packet.Send_uint32(ci->join_date); |
638
a26f83ba23f3
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
180 |
} |
a26f83ba23f3
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
181 |
|
a26f83ba23f3
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
182 |
/* Indicates end of client list */ |
6169
31cdbb4845f1
(svn r8546) -Codechange: add a seperate (wrapper) functions to send/receive booleans.
rubidium
parents:
6167
diff
changeset
|
183 |
packet.Send_bool(false); |
638
a26f83ba23f3
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
184 |
|
6149
44aedfd50791
(svn r8521) -Codechange: initial step in converting Packet to a class; make and use constructors and functions related to the reading/saving the packet size.
rubidium
parents:
6112
diff
changeset
|
185 |
this->SendPacket(&packet, client_addr); |
638
a26f83ba23f3
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
186 |
} |
a26f83ba23f3
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
187 |
|
5339
7573f179efe8
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5034
diff
changeset
|
188 |
/** |
7573f179efe8
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5034
diff
changeset
|
189 |
* A client has requested the names of some NewGRFs. |
7573f179efe8
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5034
diff
changeset
|
190 |
* |
7573f179efe8
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5034
diff
changeset
|
191 |
* Replying this can be tricky as we have a limit of SEND_MTU bytes |
7573f179efe8
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5034
diff
changeset
|
192 |
* in the reply packet and we can send up to 100 bytes per NewGRF |
7573f179efe8
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5034
diff
changeset
|
193 |
* (GRF ID, MD5sum and NETWORK_GRF_NAME_LENGTH bytes for the name). |
7573f179efe8
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5034
diff
changeset
|
194 |
* As SEND_MTU is _much_ less than 100 * NETWORK_MAX_GRF_COUNT, it |
7573f179efe8
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5034
diff
changeset
|
195 |
* could be that a packet overflows. To stop this we only reply |
7573f179efe8
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5034
diff
changeset
|
196 |
* with the first N NewGRFs so that if the first N + 1 NewGRFs |
7573f179efe8
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5034
diff
changeset
|
197 |
* would be sent, the packet overflows. |
7573f179efe8
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5034
diff
changeset
|
198 |
* in_reply and in_reply_count are used to keep a list of GRFs to |
7573f179efe8
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5034
diff
changeset
|
199 |
* send in the reply. |
7573f179efe8
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5034
diff
changeset
|
200 |
*/ |
5870
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
201 |
DEF_UDP_RECEIVE_COMMAND(Server, PACKET_UDP_CLIENT_GET_NEWGRFS) |
5339
7573f179efe8
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5034
diff
changeset
|
202 |
{ |
7573f179efe8
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5034
diff
changeset
|
203 |
uint8 num_grfs; |
7573f179efe8
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5034
diff
changeset
|
204 |
uint i; |
7573f179efe8
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5034
diff
changeset
|
205 |
|
7573f179efe8
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5034
diff
changeset
|
206 |
const GRFConfig *in_reply[NETWORK_MAX_GRF_COUNT]; |
7573f179efe8
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5034
diff
changeset
|
207 |
uint8 in_reply_count = 0; |
7573f179efe8
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5034
diff
changeset
|
208 |
uint packet_len = 0; |
7573f179efe8
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5034
diff
changeset
|
209 |
|
5568
75f13d7bfaed
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5341
diff
changeset
|
210 |
DEBUG(net, 6, "[udp] newgrf data request from %s:%d", inet_ntoa(client_addr->sin_addr), ntohs(client_addr->sin_port)); |
5339
7573f179efe8
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5034
diff
changeset
|
211 |
|
6151
4b5e33f35bbe
(svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents:
6149
diff
changeset
|
212 |
num_grfs = p->Recv_uint8 (); |
5339
7573f179efe8
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5034
diff
changeset
|
213 |
if (num_grfs > NETWORK_MAX_GRF_COUNT) return; |
7573f179efe8
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5034
diff
changeset
|
214 |
|
7573f179efe8
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5034
diff
changeset
|
215 |
for (i = 0; i < num_grfs; i++) { |
7573f179efe8
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5034
diff
changeset
|
216 |
GRFConfig c; |
7573f179efe8
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5034
diff
changeset
|
217 |
const GRFConfig *f; |
7573f179efe8
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5034
diff
changeset
|
218 |
|
5870
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
219 |
this->Recv_GRFIdentifier(p, &c); |
5339
7573f179efe8
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5034
diff
changeset
|
220 |
|
7573f179efe8
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5034
diff
changeset
|
221 |
/* Find the matching GRF file */ |
7573f179efe8
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5034
diff
changeset
|
222 |
f = FindGRFConfig(c.grfid, c.md5sum); |
7573f179efe8
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5034
diff
changeset
|
223 |
if (f == NULL) continue; // The GRF is unknown to this server |
7573f179efe8
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5034
diff
changeset
|
224 |
|
7573f179efe8
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5034
diff
changeset
|
225 |
/* If the reply might exceed the size of the packet, only reply |
5341
df905c2cbaae
(svn r7507) -Fix (7505): the name of a GRF could be "", which causes a segmentation fault. So take the filename, which cannot be "", when the of the GRF name is "". Also check for "" length when receiving GRF names.
rubidium
parents:
5339
diff
changeset
|
226 |
* the current list and do not send the other data. |
df905c2cbaae
(svn r7507) -Fix (7505): the name of a GRF could be "", which causes a segmentation fault. So take the filename, which cannot be "", when the of the GRF name is "". Also check for "" length when receiving GRF names.
rubidium
parents:
5339
diff
changeset
|
227 |
* The name could be an empty string, if so take the filename. */ |
df905c2cbaae
(svn r7507) -Fix (7505): the name of a GRF could be "", which causes a segmentation fault. So take the filename, which cannot be "", when the of the GRF name is "". Also check for "" length when receiving GRF names.
rubidium
parents:
5339
diff
changeset
|
228 |
packet_len += sizeof(c.grfid) + sizeof(c.md5sum) + |
5889
272800d151ac
(svn r8097) Replace strlen() {==,!=,>} 0 by the more concise {,!}StrEmpty(). Additionally the test takes O(1) instead of O(n) now
tron
parents:
5875
diff
changeset
|
229 |
min(strlen((f->name != NULL && !StrEmpty(f->name)) ? f->name : f->filename) + 1, (size_t)NETWORK_GRF_NAME_LENGTH); |
5339
7573f179efe8
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5034
diff
changeset
|
230 |
if (packet_len > SEND_MTU - 4) { // 4 is 3 byte header + grf count in reply |
7573f179efe8
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5034
diff
changeset
|
231 |
break; |
7573f179efe8
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5034
diff
changeset
|
232 |
} |
7573f179efe8
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5034
diff
changeset
|
233 |
in_reply[in_reply_count] = f; |
7573f179efe8
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5034
diff
changeset
|
234 |
in_reply_count++; |
7573f179efe8
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5034
diff
changeset
|
235 |
} |
7573f179efe8
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5034
diff
changeset
|
236 |
|
7573f179efe8
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5034
diff
changeset
|
237 |
if (in_reply_count == 0) return; |
7573f179efe8
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5034
diff
changeset
|
238 |
|
6149
44aedfd50791
(svn r8521) -Codechange: initial step in converting Packet to a class; make and use constructors and functions related to the reading/saving the packet size.
rubidium
parents:
6112
diff
changeset
|
239 |
Packet packet(PACKET_UDP_SERVER_NEWGRFS); |
6151
4b5e33f35bbe
(svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents:
6149
diff
changeset
|
240 |
packet.Send_uint8(in_reply_count); |
5339
7573f179efe8
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5034
diff
changeset
|
241 |
for (i = 0; i < in_reply_count; i++) { |
7573f179efe8
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5034
diff
changeset
|
242 |
char name[NETWORK_GRF_NAME_LENGTH]; |
5341
df905c2cbaae
(svn r7507) -Fix (7505): the name of a GRF could be "", which causes a segmentation fault. So take the filename, which cannot be "", when the of the GRF name is "". Also check for "" length when receiving GRF names.
rubidium
parents:
5339
diff
changeset
|
243 |
|
df905c2cbaae
(svn r7507) -Fix (7505): the name of a GRF could be "", which causes a segmentation fault. So take the filename, which cannot be "", when the of the GRF name is "". Also check for "" length when receiving GRF names.
rubidium
parents:
5339
diff
changeset
|
244 |
/* The name could be an empty string, if so take the filename */ |
5889
272800d151ac
(svn r8097) Replace strlen() {==,!=,>} 0 by the more concise {,!}StrEmpty(). Additionally the test takes O(1) instead of O(n) now
tron
parents:
5875
diff
changeset
|
245 |
ttd_strlcpy(name, (in_reply[i]->name != NULL && !StrEmpty(in_reply[i]->name)) ? |
5341
df905c2cbaae
(svn r7507) -Fix (7505): the name of a GRF could be "", which causes a segmentation fault. So take the filename, which cannot be "", when the of the GRF name is "". Also check for "" length when receiving GRF names.
rubidium
parents:
5339
diff
changeset
|
246 |
in_reply[i]->name : in_reply[i]->filename, sizeof(name)); |
6988
76eba6a9cc6f
(svn r9673) -Cleanup: remove spaces before tabs and replace non-indenting tabs with spaces.
rubidium
parents:
6920
diff
changeset
|
247 |
this->Send_GRFIdentifier(&packet, in_reply[i]); |
6151
4b5e33f35bbe
(svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents:
6149
diff
changeset
|
248 |
packet.Send_string(name); |
5339
7573f179efe8
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5034
diff
changeset
|
249 |
} |
7573f179efe8
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5034
diff
changeset
|
250 |
|
6149
44aedfd50791
(svn r8521) -Codechange: initial step in converting Packet to a class; make and use constructors and functions related to the reading/saving the packet size.
rubidium
parents:
6112
diff
changeset
|
251 |
this->SendPacket(&packet, client_addr); |
5339
7573f179efe8
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5034
diff
changeset
|
252 |
} |
7573f179efe8
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5034
diff
changeset
|
253 |
|
5870
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
254 |
///*** Communication with servers (we are client) ***/ |
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
255 |
|
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
256 |
class ClientNetworkUDPSocketHandler : public NetworkUDPSocketHandler { |
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
257 |
protected: |
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
258 |
DECLARE_UDP_RECEIVE_COMMAND(PACKET_UDP_SERVER_RESPONSE); |
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
259 |
DECLARE_UDP_RECEIVE_COMMAND(PACKET_UDP_MASTER_RESPONSE_LIST); |
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
260 |
DECLARE_UDP_RECEIVE_COMMAND(PACKET_UDP_SERVER_NEWGRFS); |
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
261 |
virtual void HandleIncomingNetworkGameInfoGRFConfig(GRFConfig *config); |
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
262 |
public: |
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
263 |
virtual ~ClientNetworkUDPSocketHandler() {} |
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
264 |
}; |
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
265 |
|
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
266 |
DEF_UDP_RECEIVE_COMMAND(Client, PACKET_UDP_SERVER_RESPONSE) |
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
267 |
{ |
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
268 |
NetworkGameList *item; |
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
269 |
|
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
270 |
// Just a fail-safe.. should never happen |
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
271 |
if (_network_udp_server) return; |
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
272 |
|
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
273 |
DEBUG(net, 4, "[udp] server response from %s:%d", inet_ntoa(client_addr->sin_addr), ntohs(client_addr->sin_port)); |
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
274 |
|
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
275 |
// Find next item |
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
276 |
item = NetworkGameListAddItem(inet_addr(inet_ntoa(client_addr->sin_addr)), ntohs(client_addr->sin_port)); |
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
277 |
|
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
278 |
this->Recv_NetworkGameInfo(p, &item->info); |
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
279 |
|
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
280 |
item->info.compatible = true; |
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
281 |
{ |
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
282 |
/* Checks whether there needs to be a request for names of GRFs and makes |
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
283 |
* the request if necessary. GRFs that need to be requested are the GRFs |
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
284 |
* that do not exist on the clients system and we do not have the name |
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
285 |
* resolved of, i.e. the name is still UNKNOWN_GRF_NAME_PLACEHOLDER. |
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
286 |
* The in_request array and in_request_count are used so there is no need |
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
287 |
* to do a second loop over the GRF list, which can be relatively expensive |
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
288 |
* due to the string comparisons. */ |
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
289 |
const GRFConfig *in_request[NETWORK_MAX_GRF_COUNT]; |
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
290 |
const GRFConfig *c; |
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
291 |
uint in_request_count = 0; |
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
292 |
struct sockaddr_in out_addr; |
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
293 |
|
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
294 |
for (c = item->info.grfconfig; c != NULL; c = c->next) { |
6555
c27c9d5b459f
(svn r9031) -Codechange: Introduce grfconfig->status, and use it for states that are
maedhros
parents:
6504
diff
changeset
|
295 |
if (c->status == GCS_NOT_FOUND) item->info.compatible = false; |
7581
c943cdf602f0
(svn r10352) -Fix: the network did not request the newgrf names of newgrfs that it couldn't find; it only wanted to request the newgrf names of newgrfs that where available locally and than were called "<Unknown>".
rubidium
parents:
7544
diff
changeset
|
296 |
if (c->status != GCS_NOT_FOUND || strcmp(c->name, UNKNOWN_GRF_NAME_PLACEHOLDER) != 0) continue; |
5870
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
297 |
in_request[in_request_count] = c; |
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
298 |
in_request_count++; |
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
299 |
} |
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
300 |
|
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
301 |
if (in_request_count > 0) { |
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
302 |
/* There are 'unknown' GRFs, now send a request for them */ |
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
303 |
uint i; |
6149
44aedfd50791
(svn r8521) -Codechange: initial step in converting Packet to a class; make and use constructors and functions related to the reading/saving the packet size.
rubidium
parents:
6112
diff
changeset
|
304 |
Packet packet(PACKET_UDP_CLIENT_GET_NEWGRFS); |
5870
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
305 |
|
6151
4b5e33f35bbe
(svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents:
6149
diff
changeset
|
306 |
packet.Send_uint8(in_request_count); |
5870
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
307 |
for (i = 0; i < in_request_count; i++) { |
6149
44aedfd50791
(svn r8521) -Codechange: initial step in converting Packet to a class; make and use constructors and functions related to the reading/saving the packet size.
rubidium
parents:
6112
diff
changeset
|
308 |
this->Send_GRFIdentifier(&packet, in_request[i]); |
5870
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
309 |
} |
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
310 |
|
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
311 |
out_addr.sin_family = AF_INET; |
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
312 |
out_addr.sin_port = htons(item->port); |
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
313 |
out_addr.sin_addr.s_addr = item->ip; |
6149
44aedfd50791
(svn r8521) -Codechange: initial step in converting Packet to a class; make and use constructors and functions related to the reading/saving the packet size.
rubidium
parents:
6112
diff
changeset
|
314 |
this->SendPacket(&packet, &out_addr); |
5870
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
315 |
} |
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
316 |
} |
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
317 |
|
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
318 |
if (item->info.hostname[0] == '\0') |
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
319 |
snprintf(item->info.hostname, sizeof(item->info.hostname), "%s", inet_ntoa(client_addr->sin_addr)); |
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
320 |
|
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
321 |
/* Check if we are allowed on this server based on the revision-match */ |
6504
5578f2fa1a73
(svn r8949) -Codechange: only test the first NETWORK_REVISION_LENGTH - 1 characters when determining network compatability. This makes it possible to have 'long' branch names while still being able to play network games.
rubidium
parents:
6447
diff
changeset
|
322 |
item->info.version_compatible = IsNetworkCompatibleVersion(item->info.server_revision); |
5870
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
323 |
item->info.compatible &= item->info.version_compatible; // Already contains match for GRFs |
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
324 |
|
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
325 |
item->online = true; |
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
326 |
|
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
327 |
UpdateNetworkGameWindow(false); |
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
328 |
} |
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
329 |
|
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
330 |
DEF_UDP_RECEIVE_COMMAND(Client, PACKET_UDP_MASTER_RESPONSE_LIST) |
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
331 |
{ |
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
332 |
int i; |
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
333 |
struct in_addr ip; |
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
334 |
uint16 port; |
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
335 |
uint8 ver; |
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
336 |
|
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
337 |
/* packet begins with the protocol version (uint8) |
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
338 |
* then an uint16 which indicates how many |
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
339 |
* ip:port pairs are in this packet, after that |
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
340 |
* an uint32 (ip) and an uint16 (port) for each pair |
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
341 |
*/ |
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
342 |
|
6151
4b5e33f35bbe
(svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents:
6149
diff
changeset
|
343 |
ver = p->Recv_uint8(); |
5870
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
344 |
|
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
345 |
if (ver == 1) { |
6151
4b5e33f35bbe
(svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents:
6149
diff
changeset
|
346 |
for (i = p->Recv_uint16(); i != 0 ; i--) { |
4b5e33f35bbe
(svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents:
6149
diff
changeset
|
347 |
ip.s_addr = TO_LE32(p->Recv_uint32()); |
4b5e33f35bbe
(svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents:
6149
diff
changeset
|
348 |
port = p->Recv_uint16(); |
5875
4a1391019791
(svn r8083) -Codechange: make a NetworkSocketHandler as base for all sockets and move a little of NetworkClientState functionality to the NetworkSocketHandler. Move the rest of the NetworkClientState to the new NetworkTCPSocketHandler class/struct, which is not yet implemented in an object oriented manner. The UDP socket handler now extends the NetworkSocketHandler instead of having a reference to a NetworkClientState.
rubidium
parents:
5870
diff
changeset
|
349 |
|
4a1391019791
(svn r8083) -Codechange: make a NetworkSocketHandler as base for all sockets and move a little of NetworkClientState functionality to the NetworkSocketHandler. Move the rest of the NetworkClientState to the new NetworkTCPSocketHandler class/struct, which is not yet implemented in an object oriented manner. The UDP socket handler now extends the NetworkSocketHandler instead of having a reference to a NetworkClientState.
rubidium
parents:
5870
diff
changeset
|
350 |
/* Somehow we reached the end of the packet */ |
4a1391019791
(svn r8083) -Codechange: make a NetworkSocketHandler as base for all sockets and move a little of NetworkClientState functionality to the NetworkSocketHandler. Move the rest of the NetworkClientState to the new NetworkTCPSocketHandler class/struct, which is not yet implemented in an object oriented manner. The UDP socket handler now extends the NetworkSocketHandler instead of having a reference to a NetworkClientState.
rubidium
parents:
5870
diff
changeset
|
351 |
if (this->HasClientQuit()) return; |
5870
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
352 |
NetworkUDPQueryServer(inet_ntoa(ip), port); |
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
353 |
} |
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
354 |
} |
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
355 |
} |
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
356 |
|
5339
7573f179efe8
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5034
diff
changeset
|
357 |
/** The return of the client's request of the names of some NewGRFs */ |
5870
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
358 |
DEF_UDP_RECEIVE_COMMAND(Client, PACKET_UDP_SERVER_NEWGRFS) |
5339
7573f179efe8
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5034
diff
changeset
|
359 |
{ |
7573f179efe8
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5034
diff
changeset
|
360 |
uint8 num_grfs; |
7573f179efe8
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5034
diff
changeset
|
361 |
uint i; |
7573f179efe8
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5034
diff
changeset
|
362 |
|
5870
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
363 |
DEBUG(net, 6, "[udp] newgrf data reply from %s:%d", inet_ntoa(client_addr->sin_addr), ntohs(client_addr->sin_port)); |
5339
7573f179efe8
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5034
diff
changeset
|
364 |
|
6151
4b5e33f35bbe
(svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents:
6149
diff
changeset
|
365 |
num_grfs = p->Recv_uint8 (); |
5339
7573f179efe8
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5034
diff
changeset
|
366 |
if (num_grfs > NETWORK_MAX_GRF_COUNT) return; |
7573f179efe8
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5034
diff
changeset
|
367 |
|
7573f179efe8
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5034
diff
changeset
|
368 |
for (i = 0; i < num_grfs; i++) { |
7573f179efe8
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5034
diff
changeset
|
369 |
char *unknown_name; |
7573f179efe8
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5034
diff
changeset
|
370 |
char name[NETWORK_GRF_NAME_LENGTH]; |
7573f179efe8
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5034
diff
changeset
|
371 |
GRFConfig c; |
7573f179efe8
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5034
diff
changeset
|
372 |
|
5870
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
373 |
this->Recv_GRFIdentifier(p, &c); |
6151
4b5e33f35bbe
(svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents:
6149
diff
changeset
|
374 |
p->Recv_string(name, sizeof(name)); |
5339
7573f179efe8
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5034
diff
changeset
|
375 |
|
5341
df905c2cbaae
(svn r7507) -Fix (7505): the name of a GRF could be "", which causes a segmentation fault. So take the filename, which cannot be "", when the of the GRF name is "". Also check for "" length when receiving GRF names.
rubidium
parents:
5339
diff
changeset
|
376 |
/* An empty name is not possible under normal circumstances |
df905c2cbaae
(svn r7507) -Fix (7505): the name of a GRF could be "", which causes a segmentation fault. So take the filename, which cannot be "", when the of the GRF name is "". Also check for "" length when receiving GRF names.
rubidium
parents:
5339
diff
changeset
|
377 |
* and causes problems when showing the NewGRF list. */ |
5889
272800d151ac
(svn r8097) Replace strlen() {==,!=,>} 0 by the more concise {,!}StrEmpty(). Additionally the test takes O(1) instead of O(n) now
tron
parents:
5875
diff
changeset
|
378 |
if (StrEmpty(name)) continue; |
5341
df905c2cbaae
(svn r7507) -Fix (7505): the name of a GRF could be "", which causes a segmentation fault. So take the filename, which cannot be "", when the of the GRF name is "". Also check for "" length when receiving GRF names.
rubidium
parents:
5339
diff
changeset
|
379 |
|
5339
7573f179efe8
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5034
diff
changeset
|
380 |
/* Finds the fake GRFConfig for the just read GRF ID and MD5sum tuple. |
7573f179efe8
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5034
diff
changeset
|
381 |
* If it exists and not resolved yet, then name of the fake GRF is |
7573f179efe8
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5034
diff
changeset
|
382 |
* overwritten with the name from the reply. */ |
7573f179efe8
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5034
diff
changeset
|
383 |
unknown_name = FindUnknownGRFName(c.grfid, c.md5sum, false); |
7573f179efe8
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5034
diff
changeset
|
384 |
if (unknown_name != NULL && strcmp(unknown_name, UNKNOWN_GRF_NAME_PLACEHOLDER) == 0) { |
7573f179efe8
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5034
diff
changeset
|
385 |
ttd_strlcpy(unknown_name, name, NETWORK_GRF_NAME_LENGTH); |
7573f179efe8
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5034
diff
changeset
|
386 |
} |
7573f179efe8
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5034
diff
changeset
|
387 |
} |
7573f179efe8
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5034
diff
changeset
|
388 |
} |
7573f179efe8
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5034
diff
changeset
|
389 |
|
5870
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
390 |
void ClientNetworkUDPSocketHandler::HandleIncomingNetworkGameInfoGRFConfig(GRFConfig *config) |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
391 |
{ |
5870
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
392 |
/* Find the matching GRF file */ |
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
393 |
const GRFConfig *f = FindGRFConfig(config->grfid, config->md5sum); |
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
394 |
if (f == NULL) { |
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
395 |
/* Don't know the GRF, so mark game incompatible and the (possibly) |
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
396 |
* already resolved name for this GRF (another server has sent the |
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
397 |
* name of the GRF already */ |
6920
ee15b916f758
(svn r9560) -Codechange: add support for multiple 'base' directories for newgrf searching.
rubidium
parents:
6573
diff
changeset
|
398 |
config->name = FindUnknownGRFName(config->grfid, config->md5sum, true); |
ee15b916f758
(svn r9560) -Codechange: add support for multiple 'base' directories for newgrf searching.
rubidium
parents:
6573
diff
changeset
|
399 |
config->status = GCS_NOT_FOUND; |
3547
a4584d709460
(svn r4413) -Fix: fixed a bug which pushed the client back to the main menu when a
truelight
parents:
3456
diff
changeset
|
400 |
} else { |
6920
ee15b916f758
(svn r9560) -Codechange: add support for multiple 'base' directories for newgrf searching.
rubidium
parents:
6573
diff
changeset
|
401 |
config->filename = f->filename; |
ee15b916f758
(svn r9560) -Codechange: add support for multiple 'base' directories for newgrf searching.
rubidium
parents:
6573
diff
changeset
|
402 |
config->name = f->name; |
ee15b916f758
(svn r9560) -Codechange: add support for multiple 'base' directories for newgrf searching.
rubidium
parents:
6573
diff
changeset
|
403 |
config->info = f->info; |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
404 |
} |
8427
143b0be22af1
(svn r11484) -Codechange: Remove the doubled function SetBitT and rename the remaining to fit with the naming style
skidd13
parents:
7868
diff
changeset
|
405 |
SetBit(config->flags, GCF_COPY); |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
406 |
} |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
407 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
408 |
// Close UDP connection |
6573 | 409 |
void NetworkUDPCloseAll() |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
410 |
{ |
5568
75f13d7bfaed
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5341
diff
changeset
|
411 |
DEBUG(net, 1, "[udp] closed listeners"); |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
412 |
|
5870
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
413 |
_udp_server_socket->Close(); |
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
414 |
_udp_master_socket->Close(); |
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
415 |
_udp_client_socket->Close(); |
764
68b398e2b780
(svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents:
738
diff
changeset
|
416 |
|
5772
fbb42af982b4
(svn r7825) -Codechange: make NetworkUDPClose close a single UDP socket. Use NetworkUDPStop to close all opened udp sockets (those were called NetworkUDPClose).
rubidium
parents:
5770
diff
changeset
|
417 |
_network_udp_server = false; |
fbb42af982b4
(svn r7825) -Codechange: make NetworkUDPClose close a single UDP socket. Use NetworkUDPStop to close all opened udp sockets (those were called NetworkUDPClose).
rubidium
parents:
5770
diff
changeset
|
418 |
_network_udp_broadcast = 0; |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
419 |
} |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
420 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
421 |
// Broadcast to all ips |
5870
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
422 |
static void NetworkUDPBroadCast(NetworkUDPSocketHandler *socket) |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
423 |
{ |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4035
diff
changeset
|
424 |
uint i; |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
425 |
|
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4035
diff
changeset
|
426 |
for (i = 0; _broadcast_list[i] != 0; i++) { |
6149
44aedfd50791
(svn r8521) -Codechange: initial step in converting Packet to a class; make and use constructors and functions related to the reading/saving the packet size.
rubidium
parents:
6112
diff
changeset
|
427 |
Packet p(PACKET_UDP_CLIENT_FIND_SERVER); |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4035
diff
changeset
|
428 |
struct sockaddr_in out_addr; |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
429 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
430 |
out_addr.sin_family = AF_INET; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
431 |
out_addr.sin_port = htons(_network_server_port); |
4034
091963647651
(svn r5293) -Fix: Not all network interfaces are capable of broadcasting. Don't record those which aren't
tron
parents:
4026
diff
changeset
|
432 |
out_addr.sin_addr.s_addr = _broadcast_list[i]; |
091963647651
(svn r5293) -Fix: Not all network interfaces are capable of broadcasting. Don't record those which aren't
tron
parents:
4026
diff
changeset
|
433 |
|
5568
75f13d7bfaed
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5341
diff
changeset
|
434 |
DEBUG(net, 4, "[udp] broadcasting to %s", inet_ntoa(out_addr.sin_addr)); |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
435 |
|
6149
44aedfd50791
(svn r8521) -Codechange: initial step in converting Packet to a class; make and use constructors and functions related to the reading/saving the packet size.
rubidium
parents:
6112
diff
changeset
|
436 |
socket->SendPacket(&p, &out_addr); |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
437 |
} |
764
68b398e2b780
(svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents:
738
diff
changeset
|
438 |
} |
68b398e2b780
(svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents:
738
diff
changeset
|
439 |
|
68b398e2b780
(svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents:
738
diff
changeset
|
440 |
|
68b398e2b780
(svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents:
738
diff
changeset
|
441 |
// Request the the server-list from the master server |
6573 | 442 |
void NetworkUDPQueryMasterServer() |
764
68b398e2b780
(svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents:
738
diff
changeset
|
443 |
{ |
68b398e2b780
(svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents:
738
diff
changeset
|
444 |
struct sockaddr_in out_addr; |
68b398e2b780
(svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents:
738
diff
changeset
|
445 |
|
5875
4a1391019791
(svn r8083) -Codechange: make a NetworkSocketHandler as base for all sockets and move a little of NetworkClientState functionality to the NetworkSocketHandler. Move the rest of the NetworkClientState to the new NetworkTCPSocketHandler class/struct, which is not yet implemented in an object oriented manner. The UDP socket handler now extends the NetworkSocketHandler instead of having a reference to a NetworkClientState.
rubidium
parents:
5870
diff
changeset
|
446 |
if (!_udp_client_socket->IsConnected()) { |
5870
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
447 |
if (!_udp_client_socket->Listen(0, 0, true)) return; |
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
448 |
} |
764
68b398e2b780
(svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents:
738
diff
changeset
|
449 |
|
6149
44aedfd50791
(svn r8521) -Codechange: initial step in converting Packet to a class; make and use constructors and functions related to the reading/saving the packet size.
rubidium
parents:
6112
diff
changeset
|
450 |
Packet p(PACKET_UDP_CLIENT_GET_LIST); |
764
68b398e2b780
(svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents:
738
diff
changeset
|
451 |
|
68b398e2b780
(svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents:
738
diff
changeset
|
452 |
out_addr.sin_family = AF_INET; |
68b398e2b780
(svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents:
738
diff
changeset
|
453 |
out_addr.sin_port = htons(NETWORK_MASTER_SERVER_PORT); |
68b398e2b780
(svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents:
738
diff
changeset
|
454 |
out_addr.sin_addr.s_addr = NetworkResolveHost(NETWORK_MASTER_SERVER_HOST); |
68b398e2b780
(svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents:
738
diff
changeset
|
455 |
|
68b398e2b780
(svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents:
738
diff
changeset
|
456 |
// packet only contains protocol version |
6151
4b5e33f35bbe
(svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents:
6149
diff
changeset
|
457 |
p.Send_uint8(NETWORK_MASTER_SERVER_VERSION); |
764
68b398e2b780
(svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents:
738
diff
changeset
|
458 |
|
6149
44aedfd50791
(svn r8521) -Codechange: initial step in converting Packet to a class; make and use constructors and functions related to the reading/saving the packet size.
rubidium
parents:
6112
diff
changeset
|
459 |
_udp_client_socket->SendPacket(&p, &out_addr); |
764
68b398e2b780
(svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents:
738
diff
changeset
|
460 |
|
6149
44aedfd50791
(svn r8521) -Codechange: initial step in converting Packet to a class; make and use constructors and functions related to the reading/saving the packet size.
rubidium
parents:
6112
diff
changeset
|
461 |
DEBUG(net, 2, "[udp] master server queried at %s:%d", inet_ntoa(out_addr.sin_addr), ntohs(out_addr.sin_port)); |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
462 |
} |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
463 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
464 |
// Find all servers |
6573 | 465 |
void NetworkUDPSearchGame() |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
466 |
{ |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
467 |
// We are still searching.. |
5568
75f13d7bfaed
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5341
diff
changeset
|
468 |
if (_network_udp_broadcast > 0) return; |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
469 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
470 |
// No UDP-socket yet.. |
5875
4a1391019791
(svn r8083) -Codechange: make a NetworkSocketHandler as base for all sockets and move a little of NetworkClientState functionality to the NetworkSocketHandler. Move the rest of the NetworkClientState to the new NetworkTCPSocketHandler class/struct, which is not yet implemented in an object oriented manner. The UDP socket handler now extends the NetworkSocketHandler instead of having a reference to a NetworkClientState.
rubidium
parents:
5870
diff
changeset
|
471 |
if (!_udp_client_socket->IsConnected()) { |
5870
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
472 |
if (!_udp_client_socket->Listen(0, 0, true)) return; |
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
473 |
} |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
474 |
|
5568
75f13d7bfaed
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5341
diff
changeset
|
475 |
DEBUG(net, 0, "[udp] searching server"); |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
476 |
|
764
68b398e2b780
(svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents:
738
diff
changeset
|
477 |
NetworkUDPBroadCast(_udp_client_socket); |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
478 |
_network_udp_broadcast = 300; // Stay searching for 300 ticks |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
479 |
} |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
480 |
|
6167
1475cf991e66
(svn r8543) -Codechange: make a real difference between querying the server via UDP and TCP.
rubidium
parents:
6151
diff
changeset
|
481 |
void NetworkUDPQueryServer(const char* host, unsigned short port, bool manually) |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
482 |
{ |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
483 |
struct sockaddr_in out_addr; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
484 |
NetworkGameList *item; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
485 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
486 |
// No UDP-socket yet.. |
5875
4a1391019791
(svn r8083) -Codechange: make a NetworkSocketHandler as base for all sockets and move a little of NetworkClientState functionality to the NetworkSocketHandler. Move the rest of the NetworkClientState to the new NetworkTCPSocketHandler class/struct, which is not yet implemented in an object oriented manner. The UDP socket handler now extends the NetworkSocketHandler instead of having a reference to a NetworkClientState.
rubidium
parents:
5870
diff
changeset
|
487 |
if (!_udp_client_socket->IsConnected()) { |
6167
1475cf991e66
(svn r8543) -Codechange: make a real difference between querying the server via UDP and TCP.
rubidium
parents:
6151
diff
changeset
|
488 |
if (!_udp_client_socket->Listen(0, 0, true)) return; |
5870
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
489 |
} |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
490 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
491 |
out_addr.sin_family = AF_INET; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
492 |
out_addr.sin_port = htons(port); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
493 |
out_addr.sin_addr.s_addr = NetworkResolveHost(host); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
494 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
495 |
// Clear item in gamelist |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
496 |
item = NetworkGameListAddItem(inet_addr(inet_ntoa(out_addr.sin_addr)), ntohs(out_addr.sin_port)); |
7827
526cc294e6e5
(svn r10694) -Codechange: update the server information in the game list every once in a while so the information stays fairly up-to-date when you are looking through the servers.
rubidium
parents:
7581
diff
changeset
|
497 |
if (StrEmpty(item->info.server_name)) { |
526cc294e6e5
(svn r10694) -Codechange: update the server information in the game list every once in a while so the information stays fairly up-to-date when you are looking through the servers.
rubidium
parents:
7581
diff
changeset
|
498 |
memset(&item->info, 0, sizeof(item->info)); |
526cc294e6e5
(svn r10694) -Codechange: update the server information in the game list every once in a while so the information stays fairly up-to-date when you are looking through the servers.
rubidium
parents:
7581
diff
changeset
|
499 |
ttd_strlcpy(item->info.server_name, host, lengthof(item->info.server_name)); |
526cc294e6e5
(svn r10694) -Codechange: update the server information in the game list every once in a while so the information stays fairly up-to-date when you are looking through the servers.
rubidium
parents:
7581
diff
changeset
|
500 |
ttd_strlcpy(item->info.hostname, host, lengthof(item->info.hostname)); |
526cc294e6e5
(svn r10694) -Codechange: update the server information in the game list every once in a while so the information stays fairly up-to-date when you are looking through the servers.
rubidium
parents:
7581
diff
changeset
|
501 |
item->online = false; |
526cc294e6e5
(svn r10694) -Codechange: update the server information in the game list every once in a while so the information stays fairly up-to-date when you are looking through the servers.
rubidium
parents:
7581
diff
changeset
|
502 |
} |
6167
1475cf991e66
(svn r8543) -Codechange: make a real difference between querying the server via UDP and TCP.
rubidium
parents:
6151
diff
changeset
|
503 |
item->manually = manually; |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
504 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
505 |
// Init the packet |
6149
44aedfd50791
(svn r8521) -Codechange: initial step in converting Packet to a class; make and use constructors and functions related to the reading/saving the packet size.
rubidium
parents:
6112
diff
changeset
|
506 |
Packet p(PACKET_UDP_CLIENT_FIND_SERVER); |
44aedfd50791
(svn r8521) -Codechange: initial step in converting Packet to a class; make and use constructors and functions related to the reading/saving the packet size.
rubidium
parents:
6112
diff
changeset
|
507 |
_udp_client_socket->SendPacket(&p, &out_addr); |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
508 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
509 |
UpdateNetworkGameWindow(false); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
510 |
} |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
511 |
|
765
7e9c5cdfdf1c
(svn r1228) -Add: [Network] When a server normally shuts down, it removed itself
truelight
parents:
764
diff
changeset
|
512 |
/* Remove our advertise from the master-server */ |
6573 | 513 |
void NetworkUDPRemoveAdvertise() |
765
7e9c5cdfdf1c
(svn r1228) -Add: [Network] When a server normally shuts down, it removed itself
truelight
parents:
764
diff
changeset
|
514 |
{ |
7e9c5cdfdf1c
(svn r1228) -Add: [Network] When a server normally shuts down, it removed itself
truelight
parents:
764
diff
changeset
|
515 |
struct sockaddr_in out_addr; |
7e9c5cdfdf1c
(svn r1228) -Add: [Network] When a server normally shuts down, it removed itself
truelight
parents:
764
diff
changeset
|
516 |
|
7e9c5cdfdf1c
(svn r1228) -Add: [Network] When a server normally shuts down, it removed itself
truelight
parents:
764
diff
changeset
|
517 |
/* Check if we are advertising */ |
5568
75f13d7bfaed
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5341
diff
changeset
|
518 |
if (!_networking || !_network_server || !_network_udp_server) return; |
765
7e9c5cdfdf1c
(svn r1228) -Add: [Network] When a server normally shuts down, it removed itself
truelight
parents:
764
diff
changeset
|
519 |
|
7e9c5cdfdf1c
(svn r1228) -Add: [Network] When a server normally shuts down, it removed itself
truelight
parents:
764
diff
changeset
|
520 |
/* check for socket */ |
5875
4a1391019791
(svn r8083) -Codechange: make a NetworkSocketHandler as base for all sockets and move a little of NetworkClientState functionality to the NetworkSocketHandler. Move the rest of the NetworkClientState to the new NetworkTCPSocketHandler class/struct, which is not yet implemented in an object oriented manner. The UDP socket handler now extends the NetworkSocketHandler instead of having a reference to a NetworkClientState.
rubidium
parents:
5870
diff
changeset
|
521 |
if (!_udp_master_socket->IsConnected()) { |
9322
0892ea4dea97
(svn r12574) -Fix: binding to a specific IP could cause OpenTTD to not register properly with the masterserver if one has multiple external interfaces.
rubidium
parents:
8766
diff
changeset
|
522 |
if (!_udp_master_socket->Listen(_network_server_bind_ip, 0, false)) return; |
5870
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
523 |
} |
765
7e9c5cdfdf1c
(svn r1228) -Add: [Network] When a server normally shuts down, it removed itself
truelight
parents:
764
diff
changeset
|
524 |
|
5568
75f13d7bfaed
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5341
diff
changeset
|
525 |
DEBUG(net, 1, "[udp] removing advertise from master server"); |
765
7e9c5cdfdf1c
(svn r1228) -Add: [Network] When a server normally shuts down, it removed itself
truelight
parents:
764
diff
changeset
|
526 |
|
7e9c5cdfdf1c
(svn r1228) -Add: [Network] When a server normally shuts down, it removed itself
truelight
parents:
764
diff
changeset
|
527 |
/* Find somewhere to send */ |
7e9c5cdfdf1c
(svn r1228) -Add: [Network] When a server normally shuts down, it removed itself
truelight
parents:
764
diff
changeset
|
528 |
out_addr.sin_family = AF_INET; |
7e9c5cdfdf1c
(svn r1228) -Add: [Network] When a server normally shuts down, it removed itself
truelight
parents:
764
diff
changeset
|
529 |
out_addr.sin_port = htons(NETWORK_MASTER_SERVER_PORT); |
7e9c5cdfdf1c
(svn r1228) -Add: [Network] When a server normally shuts down, it removed itself
truelight
parents:
764
diff
changeset
|
530 |
out_addr.sin_addr.s_addr = NetworkResolveHost(NETWORK_MASTER_SERVER_HOST); |
7e9c5cdfdf1c
(svn r1228) -Add: [Network] When a server normally shuts down, it removed itself
truelight
parents:
764
diff
changeset
|
531 |
|
7e9c5cdfdf1c
(svn r1228) -Add: [Network] When a server normally shuts down, it removed itself
truelight
parents:
764
diff
changeset
|
532 |
/* Send the packet */ |
6149
44aedfd50791
(svn r8521) -Codechange: initial step in converting Packet to a class; make and use constructors and functions related to the reading/saving the packet size.
rubidium
parents:
6112
diff
changeset
|
533 |
Packet p(PACKET_UDP_SERVER_UNREGISTER); |
765
7e9c5cdfdf1c
(svn r1228) -Add: [Network] When a server normally shuts down, it removed itself
truelight
parents:
764
diff
changeset
|
534 |
/* Packet is: Version, server_port */ |
6151
4b5e33f35bbe
(svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents:
6149
diff
changeset
|
535 |
p.Send_uint8 (NETWORK_MASTER_SERVER_VERSION); |
4b5e33f35bbe
(svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents:
6149
diff
changeset
|
536 |
p.Send_uint16(_network_server_port); |
6149
44aedfd50791
(svn r8521) -Codechange: initial step in converting Packet to a class; make and use constructors and functions related to the reading/saving the packet size.
rubidium
parents:
6112
diff
changeset
|
537 |
_udp_master_socket->SendPacket(&p, &out_addr); |
765
7e9c5cdfdf1c
(svn r1228) -Add: [Network] When a server normally shuts down, it removed itself
truelight
parents:
764
diff
changeset
|
538 |
} |
7e9c5cdfdf1c
(svn r1228) -Add: [Network] When a server normally shuts down, it removed itself
truelight
parents:
764
diff
changeset
|
539 |
|
668
346853c8b513
(svn r1106) -Add: [Network] Added master-server protocol and advertise to
truelight
parents:
638
diff
changeset
|
540 |
/* Register us to the master server |
346853c8b513
(svn r1106) -Add: [Network] Added master-server protocol and advertise to
truelight
parents:
638
diff
changeset
|
541 |
This function checks if it needs to send an advertise */ |
6573 | 542 |
void NetworkUDPAdvertise() |
668
346853c8b513
(svn r1106) -Add: [Network] Added master-server protocol and advertise to
truelight
parents:
638
diff
changeset
|
543 |
{ |
346853c8b513
(svn r1106) -Add: [Network] Added master-server protocol and advertise to
truelight
parents:
638
diff
changeset
|
544 |
struct sockaddr_in out_addr; |
346853c8b513
(svn r1106) -Add: [Network] Added master-server protocol and advertise to
truelight
parents:
638
diff
changeset
|
545 |
|
346853c8b513
(svn r1106) -Add: [Network] Added master-server protocol and advertise to
truelight
parents:
638
diff
changeset
|
546 |
/* Check if we should send an advertise */ |
346853c8b513
(svn r1106) -Add: [Network] Added master-server protocol and advertise to
truelight
parents:
638
diff
changeset
|
547 |
if (!_networking || !_network_server || !_network_udp_server || !_network_advertise) |
346853c8b513
(svn r1106) -Add: [Network] Added master-server protocol and advertise to
truelight
parents:
638
diff
changeset
|
548 |
return; |
346853c8b513
(svn r1106) -Add: [Network] Added master-server protocol and advertise to
truelight
parents:
638
diff
changeset
|
549 |
|
764
68b398e2b780
(svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents:
738
diff
changeset
|
550 |
/* check for socket */ |
5875
4a1391019791
(svn r8083) -Codechange: make a NetworkSocketHandler as base for all sockets and move a little of NetworkClientState functionality to the NetworkSocketHandler. Move the rest of the NetworkClientState to the new NetworkTCPSocketHandler class/struct, which is not yet implemented in an object oriented manner. The UDP socket handler now extends the NetworkSocketHandler instead of having a reference to a NetworkClientState.
rubidium
parents:
5870
diff
changeset
|
551 |
if (!_udp_master_socket->IsConnected()) { |
9322
0892ea4dea97
(svn r12574) -Fix: binding to a specific IP could cause OpenTTD to not register properly with the masterserver if one has multiple external interfaces.
rubidium
parents:
8766
diff
changeset
|
552 |
if (!_udp_master_socket->Listen(_network_server_bind_ip, 0, false)) return; |
5870
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
553 |
} |
764
68b398e2b780
(svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents:
738
diff
changeset
|
554 |
|
2861
c7e2c8217fed
(svn r3409) - Change the server advertisement interval to use the frame counter instead
peter1138
parents:
2817
diff
changeset
|
555 |
if (_network_need_advertise) { |
c7e2c8217fed
(svn r3409) - Change the server advertisement interval to use the frame counter instead
peter1138
parents:
2817
diff
changeset
|
556 |
_network_need_advertise = false; |
c7e2c8217fed
(svn r3409) - Change the server advertisement interval to use the frame counter instead
peter1138
parents:
2817
diff
changeset
|
557 |
_network_advertise_retries = ADVERTISE_RETRY_TIMES; |
c7e2c8217fed
(svn r3409) - Change the server advertisement interval to use the frame counter instead
peter1138
parents:
2817
diff
changeset
|
558 |
} else { |
c7e2c8217fed
(svn r3409) - Change the server advertisement interval to use the frame counter instead
peter1138
parents:
2817
diff
changeset
|
559 |
/* Only send once every ADVERTISE_NORMAL_INTERVAL ticks */ |
c7e2c8217fed
(svn r3409) - Change the server advertisement interval to use the frame counter instead
peter1138
parents:
2817
diff
changeset
|
560 |
if (_network_advertise_retries == 0) { |
c7e2c8217fed
(svn r3409) - Change the server advertisement interval to use the frame counter instead
peter1138
parents:
2817
diff
changeset
|
561 |
if ((_network_last_advertise_frame + ADVERTISE_NORMAL_INTERVAL) > _frame_counter) |
c7e2c8217fed
(svn r3409) - Change the server advertisement interval to use the frame counter instead
peter1138
parents:
2817
diff
changeset
|
562 |
return; |
c7e2c8217fed
(svn r3409) - Change the server advertisement interval to use the frame counter instead
peter1138
parents:
2817
diff
changeset
|
563 |
_network_advertise_retries = ADVERTISE_RETRY_TIMES; |
c7e2c8217fed
(svn r3409) - Change the server advertisement interval to use the frame counter instead
peter1138
parents:
2817
diff
changeset
|
564 |
} |
c7e2c8217fed
(svn r3409) - Change the server advertisement interval to use the frame counter instead
peter1138
parents:
2817
diff
changeset
|
565 |
|
c7e2c8217fed
(svn r3409) - Change the server advertisement interval to use the frame counter instead
peter1138
parents:
2817
diff
changeset
|
566 |
if ((_network_last_advertise_frame + ADVERTISE_RETRY_INTERVAL) > _frame_counter) |
764
68b398e2b780
(svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents:
738
diff
changeset
|
567 |
return; |
68b398e2b780
(svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents:
738
diff
changeset
|
568 |
} |
68b398e2b780
(svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents:
738
diff
changeset
|
569 |
|
68b398e2b780
(svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents:
738
diff
changeset
|
570 |
_network_advertise_retries--; |
2861
c7e2c8217fed
(svn r3409) - Change the server advertisement interval to use the frame counter instead
peter1138
parents:
2817
diff
changeset
|
571 |
_network_last_advertise_frame = _frame_counter; |
668
346853c8b513
(svn r1106) -Add: [Network] Added master-server protocol and advertise to
truelight
parents:
638
diff
changeset
|
572 |
|
346853c8b513
(svn r1106) -Add: [Network] Added master-server protocol and advertise to
truelight
parents:
638
diff
changeset
|
573 |
/* Find somewhere to send */ |
346853c8b513
(svn r1106) -Add: [Network] Added master-server protocol and advertise to
truelight
parents:
638
diff
changeset
|
574 |
out_addr.sin_family = AF_INET; |
346853c8b513
(svn r1106) -Add: [Network] Added master-server protocol and advertise to
truelight
parents:
638
diff
changeset
|
575 |
out_addr.sin_port = htons(NETWORK_MASTER_SERVER_PORT); |
346853c8b513
(svn r1106) -Add: [Network] Added master-server protocol and advertise to
truelight
parents:
638
diff
changeset
|
576 |
out_addr.sin_addr.s_addr = NetworkResolveHost(NETWORK_MASTER_SERVER_HOST); |
346853c8b513
(svn r1106) -Add: [Network] Added master-server protocol and advertise to
truelight
parents:
638
diff
changeset
|
577 |
|
5568
75f13d7bfaed
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5341
diff
changeset
|
578 |
DEBUG(net, 1, "[udp] advertising to master server"); |
668
346853c8b513
(svn r1106) -Add: [Network] Added master-server protocol and advertise to
truelight
parents:
638
diff
changeset
|
579 |
|
346853c8b513
(svn r1106) -Add: [Network] Added master-server protocol and advertise to
truelight
parents:
638
diff
changeset
|
580 |
/* Send the packet */ |
6149
44aedfd50791
(svn r8521) -Codechange: initial step in converting Packet to a class; make and use constructors and functions related to the reading/saving the packet size.
rubidium
parents:
6112
diff
changeset
|
581 |
Packet p(PACKET_UDP_SERVER_REGISTER); |
668
346853c8b513
(svn r1106) -Add: [Network] Added master-server protocol and advertise to
truelight
parents:
638
diff
changeset
|
582 |
/* Packet is: WELCOME_MESSAGE, Version, server_port */ |
6151
4b5e33f35bbe
(svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents:
6149
diff
changeset
|
583 |
p.Send_string(NETWORK_MASTER_SERVER_WELCOME_MESSAGE); |
4b5e33f35bbe
(svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents:
6149
diff
changeset
|
584 |
p.Send_uint8 (NETWORK_MASTER_SERVER_VERSION); |
4b5e33f35bbe
(svn r8523) -Codechange: move all the Network(Recv|Send)_(uintXX|string) functions to Packet.
rubidium
parents:
6149
diff
changeset
|
585 |
p.Send_uint16(_network_server_port); |
6149
44aedfd50791
(svn r8521) -Codechange: initial step in converting Packet to a class; make and use constructors and functions related to the reading/saving the packet size.
rubidium
parents:
6112
diff
changeset
|
586 |
_udp_master_socket->SendPacket(&p, &out_addr); |
668
346853c8b513
(svn r1106) -Add: [Network] Added master-server protocol and advertise to
truelight
parents:
638
diff
changeset
|
587 |
} |
346853c8b513
(svn r1106) -Add: [Network] Added master-server protocol and advertise to
truelight
parents:
638
diff
changeset
|
588 |
|
6573 | 589 |
void NetworkUDPInitialize() |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
590 |
{ |
5870
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
591 |
_udp_client_socket = new ClientNetworkUDPSocketHandler(); |
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
592 |
_udp_server_socket = new ServerNetworkUDPSocketHandler(); |
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
593 |
_udp_master_socket = new MasterNetworkUDPSocketHandler(); |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
594 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
595 |
_network_udp_server = false; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
596 |
_network_udp_broadcast = 0; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
597 |
} |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
598 |
|
6573 | 599 |
void NetworkUDPShutdown() |
5870
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
600 |
{ |
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
601 |
NetworkUDPCloseAll(); |
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
602 |
|
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
603 |
delete _udp_client_socket; |
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
604 |
delete _udp_server_socket; |
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
605 |
delete _udp_master_socket; |
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
606 |
} |
86e55167c9e3
(svn r8078) -Codechange: rewrite UDP part of the network code to make use classes. This is only one of the many steps to really cleanup the network code.
rubidium
parents:
5838
diff
changeset
|
607 |
|
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
608 |
#endif /* ENABLE_NETWORK */ |