add an /optional/ SetUserInfo qc callback to allout the progs to take over

userinfo setting.

float (string key, string value) SetUserInfo;

key = infostring key
value = new value
returs: 0 for key not changed, non-0 to broadcast the change
This commit is contained in:
Bill Currie 2001-07-20 04:30:33 +00:00
parent 9f09a6aa32
commit d30f1ee0c2
3 changed files with 26 additions and 17 deletions

View file

@ -170,5 +170,6 @@ extern func_t EndFrame;
extern func_t SpectatorConnect;
extern func_t SpectatorThink;
extern func_t SpectatorDisconnect;
extern func_t SetUserInfo;
#endif // __sv_progs_h

View file

@ -59,6 +59,7 @@ func_t EndFrame;
func_t SpectatorConnect;
func_t SpectatorDisconnect;
func_t SpectatorThink;
func_t SetUserInfo;
static int reserved_edicts = MAX_CLIENTS;
@ -255,6 +256,7 @@ SV_LoadProgs (void)
// Zoid, find the spectator functions
SpectatorConnect = SpectatorThink = SpectatorDisconnect = 0;
SetUserInfo = 0;
if ((f = ED_FindFunction (&sv_pr_state, "SpectatorConnect")) != NULL)
SpectatorConnect = (func_t) (f - sv_pr_state.pr_functions);
@ -262,6 +264,8 @@ SV_LoadProgs (void)
SpectatorThink = (func_t) (f - sv_pr_state.pr_functions);
if ((f = ED_FindFunction (&sv_pr_state, "SpectatorDisconnect")) != NULL)
SpectatorDisconnect = (func_t) (f - sv_pr_state.pr_functions);
if ((f = ED_FindFunction (&sv_pr_state, "SetUserInfo")) != NULL)
SetUserInfo = (func_t) (f - sv_pr_state.pr_functions);
// 2000-01-02 EndFrame function by Maddes/FrikaC
EndFrame = 0;

View file

@ -1090,10 +1090,6 @@ SV_Msg_f (void)
void
SV_SetInfo_f (void)
{
int i;
char oldval[MAX_INFO_STRING];
if (Cmd_Argc () == 1) {
SV_Printf ("User info settings:\n");
Info_Print (host_client->userinfo);
@ -1108,26 +1104,34 @@ SV_SetInfo_f (void)
if (Cmd_Argv (1)[0] == '*')
return; // don't set priveledged values
strcpy (oldval, Info_ValueForKey (host_client->userinfo, Cmd_Argv (1)));
Info_SetValueForKey (host_client->userinfo, Cmd_Argv (1), Cmd_Argv (2),
MAX_INFO_STRING);
// name is extracted below in ExtractFromUserInfo
// strncpy (host_client->name, Info_ValueForKey (host_client->userinfo, "name")
// , sizeof(host_client->name)-1);
// SV_FullClientUpdate (host_client, &sv.reliable_datagram);
// host_client->sendinfo = true;
if (SetUserInfo) {
float ret;
if (strequal
(Info_ValueForKey (host_client->userinfo, Cmd_Argv (1)), oldval))
return; // key hasn't changed
G_var (&sv_pr_state, OFS_PARM0, string) = PR_SetString (&sv_pr_state,
Cmd_Argv (1));
G_var (&sv_pr_state, OFS_PARM1, string) = PR_SetString (&sv_pr_state,
Cmd_Argv (2));
PR_ExecuteProgram (&sv_pr_state, SetUserInfo);
ret = G_FLOAT (&sv_pr_state, OFS_RETURN); // get the return value
if (!ret)
return;
} else {
char oldval[MAX_INFO_STRING];
strcpy (oldval, Info_ValueForKey (host_client->userinfo, Cmd_Argv (1)));
Info_SetValueForKey (host_client->userinfo, Cmd_Argv (1), Cmd_Argv (2),
MAX_INFO_STRING);
if (strequal
(Info_ValueForKey (host_client->userinfo, Cmd_Argv (1)), oldval))
return; // key hasn't changed
}
// process any changed values
SV_ExtractFromUserinfo (host_client);
i = host_client - svs.clients;
MSG_WriteByte (&sv.reliable_datagram, svc_setinfo);
MSG_WriteByte (&sv.reliable_datagram, i);
MSG_WriteByte (&sv.reliable_datagram, host_client - svs.clients);
MSG_WriteString (&sv.reliable_datagram, Cmd_Argv (1));
MSG_WriteString (&sv.reliable_datagram,
Info_ValueForKey (host_client->userinfo, Cmd_Argv (1)));