[Server] Use regular Ptrs where possible to avoid seizure Ptrs by lua

pull/368/merge
Koncord 7 years ago
parent f2a88e6a37
commit 4bde7d80f5

@ -121,7 +121,7 @@ void Networking::processPlayerPacket(RakNet::Packet *packet)
player->setLoadState(Player::LOADED);
player->joinChannel(0, "Default");
bool result = luaState.getEventCtrl().Call<CoreEvent::ON_PLAYER_CONNECT, bool>(player);
bool result = luaState.getEventCtrl().Call<CoreEvent::ON_PLAYER_CONNECT, bool>(player.get());
if (!result)
{
@ -297,13 +297,13 @@ void Networking::newPlayer(RakNet::RakNetGUID guid)
// If we are iterating over a player who has inputted their name, proceed
else if (pl->getLoadState() == Player::POSTLOADED)
{
playerPacketController->GetPacket(ID_PLAYER_BASEINFO)->setPlayer(pl.get());
playerPacketController->GetPacket(ID_PLAYER_STATS_DYNAMIC)->setPlayer(pl.get());
playerPacketController->GetPacket(ID_PLAYER_ATTRIBUTE)->setPlayer(pl.get());
playerPacketController->GetPacket(ID_PLAYER_SKILL)->setPlayer(pl.get());
playerPacketController->GetPacket(ID_PLAYER_POSITION)->setPlayer(pl.get());
playerPacketController->GetPacket(ID_PLAYER_CELL_CHANGE)->setPlayer(pl.get());
playerPacketController->GetPacket(ID_PLAYER_EQUIPMENT)->setPlayer(pl.get());
playerPacketController->GetPacket(ID_PLAYER_BASEINFO)->setPlayer(pl);
playerPacketController->GetPacket(ID_PLAYER_STATS_DYNAMIC)->setPlayer(pl);
playerPacketController->GetPacket(ID_PLAYER_ATTRIBUTE)->setPlayer(pl);
playerPacketController->GetPacket(ID_PLAYER_SKILL)->setPlayer(pl);
playerPacketController->GetPacket(ID_PLAYER_POSITION)->setPlayer(pl);
playerPacketController->GetPacket(ID_PLAYER_CELL_CHANGE)->setPlayer(pl);
playerPacketController->GetPacket(ID_PLAYER_EQUIPMENT)->setPlayer(pl);
playerPacketController->GetPacket(ID_PLAYER_BASEINFO)->Send(guid);
playerPacketController->GetPacket(ID_PLAYER_STATS_DYNAMIC)->Send(guid);
@ -325,7 +325,7 @@ void Networking::disconnectPlayer(RakNet::RakNetGUID guid)
if (player == nullptr)
return;
luaState.getEventCtrl().Call<CoreEvent::ON_PLAYER_DISCONNECT>(player);
luaState.getEventCtrl().Call<CoreEvent::ON_PLAYER_DISCONNECT>(player.get());
playerPacketController->GetPacket(ID_USER_DISCONNECTED)->setPlayer(player.get());
playerPacketController->GetPacket(ID_USER_DISCONNECTED)->Send(true);

@ -13,8 +13,8 @@ std::queue<Player*> Players::updateQueue;
void Players::Init(LuaState &lua)
{
sol::table playersTable = lua.getState()->create_named_table("Players");
playersTable.set_function("getByPID", &Players::getPlayerByPID);
playersTable.set_function("getByGUID", &Players::getPlayerByGUID);
playersTable.set_function("getByPID", [](int pid) { return Players::getPlayerByPID(pid).get(); });
playersTable.set_function("getByGUID", [](RakNet::RakNetGUID guid) { return Players::getPlayerByGUID(guid).get(); });
playersTable.set_function("for_each", [](sol::function func)
{
for (shared_ptr<Player> player : store)
@ -103,15 +103,17 @@ void Players::deletePlayerByGUID(RakNet::RakNetGUID guid)
if (it != ls.end())
{
(*it)->markedForDeletion = true;
mwmp::Networking::get().getState().getState()->collect_garbage();
size_t useCount = it->use_count();
ls.erase(it);
LOG_APPEND(Log::LOG_TRACE, "- references: %d", it->use_count());
LOG_APPEND(Log::LOG_TRACE, "- references: %d", useCount - 1);
}
}
void Players::for_each(std::function<void (std::shared_ptr<Player>)> func)
void Players::for_each(std::function<void (Player *)> func)
{
for (auto &player : store)
func(player);
func(player.get());
}
Players::Store::const_iterator Players::begin()

@ -47,7 +47,7 @@ public:
static Store::const_iterator end();
static size_t size();
static void for_each(std::function<void(std::shared_ptr<Player>)> func);
static void for_each(std::function<void(Player *)> func);
static void processUpdated();
private:

@ -255,12 +255,12 @@ LuaState::LuaState()
lua->set_function("setHour", [](double hour) {
auto packet = mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_GAME_TIME);
Players::for_each([&hour, &packet](std::shared_ptr<Player> player){
Players::for_each([&hour, &packet](Player *player){
player->hour = hour;
player->month = -1;
player->day = -1;
packet->setPlayer(player.get());
packet->setPlayer(player);
packet->Send(false);
});
});
@ -268,24 +268,24 @@ LuaState::LuaState()
lua->set_function("setMonth", [](int month) {
auto packet = mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_GAME_TIME);
Players::for_each([&month, &packet](std::shared_ptr<Player> player){
Players::for_each([&month, &packet](Player *player){
player->hour = -1;
player->month = month;
player->day = -1;
packet->setPlayer(player.get());
packet->setPlayer(player);
packet->Send(false);
});
});
lua->set_function("setDay", [](int day) {
auto packet = mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_GAME_TIME);
Players::for_each([&day, &packet](std::shared_ptr<Player> player){
Players::for_each([&day, &packet](Player *player){
player->hour = -1;
player->month = -1;
player->day = day;
packet->setPlayer(player.get());
packet->setPlayer(player);
packet->Send(false);
});
});

@ -25,7 +25,7 @@ namespace mwmp
actors.emplace_back(actor);
}
Networking::get().getState().getEventCtrl().Call<CoreEvent::ON_ACTOR_EQUIPMENT>(player, actors);
Networking::get().getState().getEventCtrl().Call<CoreEvent::ON_ACTOR_EQUIPMENT>(player.get(), actors);
Networking::get().getState().getActorCtrl().sendActors(player, actors, actorList.cell, true);
}

@ -26,7 +26,7 @@ namespace mwmp
actors.emplace_back(actor);
}
Networking::get().getState().getEventCtrl().Call<CoreEvent::ON_ACTOR_LIST>(player, actors);
Networking::get().getState().getEventCtrl().Call<CoreEvent::ON_ACTOR_LIST>(player.get(), actors);
Networking::get().getState().getActorCtrl().sendActors(player, actors, actorList.cell, true);
}

@ -24,7 +24,7 @@ namespace mwmp
actors.emplace_back(actor);
}
Networking::get().getState().getEventCtrl().Call<CoreEvent::ON_ACTOR_TEST>(player, actors);
Networking::get().getState().getEventCtrl().Call<CoreEvent::ON_ACTOR_TEST>(player.get(), actors);
Networking::get().getState().getActorCtrl().sendActors(player, actors, actorList.cell, true);
}

@ -30,7 +30,7 @@ namespace mwmp
player->message(player->chat.channel, "#FF0000Command not found.\n"); // inform player that command not found
break;
case CommandController::ExecResult::NOT_CMD: // cmd length < 2 or message is not cmd
lua.getEventCtrl().Call<CoreEvent::ON_PLAYER_SENDMESSAGE>(player, player->chat.message, player->chat.channel);
lua.getEventCtrl().Call<CoreEvent::ON_PLAYER_SENDMESSAGE>(player.get(), player->chat.message, player->chat.channel);
break;
case CommandController::ExecResult::SUCCESS: // returned true from function
break;

@ -21,7 +21,7 @@ namespace mwmp
{
DEBUG_PRINTF(strPacketID.c_str());
Networking::get().getState().getEventCtrl().Call<CoreEvent::ON_GUI_ACTION>(player, player->guiMessageBox.id,
Networking::get().getState().getEventCtrl().Call<CoreEvent::ON_GUI_ACTION>(player.get(), player->guiMessageBox.id,
player->guiMessageBox.data);
}
};

@ -17,7 +17,7 @@ namespace mwmp
{
DEBUG_PRINTF(strPacketID);
Networking::get().getState().getEventCtrl().Call<CoreEvent::ON_PLAYER_WEATHER>(player);
Networking::get().getState().getEventCtrl().Call<CoreEvent::ON_PLAYER_WEATHER>(player.get());
}
};
}

@ -25,7 +25,7 @@ namespace mwmp
player->sendToLoaded(packet);
Networking::get().getState().getEventCtrl().Call<CoreEvent::ON_PLAYER_ATTRIBUTE>(player);
Networking::get().getState().getEventCtrl().Call<CoreEvent::ON_PLAYER_ATTRIBUTE>(player.get());
}
}
};

@ -17,7 +17,7 @@ namespace mwmp
{
DEBUG_PRINTF(strPacketID.c_str());
Networking::get().getState().getEventCtrl().Call<CoreEvent::ON_PLAYER_BOOK>(player);
Networking::get().getState().getEventCtrl().Call<CoreEvent::ON_PLAYER_BOOK>(player.get());
}
};
}

@ -15,7 +15,7 @@ namespace mwmp
void Do(PlayerPacket &packet, const std::shared_ptr<Player> &player) override
{
Networking::get().getState().getEventCtrl().Call<CoreEvent::ON_PLAYER_BOUNTY>(player);
Networking::get().getState().getEventCtrl().Call<CoreEvent::ON_PLAYER_BOUNTY>(player.get());
}
};
}

@ -71,7 +71,7 @@ namespace mwmp
packet.setPlayer(player.get());
packet.Send(true); //send to other clients
Networking::get().getState().getEventCtrl().Call<CoreEvent::ON_PLAYER_CELLCHANGE>(player);
Networking::get().getState().getEventCtrl().Call<CoreEvent::ON_PLAYER_CELLCHANGE>(player.get());
LOG_APPEND(Log::LOG_INFO, "- Finished processing ID_PLAYER_CELL_CHANGE");
}

@ -22,7 +22,7 @@ namespace mwmp
DEBUG_PRINTF(strPacketID.c_str());
if (player->charGenState.currentStage == player->charGenState.endStage)
Networking::get().getState().getEventCtrl().Call<CoreEvent::ON_PLAYER_ENDCHARGEN>(player);
Networking::get().getState().getEventCtrl().Call<CoreEvent::ON_PLAYER_ENDCHARGEN>(player.get());
}
};
}

@ -26,7 +26,7 @@ namespace mwmp
packet.Send(true);
Networking::get().getState().getEventCtrl().Call<CoreEvent::ON_PLAYER_DEATH>(player, player->deathReason);
Networking::get().getState().getEventCtrl().Call<CoreEvent::ON_PLAYER_DEATH>(player.get(), player->deathReason);
}
};
}

@ -19,7 +19,7 @@ namespace mwmp
packet.Send(true);
Networking::get().getState().getEventCtrl().Call<CoreEvent::ON_PLAYER_DISPOSITION>(player);
Networking::get().getState().getEventCtrl().Call<CoreEvent::ON_PLAYER_DISPOSITION>(player.get());
}
};
}

@ -23,7 +23,7 @@ namespace mwmp
player->sendToLoaded(packet);
Networking::get().getState().getEventCtrl().Call<CoreEvent::ON_PLAYER_EQUIPMENT>(player);
Networking::get().getState().getEventCtrl().Call<CoreEvent::ON_PLAYER_EQUIPMENT>(player.get());
}
};
}

@ -17,7 +17,7 @@ namespace mwmp
{
DEBUG_PRINTF(strPacketID.c_str());
Networking::get().getState().getEventCtrl().Call<CoreEvent::ON_PLAYER_FACTION>(player);
Networking::get().getState().getEventCtrl().Call<CoreEvent::ON_PLAYER_FACTION>(player.get());
}
};
}

@ -21,7 +21,7 @@ namespace mwmp
{
DEBUG_PRINTF(strPacketID.c_str());
Networking::get().getState().getEventCtrl().Call<CoreEvent::ON_PLAYER_INVENTORY>(player);
Networking::get().getState().getEventCtrl().Call<CoreEvent::ON_PLAYER_INVENTORY>(player.get());
}
};
}

@ -17,7 +17,7 @@ namespace mwmp
{
DEBUG_PRINTF(strPacketID.c_str());
Networking::get().getState().getEventCtrl().Call<CoreEvent::ON_PLAYER_JOURNAL>(player);
Networking::get().getState().getEventCtrl().Call<CoreEvent::ON_PLAYER_JOURNAL>(player.get());
}
};
}

@ -19,7 +19,7 @@ namespace mwmp
packet.Send(true);
Networking::get().getState().getEventCtrl().Call<CoreEvent::ON_PLAYER_KILLCOUNT>(player);
Networking::get().getState().getEventCtrl().Call<CoreEvent::ON_PLAYER_KILLCOUNT>(player.get());
}
};
}

@ -16,7 +16,7 @@ namespace mwmp
void Do(PlayerPacket &packet, const std::shared_ptr<Player> &player) override
{
if (!player->creatureStats.mDead)
Networking::get().getState().getEventCtrl().Call<CoreEvent::ON_PLAYER_LEVEL>(player);
Networking::get().getState().getEventCtrl().Call<CoreEvent::ON_PLAYER_LEVEL>(player.get());
}
};
}

@ -17,7 +17,7 @@ namespace mwmp
{
DEBUG_PRINTF(strPacketID.c_str());
Networking::get().getState().getEventCtrl().Call<CoreEvent::ON_PLAYER_QUICKKEYS>(player);
Networking::get().getState().getEventCtrl().Call<CoreEvent::ON_PLAYER_QUICKKEYS>(player.get());
}
};
}

@ -17,7 +17,7 @@ namespace mwmp
{
DEBUG_PRINTF(strPacketID.c_str());
Networking::get().getState().getEventCtrl().Call<CoreEvent::ON_PLAYER_REST>(player);
Networking::get().getState().getEventCtrl().Call<CoreEvent::ON_PLAYER_REST>(player.get());
}
};
}

@ -25,7 +25,7 @@ namespace mwmp
packet.Send(true);
Networking::get().getState().getEventCtrl().Call<CoreEvent::ON_PLAYER_RESURRECT>(player);
Networking::get().getState().getEventCtrl().Call<CoreEvent::ON_PLAYER_RESURRECT>(player.get());
}
};
}

@ -19,7 +19,7 @@ namespace mwmp
packet.Send(true);
Networking::get().getState().getEventCtrl().Call<CoreEvent::ON_PLAYER_SHAPESHIFT>(player);
Networking::get().getState().getEventCtrl().Call<CoreEvent::ON_PLAYER_SHAPESHIFT>(player.get());
}
};
}

@ -24,7 +24,7 @@ namespace mwmp
//myPacket->Send(player, true);
player->sendToLoaded(packet);
Networking::get().getState().getEventCtrl().Call<CoreEvent::ON_PLAYER_SKILL>(player);
Networking::get().getState().getEventCtrl().Call<CoreEvent::ON_PLAYER_SKILL>(player.get());
}
}
};

@ -21,7 +21,7 @@ namespace mwmp
{
DEBUG_PRINTF(strPacketID.c_str());
Networking::get().getState().getEventCtrl().Call<CoreEvent::ON_PLAYER_SPELLBOOK>(player);
Networking::get().getState().getEventCtrl().Call<CoreEvent::ON_PLAYER_SPELLBOOK>(player.get());
}
};
}

@ -18,7 +18,7 @@ namespace mwmp
DEBUG_PRINTF(strPacketID.c_str());
//Todo: Script::Call<Script::CallbackIdentity("OnPlayerTopic")>(player.getId());
Networking::get().getState().getEventCtrl().Call<CoreEvent::ON_PLAYER_TOPIC>(player);
Networking::get().getState().getEventCtrl().Call<CoreEvent::ON_PLAYER_TOPIC>(player.get());
}
};
}

@ -22,7 +22,7 @@ namespace mwmp
auto objCtrl = Networking::get().getState().getObjectCtrl();
auto objects = objCtrl.copyObjects(event);
Networking::get().getState().getEventCtrl().Call<CoreEvent::ON_OBJECT_DELETE>(player, objects);
Networking::get().getState().getEventCtrl().Call<CoreEvent::ON_OBJECT_DELETE>(player.get(), objects);
objCtrl.sendObjects(player, objects, event.cell);
}

@ -22,7 +22,7 @@ namespace mwmp
auto objCtrl = Networking::get().getState().getObjectCtrl();
auto objects = objCtrl.copyObjects(event);
Networking::get().getState().getEventCtrl().Call<CoreEvent::ON_OBJECT_LOCK>(player, objects);
Networking::get().getState().getEventCtrl().Call<CoreEvent::ON_OBJECT_LOCK>(player.get(), objects);
objCtrl.sendObjects(player, objects, event.cell);
}

@ -29,7 +29,7 @@ namespace mwmp
auto objCtrl = Networking::get().getState().getObjectCtrl();
auto objects = objCtrl.copyObjects(event);
Networking::get().getState().getEventCtrl().Call<CoreEvent::ON_OBJECT_PLACE>(player, objects);
Networking::get().getState().getEventCtrl().Call<CoreEvent::ON_OBJECT_PLACE>(player.get(), objects);
objCtrl.sendObjects(player, objects, event.cell);
}

@ -22,7 +22,7 @@ namespace mwmp
auto objCtrl = Networking::get().getState().getObjectCtrl();
auto objects = objCtrl.copyObjects(event);
Networking::get().getState().getEventCtrl().Call<CoreEvent::ON_OBJECT_SCALE>(player, objects);
Networking::get().getState().getEventCtrl().Call<CoreEvent::ON_OBJECT_SCALE>(player.get(), objects);
objCtrl.sendObjects(player, objects, event.cell);
}

@ -29,7 +29,7 @@ namespace mwmp
auto objCtrl = Networking::get().getState().getObjectCtrl();
auto objects = objCtrl.copyObjects(event);
Networking::get().getState().getEventCtrl().Call<CoreEvent::ON_OBJECT_SCALE>(player, objects);
Networking::get().getState().getEventCtrl().Call<CoreEvent::ON_OBJECT_SCALE>(player.get(), objects);
objCtrl.sendObjects(player, objects, event.cell);
}

@ -22,7 +22,7 @@ namespace mwmp
auto objCtrl = Networking::get().getState().getObjectCtrl();
auto objects = objCtrl.copyObjects(event);
Networking::get().getState().getEventCtrl().Call<CoreEvent::ON_OBJECT_STATE>(player, objects);
Networking::get().getState().getEventCtrl().Call<CoreEvent::ON_OBJECT_STATE>(player.get(), objects);
objCtrl.sendObjects(player, objects, event.cell);
}

@ -22,7 +22,7 @@ namespace mwmp
auto objCtrl = Networking::get().getState().getObjectCtrl();
auto objects = objCtrl.copyObjects(event);
Networking::get().getState().getEventCtrl().Call<CoreEvent::ON_OBJECT_TRAP>(player, objects);
Networking::get().getState().getEventCtrl().Call<CoreEvent::ON_OBJECT_TRAP>(player.get(), objects);
objCtrl.sendObjects(player, objects, event.cell);
}

Loading…
Cancel
Save