Set the player's name as soon as they enter the game
This commit is contained in:
parent
bb9a0de4f5
commit
88d239ac36
|
@ -1253,7 +1253,8 @@ static boolean CL_SendJoin(void)
|
||||||
netbuffer->u.clientcfg.localplayers = localplayers;
|
netbuffer->u.clientcfg.localplayers = localplayers;
|
||||||
netbuffer->u.clientcfg.version = VERSION;
|
netbuffer->u.clientcfg.version = VERSION;
|
||||||
netbuffer->u.clientcfg.subversion = SUBVERSION;
|
netbuffer->u.clientcfg.subversion = SUBVERSION;
|
||||||
|
strncpy(netbuffer->u.clientcfg.names[0], cv_playername.zstring, MAXPLAYERNAME);
|
||||||
|
strncpy(netbuffer->u.clientcfg.names[1], cv_playername2.zstring, MAXPLAYERNAME);
|
||||||
return HSendPacket(servernode, true, 0, sizeof (clientconfig_pak));
|
return HSendPacket(servernode, true, 0, sizeof (clientconfig_pak));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3199,6 +3200,7 @@ static void Got_AddPlayer(UINT8 **p, INT32 playernum)
|
||||||
if (!splitscreen && !botingame)
|
if (!splitscreen && !botingame)
|
||||||
CL_ClearPlayer(newplayernum);
|
CL_ClearPlayer(newplayernum);
|
||||||
playeringame[newplayernum] = true;
|
playeringame[newplayernum] = true;
|
||||||
|
READSTRINGN(*p, player_names[newplayernum], MAXPLAYERNAME);
|
||||||
G_AddPlayer(newplayernum);
|
G_AddPlayer(newplayernum);
|
||||||
if (newplayernum+1 > doomcom->numslots)
|
if (newplayernum+1 > doomcom->numslots)
|
||||||
doomcom->numslots = (INT16)(newplayernum+1);
|
doomcom->numslots = (INT16)(newplayernum+1);
|
||||||
|
@ -3231,10 +3233,10 @@ static void Got_AddPlayer(UINT8 **p, INT32 playernum)
|
||||||
{
|
{
|
||||||
const char *address;
|
const char *address;
|
||||||
if (I_GetNodeAddress && (address = I_GetNodeAddress(node)) != NULL)
|
if (I_GetNodeAddress && (address = I_GetNodeAddress(node)) != NULL)
|
||||||
HU_AddChatText(va("\x82*Player %d has joined the game (node %d) (%s)", newplayernum+1, node, address), false); // merge join notification + IP to avoid clogging console/chat.
|
HU_AddChatText(va("\x82*%s has joined the game (node %d) (%s)", player_names[newplayernum], node, address), false); // merge join notification + IP to avoid clogging console/chat.
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
HU_AddChatText(va("\x82*Player %d has joined the game (node %d)", newplayernum+1, node), false); // if you don't wanna see the join address.
|
HU_AddChatText(va("\x82*%s has joined the game (node %d)", player_names[newplayernum], node), false); // if you don't wanna see the join address.
|
||||||
}
|
}
|
||||||
|
|
||||||
if (server && multiplayer && motd[0] != '\0')
|
if (server && multiplayer && motd[0] != '\0')
|
||||||
|
@ -3245,10 +3247,11 @@ static void Got_AddPlayer(UINT8 **p, INT32 playernum)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static boolean SV_AddWaitingPlayers(void)
|
static boolean SV_AddWaitingPlayers(const char *name, const char *name2)
|
||||||
{
|
{
|
||||||
INT32 node, n, newplayer = false;
|
INT32 node, n, newplayer = false;
|
||||||
UINT8 buf[2];
|
UINT8 buf[2 + MAXPLAYERNAME];
|
||||||
|
UINT8 *p;
|
||||||
UINT8 newplayernum = 0;
|
UINT8 newplayernum = 0;
|
||||||
|
|
||||||
// What is the reason for this? Why can't newplayernum always be 0?
|
// What is the reason for this? Why can't newplayernum always be 0?
|
||||||
|
@ -3331,18 +3334,23 @@ static boolean SV_AddWaitingPlayers(void)
|
||||||
|
|
||||||
playernode[newplayernum] = (UINT8)node;
|
playernode[newplayernum] = (UINT8)node;
|
||||||
|
|
||||||
|
p = buf + 2;
|
||||||
buf[0] = (UINT8)node;
|
buf[0] = (UINT8)node;
|
||||||
buf[1] = newplayernum;
|
buf[1] = newplayernum;
|
||||||
if (playerpernode[node] < 1)
|
if (playerpernode[node] < 1)
|
||||||
|
{
|
||||||
nodetoplayer[node] = newplayernum;
|
nodetoplayer[node] = newplayernum;
|
||||||
|
WRITESTRINGN(p, name, MAXPLAYERNAME);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
nodetoplayer2[node] = newplayernum;
|
nodetoplayer2[node] = newplayernum;
|
||||||
buf[1] |= 0x80;
|
buf[1] |= 0x80;
|
||||||
|
WRITESTRINGN(p, name2, MAXPLAYERNAME);
|
||||||
}
|
}
|
||||||
playerpernode[node]++;
|
playerpernode[node]++;
|
||||||
|
|
||||||
SendNetXCmd(XD_ADDPLAYER, &buf, 2);
|
SendNetXCmd(XD_ADDPLAYER, &buf, p - buf);
|
||||||
|
|
||||||
DEBFILE(va("Server added player %d node %d\n", newplayernum, node));
|
DEBFILE(va("Server added player %d node %d\n", newplayernum, node));
|
||||||
// use the next free slot (we can't put playeringame[newplayernum] = true here)
|
// use the next free slot (we can't put playeringame[newplayernum] = true here)
|
||||||
|
@ -3404,7 +3412,7 @@ boolean SV_SpawnServer(void)
|
||||||
else doomcom->numslots = 1;
|
else doomcom->numslots = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return SV_AddWaitingPlayers();
|
return SV_AddWaitingPlayers(cv_playername.zstring, cv_playername2.zstring);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SV_StopServer(void)
|
void SV_StopServer(void)
|
||||||
|
@ -3475,6 +3483,9 @@ static size_t TotalTextCmdPerTic(tic_t tic)
|
||||||
*/
|
*/
|
||||||
static void HandleConnect(SINT8 node)
|
static void HandleConnect(SINT8 node)
|
||||||
{
|
{
|
||||||
|
char names[MAXSPLITSCREENPLAYERS][MAXPLAYERNAME + 1];
|
||||||
|
INT32 i;
|
||||||
|
|
||||||
if (bannednode && bannednode[node])
|
if (bannednode && bannednode[node])
|
||||||
SV_SendRefuse(node, M_GetText("You have been banned\nfrom the server"));
|
SV_SendRefuse(node, M_GetText("You have been banned\nfrom the server"));
|
||||||
else if (netbuffer->u.clientcfg.version != VERSION
|
else if (netbuffer->u.clientcfg.version != VERSION
|
||||||
|
@ -3494,6 +3505,16 @@ static void HandleConnect(SINT8 node)
|
||||||
boolean newnode = false;
|
boolean newnode = false;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
for (i = 0; i < netbuffer->u.clientcfg.localplayers - playerpernode[node]; i++)
|
||||||
|
{
|
||||||
|
strlcpy(names[i], netbuffer->u.clientcfg.names[i], MAXPLAYERNAME + 1);
|
||||||
|
if (!EnsurePlayerNameIsGood(names[i], -1))
|
||||||
|
{
|
||||||
|
SV_SendRefuse(node, "Bad player name");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// client authorised to join
|
// client authorised to join
|
||||||
nodewaiting[node] = (UINT8)(netbuffer->u.clientcfg.localplayers - playerpernode[node]);
|
nodewaiting[node] = (UINT8)(netbuffer->u.clientcfg.localplayers - playerpernode[node]);
|
||||||
if (!nodeingame[node])
|
if (!nodeingame[node])
|
||||||
|
@ -3534,7 +3555,7 @@ static void HandleConnect(SINT8 node)
|
||||||
SV_SendSaveGame(node); // send a complete game state
|
SV_SendSaveGame(node); // send a complete game state
|
||||||
DEBFILE("send savegame\n");
|
DEBFILE("send savegame\n");
|
||||||
}
|
}
|
||||||
SV_AddWaitingPlayers();
|
SV_AddWaitingPlayers(names[0], names[1]);
|
||||||
player_joining = true;
|
player_joining = true;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
|
|
||||||
#include "d_ticcmd.h"
|
#include "d_ticcmd.h"
|
||||||
#include "d_netcmd.h"
|
#include "d_netcmd.h"
|
||||||
|
#include "d_net.h"
|
||||||
#include "tables.h"
|
#include "tables.h"
|
||||||
#include "d_player.h"
|
#include "d_player.h"
|
||||||
|
|
||||||
|
@ -322,6 +323,7 @@ typedef struct
|
||||||
UINT8 subversion; // Contains build version
|
UINT8 subversion; // Contains build version
|
||||||
UINT8 localplayers;
|
UINT8 localplayers;
|
||||||
UINT8 mode;
|
UINT8 mode;
|
||||||
|
char names[MAXSPLITSCREENPLAYERS][MAXPLAYERNAME];
|
||||||
} ATTRPACK clientconfig_pak;
|
} ATTRPACK clientconfig_pak;
|
||||||
|
|
||||||
#define MAXSERVERNAME 32
|
#define MAXSERVERNAME 32
|
||||||
|
|
|
@ -879,7 +879,7 @@ void D_RegisterClientCommands(void)
|
||||||
* \sa CleanupPlayerName, SetPlayerName, Got_NameAndColor
|
* \sa CleanupPlayerName, SetPlayerName, Got_NameAndColor
|
||||||
* \author Graue <graue@oceanbase.org>
|
* \author Graue <graue@oceanbase.org>
|
||||||
*/
|
*/
|
||||||
static boolean IsNameGood(char *name, INT32 playernum)
|
boolean EnsurePlayerNameIsGood(char *name, INT32 playernum)
|
||||||
{
|
{
|
||||||
INT32 ix;
|
INT32 ix;
|
||||||
|
|
||||||
|
@ -920,14 +920,14 @@ static boolean IsNameGood(char *name, INT32 playernum)
|
||||||
if (len > 1)
|
if (len > 1)
|
||||||
{
|
{
|
||||||
name[len-1] = '\0';
|
name[len-1] = '\0';
|
||||||
if (!IsNameGood (name, playernum))
|
if (!EnsurePlayerNameIsGood (name, playernum))
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else if (len == 1) // Agh!
|
else if (len == 1) // Agh!
|
||||||
{
|
{
|
||||||
// Last ditch effort...
|
// Last ditch effort...
|
||||||
sprintf(name, "%d", M_RandomKey(10));
|
sprintf(name, "%d", M_RandomKey(10));
|
||||||
if (!IsNameGood (name, playernum))
|
if (!EnsurePlayerNameIsGood (name, playernum))
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -1056,12 +1056,12 @@ static void CleanupPlayerName(INT32 playernum, const char *newname)
|
||||||
* \param newname New name for that player. Should be good, but won't
|
* \param newname New name for that player. Should be good, but won't
|
||||||
* necessarily be if the client is maliciously modified or
|
* necessarily be if the client is maliciously modified or
|
||||||
* buggy.
|
* buggy.
|
||||||
* \sa CleanupPlayerName, IsNameGood
|
* \sa CleanupPlayerName, EnsurePlayerNameIsGood
|
||||||
* \author Graue <graue@oceanbase.org>
|
* \author Graue <graue@oceanbase.org>
|
||||||
*/
|
*/
|
||||||
static void SetPlayerName(INT32 playernum, char *newname)
|
static void SetPlayerName(INT32 playernum, char *newname)
|
||||||
{
|
{
|
||||||
if (IsNameGood(newname, playernum))
|
if (EnsurePlayerNameIsGood(newname, playernum))
|
||||||
{
|
{
|
||||||
if (strcasecmp(newname, player_names[playernum]) != 0)
|
if (strcasecmp(newname, player_names[playernum]) != 0)
|
||||||
{
|
{
|
||||||
|
|
|
@ -190,6 +190,7 @@ typedef union {
|
||||||
// add game commands, needs cleanup
|
// add game commands, needs cleanup
|
||||||
void D_RegisterServerCommands(void);
|
void D_RegisterServerCommands(void);
|
||||||
void D_RegisterClientCommands(void);
|
void D_RegisterClientCommands(void);
|
||||||
|
boolean EnsurePlayerNameIsGood(char *name, INT32 playernum);
|
||||||
void D_SendPlayerConfig(void);
|
void D_SendPlayerConfig(void);
|
||||||
void Command_ExitGame_f(void);
|
void Command_ExitGame_f(void);
|
||||||
void Command_Retry_f(void);
|
void Command_Retry_f(void);
|
||||||
|
|
Loading…
Reference in New Issue