mirror of
https://github.com/minetest/minetest.git
synced 2025-01-10 23:37:29 +01:00
Switch player names to std::string
This commit is contained in:
parent
603eb57943
commit
cc8e7a569e
@ -1594,7 +1594,7 @@ Inventory* Client::getInventory(const InventoryLocation &loc)
|
||||
{
|
||||
// Check if we are working with local player inventory
|
||||
LocalPlayer *player = m_env.getLocalPlayer();
|
||||
if (!player || strcmp(player->getName(), loc.name.c_str()) != 0)
|
||||
if (!player || player->getName() != loc.name)
|
||||
return NULL;
|
||||
return &player->inventory;
|
||||
}
|
||||
|
@ -385,7 +385,7 @@ void GenericCAO::processInitData(const std::string &data)
|
||||
if (m_is_player) {
|
||||
// Check if it's the current player
|
||||
LocalPlayer *player = m_env->getLocalPlayer();
|
||||
if (player && strcmp(player->getName(), m_name.c_str()) == 0) {
|
||||
if (player && player->getName() == m_name) {
|
||||
m_is_local_player = true;
|
||||
m_is_visible = false;
|
||||
player->setCAO(this);
|
||||
|
@ -19,6 +19,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
|
||||
#include "localplayer.h"
|
||||
#include <cmath>
|
||||
#include <string>
|
||||
#include "mtevent.h"
|
||||
#include "collision.h"
|
||||
#include "nodedef.h"
|
||||
@ -75,7 +76,7 @@ void PlayerSettings::settingsChangedCallback(const std::string &name, void *data
|
||||
LocalPlayer
|
||||
*/
|
||||
|
||||
LocalPlayer::LocalPlayer(Client *client, const char *name):
|
||||
LocalPlayer::LocalPlayer(Client *client, const std::string &name):
|
||||
Player(name, client->idef()),
|
||||
m_client(client)
|
||||
{
|
||||
|
@ -24,6 +24,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
#include "constants.h"
|
||||
#include "settings.h"
|
||||
#include "lighting.h"
|
||||
#include <string>
|
||||
|
||||
class Client;
|
||||
class Environment;
|
||||
@ -63,7 +64,8 @@ private:
|
||||
class LocalPlayer : public Player
|
||||
{
|
||||
public:
|
||||
LocalPlayer(Client *client, const char *name);
|
||||
|
||||
LocalPlayer(Client *client, const std::string &name);
|
||||
virtual ~LocalPlayer();
|
||||
|
||||
// Initialize hp to 0, so that no hearts will be shown if server
|
||||
|
@ -48,8 +48,7 @@ void PlayerDatabaseFiles::deSerialize(RemotePlayer *p, std::istream &is,
|
||||
|
||||
p->m_dirty = true;
|
||||
//args.getS32("version"); // Version field value not used
|
||||
const std::string &name = args.get("name");
|
||||
strlcpy(p->m_name, name.c_str(), PLAYERNAME_SIZE);
|
||||
p->m_name = args.get("name");
|
||||
|
||||
if (sao) {
|
||||
try {
|
||||
@ -96,7 +95,7 @@ void PlayerDatabaseFiles::deSerialize(RemotePlayer *p, std::istream &is,
|
||||
p->inventory.deSerialize(is);
|
||||
} catch (SerializationError &e) {
|
||||
errorstream << "Failed to deserialize player inventory. player_name="
|
||||
<< name << " " << e.what() << std::endl;
|
||||
<< p->getName() << " " << e.what() << std::endl;
|
||||
}
|
||||
|
||||
if (!p->inventory.getList("craftpreview") && p->inventory.getList("craftresult")) {
|
||||
@ -119,7 +118,7 @@ void PlayerDatabaseFiles::serialize(RemotePlayer *p, std::ostream &os)
|
||||
// Utilize a Settings object for storing values
|
||||
Settings args("PlayerArgsEnd");
|
||||
args.setS32("version", 1);
|
||||
args.set("name", p->m_name);
|
||||
args.set("name", p->getName());
|
||||
|
||||
PlayerSAO *sao = p->getPlayerSAO();
|
||||
// This should not happen
|
||||
@ -171,7 +170,7 @@ void PlayerDatabaseFiles::savePlayer(RemotePlayer *player)
|
||||
|
||||
deSerialize(&testplayer, is, path, NULL);
|
||||
is.close();
|
||||
if (strcmp(testplayer.getName(), player->getName()) == 0) {
|
||||
if (testplayer.getName() == player->getName()) {
|
||||
path_found = true;
|
||||
continue;
|
||||
}
|
||||
|
@ -468,7 +468,7 @@ void PlayerDatabasePostgreSQL::savePlayer(RemotePlayer *player)
|
||||
std::string hp = itos(sao->getHP());
|
||||
std::string breath = itos(sao->getBreath());
|
||||
const char *values[] = {
|
||||
player->getName(),
|
||||
player->getName().c_str(),
|
||||
pitch.c_str(),
|
||||
yaw.c_str(),
|
||||
posx.c_str(), posy.c_str(), posz.c_str(),
|
||||
@ -476,7 +476,7 @@ void PlayerDatabasePostgreSQL::savePlayer(RemotePlayer *player)
|
||||
breath.c_str()
|
||||
};
|
||||
|
||||
const char* rmvalues[] = { player->getName() };
|
||||
const char* rmvalues[] = { player->getName().c_str() };
|
||||
beginSave();
|
||||
|
||||
if (getPGVersion() < 90500) {
|
||||
@ -501,7 +501,7 @@ void PlayerDatabasePostgreSQL::savePlayer(RemotePlayer *player)
|
||||
inv_id = itos(i), lsize = itos(list->getSize());
|
||||
|
||||
const char* inv_values[] = {
|
||||
player->getName(),
|
||||
player->getName().c_str(),
|
||||
inv_id.c_str(),
|
||||
width.c_str(),
|
||||
name.c_str(),
|
||||
@ -516,7 +516,7 @@ void PlayerDatabasePostgreSQL::savePlayer(RemotePlayer *player)
|
||||
std::string itemStr = oss.str(), slotId = itos(j);
|
||||
|
||||
const char* invitem_values[] = {
|
||||
player->getName(),
|
||||
player->getName().c_str(),
|
||||
inv_id.c_str(),
|
||||
slotId.c_str(),
|
||||
itemStr.c_str()
|
||||
@ -529,7 +529,7 @@ void PlayerDatabasePostgreSQL::savePlayer(RemotePlayer *player)
|
||||
const StringMap &attrs = sao->getMeta().getStrings();
|
||||
for (const auto &attr : attrs) {
|
||||
const char *meta_values[] = {
|
||||
player->getName(),
|
||||
player->getName().c_str(),
|
||||
attr.first.c_str(),
|
||||
attr.second.c_str()
|
||||
};
|
||||
@ -545,7 +545,7 @@ bool PlayerDatabasePostgreSQL::loadPlayer(RemotePlayer *player, PlayerSAO *sao)
|
||||
sanity_check(sao);
|
||||
verifyDatabase();
|
||||
|
||||
const char *values[] = { player->getName() };
|
||||
const char *values[] = { player->getName().c_str() };
|
||||
PGresult *results = execPrepared("load_player", 1, values, false, false);
|
||||
|
||||
// Player not found, return not found
|
||||
@ -580,7 +580,7 @@ bool PlayerDatabasePostgreSQL::loadPlayer(RemotePlayer *player, PlayerSAO *sao)
|
||||
std::string invIdStr = itos(invId);
|
||||
|
||||
const char* values2[] = {
|
||||
player->getName(),
|
||||
player->getName().c_str(),
|
||||
invIdStr.c_str()
|
||||
};
|
||||
PGresult *results2 = execPrepared("load_player_inventory_items", 2,
|
||||
|
@ -615,7 +615,7 @@ void Server::handleCommand_InventoryAction(NetworkPacket* pkt)
|
||||
|
||||
// If something goes wrong, this player is to blame
|
||||
RollbackScopeActor rollback_scope(m_rollback,
|
||||
std::string("player:")+player->getName());
|
||||
"player:" + player->getName());
|
||||
|
||||
/*
|
||||
Note: Always set inventory not sent, to repair cases
|
||||
@ -1069,7 +1069,7 @@ void Server::handleCommand_Interact(NetworkPacket *pkt)
|
||||
If something goes wrong, this player is to blame
|
||||
*/
|
||||
RollbackScopeActor rollback_scope(m_rollback,
|
||||
std::string("player:")+player->getName());
|
||||
"player:" + player->getName());
|
||||
|
||||
switch (action) {
|
||||
// Start digging or punch object
|
||||
@ -1400,7 +1400,7 @@ void Server::handleCommand_NodeMetaFields(NetworkPacket* pkt)
|
||||
|
||||
// If something goes wrong, this player is to blame
|
||||
RollbackScopeActor rollback_scope(m_rollback,
|
||||
std::string("player:")+player->getName());
|
||||
"player:" + player->getName());
|
||||
|
||||
// Check the target node for rollback data; leave others unnoticed
|
||||
RollbackNode rn_old(&m_env->getMap(), p, this);
|
||||
|
@ -30,10 +30,10 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
#include "porting.h" // strlcpy
|
||||
|
||||
|
||||
Player::Player(const char *name, IItemDefManager *idef):
|
||||
Player::Player(const std::string name, IItemDefManager *idef):
|
||||
inventory(idef)
|
||||
{
|
||||
strlcpy(m_name, name, PLAYERNAME_SIZE);
|
||||
m_name = name;
|
||||
|
||||
inventory.clear();
|
||||
inventory.addList("main", PLAYER_INVENTORY_SIZE);
|
||||
|
@ -28,6 +28,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
#include <mutex>
|
||||
#include <functional>
|
||||
#include <tuple>
|
||||
#include <string>
|
||||
|
||||
#define PLAYERNAME_SIZE 20
|
||||
|
||||
@ -158,7 +159,7 @@ class Player
|
||||
{
|
||||
public:
|
||||
|
||||
Player(const char *name, IItemDefManager *idef);
|
||||
Player(const std::string &name, IItemDefManager *idef);
|
||||
virtual ~Player() = 0;
|
||||
|
||||
DISABLE_CLASS_COPY(Player);
|
||||
@ -178,7 +179,7 @@ public:
|
||||
// in BS-space
|
||||
v3f getSpeed() const { return m_speed; }
|
||||
|
||||
const char *getName() const { return m_name; }
|
||||
const std::string& getName() const { return m_name; }
|
||||
|
||||
u32 getFreeHudID()
|
||||
{
|
||||
@ -251,7 +252,7 @@ public:
|
||||
u16 getMaxHotbarItemcount();
|
||||
|
||||
protected:
|
||||
char m_name[PLAYERNAME_SIZE];
|
||||
std::string m_name;
|
||||
v3f m_speed; // velocity; in BS-space
|
||||
u16 m_wield_index = 0;
|
||||
PlayerFovSpec m_fov_override_spec = { 0.0f, false, 0.0f };
|
||||
|
@ -37,7 +37,7 @@ bool RemotePlayer::m_setting_cache_loaded = false;
|
||||
float RemotePlayer::m_setting_chat_message_limit_per_10sec = 0.0f;
|
||||
u16 RemotePlayer::m_setting_chat_message_limit_trigger_kick = 0;
|
||||
|
||||
RemotePlayer::RemotePlayer(const char *name, IItemDefManager *idef):
|
||||
RemotePlayer::RemotePlayer(const std::string &name, IItemDefManager *idef):
|
||||
Player(name, idef)
|
||||
{
|
||||
if (!RemotePlayer::m_setting_cache_loaded) {
|
||||
|
@ -41,7 +41,7 @@ class RemotePlayer : public Player
|
||||
friend class PlayerDatabaseFiles;
|
||||
|
||||
public:
|
||||
RemotePlayer(const char *name, IItemDefManager *idef);
|
||||
RemotePlayer(const std::string &name, IItemDefManager *idef);
|
||||
virtual ~RemotePlayer();
|
||||
|
||||
PlayerSAO *getPlayerSAO() { return m_sao; }
|
||||
|
@ -246,7 +246,7 @@ void ScriptApiServer::freeDynamicMediaCallback(u32 token)
|
||||
lua_pop(L, 2);
|
||||
}
|
||||
|
||||
void ScriptApiServer::on_dynamic_media_added(u32 token, const char *playername)
|
||||
void ScriptApiServer::on_dynamic_media_added(u32 token, const std::string &playername)
|
||||
{
|
||||
SCRIPTAPI_PRECHECKHEADER
|
||||
|
||||
@ -257,6 +257,6 @@ void ScriptApiServer::on_dynamic_media_added(u32 token, const char *playername)
|
||||
lua_rawgeti(L, -1, token);
|
||||
luaL_checktype(L, -1, LUA_TFUNCTION);
|
||||
|
||||
lua_pushstring(L, playername);
|
||||
lua_pushstring(L, playername.c_str());
|
||||
PCALL_RES(lua_pcall(L, 1, 0, error_handler));
|
||||
}
|
||||
|
@ -53,7 +53,7 @@ public:
|
||||
/* dynamic media handling */
|
||||
static u32 allocateDynamicMediaCallback(lua_State *L, int f_idx);
|
||||
void freeDynamicMediaCallback(u32 token);
|
||||
void on_dynamic_media_added(u32 token, const char *playername);
|
||||
void on_dynamic_media_added(u32 token, const std::string &playername);
|
||||
|
||||
private:
|
||||
void getAuthHandler();
|
||||
|
@ -72,7 +72,7 @@ int LuaLocalPlayer::l_get_name(lua_State *L)
|
||||
{
|
||||
LocalPlayer *player = getobject(L, 1);
|
||||
|
||||
lua_pushstring(L, player->getName());
|
||||
lua_pushstring(L, player->getName().c_str());
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -1166,7 +1166,7 @@ int ObjectRef::l_get_player_name(lua_State *L)
|
||||
return 1;
|
||||
}
|
||||
|
||||
lua_pushstring(L, player->getName());
|
||||
lua_pushstring(L, player->getName().c_str());
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -1153,7 +1153,7 @@ PlayerSAO* Server::StageTwoClientInit(session_t peer_id)
|
||||
*/
|
||||
{
|
||||
NetworkPacket notice_pkt(TOCLIENT_UPDATE_PLAYER_LIST, 0, PEER_ID_INEXISTENT);
|
||||
notice_pkt << (u8) PLAYER_LIST_ADD << (u16) 1 << std::string(player->getName());
|
||||
notice_pkt << (u8) PLAYER_LIST_ADD << (u16) 1 << player->getName();
|
||||
m_clients.sendToAll(¬ice_pkt);
|
||||
}
|
||||
{
|
||||
@ -3176,7 +3176,7 @@ std::string Server::getStatusString()
|
||||
RemotePlayer *player = m_env->getPlayer(client_id);
|
||||
|
||||
// Get name of player
|
||||
const char *name = player ? player->getName() : "<unknown>";
|
||||
const std::string name = player ? player->getName() : "<unknown>";
|
||||
|
||||
// Add name to information string
|
||||
if (!first)
|
||||
|
@ -575,10 +575,10 @@ RemotePlayer *ServerEnvironment::getPlayer(const session_t peer_id)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
RemotePlayer *ServerEnvironment::getPlayer(const char* name, bool match_invalid_peer)
|
||||
RemotePlayer *ServerEnvironment::getPlayer(const std::string &name, bool match_invalid_peer)
|
||||
{
|
||||
for (RemotePlayer *player : m_players) {
|
||||
if (strcmp(player->getName(), name) != 0)
|
||||
if (player->getName() != name)
|
||||
continue;
|
||||
|
||||
if (match_invalid_peer || player->getPeerId() != PEER_ID_INEXISTENT)
|
||||
|
@ -379,7 +379,7 @@ public:
|
||||
bool static_exists, v3s16 static_block=v3s16(0,0,0));
|
||||
|
||||
RemotePlayer *getPlayer(const session_t peer_id);
|
||||
RemotePlayer *getPlayer(const char* name, bool match_invalid_peer = false);
|
||||
RemotePlayer *getPlayer(const std::string &name, bool match_invalid_peer = false);
|
||||
const std::vector<RemotePlayer *> getPlayers() const { return m_players; }
|
||||
u32 getPlayerCount() const { return m_players.size(); }
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user