Skip to content

Commit

Permalink
port: net: fix team/handicap menus with 5+ players
Browse files Browse the repository at this point in the history
  • Loading branch information
fgsfdsfgs committed Jan 14, 2024
1 parent e6df601 commit 7ec54e6
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 0 deletions.
2 changes: 2 additions & 0 deletions port/include/net/net.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ void netServerStageStart(void);
void netServerStageEnd(void);
void netServerKick(struct netclient *cl, const u32 reason);

struct netclient *netClientForPlayerNum(s32 playernum);

void netClientSyncRng(void);
void netClientSettingsChanged(void);

Expand Down
15 changes: 15 additions & 0 deletions port/src/net/net.c
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,21 @@ static inline const char *netGetDisconnectReason(const u32 reason)
return msgs[0];
}

struct netclient *netClientForPlayerNum(s32 playernum)
{
s32 slot = 0;
for (s32 i = 0; i < g_NetMaxClients; ++i) {
struct netclient *cl = &g_NetClients[i];
if (cl->state >= CLSTATE_LOBBY) {
if (slot == playernum) {
return cl;
}
++slot;
}
}
return NULL;
}

void netInit(void)
{
if (enet_initialize() < 0) {
Expand Down
55 changes: 55 additions & 0 deletions src/game/mplayer/setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
#include "data.h"
#include "gbiex.h"
#include "types.h"
#ifndef PLATFORM_N64
#include "net/net.h"
#endif

struct menuitem g_MpCharacterMenuItems[];
struct menudialogdef g_MpAddSimulantMenuDialog;
Expand Down Expand Up @@ -2297,6 +2300,15 @@ MenuItemHandlerResult menuhandlerMpHandicapPlayer(s32 operation, struct menuitem
char *mpMenuTextHandicapPlayerName(struct menuitem *item)
{
if (g_MpSetup.chrslots & (1 << item->param)) {
#ifndef PLATFORM_N64
if (g_NetMode) {
// use client names directly, as the config names are not set yet
struct netclient *cl = netClientForPlayerNum(item->param);
if (cl) {
return cl->settings.name;
}
}
#endif
return g_PlayerConfigsArray[item->param].base.name;
}

Expand Down Expand Up @@ -2598,6 +2610,40 @@ struct menuitem g_MpHandicapsMenuItems[] = {
0x000000ff,
menuhandlerMpHandicapPlayer,
},
#if MAX_PLAYERS > 4
{
MENUITEMTYPE_SLIDER,
4,
MENUITEMFLAG_LESSLEFTPADDING | MENUITEMFLAG_LOCKABLEMINOR,
(uintptr_t)&mpMenuTextHandicapPlayerName,
0x000000ff,
menuhandlerMpHandicapPlayer,
},
{
MENUITEMTYPE_SLIDER,
5,
MENUITEMFLAG_LESSLEFTPADDING | MENUITEMFLAG_LOCKABLEMINOR,
(uintptr_t)&mpMenuTextHandicapPlayerName,
0x000000ff,
menuhandlerMpHandicapPlayer,
},
{
MENUITEMTYPE_SLIDER,
6,
MENUITEMFLAG_LESSLEFTPADDING | MENUITEMFLAG_LOCKABLEMINOR,
(uintptr_t)&mpMenuTextHandicapPlayerName,
0x000000ff,
menuhandlerMpHandicapPlayer,
},
{
MENUITEMTYPE_SLIDER,
7,
MENUITEMFLAG_LESSLEFTPADDING | MENUITEMFLAG_LOCKABLEMINOR,
(uintptr_t)&mpMenuTextHandicapPlayerName,
0x000000ff,
menuhandlerMpHandicapPlayer,
},
#endif
{
MENUITEMTYPE_SEPARATOR,
0,
Expand Down Expand Up @@ -3407,6 +3453,15 @@ char *mpMenuTextChrNameForTeamSetup(struct menuitem *item)
struct mpchrconfig *mpchr = mpGetChrConfigBySlotNum(item->param);

if (mpchr) {
#ifndef PLATFORM_N64
if (g_NetMode) {
// use client names directly, as the config names are not set yet
struct netclient *cl = netClientForPlayerNum(item->param);
if (cl) {
return cl->settings.name;
}
}
#endif
return mpchr->name;
}

Expand Down

0 comments on commit 7ec54e6

Please sign in to comment.