aboutsummaryrefslogtreecommitdiff
path: root/src/server/game/DungeonFinding/LFGScripts.cpp
diff options
context:
space:
mode:
authorSpp <none@none>2010-12-05 17:50:26 +0100
committerSpp <none@none>2010-12-05 17:50:26 +0100
commite621f5fe98ac7f0c488ffb00b0d7844b7f4e27fd (patch)
tree7c44aeee468814baa1234d7d800d6b0ef3d14c81 /src/server/game/DungeonFinding/LFGScripts.cpp
parent71c2698faffb22fcfd0370370d80e180c70e3141 (diff)
Core/Dungeon Finder: Code cleanup and minor optimizations
- Extend LfgState to keep control of the state of group and players using LFG - Move scripts to its own class and initialize only if Dungeon finder is enabled - Updated comments to doxygen format - Use constructor initialization list - All variables are declared in the inner most scope - Fix some mem leaks - Remove no longer needed code (Cleaner) - Normalize handler function names --HG-- branch : trunk
Diffstat (limited to 'src/server/game/DungeonFinding/LFGScripts.cpp')
-rw-r--r--src/server/game/DungeonFinding/LFGScripts.cpp165
1 files changed, 165 insertions, 0 deletions
diff --git a/src/server/game/DungeonFinding/LFGScripts.cpp b/src/server/game/DungeonFinding/LFGScripts.cpp
new file mode 100644
index 00000000000..465cf7047a3
--- /dev/null
+++ b/src/server/game/DungeonFinding/LFGScripts.cpp
@@ -0,0 +1,165 @@
+/*
+ * Copyright (C) 2008-2010 TrinityCore <http://www.trinitycore.org/>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*
+ * Interaction between core and LFGScripts
+ */
+
+#include "Common.h"
+#include "SharedDefines.h"
+#include "Player.h"
+#include "Group.h"
+#include "ScriptPCH.h"
+#include "LFGScripts.h"
+#include "LFGMgr.h"
+
+LFGScripts::LFGScripts(): GroupScript("LFGScripts"), PlayerScript("LFGScripts") {}
+
+void LFGScripts::OnAddMember(Group* group, uint64 guid)
+{
+ uint64 gguid = group->GetGUID();
+ if (!gguid)
+ return;
+
+ sLog.outDebug("LFGScripts::OnAddMember [" UI64FMTD "]: added [" UI64FMTD "]", gguid, guid);
+ for (GroupReference *itr = group->GetFirstMember(); itr != NULL; itr = itr->next())
+ {
+ if (Player *plrg = itr->getSource())
+ {
+ plrg->GetSession()->SendLfgUpdatePlayer(LFG_UPDATETYPE_CLEAR_LOCK_LIST);
+ plrg->GetSession()->SendLfgUpdateParty(LFG_UPDATETYPE_CLEAR_LOCK_LIST);
+ }
+ }
+
+ // TODO - if group is queued and new player is added convert to rolecheck without notify the current players queued
+ if (group->GetLfgState() == LFG_STATE_QUEUED)
+ sLFGMgr.Leave(NULL, group);
+
+ Player *plr = sObjectMgr.GetPlayer(guid);
+ if (plr && plr->GetLfgState() == LFG_STATE_QUEUED)
+ sLFGMgr.Leave(plr);
+}
+
+void LFGScripts::OnRemoveMember(Group* group, uint64 guid, RemoveMethod& method, uint64 kicker, const char* reason)
+{
+ uint64 gguid = group->GetGUID();
+ if (!gguid || method == GROUP_REMOVEMETHOD_DEFAULT)
+ return;
+
+ sLog.outDebug("LFGScripts::OnRemoveMember [" UI64FMTD "]: remove [" UI64FMTD "] Method: %d Kicker: [" UI64FMTD "] Reason: %s", gguid, guid, method, kicker, (reason ? reason : ""));
+ if (group->GetLfgState() == LFG_STATE_QUEUED)
+ {
+ // TODO - Do not remove, just remove the one leaving and rejoin queue with all other data
+ sLFGMgr.Leave(NULL, group);
+ }
+
+ if (!group->isLFGGroup())
+ return;
+
+ if (method == GROUP_REMOVEMETHOD_KICK) // Player have been kicked
+ {
+ // TODO - Update internal kick cooldown of kicker
+ std::string str_reason = "";
+ if (reason)
+ str_reason = std::string(reason);
+ sLFGMgr.InitBoot(group, GUID_LOPART(kicker), GUID_LOPART(guid), str_reason);
+ return;
+ }
+
+ if (Player *plr = sObjectMgr.GetPlayer(guid))
+ {
+ /*
+ if (method == GROUP_REMOVEMETHOD_LEAVE)
+ // Add deserter flag
+ else if (group->isLfgKickActive())
+ // Update internal kick cooldown of kicked
+ */
+
+ plr->GetSession()->SendLfgUpdateParty(LFG_UPDATETYPE_LEADER);
+ if (plr->GetMap()->IsDungeon()) // Teleport player out the dungeon
+ sLFGMgr.TeleportPlayer(plr, true);
+ }
+
+ if (group->GetLfgState() != LFG_STATE_FINISHED_DUNGEON)// Need more players to finish the dungeon
+ sLFGMgr.OfferContinue(group);
+}
+
+void LFGScripts::OnDisband(Group* group)
+{
+ uint64 gguid = group->GetGUID();
+ if (!gguid)
+ return;
+
+ sLog.outDebug("LFGScripts::OnDisband [" UI64FMTD "]", gguid);
+ if (group->GetLfgState() == LFG_STATE_QUEUED)
+ sLFGMgr.Leave(NULL, group);
+
+ for (GroupReference *itr = group->GetFirstMember(); itr != NULL; itr = itr->next())
+ {
+ if (Player *plrg = itr->getSource())
+ {
+ plrg->GetSession()->SendLfgUpdateParty(LFG_UPDATETYPE_GROUP_DISBAND);
+ plrg->GetSession()->SendLfgUpdateParty(LFG_UPDATETYPE_LEADER);
+ if (plrg->GetMap()->IsDungeon()) // Teleport player out the dungeon
+ sLFGMgr.TeleportPlayer(plrg, true);
+ }
+ }
+}
+
+void LFGScripts::OnChangeLeader(Group* group, uint64 newLeaderGuid, uint64 oldLeaderGuid)
+{
+ uint64 gguid = group->GetGUID();
+ if (!gguid)
+ return;
+
+ sLog.outDebug("LFGScripts::OnChangeLeader [" UI64FMTD "]: old [" UI64FMTD "] new [" UI64FMTD "]", gguid, newLeaderGuid, oldLeaderGuid);
+ Player *plr = sObjectMgr.GetPlayer(newLeaderGuid);
+ if (plr)
+ plr->GetSession()->SendLfgUpdateParty(LFG_UPDATETYPE_LEADER);
+
+ plr = sObjectMgr.GetPlayer(oldLeaderGuid);
+ if (plr)
+ plr->GetSession()->SendLfgUpdateParty(LFG_UPDATETYPE_GROUP_DISBAND);
+}
+
+void LFGScripts::OnInviteMember(Group* group, uint64 guid)
+{
+ uint64 gguid = group->GetGUID();
+ if (!gguid)
+ return;
+
+ sLog.outDebug("LFGScripts::OnInviteMember [" UI64FMTD "]: invite [" UI64FMTD "] leader [" UI64FMTD "]", gguid, guid, group->GetLeaderGUID());
+ sLFGMgr.Leave(NULL, group);
+}
+
+void LFGScripts::OnLevelChanged(Player* /*player*/, uint8 /*newLevel*/)
+{
+ // TODO - Invalidate LockStatus from cache
+}
+
+void LFGScripts::OnLogout(Player* player)
+{
+ sLFGMgr.Leave(player);
+ player->GetSession()->SendLfgUpdateParty(LFG_UPDATETYPE_REMOVED_FROM_QUEUE);
+ player->GetSession()->SendLfgUpdatePlayer(LFG_UPDATETYPE_REMOVED_FROM_QUEUE);
+ player->GetSession()->SendLfgUpdateSearch(false);
+}
+
+void LFGScripts::OnLogin(Player* /*player*/)
+{
+ // TODO - Restore LfgPlayerData and send proper status to player if it was in a group
+} \ No newline at end of file