Skip to content

Commit

Permalink
- Switched to a genericly extensible representation for userinfo.
Browse files Browse the repository at this point in the history
- Fixed: The playerinfo CCMD did not range check the player number.

SVN r4253 (trunk)
  • Loading branch information
Randy Heit committed May 12, 2013
1 parent 404df07 commit 2668988
Show file tree
Hide file tree
Showing 37 changed files with 744 additions and 429 deletions.
5 changes: 3 additions & 2 deletions src/b_bot.cpp
Expand Up @@ -51,15 +51,16 @@ void FCajunMaster::ClearPlayer (int i, bool keepTeam)
players[i].mo = NULL;
}
botinfo_t *bot = botinfo;
while (bot && stricmp (players[i].userinfo.netname, bot->name))
while (bot && stricmp (players[i].userinfo.GetName(), bot->name))
bot = bot->next;
if (bot)
{
bot->inuse = false;
bot->lastteam = keepTeam ? players[i].userinfo.team : TEAM_NONE;
bot->lastteam = keepTeam ? players[i].userinfo.GetTeam() : TEAM_NONE;
}
players[i].~player_t();
::new(&players[i]) player_t;
players[i].userinfo.Reset();
playeringame[i] = false;
}

Expand Down
12 changes: 6 additions & 6 deletions src/b_game.cpp
Expand Up @@ -140,7 +140,7 @@ void FCajunMaster::Main (int buf)
//Check if player should go observer. Or un observe
if (bot_observer && !observer && !netgame)
{
Printf ("%s is now observer\n", players[consoleplayer].userinfo.netname);
Printf ("%s is now observer\n", players[consoleplayer].userinfo.GetName());
observer = true;
players[consoleplayer].mo->UnlinkFromWorld ();
players[consoleplayer].mo->flags = MF_DROPOFF|MF_NOBLOCKMAP|MF_NOCLIP|MF_NOTDMATCH|MF_NOGRAVITY|MF_FRIENDLY;
Expand All @@ -149,7 +149,7 @@ void FCajunMaster::Main (int buf)
}
else if (!bot_observer && observer && !netgame) //Go back
{
Printf ("%s returned to the fray\n", players[consoleplayer].userinfo.netname);
Printf ("%s returned to the fray\n", players[consoleplayer].userinfo.GetName());
observer = false;
players[consoleplayer].mo->UnlinkFromWorld ();
players[consoleplayer].mo->flags = MF_SOLID|MF_SHOOTABLE|MF_DROPOFF|MF_PICKUP|MF_NOTDMATCH|MF_FRIENDLY;
Expand Down Expand Up @@ -218,7 +218,7 @@ void FCajunMaster::End ()
{
if (deathmatch)
{
getspawned.Push(players[i].userinfo.netname);
getspawned.Push(players[i].userinfo.GetName());
}
CleanBotstuff (&players[i]);
}
Expand Down Expand Up @@ -353,7 +353,7 @@ void FCajunMaster::DoAddBot (int bnum, char *info)
if (!deathmatch && playerstarts[bnum].type == 0)
{
Printf ("%s tried to join, but there was no player %d start\n",
players[bnum].userinfo.netname, bnum+1);
players[bnum].userinfo.GetName(), bnum+1);
ClearPlayer (bnum, false); // Make the bot inactive again
if (botnum > 0)
{
Expand All @@ -370,9 +370,9 @@ void FCajunMaster::DoAddBot (int bnum, char *info)
botingame[bnum] = true;

if (teamplay)
Printf ("%s joined the %s team\n", players[bnum].userinfo.netname,Teams[players[bnum].userinfo.team].GetName ());
Printf ("%s joined the %s team\n", players[bnum].userinfo.GetName(), Teams[players[bnum].userinfo.GetTeam()].GetName());
else
Printf ("%s joined the game\n", players[bnum].userinfo.netname);
Printf ("%s joined the game\n", players[bnum].userinfo.GetName());

G_DoReborn (bnum, true);
if (StatusBar != NULL)
Expand Down
16 changes: 8 additions & 8 deletions src/bbannouncer.cpp
Expand Up @@ -231,7 +231,7 @@ bool AnnounceKill (AActor *killer, AActor *killee)

if (killer == NULL)
{ // The world killed the player
if (killee->player->userinfo.gender == GENDER_MALE)
if (killee->player->userinfo.GetGender() == GENDER_MALE)
{ // Only males have scrotums to separate
choice = &WorldKillSounds[rannum % 3];
}
Expand All @@ -244,19 +244,19 @@ bool AnnounceKill (AActor *killer, AActor *killee)
else if (killer == killee)
{ // The player killed self
choice = &SuicideSounds[rannum & 3];
killerName = killer->player->userinfo.netname;
killerName = killer->player->userinfo.GetName();
}
else
{ // Another player did the killing
if (killee->player->userinfo.gender == GENDER_MALE)
if (killee->player->userinfo.GetGender() == GENDER_MALE)
{ // Only males can be castrated
choice = &KillSounds[rannum % countof(KillSounds)];
}
else
{
choice = &KillSounds[rannum % (countof(KillSounds) - 1)];
}
killerName = killer->player->userinfo.netname;
killerName = killer->player->userinfo.GetName();

// Blood only plays the announcement sound on the killer's
// computer. I think it sounds neater to also hear it on
Expand All @@ -269,8 +269,8 @@ bool AnnounceKill (AActor *killer, AActor *killee)
{
char assembled[1024];

SexMessage (message, assembled, killee->player->userinfo.gender,
killee->player->userinfo.netname, killerName);
SexMessage (message, assembled, killee->player->userinfo.GetGender(),
killee->player->userinfo.GetName(), killerName);
Printf (PRINT_MEDIUM, "%s\n", assembled);
}
if (playSound)
Expand Down Expand Up @@ -301,8 +301,8 @@ bool AnnounceTelefrag (AActor *killer, AActor *killee)
{
char assembled[1024];

SexMessage (message, assembled, killee->player->userinfo.gender,
killee->player->userinfo.netname, killer->player->userinfo.netname);
SexMessage (message, assembled, killee->player->userinfo.GetGender(),
killee->player->userinfo.GetName(), killer->player->userinfo.GetName());
Printf (PRINT_MEDIUM, "%s\n", assembled);
}
if (killee->CheckLocalView (consoleplayer) ||
Expand Down
23 changes: 23 additions & 0 deletions src/c_cvars.cpp
Expand Up @@ -1477,6 +1477,29 @@ FBaseCVar *FindCVarSub (const char *var_name, int namelen)
return var;
}

//===========================================================================
//
// C_CreateCVar
//
// Create a new cvar with the specified name and type. It should not already
// exist.
//
//===========================================================================

FBaseCVar *C_CreateCVar(const char *var_name, ECVarType var_type, DWORD flags)
{
assert(FindCVar(var_name, NULL) == NULL);
switch (var_type)
{
case CVAR_Bool: return new FBoolCVar(var_name, 0, flags);
case CVAR_Int: return new FIntCVar(var_name, 0, flags);
case CVAR_Float: return new FFloatCVar(var_name, 0, flags);
case CVAR_String: return new FStringCVar(var_name, NULL, flags);
case CVAR_Color: return new FColorCVar(var_name, 0, flags);
default: return NULL;
}
}

void UnlatchCVars (void)
{
FLatchedValue var;
Expand Down
5 changes: 5 additions & 0 deletions src/c_cvars.h
Expand Up @@ -96,6 +96,7 @@ class FBaseCVar

inline const char *GetName () const { return Name; }
inline uint32 GetFlags () const { return Flags; }
inline FBaseCVar *GetNext() const { return m_Next; }

void CmdSet (const char *newval);
void ForceSet (UCVarValue value, ECVarType type);
Expand Down Expand Up @@ -181,6 +182,9 @@ void C_BackupCVars (void);
FBaseCVar *FindCVar (const char *var_name, FBaseCVar **prev);
FBaseCVar *FindCVarSub (const char *var_name, int namelen);

// Create a new cvar with the specified name and type
FBaseCVar *C_CreateCVar(const char *var_name, ECVarType var_type, DWORD flags);

// Called from G_InitNew()
void UnlatchCVars (void);

Expand Down Expand Up @@ -425,5 +429,6 @@ void C_ForgetCVars (void);

#define EXTERN_CVAR(type,name) extern F##type##CVar name;

extern FBaseCVar *CVars;

#endif //__C_CVARS_H__
3 changes: 2 additions & 1 deletion src/cmdlib.cpp
Expand Up @@ -755,7 +755,7 @@ FString strbin1 (const char *start)
//
//==========================================================================

void CleanseString(char *str)
char *CleanseString(char *str)
{
char *escape = strrchr(str, TEXTCOLOR_ESCAPE);
if (escape != NULL)
Expand All @@ -773,6 +773,7 @@ void CleanseString(char *str)
}
}
}
return str;
}

//==========================================================================
Expand Down
2 changes: 1 addition & 1 deletion src/cmdlib.h
Expand Up @@ -47,7 +47,7 @@ const char *myasctime ();

int strbin (char *str);
FString strbin1 (const char *start);
void CleanseString (char *str);
char *CleanseString (char *str);

void CreatePath(const char * fn);

Expand Down
28 changes: 14 additions & 14 deletions src/d_net.cpp
Expand Up @@ -596,12 +596,12 @@ void PlayerIsGone (int netnode, int netconsole)
if (deathmatch)
{
Printf ("%s left the game with %d frags\n",
players[netconsole].userinfo.netname,
players[netconsole].fragcount);
players[netconsole].userinfo.GetName(),
players[netconsole].fragcount);
}
else
{
Printf ("%s left the game\n", players[netconsole].userinfo.netname);
Printf ("%s left the game\n", players[netconsole].userinfo.GetName());
}

// [RH] Revert each player to their own view if spying through the player who left
Expand Down Expand Up @@ -646,7 +646,7 @@ void PlayerIsGone (int netnode, int netconsole)
{
Net_Arbitrator = i;
players[i].settings_controller = true;
Printf ("%s is the new arbitrator\n", players[i].userinfo.netname);
Printf ("%s is the new arbitrator\n", players[i].userinfo.GetName());
break;
}
}
Expand Down Expand Up @@ -1361,7 +1361,7 @@ bool DoArbitrate (void *userdata)
data->playersdetected[0] |= 1 << netbuffer[1];

StartScreen->NetMessage ("Found %s (node %d, player %d)",
players[netbuffer[1]].userinfo.netname,
players[netbuffer[1]].userinfo.GetName(),
node, netbuffer[1]+1);
}
}
Expand Down Expand Up @@ -1968,12 +1968,12 @@ void Net_DoCommand (int type, BYTE **stream, int player)
{
case DEM_SAY:
{
const char *name = players[player].userinfo.netname;
const char *name = players[player].userinfo.GetName();
BYTE who = ReadByte (stream);

s = ReadString (stream);
CleanseString (s);
if (((who & 1) == 0) || players[player].userinfo.team == TEAM_NONE)
if (((who & 1) == 0) || players[player].userinfo.GetTeam() == TEAM_NONE)
{ // Said to everyone
if (who & 2)
{
Expand All @@ -1985,7 +1985,7 @@ void Net_DoCommand (int type, BYTE **stream, int player)
}
S_Sound (CHAN_VOICE | CHAN_UI, gameinfo.chatSound, 1, ATTN_NONE);
}
else if (players[player].userinfo.team == players[consoleplayer].userinfo.team)
else if (players[player].userinfo.GetTeam() == players[consoleplayer].userinfo.GetTeam())
{ // Said only to members of the player's team
if (who & 2)
{
Expand Down Expand Up @@ -2392,7 +2392,7 @@ void Net_DoCommand (int type, BYTE **stream, int player)
players[playernum].settings_controller = true;

if (consoleplayer == playernum || consoleplayer == Net_Arbitrator)
Printf ("%s has been added to the controller list.\n", players[playernum].userinfo.netname);
Printf ("%s has been added to the controller list.\n", players[playernum].userinfo.GetName());
}
break;

Expand All @@ -2402,7 +2402,7 @@ void Net_DoCommand (int type, BYTE **stream, int player)
players[playernum].settings_controller = false;

if (consoleplayer == playernum || consoleplayer == Net_Arbitrator)
Printf ("%s has been removed from the controller list.\n", players[playernum].userinfo.netname);
Printf ("%s has been removed from the controller list.\n", players[playernum].userinfo.GetName());
}
break;

Expand Down Expand Up @@ -2653,7 +2653,7 @@ CCMD (pings)
for (i = 0; i < MAXPLAYERS; i++)
if (playeringame[i])
Printf ("% 4d %s\n", currrecvtime[i] - lastrecvtime[i],
players[i].userinfo.netname);
players[i].userinfo.GetName());
}

//==========================================================================
Expand All @@ -2675,13 +2675,13 @@ static void Network_Controller (int playernum, bool add)

if (players[playernum].settings_controller && add)
{
Printf ("%s is already on the setting controller list.\n", players[playernum].userinfo.netname);
Printf ("%s is already on the setting controller list.\n", players[playernum].userinfo.GetName());
return;
}

if (!players[playernum].settings_controller && !add)
{
Printf ("%s is not on the setting controller list.\n", players[playernum].userinfo.netname);
Printf ("%s is not on the setting controller list.\n", players[playernum].userinfo.GetName());
return;
}

Expand Down Expand Up @@ -2780,7 +2780,7 @@ CCMD (net_listcontrollers)

if (players[i].settings_controller)
{
Printf ("- %s\n", players[i].userinfo.netname);
Printf ("- %s\n", players[i].userinfo.GetName());
}
}
}

0 comments on commit 2668988

Please sign in to comment.