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"
|
|
|
|
#include "c_dispatch.h"
|
|
|
|
#include "v_palette.h"
|
|
|
|
#include "v_video.h"
|
|
|
|
#include "i_system.h"
|
|
|
|
#include "r_draw.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"
|
2007-12-26 16:06:03 +00:00
|
|
|
#include "r_translate.h"
|
2008-01-06 04:03:33 +00:00
|
|
|
#include "templates.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);
|
|
|
|
CVAR (String, skin, "base", CVAR_USERINFO | CVAR_ARCHIVE);
|
2007-12-20 20:22:31 +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,
|
|
|
|
};
|
|
|
|
|
|
|
|
const char *GenderNames[3] = { "male", "female", "other" };
|
|
|
|
|
|
|
|
static const char *UserInfoStrings[] =
|
|
|
|
{
|
|
|
|
"name",
|
|
|
|
"autoaim",
|
|
|
|
"color",
|
|
|
|
"skin",
|
|
|
|
"team",
|
|
|
|
"gender",
|
|
|
|
"neverswitchonpickup",
|
|
|
|
"movebob",
|
|
|
|
"stillbob",
|
|
|
|
"playerclass",
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void D_GetPlayerColor (int player, float *h, float *s, float *v)
|
|
|
|
{
|
2007-12-20 20:22:31 +00:00
|
|
|
userinfo_t *info = &players[player].userinfo;
|
2008-01-06 04:03:33 +00:00
|
|
|
int color = info->color;
|
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
|
|
|
|
|
|
|
if (teamplay && TEAMINFO_IsValidTeam(info->team))
|
|
|
|
{
|
|
|
|
// 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;
|
|
|
|
int tcolor = teams[info->team].playercolor;
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
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 ()
|
|
|
|
{
|
2007-12-20 20:22:31 +00:00
|
|
|
for (int i = 0; i < (signed)teams.Size (); i++)
|
|
|
|
{
|
|
|
|
teams[i].present = 0;
|
|
|
|
teams[i].ties = 0;
|
|
|
|
}
|
|
|
|
|
2006-02-24 04:48:15 +00:00
|
|
|
int numTeams = 0;
|
|
|
|
int team;
|
|
|
|
|
|
|
|
for (int i = 0; i < MAXPLAYERS; ++i)
|
|
|
|
{
|
|
|
|
if (playeringame[i])
|
|
|
|
{
|
2007-12-20 20:22:31 +00:00
|
|
|
if (TEAMINFO_IsValidTeam (players[i].userinfo.team))
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2007-12-20 20:22:31 +00:00
|
|
|
if (teams[players[i].userinfo.team].present++ == 0)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
|
|
|
numTeams++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (numTeams < 2)
|
|
|
|
{
|
|
|
|
do
|
|
|
|
{
|
2007-12-20 20:22:31 +00:00
|
|
|
team = pr_pickteam() % teams.Size ();
|
|
|
|
} while (teams[team].present != 0);
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int lowest = INT_MAX, lowestTie = 0, i;
|
|
|
|
|
2007-12-20 20:22:31 +00:00
|
|
|
for (i = 0; i < (signed)teams.Size (); ++i)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2007-12-20 20:22:31 +00:00
|
|
|
if (teams[i].present > 0)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2007-12-20 20:22:31 +00:00
|
|
|
if (teams[i].present < lowest)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2007-12-20 20:22:31 +00:00
|
|
|
lowest = teams[i].present;
|
2006-02-24 04:48:15 +00:00
|
|
|
lowestTie = 0;
|
2007-12-20 20:22:31 +00:00
|
|
|
teams[0].ties = i;
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
2007-12-20 20:22:31 +00:00
|
|
|
else if (teams[i].present == lowest)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2007-12-20 20:22:31 +00:00
|
|
|
teams[++lowestTie].ties = i;
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (lowestTie == 0)
|
|
|
|
{
|
2007-12-20 20:22:31 +00:00
|
|
|
team = teams[0].ties;
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-12-20 20:22:31 +00:00
|
|
|
team = teams[pr_pickteam() % (lowestTie+1)].ties;
|
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
|
|
|
|
2008-01-09 02:53:38 +00:00
|
|
|
if ((dmflags2 & DF2_NO_TEAM_SWITCH) && (alwaysapplydmflags || deathmatch) && TEAMINFO_IsValidTeam (info->team))
|
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;
|
|
|
|
|
2008-01-06 10:05:24 +00:00
|
|
|
if (!TEAMINFO_IsValidTeam (team))
|
2007-12-09 03:40:02 +00:00
|
|
|
{
|
|
|
|
team = TEAM_None;
|
|
|
|
}
|
2006-02-24 04:48:15 +00:00
|
|
|
oldteam = info->team;
|
|
|
|
info->team = team;
|
|
|
|
|
2007-12-20 20:22:31 +00:00
|
|
|
if (teamplay && !TEAMINFO_IsValidTeam (info->team))
|
2006-02-24 04:48:15 +00:00
|
|
|
{ // Force players onto teams in teamplay mode
|
|
|
|
info->team = D_PickRandomTeam ();
|
|
|
|
}
|
|
|
|
if (update && oldteam != info->team)
|
|
|
|
{
|
2007-12-20 20:22:31 +00:00
|
|
|
if (TEAMINFO_IsValidTeam (info->team))
|
2007-12-23 14:13:29 +00:00
|
|
|
Printf ("%s joined the %s team\n", info->netname, teams[info->team].name.GetChars());
|
2006-02-24 04:48:15 +00:00
|
|
|
else
|
|
|
|
Printf ("%s is now a loner\n", info->netname);
|
|
|
|
}
|
|
|
|
// Let the player take on the team's color
|
|
|
|
R_BuildPlayerTranslation (pnum);
|
|
|
|
if (StatusBar != NULL && StatusBar->GetPlayer() == pnum)
|
|
|
|
{
|
|
|
|
StatusBar->AttachToPlayer (&players[pnum]);
|
|
|
|
}
|
2007-12-20 20:22:31 +00:00
|
|
|
if (!TEAMINFO_IsValidTeam (info->team))
|
2006-02-24 04:48:15 +00:00
|
|
|
info->team = TEAM_None;
|
|
|
|
}
|
|
|
|
|
|
|
|
int D_GetFragCount (player_t *player)
|
|
|
|
{
|
2007-12-20 20:22:31 +00:00
|
|
|
if (!teamplay || !TEAMINFO_IsValidTeam (player->userinfo.team))
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
|
|
|
return player->fragcount;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Count total frags for this player's team
|
|
|
|
const int team = player->userinfo.team;
|
|
|
|
int count = 0;
|
|
|
|
|
|
|
|
for (int i = 0; i < MAXPLAYERS; ++i)
|
|
|
|
{
|
|
|
|
if (playeringame[i] && players[i].userinfo.team == team)
|
|
|
|
{
|
|
|
|
count += players[i].fragcount;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void D_SetupUserInfo ()
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
userinfo_t *coninfo = &players[consoleplayer].userinfo;
|
|
|
|
|
|
|
|
for (i = 0; i < MAXPLAYERS; i++)
|
|
|
|
memset (&players[i].userinfo, 0, sizeof(userinfo_t));
|
|
|
|
|
|
|
|
strncpy (coninfo->netname, name, MAXPLAYERNAME);
|
2007-12-20 20:22:31 +00:00
|
|
|
if (teamplay && !TEAMINFO_IsValidTeam (team))
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
|
|
|
coninfo->team = D_PickRandomTeam ();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
coninfo->team = team;
|
|
|
|
}
|
|
|
|
if (autoaim > 35.f || autoaim < 0.f)
|
|
|
|
{
|
|
|
|
coninfo->aimdist = ANGLE_1*35;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
coninfo->aimdist = abs ((int)(autoaim * (float)ANGLE_1));
|
|
|
|
}
|
|
|
|
coninfo->color = color;
|
2006-07-13 10:17:56 +00:00
|
|
|
coninfo->skin = R_FindSkin (skin, 0);
|
2006-02-24 04:48:15 +00:00
|
|
|
coninfo->gender = D_GenderToInt (gender);
|
|
|
|
coninfo->neverswitch = neverswitchonpickup;
|
|
|
|
coninfo->MoveBob = (fixed_t)(65536.f * movebob);
|
|
|
|
coninfo->StillBob = (fixed_t)(65536.f * stillbob);
|
|
|
|
coninfo->PlayerClass = D_PlayerClassToInt (playerclass);
|
|
|
|
R_BuildPlayerTranslation (consoleplayer);
|
|
|
|
}
|
|
|
|
|
|
|
|
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");
|
|
|
|
|
2007-12-15 03:27:40 +00:00
|
|
|
sprintf (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])
|
|
|
|
{
|
|
|
|
UpdateTeam (i, players[i].userinfo.team, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-09-14 00:02:31 +00:00
|
|
|
void D_WriteUserInfoStrings (int i, BYTE **stream, bool compact)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
|
|
|
if (i >= MAXPLAYERS)
|
|
|
|
{
|
|
|
|
WriteByte (0, stream);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
userinfo_t *info = &players[i].userinfo;
|
|
|
|
|
2006-07-13 10:17:56 +00:00
|
|
|
const PClass *type = PlayerClasses[info->PlayerClass].Type;
|
|
|
|
|
2006-02-24 04:48:15 +00:00
|
|
|
if (!compact)
|
|
|
|
{
|
|
|
|
sprintf (*((char **)stream),
|
|
|
|
"\\name\\%s"
|
|
|
|
"\\autoaim\\%g"
|
|
|
|
"\\color\\%x %x %x"
|
|
|
|
"\\skin\\%s"
|
|
|
|
"\\team\\%d"
|
|
|
|
"\\gender\\%s"
|
|
|
|
"\\neverswitchonpickup\\%d"
|
|
|
|
"\\movebob\\%g"
|
|
|
|
"\\stillbob\\%g"
|
|
|
|
"\\playerclass\\%s"
|
|
|
|
,
|
2007-12-15 03:27:40 +00:00
|
|
|
D_EscapeUserInfo(info->netname).GetChars(),
|
2006-02-24 04:48:15 +00:00
|
|
|
(double)info->aimdist / (float)ANGLE_1,
|
|
|
|
RPART(info->color), GPART(info->color), BPART(info->color),
|
2007-12-15 03:27:40 +00:00
|
|
|
D_EscapeUserInfo(skins[info->skin].name).GetChars(),
|
|
|
|
info->team,
|
2006-02-24 04:48:15 +00:00
|
|
|
info->gender == GENDER_FEMALE ? "female" :
|
|
|
|
info->gender == GENDER_NEUTER ? "other" : "male",
|
|
|
|
info->neverswitch,
|
|
|
|
(float)(info->MoveBob) / 65536.f,
|
|
|
|
(float)(info->StillBob) / 65536.f,
|
2006-07-13 10:17:56 +00:00
|
|
|
info->PlayerClass == -1 ? "Random" :
|
2007-12-15 03:27:40 +00:00
|
|
|
D_EscapeUserInfo(type->Meta.GetMetaString (APMETA_DisplayName)).GetChars()
|
2006-02-24 04:48:15 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sprintf (*((char **)stream),
|
|
|
|
"\\"
|
|
|
|
"\\%s" // name
|
|
|
|
"\\%g" // autoaim
|
|
|
|
"\\%x %x %x" // color
|
|
|
|
"\\%s" // skin
|
|
|
|
"\\%d" // team
|
|
|
|
"\\%s" // gender
|
|
|
|
"\\%d" // neverswitchonpickup
|
|
|
|
"\\%g" // movebob
|
|
|
|
"\\%g" // stillbob
|
|
|
|
"\\%s" // playerclass
|
|
|
|
,
|
2007-12-15 03:27:40 +00:00
|
|
|
D_EscapeUserInfo(info->netname).GetChars(),
|
2006-02-24 04:48:15 +00:00
|
|
|
(double)info->aimdist / (float)ANGLE_1,
|
|
|
|
RPART(info->color), GPART(info->color), BPART(info->color),
|
2007-12-15 03:27:40 +00:00
|
|
|
D_EscapeUserInfo(skins[info->skin].name).GetChars(),
|
2006-02-24 04:48:15 +00:00
|
|
|
info->team,
|
|
|
|
info->gender == GENDER_FEMALE ? "female" :
|
|
|
|
info->gender == GENDER_NEUTER ? "other" : "male",
|
|
|
|
info->neverswitch,
|
|
|
|
(float)(info->MoveBob) / 65536.f,
|
|
|
|
(float)(info->StillBob) / 65536.f,
|
2006-07-13 10:17:56 +00:00
|
|
|
info->PlayerClass == -1 ? "Random" :
|
2007-12-15 03:27:40 +00:00
|
|
|
D_EscapeUserInfo(type->Meta.GetMetaString (APMETA_DisplayName)).GetChars()
|
2006-02-24 04:48:15 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*stream += strlen (*((char **)stream)) + 1;
|
|
|
|
}
|
|
|
|
|
2006-09-14 00:02:31 +00:00
|
|
|
void D_ReadUserInfoStrings (int i, BYTE **stream, bool update)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
|
|
|
userinfo_t *info = &players[i].userinfo;
|
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;
|
|
|
|
int infotype = -1;
|
|
|
|
|
|
|
|
if (*ptr++ != '\\')
|
|
|
|
return;
|
|
|
|
|
|
|
|
compact = (*ptr == '\\') ? ptr++, true : false;
|
|
|
|
|
|
|
|
if (i < MAXPLAYERS)
|
|
|
|
{
|
|
|
|
for (;;)
|
|
|
|
{
|
2007-12-15 03:27:40 +00:00
|
|
|
int j;
|
2006-02-24 04:48:15 +00:00
|
|
|
|
2007-12-15 03:27:40 +00:00
|
|
|
breakpt = strchr (ptr, '\\');
|
2006-02-24 04:48:15 +00:00
|
|
|
|
|
|
|
if (compact)
|
|
|
|
{
|
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
|
|
|
infotype++;
|
|
|
|
}
|
2007-12-15 03:27:40 +00:00
|
|
|
else
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
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));
|
|
|
|
}
|
2006-02-24 04:48:15 +00:00
|
|
|
|
2007-12-15 03:27:40 +00:00
|
|
|
for (j = 0;
|
|
|
|
UserInfoStrings[j] && strnicmp (UserInfoStrings[j], ptr, valstart - ptr - 1) != 0;
|
|
|
|
++j)
|
|
|
|
{ }
|
2006-02-24 04:48:15 +00:00
|
|
|
if (UserInfoStrings[j] == NULL)
|
|
|
|
{
|
|
|
|
infotype = -1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
infotype = j;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
switch (infotype)
|
|
|
|
{
|
|
|
|
case INFO_Autoaim: {
|
|
|
|
double angles;
|
|
|
|
|
|
|
|
angles = atof (value);
|
|
|
|
if (angles > 35.f || angles < 0.f)
|
|
|
|
{
|
|
|
|
info->aimdist = ANGLE_1*35;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
info->aimdist = abs ((int)(angles * (float)ANGLE_1));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case INFO_Name:
|
|
|
|
{
|
|
|
|
char oldname[MAXPLAYERNAME+1];
|
|
|
|
|
|
|
|
strncpy (oldname, info->netname, MAXPLAYERNAME);
|
|
|
|
oldname[MAXPLAYERNAME] = 0;
|
|
|
|
strncpy (info->netname, value, MAXPLAYERNAME);
|
|
|
|
info->netname[MAXPLAYERNAME] = 0;
|
|
|
|
|
|
|
|
if (update && strcmp (oldname, info->netname) != 0)
|
|
|
|
{
|
|
|
|
Printf ("%s is now known as %s\n", oldname, info->netname);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case INFO_Team:
|
|
|
|
UpdateTeam (i, atoi(value), update);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case INFO_Color:
|
|
|
|
info->color = V_GetColorFromString (NULL, value);
|
|
|
|
R_BuildPlayerTranslation (i);
|
|
|
|
if (StatusBar != NULL && i == StatusBar->GetPlayer())
|
|
|
|
{
|
|
|
|
StatusBar->AttachToPlayer (&players[i]);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case INFO_Skin:
|
2006-07-13 10:17:56 +00:00
|
|
|
info->skin = R_FindSkin (value, players[i].CurrentPlayerClass);
|
|
|
|
if (players[i].mo != NULL)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2006-07-13 10:17:56 +00:00
|
|
|
if (players[i].cls != NULL &&
|
|
|
|
players[i].mo->state->sprite.index ==
|
|
|
|
GetDefaultByType (players[i].cls)->SpawnState->sprite.index)
|
|
|
|
{ // Only change the sprite if the player is using a standard one
|
|
|
|
players[i].mo->sprite = skins[info->skin].sprite;
|
2008-04-27 22:33:19 +00:00
|
|
|
players[i].mo->scaleX = skins[info->skin].ScaleX;
|
|
|
|
players[i].mo->scaleY = skins[info->skin].ScaleY;
|
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.
|
|
|
|
R_BuildPlayerTranslation (i);
|
2006-02-24 04:48:15 +00:00
|
|
|
if (StatusBar != NULL && i == StatusBar->GetPlayer())
|
|
|
|
{
|
|
|
|
StatusBar->SetFace (&skins[info->skin]);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case INFO_Gender:
|
|
|
|
info->gender = D_GenderToInt (value);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case INFO_NeverSwitchOnPickup:
|
2008-02-09 03:09:56 +00:00
|
|
|
if (value[0] >= '0' && value[0] <= '9')
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
|
|
|
info->neverswitch = atoi (value) ? true : false;
|
|
|
|
}
|
|
|
|
else if (stricmp (value, "true") == 0)
|
|
|
|
{
|
|
|
|
info->neverswitch = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
info->neverswitch = 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case INFO_MoveBob:
|
|
|
|
info->MoveBob = (fixed_t)(atof (value) * 65536.f);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case INFO_StillBob:
|
|
|
|
info->StillBob = (fixed_t)(atof (value) * 65536.f);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case INFO_PlayerClass:
|
|
|
|
info->PlayerClass = D_PlayerClassToInt (value);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (breakpt)
|
|
|
|
{
|
|
|
|
ptr = breakpt + 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*stream += strlen (*((char **)stream)) + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
FArchive &operator<< (FArchive &arc, userinfo_t &info)
|
|
|
|
{
|
|
|
|
if (arc.IsStoring ())
|
|
|
|
{
|
|
|
|
arc.Write (&info.netname, sizeof(info.netname));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
arc.Read (&info.netname, sizeof(info.netname));
|
|
|
|
}
|
- Fixed compilation with mingw again.
- Added multiple-choice sound sequences. These overcome one of the major
deficiences of the Hexen-inherited SNDSEQ system while still being Hexen
compatible: Custom door sounds can now use different opening and closing
sequences, for both normal and blazing speeds.
- Added a serializer for TArray.
- Added a countof macro to doomtype.h. See the1's blog to find out why
it's implemented the way it is.
<http://blogs.msdn.com/the1/articles/210011.aspx>
- Added a new method to FRandom for getting random numbers larger than 255,
which lets me:
- Fixed: SNDSEQ delayrand commands could delay for no more than 255 tics.
- Fixed: If you're going to have sector_t.SoundTarget, then they need to
be included in the pointer cleanup scans.
- Ported back newer name code from 2.1.
- Fixed: Using -warp with only one parameter in Doom and Heretic to
select a map on episode 1 no longer worked.
- New: Loading a multiplayer save now restores the players based on
their names rather than on their connection order. Using connection
order was sensible when -net was the only way to start a network game,
but with -host/-join, it's not so nice. Also, if there aren't enough
players in the save, then the extra players will be spawned normally,
so you can continue a saved game with more players than you started it
with.
- Added some new SNDSEQ commands to make it possible to define Heretic's
ambient sounds in SNDSEQ: volumerel, volumerand, slot, randomsequence,
delayonce, and restart. With these, it is basically possible to obsolete
all of the $ambient SNDINFO commands.
- Fixed: Sound sequences would only execute one command each time they were
ticked.
- Fixed: No bounds checking was done on the volume sound sequences played at.
- Fixed: The tic parameter to playloop was useless and caused it to
act like a redundant playrepeat. I have removed all the logic that
caused playloop to play repeating sounds, and now it acts like an
infinite sequence of play/delay commands until the sequence is
stopped.
- Fixed: Sound sequences were ticked every frame, not every tic, so all
the delay commands were timed incorrectly and varied depending on your
framerate. Since this is useful for restarting looping sounds that got
cut off, I have not changed this. Instead, the delay commands now
record the tic when execution should resume, not the number of tics
left to delay.
SVN r57 (trunk)
2006-04-21 01:22:55 +00:00
|
|
|
arc << info.team << info.aimdist << info.color << info.skin << info.gender << info.neverswitch;
|
2006-02-24 04:48:15 +00:00
|
|
|
return arc;
|
|
|
|
}
|
|
|
|
|
|
|
|
CCMD (playerinfo)
|
|
|
|
{
|
|
|
|
if (argv.argc() < 2)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < MAXPLAYERS; i++)
|
|
|
|
{
|
|
|
|
if (playeringame[i])
|
|
|
|
{
|
|
|
|
Printf ("%d. %s\n", i, players[i].userinfo.netname);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int i = atoi (argv[1]);
|
2008-02-16 15:02:52 +00:00
|
|
|
userinfo_t *ui = &players[i].userinfo;
|
|
|
|
Printf ("Name: %s\n", ui->netname);
|
2008-02-22 00:20:11 +00:00
|
|
|
Printf ("Team: %s (%d)\n", ui->team == TEAM_None ? "None" : teams[ui->team].name.GetChars(), ui->team);
|
2008-02-16 15:02:52 +00:00
|
|
|
Printf ("Aimdist: %d\n", ui->aimdist);
|
|
|
|
Printf ("Color: %06x\n", ui->color);
|
|
|
|
Printf ("Skin: %s (%d)\n", skins[ui->skin].name, ui->skin);
|
|
|
|
Printf ("Gender: %s (%d)\n", GenderNames[ui->gender], ui->gender);
|
|
|
|
Printf ("NeverSwitch: %d\n", ui->neverswitch);
|
|
|
|
Printf ("MoveBob: %g\n", ui->MoveBob/65536.f);
|
|
|
|
Printf ("StillBob: %g\n", ui->StillBob/65536.f);
|
|
|
|
Printf ("PlayerClass: %s (%d)\n",
|
|
|
|
ui->PlayerClass == -1 ? "Random" : PlayerClasses[ui->PlayerClass].Type->Meta.GetMetaString (APMETA_DisplayName),
|
|
|
|
ui->PlayerClass);
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
}
|