summaryrefslogtreecommitdiff
path: root/src/server/sv_main.c
diff options
context:
space:
mode:
author/dev/humancontroller <devhc@example.com>2015-02-08 13:55:15 +0100
committer/dev/humancontroller <devhc@example.com>2017-03-09 13:51:18 +0100
commitb392b0d97f3ea048478059873ed6dec8afd9634b (patch)
treee3fb4a9ef70d89bfb70676fe33f9b493da7051ec /src/server/sv_main.c
parent65bcf419d4b612b7d626447924fa0fe2079c18c2 (diff)
implement part 1 of the multi-protocol functionality: protocols
this contains support for connecting via, and serving simultaneously via, any of the three protocols: latest, GPP and 1.1 alternate-1 means protocol 70 (GPP), alternate-2 means protocol 69 (1.1) relevant cvars: - net_alternateProtocols - net_alt{1|2}port[6] - sv_alt{1|2}master{1|...|5} - sv_clAltProto{0|..|63}
Diffstat (limited to 'src/server/sv_main.c')
-rw-r--r--src/server/sv_main.c78
1 files changed, 51 insertions, 27 deletions
diff --git a/src/server/sv_main.c b/src/server/sv_main.c
index e5b260e5..19ec5cea 100644
--- a/src/server/sv_main.c
+++ b/src/server/sv_main.c
@@ -42,7 +42,7 @@ cvar_t *sv_maxclients;
cvar_t *sv_privateClients; // number of clients reserved for password
cvar_t *sv_hostname;
-cvar_t *sv_master[MAX_MASTER_SERVERS]; // master server ip address
+cvar_t *sv_masters[3][MAX_MASTER_SERVERS]; // master server IP addresses
cvar_t *sv_reconnectlimit; // minimum seconds between connect messages
cvar_t *sv_showloss; // report when usercmds are lost
cvar_t *sv_padPackets; // add nop bytes to messages
@@ -225,12 +225,15 @@ but not on every player enter or exit.
#define HEARTBEAT_MSEC 300*1000
void SV_MasterHeartbeat(const char *message)
{
- static netadr_t adr[MAX_MASTER_SERVERS][2]; // [2] for v4 and v6 address for the same address string.
+ static netadr_t adrs[3][MAX_MASTER_SERVERS][2]; // [2] for v4 and v6 address for the same address string.
+ int a;
int i;
int res;
int netenabled;
+ int netAlternateProtocols;
netenabled = Cvar_VariableIntegerValue("net_enabled");
+ netAlternateProtocols = Cvar_VariableIntegerValue("net_alternateProtocols");
// "dedicated 1" is for lan play, "dedicated 2" is for inet public play
if (!com_dedicated || com_dedicated->integer != 2 || !(netenabled & (NET_ENABLEV4 | NET_ENABLEV6)))
@@ -242,72 +245,86 @@ void SV_MasterHeartbeat(const char *message)
svs.nextHeartbeatTime = svs.time + HEARTBEAT_MSEC;
+ for (a = 0; a < 3; ++a)
+ {
+ // indent
+ if(a == 0 && (netAlternateProtocols & NET_DISABLEPRIMPROTO))
+ continue;
+ if(a == 1 && !(netAlternateProtocols & NET_ENABLEALT1PROTO))
+ continue;
+ if(a == 2 && !(netAlternateProtocols & NET_ENABLEALT2PROTO))
+ continue;
+
// send to group masters
for (i = 0; i < MAX_MASTER_SERVERS; i++)
{
- if(!sv_master[i]->string[0])
+ if(!sv_masters[a][i]->string[0])
continue;
// see if we haven't already resolved the name
// resolving usually causes hitches on win95, so only
// do it when needed
- if(sv_master[i]->modified || (adr[i][0].type == NA_BAD && adr[i][1].type == NA_BAD))
+ if(sv_masters[a][i]->modified || (adrs[a][i][0].type == NA_BAD && adrs[a][i][1].type == NA_BAD))
{
- sv_master[i]->modified = qfalse;
+ sv_masters[a][i]->modified = qfalse;
if(netenabled & NET_ENABLEV4)
{
- Com_Printf("Resolving %s (IPv4)\n", sv_master[i]->string);
- res = NET_StringToAdr(sv_master[i]->string, &adr[i][0], NA_IP);
+ Com_Printf("Resolving %s (IPv4)\n", sv_masters[a][i]->string);
+ res = NET_StringToAdr(sv_masters[a][i]->string, &adrs[a][i][0], NA_IP);
+ adrs[a][i][0].alternateProtocol = a;
if(res == 2)
{
// if no port was specified, use the default master port
- adr[i][0].port = BigShort(PORT_MASTER);
+ adrs[a][i][0].port = BigShort(a == 2 ? ALT2PORT_MASTER : a == 1 ? ALT1PORT_MASTER : PORT_MASTER);
}
if(res)
- Com_Printf( "%s resolved to %s\n", sv_master[i]->string, NET_AdrToStringwPort(adr[i][0]));
+ Com_Printf( "%s resolved to %s\n", sv_masters[a][i]->string, NET_AdrToStringwPort(adrs[a][i][0]));
else
- Com_Printf( "%s has no IPv4 address.\n", sv_master[i]->string);
+ Com_Printf( "%s has no IPv4 address.\n", sv_masters[a][i]->string);
}
if(netenabled & NET_ENABLEV6)
{
- Com_Printf("Resolving %s (IPv6)\n", sv_master[i]->string);
- res = NET_StringToAdr(sv_master[i]->string, &adr[i][1], NA_IP6);
+ Com_Printf("Resolving %s (IPv6)\n", sv_masters[a][i]->string);
+ res = NET_StringToAdr(sv_masters[a][i]->string, &adrs[a][i][1], NA_IP6);
+ adrs[a][i][1].alternateProtocol = a;
if(res == 2)
{
// if no port was specified, use the default master port
- adr[i][1].port = BigShort(PORT_MASTER);
+ adrs[a][i][1].port = BigShort(a == 2 ? ALT2PORT_MASTER : a == 1 ? ALT1PORT_MASTER : PORT_MASTER);
}
if(res)
- Com_Printf( "%s resolved to %s\n", sv_master[i]->string, NET_AdrToStringwPort(adr[i][1]));
+ Com_Printf( "%s resolved to %s\n", sv_masters[a][i]->string, NET_AdrToStringwPort(adrs[a][i][1]));
else
- Com_Printf( "%s has no IPv6 address.\n", sv_master[i]->string);
+ Com_Printf( "%s has no IPv6 address.\n", sv_masters[a][i]->string);
}
- if(adr[i][0].type == NA_BAD && adr[i][1].type == NA_BAD)
+ if(adrs[a][i][0].type == NA_BAD && adrs[a][i][1].type == NA_BAD)
{
- Com_Printf("Couldn't resolve address: %s\n", sv_master[i]->string);
- Cvar_Set(sv_master[i]->name, "");
- sv_master[i]->modified = qfalse;
+ Com_Printf("Couldn't resolve address: %s\n", sv_masters[a][i]->string);
+ Cvar_Set(sv_masters[a][i]->name, "");
+ sv_masters[a][i]->modified = qfalse;
continue;
}
}
- Com_Printf ("Sending heartbeat to %s\n", sv_master[i]->string );
+ Com_Printf ("Sending%s heartbeat to %s\n", (a == 2 ? " alternate-2" : a == 1 ? " alternate-1" : ""), sv_masters[a][i]->string );
// this command should be changed if the server info / status format
// ever incompatably changes
- if(adr[i][0].type != NA_BAD)
- NET_OutOfBandPrint( NS_SERVER, adr[i][0], "heartbeat %s\n", message);
- if(adr[i][1].type != NA_BAD)
- NET_OutOfBandPrint( NS_SERVER, adr[i][1], "heartbeat %s\n", message);
+ if(adrs[a][i][0].type != NA_BAD)
+ NET_OutOfBandPrint( NS_SERVER, adrs[a][i][0], "heartbeat %s\n", message);
+ if(adrs[a][i][1].type != NA_BAD)
+ NET_OutOfBandPrint( NS_SERVER, adrs[a][i][1], "heartbeat %s\n", message);
+ }
+ // outdent
}
}
@@ -542,6 +559,9 @@ static void SVC_Status( netadr_t from ) {
// to prevent timed spoofed reply packets that add ghost servers
Info_SetValueForKey( infostring, "challenge", Cmd_Argv(1) );
+ if ( from.alternateProtocol != 0 )
+ Info_SetValueForKey( infostring, "protocol", from.alternateProtocol == 2 ? "69" : "70" );
+
status[0] = 0;
statusLength = 0;
@@ -612,7 +632,7 @@ void SVC_Info( netadr_t from ) {
// to prevent timed spoofed reply packets that add ghost servers
Info_SetValueForKey( infostring, "challenge", Cmd_Argv(1) );
- Info_SetValueForKey( infostring, "protocol", va("%i", PROTOCOL_VERSION) );
+ Info_SetValueForKey( infostring, "protocol", va("%i", from.alternateProtocol == 2 ? 69 : from.alternateProtocol == 1 ? 70 : PROTOCOL_VERSION) );
Info_SetValueForKey( infostring, "gamename", com_gamename->string );
Info_SetValueForKey( infostring, "hostname", sv_hostname->string );
Info_SetValueForKey( infostring, "mapname", sv_mapname->string );
@@ -622,8 +642,12 @@ void SVC_Info( netadr_t from ) {
Info_SetValueForKey( infostring, "pure", va("%i", sv_pure->integer ) );
#ifdef USE_VOIP
- if (sv_voipProtocol->string && *sv_voipProtocol->string) {
- Info_SetValueForKey( infostring, "voip", sv_voipProtocol->string );
+ if (from.alternateProtocol == 0) {
+ if (sv_voipProtocol->string && *sv_voipProtocol->string) {
+ Info_SetValueForKey( infostring, "voip", sv_voipProtocol->string );
+ }
+ } else {
+ Info_SetValueForKey( infostring, "voip", va("%i", sv_voip->integer) );
}
#endif