forked from Mirrorlandia_minetest/minetest
CSM: Fix duplicate player names (#13910)
This commit is contained in:
parent
3491509b21
commit
2fbf5f4250
@ -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:
|
// Two cases:
|
||||||
// (a) m_nick_completion_start == m_nick_completion_end == 0
|
// (a) m_nick_completion_start == m_nick_completion_end == 0
|
||||||
|
@ -190,7 +190,7 @@ public:
|
|||||||
void historyNext();
|
void historyNext();
|
||||||
|
|
||||||
// Nick completion
|
// 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
|
// Update console size and reformat the visible portion of the prompt
|
||||||
void reformat(u32 cols);
|
void reformat(u32 cols);
|
||||||
|
@ -288,7 +288,7 @@ public:
|
|||||||
// Send the item number 'item' as player item to the server
|
// Send the item number 'item' as player item to the server
|
||||||
void setPlayerItem(u16 item);
|
void setPlayerItem(u16 item);
|
||||||
|
|
||||||
const std::list<std::string> &getConnectedPlayerNames()
|
const std::set<std::string> &getConnectedPlayerNames()
|
||||||
{
|
{
|
||||||
return m_env.getPlayerNames();
|
return m_env.getPlayerNames();
|
||||||
}
|
}
|
||||||
|
@ -20,10 +20,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "environment.h"
|
#include "environment.h"
|
||||||
#include <ISceneManager.h>
|
#include "util/numeric.h" // IntervalLimiter
|
||||||
#include "clientobject.h"
|
#include "activeobjectmgr.h" // client::ActiveObjectMgr
|
||||||
#include "util/numeric.h"
|
#include <set>
|
||||||
#include "activeobjectmgr.h"
|
|
||||||
|
|
||||||
class ClientSimpleObject;
|
class ClientSimpleObject;
|
||||||
class ClientMap;
|
class ClientMap;
|
||||||
@ -135,9 +134,9 @@ public:
|
|||||||
std::vector<PointedThing> &objects
|
std::vector<PointedThing> &objects
|
||||||
);
|
);
|
||||||
|
|
||||||
const std::list<std::string> &getPlayerNames() { return m_player_names; }
|
const std::set<std::string> &getPlayerNames() { return m_player_names; }
|
||||||
void addPlayerName(const std::string &name) { m_player_names.push_back(name); }
|
void addPlayerName(const std::string &name) { m_player_names.insert(name); }
|
||||||
void removePlayerName(const std::string &name) { m_player_names.remove(name); }
|
void removePlayerName(const std::string &name) { m_player_names.erase(name); }
|
||||||
void updateCameraOffset(const v3s16 &camera_offset)
|
void updateCameraOffset(const v3s16 &camera_offset)
|
||||||
{ m_camera_offset = camera_offset; }
|
{ m_camera_offset = camera_offset; }
|
||||||
v3s16 getCameraOffset() const { return m_camera_offset; }
|
v3s16 getCameraOffset() const { return m_camera_offset; }
|
||||||
@ -156,7 +155,7 @@ private:
|
|||||||
std::vector<ClientSimpleObject*> m_simple_objects;
|
std::vector<ClientSimpleObject*> m_simple_objects;
|
||||||
std::queue<ClientEnvEvent> m_client_event_queue;
|
std::queue<ClientEnvEvent> m_client_event_queue;
|
||||||
IntervalLimiter m_active_object_light_update_interval;
|
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;
|
v3s16 m_camera_offset;
|
||||||
u64 m_frame_time = 0;
|
u64 m_frame_time = 0;
|
||||||
u64 m_frame_dtime = 0;
|
u64 m_frame_dtime = 0;
|
||||||
|
@ -645,7 +645,7 @@ bool GUIChatConsole::OnEvent(const SEvent& event)
|
|||||||
{
|
{
|
||||||
// Tab or Shift-Tab pressed
|
// Tab or Shift-Tab pressed
|
||||||
// Nick completion
|
// Nick completion
|
||||||
std::list<std::string> names = m_client->getConnectedPlayerNames();
|
auto names = m_client->getConnectedPlayerNames();
|
||||||
bool backwards = event.KeyInput.Shift;
|
bool backwards = event.KeyInput.Shift;
|
||||||
prompt.nickCompletion(names, backwards);
|
prompt.nickCompletion(names, backwards);
|
||||||
return true;
|
return true;
|
||||||
|
@ -150,13 +150,12 @@ int ModApiClient::l_get_player_names(lua_State *L)
|
|||||||
if (checkCSMRestrictionFlag(CSM_RF_READ_PLAYERINFO))
|
if (checkCSMRestrictionFlag(CSM_RF_READ_PLAYERINFO))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
const std::list<std::string> &plist = getClient(L)->getConnectedPlayerNames();
|
auto plist = getClient(L)->getConnectedPlayerNames();
|
||||||
lua_createtable(L, plist.size(), 0);
|
lua_createtable(L, plist.size(), 0);
|
||||||
int newTable = lua_gettop(L);
|
int newTable = lua_gettop(L);
|
||||||
int index = 1;
|
int index = 1;
|
||||||
std::list<std::string>::const_iterator iter;
|
for (const std::string &name : plist) {
|
||||||
for (iter = plist.begin(); iter != plist.end(); ++iter) {
|
lua_pushstring(L, name.c_str());
|
||||||
lua_pushstring(L, (*iter).c_str());
|
|
||||||
lua_rawseti(L, newTable, index);
|
lua_rawseti(L, newTable, index);
|
||||||
index++;
|
index++;
|
||||||
}
|
}
|
||||||
|
@ -323,10 +323,10 @@ void TerminalChatConsole::step(int ch)
|
|||||||
ChatEvent *evt = m_chat_interface->outgoing_queue.pop_frontNoEx();
|
ChatEvent *evt = m_chat_interface->outgoing_queue.pop_frontNoEx();
|
||||||
switch (evt->type) {
|
switch (evt->type) {
|
||||||
case CET_NICK_REMOVE:
|
case CET_NICK_REMOVE:
|
||||||
m_nicks.remove(((ChatEventNick *)evt)->nick);
|
m_nicks.erase(((ChatEventNick *)evt)->nick);
|
||||||
break;
|
break;
|
||||||
case CET_NICK_ADD:
|
case CET_NICK_ADD:
|
||||||
m_nicks.push_back(((ChatEventNick *)evt)->nick);
|
m_nicks.insert(((ChatEventNick *)evt)->nick);
|
||||||
break;
|
break;
|
||||||
case CET_CHAT:
|
case CET_CHAT:
|
||||||
complete_redraw_needed = true;
|
complete_redraw_needed = true;
|
||||||
|
@ -23,6 +23,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||||||
#include "threading/thread.h"
|
#include "threading/thread.h"
|
||||||
#include "util/container.h"
|
#include "util/container.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
#include <set>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
|
|
||||||
@ -103,7 +104,7 @@ private:
|
|||||||
u8 m_utf8_bytes_to_wait = 0;
|
u8 m_utf8_bytes_to_wait = 0;
|
||||||
std::string m_pending_utf8_bytes;
|
std::string m_pending_utf8_bytes;
|
||||||
|
|
||||||
std::list<std::string> m_nicks;
|
std::set<std::string> m_nicks;
|
||||||
|
|
||||||
int m_cols;
|
int m_cols;
|
||||||
int m_rows;
|
int m_rows;
|
||||||
|
Loading…
Reference in New Issue
Block a user