Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unconfuse nodes #5

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
191 changes: 149 additions & 42 deletions src/d_clisrv.c
Original file line number Diff line number Diff line change
Expand Up @@ -2756,20 +2756,6 @@ void CL_Reset(void)
}

#ifndef NONET
static void Command_GetPlayerNum(void)
{
INT32 i;

for (i = 0; i < MAXPLAYERS; i++)
if (playeringame[i])
{
if (serverplayer == i)
CONS_Printf(M_GetText("num:%2d node:%2d %s\n"), i, playernode[i], player_names[i]);
else
CONS_Printf(M_GetText("\x82num:%2d node:%2d %s\n"), i, playernode[i], player_names[i]);
}
}

SINT8 nametonum(const char *name)
{
INT32 playernum, i;
Expand Down Expand Up @@ -2799,41 +2785,145 @@ SINT8 nametonum(const char *name)
return -1;
}

/** Lists all players and their player numbers.
/** List all players along with a short status.
*
* \sa Command_GetPlayerNum
* \sa Command_NodeTree
*/
static void Command_Nodes(void)
/*
Formatted like so, with each element separated by space and written on lines:
Two digit player number, colon (:), colored player name, left-aligned.
Then a "status" which is delimited by a double dash (--).
If available, an IP address and port.
Admin status written as "(admin)".
Spectating status written as "(spectator)".
If admin and spectating status both apply and the player's address was not
available, the status is "crammed". If the status is not "crammed", it is
indented the width of " -- self". The intended effect is that the spectating
status aligns with other spectating statuses.
*/
static void Command_ListPlayers(void)
{
INT32 i;
size_t maxlen = 0;
const char *address;
int width = 0;

for (i = 0; i < MAXPLAYERS; i++)
boolean admin;
boolean spectator;

/*
Mode of player status for an individual player (admin, spectator).
1 for admin
2 for spectator
4 for both
*/
int mode = 0;

INT32 totalplayers = 0;

const char *cc;
const char *pcc;

INT32 i;
int n;

for (i = 0; i < MAXPLAYERS; ++i)
if (playeringame[i])
{
const size_t plen = strlen(player_names[i]);
if (playeringame[i] && plen > maxlen)
maxlen = plen;
n = strlen(player_names[i]);
if (n > width)
width = n;

if (mode != 7)
{
admin = IsPlayerAdmin(i);
spectator = players[i].spectator;

if (admin)
mode |= 1;
if (spectator)
mode |= 2;
if (admin && spectator)
mode |= 4;
}
}

for (i = 0; i < MAXPLAYERS; i++)
{
for (i = 0; i < MAXPLAYERS; ++i)
if (playeringame[i])
{
CONS_Printf("%.2u: %*s", i, (int)maxlen, player_names[i]);
CONS_Printf(" - %.2d", playernode[i]);
if (I_GetNodeAddress && (address = I_GetNodeAddress(playernode[i])) != NULL)
CONS_Printf(" - %s", address);
{
admin = IsPlayerAdmin(i);
spectator = players[i].spectator;

if (IsPlayerAdmin(i))
CONS_Printf(M_GetText(" (verified admin)"));
if (admin)
cc = "\x85";/* red */
else if (spectator)
cc = "\x86";/* gray */
else
cc = "";

if (players[i].spectator)
CONS_Printf(M_GetText(" (spectator)"));
pcc = V_ApproximateSkinColorCode(players[i].skincolor);

CONS_Printf("\n");
CONS_Printf("%.2d: ""%s""%-*s""\x80", i, pcc,width, player_names[i]);

if (I_GetNodeAddress)
{
if (( address = I_GetNodeAddress(playernode[i]) ))
CONS_Printf(" -- %s", address);
else/* print spacer */
{
/* ...but not if there's a crammed status and were admin */
if (mode != 7 || !admin)
CONS_Printf(" -- ");/* -- self */
}
}

if (admin)
CONS_Printf(M_GetText("%s"" (admin)"),cc);
if (spectator)
CONS_Printf(M_GetText("%s"" (spectator)"),cc);

CONS_Printf("\n");

totalplayers++;
}

if (totalplayers == 1)
CONS_Printf("\nThere is 1 player in the game.\n");
else
CONS_Printf("\nThere are %d players in the game.\n", totalplayers);
}

/** Print a table listing all nodes, addresses and associated players.
*
* \sa Command_ListPlayers
*/
static void Command_NodeTree(void)
{
const char *address;

INT32 i;
INT32 totalnodes = 0;

for (i = 0; i < MAXNETNODES; ++i)
if (nodeingame[i])
{
CONS_Printf("* %d", i);
if (playerpernode[i] > 1)
CONS_Printf(" (%d players)", playerpernode[i]);
if (I_GetNodeAddress && ( address = I_GetNodeAddress(i) ))
CONS_Printf(" - %s", address);
CONS_Printf("\n");
#define PRINTPLAYERNODE( prefix, array ) if ((array)[i] > -1) \
CONS_Printf(prefix" (%d) %s\n", (array)[i], player_names[(array)[i]]);
PRINTPLAYERNODE ("|-", nodetoplayer4)
PRINTPLAYERNODE ("|-", nodetoplayer3)
PRINTPLAYERNODE ("|-", nodetoplayer2)
PRINTPLAYERNODE ("\\-", nodetoplayer)
#undef PRINTPLAYERNODE
CONS_Printf("\n");

totalnodes++;
}

CONS_Printf("%d/%d nodes connected.\n", totalnodes, MAXNETNODES);
}

static void Command_Ban(void)
Expand Down Expand Up @@ -3240,15 +3330,15 @@ void D_ClientServerInit(void)
VERSION/100, VERSION%100, SUBVERSION));

#ifndef NONET
COM_AddCommand("getplayernum", Command_GetPlayerNum);
COM_AddCommand("listplayers", Command_ListPlayers);
COM_AddCommand("kick", Command_Kick);
COM_AddCommand("ban", Command_Ban);
COM_AddCommand("banip", Command_BanIP);
COM_AddCommand("clearbans", Command_ClearBans);
COM_AddCommand("showbanlist", Command_ShowBan);
COM_AddCommand("reloadbans", Command_ReloadBan);
COM_AddCommand("connect", Command_connect);
COM_AddCommand("nodes", Command_Nodes);
COM_AddCommand("nodetree", Command_NodeTree);
#ifdef PACKETDROP
COM_AddCommand("drop", Command_Drop);
COM_AddCommand("droprate", Command_Droprate);
Expand Down Expand Up @@ -3485,14 +3575,31 @@ static void Got_AddPlayer(UINT8 **p, INT32 playernum)

if (netgame)
{
if (server && cv_showjoinaddress.value)
char *text;
if (server)
{
const char *address;
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.
if (cv_showjoinaddress.value &&
I_GetNodeAddress && ( address = I_GetNodeAddress(node) ))
{
text = va(
"\x82*Player %d (num %d) has joined the game (%s)",
newplayernum+1, newplayernum, address);
}
else
{
text = va(
"\x82Player %d (num %d) has joined the game",
newplayernum+1, newplayernum);
}
}
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.
{
text = va(
"\x82Player %d has joined the game",
newplayernum+1);
}
HU_AddChatText(text, false);
}

if (server && multiplayer && motd[0] != '\0')
Expand Down Expand Up @@ -4204,7 +4311,7 @@ static boolean CheckForSpeedHacks(UINT8 p)
|| netcmds[maketic%BACKUPTICS][p].driftturn > KART_FULLTURN || netcmds[maketic%BACKUPTICS][p].driftturn < -KART_FULLTURN)
{
XBOXSTATIC char buf[2];
CONS_Alert(CONS_WARNING, M_GetText("Illegal movement value received from node %d\n"), playernode[p]);
CONS_Alert(CONS_WARNING, M_GetText("Illegal movement value received from player %d\n"), p);
//D_Clearticcmd(k);

buf[0] = (char)p;
Expand Down
4 changes: 2 additions & 2 deletions src/d_netcmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -3858,7 +3858,7 @@ static void Command_Verify_f(void)

if (COM_Argc() != 2)
{
CONS_Printf(M_GetText("promote <node>: give admin privileges to a node\n"));
CONS_Printf(M_GetText("promote <playernum>: give admin privileges to a player\n"));
return;
}

Expand Down Expand Up @@ -3914,7 +3914,7 @@ static void Command_RemoveAdmin_f(void)

if (COM_Argc() != 2)
{
CONS_Printf(M_GetText("demote <node>: remove admin privileges from a node\n"));
CONS_Printf(M_GetText("demote <playernum>: remove admin privileges from a player\n"));
return;
}

Expand Down
Loading