Skip to content

Commit

Permalink
CSM: Fix duplicate player names
Browse files Browse the repository at this point in the history
  • Loading branch information
SmallJoker committed Oct 21, 2023
1 parent 8a98552 commit 18d53b5
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/chat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ void ChatPrompt::historyNext()
}
}

void ChatPrompt::nickCompletion(const std::list<std::string>& names, bool backwards)
void ChatPrompt::nickCompletion(const std::set<std::string> &names, bool backwards)
{
// Two cases:
// (a) m_nick_completion_start == m_nick_completion_end == 0
Expand Down
2 changes: 1 addition & 1 deletion src/chat.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ class ChatPrompt
void historyNext();

// Nick completion
void nickCompletion(const std::list<std::string>& names, bool backwards);
void nickCompletion(const std::set<std::string> &names, bool backwards);

// Update console size and reformat the visible portion of the prompt
void reformat(u32 cols);
Expand Down
2 changes: 1 addition & 1 deletion src/client/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef
// Send the item number 'item' as player item to the server
void setPlayerItem(u16 item);

const std::list<std::string> &getConnectedPlayerNames()
const std::set<std::string> &getConnectedPlayerNames()
{
return m_env.getPlayerNames();
}
Expand Down
15 changes: 7 additions & 8 deletions src/client/clientenvironment.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#pragma once

#include "environment.h"
#include <ISceneManager.h>
#include "clientobject.h"
#include "util/numeric.h"
#include "activeobjectmgr.h"
#include "util/numeric.h" // IntervalLimiter
#include "activeobjectmgr.h" // client::ActiveObjectMgr
#include <set>

class ClientSimpleObject;
class ClientMap;
Expand Down Expand Up @@ -135,9 +134,9 @@ class ClientEnvironment : public Environment
std::vector<PointedThing> &objects
);

const std::list<std::string> &getPlayerNames() { return m_player_names; }
void addPlayerName(const std::string &name) { m_player_names.push_back(name); }
void removePlayerName(const std::string &name) { m_player_names.remove(name); }
const std::set<std::string> &getPlayerNames() { return m_player_names; }
void addPlayerName(const std::string &name) { m_player_names.insert(name); }
void removePlayerName(const std::string &name) { m_player_names.erase(name); }
void updateCameraOffset(const v3s16 &camera_offset)
{ m_camera_offset = camera_offset; }
v3s16 getCameraOffset() const { return m_camera_offset; }
Expand All @@ -156,7 +155,7 @@ class ClientEnvironment : public Environment
std::vector<ClientSimpleObject*> m_simple_objects;
std::queue<ClientEnvEvent> m_client_event_queue;
IntervalLimiter m_active_object_light_update_interval;
std::list<std::string> m_player_names;
std::set<std::string> m_player_names;
v3s16 m_camera_offset;
u64 m_frame_time = 0;
u64 m_frame_dtime = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/gui/guiChatConsole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ bool GUIChatConsole::OnEvent(const SEvent& event)
{
// Tab or Shift-Tab pressed
// Nick completion
std::list<std::string> names = m_client->getConnectedPlayerNames();
auto names = m_client->getConnectedPlayerNames();
bool backwards = event.KeyInput.Shift;
prompt.nickCompletion(names, backwards);
return true;
Expand Down
7 changes: 3 additions & 4 deletions src/script/lua_api/l_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,12 @@ int ModApiClient::l_get_player_names(lua_State *L)
if (checkCSMRestrictionFlag(CSM_RF_READ_PLAYERINFO))
return 0;

const std::list<std::string> &plist = getClient(L)->getConnectedPlayerNames();
auto plist = getClient(L)->getConnectedPlayerNames();
lua_createtable(L, plist.size(), 0);
int newTable = lua_gettop(L);
int index = 1;
std::list<std::string>::const_iterator iter;
for (iter = plist.begin(); iter != plist.end(); ++iter) {
lua_pushstring(L, (*iter).c_str());
for (const std::string &name : plist) {
lua_pushstring(L, name.c_str());
lua_rawseti(L, newTable, index);
index++;
}
Expand Down

0 comments on commit 18d53b5

Please sign in to comment.