From 631f6d70a5fbc441bec6cbfa34eec9fbaa2fe3b7 Mon Sep 17 00:00:00 2001 From: Anand S Date: Tue, 7 Aug 2018 11:16:35 +0530 Subject: [PATCH 1/2] Fix wrong pointer placement --- src/network/serverpackethandler.cpp | 42 +++++++++++++------------- src/server.h | 46 ++++++++++++++--------------- 2 files changed, 44 insertions(+), 44 deletions(-) diff --git a/src/network/serverpackethandler.cpp b/src/network/serverpackethandler.cpp index 91caee0bd9ba4..d8a64f6346f01 100644 --- a/src/network/serverpackethandler.cpp +++ b/src/network/serverpackethandler.cpp @@ -40,13 +40,13 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "util/serialize.h" #include "util/srp.h" -void Server::handleCommand_Deprecated(NetworkPacket* pkt) +void Server::handleCommand_Deprecated(NetworkPacket *pkt) { infostream << "Server: " << toServerCommandTable[pkt->getCommand()].name << " not supported anymore" << std::endl; } -void Server::handleCommand_Init(NetworkPacket* pkt) +void Server::handleCommand_Init(NetworkPacket *pkt) { if(pkt->getSize() < 1) @@ -279,7 +279,7 @@ void Server::handleCommand_Init(NetworkPacket* pkt) m_clients.event(pkt->getPeerId(), CSE_Hello); } -void Server::handleCommand_Init2(NetworkPacket* pkt) +void Server::handleCommand_Init2(NetworkPacket *pkt) { verbosestream << "Server: Got TOSERVER_INIT2 from " << pkt->getPeerId() << std::endl; @@ -331,7 +331,7 @@ void Server::handleCommand_Init2(NetworkPacket* pkt) } } -void Server::handleCommand_RequestMedia(NetworkPacket* pkt) +void Server::handleCommand_RequestMedia(NetworkPacket *pkt) { std::vector tosend; u16 numfiles; @@ -355,7 +355,7 @@ void Server::handleCommand_RequestMedia(NetworkPacket* pkt) sendRequestedMedia(pkt->getPeerId(), tosend); } -void Server::handleCommand_ClientReady(NetworkPacket* pkt) +void Server::handleCommand_ClientReady(NetworkPacket *pkt) { session_t peer_id = pkt->getPeerId(); @@ -407,7 +407,7 @@ void Server::handleCommand_ClientReady(NetworkPacket* pkt) } } -void Server::handleCommand_GotBlocks(NetworkPacket* pkt) +void Server::handleCommand_GotBlocks(NetworkPacket *pkt) { if (pkt->getSize() < 1) return; @@ -495,7 +495,7 @@ void Server::process_PlayerPos(RemotePlayer *player, PlayerSAO *playersao, } } -void Server::handleCommand_PlayerPos(NetworkPacket* pkt) +void Server::handleCommand_PlayerPos(NetworkPacket *pkt) { RemotePlayer *player = m_env->getPlayer(pkt->getPeerId()); if (player == NULL) { @@ -525,7 +525,7 @@ void Server::handleCommand_PlayerPos(NetworkPacket* pkt) process_PlayerPos(player, playersao, pkt); } -void Server::handleCommand_DeletedBlocks(NetworkPacket* pkt) +void Server::handleCommand_DeletedBlocks(NetworkPacket *pkt) { if (pkt->getSize() < 1) return; @@ -555,7 +555,7 @@ void Server::handleCommand_DeletedBlocks(NetworkPacket* pkt) } } -void Server::handleCommand_InventoryAction(NetworkPacket* pkt) +void Server::handleCommand_InventoryAction(NetworkPacket *pkt) { RemotePlayer *player = m_env->getPlayer(pkt->getPeerId()); @@ -733,7 +733,7 @@ void Server::handleCommand_InventoryAction(NetworkPacket* pkt) SendInventory(playersao); } -void Server::handleCommand_ChatMessage(NetworkPacket* pkt) +void Server::handleCommand_ChatMessage(NetworkPacket *pkt) { /* u16 command @@ -772,7 +772,7 @@ void Server::handleCommand_ChatMessage(NetworkPacket* pkt) } } -void Server::handleCommand_Damage(NetworkPacket* pkt) +void Server::handleCommand_Damage(NetworkPacket *pkt) { u8 damage; @@ -815,7 +815,7 @@ void Server::handleCommand_Damage(NetworkPacket* pkt) } } -void Server::handleCommand_Password(NetworkPacket* pkt) +void Server::handleCommand_Password(NetworkPacket *pkt) { if (pkt->getSize() != PASSWORD_SIZE * 2) return; @@ -893,7 +893,7 @@ void Server::handleCommand_Password(NetworkPacket* pkt) } } -void Server::handleCommand_PlayerItem(NetworkPacket* pkt) +void Server::handleCommand_PlayerItem(NetworkPacket *pkt) { if (pkt->getSize() < 2) return; @@ -924,7 +924,7 @@ void Server::handleCommand_PlayerItem(NetworkPacket* pkt) playersao->setWieldIndex(item); } -void Server::handleCommand_Respawn(NetworkPacket* pkt) +void Server::handleCommand_Respawn(NetworkPacket *pkt) { RemotePlayer *player = m_env->getPlayer(pkt->getPeerId()); if (player == NULL) { @@ -981,7 +981,7 @@ bool Server::checkInteractDistance(RemotePlayer *player, const f32 d, const std: return true; } -void Server::handleCommand_Interact(NetworkPacket* pkt) +void Server::handleCommand_Interact(NetworkPacket *pkt) { /* [0] u16 command @@ -1395,7 +1395,7 @@ void Server::handleCommand_Interact(NetworkPacket* pkt) } } -void Server::handleCommand_RemovedSounds(NetworkPacket* pkt) +void Server::handleCommand_RemovedSounds(NetworkPacket *pkt) { u16 num; *pkt >> num; @@ -1416,7 +1416,7 @@ void Server::handleCommand_RemovedSounds(NetworkPacket* pkt) } } -void Server::handleCommand_NodeMetaFields(NetworkPacket* pkt) +void Server::handleCommand_NodeMetaFields(NetworkPacket *pkt) { v3s16 p; std::string formname; @@ -1468,7 +1468,7 @@ void Server::handleCommand_NodeMetaFields(NetworkPacket* pkt) } } -void Server::handleCommand_InventoryFields(NetworkPacket* pkt) +void Server::handleCommand_InventoryFields(NetworkPacket *pkt) { std::string client_formspec_name; u16 num; @@ -1531,7 +1531,7 @@ void Server::handleCommand_InventoryFields(NetworkPacket* pkt) actionstream << ", possible exploitation attempt" << std::endl; } -void Server::handleCommand_FirstSrp(NetworkPacket* pkt) +void Server::handleCommand_FirstSrp(NetworkPacket *pkt) { RemoteClient* client = getClient(pkt->getPeerId(), CS_Invalid); ClientState cstate = client->getState(); @@ -1597,7 +1597,7 @@ void Server::handleCommand_FirstSrp(NetworkPacket* pkt) } } -void Server::handleCommand_SrpBytesA(NetworkPacket* pkt) +void Server::handleCommand_SrpBytesA(NetworkPacket *pkt) { RemoteClient* client = getClient(pkt->getPeerId(), CS_Invalid); ClientState cstate = client->getState(); @@ -1703,7 +1703,7 @@ void Server::handleCommand_SrpBytesA(NetworkPacket* pkt) Send(&resp_pkt); } -void Server::handleCommand_SrpBytesM(NetworkPacket* pkt) +void Server::handleCommand_SrpBytesM(NetworkPacket *pkt) { RemoteClient* client = getClient(pkt->getPeerId(), CS_Invalid); ClientState cstate = client->getState(); diff --git a/src/server.h b/src/server.h index 186818b2e1afc..2e95981ee65e5 100644 --- a/src/server.h +++ b/src/server.h @@ -143,33 +143,33 @@ class Server : public con::PeerHandler, public MapEventReceiver, * Command Handlers */ - void handleCommand(NetworkPacket* pkt); + void handleCommand(NetworkPacket *pkt); - void handleCommand_Null(NetworkPacket* pkt) {}; - void handleCommand_Deprecated(NetworkPacket* pkt); - void handleCommand_Init(NetworkPacket* pkt); - void handleCommand_Init2(NetworkPacket* pkt); + void handleCommand_Null(NetworkPacket *pkt) {}; + void handleCommand_Deprecated(NetworkPacket *pkt); + void handleCommand_Init(NetworkPacket *pkt); + void handleCommand_Init2(NetworkPacket *pkt); void handleCommand_ModChannelJoin(NetworkPacket *pkt); void handleCommand_ModChannelLeave(NetworkPacket *pkt); void handleCommand_ModChannelMsg(NetworkPacket *pkt); - void handleCommand_RequestMedia(NetworkPacket* pkt); - void handleCommand_ClientReady(NetworkPacket* pkt); - void handleCommand_GotBlocks(NetworkPacket* pkt); - void handleCommand_PlayerPos(NetworkPacket* pkt); - void handleCommand_DeletedBlocks(NetworkPacket* pkt); - void handleCommand_InventoryAction(NetworkPacket* pkt); - void handleCommand_ChatMessage(NetworkPacket* pkt); - void handleCommand_Damage(NetworkPacket* pkt); - void handleCommand_Password(NetworkPacket* pkt); - void handleCommand_PlayerItem(NetworkPacket* pkt); - void handleCommand_Respawn(NetworkPacket* pkt); - void handleCommand_Interact(NetworkPacket* pkt); - void handleCommand_RemovedSounds(NetworkPacket* pkt); - void handleCommand_NodeMetaFields(NetworkPacket* pkt); - void handleCommand_InventoryFields(NetworkPacket* pkt); - void handleCommand_FirstSrp(NetworkPacket* pkt); - void handleCommand_SrpBytesA(NetworkPacket* pkt); - void handleCommand_SrpBytesM(NetworkPacket* pkt); + void handleCommand_RequestMedia(NetworkPacket *pkt); + void handleCommand_ClientReady(NetworkPacket *pkt); + void handleCommand_GotBlocks(NetworkPacket *pkt); + void handleCommand_PlayerPos(NetworkPacket *pkt); + void handleCommand_DeletedBlocks(NetworkPacket *pkt); + void handleCommand_InventoryAction(NetworkPacket *pkt); + void handleCommand_ChatMessage(NetworkPacket *pkt); + void handleCommand_Damage(NetworkPacket *pkt); + void handleCommand_Password(NetworkPacket *pkt); + void handleCommand_PlayerItem(NetworkPacket *pkt); + void handleCommand_Respawn(NetworkPacket *pkt); + void handleCommand_Interact(NetworkPacket *pkt); + void handleCommand_RemovedSounds(NetworkPacket *pkt); + void handleCommand_NodeMetaFields(NetworkPacket *pkt); + void handleCommand_InventoryFields(NetworkPacket *pkt); + void handleCommand_FirstSrp(NetworkPacket *pkt); + void handleCommand_SrpBytesA(NetworkPacket *pkt); + void handleCommand_SrpBytesM(NetworkPacket *pkt); void ProcessData(NetworkPacket *pkt); From 13face0b0f662b1467c109ea3d080a139bf94afd Mon Sep 17 00:00:00 2001 From: Anand S Date: Tue, 7 Aug 2018 11:42:12 +0530 Subject: [PATCH 2/2] Replace all ' == NULL' with '!' --- src/script/lua_api/l_object.cpp | 225 +++++++++++++++++++------------- 1 file changed, 133 insertions(+), 92 deletions(-) diff --git a/src/script/lua_api/l_object.cpp b/src/script/lua_api/l_object.cpp index 238c1ee1ca94e..1abd7592e0810 100644 --- a/src/script/lua_api/l_object.cpp +++ b/src/script/lua_api/l_object.cpp @@ -56,7 +56,7 @@ ServerActiveObject* ObjectRef::getobject(ObjectRef *ref) LuaEntitySAO* ObjectRef::getluaobject(ObjectRef *ref) { ServerActiveObject *obj = getobject(ref); - if (obj == NULL) + if (!obj) return NULL; if (obj->getType() != ACTIVEOBJECT_TYPE_LUAENTITY) return NULL; @@ -66,7 +66,7 @@ LuaEntitySAO* ObjectRef::getluaobject(ObjectRef *ref) PlayerSAO* ObjectRef::getplayersao(ObjectRef *ref) { ServerActiveObject *obj = getobject(ref); - if (obj == NULL) + if (!obj) return NULL; if (obj->getType() != ACTIVEOBJECT_TYPE_PLAYER) return NULL; @@ -76,7 +76,7 @@ PlayerSAO* ObjectRef::getplayersao(ObjectRef *ref) RemotePlayer *ObjectRef::getplayer(ObjectRef *ref) { PlayerSAO *playersao = getplayersao(ref); - if (playersao == NULL) + if (!playersao) return NULL; return playersao->getPlayer(); } @@ -98,7 +98,7 @@ int ObjectRef::l_remove(lua_State *L) ObjectRef *ref = checkobject(L, 1); ServerActiveObject *co = getobject(ref); - if (co == NULL) + if (!co) return 0; if (co->getType() == ACTIVEOBJECT_TYPE_PLAYER) return 0; @@ -118,7 +118,8 @@ int ObjectRef::l_get_pos(lua_State *L) NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); ServerActiveObject *co = getobject(ref); - if (co == NULL) return 0; + if (!co) + return 0; v3f pos = co->getBasePosition() / BS; lua_newtable(L); lua_pushnumber(L, pos.X); @@ -137,7 +138,8 @@ int ObjectRef::l_set_pos(lua_State *L) ObjectRef *ref = checkobject(L, 1); //LuaEntitySAO *co = getluaobject(ref); ServerActiveObject *co = getobject(ref); - if (co == NULL) return 0; + if (!co) + return 0; // pos v3f pos = checkFloatPos(L, 2); // Do it @@ -152,7 +154,8 @@ int ObjectRef::l_move_to(lua_State *L) ObjectRef *ref = checkobject(L, 1); //LuaEntitySAO *co = getluaobject(ref); ServerActiveObject *co = getobject(ref); - if (co == NULL) return 0; + if (!co) + return 0; // pos v3f pos = checkFloatPos(L, 2); // continuous @@ -170,8 +173,10 @@ int ObjectRef::l_punch(lua_State *L) ObjectRef *puncher_ref = checkobject(L, 2); ServerActiveObject *co = getobject(ref); ServerActiveObject *puncher = getobject(puncher_ref); - if (co == NULL) return 0; - if (puncher == NULL) return 0; + if (!co) + return 0; + if (!puncher) + return 0; v3f dir; if (lua_type(L, 5) != LUA_TTABLE) dir = co->getBasePosition() - puncher->getBasePosition(); @@ -212,8 +217,10 @@ int ObjectRef::l_right_click(lua_State *L) ObjectRef *ref2 = checkobject(L, 2); ServerActiveObject *co = getobject(ref); ServerActiveObject *co2 = getobject(ref2); - if (co == NULL) return 0; - if (co2 == NULL) return 0; + if (!co) + return 0; + if (!co) + return 0; // Do it co->rightClick(co2); return 0; @@ -230,7 +237,7 @@ int ObjectRef::l_set_hp(lua_State *L) ObjectRef *ref = checkobject(L, 1); luaL_checknumber(L, 2); ServerActiveObject *co = getobject(ref); - if (co == NULL) + if (!co) return 0; // Get HP @@ -269,7 +276,7 @@ int ObjectRef::l_get_hp(lua_State *L) NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); ServerActiveObject *co = getobject(ref); - if (co == NULL) { + if (!co) { // Default hp is 1 lua_pushnumber(L, 1); return 1; @@ -288,7 +295,8 @@ int ObjectRef::l_get_inventory(lua_State *L) NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); ServerActiveObject *co = getobject(ref); - if (co == NULL) return 0; + if (!co) + return 0; // Do it InventoryLocation loc = co->getInventoryLocation(); if (getServer(L)->getInventory(loc) != NULL) @@ -304,7 +312,8 @@ int ObjectRef::l_get_wield_list(lua_State *L) NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); ServerActiveObject *co = getobject(ref); - if (co == NULL) return 0; + if (!co) + return 0; // Do it lua_pushstring(L, co->getWieldList().c_str()); return 1; @@ -316,7 +325,8 @@ int ObjectRef::l_get_wield_index(lua_State *L) NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); ServerActiveObject *co = getobject(ref); - if (co == NULL) return 0; + if (!co) + return 0; // Do it lua_pushinteger(L, co->getWieldIndex() + 1); return 1; @@ -328,7 +338,7 @@ int ObjectRef::l_get_wielded_item(lua_State *L) NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); ServerActiveObject *co = getobject(ref); - if (co == NULL) { + if (!co) { // Empty ItemStack LuaItemStack::create(L, ItemStack()); return 1; @@ -344,7 +354,8 @@ int ObjectRef::l_set_wielded_item(lua_State *L) NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); ServerActiveObject *co = getobject(ref); - if (co == NULL) return 0; + if (!co) + return 0; // Do it ItemStack item = read_item(L, 2, getServer(L)->idef()); bool success = co->setWieldedItem(item); @@ -361,7 +372,8 @@ int ObjectRef::l_set_armor_groups(lua_State *L) NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); ServerActiveObject *co = getobject(ref); - if (co == NULL) return 0; + if (!co) + return 0; // Do it ItemGroupList groups; read_groups(L, 2, groups); @@ -375,7 +387,7 @@ int ObjectRef::l_get_armor_groups(lua_State *L) NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); ServerActiveObject *co = getobject(ref); - if (co == NULL) + if (!co) return 0; // Do it push_groups(L, co->getArmorGroups()); @@ -389,7 +401,8 @@ int ObjectRef::l_set_physics_override(lua_State *L) NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); PlayerSAO *co = (PlayerSAO *) getobject(ref); - if (co == NULL) return 0; + if (!co) + return 0; // Do it if (lua_istable(L, 2)) { co->m_physics_override_speed = getfloatfield_default( @@ -429,7 +442,7 @@ int ObjectRef::l_get_physics_override(lua_State *L) NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); PlayerSAO *co = (PlayerSAO *)getobject(ref); - if (co == NULL) + if (!co) return 0; // Do it lua_newtable(L); @@ -454,7 +467,8 @@ int ObjectRef::l_set_animation(lua_State *L) NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); ServerActiveObject *co = getobject(ref); - if (co == NULL) return 0; + if (!co) + return 0; // Do it v2f frames = v2f(1, 1); if (!lua_isnil(L, 2)) @@ -478,7 +492,7 @@ int ObjectRef::l_get_animation(lua_State *L) NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); ServerActiveObject *co = getobject(ref); - if (co == NULL) + if (!co) return 0; // Do it v2f frames = v2f(1,1); @@ -500,7 +514,7 @@ int ObjectRef::l_set_local_animation(lua_State *L) NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); RemotePlayer *player = getplayer(ref); - if (player == NULL) + if (!player) return 0; // Do it v2s32 frames[4]; @@ -523,7 +537,7 @@ int ObjectRef::l_get_local_animation(lua_State *L) NO_MAP_LOCK_REQUIRED ObjectRef *ref = checkobject(L, 1); RemotePlayer *player = getplayer(ref); - if (player == NULL) + if (!player) return 0; v2s32 frames[4]; @@ -544,7 +558,7 @@ int ObjectRef::l_set_eye_offset(lua_State *L) NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); RemotePlayer *player = getplayer(ref); - if (player == NULL) + if (!player) return 0; // Do it v3f offset_first = v3f(0, 0, 0); @@ -572,7 +586,7 @@ int ObjectRef::l_get_eye_offset(lua_State *L) NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); RemotePlayer *player = getplayer(ref); - if (player == NULL) + if (!player) return 0; // Do it push_v3f(L, player->eye_offset_first); @@ -586,7 +600,7 @@ int ObjectRef::l_set_animation_frame_speed(lua_State *L) NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); ServerActiveObject *co = getobject(ref); - if (co == NULL) + if (!co) return 0; // Do it @@ -606,7 +620,8 @@ int ObjectRef::l_set_bone_position(lua_State *L) NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); ServerActiveObject *co = getobject(ref); - if (co == NULL) return 0; + if (!co) + return 0; // Do it std::string bone; if (!lua_isnil(L, 2)) @@ -627,7 +642,7 @@ int ObjectRef::l_get_bone_position(lua_State *L) NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); ServerActiveObject *co = getobject(ref); - if (co == NULL) + if (!co) return 0; // Do it std::string bone; @@ -652,9 +667,9 @@ int ObjectRef::l_set_attach(lua_State *L) ObjectRef *parent_ref = checkobject(L, 2); ServerActiveObject *co = getobject(ref); ServerActiveObject *parent = getobject(parent_ref); - if (co == NULL) + if (!co) return 0; - if (parent == NULL) + if (!parent) return 0; // Do it int parent_id = 0; @@ -688,7 +703,7 @@ int ObjectRef::l_get_attach(lua_State *L) ObjectRef *ref = checkobject(L, 1); ServerActiveObject *co = getobject(ref); - if (co == NULL) + if (!co) return 0; // Do it @@ -715,7 +730,7 @@ int ObjectRef::l_set_detach(lua_State *L) ObjectRef *ref = checkobject(L, 1); ServerActiveObject *co = getobject(ref); - if (co == NULL) + if (!co) return 0; co->clearParentAttachment(); @@ -728,7 +743,8 @@ int ObjectRef::l_set_properties(lua_State *L) NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); ServerActiveObject *co = getobject(ref); - if (co == NULL) return 0; + if (!co) + return 0; ObjectProperties *prop = co->accessObjectProperties(); if (!prop) return 0; @@ -749,7 +765,7 @@ int ObjectRef::l_get_properties(lua_State *L) NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); ServerActiveObject *co = getobject(ref); - if (co == NULL) + if (!co) return 0; ObjectProperties *prop = co->accessObjectProperties(); if (!prop) @@ -775,7 +791,7 @@ int ObjectRef::l_set_nametag_attributes(lua_State *L) ObjectRef *ref = checkobject(L, 1); ServerActiveObject *co = getobject(ref); - if (co == NULL) + if (!co) return 0; ObjectProperties *prop = co->accessObjectProperties(); if (!prop) @@ -804,7 +820,7 @@ int ObjectRef::l_get_nametag_attributes(lua_State *L) ObjectRef *ref = checkobject(L, 1); ServerActiveObject *co = getobject(ref); - if (co == NULL) + if (!co) return 0; ObjectProperties *prop = co->accessObjectProperties(); if (!prop) @@ -828,7 +844,8 @@ int ObjectRef::l_set_velocity(lua_State *L) NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); LuaEntitySAO *co = getluaobject(ref); - if (co == NULL) return 0; + if (!co) + return 0; v3f pos = checkFloatPos(L, 2); // Do it co->setVelocity(pos); @@ -855,7 +872,8 @@ int ObjectRef::l_get_velocity(lua_State *L) NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); LuaEntitySAO *co = getluaobject(ref); - if (co == NULL) return 0; + if (!co) + return 0; // Do it v3f v = co->getVelocity(); pushFloatPos(L, v); @@ -868,7 +886,8 @@ int ObjectRef::l_set_acceleration(lua_State *L) NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); LuaEntitySAO *co = getluaobject(ref); - if (co == NULL) return 0; + if (!co) + return 0; // pos v3f pos = checkFloatPos(L, 2); // Do it @@ -882,7 +901,8 @@ int ObjectRef::l_get_acceleration(lua_State *L) NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); LuaEntitySAO *co = getluaobject(ref); - if (co == NULL) return 0; + if (!co) + return 0; // Do it v3f v = co->getAcceleration(); pushFloatPos(L, v); @@ -895,7 +915,8 @@ int ObjectRef::l_set_yaw(lua_State *L) NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); LuaEntitySAO *co = getluaobject(ref); - if (co == NULL) return 0; + if (!co) + return 0; if (isNaN(L, 2)) throw LuaError("ObjectRef::set_yaw: NaN value is not allowed."); @@ -911,7 +932,8 @@ int ObjectRef::l_get_yaw(lua_State *L) NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); LuaEntitySAO *co = getluaobject(ref); - if (co == NULL) return 0; + if (!co) + return 0; // Do it float yaw = co->getYaw() * core::DEGTORAD; lua_pushnumber(L, yaw); @@ -924,7 +946,8 @@ int ObjectRef::l_set_texture_mod(lua_State *L) NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); LuaEntitySAO *co = getluaobject(ref); - if (co == NULL) return 0; + if (!co) + return 0; // Do it std::string mod = luaL_checkstring(L, 2); co->setTextureMod(mod); @@ -937,7 +960,8 @@ int ObjectRef::l_get_texture_mod(lua_State *L) NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); LuaEntitySAO *co = getluaobject(ref); - if (co == NULL) return 0; + if (!co) + return 0; // Do it std::string mod = co->getTextureMod(); lua_pushstring(L, mod.c_str()); @@ -951,7 +975,8 @@ int ObjectRef::l_set_sprite(lua_State *L) NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); LuaEntitySAO *co = getluaobject(ref); - if (co == NULL) return 0; + if (!co) + return 0; // Do it v2s16 p(0,0); if (!lua_isnil(L, 2)) @@ -977,7 +1002,8 @@ int ObjectRef::l_get_entity_name(lua_State *L) ObjectRef *ref = checkobject(L, 1); LuaEntitySAO *co = getluaobject(ref); log_deprecated(L,"Deprecated call to \"get_entity_name"); - if (co == NULL) return 0; + if (!co) + return 0; // Do it std::string name = co->getName(); lua_pushstring(L, name.c_str()); @@ -990,7 +1016,8 @@ int ObjectRef::l_get_luaentity(lua_State *L) NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); LuaEntitySAO *co = getluaobject(ref); - if (co == NULL) return 0; + if (!co) + return 0; // Do it luaentity_get(L, co->getId()); return 1; @@ -1004,7 +1031,7 @@ int ObjectRef::l_is_player_connected(lua_State *L) NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); RemotePlayer *player = getplayer(ref); - lua_pushboolean(L, (player != NULL && player->getPeerId() != PEER_ID_INEXISTENT)); + lua_pushboolean(L, (player && player->getPeerId() != PEER_ID_INEXISTENT)); return 1; } @@ -1014,7 +1041,7 @@ int ObjectRef::l_get_player_name(lua_State *L) NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); RemotePlayer *player = getplayer(ref); - if (player == NULL) { + if (!player) { lua_pushlstring(L, "", 0); return 1; } @@ -1029,7 +1056,7 @@ int ObjectRef::l_get_player_velocity(lua_State *L) NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); RemotePlayer *player = getplayer(ref); - if (player == NULL) { + if (!player) { lua_pushnil(L); return 1; } @@ -1044,7 +1071,8 @@ int ObjectRef::l_get_look_dir(lua_State *L) NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); PlayerSAO* co = getplayersao(ref); - if (co == NULL) return 0; + if (!co) + return 0; // Do it float pitch = co->getRadPitchDep(); float yaw = co->getRadYawDep(); @@ -1065,7 +1093,8 @@ int ObjectRef::l_get_look_pitch(lua_State *L) ObjectRef *ref = checkobject(L, 1); PlayerSAO* co = getplayersao(ref); - if (co == NULL) return 0; + if (!co) + return 0; // Do it lua_pushnumber(L, co->getRadPitchDep()); return 1; @@ -1082,7 +1111,8 @@ int ObjectRef::l_get_look_yaw(lua_State *L) ObjectRef *ref = checkobject(L, 1); PlayerSAO* co = getplayersao(ref); - if (co == NULL) return 0; + if (!co) + return 0; // Do it lua_pushnumber(L, co->getRadYawDep()); return 1; @@ -1094,7 +1124,8 @@ int ObjectRef::l_get_look_vertical(lua_State *L) NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); PlayerSAO* co = getplayersao(ref); - if (co == NULL) return 0; + if (!co) + return 0; // Do it lua_pushnumber(L, co->getRadPitch()); return 1; @@ -1106,7 +1137,8 @@ int ObjectRef::l_get_look_horizontal(lua_State *L) NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); PlayerSAO* co = getplayersao(ref); - if (co == NULL) return 0; + if (!co) + return 0; // Do it lua_pushnumber(L, co->getRadYaw()); return 1; @@ -1118,7 +1150,8 @@ int ObjectRef::l_set_look_vertical(lua_State *L) NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); PlayerSAO* co = getplayersao(ref); - if (co == NULL) return 0; + if (!co) + return 0; float pitch = readParam(L, 2) * core::RADTODEG; // Do it co->setPitchAndSend(pitch); @@ -1131,7 +1164,8 @@ int ObjectRef::l_set_look_horizontal(lua_State *L) NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); PlayerSAO* co = getplayersao(ref); - if (co == NULL) return 0; + if (!co) + return 0; float yaw = readParam(L, 2) * core::RADTODEG; // Do it co->setYawAndSend(yaw); @@ -1149,7 +1183,8 @@ int ObjectRef::l_set_look_pitch(lua_State *L) ObjectRef *ref = checkobject(L, 1); PlayerSAO* co = getplayersao(ref); - if (co == NULL) return 0; + if (!co) + return 0; float pitch = readParam(L, 2) * core::RADTODEG; // Do it co->setPitchAndSend(pitch); @@ -1167,7 +1202,8 @@ int ObjectRef::l_set_look_yaw(lua_State *L) ObjectRef *ref = checkobject(L, 1); PlayerSAO* co = getplayersao(ref); - if (co == NULL) return 0; + if (!co) + return 0; float yaw = readParam(L, 2) * core::RADTODEG; // Do it co->setYawAndSend(yaw); @@ -1180,7 +1216,8 @@ int ObjectRef::l_set_fov(lua_State *L) NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); RemotePlayer *player = getplayer(ref); - if (player == NULL) return 0; + if (!player) + return 0; f32 fov = luaL_checknumber(L, 2); getServer(L)->setPlayerFov(player, fov); @@ -1194,7 +1231,8 @@ int ObjectRef::l_get_fov(lua_State *L) NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); RemotePlayer *player = getplayer(ref); - if (player == NULL) return 0; + if (!player) + return 0; f32 fov = getServer(L)->getPlayerFov(player); lua_pushnumber(L, fov); @@ -1208,7 +1246,8 @@ int ObjectRef::l_set_breath(lua_State *L) NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); PlayerSAO* co = getplayersao(ref); - if (co == NULL) return 0; + if (!co) + return 0; u16 breath = luaL_checknumber(L, 2); co->setBreath(breath); @@ -1221,7 +1260,8 @@ int ObjectRef::l_get_breath(lua_State *L) NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); PlayerSAO* co = getplayersao(ref); - if (co == NULL) return 0; + if (!co) + return 0; // Do it u16 breath = co->getBreath(); lua_pushinteger (L, breath); @@ -1233,7 +1273,7 @@ int ObjectRef::l_set_attribute(lua_State *L) { ObjectRef *ref = checkobject(L, 1); PlayerSAO* co = getplayersao(ref); - if (co == NULL) + if (!co) return 0; std::string attr = luaL_checkstring(L, 2); @@ -1251,7 +1291,7 @@ int ObjectRef::l_get_attribute(lua_State *L) { ObjectRef *ref = checkobject(L, 1); PlayerSAO* co = getplayersao(ref); - if (co == NULL) + if (!co) return 0; std::string attr = luaL_checkstring(L, 2); @@ -1271,7 +1311,7 @@ int ObjectRef::l_get_meta(lua_State *L) { ObjectRef *ref = checkobject(L, 1); PlayerSAO *co = getplayersao(ref); - if (co == NULL) + if (!co) return 0; PlayerMetaRef::create(L, &co->getMeta()); @@ -1285,7 +1325,8 @@ int ObjectRef::l_set_inventory_formspec(lua_State *L) NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); RemotePlayer *player = getplayer(ref); - if (player == NULL) return 0; + if (!player) + return 0; std::string formspec = luaL_checkstring(L, 2); player->inventory_formspec = formspec; @@ -1300,7 +1341,8 @@ int ObjectRef::l_get_inventory_formspec(lua_State *L) NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); RemotePlayer *player = getplayer(ref); - if (player == NULL) return 0; + if (!player) + return 0; std::string formspec = player->inventory_formspec; lua_pushlstring(L, formspec.c_str(), formspec.size()); @@ -1313,7 +1355,7 @@ int ObjectRef::l_set_formspec_prepend(lua_State *L) NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); RemotePlayer *player = getplayer(ref); - if (player == NULL) + if (!player) return 0; std::string formspec = luaL_checkstring(L, 2); @@ -1330,7 +1372,7 @@ int ObjectRef::l_get_formspec_prepend(lua_State *L) NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); RemotePlayer *player = getplayer(ref); - if (player == NULL) + if (!player) return 0; std::string formspec = player->formspec_prepend; @@ -1344,7 +1386,7 @@ int ObjectRef::l_get_player_control(lua_State *L) NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); RemotePlayer *player = getplayer(ref); - if (player == NULL) { + if (!player) { lua_pushlstring(L, "", 0); return 1; } @@ -1378,7 +1420,7 @@ int ObjectRef::l_get_player_control_bits(lua_State *L) NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); RemotePlayer *player = getplayer(ref); - if (player == NULL) { + if (!player) { lua_pushlstring(L, "", 0); return 1; } @@ -1393,7 +1435,7 @@ int ObjectRef::l_hud_add(lua_State *L) NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); RemotePlayer *player = getplayer(ref); - if (player == NULL) + if (!player) return 0; HudElement *elem = new HudElement; @@ -1415,7 +1457,7 @@ int ObjectRef::l_hud_remove(lua_State *L) NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); RemotePlayer *player = getplayer(ref); - if (player == NULL) + if (!player) return 0; u32 id = -1; @@ -1435,7 +1477,7 @@ int ObjectRef::l_hud_change(lua_State *L) NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); RemotePlayer *player = getplayer(ref); - if (player == NULL) + if (!player) return 0; u32 id = lua_isnumber(L, 2) ? lua_tonumber(L, 2) : -1; @@ -1459,7 +1501,7 @@ int ObjectRef::l_hud_get(lua_State *L) NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); RemotePlayer *player = getplayer(ref); - if (player == NULL) + if (!player) return 0; u32 id = lua_tonumber(L, -1); @@ -1477,7 +1519,7 @@ int ObjectRef::l_hud_set_flags(lua_State *L) NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); RemotePlayer *player = getplayer(ref); - if (player == NULL) + if (!player) return 0; u32 flags = 0; @@ -1503,7 +1545,7 @@ int ObjectRef::l_hud_get_flags(lua_State *L) NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); RemotePlayer *player = getplayer(ref); - if (player == NULL) + if (!player) return 0; lua_newtable(L); @@ -1531,7 +1573,7 @@ int ObjectRef::l_hud_set_hotbar_itemcount(lua_State *L) NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); RemotePlayer *player = getplayer(ref); - if (player == NULL) + if (!player) return 0; s32 hotbar_itemcount = lua_tonumber(L, 2); @@ -1549,7 +1591,7 @@ int ObjectRef::l_hud_get_hotbar_itemcount(lua_State *L) NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); RemotePlayer *player = getplayer(ref); - if (player == NULL) + if (!player) return 0; lua_pushnumber(L, player->getHotbarItemcount()); @@ -1562,7 +1604,7 @@ int ObjectRef::l_hud_set_hotbar_image(lua_State *L) NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); RemotePlayer *player = getplayer(ref); - if (player == NULL) + if (!player) return 0; std::string name = readParam(L, 2); @@ -1577,7 +1619,7 @@ int ObjectRef::l_hud_get_hotbar_image(lua_State *L) NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); RemotePlayer *player = getplayer(ref); - if (player == NULL) + if (!player) return 0; const std::string &name = player->getHotbarImage(); @@ -1591,7 +1633,7 @@ int ObjectRef::l_hud_set_hotbar_selected_image(lua_State *L) NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); RemotePlayer *player = getplayer(ref); - if (player == NULL) + if (!player) return 0; std::string name = readParam(L, 2); @@ -1606,7 +1648,7 @@ int ObjectRef::l_hud_get_hotbar_selected_image(lua_State *L) NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); RemotePlayer *player = getplayer(ref); - if (player == NULL) + if (!player) return 0; const std::string &name = player->getHotbarSelectedImage(); @@ -1620,7 +1662,7 @@ int ObjectRef::l_set_sky(lua_State *L) NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); RemotePlayer *player = getplayer(ref); - if (player == NULL) + if (!player) return 0; video::SColor bgcolor(255,255,255,255); @@ -1660,7 +1702,7 @@ int ObjectRef::l_get_sky(lua_State *L) NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); RemotePlayer *player = getplayer(ref); - if (player == NULL) + if (!player) return 0; video::SColor bgcolor(255, 255, 255, 255); std::string type; @@ -1761,7 +1803,7 @@ int ObjectRef::l_override_day_night_ratio(lua_State *L) NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); RemotePlayer *player = getplayer(ref); - if (player == NULL) + if (!player) return 0; bool do_override = false; @@ -1784,7 +1826,7 @@ int ObjectRef::l_get_day_night_ratio(lua_State *L) NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); RemotePlayer *player = getplayer(ref); - if (player == NULL) + if (!player) return 0; bool do_override; @@ -1909,7 +1951,6 @@ luaL_Reg ObjectRef::methods[] = { luamethod(ObjectRef, set_look_pitch), luamethod(ObjectRef, get_fov), luamethod(ObjectRef, set_fov), - luamethod(ObjectRef, clear_fov), luamethod(ObjectRef, get_breath), luamethod(ObjectRef, set_breath), luamethod(ObjectRef, get_attribute),