1
0

Implemented the actual tab completion for commands and playernames.

Each command is reported only if the player has the permission to use it.
This commit is contained in:
madmaxoft 2013-07-31 11:16:11 +02:00
parent e9f18f8b4f
commit e8a907d89e
4 changed files with 30 additions and 16 deletions

View File

@ -1239,7 +1239,7 @@ void cClientHandle::HandleTabCompletion(const AString & a_Text)
{ {
AStringVector Results; AStringVector Results;
m_Player->GetWorld()->TabCompleteUserName(a_Text, Results); m_Player->GetWorld()->TabCompleteUserName(a_Text, Results);
cRoot::Get()->GetPluginManager()->TabCompleteCommand(a_Text, Results); cRoot::Get()->GetPluginManager()->TabCompleteCommand(a_Text, Results, m_Player);
if (Results.empty()) if (Results.empty())
{ {
return; return;

View File

@ -1335,14 +1335,22 @@ bool cPluginManager::ExecuteConsoleCommand(const AStringVector & a_Split, cComma
void cPluginManager::TabCompleteCommand(const AString & a_Text, AStringVector & a_Results) void cPluginManager::TabCompleteCommand(const AString & a_Text, AStringVector & a_Results, cPlayer * a_Player)
{ {
// TODO for (CommandMap::iterator itr = m_Commands.begin(), end = m_Commands.end(); itr != end; ++itr)
// DEBUG: {
LOGWARNING("%s: Not implemented yet!", __FUNCTION__); if (NoCaseCompare(itr->first.substr(0, a_Text.length()), a_Text) != 0)
a_Results.push_back(a_Text + "_plgmgr1"); {
a_Results.push_back(a_Text + "_plgmgr3"); // Command name doesn't match
a_Results.push_back(a_Text + "_plgmgr2"); continue;
}
if ((a_Player != NULL) && !a_Player->HasPermission(itr->second.m_Permission))
{
// Player doesn't have permission for the command
continue;
}
a_Results.push_back(itr->first);
}
} }

View File

@ -197,8 +197,10 @@ public: // tolua_export
/// Executes the command split into a_Split, as if it was given on the console. Returns true if executed. Output is sent to the a_Output callback /// Executes the command split into a_Split, as if it was given on the console. Returns true if executed. Output is sent to the a_Output callback
bool ExecuteConsoleCommand(const AStringVector & a_Split, cCommandOutputCallback & a_Output); bool ExecuteConsoleCommand(const AStringVector & a_Split, cCommandOutputCallback & a_Output);
/// Appends all commands beginning with a_Text (case-insensitive) into a_Results /** Appends all commands beginning with a_Text (case-insensitive) into a_Results.
void TabCompleteCommand(const AString & a_Text, AStringVector & a_Results); If a_Player is not NULL, only commands for which the player has permissions are added.
*/
void TabCompleteCommand(const AString & a_Text, AStringVector & a_Results, cPlayer * a_Player);
private: private:
friend class cRoot; friend class cRoot;

View File

@ -2366,12 +2366,16 @@ int cWorld::SpawnMob(double a_PosX, double a_PosY, double a_PosZ, int a_EntityTy
void cWorld::TabCompleteUserName(const AString & a_Text, AStringVector & a_Results) void cWorld::TabCompleteUserName(const AString & a_Text, AStringVector & a_Results)
{ {
// TODO cCSLock Lock(m_CSPlayers);
// DEBUG: for (cPlayerList::iterator itr = m_Players.begin(), end = m_Players.end(); itr != end; ++itr)
LOGWARNING("%s: Not implemented yet!", __FUNCTION__); {
a_Results.push_back(a_Text + "_world1"); if (NoCaseCompare((*itr)->GetName().substr(0, a_Text.length()), a_Text) != 0)
a_Results.push_back(a_Text + "_world3"); {
a_Results.push_back(a_Text + "_world2"); // Player name doesn't match
continue;
}
a_Results.push_back((*itr)->GetName());
}
} }