Make info_t opaque.

I didn't like the way client/server code was poking around at the
implementation. Instead, provide a couple of accessor functions for the
same information.
This commit is contained in:
Bill Currie 2012-05-21 22:50:59 +09:00
parent da8355a5f6
commit b4ad695e16
7 changed files with 34 additions and 14 deletions

View file

@ -40,11 +40,7 @@
#define MAX_SERVERINFO_STRING 512
#define MAX_LOCALINFO_STRING 32768
typedef struct info_s {
struct hashtab_s *tab;
size_t maxsize;
int cursize;
} info_t;
typedef struct info_s info_t;
typedef struct info_key_s {
const char *key;
@ -54,6 +50,9 @@ typedef struct info_key_s {
qboolean Info_FilterForKey (const char *key, const char **filter_list);
void Info_Print (info_t *info);
int Info_CurrentSize (info_t *info);
info_key_t *Info_Key (info_t *info, const char *key);
info_key_t **Info_KeyList (info_t *info);
void Info_RemoveKey (info_t *info, const char *key);
int Info_SetValueForKey (info_t *info, const char *key, const char *value, int flags);
int Info_SetValueForStarKey (info_t *info, const char *key, const char *value, int flags);

View file

@ -45,6 +45,12 @@
#include "compat.h"
struct info_s {
struct hashtab_s *tab;
size_t maxsize;
int cursize;
};
/*
Info_FilterForKey
@ -63,6 +69,11 @@ Info_FilterForKey (const char *key, const char **filter_list)
return false;
}
VISIBLE int
Info_CurrentSize (info_t *info)
{
return info->cursize;
}
/*
Info_ValueForKey
@ -79,6 +90,18 @@ Info_ValueForKey (info_t *info, const char *key)
return "";
}
VISIBLE info_key_t *
Info_Key (info_t *info, const char *key)
{
return Hash_Find (info->tab, key);
}
VISIBLE info_key_t **
Info_KeyList (info_t *info)
{
return (info_key_t **) Hash_GetList (info->tab);
}
VISIBLE void
Info_RemoveKey (info_t *info, const char *key)
{

View file

@ -207,7 +207,8 @@ cl_spawn_f (client_t *cl, void *unused)
for (i = 0, pl = sv->players; i < MAX_SV_PLAYERS; i++, pl++) {
if (!pl->info)
continue;
msg = MSG_ReliableCheckBlock (&cl->backbuf, 24 + pl->info->cursize);
msg = MSG_ReliableCheckBlock (&cl->backbuf,
24 + Info_CurrentSize(pl->info));
MSG_WriteByte (msg, svc_updatefrags);
MSG_WriteByte (msg, i);
MSG_WriteShort (msg, pl->frags);

View file

@ -49,7 +49,6 @@
#include "QF/draw.h"
#include "QF/dstring.h"
#include "QF/gib.h"
#include "QF/hash.h"
#include "QF/idparse.h"
#include "QF/msg.h"
#include "QF/progs.h"
@ -1102,9 +1101,9 @@ CL_ProcessUserInfo (int slot, player_info_t *player)
player->bottomcolor =
atoi (Info_ValueForKey (player->userinfo, "bottomcolor"));
while (!(player->team = Hash_Find (player->userinfo->tab, "team")))
while (!(player->team = Info_Key (player->userinfo, "team")))
Info_SetValueForKey (player->userinfo, "team", "", 1);
while (!(player->skinname = Hash_Find (player->userinfo->tab, "skin")))
while (!(player->skinname = Info_Key (player->userinfo, "skin")))
Info_SetValueForKey (player->userinfo, "skin", "", 1);
if (Info_ValueForKey (player->userinfo, "*spectator")[0])

View file

@ -36,7 +36,6 @@
#endif
#include "QF/dstring.h"
#include "QF/hash.h"
#include "QF/info.h"
#include "QF/gib.h"
@ -88,8 +87,7 @@ SV_GIB_Client_GetKeys_f (void)
GIB_Error ("uid", "No user with id '%s' was found on the server.",
GIB_Argv (1));
else if (GIB_CanReturn ()) {
info_key_t **key, **keys =
(info_key_t **) Hash_GetList (cl->userinfo->tab);
info_key_t **key, **keys = Info_KeyList (cl->userinfo);
for (key = keys; *key; key++)
dstring_appendstr (GIB_Return (0), (*key)->key);
free (keys);

View file

@ -452,7 +452,7 @@ SV_FullClientUpdateToClient (client_t *client, backbuf_t *backbuf)
{
if (client->state < cs_connected && client->state != cs_server)
return;
MSG_ReliableCheckBlock (backbuf, 24 + client->userinfo->cursize);
MSG_ReliableCheckBlock (backbuf, 24 + Info_CurrentSize (client->userinfo));
if (backbuf->num_backbuf) {
SV_FullClientUpdate (client, &backbuf->backbuf);
MSG_Reliable_FinishWrite (backbuf);

View file

@ -407,7 +407,7 @@ SV_qtvConnect (int qport, info_t *info)
return;
}
proxy->info = info;
while (!(proxy->name_key = Hash_Find (proxy->info->tab, "name")))
while (!(proxy->name_key = Info_Key (proxy->info, "name")))
Info_SetValueForKey (proxy->info, "name", "\"unnamed proxy\"", 1);
Netchan_Setup (&proxy->netchan, net_from, qport, NC_QPORT_READ);