author | KUDr |
Fri, 12 Jan 2007 15:43:00 +0000 | |
changeset 5620 | eab6f02899a0 |
parent 5619 | 9f5a7152403a |
child 5624 | 6afe9d27430a |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
4826
6a545d194528
(svn r6750) -Codechange: Juggle around some header includes as they're only used when
Darkvater
parents:
4344
diff
changeset
|
3 |
#ifdef ENABLE_NETWORK |
6a545d194528
(svn r6750) -Codechange: Juggle around some header includes as they're only used when
Darkvater
parents:
4344
diff
changeset
|
4 |
|
5469
7edfc643abbc
(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:
5380
diff
changeset
|
5 |
#include "../stdafx.h" |
7edfc643abbc
(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:
5380
diff
changeset
|
6 |
#include "../debug.h" |
7edfc643abbc
(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:
5380
diff
changeset
|
7 |
#include "../string.h" |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
8 |
#include "network_data.h" |
5469
7edfc643abbc
(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:
5380
diff
changeset
|
9 |
#include "../date.h" |
7edfc643abbc
(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:
5380
diff
changeset
|
10 |
#include "../map.h" |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
11 |
#include "network_gamelist.h" |
764
7e1e17b7c7d4
(svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents:
738
diff
changeset
|
12 |
#include "network_udp.h" |
5469
7edfc643abbc
(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:
5380
diff
changeset
|
13 |
#include "../variables.h" |
7edfc643abbc
(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:
5380
diff
changeset
|
14 |
#include "../newgrf_config.h" |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
15 |
|
5469
7edfc643abbc
(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:
5380
diff
changeset
|
16 |
#include "core/udp.h" |
7edfc643abbc
(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:
5380
diff
changeset
|
17 |
|
7edfc643abbc
(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:
5380
diff
changeset
|
18 |
/** |
7edfc643abbc
(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:
5380
diff
changeset
|
19 |
* @file network_udp.c This file handles the UDP related communication. |
7edfc643abbc
(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:
5380
diff
changeset
|
20 |
* |
7edfc643abbc
(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:
5380
diff
changeset
|
21 |
* This is the GameServer <-> MasterServer and GameServer <-> GameClient |
7edfc643abbc
(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:
5380
diff
changeset
|
22 |
* communication before the game is being joined. |
7edfc643abbc
(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:
5380
diff
changeset
|
23 |
*/ |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
24 |
|
764
7e1e17b7c7d4
(svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents:
738
diff
changeset
|
25 |
enum { |
2861
e42d249af3cb
(svn r3409) - Change the server advertisement interval to use the frame counter instead
peter1138
parents:
2817
diff
changeset
|
26 |
ADVERTISE_NORMAL_INTERVAL = 30000, // interval between advertising in ticks (15 minutes) |
4344
7e123fec5b0b
(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
|
27 |
ADVERTISE_RETRY_INTERVAL = 300, // readvertise when no response after this many ticks (9 seconds) |
7e123fec5b0b
(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
|
28 |
ADVERTISE_RETRY_TIMES = 3 // give up readvertising after this much failed retries |
764
7e1e17b7c7d4
(svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents:
738
diff
changeset
|
29 |
}; |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
30 |
|
5619
9f5a7152403a
(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:
5587
diff
changeset
|
31 |
NetworkUDPSocketHandler *_udp_client_socket; ///< udp client socket |
9f5a7152403a
(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:
5587
diff
changeset
|
32 |
NetworkUDPSocketHandler *_udp_server_socket; ///< udp server socket |
9f5a7152403a
(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:
5587
diff
changeset
|
33 |
NetworkUDPSocketHandler *_udp_master_socket; ///< udp master socket |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
34 |
|
5619
9f5a7152403a
(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:
5587
diff
changeset
|
35 |
#define DEF_UDP_RECEIVE_COMMAND(cls, type) void cls ##NetworkUDPSocketHandler::NetworkPacketReceive_ ## type ## _command(Packet *p, const struct sockaddr_in *client_addr) |
903
a301a264e0fc
(svn r1389) -Add: [Network] Added packet protection. No longer a client or server
truelight
parents:
850
diff
changeset
|
36 |
|
5619
9f5a7152403a
(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:
5587
diff
changeset
|
37 |
///*** Communication with the masterserver ***/ |
9f5a7152403a
(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:
5587
diff
changeset
|
38 |
|
9f5a7152403a
(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:
5587
diff
changeset
|
39 |
class MasterNetworkUDPSocketHandler : public NetworkUDPSocketHandler { |
9f5a7152403a
(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:
5587
diff
changeset
|
40 |
protected: |
9f5a7152403a
(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:
5587
diff
changeset
|
41 |
DECLARE_UDP_RECEIVE_COMMAND(PACKET_UDP_MASTER_ACK_REGISTER); |
9f5a7152403a
(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:
5587
diff
changeset
|
42 |
public: |
9f5a7152403a
(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:
5587
diff
changeset
|
43 |
virtual ~MasterNetworkUDPSocketHandler() {} |
9f5a7152403a
(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:
5587
diff
changeset
|
44 |
}; |
9f5a7152403a
(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:
5587
diff
changeset
|
45 |
|
9f5a7152403a
(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:
5587
diff
changeset
|
46 |
DEF_UDP_RECEIVE_COMMAND(Master, PACKET_UDP_MASTER_ACK_REGISTER) |
9f5a7152403a
(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:
5587
diff
changeset
|
47 |
{ |
9f5a7152403a
(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:
5587
diff
changeset
|
48 |
_network_advertise_retries = 0; |
9f5a7152403a
(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:
5587
diff
changeset
|
49 |
DEBUG(net, 2, "[udp] advertising on master server successfull"); |
9f5a7152403a
(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:
5587
diff
changeset
|
50 |
|
9f5a7152403a
(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:
5587
diff
changeset
|
51 |
/* We are advertised, but we don't want to! */ |
9f5a7152403a
(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:
5587
diff
changeset
|
52 |
if (!_network_advertise) NetworkUDPRemoveAdvertise(); |
9f5a7152403a
(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:
5587
diff
changeset
|
53 |
} |
9f5a7152403a
(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:
5587
diff
changeset
|
54 |
|
9f5a7152403a
(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:
5587
diff
changeset
|
55 |
///*** Communication with clients (we are server) ***/ |
9f5a7152403a
(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:
5587
diff
changeset
|
56 |
|
9f5a7152403a
(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:
5587
diff
changeset
|
57 |
class ServerNetworkUDPSocketHandler : public NetworkUDPSocketHandler { |
9f5a7152403a
(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:
5587
diff
changeset
|
58 |
protected: |
9f5a7152403a
(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:
5587
diff
changeset
|
59 |
DECLARE_UDP_RECEIVE_COMMAND(PACKET_UDP_CLIENT_FIND_SERVER); |
9f5a7152403a
(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:
5587
diff
changeset
|
60 |
DECLARE_UDP_RECEIVE_COMMAND(PACKET_UDP_CLIENT_DETAIL_INFO); |
9f5a7152403a
(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:
5587
diff
changeset
|
61 |
DECLARE_UDP_RECEIVE_COMMAND(PACKET_UDP_CLIENT_GET_NEWGRFS); |
9f5a7152403a
(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:
5587
diff
changeset
|
62 |
public: |
9f5a7152403a
(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:
5587
diff
changeset
|
63 |
virtual ~ServerNetworkUDPSocketHandler() {} |
9f5a7152403a
(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:
5587
diff
changeset
|
64 |
}; |
9f5a7152403a
(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:
5587
diff
changeset
|
65 |
|
9f5a7152403a
(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:
5587
diff
changeset
|
66 |
DEF_UDP_RECEIVE_COMMAND(Server, PACKET_UDP_CLIENT_FIND_SERVER) |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
67 |
{ |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
68 |
Packet *packet; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
69 |
// Just a fail-safe.. should never happen |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
70 |
if (!_network_udp_server) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
71 |
return; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
72 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
73 |
packet = NetworkSend_Init(PACKET_UDP_SERVER_RESPONSE); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
74 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
75 |
// Update some game_info |
5469
7edfc643abbc
(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:
5380
diff
changeset
|
76 |
_network_game_info.game_date = _date; |
7edfc643abbc
(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:
5380
diff
changeset
|
77 |
_network_game_info.map_width = MapSizeX(); |
7edfc643abbc
(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:
5380
diff
changeset
|
78 |
_network_game_info.map_height = MapSizeY(); |
7edfc643abbc
(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:
5380
diff
changeset
|
79 |
_network_game_info.map_set = _opt.landscape; |
7edfc643abbc
(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:
5380
diff
changeset
|
80 |
_network_game_info.companies_on = ActivePlayerCount(); |
7edfc643abbc
(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:
5380
diff
changeset
|
81 |
_network_game_info.spectators_on = NetworkSpectatorCount(); |
7edfc643abbc
(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:
5380
diff
changeset
|
82 |
_network_game_info.grfconfig = _grfconfig; |
5339
96ac3f4933bb
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5034
diff
changeset
|
83 |
|
5619
9f5a7152403a
(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:
5587
diff
changeset
|
84 |
this->Send_NetworkGameInfo(packet, &_network_game_info); |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
85 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
86 |
// Let the client know that we are here |
5619
9f5a7152403a
(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:
5587
diff
changeset
|
87 |
this->SendPacket(packet, client_addr); |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
88 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
89 |
free(packet); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
90 |
|
5380
8ea58542b6e0
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5341
diff
changeset
|
91 |
DEBUG(net, 2, "[udp] queried from '%s'", inet_ntoa(client_addr->sin_addr)); |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
92 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
93 |
|
5619
9f5a7152403a
(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:
5587
diff
changeset
|
94 |
DEF_UDP_RECEIVE_COMMAND(Server, PACKET_UDP_CLIENT_DETAIL_INFO) |
638
cb9f5f50d3c7
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
95 |
{ |
716
8af847728d5b
(svn r1168) -Cleanup: [Network] Cleaned the network code a bit. Added 'const'
truelight
parents:
668
diff
changeset
|
96 |
NetworkClientState *cs; |
638
cb9f5f50d3c7
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
97 |
NetworkClientInfo *ci; |
cb9f5f50d3c7
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
98 |
Packet *packet; |
cb9f5f50d3c7
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
99 |
Player *player; |
cb9f5f50d3c7
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
100 |
byte current = 0; |
cb9f5f50d3c7
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
101 |
int i; |
cb9f5f50d3c7
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
102 |
|
cb9f5f50d3c7
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
103 |
// Just a fail-safe.. should never happen |
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4035
diff
changeset
|
104 |
if (!_network_udp_server) return; |
638
cb9f5f50d3c7
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
105 |
|
cb9f5f50d3c7
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
106 |
packet = NetworkSend_Init(PACKET_UDP_SERVER_DETAIL_INFO); |
cb9f5f50d3c7
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
107 |
|
cb9f5f50d3c7
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
108 |
/* Send the amount of active companies */ |
cb9f5f50d3c7
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
109 |
NetworkSend_uint8 (packet, NETWORK_COMPANY_INFO_VERSION); |
2944
2360b2da2bb0
(svn r3500) - Workaround the inaccurate count of spectators/companies that can happen in certain border-cases. For now just dynamically get this value when requested so it is always right. To do properly all player/client creation/destruction needs a hook for networking.
Darkvater
parents:
2881
diff
changeset
|
110 |
NetworkSend_uint8 (packet, ActivePlayerCount()); |
638
cb9f5f50d3c7
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
111 |
|
cb9f5f50d3c7
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
112 |
/* Fetch the latest version of everything */ |
cb9f5f50d3c7
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
113 |
NetworkPopulateCompanyInfo(); |
cb9f5f50d3c7
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
114 |
|
cb9f5f50d3c7
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
115 |
/* Go through all the players */ |
cb9f5f50d3c7
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
116 |
FOR_ALL_PLAYERS(player) { |
cb9f5f50d3c7
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
117 |
/* Skip non-active players */ |
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4035
diff
changeset
|
118 |
if (!player->is_active) continue; |
638
cb9f5f50d3c7
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
119 |
|
cb9f5f50d3c7
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
120 |
current++; |
cb9f5f50d3c7
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
121 |
|
cb9f5f50d3c7
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
122 |
/* Send the information */ |
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4035
diff
changeset
|
123 |
NetworkSend_uint8(packet, current); |
638
cb9f5f50d3c7
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
124 |
|
cb9f5f50d3c7
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
125 |
NetworkSend_string(packet, _network_player_info[player->index].company_name); |
4326
2e2c9d21ed96
(svn r5999) -Feature: change the original date format to a 32 bits format based at the year 0.
rubidium
parents:
4261
diff
changeset
|
126 |
NetworkSend_uint32(packet, _network_player_info[player->index].inaugurated_year); |
638
cb9f5f50d3c7
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
127 |
NetworkSend_uint64(packet, _network_player_info[player->index].company_value); |
cb9f5f50d3c7
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
128 |
NetworkSend_uint64(packet, _network_player_info[player->index].money); |
cb9f5f50d3c7
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
129 |
NetworkSend_uint64(packet, _network_player_info[player->index].income); |
cb9f5f50d3c7
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
130 |
NetworkSend_uint16(packet, _network_player_info[player->index].performance); |
cb9f5f50d3c7
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
131 |
|
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4035
diff
changeset
|
132 |
/* Send 1 if there is a passord for the company else send 0 */ |
1011
933efc472c62
(svn r1510) -Add: Improved Network Lobby GUI: (bociusz)
truelight
parents:
985
diff
changeset
|
133 |
if (_network_player_info[player->index].password[0] != '\0') { |
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4035
diff
changeset
|
134 |
NetworkSend_uint8(packet, 1); |
1011
933efc472c62
(svn r1510) -Add: Improved Network Lobby GUI: (bociusz)
truelight
parents:
985
diff
changeset
|
135 |
} else { |
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4035
diff
changeset
|
136 |
NetworkSend_uint8(packet, 0); |
1019
6bae6c11e865
(svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents:
1011
diff
changeset
|
137 |
} |
6bae6c11e865
(svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents:
1011
diff
changeset
|
138 |
|
638
cb9f5f50d3c7
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
139 |
for (i = 0; i < NETWORK_VEHICLE_TYPES; i++) |
cb9f5f50d3c7
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
140 |
NetworkSend_uint16(packet, _network_player_info[player->index].num_vehicle[i]); |
cb9f5f50d3c7
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
141 |
|
cb9f5f50d3c7
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
142 |
for (i = 0; i < NETWORK_STATION_TYPES; i++) |
cb9f5f50d3c7
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
143 |
NetworkSend_uint16(packet, _network_player_info[player->index].num_station[i]); |
cb9f5f50d3c7
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
144 |
|
cb9f5f50d3c7
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
145 |
/* Find the clients that are connected to this player */ |
cb9f5f50d3c7
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
146 |
FOR_ALL_CLIENTS(cs) { |
cb9f5f50d3c7
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
147 |
ci = DEREF_CLIENT_INFO(cs); |
4878
4d4f76a898fd
(svn r6814) -Codechange: For network games ci->client_playas was always p->index + 1. To
Darkvater
parents:
4826
diff
changeset
|
148 |
if (ci->client_playas == player->index) { |
638
cb9f5f50d3c7
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
149 |
/* The uint8 == 1 indicates that a client is following */ |
cb9f5f50d3c7
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
150 |
NetworkSend_uint8(packet, 1); |
cb9f5f50d3c7
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
151 |
NetworkSend_string(packet, ci->client_name); |
cb9f5f50d3c7
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
152 |
NetworkSend_string(packet, ci->unique_id); |
4326
2e2c9d21ed96
(svn r5999) -Feature: change the original date format to a 32 bits format based at the year 0.
rubidium
parents:
4261
diff
changeset
|
153 |
NetworkSend_uint32(packet, ci->join_date); |
638
cb9f5f50d3c7
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
154 |
} |
cb9f5f50d3c7
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
155 |
} |
cb9f5f50d3c7
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
156 |
/* Also check for the server itself */ |
cb9f5f50d3c7
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
157 |
ci = NetworkFindClientInfoFromIndex(NETWORK_SERVER_INDEX); |
4878
4d4f76a898fd
(svn r6814) -Codechange: For network games ci->client_playas was always p->index + 1. To
Darkvater
parents:
4826
diff
changeset
|
158 |
if (ci->client_playas == player->index) { |
638
cb9f5f50d3c7
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
159 |
/* The uint8 == 1 indicates that a client is following */ |
cb9f5f50d3c7
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
160 |
NetworkSend_uint8(packet, 1); |
cb9f5f50d3c7
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
161 |
NetworkSend_string(packet, ci->client_name); |
cb9f5f50d3c7
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
162 |
NetworkSend_string(packet, ci->unique_id); |
4326
2e2c9d21ed96
(svn r5999) -Feature: change the original date format to a 32 bits format based at the year 0.
rubidium
parents:
4261
diff
changeset
|
163 |
NetworkSend_uint32(packet, ci->join_date); |
638
cb9f5f50d3c7
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
164 |
} |
cb9f5f50d3c7
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
165 |
|
cb9f5f50d3c7
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
166 |
/* Indicates end of client list */ |
cb9f5f50d3c7
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
167 |
NetworkSend_uint8(packet, 0); |
cb9f5f50d3c7
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
168 |
} |
cb9f5f50d3c7
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
169 |
|
cb9f5f50d3c7
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
170 |
/* And check if we have any spectators */ |
cb9f5f50d3c7
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
171 |
FOR_ALL_CLIENTS(cs) { |
cb9f5f50d3c7
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
172 |
ci = DEREF_CLIENT_INFO(cs); |
4878
4d4f76a898fd
(svn r6814) -Codechange: For network games ci->client_playas was always p->index + 1. To
Darkvater
parents:
4826
diff
changeset
|
173 |
if (!IsValidPlayer(ci->client_playas)) { |
638
cb9f5f50d3c7
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
174 |
/* The uint8 == 1 indicates that a client is following */ |
cb9f5f50d3c7
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
175 |
NetworkSend_uint8(packet, 1); |
cb9f5f50d3c7
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
176 |
NetworkSend_string(packet, ci->client_name); |
cb9f5f50d3c7
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
177 |
NetworkSend_string(packet, ci->unique_id); |
4326
2e2c9d21ed96
(svn r5999) -Feature: change the original date format to a 32 bits format based at the year 0.
rubidium
parents:
4261
diff
changeset
|
178 |
NetworkSend_uint32(packet, ci->join_date); |
638
cb9f5f50d3c7
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
179 |
} |
cb9f5f50d3c7
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
180 |
} |
4880
aac84a9dcd03
(svn r6816) -Codechange: Some coding style, variable localization, const correctness.
Darkvater
parents:
4878
diff
changeset
|
181 |
|
638
cb9f5f50d3c7
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
182 |
/* Also check for the server itself */ |
cb9f5f50d3c7
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
183 |
ci = NetworkFindClientInfoFromIndex(NETWORK_SERVER_INDEX); |
4878
4d4f76a898fd
(svn r6814) -Codechange: For network games ci->client_playas was always p->index + 1. To
Darkvater
parents:
4826
diff
changeset
|
184 |
if (!IsValidPlayer(ci->client_playas)) { |
638
cb9f5f50d3c7
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
185 |
/* The uint8 == 1 indicates that a client is following */ |
cb9f5f50d3c7
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
186 |
NetworkSend_uint8(packet, 1); |
cb9f5f50d3c7
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
187 |
NetworkSend_string(packet, ci->client_name); |
cb9f5f50d3c7
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
188 |
NetworkSend_string(packet, ci->unique_id); |
4326
2e2c9d21ed96
(svn r5999) -Feature: change the original date format to a 32 bits format based at the year 0.
rubidium
parents:
4261
diff
changeset
|
189 |
NetworkSend_uint32(packet, ci->join_date); |
638
cb9f5f50d3c7
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
190 |
} |
cb9f5f50d3c7
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
191 |
|
cb9f5f50d3c7
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
192 |
/* Indicates end of client list */ |
cb9f5f50d3c7
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
193 |
NetworkSend_uint8(packet, 0); |
cb9f5f50d3c7
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
194 |
|
5619
9f5a7152403a
(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:
5587
diff
changeset
|
195 |
this->SendPacket(packet, client_addr); |
638
cb9f5f50d3c7
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
196 |
free(packet); |
cb9f5f50d3c7
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
197 |
} |
cb9f5f50d3c7
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
198 |
|
5339
96ac3f4933bb
(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 |
/** |
96ac3f4933bb
(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 |
* A client has requested the names of some NewGRFs. |
96ac3f4933bb
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5034
diff
changeset
|
201 |
* |
96ac3f4933bb
(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 |
* Replying this can be tricky as we have a limit of SEND_MTU bytes |
96ac3f4933bb
(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 |
* in the reply packet and we can send up to 100 bytes per NewGRF |
96ac3f4933bb
(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 |
* (GRF ID, MD5sum and NETWORK_GRF_NAME_LENGTH bytes for the name). |
96ac3f4933bb
(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 |
* As SEND_MTU is _much_ less than 100 * NETWORK_MAX_GRF_COUNT, it |
96ac3f4933bb
(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 |
* could be that a packet overflows. To stop this we only reply |
96ac3f4933bb
(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 |
* with the first N NewGRFs so that if the first N + 1 NewGRFs |
96ac3f4933bb
(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 |
* would be sent, the packet overflows. |
96ac3f4933bb
(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 |
* in_reply and in_reply_count are used to keep a list of GRFs to |
96ac3f4933bb
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5034
diff
changeset
|
210 |
* send in the reply. |
96ac3f4933bb
(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 |
*/ |
5619
9f5a7152403a
(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:
5587
diff
changeset
|
212 |
DEF_UDP_RECEIVE_COMMAND(Server, PACKET_UDP_CLIENT_GET_NEWGRFS) |
5339
96ac3f4933bb
(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 |
{ |
96ac3f4933bb
(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 |
uint8 num_grfs; |
96ac3f4933bb
(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 |
uint i; |
96ac3f4933bb
(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 |
|
96ac3f4933bb
(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 *in_reply[NETWORK_MAX_GRF_COUNT]; |
96ac3f4933bb
(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 |
Packet *packet; |
96ac3f4933bb
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5034
diff
changeset
|
219 |
uint8 in_reply_count = 0; |
96ac3f4933bb
(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 |
uint packet_len = 0; |
96ac3f4933bb
(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 |
|
5380
8ea58542b6e0
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5341
diff
changeset
|
222 |
DEBUG(net, 6, "[udp] newgrf data request from %s:%d", inet_ntoa(client_addr->sin_addr), ntohs(client_addr->sin_port)); |
5339
96ac3f4933bb
(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 |
|
5619
9f5a7152403a
(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:
5587
diff
changeset
|
224 |
num_grfs = NetworkRecv_uint8 (&this->cs, p); |
5339
96ac3f4933bb
(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 (num_grfs > NETWORK_MAX_GRF_COUNT) return; |
96ac3f4933bb
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5034
diff
changeset
|
226 |
|
96ac3f4933bb
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5034
diff
changeset
|
227 |
for (i = 0; i < num_grfs; i++) { |
96ac3f4933bb
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5034
diff
changeset
|
228 |
GRFConfig c; |
96ac3f4933bb
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5034
diff
changeset
|
229 |
const GRFConfig *f; |
96ac3f4933bb
(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 |
|
5619
9f5a7152403a
(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:
5587
diff
changeset
|
231 |
this->Recv_GRFIdentifier(p, &c); |
5339
96ac3f4933bb
(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 |
|
96ac3f4933bb
(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 |
/* Find the matching GRF file */ |
96ac3f4933bb
(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 |
f = FindGRFConfig(c.grfid, c.md5sum); |
96ac3f4933bb
(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 |
if (f == NULL) continue; // The GRF is unknown to this server |
96ac3f4933bb
(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 |
|
96ac3f4933bb
(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 the reply might exceed the size of the packet, only reply |
5341
02fb6f89fc8a
(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
|
238 |
* the current list and do not send the other data. |
02fb6f89fc8a
(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
|
239 |
* The name could be an empty string, if so take the filename. */ |
02fb6f89fc8a
(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
|
240 |
packet_len += sizeof(c.grfid) + sizeof(c.md5sum) + |
5587
167d9a91ef02
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5584
diff
changeset
|
241 |
min(strlen((f->name != NULL && strlen(f->name) > 0) ? f->name : f->filename) + 1, (size_t)NETWORK_GRF_NAME_LENGTH); |
5339
96ac3f4933bb
(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 |
if (packet_len > SEND_MTU - 4) { // 4 is 3 byte header + grf count in reply |
96ac3f4933bb
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5034
diff
changeset
|
243 |
break; |
96ac3f4933bb
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5034
diff
changeset
|
244 |
} |
96ac3f4933bb
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5034
diff
changeset
|
245 |
in_reply[in_reply_count] = f; |
96ac3f4933bb
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5034
diff
changeset
|
246 |
in_reply_count++; |
96ac3f4933bb
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5034
diff
changeset
|
247 |
} |
96ac3f4933bb
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5034
diff
changeset
|
248 |
|
96ac3f4933bb
(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 |
if (in_reply_count == 0) return; |
96ac3f4933bb
(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 |
|
96ac3f4933bb
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5034
diff
changeset
|
251 |
packet = NetworkSend_Init(PACKET_UDP_SERVER_NEWGRFS); |
96ac3f4933bb
(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 |
NetworkSend_uint8 (packet, in_reply_count); |
96ac3f4933bb
(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 |
for (i = 0; i < in_reply_count; i++) { |
96ac3f4933bb
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5034
diff
changeset
|
254 |
char name[NETWORK_GRF_NAME_LENGTH]; |
5341
02fb6f89fc8a
(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
|
255 |
|
02fb6f89fc8a
(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
|
256 |
/* The name could be an empty string, if so take the filename */ |
02fb6f89fc8a
(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
|
257 |
ttd_strlcpy(name, (in_reply[i]->name != NULL && strlen(in_reply[i]->name) > 0) ? |
02fb6f89fc8a
(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
|
258 |
in_reply[i]->name : in_reply[i]->filename, sizeof(name)); |
5619
9f5a7152403a
(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:
5587
diff
changeset
|
259 |
this->Send_GRFIdentifier(packet, in_reply[i]); |
5339
96ac3f4933bb
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5034
diff
changeset
|
260 |
NetworkSend_string(packet, name); |
96ac3f4933bb
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5034
diff
changeset
|
261 |
} |
96ac3f4933bb
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5034
diff
changeset
|
262 |
|
5619
9f5a7152403a
(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:
5587
diff
changeset
|
263 |
this->SendPacket(packet, client_addr); |
5339
96ac3f4933bb
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5034
diff
changeset
|
264 |
free(packet); |
96ac3f4933bb
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5034
diff
changeset
|
265 |
} |
96ac3f4933bb
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5034
diff
changeset
|
266 |
|
5619
9f5a7152403a
(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:
5587
diff
changeset
|
267 |
///*** Communication with servers (we are client) ***/ |
9f5a7152403a
(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:
5587
diff
changeset
|
268 |
|
9f5a7152403a
(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:
5587
diff
changeset
|
269 |
class ClientNetworkUDPSocketHandler : public NetworkUDPSocketHandler { |
9f5a7152403a
(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:
5587
diff
changeset
|
270 |
protected: |
9f5a7152403a
(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:
5587
diff
changeset
|
271 |
DECLARE_UDP_RECEIVE_COMMAND(PACKET_UDP_SERVER_RESPONSE); |
9f5a7152403a
(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:
5587
diff
changeset
|
272 |
DECLARE_UDP_RECEIVE_COMMAND(PACKET_UDP_MASTER_RESPONSE_LIST); |
9f5a7152403a
(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:
5587
diff
changeset
|
273 |
DECLARE_UDP_RECEIVE_COMMAND(PACKET_UDP_SERVER_NEWGRFS); |
9f5a7152403a
(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:
5587
diff
changeset
|
274 |
virtual void HandleIncomingNetworkGameInfoGRFConfig(GRFConfig *config); |
9f5a7152403a
(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:
5587
diff
changeset
|
275 |
public: |
9f5a7152403a
(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:
5587
diff
changeset
|
276 |
virtual ~ClientNetworkUDPSocketHandler() {} |
9f5a7152403a
(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:
5587
diff
changeset
|
277 |
}; |
9f5a7152403a
(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:
5587
diff
changeset
|
278 |
|
9f5a7152403a
(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:
5587
diff
changeset
|
279 |
DEF_UDP_RECEIVE_COMMAND(Client, PACKET_UDP_SERVER_RESPONSE) |
9f5a7152403a
(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:
5587
diff
changeset
|
280 |
{ |
9f5a7152403a
(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:
5587
diff
changeset
|
281 |
extern const char _openttd_revision[]; |
9f5a7152403a
(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:
5587
diff
changeset
|
282 |
NetworkGameList *item; |
9f5a7152403a
(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:
5587
diff
changeset
|
283 |
|
9f5a7152403a
(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:
5587
diff
changeset
|
284 |
// Just a fail-safe.. should never happen |
9f5a7152403a
(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:
5587
diff
changeset
|
285 |
if (_network_udp_server) return; |
9f5a7152403a
(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:
5587
diff
changeset
|
286 |
|
9f5a7152403a
(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:
5587
diff
changeset
|
287 |
DEBUG(net, 4, "[udp] server response from %s:%d", inet_ntoa(client_addr->sin_addr), ntohs(client_addr->sin_port)); |
9f5a7152403a
(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:
5587
diff
changeset
|
288 |
|
9f5a7152403a
(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:
5587
diff
changeset
|
289 |
// Find next item |
9f5a7152403a
(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:
5587
diff
changeset
|
290 |
item = NetworkGameListAddItem(inet_addr(inet_ntoa(client_addr->sin_addr)), ntohs(client_addr->sin_port)); |
9f5a7152403a
(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:
5587
diff
changeset
|
291 |
|
9f5a7152403a
(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:
5587
diff
changeset
|
292 |
this->Recv_NetworkGameInfo(p, &item->info); |
9f5a7152403a
(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:
5587
diff
changeset
|
293 |
|
9f5a7152403a
(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:
5587
diff
changeset
|
294 |
item->info.compatible = true; |
9f5a7152403a
(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:
5587
diff
changeset
|
295 |
{ |
9f5a7152403a
(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:
5587
diff
changeset
|
296 |
/* Checks whether there needs to be a request for names of GRFs and makes |
9f5a7152403a
(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:
5587
diff
changeset
|
297 |
* the request if necessary. GRFs that need to be requested are the GRFs |
9f5a7152403a
(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:
5587
diff
changeset
|
298 |
* that do not exist on the clients system and we do not have the name |
9f5a7152403a
(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:
5587
diff
changeset
|
299 |
* resolved of, i.e. the name is still UNKNOWN_GRF_NAME_PLACEHOLDER. |
9f5a7152403a
(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:
5587
diff
changeset
|
300 |
* The in_request array and in_request_count are used so there is no need |
9f5a7152403a
(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:
5587
diff
changeset
|
301 |
* to do a second loop over the GRF list, which can be relatively expensive |
9f5a7152403a
(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:
5587
diff
changeset
|
302 |
* due to the string comparisons. */ |
9f5a7152403a
(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:
5587
diff
changeset
|
303 |
const GRFConfig *in_request[NETWORK_MAX_GRF_COUNT]; |
9f5a7152403a
(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:
5587
diff
changeset
|
304 |
const GRFConfig *c; |
9f5a7152403a
(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:
5587
diff
changeset
|
305 |
uint in_request_count = 0; |
9f5a7152403a
(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:
5587
diff
changeset
|
306 |
struct sockaddr_in out_addr; |
9f5a7152403a
(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:
5587
diff
changeset
|
307 |
|
9f5a7152403a
(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:
5587
diff
changeset
|
308 |
for (c = item->info.grfconfig; c != NULL; c = c->next) { |
9f5a7152403a
(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:
5587
diff
changeset
|
309 |
if (HASBIT(c->flags, GCF_NOT_FOUND)) item->info.compatible = false; |
9f5a7152403a
(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:
5587
diff
changeset
|
310 |
if (!HASBIT(c->flags, GCF_NOT_FOUND) || strcmp(c->name, UNKNOWN_GRF_NAME_PLACEHOLDER) != 0) continue; |
9f5a7152403a
(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:
5587
diff
changeset
|
311 |
in_request[in_request_count] = c; |
9f5a7152403a
(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:
5587
diff
changeset
|
312 |
in_request_count++; |
9f5a7152403a
(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:
5587
diff
changeset
|
313 |
} |
9f5a7152403a
(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:
5587
diff
changeset
|
314 |
|
9f5a7152403a
(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:
5587
diff
changeset
|
315 |
if (in_request_count > 0) { |
9f5a7152403a
(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:
5587
diff
changeset
|
316 |
/* There are 'unknown' GRFs, now send a request for them */ |
9f5a7152403a
(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:
5587
diff
changeset
|
317 |
uint i; |
9f5a7152403a
(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:
5587
diff
changeset
|
318 |
Packet *packet = NetworkSend_Init(PACKET_UDP_CLIENT_GET_NEWGRFS); |
9f5a7152403a
(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:
5587
diff
changeset
|
319 |
|
9f5a7152403a
(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:
5587
diff
changeset
|
320 |
NetworkSend_uint8 (packet, in_request_count); |
9f5a7152403a
(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:
5587
diff
changeset
|
321 |
for (i = 0; i < in_request_count; i++) { |
9f5a7152403a
(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:
5587
diff
changeset
|
322 |
this->Send_GRFIdentifier(packet, in_request[i]); |
9f5a7152403a
(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:
5587
diff
changeset
|
323 |
} |
9f5a7152403a
(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:
5587
diff
changeset
|
324 |
|
9f5a7152403a
(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:
5587
diff
changeset
|
325 |
out_addr.sin_family = AF_INET; |
9f5a7152403a
(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:
5587
diff
changeset
|
326 |
out_addr.sin_port = htons(item->port); |
9f5a7152403a
(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:
5587
diff
changeset
|
327 |
out_addr.sin_addr.s_addr = item->ip; |
9f5a7152403a
(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:
5587
diff
changeset
|
328 |
this->SendPacket(packet, &out_addr); |
9f5a7152403a
(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:
5587
diff
changeset
|
329 |
free(packet); |
9f5a7152403a
(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:
5587
diff
changeset
|
330 |
} |
9f5a7152403a
(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:
5587
diff
changeset
|
331 |
} |
9f5a7152403a
(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:
5587
diff
changeset
|
332 |
|
9f5a7152403a
(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:
5587
diff
changeset
|
333 |
if (item->info.server_lang >= NETWORK_NUM_LANGUAGES) item->info.server_lang = 0; |
9f5a7152403a
(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:
5587
diff
changeset
|
334 |
if (item->info.map_set >= NUM_LANDSCAPE ) item->info.map_set = 0; |
9f5a7152403a
(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:
5587
diff
changeset
|
335 |
|
9f5a7152403a
(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:
5587
diff
changeset
|
336 |
if (item->info.hostname[0] == '\0') |
9f5a7152403a
(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:
5587
diff
changeset
|
337 |
snprintf(item->info.hostname, sizeof(item->info.hostname), "%s", inet_ntoa(client_addr->sin_addr)); |
9f5a7152403a
(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:
5587
diff
changeset
|
338 |
|
9f5a7152403a
(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:
5587
diff
changeset
|
339 |
/* Check if we are allowed on this server based on the revision-match */ |
9f5a7152403a
(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:
5587
diff
changeset
|
340 |
item->info.version_compatible = |
9f5a7152403a
(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:
5587
diff
changeset
|
341 |
strcmp(item->info.server_revision, _openttd_revision) == 0 || |
9f5a7152403a
(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:
5587
diff
changeset
|
342 |
strcmp(item->info.server_revision, NOREV_STRING) == 0; |
9f5a7152403a
(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:
5587
diff
changeset
|
343 |
item->info.compatible &= item->info.version_compatible; // Already contains match for GRFs |
9f5a7152403a
(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:
5587
diff
changeset
|
344 |
|
9f5a7152403a
(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:
5587
diff
changeset
|
345 |
item->online = true; |
9f5a7152403a
(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:
5587
diff
changeset
|
346 |
|
9f5a7152403a
(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:
5587
diff
changeset
|
347 |
UpdateNetworkGameWindow(false); |
9f5a7152403a
(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:
5587
diff
changeset
|
348 |
} |
9f5a7152403a
(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:
5587
diff
changeset
|
349 |
|
9f5a7152403a
(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:
5587
diff
changeset
|
350 |
DEF_UDP_RECEIVE_COMMAND(Client, PACKET_UDP_MASTER_RESPONSE_LIST) |
9f5a7152403a
(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:
5587
diff
changeset
|
351 |
{ |
9f5a7152403a
(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:
5587
diff
changeset
|
352 |
int i; |
9f5a7152403a
(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:
5587
diff
changeset
|
353 |
struct in_addr ip; |
9f5a7152403a
(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:
5587
diff
changeset
|
354 |
uint16 port; |
9f5a7152403a
(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:
5587
diff
changeset
|
355 |
uint8 ver; |
9f5a7152403a
(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:
5587
diff
changeset
|
356 |
|
9f5a7152403a
(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:
5587
diff
changeset
|
357 |
/* packet begins with the protocol version (uint8) |
9f5a7152403a
(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:
5587
diff
changeset
|
358 |
* then an uint16 which indicates how many |
9f5a7152403a
(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:
5587
diff
changeset
|
359 |
* ip:port pairs are in this packet, after that |
9f5a7152403a
(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:
5587
diff
changeset
|
360 |
* an uint32 (ip) and an uint16 (port) for each pair |
9f5a7152403a
(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:
5587
diff
changeset
|
361 |
*/ |
9f5a7152403a
(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:
5587
diff
changeset
|
362 |
|
9f5a7152403a
(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:
5587
diff
changeset
|
363 |
ver = NetworkRecv_uint8(&this->cs, p); |
9f5a7152403a
(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:
5587
diff
changeset
|
364 |
|
9f5a7152403a
(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:
5587
diff
changeset
|
365 |
if (this->cs.has_quit) return; |
9f5a7152403a
(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:
5587
diff
changeset
|
366 |
|
9f5a7152403a
(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:
5587
diff
changeset
|
367 |
if (ver == 1) { |
9f5a7152403a
(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:
5587
diff
changeset
|
368 |
for (i = NetworkRecv_uint16(&this->cs, p); i != 0 ; i--) { |
9f5a7152403a
(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:
5587
diff
changeset
|
369 |
ip.s_addr = TO_LE32(NetworkRecv_uint32(&this->cs, p)); |
9f5a7152403a
(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:
5587
diff
changeset
|
370 |
port = NetworkRecv_uint16(&this->cs, p); |
9f5a7152403a
(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:
5587
diff
changeset
|
371 |
NetworkUDPQueryServer(inet_ntoa(ip), port); |
9f5a7152403a
(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:
5587
diff
changeset
|
372 |
} |
9f5a7152403a
(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:
5587
diff
changeset
|
373 |
} |
9f5a7152403a
(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:
5587
diff
changeset
|
374 |
} |
9f5a7152403a
(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:
5587
diff
changeset
|
375 |
|
5339
96ac3f4933bb
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5034
diff
changeset
|
376 |
/** The return of the client's request of the names of some NewGRFs */ |
5619
9f5a7152403a
(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:
5587
diff
changeset
|
377 |
DEF_UDP_RECEIVE_COMMAND(Client, PACKET_UDP_SERVER_NEWGRFS) |
5339
96ac3f4933bb
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5034
diff
changeset
|
378 |
{ |
96ac3f4933bb
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5034
diff
changeset
|
379 |
uint8 num_grfs; |
96ac3f4933bb
(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 |
uint i; |
96ac3f4933bb
(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 |
|
5619
9f5a7152403a
(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:
5587
diff
changeset
|
382 |
DEBUG(net, 6, "[udp] newgrf data reply from %s:%d", inet_ntoa(client_addr->sin_addr), ntohs(client_addr->sin_port)); |
5339
96ac3f4933bb
(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 |
|
5619
9f5a7152403a
(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:
5587
diff
changeset
|
384 |
num_grfs = NetworkRecv_uint8 (&this->cs, p); |
5339
96ac3f4933bb
(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 |
if (num_grfs > NETWORK_MAX_GRF_COUNT) return; |
96ac3f4933bb
(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 |
|
96ac3f4933bb
(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 |
for (i = 0; i < num_grfs; i++) { |
96ac3f4933bb
(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 |
char *unknown_name; |
96ac3f4933bb
(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 |
char name[NETWORK_GRF_NAME_LENGTH]; |
96ac3f4933bb
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5034
diff
changeset
|
390 |
GRFConfig c; |
96ac3f4933bb
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5034
diff
changeset
|
391 |
|
5619
9f5a7152403a
(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:
5587
diff
changeset
|
392 |
this->Recv_GRFIdentifier(p, &c); |
9f5a7152403a
(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:
5587
diff
changeset
|
393 |
NetworkRecv_string(&this->cs, p, name, sizeof(name)); |
5339
96ac3f4933bb
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5034
diff
changeset
|
394 |
|
5341
02fb6f89fc8a
(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
|
395 |
/* An empty name is not possible under normal circumstances |
02fb6f89fc8a
(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
|
396 |
* and causes problems when showing the NewGRF list. */ |
02fb6f89fc8a
(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
|
397 |
if (strlen(name) == 0) continue; |
02fb6f89fc8a
(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
|
398 |
|
5339
96ac3f4933bb
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5034
diff
changeset
|
399 |
/* Finds the fake GRFConfig for the just read GRF ID and MD5sum tuple. |
96ac3f4933bb
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5034
diff
changeset
|
400 |
* If it exists and not resolved yet, then name of the fake GRF is |
96ac3f4933bb
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5034
diff
changeset
|
401 |
* overwritten with the name from the reply. */ |
96ac3f4933bb
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5034
diff
changeset
|
402 |
unknown_name = FindUnknownGRFName(c.grfid, c.md5sum, false); |
96ac3f4933bb
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5034
diff
changeset
|
403 |
if (unknown_name != NULL && strcmp(unknown_name, UNKNOWN_GRF_NAME_PLACEHOLDER) == 0) { |
96ac3f4933bb
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5034
diff
changeset
|
404 |
ttd_strlcpy(unknown_name, name, NETWORK_GRF_NAME_LENGTH); |
96ac3f4933bb
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5034
diff
changeset
|
405 |
} |
96ac3f4933bb
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5034
diff
changeset
|
406 |
} |
96ac3f4933bb
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5034
diff
changeset
|
407 |
} |
96ac3f4933bb
(svn r7505) -Feature: show NewGRFs used on a game server, show which NewGRFs you do and do not have.
rubidium
parents:
5034
diff
changeset
|
408 |
|
5619
9f5a7152403a
(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:
5587
diff
changeset
|
409 |
void ClientNetworkUDPSocketHandler::HandleIncomingNetworkGameInfoGRFConfig(GRFConfig *config) |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
410 |
{ |
5619
9f5a7152403a
(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:
5587
diff
changeset
|
411 |
/* Find the matching GRF file */ |
9f5a7152403a
(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:
5587
diff
changeset
|
412 |
const GRFConfig *f = FindGRFConfig(config->grfid, config->md5sum); |
9f5a7152403a
(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:
5587
diff
changeset
|
413 |
if (f == NULL) { |
9f5a7152403a
(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:
5587
diff
changeset
|
414 |
/* Don't know the GRF, so mark game incompatible and the (possibly) |
9f5a7152403a
(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:
5587
diff
changeset
|
415 |
* already resolved name for this GRF (another server has sent the |
9f5a7152403a
(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:
5587
diff
changeset
|
416 |
* name of the GRF already */ |
9f5a7152403a
(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:
5587
diff
changeset
|
417 |
config->name = FindUnknownGRFName(config->grfid, config->md5sum, true); |
9f5a7152403a
(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:
5587
diff
changeset
|
418 |
SETBIT(config->flags, GCF_NOT_FOUND); |
3547
fea14ff86f9e
(svn r4413) -Fix: fixed a bug which pushed the client back to the main menu when a
truelight
parents:
3456
diff
changeset
|
419 |
} else { |
5619
9f5a7152403a
(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:
5587
diff
changeset
|
420 |
config->filename = f->filename; |
9f5a7152403a
(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:
5587
diff
changeset
|
421 |
config->name = f->name; |
9f5a7152403a
(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:
5587
diff
changeset
|
422 |
config->info = f->info; |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
423 |
} |
5619
9f5a7152403a
(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:
5587
diff
changeset
|
424 |
SETBIT(config->flags, GCF_COPY); |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
425 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
426 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
427 |
// Close UDP connection |
5619
9f5a7152403a
(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:
5587
diff
changeset
|
428 |
void NetworkUDPCloseAll(void) |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
429 |
{ |
5380
8ea58542b6e0
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5341
diff
changeset
|
430 |
DEBUG(net, 1, "[udp] closed listeners"); |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
431 |
|
5619
9f5a7152403a
(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:
5587
diff
changeset
|
432 |
_udp_server_socket->Close(); |
9f5a7152403a
(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:
5587
diff
changeset
|
433 |
_udp_master_socket->Close(); |
9f5a7152403a
(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:
5587
diff
changeset
|
434 |
_udp_client_socket->Close(); |
764
7e1e17b7c7d4
(svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents:
738
diff
changeset
|
435 |
|
5521
53a834d67956
(svn r7825) -Codechange: make NetworkUDPClose close a single UDP socket. Use NetworkUDPStop to close all opened udp sockets (those were called NetworkUDPClose).
rubidium
parents:
5519
diff
changeset
|
436 |
_network_udp_server = false; |
53a834d67956
(svn r7825) -Codechange: make NetworkUDPClose close a single UDP socket. Use NetworkUDPStop to close all opened udp sockets (those were called NetworkUDPClose).
rubidium
parents:
5519
diff
changeset
|
437 |
_network_udp_broadcast = 0; |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
438 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
439 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
440 |
// Broadcast to all ips |
5619
9f5a7152403a
(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:
5587
diff
changeset
|
441 |
static void NetworkUDPBroadCast(NetworkUDPSocketHandler *socket) |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
442 |
{ |
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4035
diff
changeset
|
443 |
Packet* p = NetworkSend_Init(PACKET_UDP_CLIENT_FIND_SERVER); |
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4035
diff
changeset
|
444 |
uint i; |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
445 |
|
4077
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4035
diff
changeset
|
446 |
for (i = 0; _broadcast_list[i] != 0; i++) { |
d4d440dd8925
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4035
diff
changeset
|
447 |
struct sockaddr_in out_addr; |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
448 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
449 |
out_addr.sin_family = AF_INET; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
450 |
out_addr.sin_port = htons(_network_server_port); |
4034
581c6cb62e72
(svn r5293) -Fix: Not all network interfaces are capable of broadcasting. Don't record those which aren't
tron
parents:
4026
diff
changeset
|
451 |
out_addr.sin_addr.s_addr = _broadcast_list[i]; |
581c6cb62e72
(svn r5293) -Fix: Not all network interfaces are capable of broadcasting. Don't record those which aren't
tron
parents:
4026
diff
changeset
|
452 |
|
5380
8ea58542b6e0
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5341
diff
changeset
|
453 |
DEBUG(net, 4, "[udp] broadcasting to %s", inet_ntoa(out_addr.sin_addr)); |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
454 |
|
5619
9f5a7152403a
(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:
5587
diff
changeset
|
455 |
socket->SendPacket(p, &out_addr); |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
456 |
} |
4035 | 457 |
|
458 |
free(p); |
|
764
7e1e17b7c7d4
(svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents:
738
diff
changeset
|
459 |
} |
7e1e17b7c7d4
(svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents:
738
diff
changeset
|
460 |
|
7e1e17b7c7d4
(svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents:
738
diff
changeset
|
461 |
|
7e1e17b7c7d4
(svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents:
738
diff
changeset
|
462 |
// Request the the server-list from the master server |
7e1e17b7c7d4
(svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents:
738
diff
changeset
|
463 |
void NetworkUDPQueryMasterServer(void) |
7e1e17b7c7d4
(svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents:
738
diff
changeset
|
464 |
{ |
7e1e17b7c7d4
(svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents:
738
diff
changeset
|
465 |
struct sockaddr_in out_addr; |
7e1e17b7c7d4
(svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents:
738
diff
changeset
|
466 |
Packet *p; |
7e1e17b7c7d4
(svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents:
738
diff
changeset
|
467 |
|
5619
9f5a7152403a
(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:
5587
diff
changeset
|
468 |
if (!_udp_client_socket->IsListening()) { |
9f5a7152403a
(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:
5587
diff
changeset
|
469 |
if (!_udp_client_socket->Listen(0, 0, true)) return; |
9f5a7152403a
(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:
5587
diff
changeset
|
470 |
} |
764
7e1e17b7c7d4
(svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents:
738
diff
changeset
|
471 |
|
7e1e17b7c7d4
(svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents:
738
diff
changeset
|
472 |
p = NetworkSend_Init(PACKET_UDP_CLIENT_GET_LIST); |
7e1e17b7c7d4
(svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents:
738
diff
changeset
|
473 |
|
7e1e17b7c7d4
(svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents:
738
diff
changeset
|
474 |
out_addr.sin_family = AF_INET; |
7e1e17b7c7d4
(svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents:
738
diff
changeset
|
475 |
out_addr.sin_port = htons(NETWORK_MASTER_SERVER_PORT); |
7e1e17b7c7d4
(svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents:
738
diff
changeset
|
476 |
out_addr.sin_addr.s_addr = NetworkResolveHost(NETWORK_MASTER_SERVER_HOST); |
7e1e17b7c7d4
(svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents:
738
diff
changeset
|
477 |
|
7e1e17b7c7d4
(svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents:
738
diff
changeset
|
478 |
// packet only contains protocol version |
7e1e17b7c7d4
(svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents:
738
diff
changeset
|
479 |
NetworkSend_uint8(p, NETWORK_MASTER_SERVER_VERSION); |
7e1e17b7c7d4
(svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents:
738
diff
changeset
|
480 |
|
5619
9f5a7152403a
(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:
5587
diff
changeset
|
481 |
_udp_client_socket->SendPacket(p, &out_addr); |
764
7e1e17b7c7d4
(svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents:
738
diff
changeset
|
482 |
|
5380
8ea58542b6e0
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5341
diff
changeset
|
483 |
DEBUG(net, 2, "[udp] master server queried at %s:%d", inet_ntoa(out_addr.sin_addr),ntohs(out_addr.sin_port)); |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
484 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
485 |
free(p); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
486 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
487 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
488 |
// Find all servers |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
489 |
void NetworkUDPSearchGame(void) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
490 |
{ |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
491 |
// We are still searching.. |
5380
8ea58542b6e0
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5341
diff
changeset
|
492 |
if (_network_udp_broadcast > 0) return; |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
493 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
494 |
// No UDP-socket yet.. |
5619
9f5a7152403a
(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:
5587
diff
changeset
|
495 |
if (!_udp_client_socket->IsListening()) { |
9f5a7152403a
(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:
5587
diff
changeset
|
496 |
if (!_udp_client_socket->Listen(0, 0, true)) return; |
9f5a7152403a
(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:
5587
diff
changeset
|
497 |
} |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
498 |
|
5380
8ea58542b6e0
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5341
diff
changeset
|
499 |
DEBUG(net, 0, "[udp] searching server"); |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
500 |
|
764
7e1e17b7c7d4
(svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents:
738
diff
changeset
|
501 |
NetworkUDPBroadCast(_udp_client_socket); |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
502 |
_network_udp_broadcast = 300; // Stay searching for 300 ticks |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
503 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
504 |
|
1329 | 505 |
NetworkGameList *NetworkUDPQueryServer(const char* host, unsigned short port) |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
506 |
{ |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
507 |
struct sockaddr_in out_addr; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
508 |
Packet *p; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
509 |
NetworkGameList *item; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
510 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
511 |
// No UDP-socket yet.. |
5619
9f5a7152403a
(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:
5587
diff
changeset
|
512 |
if (!_udp_client_socket->IsListening()) { |
9f5a7152403a
(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:
5587
diff
changeset
|
513 |
if (!_udp_client_socket->Listen(0, 0, true)) return NULL; |
9f5a7152403a
(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:
5587
diff
changeset
|
514 |
} |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
515 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
516 |
out_addr.sin_family = AF_INET; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
517 |
out_addr.sin_port = htons(port); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
518 |
out_addr.sin_addr.s_addr = NetworkResolveHost(host); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
519 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
520 |
// Clear item in gamelist |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
521 |
item = NetworkGameListAddItem(inet_addr(inet_ntoa(out_addr.sin_addr)), ntohs(out_addr.sin_port)); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
522 |
memset(&item->info, 0, sizeof(item->info)); |
3550
1c07423d9bf2
(svn r4416) Remove a pointless buffer copy and use strlcpy() instead of snprintf("%s")
tron
parents:
3547
diff
changeset
|
523 |
ttd_strlcpy(item->info.server_name, host, lengthof(item->info.server_name)); |
1c07423d9bf2
(svn r4416) Remove a pointless buffer copy and use strlcpy() instead of snprintf("%s")
tron
parents:
3547
diff
changeset
|
524 |
ttd_strlcpy(item->info.hostname, host, lengthof(item->info.hostname)); |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
525 |
item->online = false; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
526 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
527 |
// Init the packet |
638
cb9f5f50d3c7
(svn r1069) -Add: [Network] Added UDP-packet for detail info about a server for
truelight
parents:
629
diff
changeset
|
528 |
p = NetworkSend_Init(PACKET_UDP_CLIENT_FIND_SERVER); |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
529 |
|
5619
9f5a7152403a
(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:
5587
diff
changeset
|
530 |
_udp_client_socket->SendPacket(p, &out_addr); |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
531 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
532 |
free(p); |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
533 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
534 |
UpdateNetworkGameWindow(false); |
738
b96ab9e63d22
(svn r1194) Feature: You can now add and remove servers from the server list. Those will be remembered until you delete them by pressing the Delete key.
dominik
parents:
716
diff
changeset
|
535 |
return item; |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
536 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
537 |
|
765
18104986675d
(svn r1228) -Add: [Network] When a server normally shuts down, it removed itself
truelight
parents:
764
diff
changeset
|
538 |
/* Remove our advertise from the master-server */ |
18104986675d
(svn r1228) -Add: [Network] When a server normally shuts down, it removed itself
truelight
parents:
764
diff
changeset
|
539 |
void NetworkUDPRemoveAdvertise(void) |
18104986675d
(svn r1228) -Add: [Network] When a server normally shuts down, it removed itself
truelight
parents:
764
diff
changeset
|
540 |
{ |
18104986675d
(svn r1228) -Add: [Network] When a server normally shuts down, it removed itself
truelight
parents:
764
diff
changeset
|
541 |
struct sockaddr_in out_addr; |
18104986675d
(svn r1228) -Add: [Network] When a server normally shuts down, it removed itself
truelight
parents:
764
diff
changeset
|
542 |
Packet *p; |
18104986675d
(svn r1228) -Add: [Network] When a server normally shuts down, it removed itself
truelight
parents:
764
diff
changeset
|
543 |
|
18104986675d
(svn r1228) -Add: [Network] When a server normally shuts down, it removed itself
truelight
parents:
764
diff
changeset
|
544 |
/* Check if we are advertising */ |
5380
8ea58542b6e0
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5341
diff
changeset
|
545 |
if (!_networking || !_network_server || !_network_udp_server) return; |
765
18104986675d
(svn r1228) -Add: [Network] When a server normally shuts down, it removed itself
truelight
parents:
764
diff
changeset
|
546 |
|
18104986675d
(svn r1228) -Add: [Network] When a server normally shuts down, it removed itself
truelight
parents:
764
diff
changeset
|
547 |
/* check for socket */ |
5619
9f5a7152403a
(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:
5587
diff
changeset
|
548 |
if (!_udp_master_socket->IsListening()) { |
9f5a7152403a
(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:
5587
diff
changeset
|
549 |
if (!_udp_master_socket->Listen(0, 0, false)) return; |
9f5a7152403a
(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:
5587
diff
changeset
|
550 |
} |
765
18104986675d
(svn r1228) -Add: [Network] When a server normally shuts down, it removed itself
truelight
parents:
764
diff
changeset
|
551 |
|
5380
8ea58542b6e0
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5341
diff
changeset
|
552 |
DEBUG(net, 1, "[udp] removing advertise from master server"); |
765
18104986675d
(svn r1228) -Add: [Network] When a server normally shuts down, it removed itself
truelight
parents:
764
diff
changeset
|
553 |
|
18104986675d
(svn r1228) -Add: [Network] When a server normally shuts down, it removed itself
truelight
parents:
764
diff
changeset
|
554 |
/* Find somewhere to send */ |
18104986675d
(svn r1228) -Add: [Network] When a server normally shuts down, it removed itself
truelight
parents:
764
diff
changeset
|
555 |
out_addr.sin_family = AF_INET; |
18104986675d
(svn r1228) -Add: [Network] When a server normally shuts down, it removed itself
truelight
parents:
764
diff
changeset
|
556 |
out_addr.sin_port = htons(NETWORK_MASTER_SERVER_PORT); |
18104986675d
(svn r1228) -Add: [Network] When a server normally shuts down, it removed itself
truelight
parents:
764
diff
changeset
|
557 |
out_addr.sin_addr.s_addr = NetworkResolveHost(NETWORK_MASTER_SERVER_HOST); |
18104986675d
(svn r1228) -Add: [Network] When a server normally shuts down, it removed itself
truelight
parents:
764
diff
changeset
|
558 |
|
18104986675d
(svn r1228) -Add: [Network] When a server normally shuts down, it removed itself
truelight
parents:
764
diff
changeset
|
559 |
/* Send the packet */ |
18104986675d
(svn r1228) -Add: [Network] When a server normally shuts down, it removed itself
truelight
parents:
764
diff
changeset
|
560 |
p = NetworkSend_Init(PACKET_UDP_SERVER_UNREGISTER); |
18104986675d
(svn r1228) -Add: [Network] When a server normally shuts down, it removed itself
truelight
parents:
764
diff
changeset
|
561 |
/* Packet is: Version, server_port */ |
18104986675d
(svn r1228) -Add: [Network] When a server normally shuts down, it removed itself
truelight
parents:
764
diff
changeset
|
562 |
NetworkSend_uint8(p, NETWORK_MASTER_SERVER_VERSION); |
18104986675d
(svn r1228) -Add: [Network] When a server normally shuts down, it removed itself
truelight
parents:
764
diff
changeset
|
563 |
NetworkSend_uint16(p, _network_server_port); |
5619
9f5a7152403a
(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:
5587
diff
changeset
|
564 |
_udp_master_socket->SendPacket(p, &out_addr); |
765
18104986675d
(svn r1228) -Add: [Network] When a server normally shuts down, it removed itself
truelight
parents:
764
diff
changeset
|
565 |
|
18104986675d
(svn r1228) -Add: [Network] When a server normally shuts down, it removed itself
truelight
parents:
764
diff
changeset
|
566 |
free(p); |
18104986675d
(svn r1228) -Add: [Network] When a server normally shuts down, it removed itself
truelight
parents:
764
diff
changeset
|
567 |
} |
18104986675d
(svn r1228) -Add: [Network] When a server normally shuts down, it removed itself
truelight
parents:
764
diff
changeset
|
568 |
|
668
1fe298df8526
(svn r1106) -Add: [Network] Added master-server protocol and advertise to
truelight
parents:
638
diff
changeset
|
569 |
/* Register us to the master server |
1fe298df8526
(svn r1106) -Add: [Network] Added master-server protocol and advertise to
truelight
parents:
638
diff
changeset
|
570 |
This function checks if it needs to send an advertise */ |
716
8af847728d5b
(svn r1168) -Cleanup: [Network] Cleaned the network code a bit. Added 'const'
truelight
parents:
668
diff
changeset
|
571 |
void NetworkUDPAdvertise(void) |
668
1fe298df8526
(svn r1106) -Add: [Network] Added master-server protocol and advertise to
truelight
parents:
638
diff
changeset
|
572 |
{ |
1fe298df8526
(svn r1106) -Add: [Network] Added master-server protocol and advertise to
truelight
parents:
638
diff
changeset
|
573 |
struct sockaddr_in out_addr; |
1fe298df8526
(svn r1106) -Add: [Network] Added master-server protocol and advertise to
truelight
parents:
638
diff
changeset
|
574 |
Packet *p; |
1fe298df8526
(svn r1106) -Add: [Network] Added master-server protocol and advertise to
truelight
parents:
638
diff
changeset
|
575 |
|
1fe298df8526
(svn r1106) -Add: [Network] Added master-server protocol and advertise to
truelight
parents:
638
diff
changeset
|
576 |
/* Check if we should send an advertise */ |
1fe298df8526
(svn r1106) -Add: [Network] Added master-server protocol and advertise to
truelight
parents:
638
diff
changeset
|
577 |
if (!_networking || !_network_server || !_network_udp_server || !_network_advertise) |
1fe298df8526
(svn r1106) -Add: [Network] Added master-server protocol and advertise to
truelight
parents:
638
diff
changeset
|
578 |
return; |
1fe298df8526
(svn r1106) -Add: [Network] Added master-server protocol and advertise to
truelight
parents:
638
diff
changeset
|
579 |
|
764
7e1e17b7c7d4
(svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents:
738
diff
changeset
|
580 |
/* check for socket */ |
5619
9f5a7152403a
(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:
5587
diff
changeset
|
581 |
if (!_udp_master_socket->IsListening()) { |
9f5a7152403a
(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:
5587
diff
changeset
|
582 |
if (!_udp_master_socket->Listen(0, 0, false)) return; |
9f5a7152403a
(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:
5587
diff
changeset
|
583 |
} |
764
7e1e17b7c7d4
(svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents:
738
diff
changeset
|
584 |
|
2861
e42d249af3cb
(svn r3409) - Change the server advertisement interval to use the frame counter instead
peter1138
parents:
2817
diff
changeset
|
585 |
if (_network_need_advertise) { |
e42d249af3cb
(svn r3409) - Change the server advertisement interval to use the frame counter instead
peter1138
parents:
2817
diff
changeset
|
586 |
_network_need_advertise = false; |
e42d249af3cb
(svn r3409) - Change the server advertisement interval to use the frame counter instead
peter1138
parents:
2817
diff
changeset
|
587 |
_network_advertise_retries = ADVERTISE_RETRY_TIMES; |
e42d249af3cb
(svn r3409) - Change the server advertisement interval to use the frame counter instead
peter1138
parents:
2817
diff
changeset
|
588 |
} else { |
e42d249af3cb
(svn r3409) - Change the server advertisement interval to use the frame counter instead
peter1138
parents:
2817
diff
changeset
|
589 |
/* Only send once every ADVERTISE_NORMAL_INTERVAL ticks */ |
e42d249af3cb
(svn r3409) - Change the server advertisement interval to use the frame counter instead
peter1138
parents:
2817
diff
changeset
|
590 |
if (_network_advertise_retries == 0) { |
e42d249af3cb
(svn r3409) - Change the server advertisement interval to use the frame counter instead
peter1138
parents:
2817
diff
changeset
|
591 |
if ((_network_last_advertise_frame + ADVERTISE_NORMAL_INTERVAL) > _frame_counter) |
e42d249af3cb
(svn r3409) - Change the server advertisement interval to use the frame counter instead
peter1138
parents:
2817
diff
changeset
|
592 |
return; |
e42d249af3cb
(svn r3409) - Change the server advertisement interval to use the frame counter instead
peter1138
parents:
2817
diff
changeset
|
593 |
_network_advertise_retries = ADVERTISE_RETRY_TIMES; |
e42d249af3cb
(svn r3409) - Change the server advertisement interval to use the frame counter instead
peter1138
parents:
2817
diff
changeset
|
594 |
} |
e42d249af3cb
(svn r3409) - Change the server advertisement interval to use the frame counter instead
peter1138
parents:
2817
diff
changeset
|
595 |
|
e42d249af3cb
(svn r3409) - Change the server advertisement interval to use the frame counter instead
peter1138
parents:
2817
diff
changeset
|
596 |
if ((_network_last_advertise_frame + ADVERTISE_RETRY_INTERVAL) > _frame_counter) |
764
7e1e17b7c7d4
(svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents:
738
diff
changeset
|
597 |
return; |
7e1e17b7c7d4
(svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents:
738
diff
changeset
|
598 |
} |
7e1e17b7c7d4
(svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents:
738
diff
changeset
|
599 |
|
7e1e17b7c7d4
(svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents:
738
diff
changeset
|
600 |
_network_advertise_retries--; |
2861
e42d249af3cb
(svn r3409) - Change the server advertisement interval to use the frame counter instead
peter1138
parents:
2817
diff
changeset
|
601 |
_network_last_advertise_frame = _frame_counter; |
668
1fe298df8526
(svn r1106) -Add: [Network] Added master-server protocol and advertise to
truelight
parents:
638
diff
changeset
|
602 |
|
1fe298df8526
(svn r1106) -Add: [Network] Added master-server protocol and advertise to
truelight
parents:
638
diff
changeset
|
603 |
/* Find somewhere to send */ |
1fe298df8526
(svn r1106) -Add: [Network] Added master-server protocol and advertise to
truelight
parents:
638
diff
changeset
|
604 |
out_addr.sin_family = AF_INET; |
1fe298df8526
(svn r1106) -Add: [Network] Added master-server protocol and advertise to
truelight
parents:
638
diff
changeset
|
605 |
out_addr.sin_port = htons(NETWORK_MASTER_SERVER_PORT); |
1fe298df8526
(svn r1106) -Add: [Network] Added master-server protocol and advertise to
truelight
parents:
638
diff
changeset
|
606 |
out_addr.sin_addr.s_addr = NetworkResolveHost(NETWORK_MASTER_SERVER_HOST); |
1fe298df8526
(svn r1106) -Add: [Network] Added master-server protocol and advertise to
truelight
parents:
638
diff
changeset
|
607 |
|
5380
8ea58542b6e0
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5341
diff
changeset
|
608 |
DEBUG(net, 1, "[udp] advertising to master server"); |
668
1fe298df8526
(svn r1106) -Add: [Network] Added master-server protocol and advertise to
truelight
parents:
638
diff
changeset
|
609 |
|
1fe298df8526
(svn r1106) -Add: [Network] Added master-server protocol and advertise to
truelight
parents:
638
diff
changeset
|
610 |
/* Send the packet */ |
1fe298df8526
(svn r1106) -Add: [Network] Added master-server protocol and advertise to
truelight
parents:
638
diff
changeset
|
611 |
p = NetworkSend_Init(PACKET_UDP_SERVER_REGISTER); |
1fe298df8526
(svn r1106) -Add: [Network] Added master-server protocol and advertise to
truelight
parents:
638
diff
changeset
|
612 |
/* Packet is: WELCOME_MESSAGE, Version, server_port */ |
1fe298df8526
(svn r1106) -Add: [Network] Added master-server protocol and advertise to
truelight
parents:
638
diff
changeset
|
613 |
NetworkSend_string(p, NETWORK_MASTER_SERVER_WELCOME_MESSAGE); |
1fe298df8526
(svn r1106) -Add: [Network] Added master-server protocol and advertise to
truelight
parents:
638
diff
changeset
|
614 |
NetworkSend_uint8(p, NETWORK_MASTER_SERVER_VERSION); |
1fe298df8526
(svn r1106) -Add: [Network] Added master-server protocol and advertise to
truelight
parents:
638
diff
changeset
|
615 |
NetworkSend_uint16(p, _network_server_port); |
5619
9f5a7152403a
(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:
5587
diff
changeset
|
616 |
_udp_master_socket->SendPacket(p, &out_addr); |
764
7e1e17b7c7d4
(svn r1227) -Add: Ingame Server-list (select Internet, then Find Servers)
truelight
parents:
738
diff
changeset
|
617 |
|
668
1fe298df8526
(svn r1106) -Add: [Network] Added master-server protocol and advertise to
truelight
parents:
638
diff
changeset
|
618 |
free(p); |
1fe298df8526
(svn r1106) -Add: [Network] Added master-server protocol and advertise to
truelight
parents:
638
diff
changeset
|
619 |
} |
1fe298df8526
(svn r1106) -Add: [Network] Added master-server protocol and advertise to
truelight
parents:
638
diff
changeset
|
620 |
|
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
621 |
void NetworkUDPInitialize(void) |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
622 |
{ |
5619
9f5a7152403a
(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:
5587
diff
changeset
|
623 |
_udp_client_socket = new ClientNetworkUDPSocketHandler(); |
9f5a7152403a
(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:
5587
diff
changeset
|
624 |
_udp_server_socket = new ServerNetworkUDPSocketHandler(); |
9f5a7152403a
(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:
5587
diff
changeset
|
625 |
_udp_master_socket = new MasterNetworkUDPSocketHandler(); |
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
626 |
|
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
627 |
_network_udp_server = false; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
628 |
_network_udp_broadcast = 0; |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
629 |
} |
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
630 |
|
5619
9f5a7152403a
(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:
5587
diff
changeset
|
631 |
void NetworkUDPShutdown(void) |
9f5a7152403a
(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:
5587
diff
changeset
|
632 |
{ |
9f5a7152403a
(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:
5587
diff
changeset
|
633 |
NetworkUDPCloseAll(); |
9f5a7152403a
(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:
5587
diff
changeset
|
634 |
|
9f5a7152403a
(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:
5587
diff
changeset
|
635 |
delete _udp_client_socket; |
9f5a7152403a
(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:
5587
diff
changeset
|
636 |
delete _udp_server_socket; |
9f5a7152403a
(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:
5587
diff
changeset
|
637 |
delete _udp_master_socket; |
9f5a7152403a
(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:
5587
diff
changeset
|
638 |
} |
9f5a7152403a
(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:
5587
diff
changeset
|
639 |
|
543
946badd71033
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
640 |
#endif /* ENABLE_NETWORK */ |