Skip to content

Commit

Permalink
client: display correct port of MOTD and update servers, refs #32
Browse files Browse the repository at this point in the history
  • Loading branch information
JanSimek committed Feb 13, 2013
1 parent 3c7eca4 commit 1a3e8fb
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 49 deletions.
50 changes: 25 additions & 25 deletions src/client/cl_main.c
Expand Up @@ -1178,25 +1178,26 @@ void CL_RequestMotd(void)
return;
}

Com_Printf("MOTD: resolving %s\n", MOTD_SERVER_NAME);
if (!NET_StringToAdr(MOTD_SERVER_NAME, &cls.updateServer, NA_IP))
Com_Printf("MOTD: resolving %s... ", MOTD_SERVER_NAME);

if (!NET_StringToAdr(va("%s:%i", MOTD_SERVER_NAME, PORT_MOTD), &cls.motdServer, NA_UNSPEC))
{
Com_Printf("MOTD: couldn't resolve address\n");
Com_Printf("couldn't resolve address\n");
return;
}
else
{
Com_Printf("resolved to %s\n", NET_AdrToString(cls.motdServer));
}

cls.updateServer.port = BigShort(PORT_MOTD);
Com_Printf("MOTD: %s resolved to %s\n", MOTD_SERVER_NAME,
NET_AdrToString(cls.updateServer));
Com_sprintf(cls.motdChallenge, sizeof(cls.motdChallenge), "%i", rand());

info[0] = 0;
Com_sprintf(cls.updateChallenge, sizeof(cls.updateChallenge), "%i", rand());

Info_SetValueForKey(info, "challenge", cls.updateChallenge);
Info_SetValueForKey(info, "challenge", cls.motdChallenge);
Info_SetValueForKey(info, "version", ETLEGACY_VERSION_SHORT);
Info_SetValueForKey(info, "platform", CPUSTRING);

NET_OutOfBandPrint(NS_CLIENT, cls.updateServer, "getmotd \"%s\"", info);
NET_OutOfBandPrint(NS_CLIENT, cls.motdServer, "getmotd \"%s\"", info);
}

/*
Expand Down Expand Up @@ -2186,18 +2187,16 @@ void CL_DisconnectPacket(netadr_t from)
}
}

/*
===================
CL_MotdPacket
===================
*/
/**
* @brief Client received 'motd' connectionless packet
*/
void CL_MotdPacket(netadr_t from)
{
char *challenge;
char *info;

// if not from our server, ignore it
if (!NET_CompareAdr(from, cls.updateServer))
if (!NET_CompareAdr(from, cls.motdServer))
{
return;
}
Expand All @@ -2206,7 +2205,7 @@ void CL_MotdPacket(netadr_t from)

// check challenge
challenge = Info_ValueForKey(info, "challenge");
if (strcmp(challenge, cls.updateChallenge))
if (strcmp(challenge, cls.motdChallenge))
{
return;
}
Expand Down Expand Up @@ -3326,7 +3325,7 @@ void CL_CheckAutoUpdate(void)

if (!cl_autoupdate->integer)
{
Com_Printf("Updater is disabled by cl_autoupdate 0.\n");
Com_DPrintf("Updater is disabled by cl_autoupdate 0.\n");
return;
}

Expand All @@ -3337,16 +3336,19 @@ void CL_CheckAutoUpdate(void)
}

// Resolve update server
if (!NET_StringToAdr(cls.autoupdateServerName, &cls.autoupdateServer, NA_UNSPEC))
Com_Printf("Updater: resolving %s... ", UPDATE_SERVER_NAME);

if (!NET_StringToAdr(va("%s:%i", UPDATE_SERVER_NAME, PORT_UPDATE), &cls.autoupdateServer, NA_UNSPEC))
{
Com_DPrintf("Failed to resolve the update server.\n");
Com_Printf("couldn't resolve address\n");

autoupdateChecked = qtrue;
return;
}

cls.autoupdateServer.port = BigShort(PORT_UPDATE);
Com_DPrintf("Update server at: %s (%s)\n", NET_AdrToString(cls.autoupdateServer), cls.autoupdateServerName);
else
{
Com_Printf("resolved to %s\n", NET_AdrToString(cls.autoupdateServer));
}

info[0] = 0;
Info_SetValueForKey(info, "version", ETLEGACY_VERSION_SHORT);
Expand Down Expand Up @@ -3755,8 +3757,6 @@ void CL_Init(void)
cl_updateavailable = Cvar_Get("cl_updateavailable", "0", CVAR_ROM);
cl_updatefiles = Cvar_Get("cl_updatefiles", "", CVAR_ROM);

Q_strncpyz(cls.autoupdateServerName, UPDATE_SERVER_NAME, MAX_QPATH);

// register our commands
Cmd_AddCommand("cmd", CL_ForwardToServer_f);
Cmd_AddCommand("configstrings", CL_Configstrings_f);
Expand Down
8 changes: 3 additions & 5 deletions src/client/client.h
Expand Up @@ -343,14 +343,12 @@ typedef struct
int masterNum;

// update server info
netadr_t updateServer;
char updateChallenge[MAX_TOKEN_CHARS];
char motdChallenge[MAX_TOKEN_CHARS];
char updateInfoString[MAX_INFO_STRING];

netadr_t authorizeServer;

char autoupdateServerName[MAX_QPATH];
netadr_t autoupdateServer;
netadr_t motdServer;
netadr_t authorizeServer; // Unused.

// rendering info
glconfig_t glconfig;
Expand Down
22 changes: 7 additions & 15 deletions src/qcommon/net_chan.c
Expand Up @@ -570,13 +570,9 @@ void NET_SendPacket(netsrc_t sock, int length, const void *data, netadr_t to)
}
}

/*
===============
NET_OutOfBandPrint
Sends a text message in an out-of-band datagram
================
*/
/**
* @brief Sends a text message in an out-of-band datagram
*/
void QDECL NET_OutOfBandPrint(netsrc_t sock, netadr_t adr, const char *format, ...)
{
va_list argptr;
Expand Down Expand Up @@ -628,14 +624,10 @@ void QDECL NET_OutOfBandData(netsrc_t sock, netadr_t adr, const char *format, in
NET_SendPacket(sock, mbuf.cursize, mbuf.data, adr);
}

/*
=============
NET_StringToAdr
Traps "localhost" for loopback, passes everything else to system
return 0 on address not found, 1 on address found with port, 2 on address found without port.
=============
*/
/**
* @brief Traps "localhost" for loopback, passes everything else to system.
* @return 0 on address not found, 1 on address found with port, 2 on address found without port.
*/
int NET_StringToAdr(const char *s, netadr_t *a, netadrtype_t family)
{
char base[MAX_STRING_CHARS], *search;
Expand Down
4 changes: 2 additions & 2 deletions src/qcommon/net_ip.c
Expand Up @@ -568,7 +568,7 @@ qboolean NET_CompareBaseAdrMask(netadr_t a, netadr_t b, int netmask)
}


/*
/**
* @brief Compares ip addresses without the port.
*/
qboolean NET_CompareBaseAdr(netadr_t a, netadr_t b)
Expand Down Expand Up @@ -610,7 +610,7 @@ const char *NET_AdrToString(netadr_t a)
return s;
}

/*
/**
* @warning Function is broken, because NET_AdrToString already adds port to IPv4 addresses.
* @deprecated Use NET_AdrToString for compatibility with W:ET 2.60b.
*/
Expand Down
2 changes: 1 addition & 1 deletion src/qcommon/qcommon.h
Expand Up @@ -185,7 +185,7 @@ typedef enum
NS_SERVER
} netsrc_t;

/*
/**
* @def NET_ADDRSTRMAXLEN
* @brief maximum length of an IPv6 address string including trailing '\0'
*/
Expand Down
2 changes: 1 addition & 1 deletion src/server/sv_main.c
Expand Up @@ -183,7 +183,7 @@ void SV_AddServerCommand(client_t *client, const char *cmd)
}


/*
/**
* @brief Sends a reliable command string to be interpreted by the client game
* module: "cp", "print", "chat", etc
*
Expand Down

0 comments on commit 1a3e8fb

Please sign in to comment.