Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit a4267de

Browse files
authored
Fix #406: improve help command in server console (#1639)
* Improve help command in server console * Add more definitions from the wiki * Update CMainConfig.h * Update CConsole.h * Update CConsoleCommand.h * refactor from string to const char*
1 parent 30eda4f commit a4267de

File tree

7 files changed

+105
-82
lines changed

7 files changed

+105
-82
lines changed

‎Server/mods/deathmatch/logic/CConsole.cpp‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,10 @@ bool CConsole::HandleInput(const char* szCommand, CClient* pClient, CClient* pEc
119119
return false;
120120
}
121121

122-
void CConsole::AddCommand(FCommandHandler* pHandler, const char* szCommand, bool bRestricted)
122+
void CConsole::AddCommand(FCommandHandler* pHandler, const char* szCommand, bool bRestricted, constchar* szConsoleHelpText)
123123
{
124124
// Make a command class and add it to the list
125-
CConsoleCommand* pCommand = new CConsoleCommand(pHandler, szCommand, bRestricted);
125+
CConsoleCommand* pCommand = new CConsoleCommand(pHandler, szCommand, bRestricted, szConsoleHelpText);
126126
m_Commands.push_back(pCommand);
127127
}
128128

‎Server/mods/deathmatch/logic/CConsole.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,14 @@ class CConsole
2424

2525
bool HandleInput(const char* szCommand, CClient* pClient, CClient* pEchoClient);
2626

27-
void AddCommand(FCommandHandler* pHandler, const char* szCommand, bool bRestricted);
27+
void AddCommand(FCommandHandler* pHandler, const char* szCommand, bool bRestricted, constchar* szConsoleHelpText);
2828
void DeleteCommand(const char* szCommand);
2929
void DeleteAllCommands();
3030
CConsoleCommand* GetCommand(const char* szKey);
3131

3232
list<CConsoleCommand*>::const_iterator CommandsBegin() { return m_Commands.begin(); };
3333
list<CConsoleCommand*>::const_iterator CommandsEnd() { return m_Commands.end(); };
34+
const auto& CommandsList() { return m_Commands; }
3435

3536
class CBlipManager* GetBlipManager() { return m_pBlipManager; };
3637
class CLuaManager* GetLuaManager() { return m_pLuaManager; };

‎Server/mods/deathmatch/logic/CConsoleCommand.cpp‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
#include "StdInc.h"
1313

14-
CConsoleCommand::CConsoleCommand(FCommandHandler* pHandler, const char* szCommand, bool bRestricted)
14+
CConsoleCommand::CConsoleCommand(FCommandHandler* pHandler, const char* szCommand, bool bRestricted, constchar* szConsoleHelpText)
1515
{
1616
// Init
1717
m_pHandler = pHandler;
@@ -20,6 +20,7 @@ CConsoleCommand::CConsoleCommand(FCommandHandler* pHandler, const char* szComman
2020
m_szCommand = new char[strlen(szCommand) + 1];
2121
strcpy(m_szCommand, szCommand);
2222
m_bRestricted = bRestricted;
23+
m_szConsoleHelpText = szConsoleHelpText;
2324
}
2425

2526
bool CConsoleCommand::operator()(CConsole* pConsole, const char* szArguments, CClient* pClient, CClient* pEchoClient)

‎Server/mods/deathmatch/logic/CConsoleCommand.h‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,18 @@ typedef bool(FCommandHandler)(class CConsole*, const char*, CClient*, CClient*);
1818
class CConsoleCommand
1919
{
2020
public:
21-
CConsoleCommand(FCommandHandler* pHandler, const char* szCommand, bool bRestricted);
21+
CConsoleCommand(FCommandHandler* pHandler, const char* szCommand, bool bRestricted, constchar* szConsoleHelpText);
2222
~CConsoleCommand() { delete[] m_szCommand; };
2323

2424
bool operator()(class CConsole* pConsole, const char* szArguments, CClient* pClient, CClient* pEchoClient);
2525
FCommandHandler* GetHandler() { return m_pHandler; };
2626
const char* GetCommand() { return m_szCommand; };
2727
bool IsRestricted() { return m_bRestricted; };
28+
const char* GetHelp() { return m_szConsoleHelpText; };
2829

2930
private:
3031
FCommandHandler* m_pHandler;
3132
char* m_szCommand;
3233
bool m_bRestricted;
34+
const char* m_szConsoleHelpText;
3335
};

‎Server/mods/deathmatch/logic/CConsoleCommands.cpp‎

Lines changed: 40 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1283,32 +1283,51 @@ bool CConsoleCommands::DebugScript(CConsole* pConsole, const char* szArguments,
12831283
bool CConsoleCommands::Help(CConsole* pConsole, const char* szArguments, CClient* pClient, CClient* pEchoClient)
12841284
{
12851285
// Help string
1286-
std::string strHelpText = "Available commands:\n\n";
1287-
1288-
// Loop through all added commands
1289-
int iCount = 0;
1290-
list<CConsoleCommand*>::const_iterator iter = pConsole->CommandsBegin();
1291-
for (; iter != pConsole->CommandsEnd(); iter++)
1286+
if (!szArguments)
12921287
{
1293-
// Add a new line every third command
1294-
if (iCount == 3)
1288+
std::string strHelpText = "Available commands:\n\n";
1289+
pEchoClient->SendConsole("help [command]");
1290+
1291+
// Loop through all added commands
1292+
int iCount = 0;
1293+
for (CConsoleCommand* command : pConsole->CommandsList())
12951294
{
1296-
iCount = 0;
1297-
strHelpText.append("\n");
1298-
}
1295+
// Add a new line every third command
1296+
if (iCount == 3)
1297+
{
1298+
iCount = 0;
1299+
strHelpText.append("\n");
1300+
}
12991301

1300-
// Add the commandname and pad it to 20 letters with spaces
1301-
const char* szCommand = (*iter)->GetCommand();
1302-
strHelpText.append(szCommand);
1303-
strHelpText.append(25 - strlen(szCommand), ' ');
1302+
// Add the commandname and pad it to 20 letters with spaces
1303+
const char* szCommand = (command)->GetCommand();
1304+
strHelpText.append(szCommand);
1305+
strHelpText.append(25 - strlen(szCommand), ' ');
13041306

1305-
// Increment count so we can keep track of how many we've put at one line
1306-
++iCount;
1307-
}
1307+
// Increment count so we can keep track of how many we've put at one line
1308+
++iCount;
1309+
}
13081310

1309-
// Show it
1310-
pEchoClient->SendConsole(strHelpText.c_str());
1311-
return true;
1311+
// Show it
1312+
pEchoClient->SendConsole(strHelpText.c_str());
1313+
return true;
1314+
}
1315+
else
1316+
{
1317+
// help [command]
1318+
if (szArguments && !strcmp(szArguments, "help") == 0)
1319+
{
1320+
CConsoleCommand* pConsoleCommand = pConsole->GetCommand(szArguments);
1321+
if (pConsoleCommand)
1322+
{
1323+
pEchoClient->SendConsole(pConsoleCommand->GetHelp());
1324+
return true;
1325+
}
1326+
else
1327+
pEchoClient->SendConsole("Couldn't find the command.");
1328+
}
1329+
}
1330+
return false;
13121331
}
13131332

13141333
bool CConsoleCommands::ReloadBans(CConsole* pConsole, const char* szArguments, CClient* pClient, CClient* pEchoClient)

‎Server/mods/deathmatch/logic/CMainConfig.cpp‎

Lines changed: 55 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -740,59 +740,59 @@ bool CMainConfig::LoadExtended()
740740
CLogger::SetMinLogLevel(LOGLEVEL_LOW);
741741

742742
// Register the commands
743-
RegisterCommand("start", CConsoleCommands::StartResource, false);
744-
RegisterCommand("stop", CConsoleCommands::StopResource, false);
745-
RegisterCommand("stopall", CConsoleCommands::StopAllResources, false);
746-
RegisterCommand("restart", CConsoleCommands::RestartResource, false);
747-
RegisterCommand("refresh", CConsoleCommands::RefreshResources, false);
748-
RegisterCommand("refreshall", CConsoleCommands::RefreshAllResources, false);
749-
RegisterCommand("list", CConsoleCommands::ListResources, false);
750-
RegisterCommand("info", CConsoleCommands::ResourceInfo, false);
751-
RegisterCommand("upgrade", CConsoleCommands::UpgradeResources, false);
752-
RegisterCommand("check", CConsoleCommands::CheckResources, false);
753-
754-
RegisterCommand("say", CConsoleCommands::Say, false);
755-
RegisterCommand("teamsay", CConsoleCommands::TeamSay, false);
756-
RegisterCommand("msg", CConsoleCommands::Msg, false);
757-
RegisterCommand("me", CConsoleCommands::Me, false);
758-
RegisterCommand("nick", CConsoleCommands::Nick, false);
759-
760-
RegisterCommand("login", CConsoleCommands::LogIn, false);
761-
RegisterCommand("logout", CConsoleCommands::LogOut, false);
762-
RegisterCommand("chgmypass", CConsoleCommands::ChgMyPass, false);
763-
764-
RegisterCommand("addaccount", CConsoleCommands::AddAccount, false);
765-
RegisterCommand("delaccount", CConsoleCommands::DelAccount, false);
766-
RegisterCommand("chgpass", CConsoleCommands::ChgPass, false);
767-
RegisterCommand("shutdown", CConsoleCommands::Shutdown, false);
768-
769-
RegisterCommand("aexec", CConsoleCommands::AExec, false);
770-
771-
RegisterCommand("whois", CConsoleCommands::WhoIs, false);
772-
773-
RegisterCommand("debugscript", CConsoleCommands::DebugScript, false);
774-
775-
RegisterCommand("help", CConsoleCommands::Help, false);
776-
777-
RegisterCommand("loadmodule", CConsoleCommands::LoadModule, false);
778-
RegisterCommand("unloadmodule", CConsoleCommands::UnloadModule, false);
779-
RegisterCommand("reloadmodule", CConsoleCommands::ReloadModule, false);
780-
781-
RegisterCommand("ver", CConsoleCommands::Ver, false);
782-
RegisterCommand("sver", CConsoleCommands::Ver, false);
783-
RegisterCommand("ase", CConsoleCommands::Ase, false);
784-
RegisterCommand("openports", CConsoleCommands::OpenPortsTest, false);
785-
786-
RegisterCommand("debugdb", CConsoleCommands::SetDbLogLevel, false);
787-
788-
RegisterCommand("reloadbans", CConsoleCommands::ReloadBans, false);
789-
790-
RegisterCommand("aclrequest", CConsoleCommands::AclRequest, false);
791-
RegisterCommand("authserial", CConsoleCommands::AuthorizeSerial, false);
792-
RegisterCommand("reloadacl", CConsoleCommands::ReloadAcl, false);
793-
RegisterCommand("debugjoinflood", CConsoleCommands::DebugJoinFlood, false);
794-
RegisterCommand("debuguptime", CConsoleCommands::DebugUpTime, false);
795-
RegisterCommand("sfakelag", CConsoleCommands::FakeLag, false);
743+
RegisterCommand("start", CConsoleCommands::StartResource, false, "Usage: start <resource-name>\nStart a loaded resource eg: start admin");
744+
RegisterCommand("stop", CConsoleCommands::StopResource, false, "Usage: stop <resource-name>\nStop a resource eg: stop admin");
745+
RegisterCommand("stopall", CConsoleCommands::StopAllResources, false, "Stop all running resources");
746+
RegisterCommand("restart", CConsoleCommands::RestartResource, false, "Usage: restart <resource-name>\nRestarts a running resource eg: restart admin");
747+
RegisterCommand("refresh", CConsoleCommands::RefreshResources, false, "Refresh resource list to find new resources");
748+
RegisterCommand("refreshall", CConsoleCommands::RefreshAllResources, false, "Refresh resources and restart any changed resources");
749+
RegisterCommand("list", CConsoleCommands::ListResources, false, "Shows a list of resources");
750+
RegisterCommand("info", CConsoleCommands::ResourceInfo, false, "Usage: info <resource-name>\nGet info for a resource eg: info admin");
751+
RegisterCommand("upgrade", CConsoleCommands::UpgradeResources, false, "Usage: upgrade [ all | <resource-name> ]\nPerform a basic upgrade of all resources.");
752+
RegisterCommand("check", CConsoleCommands::CheckResources, false, "Usage: check [ all | <resource-name> ]\nChecks which files would be changed with upgrade command. Does not modify anything.");
753+
754+
RegisterCommand("say", CConsoleCommands::Say, false, "Usage: say <text>\nShow a message to all players on the server eg: say hello");
755+
RegisterCommand("teamsay", CConsoleCommands::TeamSay, false, "Usage: teamsay <test>\nSend a message to all players on the same team");
756+
RegisterCommand("msg", CConsoleCommands::Msg, false, "Usage: msg <nick> <text>\nSend a message to a player eg: msg playername hello");
757+
RegisterCommand("me", CConsoleCommands::Me, false, "Usage: me <text>\nShow a message to all players on the server, with your nick prepended");
758+
RegisterCommand("nick", CConsoleCommands::Nick, false, "Usage: nick <old-nick> <new-nick>\nChange your ingame nickname");
759+
760+
RegisterCommand("login", CConsoleCommands::LogIn, false, "Usage: login <accountname> <password>\nLogin to an account eg: login accountname password");
761+
RegisterCommand("logout", CConsoleCommands::LogOut, false, "Log out of the current account");
762+
RegisterCommand("chgmypass", CConsoleCommands::ChgMyPass, false, "Usage: chgmypass <oldpass> <newpass>\nChange your password eg: chgmypass oldpw newpw");
763+
764+
RegisterCommand("addaccount", CConsoleCommands::AddAccount, false, "Usage: addaccount <accountname> <password>\nAdd an account eg: addaccount accountname password");
765+
RegisterCommand("delaccount", CConsoleCommands::DelAccount, false, "Usage: delaccount <accountname>\nDelete an account eg: delaccount accountname");
766+
RegisterCommand("chgpass", CConsoleCommands::ChgPass, false, "Usage: chgpass <accountname> <password>\nChange an accounts password eg: chgpass account newpw");
767+
RegisterCommand("shutdown", CConsoleCommands::Shutdown, false, "Usage: shutdown <reason>\nShutdown the server eg: shutdown put reason here");
768+
769+
RegisterCommand("aexec", CConsoleCommands::AExec, false, "Usage: aexec <nick> <command>\nForce a player to execute a command eg: aexec playername say hello");
770+
771+
RegisterCommand("whois", CConsoleCommands::WhoIs, false, "Usage: whois <nick>\nGet the IP of a player currently connected (use whowas for IP/serial/version)");
772+
773+
RegisterCommand("debugscript", CConsoleCommands::DebugScript, false, "Usage: debugscript <0-3>\nRemove (This does not work 'Incorrect client type for this command')");
774+
775+
RegisterCommand("help", CConsoleCommands::Help, false, "");
776+
777+
RegisterCommand("loadmodule", CConsoleCommands::LoadModule, false, "Usage: loadmodule <module-filename>\nLoad a module eg: loadmodule ml_sockets.dll");
778+
RegisterCommand("unloadmodule", CConsoleCommands::UnloadModule, false, "Usage: unloadmodule <module-filename>\nUnload a module eg: unloadmodule ml_sockets.dll");
779+
RegisterCommand("reloadmodule", CConsoleCommands::ReloadModule, false, "Usage: reloadmodule <module-filename>\nReload a module eg: reloadmodule ml_sockets.dll");
780+
781+
RegisterCommand("ver", CConsoleCommands::Ver, false, "Get the MTA version");
782+
RegisterCommand("sver", CConsoleCommands::Ver, false, "Get the server MTA version");
783+
RegisterCommand("ase", CConsoleCommands::Ase, false, "See the amount of master server list queries");
784+
RegisterCommand("openports", CConsoleCommands::OpenPortsTest, false, "Test if server ports are open");
785+
786+
RegisterCommand("debugdb", CConsoleCommands::SetDbLogLevel, false, "Usage: debugdb <0-2>\nSet logging level for database functions. [0-Off 1-Errors only 2-All]");
787+
788+
RegisterCommand("reloadbans", CConsoleCommands::ReloadBans, false, "Reloads all the bans from banlist.xml.");
789+
790+
RegisterCommand("aclrequest", CConsoleCommands::AclRequest, false, "Usage: aclrequest [ list | allow | deny ] <resource-name> [ <right> | all ]\nManage ACL requests from resources implementing <aclrequest> in their meta.xml");
791+
RegisterCommand("authserial", CConsoleCommands::AuthorizeSerial, false, "Usage: authserial <account-name> [list|removelast|httppass]\nManage serial authentication for an account.");
792+
RegisterCommand("reloadacl", CConsoleCommands::ReloadAcl, false, "Perform a simple ACL reload");
793+
RegisterCommand("debugjoinflood", CConsoleCommands::DebugJoinFlood, false, "Shows debug information regarding the join flood mitigation feature.");
794+
RegisterCommand("debuguptime", CConsoleCommands::DebugUpTime, false, "Shows how many days the server has been up and running.");
795+
RegisterCommand("sfakelag", CConsoleCommands::FakeLag, false, "Usage: sfakelag <packet loss> <extra ping> <ping variance> [<KBPS limit>]\nOnly available if enabled in the mtaserver.conf file.\nAdds artificial packet loss, ping, jitter and bandwidth limits to the server-client connections.");
796796
return true;
797797
}
798798

@@ -914,10 +914,10 @@ bool CMainConfig::SetFPSLimit(unsigned short usFPS, bool bSave)
914914
return false;
915915
}
916916

917-
void CMainConfig::RegisterCommand(const char* szName, FCommandHandler* pFunction, bool bRestricted)
917+
void CMainConfig::RegisterCommand(const char* szName, FCommandHandler* pFunction, bool bRestricted, constchar* szConsoleHelpText)
918918
{
919919
// Register the function with the given name and function pointer
920-
m_pConsole->AddCommand(pFunction, szName, bRestricted);
920+
m_pConsole->AddCommand(pFunction, szName, bRestricted, szConsoleHelpText);
921921
}
922922

923923
void CMainConfig::SetCommandLineParser(CCommandLineParser* pCommandLineParser)

‎Server/mods/deathmatch/logic/CMainConfig.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ class CMainConfig : public CXMLConfig
141141
void OnAseSettingChange();
142142

143143
private:
144-
void RegisterCommand(const char* szName, FCommandHandler* pFunction, bool bRestricted);
144+
void RegisterCommand(const char* szName, FCommandHandler* pFunction, bool bRestricted, constchar* szConsoleHelpText);
145145
bool GetSettingTable(const SString& strName, const char** szAttribNames, uint uiNumAttribNames, CLuaArguments* outTable);
146146
bool AddMissingSettings();
147147

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /