- Fix masterserver disconnect (patch by Gerard)
- Show hostname:port on connection errors - Make gameserver and masterserver port configurable (as well as the masterserver name) git-svn-id: svn+ssh://svn.gna.org/svn/warzone/trunk@1512 4a71c877-e1ca-e34f-864e-861f7616d084master
parent
d4f8ef1d55
commit
49b314f6a2
|
@ -16,13 +16,13 @@ PackageDesktop: share/applications/warzone2100.desktop
|
||||||
AutopackageTarget: 1.2
|
AutopackageTarget: 1.2
|
||||||
|
|
||||||
[BuildPrepare]
|
[BuildPrepare]
|
||||||
prepareBuild --enable-data
|
prepareBuild --enable-data --disable-mp3
|
||||||
|
|
||||||
[BuildUnprepare]
|
[BuildUnprepare]
|
||||||
unprepareBuild
|
unprepareBuild
|
||||||
|
|
||||||
[Globals]
|
[Globals]
|
||||||
export APBUILD_STATIC="mad"
|
export APBUILD_STATIC="physfs=libphysfs.a"
|
||||||
|
|
||||||
[Imports]
|
[Imports]
|
||||||
echo '*' | import
|
echo '*' | import
|
||||||
|
@ -33,7 +33,6 @@ require @libsdl.org/sdl 1.2
|
||||||
require @libsdl.org/sdl_net 1.2
|
require @libsdl.org/sdl_net 1.2
|
||||||
require @opengl.org/opengl 1
|
require @opengl.org/opengl 1
|
||||||
require @openal.org/openal 0
|
require @openal.org/openal 0
|
||||||
require @icculus.org/physfs 1
|
|
||||||
require @libpng.org/libpng 3
|
require @libpng.org/libpng 3
|
||||||
require @xiph.org/libogg 0
|
require @xiph.org/libogg 0
|
||||||
require @xiph.org/libvorbis 0
|
require @xiph.org/libvorbis 0
|
||||||
|
|
|
@ -41,10 +41,11 @@
|
||||||
#include "netplay.h"
|
#include "netplay.h"
|
||||||
#include "netlog.h"
|
#include "netlog.h"
|
||||||
|
|
||||||
char* master_server = "warzone2100.kicks-ass.org";
|
|
||||||
#define MASTER_SERVER_PORT 9998
|
|
||||||
|
|
||||||
#define WARZONE_NET_PORT 9999
|
// WARNING !!! This is initialised via configuration.c !!!
|
||||||
|
char masterserver_name[255] = {'\0'};
|
||||||
|
unsigned int masterserver_port = 0, gameserver_port = 0;
|
||||||
|
|
||||||
#define MAX_CONNECTED_PLAYERS 8
|
#define MAX_CONNECTED_PLAYERS 8
|
||||||
#define MAX_TMP_SOCKETS 16
|
#define MAX_TMP_SOCKETS 16
|
||||||
|
|
||||||
|
@ -477,7 +478,7 @@ BOOL NETsetGameFlags(UDWORD flag, SDWORD value)
|
||||||
// setup stuff
|
// setup stuff
|
||||||
BOOL NETinit(BOOL bFirstCall)
|
BOOL NETinit(BOOL bFirstCall)
|
||||||
{
|
{
|
||||||
UDWORD i;
|
UDWORD i;
|
||||||
debug( LOG_NET, "NETinit" );
|
debug( LOG_NET, "NETinit" );
|
||||||
|
|
||||||
// NEThashFile("warzonedebug.exe");
|
// NEThashFile("warzonedebug.exe");
|
||||||
|
@ -980,14 +981,14 @@ BOOL NETsetupTCPIP(void ** addr, char * machine)
|
||||||
debug( LOG_NET, "NETsetupTCPIP\n" );
|
debug( LOG_NET, "NETsetupTCPIP\n" );
|
||||||
|
|
||||||
if ( hostname != NULL
|
if ( hostname != NULL
|
||||||
&& hostname != master_server) {
|
&& hostname != masterserver_name) {
|
||||||
free(hostname);
|
free(hostname);
|
||||||
}
|
}
|
||||||
if ( machine != NULL
|
if ( machine != NULL
|
||||||
&& machine[0] != '\0') {
|
&& machine[0] != '\0') {
|
||||||
hostname = strdup(machine);
|
hostname = strdup(machine);
|
||||||
} else {
|
} else {
|
||||||
hostname = master_server;
|
hostname = masterserver_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
@ -1126,15 +1127,15 @@ void NETregisterServer(int state) {
|
||||||
if (state != registered) {
|
if (state != registered) {
|
||||||
switch(state) {
|
switch(state) {
|
||||||
case 1: {
|
case 1: {
|
||||||
if(SDLNet_ResolveHost(&ip, master_server, MASTER_SERVER_PORT) == -1) {
|
if(SDLNet_ResolveHost(&ip, masterserver_name, masterserver_port) == -1) {
|
||||||
debug( LOG_ERROR, "NETregisterServer: couldn't resolve master server (%s): %s\n", master_server, SDLNet_GetError() );
|
debug( LOG_ERROR, "NETregisterServer: Cannot resolve masterserver \"%s\": %s\n", masterserver_name, SDLNet_GetError() );
|
||||||
server_not_there = 1;
|
server_not_there = 1;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!rs_socket) rs_socket = SDLNet_TCP_Open(&ip);
|
if(!rs_socket) rs_socket = SDLNet_TCP_Open(&ip);
|
||||||
if(rs_socket == NULL) {
|
if(rs_socket == NULL) {
|
||||||
debug( LOG_ERROR, "NETregisterServer: Cannot connect to master server (%s): %s\n", master_server, SDLNet_GetError() );
|
debug( LOG_ERROR, "NETregisterServer: Cannot connect to masterserver \"%s:%d\": %s\n", masterserver_name, masterserver_port, SDLNet_GetError() );
|
||||||
server_not_there = 1;
|
server_not_there = 1;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1169,7 +1170,7 @@ static void NETallowJoining(void) {
|
||||||
if (tmp_socket_set == NULL) {
|
if (tmp_socket_set == NULL) {
|
||||||
tmp_socket_set = SDLNet_AllocSocketSet(MAX_TMP_SOCKETS+1);
|
tmp_socket_set = SDLNet_AllocSocketSet(MAX_TMP_SOCKETS+1);
|
||||||
if (tmp_socket_set == NULL) {
|
if (tmp_socket_set == NULL) {
|
||||||
debug( LOG_ERROR, "Couldn't create socket set: %s\n", SDLNet_GetError() );
|
debug( LOG_ERROR, "NETallowJoining: Cannot create socket set: %s\n", SDLNet_GetError() );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
SDLNet_TCP_AddSocket(tmp_socket_set, tcp_socket);
|
SDLNet_TCP_AddSocket(tmp_socket_set, tcp_socket);
|
||||||
|
@ -1248,6 +1249,10 @@ static void NETallowJoining(void) {
|
||||||
for (j = 0; j < MAX_CONNECTED_PLAYERS; ++j) {
|
for (j = 0; j < MAX_CONNECTED_PLAYERS; ++j) {
|
||||||
NETBroadcastPlayerInfo(j);
|
NETBroadcastPlayerInfo(j);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Make sure the master server gets updated by disconnecting from it
|
||||||
|
// NETallowJoining will reconnect
|
||||||
|
NETregisterServer(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1271,20 +1276,20 @@ BOOL NEThostGame(const char* SessionName, const char* PlayerName,
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(SDLNet_ResolveHost(&ip, NULL, WARZONE_NET_PORT) == -1) {
|
if(SDLNet_ResolveHost(&ip, NULL, gameserver_port) == -1) {
|
||||||
debug( LOG_ERROR, "NEThostGame: couldn't resolve master self: %s\n", SDLNet_GetError() );
|
debug( LOG_ERROR, "NEThostGame: Cannot resolve master self: %s\n", SDLNet_GetError() );
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!tcp_socket) tcp_socket = SDLNet_TCP_Open(&ip);
|
if(!tcp_socket) tcp_socket = SDLNet_TCP_Open(&ip);
|
||||||
if(tcp_socket == NULL) {
|
if(tcp_socket == NULL) {
|
||||||
printf("SDLNet_TCP_Open: %s\n", SDLNet_GetError());
|
printf("NEThostGame: Cannot connect to master self: %s\n", SDLNet_GetError());
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!socket_set) socket_set = SDLNet_AllocSocketSet(MAX_CONNECTED_PLAYERS);
|
if(!socket_set) socket_set = SDLNet_AllocSocketSet(MAX_CONNECTED_PLAYERS);
|
||||||
if (socket_set == NULL) {
|
if (socket_set == NULL) {
|
||||||
debug( LOG_ERROR, "Couldn't create socket set: %s\n", SDLNet_GetError() );
|
debug( LOG_ERROR, "NEThostGame: Cannot create socket set: %s\n", SDLNet_GetError() );
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
for (i = 0; i < MAX_CONNECTED_PLAYERS; ++i) {
|
for (i = 0; i < MAX_CONNECTED_PLAYERS; ++i) {
|
||||||
|
@ -1327,19 +1332,21 @@ BOOL NEThaltJoining(void)
|
||||||
debug( LOG_NET, "NEThaltJoining\n" );
|
debug( LOG_NET, "NEThaltJoining\n" );
|
||||||
|
|
||||||
allow_joining = FALSE;
|
allow_joining = FALSE;
|
||||||
|
// disconnect from the master server
|
||||||
|
NETregisterServer(0);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ////////////////////////////////////////////////////////////////////////
|
// ////////////////////////////////////////////////////////////////////////
|
||||||
// find games on open connection, option to do this asynchronously
|
// find games on open connection, option to do this asynchronously
|
||||||
// since it can sometimes take a while.
|
// since it can sometimes take a while.
|
||||||
BOOL NETfindGame(BOOL async) /// may (not) want to use async here...
|
BOOL NETfindGame(BOOL async) // may (not) want to use async here...
|
||||||
{
|
{
|
||||||
static UDWORD gamecount = 0, gamesavailable;
|
static UDWORD gamecount = 0, gamesavailable;
|
||||||
IPaddress ip;
|
IPaddress ip;
|
||||||
char buffer[sizeof(GAMESTRUCT)*2];
|
char buffer[sizeof(GAMESTRUCT)*2];
|
||||||
GAMESTRUCT* tmpgame = (GAMESTRUCT*)buffer;
|
GAMESTRUCT* tmpgame = (GAMESTRUCT*)buffer;
|
||||||
|
unsigned int port = (hostname == masterserver_name) ? masterserver_port : gameserver_port;
|
||||||
|
|
||||||
debug( LOG_NET, "NETfindGame\n" );
|
debug( LOG_NET, "NETfindGame\n" );
|
||||||
|
|
||||||
|
@ -1355,9 +1362,8 @@ BOOL NETfindGame(BOOL async) /// may (not) want to use async here...
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (SDLNet_ResolveHost(&ip, hostname, (hostname == master_server) ? MASTER_SERVER_PORT
|
if (SDLNet_ResolveHost(&ip, hostname, port) == -1) {
|
||||||
: WARZONE_NET_PORT) == -1) {
|
debug( LOG_ERROR, "NETfindGame: Cannot resolve hostname \"%s\": %s\n", hostname, SDLNet_GetError() );
|
||||||
debug( LOG_ERROR, "NETfindGame: couldn't resolve hostname (%s): %s\n", hostname, SDLNet_GetError() );
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1367,13 +1373,13 @@ BOOL NETfindGame(BOOL async) /// may (not) want to use async here...
|
||||||
|
|
||||||
tcp_socket = SDLNet_TCP_Open(&ip);
|
tcp_socket = SDLNet_TCP_Open(&ip);
|
||||||
if (tcp_socket == NULL) {
|
if (tcp_socket == NULL) {
|
||||||
debug( LOG_ERROR, "SDLNet_TCP_Open: %s\n", SDLNet_GetError() );
|
debug( LOG_ERROR, "NETfindGame: Cannot connect to \"%s:%d\": %s\n", hostname, port, SDLNet_GetError() );
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
socket_set = SDLNet_AllocSocketSet(1);
|
socket_set = SDLNet_AllocSocketSet(1);
|
||||||
if (socket_set == NULL) {
|
if (socket_set == NULL) {
|
||||||
debug( LOG_ERROR, "Couldn't create socket set: %s\n", SDLNet_GetError() );
|
debug( LOG_ERROR, "NETfindGame: Cannot create socket set: %s\n", SDLNet_GetError() );
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
SDLNet_TCP_AddSocket(socket_set, tcp_socket);
|
SDLNet_TCP_AddSocket(socket_set, tcp_socket);
|
||||||
|
@ -1431,13 +1437,13 @@ BOOL NETjoinGame(UDWORD gameNumber, const char* playername)
|
||||||
|
|
||||||
NETclose(); // just to be sure :)
|
NETclose(); // just to be sure :)
|
||||||
|
|
||||||
if (hostname != master_server) {
|
if (hostname != masterserver_name) {
|
||||||
free(hostname);
|
free(hostname);
|
||||||
}
|
}
|
||||||
hostname = strdup(NetPlay.games[gameNumber].desc.host);
|
hostname = strdup(NetPlay.games[gameNumber].desc.host);
|
||||||
|
|
||||||
if(SDLNet_ResolveHost(&ip, hostname, WARZONE_NET_PORT) == -1) {
|
if(SDLNet_ResolveHost(&ip, hostname, gameserver_port) == -1) {
|
||||||
debug( LOG_ERROR, "NETjoinGame: couldn't resolve hostname (%s): %s\n", hostname, SDLNet_GetError() );
|
debug( LOG_ERROR, "NETjoinGame: Cannot resolve hostname \"%s\": %s\n", hostname, SDLNet_GetError() );
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1447,13 +1453,13 @@ BOOL NETjoinGame(UDWORD gameNumber, const char* playername)
|
||||||
|
|
||||||
tcp_socket = SDLNet_TCP_Open(&ip);
|
tcp_socket = SDLNet_TCP_Open(&ip);
|
||||||
if (tcp_socket == NULL) {
|
if (tcp_socket == NULL) {
|
||||||
debug( LOG_ERROR, "SDLNet_TCP_Open: %s\n", SDLNet_GetError() );
|
debug( LOG_ERROR, "NETjoinGame: Cannot connect to \"%s:%d\": %s\n", hostname, gameserver_port, SDLNet_GetError() );
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
socket_set = SDLNet_AllocSocketSet(1);
|
socket_set = SDLNet_AllocSocketSet(1);
|
||||||
if (socket_set == NULL) {
|
if (socket_set == NULL) {
|
||||||
debug( LOG_ERROR, "Couldn't create socket set: %s\n", SDLNet_GetError() );
|
debug( LOG_ERROR, "NETjoinGame: Cannot create socket set: %s\n", SDLNet_GetError() );
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
SDLNet_TCP_AddSocket(socket_set, tcp_socket);
|
SDLNet_TCP_AddSocket(socket_set, tcp_socket);
|
||||||
|
@ -1518,3 +1524,34 @@ BOOL NETjoinGame(UDWORD gameNumber, const char* playername)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* Set the masterserver name
|
||||||
|
* \param hostname The hostname of the masterserver to connect to
|
||||||
|
*/
|
||||||
|
void NETsetMasterserverName(const char* hostname)
|
||||||
|
{
|
||||||
|
size_t name_size = strlen(hostname);
|
||||||
|
if ( name_size > 255 )
|
||||||
|
name_size = 255;
|
||||||
|
strncpy(masterserver_name, hostname, name_size);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* Set the masterserver port
|
||||||
|
* \param port The port of the masterserver to connect to
|
||||||
|
*/
|
||||||
|
void NETsetMasterserverPort(unsigned int port)
|
||||||
|
{
|
||||||
|
masterserver_port = port;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* Set the port we shall host games on
|
||||||
|
* \param port The port to listen to
|
||||||
|
*/
|
||||||
|
void NETsetGameserverPort(unsigned int port)
|
||||||
|
{
|
||||||
|
gameserver_port = port;
|
||||||
|
}
|
||||||
|
|
|
@ -177,6 +177,9 @@ extern UDWORD NEThashBuffer(char *pData, UDWORD size);
|
||||||
extern WZ_DECL_DEPRECATED BOOL NETcheckRegistryEntries (char *name,char *guid);
|
extern WZ_DECL_DEPRECATED BOOL NETcheckRegistryEntries (char *name,char *guid);
|
||||||
extern WZ_DECL_DEPRECATED BOOL NETsetRegistryEntries (char *name,char *guid,char *file,char *cline,char *path,char *cdir);
|
extern WZ_DECL_DEPRECATED BOOL NETsetRegistryEntries (char *name,char *guid,char *file,char *cline,char *path,char *cdir);
|
||||||
extern WZ_DECL_DEPRECATED BOOL NETconnectToLobby (LPNETPLAY lpNetPlay);
|
extern WZ_DECL_DEPRECATED BOOL NETconnectToLobby (LPNETPLAY lpNetPlay);
|
||||||
|
extern void NETsetMasterserverName(const char* hostname);
|
||||||
|
extern void NETsetMasterserverPort(unsigned int port);
|
||||||
|
extern void NETsetGameserverPort(unsigned int port);
|
||||||
|
|
||||||
// Some shortcuts to help you along!
|
// Some shortcuts to help you along!
|
||||||
/* FIXME: This is _not_ portable! Bad, Pumpkin, bad! - Per */
|
/* FIXME: This is _not_ portable! Bad, Pumpkin, bad! - Per */
|
||||||
|
|
|
@ -192,6 +192,36 @@ BOOL loadConfig(void)
|
||||||
setWarzoneKeyNumeric("mouseflip", TRUE);
|
setWarzoneKeyNumeric("mouseflip", TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (getWarzoneKeyString("masterserver_name", sBuf))
|
||||||
|
{
|
||||||
|
NETsetMasterserverName(sBuf);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
NETsetMasterserverName("lobby.wz2100.net");
|
||||||
|
setWarzoneKeyString("masterserver_name", "lobby.wz2100.net");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (getWarzoneKeyNumeric("masterserver_port", &val))
|
||||||
|
{
|
||||||
|
NETsetMasterserverPort(val);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
NETsetMasterserverPort(9998);
|
||||||
|
setWarzoneKeyNumeric("masterserver_port", 9998);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (getWarzoneKeyNumeric("gameserver_port", &val))
|
||||||
|
{
|
||||||
|
NETsetGameserverPort(val);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
NETsetGameserverPort(9999);
|
||||||
|
setWarzoneKeyNumeric("gameserver_port", 9999);
|
||||||
|
}
|
||||||
|
|
||||||
// //////////////////////////
|
// //////////////////////////
|
||||||
// sequences
|
// sequences
|
||||||
if(getWarzoneKeyNumeric("sequences", &val))
|
if(getWarzoneKeyNumeric("sequences", &val))
|
||||||
|
@ -311,7 +341,7 @@ BOOL loadConfig(void)
|
||||||
// /////////////////////////
|
// /////////////////////////
|
||||||
|
|
||||||
// game name
|
// game name
|
||||||
if (getWarzoneKeyString("gameName",(char*)&sBuf))
|
if (getWarzoneKeyString("gameName", sBuf))
|
||||||
{
|
{
|
||||||
strcpy(game.name, sBuf);
|
strcpy(game.name, sBuf);
|
||||||
}
|
}
|
||||||
|
@ -321,7 +351,7 @@ BOOL loadConfig(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
// player name
|
// player name
|
||||||
if (getWarzoneKeyString("playerName",(char*)&sBuf))
|
if (getWarzoneKeyString("playerName", sBuf))
|
||||||
{
|
{
|
||||||
strcpy((char*)sPlayer, sBuf);
|
strcpy((char*)sPlayer, sBuf);
|
||||||
}
|
}
|
||||||
|
@ -331,7 +361,7 @@ BOOL loadConfig(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
// map name
|
// map name
|
||||||
if(getWarzoneKeyString("mapName",(char*)&sBuf))
|
if(getWarzoneKeyString("mapName", sBuf))
|
||||||
{
|
{
|
||||||
strcpy(game.map, sBuf);
|
strcpy(game.map, sBuf);
|
||||||
}
|
}
|
||||||
|
@ -430,7 +460,7 @@ BOOL loadConfig(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
// force name
|
// force name
|
||||||
if(getWarzoneKeyString("forceName",(char*)&sBuf))
|
if(getWarzoneKeyString("forceName", sBuf))
|
||||||
{
|
{
|
||||||
strcpy(sForceName, sBuf);
|
strcpy(sForceName, sBuf);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue