Limited the struct qsocket_s details only to net_*.c sources :

For menu serverlist handling, added new procedures NET_SlistSort,
NET_SlistPrintServer and NET_SlistPrintServerName. Added new
procedure NET_QSocketGetTime for status and spawn commands' print
functionality in host_cmd.c. Added new NET_QSocketGetAddressString
procedure for status and connect commands' print functionality in
host_cmd.c and sv_main.c.  Patch ported over from uhexen2.

git-svn-id: http://svn.code.sf.net/p/quakespasm/code/trunk/quakespasm@657 af15c1b1-3010-417e-b628-4374ebc0bcbd
This commit is contained in:
sezero 2012-04-18 20:33:12 +00:00
parent f8c136c534
commit 7b5b0b6502
5 changed files with 83 additions and 45 deletions

View File

@ -20,12 +20,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "q_stdinc.h"
#include "arch_def.h"
#include "net_sys.h" /* for net_defs.h */
#include <dirent.h>
#include "quakedef.h"
#include "net_defs.h" /* for struct qsocket_s details */
#include <dirent.h>
extern cvar_t pausable;
@ -533,7 +529,7 @@ void Host_Status_f (void)
{
if (!client->active)
continue;
seconds = (int)(net_time - client->netconnection->connecttime);
seconds = (int)(net_time - NET_QSocketGetTime(client->netconnection));
minutes = seconds / 60;
if (minutes)
{
@ -545,7 +541,7 @@ void Host_Status_f (void)
else
hours = 0;
print_fn ("#%-2u %-16.16s %3i %2i:%02i:%02i\n", j+1, client->name, (int)client->edict->v.frags, hours, minutes, seconds);
print_fn (" %s\n", client->netconnection->address);
print_fn (" %s\n", NET_QSocketGetAddressString(client->netconnection));
}
}
@ -1632,7 +1628,7 @@ void Host_Spawn_f (void)
pr_global_struct->self = EDICT_TO_PROG(sv_player);
PR_ExecuteProgram (pr_global_struct->ClientConnect);
if ((Sys_DoubleTime() - host_client->netconnection->connecttime) <= sv.time)
if ((Sys_DoubleTime() - NET_QSocketGetTime(host_client->netconnection)) <= sv.time)
Sys_Printf ("%s entered the game\n", host_client->name);
PR_ExecuteProgram (pr_global_struct->PutClientInServer);

View File

@ -19,11 +19,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "q_stdinc.h"
#include "arch_def.h"
#include "net_sys.h" /* FIXME */
#include "quakedef.h"
#include "net_defs.h" /* FIXME */
#include "bgmusic.h"
void (*vid_menucmdfn)(void); //johnfitz
@ -2341,42 +2337,19 @@ void M_Menu_ServerList_f (void)
void M_ServerList_Draw (void)
{
int n;
char string [64];
int n;
qpic_t *p;
if (!slist_sorted)
{
if (hostCacheCount > 1)
{
int i,j;
hostcache_t temp;
for (i = 0; i < hostCacheCount; i++)
{
for (j = i + 1; j < hostCacheCount; j++)
{
if (strcmp(hostcache[j].name, hostcache[i].name) < 0)
{
Q_memcpy(&temp, &hostcache[j], sizeof(hostcache_t));
Q_memcpy(&hostcache[j], &hostcache[i], sizeof(hostcache_t));
Q_memcpy(&hostcache[i], &temp, sizeof(hostcache_t));
}
}
}
}
slist_sorted = true;
NET_SlistSort ();
}
p = Draw_CachePic ("gfx/p_multi.lmp");
M_DrawPic ( (320-p->width)/2, 4, p);
for (n = 0; n < hostCacheCount; n++)
{
if (hostcache[n].maxusers)
sprintf(string, "%-15.15s %-15.15s %2u/%2u\n", hostcache[n].name, hostcache[n].map, hostcache[n].users, hostcache[n].maxusers);
else
sprintf(string, "%-15.15s %-15.15s\n", hostcache[n].name, hostcache[n].map);
M_Print (16, 32 + 8*n, string);
}
M_Print (16, 32 + 8*n, NET_SlistPrintServer (n));
M_DrawCharacter (0, 32 + slist_cursor*8, 12+((int)(realtime*4)&1));
if (*m_return_reason)
@ -2420,7 +2393,7 @@ void M_ServerList_Key (int k)
IN_Activate();
key_dest = key_game;
m_state = m_none;
Cbuf_AddText ( va ("connect \"%s\"\n", hostcache[slist_cursor].cname) );
Cbuf_AddText ( va ("connect \"%s\"\n", NET_SlistPrintServerName(slist_cursor)) );
break;
default:

View File

@ -54,6 +54,9 @@ struct qsocket_s *NET_CheckNewConnections (void);
struct qsocket_s *NET_Connect (const char *host);
// called by client to connect to a host. Returns -1 if not able to
double NET_QSocketGetTime (struct qsocket_s *sock);
const char *NET_QSocketGetAddressString (struct qsocket_s *sock);
qboolean NET_CanSendMessage (struct qsocket_s *sock);
// Returns true or false if the given qsocket can currently accept a
// message to be transmitted.
@ -92,7 +95,12 @@ extern qboolean slistInProgress;
extern qboolean slistSilent;
extern qboolean slistLocal;
extern int hostCacheCount;
void NET_Slist_f (void);
void NET_SlistSort (void);
const char *NET_SlistPrintServer (int n);
const char *NET_SlistPrintServerName (int n);
/* FIXME: driver related, but public:

View File

@ -156,6 +156,18 @@ void NET_FreeQSocket(qsocket_t *sock)
}
double NET_QSocketGetTime (qsocket_t *s)
{
return s->connecttime;
}
const char *NET_QSocketGetAddressString (qsocket_t *s)
{
return s->address;
}
static void NET_Listen_f (void)
{
if (Cmd_Argc () != 2)
@ -296,6 +308,59 @@ void NET_Slist_f (void)
}
void NET_SlistSort (void)
{
if (hostCacheCount > 1)
{
int i, j;
hostcache_t temp;
for (i = 0; i < hostCacheCount; i++)
{
for (j = i + 1; j < hostCacheCount; j++)
{
if (strcmp(hostcache[j].name, hostcache[i].name) < 0)
{
memcpy(&temp, &hostcache[j], sizeof(hostcache_t));
memcpy(&hostcache[j], &hostcache[i], sizeof(hostcache_t));
memcpy(&hostcache[i], &temp, sizeof(hostcache_t));
}
}
}
}
}
const char *NET_SlistPrintServer (int idx)
{
static char string[64];
if (idx < 0 || idx >= hostCacheCount)
return "";
if (hostcache[idx].maxusers)
{
q_snprintf(string, sizeof(string), "%-15.15s %-15.15s %2u/%2u\n",
hostcache[idx].name, hostcache[idx].map,
hostcache[idx].users, hostcache[idx].maxusers);
}
else
{
q_snprintf(string, sizeof(string), "%-15.15s %-15.15s\n",
hostcache[idx].name, hostcache[idx].map);
}
return string;
}
const char *NET_SlistPrintServerName (int idx)
{
if (idx < 0 || idx >= hostCacheCount)
return "";
return hostcache[idx].cname;
}
static void Slist_Send (void *unused)
{
for (net_driverlevel = 0; net_driverlevel < net_numdrivers; net_driverlevel++)

View File

@ -20,11 +20,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
// sv_main.c -- server main program
#include "q_stdinc.h"
#include "arch_def.h"
#include "net_sys.h" /* for net_defs.h */
#include "quakedef.h"
#include "net_defs.h" /* for struct qsocket_s details */
server_t sv;
server_static_t svs;
@ -329,7 +325,7 @@ void SV_ConnectClient (int clientnum)
client = svs.clients + clientnum;
Con_DPrintf ("Client %s connected\n", client->netconnection->address);
Con_DPrintf ("Client %s connected\n", NET_QSocketGetAddressString(client->netconnection));
edictnum = clientnum+1;
@ -919,7 +915,7 @@ qboolean SV_SendClientDatagram (client_t *client)
msg.cursize = 0;
//johnfitz -- if client is nonlocal, use smaller max size so packets aren't fragmented
if (Q_strcmp (client->netconnection->address, "LOCAL") != 0)
if (Q_strcmp(NET_QSocketGetAddressString(client->netconnection), "LOCAL") != 0)
msg.maxsize = DATAGRAM_MTU;
//johnfitz