Skip to content

Commit

Permalink
Fix OpenTTD#12076: Do not allow 'join' command on dedicated servers
Browse files Browse the repository at this point in the history
  • Loading branch information
rubidium42 committed Mar 2, 2024
1 parent 253ba0d commit aff0930
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/console_cmds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,21 @@ DEF_CONSOLE_HOOK(ConHookNeedNetwork)
return CHR_ALLOW;
}

/**
* Check whether we are in a multiplayer game and are playing, i.e. we are not the dedicated server.
* @return Are we a client or non-dedicated server in a network game? True when yes, false otherwise.
*/
DEF_CONSOLE_HOOK(ConHookNeedNonDedicatedNetwork)
{
if (!NetworkAvailable(echo)) return CHR_DISALLOW;

if (_network_dedicated) {
if (echo) IConsolePrint(CC_ERROR, "This command is not available to a dedicated network server.");
return CHR_DISALLOW;
}
return CHR_ALLOW;
}

/**
* Check whether we are in singleplayer mode.
* @return True when no network is active.
Expand Down Expand Up @@ -2693,7 +2708,7 @@ void IConsoleStdLibRegister()
IConsole::CmdRegister("reconnect", ConNetworkReconnect, ConHookClientOnly);
IConsole::CmdRegister("rcon", ConRcon, ConHookNeedNetwork);

IConsole::CmdRegister("join", ConJoinCompany, ConHookNeedNetwork);
IConsole::CmdRegister("join", ConJoinCompany, ConHookNeedNonDedicatedNetwork);
IConsole::AliasRegister("spectate", "join 255");
IConsole::CmdRegister("move", ConMoveClient, ConHookServerOnly);
IConsole::CmdRegister("reset_company", ConResetCompany, ConHookServerOnly);
Expand Down

0 comments on commit aff0930

Please sign in to comment.