mirror of https://github.com/OpenTTD/OpenTTD
(svn r1106) -Add: [Network] Added master-server protocol and advertise to
master-server option. No GUI yet, and disabled by default (it still is WIP)release/0.4.5
parent
d867a845fd
commit
015fb81810
|
@ -871,6 +871,10 @@ bool NetworkServerStart(void)
|
||||||
IConsoleCmdExec("exec scripts/on_server.scr 0");
|
IConsoleCmdExec("exec scripts/on_server.scr 0");
|
||||||
// if the server is dedicated ... add some other script
|
// if the server is dedicated ... add some other script
|
||||||
if (_network_dedicated) IConsoleCmdExec("exec scripts/on_dedicated.scr 0");
|
if (_network_dedicated) IConsoleCmdExec("exec scripts/on_dedicated.scr 0");
|
||||||
|
|
||||||
|
/* Try to register us to the master server */
|
||||||
|
_network_last_advertise_date = 0;
|
||||||
|
NetworkUDPAdvertise();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1163,6 +1167,8 @@ void NetworkStartUp(void)
|
||||||
// Network is available
|
// Network is available
|
||||||
_network_available = true;
|
_network_available = true;
|
||||||
_network_dedicated = false;
|
_network_dedicated = false;
|
||||||
|
_network_advertise = false;
|
||||||
|
_network_last_advertise_date = 0;
|
||||||
|
|
||||||
/* Load the ip from the openttd.cfg */
|
/* Load the ip from the openttd.cfg */
|
||||||
_network_server_bind_ip = inet_addr(_network_server_bind_ip_host);
|
_network_server_bind_ip = inet_addr(_network_server_bind_ip_host);
|
||||||
|
|
|
@ -28,6 +28,11 @@
|
||||||
// Do not change this next line. It should _ALWAYS_ be MAX_CLIENTS + 1
|
// Do not change this next line. It should _ALWAYS_ be MAX_CLIENTS + 1
|
||||||
#define MAX_CLIENT_INFO (MAX_CLIENTS + 1)
|
#define MAX_CLIENT_INFO (MAX_CLIENTS + 1)
|
||||||
|
|
||||||
|
/* Stuff for the master-server */
|
||||||
|
#define NETWORK_MASTER_SERVER_PORT 3978
|
||||||
|
#define NETWORK_MASTER_SERVER_HOST "master.openttd.org"
|
||||||
|
#define NETWORK_MASTER_SERVER_WELCOME_MESSAGE "OpenTTDRegister"
|
||||||
|
|
||||||
#define NETWORK_DEFAULT_PORT 3979
|
#define NETWORK_DEFAULT_PORT 3979
|
||||||
|
|
||||||
#define MAX_INTERFACES 9
|
#define MAX_INTERFACES 9
|
||||||
|
@ -166,6 +171,9 @@ VARDEF uint8 _network_reconnect;
|
||||||
VARDEF bool _network_udp_server;
|
VARDEF bool _network_udp_server;
|
||||||
VARDEF uint16 _network_udp_broadcast;
|
VARDEF uint16 _network_udp_broadcast;
|
||||||
|
|
||||||
|
VARDEF bool _network_advertise;
|
||||||
|
VARDEF uint16 _network_last_advertise_date;
|
||||||
|
|
||||||
#endif /* ENABLE_NETWORK */
|
#endif /* ENABLE_NETWORK */
|
||||||
|
|
||||||
// Those variables must always be registered!
|
// Those variables must always be registered!
|
||||||
|
|
|
@ -18,6 +18,8 @@
|
||||||
#define NETWORK_GAME_INFO_VERSION 1
|
#define NETWORK_GAME_INFO_VERSION 1
|
||||||
// What version of company info is this?
|
// What version of company info is this?
|
||||||
#define NETWORK_COMPANY_INFO_VERSION 1
|
#define NETWORK_COMPANY_INFO_VERSION 1
|
||||||
|
// What version of master-server-protocol do we use?
|
||||||
|
#define NETWORK_MASTER_SERVER_VERSION 1
|
||||||
|
|
||||||
typedef uint16 PacketSize;
|
typedef uint16 PacketSize;
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
|
|
||||||
#include "table/strings.h"
|
#include "table/strings.h"
|
||||||
#include "network_server.h"
|
#include "network_server.h"
|
||||||
|
#include "network_udp.h"
|
||||||
#include "console.h"
|
#include "console.h"
|
||||||
#include "command.h"
|
#include "command.h"
|
||||||
#include "gfx.h"
|
#include "gfx.h"
|
||||||
|
@ -1198,7 +1199,7 @@ void NetworkPopulateCompanyInfo(void)
|
||||||
if (ci != NULL && ci->client_playas > 0 && ci->client_playas <= MAX_PLAYERS) {
|
if (ci != NULL && ci->client_playas > 0 && ci->client_playas <= MAX_PLAYERS) {
|
||||||
if (strlen(_network_player_info[ci->client_playas-1].players) != 0)
|
if (strlen(_network_player_info[ci->client_playas-1].players) != 0)
|
||||||
strncat(_network_player_info[ci->client_playas-1].players, ", ", sizeof(_network_player_info[ci->client_playas-1].players));
|
strncat(_network_player_info[ci->client_playas-1].players, ", ", sizeof(_network_player_info[ci->client_playas-1].players));
|
||||||
|
|
||||||
strncat(_network_player_info[ci->client_playas-1].players, client_name, sizeof(_network_player_info[ci->client_playas-1].players));
|
strncat(_network_player_info[ci->client_playas-1].players, client_name, sizeof(_network_player_info[ci->client_playas-1].players));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1372,6 +1373,9 @@ void NetworkServer_Tick(void)
|
||||||
last_sync_frame = _frame_counter;
|
last_sync_frame = _frame_counter;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* See if we need to advertise */
|
||||||
|
NetworkUDPAdvertise();
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* ENABLE_NETWORK */
|
#endif /* ENABLE_NETWORK */
|
||||||
|
|
|
@ -19,6 +19,7 @@ typedef enum {
|
||||||
PACKET_UDP_SERVER_RESPONSE,
|
PACKET_UDP_SERVER_RESPONSE,
|
||||||
PACKET_UDP_CLIENT_DETAIL_INFO,
|
PACKET_UDP_CLIENT_DETAIL_INFO,
|
||||||
PACKET_UDP_SERVER_DETAIL_INFO, // Is not used in OpenTTD itself, only for external querying
|
PACKET_UDP_SERVER_DETAIL_INFO, // Is not used in OpenTTD itself, only for external querying
|
||||||
|
PACKET_UDP_SERVER_REGISTER, // Packet to register itself to the master server
|
||||||
PACKET_UDP_END
|
PACKET_UDP_END
|
||||||
} PacketUDPType;
|
} PacketUDPType;
|
||||||
|
|
||||||
|
@ -218,6 +219,7 @@ static NetworkUDPPacket* const _network_udp_packet[] = {
|
||||||
RECEIVE_COMMAND(PACKET_UDP_SERVER_RESPONSE),
|
RECEIVE_COMMAND(PACKET_UDP_SERVER_RESPONSE),
|
||||||
RECEIVE_COMMAND(PACKET_UDP_CLIENT_DETAIL_INFO),
|
RECEIVE_COMMAND(PACKET_UDP_CLIENT_DETAIL_INFO),
|
||||||
NULL,
|
NULL,
|
||||||
|
NULL,
|
||||||
};
|
};
|
||||||
|
|
||||||
// If this fails, check the array above with network_data.h
|
// If this fails, check the array above with network_data.h
|
||||||
|
@ -467,6 +469,39 @@ void NetworkUDPQueryServer(const byte* host, unsigned short port)
|
||||||
UpdateNetworkGameWindow(false);
|
UpdateNetworkGameWindow(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Register us to the master server
|
||||||
|
This function checks if it needs to send an advertise */
|
||||||
|
void NetworkUDPAdvertise()
|
||||||
|
{
|
||||||
|
struct sockaddr_in out_addr;
|
||||||
|
Packet *p;
|
||||||
|
|
||||||
|
/* Check if we should send an advertise */
|
||||||
|
if (!_networking || !_network_server || !_network_udp_server || !_network_advertise)
|
||||||
|
return;
|
||||||
|
|
||||||
|
/* Only send once in the 450 game-days (about 15 minutes) */
|
||||||
|
if (_network_last_advertise_date + 450 > _date)
|
||||||
|
return;
|
||||||
|
_network_last_advertise_date = _date;
|
||||||
|
|
||||||
|
/* Find somewhere to send */
|
||||||
|
out_addr.sin_family = AF_INET;
|
||||||
|
out_addr.sin_port = htons(NETWORK_MASTER_SERVER_PORT);
|
||||||
|
out_addr.sin_addr.s_addr = NetworkResolveHost(NETWORK_MASTER_SERVER_HOST);
|
||||||
|
|
||||||
|
DEBUG(net, 1)("[NET][UDP] Advertising to master server");
|
||||||
|
|
||||||
|
/* Send the packet */
|
||||||
|
p = NetworkSend_Init(PACKET_UDP_SERVER_REGISTER);
|
||||||
|
/* Packet is: WELCOME_MESSAGE, Version, server_port */
|
||||||
|
NetworkSend_string(p, NETWORK_MASTER_SERVER_WELCOME_MESSAGE);
|
||||||
|
NetworkSend_uint8(p, NETWORK_MASTER_SERVER_VERSION);
|
||||||
|
NetworkSend_uint16(p, _network_server_port);
|
||||||
|
NetworkSendUDP_Packet(p, &out_addr);
|
||||||
|
free(p);
|
||||||
|
}
|
||||||
|
|
||||||
void NetworkUDPInitialize(void)
|
void NetworkUDPInitialize(void)
|
||||||
{
|
{
|
||||||
_udp_client_socket = INVALID_SOCKET;
|
_udp_client_socket = INVALID_SOCKET;
|
||||||
|
|
|
@ -6,5 +6,6 @@ bool NetworkUDPListen(uint32 host, uint16 port);
|
||||||
void NetworkUDPReceive(void);
|
void NetworkUDPReceive(void);
|
||||||
void NetworkUDPSearchGame(void);
|
void NetworkUDPSearchGame(void);
|
||||||
void NetworkUDPQueryServer(const byte* host, unsigned short port);
|
void NetworkUDPQueryServer(const byte* host, unsigned short port);
|
||||||
|
void NetworkUDPAdvertise();
|
||||||
|
|
||||||
#endif /* NETWORK_LAN_H */
|
#endif /* NETWORK_LAN_H */
|
||||||
|
|
Loading…
Reference in New Issue