1
0
Fork 0

Tab completion across worlds (#3270)

Fixes #2563.
This commit is contained in:
Alexander Harkness 2016-07-21 12:00:30 +01:00 committed by Mattes D
parent fc5fb03fec
commit a2a9341c24
5 changed files with 55 additions and 1 deletions

View File

@ -1831,12 +1831,24 @@ void cClientHandle::HandleUnmount(void)
void cClientHandle::HandleTabCompletion(const AString & a_Text)
{
AStringVector Results;
m_Player->GetWorld()->TabCompleteUserName(a_Text, Results);
// Get player name completions.
if (cRoot::Get()->GetServer()->ShouldAllowMultiWorldTabCompletion())
{
Results = cRoot::Get()->GetPlayerTabCompletionMultiWorld(a_Text);
}
else
{
m_Player->GetWorld()->TabCompleteUserName(a_Text, Results);
}
// Get command completions.
cRoot::Get()->GetPluginManager()->TabCompleteCommand(a_Text, Results, m_Player);
if (Results.empty())
{
return;
}
// Sort and send results.
std::sort(Results.begin(), Results.end());
SendTabCompletionResults(Results);
}

View File

@ -1006,3 +1006,33 @@ int cRoot::GetFurnaceFuelBurnTime(const cItem & a_Fuel)
cFurnaceRecipe * FR = Get()->GetFurnaceRecipe();
return FR->GetBurnTime(a_Fuel);
}
AStringVector cRoot::GetPlayerTabCompletionMultiWorld(const AString & a_Text)
{
AStringVector Results;
class cWorldCallback : public cWorldListCallback
{
public:
cWorldCallback(AStringVector & a_Results, const AString & a_Search) :
m_Results(a_Results),
m_Search(a_Search)
{
}
virtual bool Item(cWorld * a_World) override
{
a_World->TabCompleteUserName(m_Search, m_Results);
return true;
}
private:
AStringVector & m_Results;
const AString & m_Search;
} WC(Results, a_Text);
Get()->ForEachWorld(WC);
return Results;
}

View File

@ -89,6 +89,10 @@ public:
/** Returns the number of ticks for how long the item would fuel a furnace. Returns zero if not a fuel */
static int GetFurnaceFuelBurnTime(const cItem & a_Fuel); // tolua_export
/** Returns the completions for a player name across all worlds. Returns an
empty vector if none are found. */
AStringVector GetPlayerTabCompletionMultiWorld(const AString & a_Text);
/** The current time where the startup of the server has been completed */
std::chrono::steady_clock::time_point m_StartTime;

View File

@ -234,6 +234,7 @@ bool cServer::InitServer(cSettingsRepositoryInterface & a_Settings, bool a_Shoul
LOGWARNING("WARNING: BungeeCord is allowed and server set to online mode. This is unsafe and will not work properly. Disable either authentication or BungeeCord in settings.ini.");
}
m_ShouldAllowMultiWorldTabCompletion = a_Settings.GetValueSetB("Server", "AllowMultiWorldTabCompletion", true);
m_ShouldLoadOfflinePlayerData = a_Settings.GetValueSetB("PlayerData", "LoadOfflinePlayerData", false);
m_ShouldLoadNamedPlayerData = a_Settings.GetValueSetB("PlayerData", "LoadNamedPlayerData", true);

View File

@ -139,6 +139,10 @@ public:
it makes the server vulnerable to identity theft through direct connections. */
bool ShouldAllowBungeeCord(void) const { return m_ShouldAllowBungeeCord; }
/** Returns true if usernames should be completed across worlds. This is read
from the settings. */
bool ShouldAllowMultiWorldTabCompletion(void) const { return m_ShouldAllowMultiWorldTabCompletion; }
private:
friend class cRoot; // so cRoot can create and destroy cServer
@ -230,6 +234,9 @@ private:
/** True if BungeeCord handshake packets (with player UUID) should be accepted. */
bool m_ShouldAllowBungeeCord;
/** True if usernames should be completed across worlds. */
bool m_ShouldAllowMultiWorldTabCompletion;
/** The list of ports on which the server should listen for connections.
Initialized in InitServer(), used in Start(). */
AStringVector m_Ports;