diff options
author | Loic Blot <loic.blot@unix-experience.fr> | 2016-10-08 16:31:22 +0200 |
---|---|---|
committer | Ner'zhul <nerzhul@users.noreply.github.com> | 2016-10-08 22:27:44 +0200 |
commit | fd5a130b86c08f0b3190c3d81affd4869c139fb7 (patch) | |
tree | 8300ec1e77cfd8c38292f5b81e8e0fb82de0d53d /src | |
parent | 067766eec213918b6cb5b2533d0c78eceb3949ec (diff) | |
download | minetest-fd5a130b86c08f0b3190c3d81affd4869c139fb7.tar.gz minetest-fd5a130b86c08f0b3190c3d81affd4869c139fb7.tar.bz2 minetest-fd5a130b86c08f0b3190c3d81affd4869c139fb7.zip |
More code cleanup (UNORDERED + RemotePlayer/LocalPlayer)
* ClientEnvironment now uses UNORDERED MAP for active objects
* Use RemotePlayer and LocalPlayer everywhere it's possible
* Minor code style fixes
* Drop Client::getBreath() unused function
Diffstat (limited to 'src')
-rw-r--r-- | src/client.cpp | 21 | ||||
-rw-r--r-- | src/client.h | 1 | ||||
-rw-r--r-- | src/clientiface.cpp | 13 | ||||
-rw-r--r-- | src/content_cao.cpp | 7 | ||||
-rw-r--r-- | src/environment.cpp | 105 | ||||
-rw-r--r-- | src/environment.h | 12 | ||||
-rw-r--r-- | src/network/clientpackethandler.cpp | 18 | ||||
-rw-r--r-- | src/network/serverpackethandler.cpp | 6 | ||||
-rw-r--r-- | src/script/lua_api/l_object.cpp | 36 | ||||
-rw-r--r-- | src/server.cpp | 57 |
10 files changed, 124 insertions, 152 deletions
diff --git a/src/client.cpp b/src/client.cpp index 392dabde6..cd010e592 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -383,7 +383,7 @@ void Client::step(float dtime) if(counter <= 0.0) { counter = 2.0; - Player *myplayer = m_env.getLocalPlayer(); + LocalPlayer *myplayer = m_env.getLocalPlayer(); FATAL_ERROR_IF(myplayer == NULL, "Local player not found in environment."); u16 proto_version_min = g_settings->getFlag("send_pre_v25_init") ? @@ -613,7 +613,7 @@ void Client::step(float dtime) { // Do this every <interval> seconds after TOCLIENT_INVENTORY // Reset the locally changed inventory to the authoritative inventory - Player *player = m_env.getLocalPlayer(); + LocalPlayer *player = m_env.getLocalPlayer(); player->inventory = *m_inventory_from_server; m_inventory_updated = true; } @@ -1191,7 +1191,7 @@ void Client::sendChatMessage(const std::wstring &message) void Client::sendChangePassword(const std::string &oldpassword, const std::string &newpassword) { - Player *player = m_env.getLocalPlayer(); + LocalPlayer *player = m_env.getLocalPlayer(); if (player == NULL) return; @@ -1317,7 +1317,7 @@ void Client::sendPlayerPos() void Client::sendPlayerItem(u16 item) { - Player *myplayer = m_env.getLocalPlayer(); + LocalPlayer *myplayer = m_env.getLocalPlayer(); if(myplayer == NULL) return; @@ -1398,7 +1398,7 @@ bool Client::getLocalInventoryUpdated() // Copies the inventory of the local player to parameter void Client::getLocalInventory(Inventory &dst) { - Player *player = m_env.getLocalPlayer(); + LocalPlayer *player = m_env.getLocalPlayer(); assert(player != NULL); dst = player->inventory; } @@ -1411,7 +1411,7 @@ Inventory* Client::getInventory(const InventoryLocation &loc) break; case InventoryLocation::CURRENT_PLAYER: { - Player *player = m_env.getLocalPlayer(); + LocalPlayer *player = m_env.getLocalPlayer(); assert(player != NULL); return &player->inventory; } @@ -1537,18 +1537,11 @@ void Client::setCrack(int level, v3s16 pos) u16 Client::getHP() { - Player *player = m_env.getLocalPlayer(); + LocalPlayer *player = m_env.getLocalPlayer(); assert(player != NULL); return player->hp; } -u16 Client::getBreath() -{ - Player *player = m_env.getLocalPlayer(); - assert(player != NULL); - return player->getBreath(); -} - bool Client::getChatMessage(std::wstring &message) { if(m_chat_queue.size() == 0) diff --git a/src/client.h b/src/client.h index a71c1dcbc..72baac2d2 100644 --- a/src/client.h +++ b/src/client.h @@ -460,7 +460,6 @@ public: void setCrack(int level, v3s16 pos); u16 getHP(); - u16 getBreath(); bool checkPrivilege(const std::string &priv) const { return (m_privileges.count(priv) != 0); } diff --git a/src/clientiface.cpp b/src/clientiface.cpp index e7ad39579..e55c07cb6 100644 --- a/src/clientiface.cpp +++ b/src/clientiface.cpp @@ -77,9 +77,9 @@ void RemoteClient::GetNextBlocks ( if(m_nothing_to_send_pause_timer >= 0) return; - Player *player = env->getPlayer(peer_id); + RemotePlayer *player = env->getPlayer(peer_id); // This can happen sometimes; clients and players are not in perfect sync. - if(player == NULL) + if (player == NULL) return; // Won't send anything if already sending @@ -645,8 +645,7 @@ void ClientInterface::step(float dtime) void ClientInterface::UpdatePlayerList() { - if (m_env != NULL) - { + if (m_env != NULL) { std::vector<u16> clients = getClientIDs(); m_clients_names.clear(); @@ -654,10 +653,8 @@ void ClientInterface::UpdatePlayerList() if(!clients.empty()) infostream<<"Players:"<<std::endl; - for(std::vector<u16>::iterator - i = clients.begin(); - i != clients.end(); ++i) { - Player *player = m_env->getPlayer(*i); + for (std::vector<u16>::iterator i = clients.begin(); i != clients.end(); ++i) { + RemotePlayer *player = m_env->getPlayer(*i); if (player == NULL) continue; diff --git a/src/content_cao.cpp b/src/content_cao.cpp index 207a630d7..a53768149 100644 --- a/src/content_cao.cpp +++ b/src/content_cao.cpp @@ -655,12 +655,11 @@ void GenericCAO::initialize(const std::string &data) if(m_is_player) { - Player *player = m_env->getPlayer(m_name.c_str()); - if(player && player->isLocal()) - { + LocalPlayer *player = m_env->getPlayer(m_name.c_str()); + if (player && player->isLocal()) { m_is_local_player = true; m_is_visible = false; - LocalPlayer* localplayer = dynamic_cast<LocalPlayer*>(player); + LocalPlayer* localplayer = player; assert( localplayer != NULL ); localplayer->setCAO(this); diff --git a/src/environment.cpp b/src/environment.cpp index d30b70527..bc246f66c 100644 --- a/src/environment.cpp +++ b/src/environment.cpp @@ -105,20 +105,20 @@ void Environment::removePlayer(Player* player) } } -Player * Environment::getPlayer(u16 peer_id) +Player *Environment::getPlayer(u16 peer_id) { - for(std::vector<Player*>::iterator i = m_players.begin(); + for (std::vector<Player*>::iterator i = m_players.begin(); i != m_players.end(); ++i) { Player *player = *i; - if(player->peer_id == peer_id) + if (player->peer_id == peer_id) return player; } return NULL; } -Player * Environment::getPlayer(const char *name) +Player *Environment::getPlayer(const char *name) { - for(std::vector<Player*>::iterator i = m_players.begin(); + for (std::vector<Player*>::iterator i = m_players.begin(); i != m_players.end(); ++i) { Player *player = *i; if(strcmp(player->getName(), name) == 0) @@ -602,11 +602,9 @@ void ServerEnvironment::kickAllPlayers(AccessDeniedCode reason, const std::string &str_reason, bool reconnect) { for (std::vector<Player*>::iterator it = m_players.begin(); - it != m_players.end(); - ++it) { + it != m_players.end(); ++it) { ((Server*)m_gamedef)->DenyAccessVerCompliant((*it)->peer_id, - (*it)->protocol_version, (AccessDeniedCode)reason, - str_reason, reconnect); + (*it)->protocol_version, reason, str_reason, reconnect); } } @@ -633,14 +631,14 @@ void ServerEnvironment::savePlayer(RemotePlayer *player) player->save(players_path); } -Player *ServerEnvironment::loadPlayer(const std::string &playername) +RemotePlayer *ServerEnvironment::loadPlayer(const std::string &playername) { bool newplayer = false; bool found = false; std::string players_path = m_path_world + DIR_DELIM "players" DIR_DELIM; std::string path = players_path + playername; - RemotePlayer *player = static_cast<RemotePlayer *>(getPlayer(playername.c_str())); + RemotePlayer *player = getPlayer(playername.c_str()); if (!player) { player = new RemotePlayer(m_gamedef, ""); newplayer = true; @@ -1254,10 +1252,10 @@ void ServerEnvironment::step(float dtime) */ { ScopeProfiler sp(g_profiler, "SEnv: handle players avg", SPT_AVG); - for(std::vector<Player*>::iterator i = m_players.begin(); - i != m_players.end(); ++i) - { - Player *player = *i; + for (std::vector<Player*>::iterator i = m_players.begin(); + i != m_players.end(); ++i) { + RemotePlayer *player = dynamic_cast<RemotePlayer *>(*i); + assert(player); // Ignore disconnected players if(player->peer_id == 0) @@ -1277,12 +1275,12 @@ void ServerEnvironment::step(float dtime) Get player block positions */ std::vector<v3s16> players_blockpos; - for(std::vector<Player*>::iterator - i = m_players.begin(); + for (std::vector<Player*>::iterator i = m_players.begin(); i != m_players.end(); ++i) { - Player *player = *i; + RemotePlayer *player = dynamic_cast<RemotePlayer *>(*i); + assert(player); // Ignore disconnected players - if(player->peer_id == 0) + if (player->peer_id == 0) continue; v3s16 blockpos = getNodeBlockPos( @@ -1381,8 +1379,7 @@ void ServerEnvironment::step(float dtime) block->m_node_timers.step((float)dtime); if (!elapsed_timers.empty()) { MapNode n; - for (std::vector<NodeTimer>::iterator - i = elapsed_timers.begin(); + for (std::vector<NodeTimer>::iterator i = elapsed_timers.begin(); i != elapsed_timers.end(); ++i) { n = block->getNodeNoEx(i->position); p = i->position + block->getPosRelative(); @@ -1571,7 +1568,7 @@ u16 ServerEnvironment::addActiveObject(ServerActiveObject *object) Finds out what new objects have been added to inside a radius around a position */ -void ServerEnvironment::getAddedActiveObjects(Player *player, s16 radius, +void ServerEnvironment::getAddedActiveObjects(RemotePlayer *player, s16 radius, s16 player_radius, std::set<u16> ¤t_objects, std::queue<u16> &added_objects) @@ -1624,7 +1621,7 @@ void ServerEnvironment::getAddedActiveObjects(Player *player, s16 radius, Finds out what objects have been removed from inside a radius around a position */ -void ServerEnvironment::getRemovedActiveObjects(Player *player, s16 radius, +void ServerEnvironment::getRemovedActiveObjects(RemotePlayer *player, s16 radius, s16 player_radius, std::set<u16> ¤t_objects, std::queue<u16> &removed_objects) @@ -2269,10 +2266,8 @@ ClientEnvironment::ClientEnvironment(ClientMap *map, scene::ISceneManager *smgr, ClientEnvironment::~ClientEnvironment() { // delete active objects - for(std::map<u16, ClientActiveObject*>::iterator - i = m_active_objects.begin(); - i != m_active_objects.end(); ++i) - { + for (UNORDERED_MAP<u16, ClientActiveObject*>::iterator i = m_active_objects.begin(); + i != m_active_objects.end(); ++i) { delete i->second; } @@ -2312,18 +2307,18 @@ void ClientEnvironment::addPlayer(Player *player) It is a failure if player is local and there already is a local player */ - FATAL_ERROR_IF(player->isLocal() == true && getLocalPlayer() != NULL, - "Player is local but there is already a local player"); + FATAL_ERROR_IF(player->isLocal() && getLocalPlayer() != NULL, + "Player is local but there is already a local player"); Environment::addPlayer(player); } -LocalPlayer * ClientEnvironment::getLocalPlayer() +LocalPlayer *ClientEnvironment::getLocalPlayer() { for(std::vector<Player*>::iterator i = m_players.begin(); i != m_players.end(); ++i) { Player *player = *i; - if(player->isLocal()) + if (player->isLocal()) return (LocalPlayer*)player; } return NULL; @@ -2407,11 +2402,11 @@ void ClientEnvironment::step(float dtime) { // Apply physics - if(free_move == false && is_climbing == false) + if(!free_move && !is_climbing) { // Gravity v3f speed = lplayer->getSpeed(); - if(lplayer->in_liquid == false) + if(!lplayer->in_liquid) speed.Y -= lplayer->movement_gravity * lplayer->physics_override_gravity * dtime_part * 2; // Liquid floating / sinking @@ -2566,14 +2561,15 @@ void ClientEnvironment::step(float dtime) /* Stuff that can be done in an arbitarily large dtime */ - for(std::vector<Player*>::iterator i = m_players.begin(); + for (std::vector<Player*>::iterator i = m_players.begin(); i != m_players.end(); ++i) { - Player *player = *i; + LocalPlayer *player = dynamic_cast<LocalPlayer *>(*i); + assert(player); /* Handle non-local players */ - if(player->isLocal() == false) { + if (!player->isLocal()) { // Move player->move(dtime, this, 100*BS); @@ -2604,10 +2600,8 @@ void ClientEnvironment::step(float dtime) g_profiler->avg("CEnv: num of objects", m_active_objects.size()); bool update_lighting = m_active_object_light_update_interval.step(dtime, 0.21); - for(std::map<u16, ClientActiveObject*>::iterator - i = m_active_objects.begin(); - i != m_active_objects.end(); ++i) - { + for (UNORDERED_MAP<u16, ClientActiveObject*>::iterator i = m_active_objects.begin(); + i != m_active_objects.end(); ++i) { ClientActiveObject* obj = i->second; // Step object obj->step(dtime, this); @@ -2666,15 +2660,14 @@ GenericCAO* ClientEnvironment::getGenericCAO(u16 id) ClientActiveObject* ClientEnvironment::getActiveObject(u16 id) { - std::map<u16, ClientActiveObject*>::iterator n; - n = m_active_objects.find(id); - if(n == m_active_objects.end()) + UNORDERED_MAP<u16, ClientActiveObject*>::iterator n = m_active_objects.find(id); + if (n == m_active_objects.end()) return NULL; return n->second; } -bool isFreeClientActiveObjectId(u16 id, - std::map<u16, ClientActiveObject*> &objects) +bool isFreeClientActiveObjectId(const u16 id, + UNORDERED_MAP<u16, ClientActiveObject*> &objects) { if(id == 0) return false; @@ -2682,19 +2675,17 @@ bool isFreeClientActiveObjectId(u16 id, return objects.find(id) == objects.end(); } -u16 getFreeClientActiveObjectId( - std::map<u16, ClientActiveObject*> &objects) +u16 getFreeClientActiveObjectId(UNORDERED_MAP<u16, ClientActiveObject*> &objects) { //try to reuse id's as late as possible static u16 last_used_id = 0; u16 startid = last_used_id; - for(;;) - { + for(;;) { last_used_id ++; - if(isFreeClientActiveObjectId(last_used_id, objects)) + if (isFreeClientActiveObjectId(last_used_id, objects)) return last_used_id; - if(last_used_id == startid) + if (last_used_id == startid) return 0; } } @@ -2714,8 +2705,7 @@ u16 ClientEnvironment::addActiveObject(ClientActiveObject *object) } object->setId(new_id); } - if(isFreeClientActiveObjectId(object->getId(), m_active_objects) == false) - { + if(!isFreeClientActiveObjectId(object->getId(), m_active_objects)) { infostream<<"ClientEnvironment::addActiveObject(): " <<"id is not free ("<<object->getId()<<")"<<std::endl; delete object; @@ -2779,8 +2769,7 @@ void ClientEnvironment::removeActiveObject(u16 id) verbosestream<<"ClientEnvironment::removeActiveObject(): " <<"id="<<id<<std::endl; ClientActiveObject* obj = getActiveObject(id); - if(obj == NULL) - { + if (obj == NULL) { infostream<<"ClientEnvironment::removeActiveObject(): " <<"id="<<id<<" not found"<<std::endl; return; @@ -2848,10 +2837,8 @@ void ClientEnvironment::updateLocalPlayerBreath(u16 breath) void ClientEnvironment::getActiveObjects(v3f origin, f32 max_d, std::vector<DistanceSortedActiveObject> &dest) { - for(std::map<u16, ClientActiveObject*>::iterator - i = m_active_objects.begin(); - i != m_active_objects.end(); ++i) - { + for (UNORDERED_MAP<u16, ClientActiveObject*>::iterator i = m_active_objects.begin(); + i != m_active_objects.end(); ++i) { ClientActiveObject* obj = i->second; f32 d = (obj->getPosition() - origin).getLength(); diff --git a/src/environment.h b/src/environment.h index 66d9c19c0..99066c367 100644 --- a/src/environment.h +++ b/src/environment.h @@ -94,8 +94,8 @@ public: u32 m_added_objects; protected: - Player * getPlayer(u16 peer_id); - Player * getPlayer(const char *name); + Player *getPlayer(u16 peer_id); + Player *getPlayer(const char *name); // peer_ids in here should be unique, except that there may be many 0s std::vector<Player*> m_players; @@ -324,7 +324,7 @@ public: // Save players void saveLoadedPlayers(); void savePlayer(RemotePlayer *player); - Player *loadPlayer(const std::string &playername); + RemotePlayer *loadPlayer(const std::string &playername); /* Save and load time of day and game timer @@ -368,7 +368,7 @@ public: Find out what new objects have been added to inside a radius around a position */ - void getAddedActiveObjects(Player *player, s16 radius, + void getAddedActiveObjects(RemotePlayer *player, s16 radius, s16 player_radius, std::set<u16> ¤t_objects, std::queue<u16> &added_objects); @@ -377,7 +377,7 @@ public: Find out what new objects have been removed from inside a radius around a position */ - void getRemovedActiveObjects(Player* player, s16 radius, + void getRemovedActiveObjects(RemotePlayer* player, s16 radius, s16 player_radius, std::set<u16> ¤t_objects, std::queue<u16> &removed_objects); @@ -649,7 +649,7 @@ private: ITextureSource *m_texturesource; IGameDef *m_gamedef; IrrlichtDevice *m_irr; - std::map<u16, ClientActiveObject*> m_active_objects; + UNORDERED_MAP<u16, ClientActiveObject*> m_active_objects; std::vector<ClientSimpleObject*> m_simple_objects; std::queue<ClientEnvEvent> m_client_event_queue; IntervalLimiter m_active_object_light_update_interval; diff --git a/src/network/clientpackethandler.cpp b/src/network/clientpackethandler.cpp index 35e350f20..b39356e92 100644 --- a/src/network/clientpackethandler.cpp +++ b/src/network/clientpackethandler.cpp @@ -110,7 +110,7 @@ void Client::handleCommand_AuthAccept(NetworkPacket* pkt) playerpos -= v3f(0, BS / 2, 0); // Set player position - Player *player = m_env.getLocalPlayer(); + LocalPlayer *player = m_env.getLocalPlayer(); assert(player != NULL); player->setPosition(playerpos); @@ -176,7 +176,7 @@ void Client::handleCommand_InitLegacy(NetworkPacket* pkt) // Set player position - Player *player = m_env.getLocalPlayer(); + LocalPlayer *player = m_env.getLocalPlayer(); assert(player != NULL); player->setPosition(playerpos_f); @@ -333,7 +333,7 @@ void Client::handleCommand_Inventory(NetworkPacket* pkt) std::string datastring(pkt->getString(0), pkt->getSize()); std::istringstream is(datastring, std::ios_base::binary); - Player *player = m_env.getLocalPlayer(); + LocalPlayer *player = m_env.getLocalPlayer(); assert(player != NULL); player->inventory.deSerialize(is); @@ -486,7 +486,7 @@ void Client::handleCommand_ActiveObjectMessages(NetworkPacket* pkt) void Client::handleCommand_Movement(NetworkPacket* pkt) { - Player *player = m_env.getLocalPlayer(); + LocalPlayer *player = m_env.getLocalPlayer(); assert(player != NULL); float mad, maa, maf, msw, mscr, msf, mscl, msj, lf, lfs, ls, g; @@ -511,7 +511,7 @@ void Client::handleCommand_Movement(NetworkPacket* pkt) void Client::handleCommand_HP(NetworkPacket* pkt) { - Player *player = m_env.getLocalPlayer(); + LocalPlayer *player = m_env.getLocalPlayer(); assert(player != NULL); u8 oldhp = player->hp; @@ -532,7 +532,7 @@ void Client::handleCommand_HP(NetworkPacket* pkt) void Client::handleCommand_Breath(NetworkPacket* pkt) { - Player *player = m_env.getLocalPlayer(); + LocalPlayer *player = m_env.getLocalPlayer(); assert(player != NULL); u16 breath; @@ -544,7 +544,7 @@ void Client::handleCommand_Breath(NetworkPacket* pkt) void Client::handleCommand_MovePlayer(NetworkPacket* pkt) { - Player *player = m_env.getLocalPlayer(); + LocalPlayer *player = m_env.getLocalPlayer(); assert(player != NULL); v3f pos; @@ -840,7 +840,7 @@ void Client::handleCommand_Privileges(NetworkPacket* pkt) void Client::handleCommand_InventoryFormSpec(NetworkPacket* pkt) { - Player *player = m_env.getLocalPlayer(); + LocalPlayer *player = m_env.getLocalPlayer(); assert(player != NULL); // Store formspec in LocalPlayer @@ -1098,7 +1098,7 @@ void Client::handleCommand_HudSetFlags(NetworkPacket* pkt) *pkt >> flags >> mask; - Player *player = m_env.getLocalPlayer(); + LocalPlayer *player = m_env.getLocalPlayer(); assert(player != NULL); bool was_minimap_visible = player->hud_flags & HUD_FLAG_MINIMAP_VISIBLE; diff --git a/src/network/serverpackethandler.cpp b/src/network/serverpackethandler.cpp index 6ef768295..554025747 100644 --- a/src/network/serverpackethandler.cpp +++ b/src/network/serverpackethandler.cpp @@ -1052,7 +1052,7 @@ void Server::handleCommand_ChatMessage(NetworkPacket* pkt) message += (wchar_t)tmp_wchar; } - Player *player = m_env->getPlayer(pkt->getPeerId()); + RemotePlayer *player = m_env->getPlayer(pkt->getPeerId()); if (player == NULL) { errorstream << "Server::ProcessData(): Canceling: " "No player for peer_id=" << pkt->getPeerId() @@ -1179,7 +1179,7 @@ void Server::handleCommand_Password(NetworkPacket* pkt) newpwd += c; } - Player *player = m_env->getPlayer(pkt->getPeerId()); + RemotePlayer *player = m_env->getPlayer(pkt->getPeerId()); if (player == NULL) { errorstream << "Server::ProcessData(): Canceling: " "No player for peer_id=" << pkt->getPeerId() @@ -1255,7 +1255,7 @@ void Server::handleCommand_PlayerItem(NetworkPacket* pkt) void Server::handleCommand_Respawn(NetworkPacket* pkt) { - Player *player = m_env->getPlayer(pkt->getPeerId()); + RemotePlayer *player = m_env->getPlayer(pkt->getPeerId()); if (player == NULL) { errorstream << "Server::ProcessData(): Canceling: " "No player for peer_id=" << pkt->getPeerId() diff --git a/src/script/lua_api/l_object.cpp b/src/script/lua_api/l_object.cpp index b58d8e6cd..74b33da37 100644 --- a/src/script/lua_api/l_object.cpp +++ b/src/script/lua_api/l_object.cpp @@ -533,7 +533,7 @@ int ObjectRef::l_get_local_animation(lua_State *L) { NO_MAP_LOCK_REQUIRED ObjectRef *ref = checkobject(L, 1); - Player *player = getplayer(ref); + RemotePlayer *player = getplayer(ref); if (player == NULL) return 0; @@ -584,7 +584,7 @@ int ObjectRef::l_get_eye_offset(lua_State *L) { NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); - Player *player = getplayer(ref); + RemotePlayer *player = getplayer(ref); if (player == NULL) return 0; // Do it @@ -762,7 +762,7 @@ int ObjectRef::l_is_player(lua_State *L) { NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); - Player *player = getplayer(ref); + RemotePlayer *player = getplayer(ref); lua_pushboolean(L, (player != NULL)); return 1; } @@ -973,7 +973,7 @@ int ObjectRef::l_is_player_connected(lua_State *L) { NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); - Player *player = getplayer(ref); + RemotePlayer *player = getplayer(ref); lua_pushboolean(L, (player != NULL && player->peer_id != 0)); return 1; } @@ -983,7 +983,7 @@ int ObjectRef::l_get_player_name(lua_State *L) { NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); - Player *player = getplayer(ref); + RemotePlayer *player = getplayer(ref); if (player == NULL) { lua_pushlstring(L, "", 0); return 1; @@ -998,7 +998,7 @@ int ObjectRef::l_get_player_velocity(lua_State *L) { NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); - Player *player = getplayer(ref); + RemotePlayer *player = getplayer(ref); if (player == NULL) { lua_pushnil(L); return 1; @@ -1013,7 +1013,7 @@ int ObjectRef::l_get_look_dir(lua_State *L) { NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); - Player *player = getplayer(ref); + RemotePlayer *player = getplayer(ref); if (player == NULL) return 0; // Do it float pitch = player->getRadPitchDep(); @@ -1033,7 +1033,7 @@ int ObjectRef::l_get_look_pitch(lua_State *L) "Deprecated call to get_look_pitch, use get_look_vertical instead"); ObjectRef *ref = checkobject(L, 1); - Player *player = getplayer(ref); + RemotePlayer *player = getplayer(ref); if (player == NULL) return 0; // Do it lua_pushnumber(L, player->getRadPitchDep()); @@ -1050,7 +1050,7 @@ int ObjectRef::l_get_look_yaw(lua_State *L) "Deprecated call to get_look_yaw, use get_look_horizontal instead"); ObjectRef *ref = checkobject(L, 1); - Player *player = getplayer(ref); + RemotePlayer *player = getplayer(ref); if (player == NULL) return 0; // Do it lua_pushnumber(L, player->getRadYawDep()); @@ -1062,7 +1062,7 @@ int ObjectRef::l_get_look_vertical(lua_State *L) { NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); - Player *player = getplayer(ref); + RemotePlayer *player = getplayer(ref); if (player == NULL) return 0; // Do it lua_pushnumber(L, player->getRadPitch()); @@ -1074,7 +1074,7 @@ int ObjectRef::l_get_look_horizontal(lua_State *L) { NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); - Player *player = getplayer(ref); + RemotePlayer *player = getplayer(ref); if (player == NULL) return 0; // Do it lua_pushnumber(L, player->getRadYaw()); @@ -1179,7 +1179,7 @@ int ObjectRef::l_set_inventory_formspec(lua_State *L) { NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); - Player *player = getplayer(ref); + RemotePlayer *player = getplayer(ref); if (player == NULL) return 0; std::string formspec = luaL_checkstring(L, 2); @@ -1194,7 +1194,7 @@ int ObjectRef::l_get_inventory_formspec(lua_State *L) { NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); - Player *player = getplayer(ref); + RemotePlayer *player = getplayer(ref); if (player == NULL) return 0; std::string formspec = player->inventory_formspec; @@ -1207,7 +1207,7 @@ int ObjectRef::l_get_player_control(lua_State *L) { NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); - Player *player = getplayer(ref); + RemotePlayer *player = getplayer(ref); if (player == NULL) { lua_pushlstring(L, "", 0); return 1; @@ -1241,7 +1241,7 @@ int ObjectRef::l_get_player_control_bits(lua_State *L) { NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); - Player *player = getplayer(ref); + RemotePlayer *player = getplayer(ref); if (player == NULL) { lua_pushlstring(L, "", 0); return 1; @@ -1416,7 +1416,7 @@ int ObjectRef::l_hud_get(lua_State *L) { NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); - Player *player = getplayer(ref); + RemotePlayer *player = getplayer(ref); if (player == NULL) return 0; @@ -1493,7 +1493,7 @@ int ObjectRef::l_hud_get_flags(lua_State *L) { NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); - Player *player = getplayer(ref); + RemotePlayer *player = getplayer(ref); if (player == NULL) return 0; @@ -1649,7 +1649,7 @@ int ObjectRef::l_get_sky(lua_State *L) { NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); - Player *player = getplayer(ref); + RemotePlayer *player = getplayer(ref); if (player == NULL) return 0; video::SColor bgcolor(255, 255, 255, 255); diff --git a/src/server.cpp b/src/server.cpp index dee8a3d70..67dbe1545 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -692,7 +692,7 @@ void Server::AsyncRunStep(bool initial_step) if (client->getState() < CS_DefinitionsSent) continue; - Player *player = m_env->getPlayer(client->peer_id); + RemotePlayer *player = m_env->getPlayer(client->peer_id); if (player == NULL) { // This can happen if the client timeouts somehow /*warningstream<<FUNCTION_NAME<<": Client " @@ -1857,7 +1857,7 @@ void Server::SendPlayerBreath(u16 peer_id) void Server::SendMovePlayer(u16 peer_id) { DSTACK(FUNCTION_NAME); - Player *player = m_env->getPlayer(peer_id); + RemotePlayer *player = m_env->getPlayer(peer_id); assert(player); NetworkPacket pkt(TOCLIENT_MOVE_PLAYER, sizeof(v3f) + sizeof(f32) * 2, peer_id); @@ -1896,7 +1896,7 @@ void Server::SendEyeOffset(u16 peer_id, v3f first, v3f third) } void Server::SendPlayerPrivileges(u16 peer_id) { - Player *player = m_env->getPlayer(peer_id); + RemotePlayer *player = m_env->getPlayer(peer_id); assert(player); if(player->peer_id == PEER_ID_INEXISTENT) return; @@ -1917,7 +1917,7 @@ void Server::SendPlayerPrivileges(u16 peer_id) void Server::SendPlayerInventoryFormspec(u16 peer_id) { - Player *player = m_env->getPlayer(peer_id); + RemotePlayer *player = m_env->getPlayer(peer_id); assert(player); if(player->peer_id == PEER_ID_INEXISTENT) return; @@ -1962,7 +1962,7 @@ s32 Server::playSound(const SimpleSoundSpec &spec, std::vector<u16> dst_clients; if(params.to_player != "") { - Player *player = m_env->getPlayer(params.to_player.c_str()); + RemotePlayer *player = m_env->getPlayer(params.to_player.c_str()); if(!player){ infostream<<"Server::playSound: Player \""<<params.to_player <<"\" not found"<<std::endl; @@ -1978,13 +1978,12 @@ s32 Server::playSound(const SimpleSoundSpec &spec, else { std::vector<u16> clients = m_clients.getClientIDs(); - for(std::vector<u16>::iterator - i = clients.begin(); i != clients.end(); ++i) { - Player *player = m_env->getPlayer(*i); - if(!player) + for (std::vector<u16>::iterator i = clients.begin(); i != clients.end(); ++i) { + RemotePlayer *player = m_env->getPlayer(*i); + if (!player) continue; - if(pos_exists) { + if (pos_exists) { if(player->getPosition().getDistanceFrom(pos) > params.max_hear_distance) continue; @@ -2048,7 +2047,7 @@ void Server::sendRemoveNode(v3s16 p, u16 ignore_id, i != clients.end(); ++i) { if (far_players) { // Get player - if(Player *player = m_env->getPlayer(*i)) { + if (RemotePlayer *player = m_env->getPlayer(*i)) { // If player is far away, only set modified blocks not sent v3f player_pos = player->getPosition(); if(player_pos.getDistanceFrom(p_f) > maxd) { @@ -2076,7 +2075,7 @@ void Server::sendAddNode(v3s16 p, MapNode n, u16 ignore_id, if(far_players) { // Get player - if(Player *player = m_env->getPlayer(*i)) { + if (RemotePlayer *player = m_env->getPlayer(*i)) { // If player is far away, only set modified blocks not sent v3f player_pos = player->getPosition(); if(player_pos.getDistanceFrom(p_f) > maxd) { @@ -2661,8 +2660,8 @@ void Server::DeleteClient(u16 peer_id, ClientDeletionReason reason) for(std::vector<u16>::iterator i = clients.begin(); i != clients.end(); ++i) { // Get player - Player *player = m_env->getPlayer(*i); - if(!player) + RemotePlayer *player = m_env->getPlayer(*i); + if (!player) continue; // Get name of player @@ -2842,8 +2841,8 @@ RemoteClient* Server::getClientNoEx(u16 peer_id, ClientState state_min) std::string Server::getPlayerName(u16 peer_id) { - Player *player = m_env->getPlayer(peer_id); - if(player == NULL) + RemotePlayer *player = m_env->getPlayer(peer_id); + if (player == NULL) return "[id="+itos(peer_id)+"]"; return player->getName(); } @@ -2870,13 +2869,12 @@ std::wstring Server::getStatusString() bool first = true; os<<L", clients={"; std::vector<u16> clients = m_clients.getClientIDs(); - for(std::vector<u16>::iterator i = clients.begin(); - i != clients.end(); ++i) { + for (std::vector<u16>::iterator i = clients.begin(); i != clients.end(); ++i) { // Get player - Player *player = m_env->getPlayer(*i); + RemotePlayer *player = m_env->getPlayer(*i); // Get name of player std::wstring name = L"unknown"; - if(player != NULL) + if (player != NULL) name = narrow_to_wide(player->getName()); // Add name to information string if(!first) @@ -2912,12 +2910,11 @@ void Server::reportPrivsModified(const std::string &name) std::vector<u16> clients = m_clients.getClientIDs(); for(std::vector<u16>::iterator i = clients.begin(); i != clients.end(); ++i) { - Player *player = m_env->getPlayer(*i); + RemotePlayer *player = m_env->getPlayer(*i); reportPrivsModified(player->getName()); } } else { - RemotePlayer *player = - dynamic_cast<RemotePlayer *>(m_env->getPlayer(name.c_str())); + RemotePlayer *player = m_env->getPlayer(name.c_str()); if (!player) return; SendPlayerPrivileges(player->peer_id); @@ -2932,8 +2929,8 @@ void Server::reportPrivsModified(const std::string &name) void Server::reportInventoryFormspecModified(const std::string &name) { - Player *player = m_env->getPlayer(name.c_str()); - if(!player) + RemotePlayer *player = m_env->getPlayer(name.c_str()); + if (!player) return; SendPlayerInventoryFormspec(player->peer_id); } @@ -2963,7 +2960,7 @@ void Server::notifyPlayer(const char *name, const std::wstring &msg) m_admin_chat->outgoing_queue.push_back(new ChatEventChat("", msg)); } - Player *player = m_env->getPlayer(name); + RemotePlayer *player = m_env->getPlayer(name); if (!player) { return; } @@ -2981,7 +2978,7 @@ bool Server::showFormspec(const char *playername, const std::string &formspec, if (!m_env) return false; - Player *player = m_env->getPlayer(playername); + RemotePlayer *player = m_env->getPlayer(playername); if (!player) return false; @@ -3152,7 +3149,7 @@ void Server::spawnParticle(const std::string &playername, v3f pos, u16 peer_id = PEER_ID_INEXISTENT; if (playername != "") { - Player* player = m_env->getPlayer(playername.c_str()); + RemotePlayer* player = m_env->getPlayer(playername.c_str()); if (!player) return; peer_id = player->peer_id; @@ -3176,7 +3173,7 @@ u32 Server::addParticleSpawner(u16 amount, float spawntime, u16 peer_id = PEER_ID_INEXISTENT; if (playername != "") { - Player* player = m_env->getPlayer(playername.c_str()); + RemotePlayer* player = m_env->getPlayer(playername.c_str()); if (!player) return -1; peer_id = player->peer_id; @@ -3199,7 +3196,7 @@ void Server::deleteParticleSpawner(const std::string &playername, u32 id) u16 peer_id = PEER_ID_INEXISTENT; if (playername != "") { - Player* player = m_env->getPlayer(playername.c_str()); + RemotePlayer* player = m_env->getPlayer(playername.c_str()); if (!player) return; peer_id = player->peer_id; |