2006-02-24 04:48:15 +00:00
|
|
|
/*
|
|
|
|
** d_netinfo.cpp
|
|
|
|
** Manages transport of user and "server" cvars across a network
|
|
|
|
**
|
|
|
|
**---------------------------------------------------------------------------
|
2006-06-11 01:37:00 +00:00
|
|
|
** Copyright 1998-2006 Randy Heit
|
2006-02-24 04:48:15 +00:00
|
|
|
** All rights reserved.
|
|
|
|
**
|
|
|
|
** Redistribution and use in source and binary forms, with or without
|
|
|
|
** modification, are permitted provided that the following conditions
|
|
|
|
** are met:
|
|
|
|
**
|
|
|
|
** 1. Redistributions of source code must retain the above copyright
|
|
|
|
** notice, this list of conditions and the following disclaimer.
|
|
|
|
** 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
** notice, this list of conditions and the following disclaimer in the
|
|
|
|
** documentation and/or other materials provided with the distribution.
|
|
|
|
** 3. The name of the author may not be used to endorse or promote products
|
|
|
|
** derived from this software without specific prior written permission.
|
|
|
|
**
|
|
|
|
** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
**---------------------------------------------------------------------------
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <math.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
#include "doomtype.h"
|
|
|
|
#include "doomdef.h"
|
|
|
|
#include "doomstat.h"
|
|
|
|
#include "d_netinf.h"
|
|
|
|
#include "d_net.h"
|
|
|
|
#include "d_protocol.h"
|
2011-07-06 14:20:54 +00:00
|
|
|
#include "d_player.h"
|
2006-02-24 04:48:15 +00:00
|
|
|
#include "c_dispatch.h"
|
|
|
|
#include "v_palette.h"
|
|
|
|
#include "v_video.h"
|
|
|
|
#include "i_system.h"
|
|
|
|
#include "r_state.h"
|
|
|
|
#include "sbar.h"
|
|
|
|
#include "gi.h"
|
|
|
|
#include "m_random.h"
|
2007-12-20 20:22:31 +00:00
|
|
|
#include "teaminfo.h"
|
2011-07-06 08:50:15 +00:00
|
|
|
#include "r_data/r_translate.h"
|
2008-01-06 04:03:33 +00:00
|
|
|
#include "templates.h"
|
2009-02-20 00:53:25 +00:00
|
|
|
#include "cmdlib.h"
|
2011-07-06 14:20:54 +00:00
|
|
|
#include "farchive.h"
|
2006-02-24 04:48:15 +00:00
|
|
|
|
|
|
|
static FRandom pr_pickteam ("PickRandomTeam");
|
|
|
|
|
2006-09-14 00:02:31 +00:00
|
|
|
extern bool st_firsttime;
|
2006-02-24 04:48:15 +00:00
|
|
|
EXTERN_CVAR (Bool, teamplay)
|
|
|
|
|
|
|
|
CVAR (Float, autoaim, 5000.f, CVAR_USERINFO | CVAR_ARCHIVE);
|
|
|
|
CVAR (String, name, "Player", CVAR_USERINFO | CVAR_ARCHIVE);
|
|
|
|
CVAR (Color, color, 0x40cf00, CVAR_USERINFO | CVAR_ARCHIVE);
|
2010-03-06 02:51:23 +00:00
|
|
|
CVAR (Int, colorset, 0, CVAR_USERINFO | CVAR_ARCHIVE);
|
2006-02-24 04:48:15 +00:00
|
|
|
CVAR (String, skin, "base", CVAR_USERINFO | CVAR_ARCHIVE);
|
2009-02-04 23:14:28 +00:00
|
|
|
CVAR (Int, team, TEAM_NONE, CVAR_USERINFO | CVAR_ARCHIVE);
|
2006-02-24 04:48:15 +00:00
|
|
|
CVAR (String, gender, "male", CVAR_USERINFO | CVAR_ARCHIVE);
|
|
|
|
CVAR (Bool, neverswitchonpickup, false, CVAR_USERINFO | CVAR_ARCHIVE);
|
|
|
|
CVAR (Float, movebob, 0.25f, CVAR_USERINFO | CVAR_ARCHIVE);
|
|
|
|
CVAR (Float, stillbob, 0.f, CVAR_USERINFO | CVAR_ARCHIVE);
|
|
|
|
CVAR (String, playerclass, "Fighter", CVAR_USERINFO | CVAR_ARCHIVE);
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
INFO_Name,
|
|
|
|
INFO_Autoaim,
|
|
|
|
INFO_Color,
|
|
|
|
INFO_Skin,
|
|
|
|
INFO_Team,
|
|
|
|
INFO_Gender,
|
|
|
|
INFO_NeverSwitchOnPickup,
|
|
|
|
INFO_MoveBob,
|
|
|
|
INFO_StillBob,
|
|
|
|
INFO_PlayerClass,
|
2010-03-06 02:51:23 +00:00
|
|
|
INFO_ColorSet,
|
2006-02-24 04:48:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const char *GenderNames[3] = { "male", "female", "other" };
|
|
|
|
|
2007-12-15 03:27:40 +00:00
|
|
|
// Replace \ with %/ and % with %%
|
|
|
|
FString D_EscapeUserInfo (const char *str)
|
|
|
|
{
|
|
|
|
FString ret;
|
|
|
|
|
|
|
|
for (; *str != '\0'; ++str)
|
|
|
|
{
|
|
|
|
if (*str == '\\')
|
|
|
|
{
|
|
|
|
ret << '%' << '/';
|
|
|
|
}
|
|
|
|
else if (*str == '%')
|
|
|
|
{
|
|
|
|
ret << '%' << '%';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ret << *str;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Replace %/ with \ and %% with %
|
|
|
|
FString D_UnescapeUserInfo (const char *str, size_t len)
|
|
|
|
{
|
|
|
|
const char *end = str + len;
|
|
|
|
FString ret;
|
|
|
|
|
|
|
|
while (*str != '\0' && str < end)
|
|
|
|
{
|
|
|
|
if (*str == '%')
|
|
|
|
{
|
|
|
|
if (*(str + 1) == '/')
|
|
|
|
{
|
|
|
|
ret << '\\';
|
|
|
|
str += 2;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else if (*(str + 1) == '%')
|
|
|
|
{
|
|
|
|
str++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ret << *str++;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2006-02-24 04:48:15 +00:00
|
|
|
int D_GenderToInt (const char *gender)
|
|
|
|
{
|
|
|
|
if (!stricmp (gender, "female"))
|
|
|
|
return GENDER_FEMALE;
|
|
|
|
else if (!stricmp (gender, "other") || !stricmp (gender, "cyborg"))
|
|
|
|
return GENDER_NEUTER;
|
|
|
|
else
|
|
|
|
return GENDER_MALE;
|
|
|
|
}
|
|
|
|
|
2006-07-13 10:17:56 +00:00
|
|
|
int D_PlayerClassToInt (const char *classname)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2006-07-13 10:17:56 +00:00
|
|
|
if (PlayerClasses.Size () > 1)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2006-07-13 10:17:56 +00:00
|
|
|
for (unsigned int i = 0; i < PlayerClasses.Size (); ++i)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2006-07-13 10:17:56 +00:00
|
|
|
const PClass *type = PlayerClasses[i].Type;
|
|
|
|
|
|
|
|
if (stricmp (type->Meta.GetMetaString (APMETA_DisplayName), classname) == 0)
|
|
|
|
{
|
|
|
|
return i;
|
|
|
|
}
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
2006-07-13 10:17:56 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return 0;
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-06 02:51:23 +00:00
|
|
|
void D_GetPlayerColor (int player, float *h, float *s, float *v, FPlayerColorSet **set)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2007-12-20 20:22:31 +00:00
|
|
|
userinfo_t *info = &players[player].userinfo;
|
2010-03-06 02:51:23 +00:00
|
|
|
FPlayerColorSet *colorset = NULL;
|
2013-05-12 18:27:03 +00:00
|
|
|
uint32 color;
|
|
|
|
int team;
|
2010-03-06 02:51:23 +00:00
|
|
|
|
|
|
|
if (players[player].mo != NULL)
|
|
|
|
{
|
2013-05-12 18:27:03 +00:00
|
|
|
colorset = P_GetPlayerColorSet(players[player].mo->GetClass()->TypeName, info->GetColorSet());
|
2010-03-06 02:51:23 +00:00
|
|
|
}
|
|
|
|
if (colorset != NULL)
|
|
|
|
{
|
|
|
|
color = GPalette.BaseColors[GPalette.Remap[colorset->RepresentativeColor]];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-05-12 18:27:03 +00:00
|
|
|
color = info->GetColor();
|
2010-03-06 02:51:23 +00:00
|
|
|
}
|
2006-02-24 04:48:15 +00:00
|
|
|
|
|
|
|
RGBtoHSV (RPART(color)/255.f, GPART(color)/255.f, BPART(color)/255.f,
|
|
|
|
h, s, v);
|
2008-01-06 04:03:33 +00:00
|
|
|
|
2013-05-12 18:27:03 +00:00
|
|
|
if (teamplay && TeamLibrary.IsValidTeam((team = info->GetTeam())) && !Teams[team].GetAllowCustomPlayerColor())
|
2008-01-06 04:03:33 +00:00
|
|
|
{
|
|
|
|
// In team play, force the player to use the team's hue
|
|
|
|
// and adjust the saturation and value so that the team
|
|
|
|
// hue is visible in the final color.
|
|
|
|
float ts, tv;
|
2013-05-12 18:27:03 +00:00
|
|
|
int tcolor = Teams[team].GetPlayerColor ();
|
2008-01-06 04:03:33 +00:00
|
|
|
|
|
|
|
RGBtoHSV (RPART(tcolor)/255.f, GPART(tcolor)/255.f, BPART(tcolor)/255.f,
|
|
|
|
h, &ts, &tv);
|
|
|
|
|
|
|
|
*s = clamp(ts + *s * 0.15f - 0.075f, 0.f, 1.f);
|
|
|
|
*v = clamp(tv + *v * 0.5f - 0.25f, 0.f, 1.f);
|
2013-02-27 03:27:33 +00:00
|
|
|
|
|
|
|
// Make sure not to pass back any colorset in teamplay.
|
|
|
|
colorset = NULL;
|
2008-01-06 04:03:33 +00:00
|
|
|
}
|
2010-03-06 02:51:23 +00:00
|
|
|
if (set != NULL)
|
|
|
|
{
|
|
|
|
*set = colorset;
|
|
|
|
}
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Find out which teams are present. If there is only one,
|
|
|
|
// then another team should be chosen at random.
|
|
|
|
//
|
|
|
|
// Otherwise, join whichever team has fewest players. If
|
|
|
|
// teams are tied for fewest players, pick one of those
|
|
|
|
// at random.
|
|
|
|
|
|
|
|
void D_PickRandomTeam (int player)
|
|
|
|
{
|
|
|
|
static char teamline[8] = "\\team\\X";
|
|
|
|
|
2006-09-14 00:02:31 +00:00
|
|
|
BYTE *foo = (BYTE *)teamline;
|
2006-12-21 04:34:43 +00:00
|
|
|
teamline[6] = (char)D_PickRandomTeam() + '0';
|
2006-02-24 04:48:15 +00:00
|
|
|
D_ReadUserInfoStrings (player, &foo, teamplay);
|
|
|
|
}
|
|
|
|
|
|
|
|
int D_PickRandomTeam ()
|
|
|
|
{
|
2009-02-04 23:14:28 +00:00
|
|
|
for (unsigned int i = 0; i < Teams.Size (); i++)
|
2007-12-20 20:22:31 +00:00
|
|
|
{
|
2009-02-04 23:14:28 +00:00
|
|
|
Teams[i].m_iPresent = 0;
|
|
|
|
Teams[i].m_iTies = 0;
|
2007-12-20 20:22:31 +00:00
|
|
|
}
|
|
|
|
|
2006-02-24 04:48:15 +00:00
|
|
|
int numTeams = 0;
|
|
|
|
int team;
|
|
|
|
|
|
|
|
for (int i = 0; i < MAXPLAYERS; ++i)
|
|
|
|
{
|
|
|
|
if (playeringame[i])
|
|
|
|
{
|
2013-05-12 18:27:03 +00:00
|
|
|
team = players[i].userinfo.GetTeam();
|
|
|
|
if (TeamLibrary.IsValidTeam(team))
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2013-05-12 18:27:03 +00:00
|
|
|
if (Teams[team].m_iPresent++ == 0)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
|
|
|
numTeams++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (numTeams < 2)
|
|
|
|
{
|
|
|
|
do
|
|
|
|
{
|
2013-05-12 18:27:03 +00:00
|
|
|
team = pr_pickteam() % Teams.Size();
|
2009-02-04 23:14:28 +00:00
|
|
|
} while (Teams[team].m_iPresent != 0);
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-02-04 23:14:28 +00:00
|
|
|
int lowest = INT_MAX, lowestTie = 0;
|
|
|
|
unsigned int i;
|
2006-02-24 04:48:15 +00:00
|
|
|
|
2009-02-04 23:14:28 +00:00
|
|
|
for (i = 0; i < Teams.Size (); ++i)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2009-02-04 23:14:28 +00:00
|
|
|
if (Teams[i].m_iPresent > 0)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2009-02-04 23:14:28 +00:00
|
|
|
if (Teams[i].m_iPresent < lowest)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2009-02-04 23:14:28 +00:00
|
|
|
lowest = Teams[i].m_iPresent;
|
2006-02-24 04:48:15 +00:00
|
|
|
lowestTie = 0;
|
2009-02-04 23:14:28 +00:00
|
|
|
Teams[0].m_iTies = i;
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
2009-02-04 23:14:28 +00:00
|
|
|
else if (Teams[i].m_iPresent == lowest)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2009-02-04 23:14:28 +00:00
|
|
|
Teams[++lowestTie].m_iTies = i;
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (lowestTie == 0)
|
|
|
|
{
|
2009-02-04 23:14:28 +00:00
|
|
|
team = Teams[0].m_iTies;
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-02-04 23:14:28 +00:00
|
|
|
team = Teams[pr_pickteam() % (lowestTie+1)].m_iTies;
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return team;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void UpdateTeam (int pnum, int team, bool update)
|
|
|
|
{
|
|
|
|
userinfo_t *info = &players[pnum].userinfo;
|
2007-12-24 14:24:24 +00:00
|
|
|
|
2013-05-12 18:27:03 +00:00
|
|
|
if ((dmflags2 & DF2_NO_TEAM_SWITCH) && (alwaysapplydmflags || deathmatch) && TeamLibrary.IsValidTeam (info->GetTeam()))
|
2007-12-24 14:24:24 +00:00
|
|
|
{
|
|
|
|
Printf ("Team changing has been disabled!\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-02-24 04:48:15 +00:00
|
|
|
int oldteam;
|
|
|
|
|
2009-02-04 23:14:28 +00:00
|
|
|
if (!TeamLibrary.IsValidTeam (team))
|
2007-12-09 03:40:02 +00:00
|
|
|
{
|
2009-02-04 23:14:28 +00:00
|
|
|
team = TEAM_NONE;
|
2007-12-09 03:40:02 +00:00
|
|
|
}
|
2013-05-12 18:27:03 +00:00
|
|
|
oldteam = info->GetTeam();
|
|
|
|
team = info->TeamChanged(team);
|
2006-02-24 04:48:15 +00:00
|
|
|
|
2013-05-12 18:27:03 +00:00
|
|
|
if (update && oldteam != team)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2013-05-12 18:27:03 +00:00
|
|
|
if (TeamLibrary.IsValidTeam (team))
|
|
|
|
Printf ("%s joined the %s team\n", info->GetName(), Teams[team].GetName ());
|
2006-02-24 04:48:15 +00:00
|
|
|
else
|
2013-05-12 18:27:03 +00:00
|
|
|
Printf ("%s is now a loner\n", info->GetName());
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
// Let the player take on the team's color
|
|
|
|
R_BuildPlayerTranslation (pnum);
|
|
|
|
if (StatusBar != NULL && StatusBar->GetPlayer() == pnum)
|
|
|
|
{
|
|
|
|
StatusBar->AttachToPlayer (&players[pnum]);
|
|
|
|
}
|
2013-05-12 18:27:03 +00:00
|
|
|
// Double-check
|
|
|
|
if (!TeamLibrary.IsValidTeam (team))
|
|
|
|
{
|
|
|
|
*static_cast<FIntCVar *>((*info)[NAME_Team]) = TEAM_NONE;
|
|
|
|
}
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int D_GetFragCount (player_t *player)
|
|
|
|
{
|
2013-05-12 18:27:03 +00:00
|
|
|
const int team = player->userinfo.GetTeam();
|
|
|
|
if (!teamplay || !TeamLibrary.IsValidTeam(team))
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
|
|
|
return player->fragcount;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Count total frags for this player's team
|
|
|
|
int count = 0;
|
|
|
|
|
|
|
|
for (int i = 0; i < MAXPLAYERS; ++i)
|
|
|
|
{
|
2013-05-12 18:27:03 +00:00
|
|
|
if (playeringame[i] && players[i].userinfo.GetTeam() == team)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
|
|
|
count += players[i].fragcount;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void D_SetupUserInfo ()
|
|
|
|
{
|
|
|
|
int i;
|
2013-05-12 18:27:03 +00:00
|
|
|
userinfo_t *coninfo;
|
2006-02-24 04:48:15 +00:00
|
|
|
|
2013-05-12 18:27:03 +00:00
|
|
|
// Reset everybody's userinfo to a default state.
|
2006-02-24 04:48:15 +00:00
|
|
|
for (i = 0; i < MAXPLAYERS; i++)
|
|
|
|
{
|
2013-05-12 18:27:03 +00:00
|
|
|
players[i].userinfo.Reset();
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
2013-05-12 18:27:03 +00:00
|
|
|
// Initialize the console player's user info
|
|
|
|
coninfo = &players[consoleplayer].userinfo;
|
|
|
|
|
|
|
|
for (FBaseCVar *cvar = CVars; cvar != NULL; cvar = cvar->GetNext())
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2013-05-25 17:08:59 +00:00
|
|
|
if ((cvar->GetFlags() & (CVAR_USERINFO|CVAR_IGNORE)) == CVAR_USERINFO)
|
2013-05-12 18:27:03 +00:00
|
|
|
{
|
|
|
|
FBaseCVar **newcvar;
|
|
|
|
FName cvarname(cvar->GetName());
|
|
|
|
|
|
|
|
switch (cvarname.GetIndex())
|
|
|
|
{
|
|
|
|
// Some cvars don't copy their original value directly.
|
|
|
|
case NAME_Team: coninfo->TeamChanged(team); break;
|
2014-02-24 22:18:10 +00:00
|
|
|
case NAME_Skin: coninfo->SkinChanged(skin, players[consoleplayer].CurrentPlayerClass); break;
|
2013-05-12 18:27:03 +00:00
|
|
|
case NAME_Gender: coninfo->GenderChanged(gender); break;
|
|
|
|
case NAME_PlayerClass: coninfo->PlayerClassChanged(playerclass); break;
|
|
|
|
// The rest do.
|
|
|
|
default:
|
|
|
|
newcvar = coninfo->CheckKey(cvarname);
|
|
|
|
(*newcvar)->SetGenericRep(cvar->GetGenericRep(CVAR_String), CVAR_String);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
2013-05-12 18:27:03 +00:00
|
|
|
R_BuildPlayerTranslation(consoleplayer);
|
|
|
|
}
|
|
|
|
|
|
|
|
void userinfo_t::Reset()
|
|
|
|
{
|
|
|
|
// Clear this player's userinfo.
|
|
|
|
TMapIterator<FName, FBaseCVar *> it(*this);
|
|
|
|
TMap<FName, FBaseCVar *>::Pair *pair;
|
|
|
|
|
|
|
|
while (it.NextPair(pair))
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2013-05-12 18:27:03 +00:00
|
|
|
delete pair->Value;
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
2013-05-12 18:27:03 +00:00
|
|
|
Clear();
|
|
|
|
|
|
|
|
// Create userinfo vars for this player, initialized to their defaults.
|
|
|
|
for (FBaseCVar *cvar = CVars; cvar != NULL; cvar = cvar->GetNext())
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2013-05-25 17:08:59 +00:00
|
|
|
if ((cvar->GetFlags() & (CVAR_USERINFO|CVAR_IGNORE)) == CVAR_USERINFO)
|
2013-05-12 18:27:03 +00:00
|
|
|
{
|
|
|
|
ECVarType type;
|
|
|
|
FName cvarname(cvar->GetName());
|
|
|
|
FBaseCVar *newcvar;
|
|
|
|
|
|
|
|
// Some cvars have different types for their shadow copies.
|
|
|
|
switch (cvarname.GetIndex())
|
|
|
|
{
|
|
|
|
case NAME_Skin: type = CVAR_Int; break;
|
|
|
|
case NAME_Gender: type = CVAR_Int; break;
|
|
|
|
case NAME_PlayerClass: type = CVAR_Int; break;
|
|
|
|
default: type = cvar->GetRealType(); break;
|
|
|
|
}
|
- Added three new ACS functions:
* int GetUserCVar(int playernum, "cvarname")
* bool SetCVar("cvarname", newvalue)
* bool SetUserCVar(int playernum, "cvarname", newvalue)
GetUserCVar is analogous to GetCVar, except it returns the value of a user cvar for a
specific player. (All user cvars can be examined using the playerinfo console command.)
SetCVar sets a cvar to a new value. If the cvar is floating point, then newvalue is treated
as a fixed point number, otherwise it's treated as an integer. SetUserCVar is the same, but
for a specific player's user cvar.
SetCVar and SetUserCVar can only change cvars created via CVARINFO. They cannot alter built-in cvars.
If you use GetCVar or SetCVar with a user cvar, they will act on the copy of the user cvar
for the player who activated the script. e.g.
GetCVar("gender")
is the same as
GetUserCVar(PlayerNumber(), "gender")
If you get the value of a floating point cvar, it will be returned as a fixed point number.
Otherwise, it will be returned as an integer.
SVN r4283 (trunk)
2013-05-25 19:08:05 +00:00
|
|
|
newcvar = C_CreateCVar(NULL, type, cvar->GetFlags() & CVAR_MOD);
|
2013-05-12 18:27:03 +00:00
|
|
|
newcvar->SetGenericRepDefault(cvar->GetGenericRepDefault(CVAR_String), CVAR_String);
|
|
|
|
Insert(cvarname, newcvar);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int userinfo_t::TeamChanged(int team)
|
|
|
|
{
|
|
|
|
if (teamplay && !TeamLibrary.IsValidTeam(team))
|
|
|
|
{ // Force players onto teams in teamplay mode
|
|
|
|
team = D_PickRandomTeam();
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
2013-05-12 18:27:03 +00:00
|
|
|
*static_cast<FIntCVar *>((*this)[NAME_Team]) = team;
|
|
|
|
return team;
|
|
|
|
}
|
|
|
|
|
2014-02-24 22:18:10 +00:00
|
|
|
int userinfo_t::SkinChanged(const char *skinname, int playerclass)
|
2013-05-12 18:27:03 +00:00
|
|
|
{
|
2014-02-24 22:18:10 +00:00
|
|
|
int skinnum = R_FindSkin(skinname, playerclass);
|
2013-05-12 18:27:03 +00:00
|
|
|
*static_cast<FIntCVar *>((*this)[NAME_Skin]) = skinnum;
|
|
|
|
return skinnum;
|
|
|
|
}
|
|
|
|
|
|
|
|
int userinfo_t::SkinNumChanged(int skinnum)
|
|
|
|
{
|
|
|
|
*static_cast<FIntCVar *>((*this)[NAME_Skin]) = skinnum;
|
|
|
|
return skinnum;
|
|
|
|
}
|
|
|
|
|
|
|
|
int userinfo_t::GenderChanged(const char *gendername)
|
|
|
|
{
|
|
|
|
int gendernum = D_GenderToInt(gendername);
|
|
|
|
*static_cast<FIntCVar *>((*this)[NAME_Gender]) = gendernum;
|
|
|
|
return gendernum;
|
|
|
|
}
|
|
|
|
|
|
|
|
int userinfo_t::PlayerClassChanged(const char *classname)
|
|
|
|
{
|
|
|
|
int classnum = D_PlayerClassToInt(classname);
|
|
|
|
*static_cast<FIntCVar *>((*this)[NAME_PlayerClass]) = classnum;
|
|
|
|
return classnum;
|
|
|
|
}
|
|
|
|
|
|
|
|
int userinfo_t::PlayerClassNumChanged(int classnum)
|
|
|
|
{
|
|
|
|
*static_cast<FIntCVar *>((*this)[NAME_PlayerClass]) = classnum;
|
|
|
|
return classnum;
|
|
|
|
}
|
|
|
|
|
|
|
|
int userinfo_t::ColorSetChanged(int setnum)
|
|
|
|
{
|
|
|
|
*static_cast<FIntCVar *>((*this)[NAME_ColorSet]) = setnum;
|
|
|
|
return setnum;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32 userinfo_t::ColorChanged(const char *colorname)
|
|
|
|
{
|
|
|
|
FColorCVar *color = static_cast<FColorCVar *>((*this)[NAME_Color]);
|
|
|
|
assert(color != NULL);
|
|
|
|
UCVarValue val;
|
|
|
|
val.String = const_cast<char *>(colorname);
|
|
|
|
color->SetGenericRep(val, CVAR_String);
|
|
|
|
*static_cast<FIntCVar *>((*this)[NAME_ColorSet]) = -1;
|
|
|
|
return *color;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32 userinfo_t::ColorChanged(uint32 colorval)
|
|
|
|
{
|
|
|
|
FColorCVar *color = static_cast<FColorCVar *>((*this)[NAME_Color]);
|
|
|
|
assert(color != NULL);
|
|
|
|
UCVarValue val;
|
|
|
|
val.Int = colorval;
|
|
|
|
color->SetGenericRep(val, CVAR_Int);
|
|
|
|
// This version is called by the menu code. Do not implicitly set colorset.
|
|
|
|
return colorval;
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void D_UserInfoChanged (FBaseCVar *cvar)
|
|
|
|
{
|
|
|
|
UCVarValue val;
|
2007-12-15 03:27:40 +00:00
|
|
|
FString escaped_val;
|
2006-02-24 04:48:15 +00:00
|
|
|
char foo[256];
|
|
|
|
|
|
|
|
if (cvar == &autoaim)
|
|
|
|
{
|
|
|
|
if (autoaim < 0.0f)
|
|
|
|
{
|
|
|
|
autoaim = 0.0f;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if (autoaim > 5000.0f)
|
|
|
|
{
|
|
|
|
autoaim = 5000.f;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
val = cvar->GetGenericRep (CVAR_String);
|
2007-12-15 03:27:40 +00:00
|
|
|
escaped_val = D_EscapeUserInfo(val.String);
|
|
|
|
if (4 + strlen(cvar->GetName()) + escaped_val.Len() > 256)
|
2006-02-24 04:48:15 +00:00
|
|
|
I_Error ("User info descriptor too big");
|
|
|
|
|
About a week's worth of changes here. As a heads-up, I wouldn't be
surprised if this doesn't build in Linux right now. The CMakeLists.txt
were checked with MinGW and NMake, but how they fair under Linux is an
unknown to me at this time.
- Converted most sprintf (and all wsprintf) calls to either mysnprintf or
FStrings, depending on the situation.
- Changed the strings in the wbstartstruct to be FStrings.
- Changed myvsnprintf() to output nothing if count is greater than INT_MAX.
This is so that I can use a series of mysnprintf() calls and advance the
pointer for each one. Once the pointer goes beyond the end of the buffer,
the count will go negative, but since it's an unsigned type it will be
seen as excessively huge instead. This should not be a problem, as there's
no reason for ZDoom to be using text buffers larger than 2 GB anywhere.
- Ripped out the disabled bit from FGameConfigFile::MigrateOldConfig().
- Changed CalcMapName() to return an FString instead of a pointer to a static
buffer.
- Changed startmap in d_main.cpp into an FString.
- Changed CheckWarpTransMap() to take an FString& as the first argument.
- Changed d_mapname in g_level.cpp into an FString.
- Changed DoSubstitution() in ct_chat.cpp to place the substitutions in an
FString.
- Fixed: The MAPINFO parser wrote into the string buffer to construct a map
name when given a Hexen map number. This was fine with the old scanner
code, but only a happy coincidence prevents it from crashing with the new
code
- Added the 'B' conversion specifier to StringFormat::VWorker() for printing
binary numbers.
- Added CMake support for building with MinGW, MSYS, and NMake. Linux support
is probably broken until I get around to booting into Linux again. Niceties
provided over the existing Makefiles they're replacing:
* All command-line builds can use the same build system, rather than having
a separate one for MinGW and another for Linux.
* Microsoft's NMake tool is supported as a target.
* Progress meters.
* Parallel makes work from a fresh checkout without needing to be primed
first with a single-threaded make.
* Porting to other architectures should be simplified, whenever that day
comes.
- Replaced the makewad tool with zipdir. This handles the dependency tracking
itself instead of generating an external makefile to do it, since I couldn't
figure out how to generate a makefile with an external tool and include it
with a CMake-generated makefile. Where makewad used a master list of files
to generate the package file, zipdir just zips the entire contents of one or
more directories.
- Added the gdtoa package from netlib's fp library so that ZDoom's printf-style
formatting can be entirely independant of the CRT.
SVN r1082 (trunk)
2008-07-23 04:57:26 +00:00
|
|
|
mysnprintf (foo, countof(foo), "\\%s\\%s", cvar->GetName(), escaped_val.GetChars());
|
2006-02-24 04:48:15 +00:00
|
|
|
|
|
|
|
Net_WriteByte (DEM_UINFCHANGED);
|
|
|
|
Net_WriteString (foo);
|
|
|
|
}
|
|
|
|
|
2006-09-14 00:02:31 +00:00
|
|
|
static const char *SetServerVar (char *name, ECVarType type, BYTE **stream, bool singlebit)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
|
|
|
FBaseCVar *var = FindCVar (name, NULL);
|
|
|
|
UCVarValue value;
|
|
|
|
|
|
|
|
if (singlebit)
|
|
|
|
{
|
|
|
|
if (var != NULL)
|
|
|
|
{
|
|
|
|
int bitdata;
|
|
|
|
int mask;
|
|
|
|
|
|
|
|
value = var->GetFavoriteRep (&type);
|
|
|
|
if (type != CVAR_Int)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
bitdata = ReadByte (stream);
|
|
|
|
mask = 1 << (bitdata & 31);
|
|
|
|
if (bitdata & 32)
|
|
|
|
{
|
|
|
|
value.Int |= mask;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
value.Int &= ~mask;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case CVAR_Bool: value.Bool = ReadByte (stream) ? 1 : 0; break;
|
|
|
|
case CVAR_Int: value.Int = ReadLong (stream); break;
|
|
|
|
case CVAR_Float: value.Float = ReadFloat (stream); break;
|
|
|
|
case CVAR_String: value.String = ReadString (stream); break;
|
|
|
|
default: break; // Silence GCC
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (var)
|
|
|
|
{
|
|
|
|
var->ForceSet (value, type);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (type == CVAR_String)
|
|
|
|
{
|
|
|
|
delete[] value.String;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (var == &teamplay)
|
|
|
|
{
|
|
|
|
// Put players on teams if teamplay turned on
|
|
|
|
for (int i = 0; i < MAXPLAYERS; ++i)
|
|
|
|
{
|
|
|
|
if (playeringame[i])
|
|
|
|
{
|
2013-05-12 18:27:03 +00:00
|
|
|
UpdateTeam (i, players[i].userinfo.GetTeam(), true);
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (var)
|
|
|
|
{
|
|
|
|
value = var->GetGenericRep (CVAR_String);
|
|
|
|
return value.String;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
EXTERN_CVAR (Float, sv_gravity)
|
|
|
|
|
|
|
|
void D_SendServerInfoChange (const FBaseCVar *cvar, UCVarValue value, ECVarType type)
|
|
|
|
{
|
|
|
|
size_t namelen;
|
|
|
|
|
|
|
|
namelen = strlen (cvar->GetName ());
|
|
|
|
|
|
|
|
Net_WriteByte (DEM_SINFCHANGED);
|
|
|
|
Net_WriteByte ((BYTE)(namelen | (type << 6)));
|
|
|
|
Net_WriteBytes ((BYTE *)cvar->GetName (), (int)namelen);
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case CVAR_Bool: Net_WriteByte (value.Bool); break;
|
|
|
|
case CVAR_Int: Net_WriteLong (value.Int); break;
|
|
|
|
case CVAR_Float: Net_WriteFloat (value.Float); break;
|
|
|
|
case CVAR_String: Net_WriteString (value.String); break;
|
|
|
|
default: break; // Silence GCC
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void D_SendServerFlagChange (const FBaseCVar *cvar, int bitnum, bool set)
|
|
|
|
{
|
|
|
|
int namelen;
|
|
|
|
|
|
|
|
namelen = (int)strlen (cvar->GetName ());
|
|
|
|
|
|
|
|
Net_WriteByte (DEM_SINFCHANGEDXOR);
|
2006-12-21 04:34:43 +00:00
|
|
|
Net_WriteByte ((BYTE)namelen);
|
2006-02-24 04:48:15 +00:00
|
|
|
Net_WriteBytes ((BYTE *)cvar->GetName (), namelen);
|
2006-12-21 04:34:43 +00:00
|
|
|
Net_WriteByte (BYTE(bitnum | (set << 5)));
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
|
2006-09-14 00:02:31 +00:00
|
|
|
void D_DoServerInfoChange (BYTE **stream, bool singlebit)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
|
|
|
const char *value;
|
|
|
|
char name[64];
|
|
|
|
int len;
|
|
|
|
int type;
|
|
|
|
|
|
|
|
len = ReadByte (stream);
|
|
|
|
type = len >> 6;
|
|
|
|
len &= 0x3f;
|
|
|
|
if (len == 0)
|
|
|
|
return;
|
|
|
|
memcpy (name, *stream, len);
|
|
|
|
*stream += len;
|
|
|
|
name[len] = 0;
|
|
|
|
|
|
|
|
if ( (value = SetServerVar (name, (ECVarType)type, stream, singlebit)) && netgame)
|
|
|
|
{
|
|
|
|
Printf ("%s changed to %s\n", name, value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-12 18:27:03 +00:00
|
|
|
static int STACK_ARGS userinfosortfunc(const void *a, const void *b)
|
|
|
|
{
|
|
|
|
TMap<FName, FBaseCVar *>::ConstPair *pair1 = *(TMap<FName, FBaseCVar *>::ConstPair **)a;
|
|
|
|
TMap<FName, FBaseCVar *>::ConstPair *pair2 = *(TMap<FName, FBaseCVar *>::ConstPair **)b;
|
|
|
|
return stricmp(pair1->Key.GetChars(), pair2->Key.GetChars());
|
|
|
|
}
|
|
|
|
|
|
|
|
static int STACK_ARGS namesortfunc(const void *a, const void *b)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2013-05-12 18:27:03 +00:00
|
|
|
FName *name1 = (FName *)a;
|
|
|
|
FName *name2 = (FName *)b;
|
|
|
|
return stricmp(name1->GetChars(), name2->GetChars());
|
|
|
|
}
|
|
|
|
|
|
|
|
void D_WriteUserInfoStrings (int pnum, BYTE **stream, bool compact)
|
|
|
|
{
|
|
|
|
if (pnum >= MAXPLAYERS)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
|
|
|
WriteByte (0, stream);
|
2013-05-12 18:27:03 +00:00
|
|
|
return;
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
|
2013-05-12 18:27:03 +00:00
|
|
|
userinfo_t *info = &players[pnum].userinfo;
|
|
|
|
TArray<TMap<FName, FBaseCVar *>::Pair *> userinfo_pairs(info->CountUsed());
|
|
|
|
TMap<FName, FBaseCVar *>::Iterator it(*info);
|
|
|
|
TMap<FName, FBaseCVar *>::Pair *pair;
|
|
|
|
UCVarValue cval;
|
|
|
|
|
|
|
|
// Create a simple array of all userinfo cvars
|
|
|
|
while (it.NextPair(pair))
|
|
|
|
{
|
|
|
|
userinfo_pairs.Push(pair);
|
|
|
|
}
|
|
|
|
// For compact mode, these need to be sorted. Verbose mode doesn't matter.
|
|
|
|
if (compact)
|
|
|
|
{
|
|
|
|
qsort(&userinfo_pairs[0], userinfo_pairs.Size(), sizeof(pair), userinfosortfunc);
|
|
|
|
// Compact mode is signified by starting the string with two backslash characters.
|
|
|
|
// We output one now. The second will be output as part of the first value.
|
|
|
|
*(*stream)++ = '\\';
|
|
|
|
}
|
|
|
|
for (unsigned int i = 0; i < userinfo_pairs.Size(); ++i)
|
|
|
|
{
|
|
|
|
pair = userinfo_pairs[i];
|
2006-07-13 10:17:56 +00:00
|
|
|
|
2006-02-24 04:48:15 +00:00
|
|
|
if (!compact)
|
2013-05-12 18:27:03 +00:00
|
|
|
{ // In verbose mode, prepend the cvar's name
|
2013-07-02 02:40:09 +00:00
|
|
|
*stream += sprintf(*((char **)stream), "\\%s", pair->Key.GetChars());
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
2013-05-12 18:27:03 +00:00
|
|
|
// A few of these need special handling for compatibility reasons.
|
|
|
|
switch (pair->Key.GetIndex())
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2013-05-12 18:27:03 +00:00
|
|
|
case NAME_Gender:
|
|
|
|
*stream += sprintf(*((char **)stream), "\\%s",
|
|
|
|
*static_cast<FIntCVar *>(pair->Value) == GENDER_FEMALE ? "female" :
|
|
|
|
*static_cast<FIntCVar *>(pair->Value) == GENDER_NEUTER ? "other" : "male");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NAME_PlayerClass:
|
|
|
|
*stream += sprintf(*((char **)stream), "\\%s", info->GetPlayerClassNum() == -1 ? "Random" :
|
|
|
|
D_EscapeUserInfo(info->GetPlayerClassType()->Meta.GetMetaString(APMETA_DisplayName)).GetChars());
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NAME_Skin:
|
|
|
|
*stream += sprintf(*((char **)stream), "\\%s", D_EscapeUserInfo(skins[info->GetSkin()].name).GetChars());
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
cval = pair->Value->GetGenericRep(CVAR_String);
|
|
|
|
*stream += sprintf(*((char **)stream), "\\%s", cval.String);
|
|
|
|
break;
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
}
|
2013-05-12 18:27:03 +00:00
|
|
|
*(*stream)++ = '\0';
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
|
2013-05-12 18:27:03 +00:00
|
|
|
void D_ReadUserInfoStrings (int pnum, BYTE **stream, bool update)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2013-05-12 18:27:03 +00:00
|
|
|
userinfo_t *info = &players[pnum].userinfo;
|
|
|
|
TArray<FName> compact_names(info->CountUsed());
|
|
|
|
FBaseCVar **cvar_ptr;
|
2007-12-15 03:27:40 +00:00
|
|
|
const char *ptr = *((const char **)stream);
|
|
|
|
const char *breakpt;
|
|
|
|
FString value;
|
2006-02-24 04:48:15 +00:00
|
|
|
bool compact;
|
2013-05-12 18:27:03 +00:00
|
|
|
FName keyname;
|
|
|
|
unsigned int infotype = 0;
|
2006-02-24 04:48:15 +00:00
|
|
|
|
|
|
|
if (*ptr++ != '\\')
|
|
|
|
return;
|
|
|
|
|
|
|
|
compact = (*ptr == '\\') ? ptr++, true : false;
|
|
|
|
|
2013-05-12 18:27:03 +00:00
|
|
|
// We need the cvar names in sorted order for compact mode
|
|
|
|
if (compact)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2013-05-12 18:27:03 +00:00
|
|
|
TMap<FName, FBaseCVar *>::Iterator it(*info);
|
|
|
|
TMap<FName, FBaseCVar *>::Pair *pair;
|
|
|
|
|
|
|
|
while (it.NextPair(pair))
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2013-05-12 18:27:03 +00:00
|
|
|
compact_names.Push(pair->Key);
|
|
|
|
}
|
|
|
|
qsort(&compact_names[0], compact_names.Size(), sizeof(FName), namesortfunc);
|
|
|
|
}
|
2006-02-24 04:48:15 +00:00
|
|
|
|
2013-05-12 18:27:03 +00:00
|
|
|
if (pnum < MAXPLAYERS)
|
|
|
|
{
|
|
|
|
for (breakpt = ptr; breakpt != NULL; ptr = breakpt + 1)
|
|
|
|
{
|
|
|
|
breakpt = strchr(ptr, '\\');
|
2006-02-24 04:48:15 +00:00
|
|
|
|
|
|
|
if (compact)
|
|
|
|
{
|
2013-05-12 18:27:03 +00:00
|
|
|
// Compact has just the value.
|
|
|
|
if (infotype >= compact_names.Size())
|
|
|
|
{ // Too many entries! OMG!
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
keyname = compact_names[infotype++];
|
2008-02-09 03:09:56 +00:00
|
|
|
value = D_UnescapeUserInfo(ptr, breakpt != NULL ? breakpt - ptr : strlen(ptr));
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
2007-12-15 03:27:40 +00:00
|
|
|
else
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2013-05-12 18:27:03 +00:00
|
|
|
// Verbose has both the key name and its value.
|
2007-12-15 03:27:40 +00:00
|
|
|
assert(breakpt != NULL);
|
|
|
|
// A malicious remote machine could invalidate the above assert.
|
|
|
|
if (breakpt == NULL)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
const char *valstart = breakpt + 1;
|
|
|
|
if ( (breakpt = strchr (valstart, '\\')) != NULL )
|
|
|
|
{
|
|
|
|
value = D_UnescapeUserInfo(valstart, breakpt - valstart);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
value = D_UnescapeUserInfo(valstart, strlen(valstart));
|
|
|
|
}
|
2013-05-12 18:27:03 +00:00
|
|
|
keyname = FName(ptr, valstart - ptr - 1, true);
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
2013-05-12 18:27:03 +00:00
|
|
|
|
|
|
|
// A few of these need special handling.
|
|
|
|
switch (keyname)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2013-05-12 18:27:03 +00:00
|
|
|
case NAME_Gender:
|
|
|
|
info->GenderChanged(value);
|
2006-02-24 04:48:15 +00:00
|
|
|
break;
|
|
|
|
|
2013-05-12 18:27:03 +00:00
|
|
|
case NAME_PlayerClass:
|
|
|
|
info->PlayerClassChanged(value);
|
2006-02-24 04:48:15 +00:00
|
|
|
break;
|
|
|
|
|
2013-05-12 18:27:03 +00:00
|
|
|
case NAME_Skin:
|
2014-02-24 22:18:10 +00:00
|
|
|
info->SkinChanged(value, players[pnum].CurrentPlayerClass);
|
2013-05-12 18:27:03 +00:00
|
|
|
if (players[pnum].mo != NULL)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2013-05-12 18:27:03 +00:00
|
|
|
if (players[pnum].cls != NULL &&
|
|
|
|
!(players[pnum].mo->flags4 & MF4_NOSKIN) &&
|
|
|
|
players[pnum].mo->state->sprite ==
|
|
|
|
GetDefaultByType (players[pnum].cls)->SpawnState->sprite)
|
2006-07-13 10:17:56 +00:00
|
|
|
{ // Only change the sprite if the player is using a standard one
|
2013-05-12 18:27:03 +00:00
|
|
|
players[pnum].mo->sprite = skins[info->GetSkin()].sprite;
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
}
|
2006-07-13 10:17:56 +00:00
|
|
|
// Rebuild translation in case the new skin uses a different range
|
|
|
|
// than the old one.
|
2013-05-12 18:27:03 +00:00
|
|
|
R_BuildPlayerTranslation(pnum);
|
2006-02-24 04:48:15 +00:00
|
|
|
break;
|
|
|
|
|
2013-05-12 18:27:03 +00:00
|
|
|
case NAME_Team:
|
|
|
|
UpdateTeam(pnum, atoi(value), update);
|
2006-02-24 04:48:15 +00:00
|
|
|
break;
|
|
|
|
|
2013-05-12 18:27:03 +00:00
|
|
|
case NAME_Color:
|
|
|
|
info->ColorChanged(value);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
cvar_ptr = info->CheckKey(keyname);
|
|
|
|
if (cvar_ptr != NULL)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2013-05-12 18:27:03 +00:00
|
|
|
assert(*cvar_ptr != NULL);
|
|
|
|
UCVarValue val;
|
|
|
|
FString oldname;
|
|
|
|
|
|
|
|
if (keyname == NAME_Name)
|
|
|
|
{
|
|
|
|
val = (*cvar_ptr)->GetGenericRep(CVAR_String);
|
|
|
|
oldname = val.String;
|
|
|
|
}
|
|
|
|
val.String = CleanseString(value.LockBuffer());
|
|
|
|
(*cvar_ptr)->SetGenericRep(val, CVAR_String);
|
|
|
|
value.UnlockBuffer();
|
2014-01-18 20:18:35 +00:00
|
|
|
if (keyname == NAME_Name && update && oldname.Compare (value))
|
2013-05-12 18:27:03 +00:00
|
|
|
{
|
|
|
|
Printf("%s is now known as %s\n", oldname.GetChars(), value.GetChars());
|
|
|
|
}
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
2013-05-12 18:27:03 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (keyname == NAME_Color || keyname == NAME_ColorSet)
|
|
|
|
{
|
|
|
|
R_BuildPlayerTranslation(pnum);
|
|
|
|
if (StatusBar != NULL && pnum == StatusBar->GetPlayer())
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2013-05-12 18:27:03 +00:00
|
|
|
StatusBar->AttachToPlayer(&players[pnum]);
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
2013-05-12 18:27:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*stream += strlen (*((char **)stream)) + 1;
|
|
|
|
}
|
2006-02-24 04:48:15 +00:00
|
|
|
|
2013-05-12 18:27:03 +00:00
|
|
|
void ReadCompatibleUserInfo(FArchive &arc, userinfo_t &info)
|
|
|
|
{
|
2013-05-18 15:38:10 +00:00
|
|
|
char netname[MAXPLAYERNAME + 1];
|
2013-05-12 18:27:03 +00:00
|
|
|
BYTE team;
|
|
|
|
int aimdist, color, colorset, skin, gender;
|
|
|
|
bool neverswitch;
|
|
|
|
//fixed_t movebob, stillbob; These were never serialized!
|
|
|
|
//int playerclass; "
|
|
|
|
|
|
|
|
info.Reset();
|
|
|
|
|
|
|
|
arc.Read(&netname, sizeof(netname));
|
|
|
|
arc << team << aimdist << color << skin << gender << neverswitch << colorset;
|
|
|
|
|
|
|
|
*static_cast<FStringCVar *>(info[NAME_Name]) = netname;
|
|
|
|
*static_cast<FIntCVar *>(info[NAME_Team]) = team;
|
2013-05-18 15:38:10 +00:00
|
|
|
*static_cast<FFloatCVar *>(info[NAME_Autoaim]) = (float)aimdist / ANGLE_1;
|
2013-05-12 18:27:03 +00:00
|
|
|
*static_cast<FIntCVar *>(info[NAME_Skin]) = skin;
|
|
|
|
*static_cast<FIntCVar *>(info[NAME_Gender]) = gender;
|
|
|
|
*static_cast<FBoolCVar *>(info[NAME_NeverSwitchOnPickup]) = neverswitch;
|
|
|
|
*static_cast<FIntCVar *>(info[NAME_ColorSet]) = colorset;
|
2006-02-24 04:48:15 +00:00
|
|
|
|
2013-05-12 18:27:03 +00:00
|
|
|
UCVarValue val;
|
|
|
|
val.Int = color;
|
|
|
|
static_cast<FColorCVar *>(info[NAME_Color])->SetGenericRep(val, CVAR_Int);
|
|
|
|
}
|
2006-02-24 04:48:15 +00:00
|
|
|
|
2013-05-12 18:27:03 +00:00
|
|
|
void WriteUserInfo(FArchive &arc, userinfo_t &info)
|
|
|
|
{
|
|
|
|
TMapIterator<FName, FBaseCVar *> it(info);
|
|
|
|
TMap<FName, FBaseCVar *>::Pair *pair;
|
|
|
|
FName name;
|
|
|
|
UCVarValue val;
|
|
|
|
int i;
|
2006-02-24 04:48:15 +00:00
|
|
|
|
2013-05-12 18:27:03 +00:00
|
|
|
while (it.NextPair(pair))
|
|
|
|
{
|
|
|
|
name = pair->Key;
|
|
|
|
arc << name;
|
|
|
|
switch (name.GetIndex())
|
|
|
|
{
|
|
|
|
case NAME_Skin:
|
|
|
|
arc.WriteString(skins[info.GetSkin()].name);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NAME_PlayerClass:
|
|
|
|
i = info.GetPlayerClassNum();
|
|
|
|
arc.WriteString(i == -1 ? "Random" : PlayerClasses[i].Type->Meta.GetMetaString(APMETA_DisplayName));
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
val = pair->Value->GetGenericRep(CVAR_String);
|
|
|
|
arc.WriteString(val.String);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
name = NAME_None;
|
|
|
|
arc << name;
|
|
|
|
}
|
2006-02-24 04:48:15 +00:00
|
|
|
|
2014-02-24 22:27:57 +00:00
|
|
|
void ReadUserInfo(FArchive &arc, userinfo_t &info, FString &skin)
|
2013-05-12 18:27:03 +00:00
|
|
|
{
|
|
|
|
FName name;
|
|
|
|
FBaseCVar **cvar;
|
|
|
|
char *str = NULL;
|
|
|
|
UCVarValue val;
|
|
|
|
|
2014-02-24 22:27:57 +00:00
|
|
|
if (SaveVersion < 4253)
|
|
|
|
{
|
|
|
|
ReadCompatibleUserInfo(arc, info);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-05-12 18:27:03 +00:00
|
|
|
info.Reset();
|
2014-02-24 22:27:57 +00:00
|
|
|
skin = NULL;
|
2013-05-12 18:27:03 +00:00
|
|
|
for (arc << name; name != NAME_None; arc << name)
|
|
|
|
{
|
|
|
|
cvar = info.CheckKey(name);
|
|
|
|
arc << str;
|
|
|
|
if (cvar != NULL && *cvar != NULL)
|
|
|
|
{
|
|
|
|
switch (name)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2013-05-12 18:27:03 +00:00
|
|
|
case NAME_Team: info.TeamChanged(atoi(str)); break;
|
2014-02-24 22:27:57 +00:00
|
|
|
case NAME_Skin: skin = str; break; // Caller must call SkinChanged() once current calss is known
|
2013-05-12 18:27:03 +00:00
|
|
|
case NAME_PlayerClass: info.PlayerClassChanged(str); break;
|
|
|
|
default:
|
|
|
|
val.String = str;
|
|
|
|
(*cvar)->SetGenericRep(val, CVAR_String);
|
2006-02-24 04:48:15 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-05-12 18:27:03 +00:00
|
|
|
if (str != NULL)
|
|
|
|
{
|
|
|
|
delete[] str;
|
|
|
|
}
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CCMD (playerinfo)
|
|
|
|
{
|
|
|
|
if (argv.argc() < 2)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < MAXPLAYERS; i++)
|
|
|
|
{
|
|
|
|
if (playeringame[i])
|
|
|
|
{
|
2013-05-12 18:27:03 +00:00
|
|
|
Printf("%d. %s\n", i, players[i].userinfo.GetName());
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-05-12 18:27:03 +00:00
|
|
|
int i = atoi(argv[1]);
|
|
|
|
|
|
|
|
if (i < 0 || i >= MAXPLAYERS)
|
|
|
|
{
|
|
|
|
Printf("Bad player number\n");
|
|
|
|
return;
|
|
|
|
}
|
2008-02-16 15:02:52 +00:00
|
|
|
userinfo_t *ui = &players[i].userinfo;
|
2013-05-12 18:27:03 +00:00
|
|
|
|
|
|
|
if (!playeringame[i])
|
|
|
|
{
|
|
|
|
Printf(TEXTCOLOR_ORANGE "Player %d is not in the game\n", i);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Print special info
|
|
|
|
Printf("%20s: %s\n", "Name", ui->GetName());
|
|
|
|
Printf("%20s: %s (%d)\n", "Team", ui->GetTeam() == TEAM_NONE ? "None" : Teams[ui->GetTeam()].GetName(), ui->GetTeam());
|
|
|
|
Printf("%20s: %s (%d)\n", "Skin", skins[ui->GetSkin()].name, ui->GetSkin());
|
|
|
|
Printf("%20s: %s (%d)\n", "Gender", GenderNames[ui->GetGender()], ui->GetGender());
|
|
|
|
Printf("%20s: %s (%d)\n", "PlayerClass",
|
|
|
|
ui->GetPlayerClassNum() == -1 ? "Random" : ui->GetPlayerClassType()->Meta.GetMetaString (APMETA_DisplayName),
|
|
|
|
ui->GetPlayerClassNum());
|
|
|
|
|
|
|
|
// Print generic info
|
|
|
|
TMapIterator<FName, FBaseCVar *> it(*ui);
|
|
|
|
TMap<FName, FBaseCVar *>::Pair *pair;
|
|
|
|
|
|
|
|
while (it.NextPair(pair))
|
|
|
|
{
|
|
|
|
if (pair->Key != NAME_Name && pair->Key != NAME_Team && pair->Key != NAME_Skin &&
|
|
|
|
pair->Key != NAME_Gender && pair->Key != NAME_PlayerClass)
|
|
|
|
{
|
|
|
|
UCVarValue val = pair->Value->GetGenericRep(CVAR_String);
|
|
|
|
Printf("%20s: %s\n", pair->Key.GetChars(), val.String);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (argv.argc() > 2)
|
|
|
|
{
|
|
|
|
PrintMiscActorInfo(players[i].mo);
|
|
|
|
}
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
}
|
2013-07-14 08:58:53 +00:00
|
|
|
|
|
|
|
userinfo_t::~userinfo_t()
|
|
|
|
{
|
|
|
|
TMapIterator<FName, FBaseCVar *> it(*this);
|
|
|
|
TMap<FName, FBaseCVar *>::Pair *pair;
|
|
|
|
|
|
|
|
while (it.NextPair(pair))
|
|
|
|
{
|
|
|
|
delete pair->Value;
|
|
|
|
}
|
2013-09-19 02:14:44 +00:00
|
|
|
this->Clear();
|
2013-07-14 08:58:53 +00:00
|
|
|
}
|