diff options
author | Spp <spp@jorge.gr> | 2011-12-27 10:05:49 +0100 |
---|---|---|
committer | Spp <spp@jorge.gr> | 2011-12-27 10:15:27 +0100 |
commit | fa9daaf95b9f09f3a442087cbc59abc782814c63 (patch) | |
tree | c24fe99837993c101de77df1416fde629c993817 /src/server/game/Groups/Group.cpp | |
parent | 8323027e0c15e97e5da5ec0948c447273321d43f (diff) | |
parent | 317628902462c371dc29ec984803fbfb6412402c (diff) |
Merge branch 'master' into 4.x and some warning fixes
Diffstat (limited to 'src/server/game/Groups/Group.cpp')
-rwxr-xr-x | src/server/game/Groups/Group.cpp | 180 |
1 files changed, 147 insertions, 33 deletions
diff --git a/src/server/game/Groups/Group.cpp b/src/server/game/Groups/Group.cpp index 459cbc73623..39951e0c6c7 100755 --- a/src/server/game/Groups/Group.cpp +++ b/src/server/game/Groups/Group.cpp @@ -123,12 +123,30 @@ bool Group::Create(Player* leader) sGroupMgr->RegisterGroupDbStoreId(m_dbStoreId, this); - // store group in database - CharacterDatabase.PExecute("INSERT INTO groups (guid, leaderGuid, lootMethod, looterGuid, lootThreshold, icon1, icon2, icon3, icon4, icon5, icon6, icon7, icon8, groupType, difficulty, raiddifficulty) " - "VALUES ('%u', '%u', '%u', '%u', '%u', '" UI64FMTD "', '" UI64FMTD "', '" UI64FMTD "', '" UI64FMTD "', '" UI64FMTD "', '" UI64FMTD "', '" UI64FMTD "', '" UI64FMTD "', '%u', '%u', '%u')", - m_dbStoreId, GUID_LOPART(m_leaderGuid), uint32(m_lootMethod), - GUID_LOPART(m_looterGuid), uint32(m_lootThreshold), m_targetIcons[0], m_targetIcons[1], m_targetIcons[2], m_targetIcons[3], m_targetIcons[4], m_targetIcons[5], m_targetIcons[6], - m_targetIcons[7], uint8(m_groupType), uint32(m_dungeonDifficulty), m_raidDifficulty); + // Store group in database + PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_ADD_GROUP); + + uint8 index = 0; + + stmt->setUInt32(index++, m_dbStoreId); + stmt->setUInt32(index++, GUID_LOPART(m_leaderGuid)); + stmt->setUInt8(index++, uint8(m_lootMethod)); + stmt->setUInt32(index++, GUID_LOPART(m_looterGuid)); + stmt->setUInt8(index++, uint8(m_lootThreshold)); + stmt->setUInt32(index++, uint32(m_targetIcons[0])); + stmt->setUInt32(index++, uint32(m_targetIcons[1])); + stmt->setUInt32(index++, uint32(m_targetIcons[2])); + stmt->setUInt32(index++, uint32(m_targetIcons[3])); + stmt->setUInt32(index++, uint32(m_targetIcons[4])); + stmt->setUInt32(index++, uint32(m_targetIcons[5])); + stmt->setUInt32(index++, uint32(m_targetIcons[6])); + stmt->setUInt32(index++, uint32(m_targetIcons[7])); + stmt->setUInt8(index++, uint8(m_groupType)); + stmt->setUInt32(index++, uint8(m_dungeonDifficulty)); + stmt->setUInt32(index++, uint8(m_raidDifficulty)); + + CharacterDatabase.Execute(stmt); + ASSERT(AddMember(leader)); // If the leader can't be added to a new group because it appears full, something is clearly wrong. @@ -200,7 +218,15 @@ void Group::ConvertToLFG() m_groupType = GroupType(m_groupType | GROUPTYPE_LFG | GROUPTYPE_UNK1); m_lootMethod = NEED_BEFORE_GREED; if (!isBGGroup()) - CharacterDatabase.PExecute("UPDATE groups SET groupType='%u' WHERE guid='%u'", uint8(m_groupType), m_dbStoreId); + { + PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPDATE_GROUP_TYPE); + + stmt->setUInt8(0, uint8(m_groupType)); + stmt->setUInt32(1, m_dbStoreId); + + CharacterDatabase.Execute(stmt); + } + SendUpdate(); } @@ -211,7 +237,15 @@ void Group::ConvertToRaid() _initRaidSubGroupsCounter(); if (!isBGGroup()) - CharacterDatabase.PExecute("UPDATE groups SET groupType='%u' WHERE guid='%u'", uint8(m_groupType), m_dbStoreId); + { + PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPDATE_GROUP_TYPE); + + stmt->setUInt8(0, uint8(m_groupType)); + stmt->setUInt32(1, m_dbStoreId); + + CharacterDatabase.Execute(stmt); + } + SendUpdate(); // update quest related GO states (quest activity dependent from raid membership) @@ -343,8 +377,18 @@ bool Group::AddMember(Player* player) // insert into the table if we're not a battleground group if (!isBGGroup()) - CharacterDatabase.PExecute("INSERT INTO group_member (guid, memberGuid, memberFlags, subgroup, roles) VALUES(%u, %u, %u, %u, %u)", - m_dbStoreId, GUID_LOPART(member.guid), member.flags, member.group, member.roles); + { + PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_ADD_GROUP_MEMBER); + + stmt->setUInt32(0, m_dbStoreId); + stmt->setUInt32(1, GUID_LOPART(member.guid)); + stmt->setUInt8(2, member.flags); + stmt->setUInt8(3, member.group); + stmt->setUInt8(4, member.roles); + + CharacterDatabase.Execute(stmt); + + } SendUpdate(); sScriptMgr->OnGroupAddMember(this, player->GetGUID()); @@ -435,7 +479,11 @@ bool Group::RemoveMember(uint64 guid, const RemoveMethod &method /*= GROUP_REMOV } // Remove player from group in DB - CharacterDatabase.PExecute("DELETE FROM group_member WHERE memberGuid=%u", GUID_LOPART(guid)); + PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_GROUP_MEMBER); + + stmt->setUInt32(0, GUID_LOPART(guid)); + + CharacterDatabase.Execute(stmt); // Reevaluate group enchanter if the leaving player had enchanting skill or the player is offline if ((player && player->GetSkillValue(SKILL_ENCHANTING)) || !player) @@ -530,14 +578,24 @@ void Group::ChangeLeader(uint64 guid) } // Same in the database - CharacterDatabase.PExecute("DELETE FROM group_instance WHERE guid=%u AND (permanent = 1 OR instance IN (SELECT instance FROM character_instance WHERE guid = '%u'))", - m_dbStoreId, player->GetGUIDLow()); + + PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_GROUP_INSTANCE_PERM_BINDING); + + stmt->setUInt32(0, m_dbStoreId); + stmt->setUInt32(1, player->GetGUIDLow()); + + CharacterDatabase.Execute(stmt); // Copy the permanent binds from the new leader to the group Player::ConvertInstancesToGroup(player, this, true); - // update the group leader - CharacterDatabase.PExecute("UPDATE groups SET leaderGuid='%u' WHERE guid='%u'", player->GetGUIDLow(), m_dbStoreId); + // Update the group leader + stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPDATE_GROUP_LEADER); + + stmt->setUInt32(0, player->GetGUIDLow()); + stmt->setUInt32(1, m_dbStoreId); + + CharacterDatabase.Execute(stmt); } m_leaderGuid = player->GetGUID(); @@ -1322,7 +1380,14 @@ bool Group::_setMembersGroup(uint64 guid, uint8 group) SubGroupCounterIncrease(group); if (!isBGGroup()) - CharacterDatabase.PExecute("UPDATE group_member SET subgroup='%u' WHERE memberGuid='%u'", group, GUID_LOPART(guid)); + { + PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPDATE_GROUP_MEMBER_SUBGROUP); + + stmt->setUInt8(0, group); + stmt->setUInt32(1, GUID_LOPART(guid)); + + CharacterDatabase.Execute(stmt); + } return true; } @@ -1366,7 +1431,14 @@ void Group::ChangeMembersGroup(uint64 guid, uint8 group) // Preserve new sub group in database for non-raid groups if (!isBGGroup()) - CharacterDatabase.PExecute("UPDATE group_member SET subgroup='%u' WHERE memberGuid='%u'", group, GUID_LOPART(guid)); + { + PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPDATE_GROUP_MEMBER_SUBGROUP); + + stmt->setUInt8(0, group); + stmt->setUInt32(1, GUID_LOPART(guid)); + + CharacterDatabase.Execute(stmt); + } // In case the moved player is online, update the player object with the new sub group references if (Player* player = ObjectAccessor::FindPlayer(guid)) @@ -1554,7 +1626,14 @@ void Group::SetDungeonDifficulty(Difficulty difficulty) { m_dungeonDifficulty = difficulty; if (!isBGGroup()) - CharacterDatabase.PExecute("UPDATE groups SET difficulty = %u WHERE guid ='%u'", m_dungeonDifficulty, m_dbStoreId); + { + PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPDATE_GROUP_DIFFICULTY); + + stmt->setUInt8(0, uint8(m_dungeonDifficulty)); + stmt->setUInt32(1, m_dbStoreId); + + CharacterDatabase.Execute(stmt); + } for (GroupReference* itr = GetFirstMember(); itr != NULL; itr = itr->next()) { @@ -1571,7 +1650,14 @@ void Group::SetRaidDifficulty(Difficulty difficulty) { m_raidDifficulty = difficulty; if (!isBGGroup()) - CharacterDatabase.PExecute("UPDATE groups SET raiddifficulty = %u WHERE guid ='%u'", m_raidDifficulty, m_dbStoreId); + { + PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPDATE_GROUP_RAID_DIFFICULTY); + + stmt->setUInt8(0, uint8(m_raidDifficulty)); + stmt->setUInt32(1, m_dbStoreId); + + CharacterDatabase.Execute(stmt); + } for (GroupReference* itr = GetFirstMember(); itr != NULL; itr = itr->next()) { @@ -1609,9 +1695,9 @@ void Group::ResetInstances(uint8 method, bool isRaid, Player* SendMsgTo) for (BoundInstancesMap::iterator itr = m_boundInstances[diff].begin(); itr != m_boundInstances[diff].end();) { - InstanceSave* p = itr->second.save; + InstanceSave* instanceSave = itr->second.save; const MapEntry* entry = sMapStore.LookupEntry(itr->first); - if (!entry || entry->IsRaid() != isRaid || (!p->CanReset() && method != INSTANCE_RESET_GROUP_DISBAND)) + if (!entry || entry->IsRaid() != isRaid || (!instanceSave->CanReset() && method != INSTANCE_RESET_GROUP_DISBAND)) { ++itr; continue; @@ -1629,10 +1715,10 @@ void Group::ResetInstances(uint8 method, bool isRaid, Player* SendMsgTo) bool isEmpty = true; // if the map is loaded, reset it - Map* map = sMapMgr->FindMap(p->GetMapId(), p->GetInstanceId()); - if (map && map->IsDungeon() && !(method == INSTANCE_RESET_GROUP_DISBAND && !p->CanReset())) + Map* map = sMapMgr->FindMap(instanceSave->GetMapId(), instanceSave->GetInstanceId()); + if (map && map->IsDungeon() && !(method == INSTANCE_RESET_GROUP_DISBAND && !instanceSave->CanReset())) { - if (p->CanReset()) + if (instanceSave->CanReset()) isEmpty = ((InstanceMap*)map)->Reset(method); else isEmpty = !map->HavePlayers(); @@ -1641,25 +1727,32 @@ void Group::ResetInstances(uint8 method, bool isRaid, Player* SendMsgTo) if (SendMsgTo) { if (isEmpty) - SendMsgTo->SendResetInstanceSuccess(p->GetMapId()); + SendMsgTo->SendResetInstanceSuccess(instanceSave->GetMapId()); else - SendMsgTo->SendResetInstanceFailed(0, p->GetMapId()); + SendMsgTo->SendResetInstanceFailed(0, instanceSave->GetMapId()); } if (isEmpty || method == INSTANCE_RESET_GROUP_DISBAND || method == INSTANCE_RESET_CHANGE_DIFFICULTY) { // do not reset the instance, just unbind if others are permanently bound to it - if (p->CanReset()) - p->DeleteFromDB(); + if (instanceSave->CanReset()) + instanceSave->DeleteFromDB(); else - CharacterDatabase.PExecute("DELETE FROM group_instance WHERE instance = '%u'", p->GetInstanceId()); + { + PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_GROUP_INSTANCE_BY_INSTANCE); + + stmt->setUInt32(0, instanceSave->GetInstanceId()); + + CharacterDatabase.Execute(stmt); + } + // i don't know for sure if hash_map iterators m_boundInstances[diff].erase(itr); itr = m_boundInstances[diff].begin(); // this unloads the instance save unless online players are bound to it // (eg. permanent binds or GM solo binds) - p->RemoveGroup(this); + instanceSave->RemoveGroup(this); } else ++itr; @@ -1712,7 +1805,15 @@ InstanceGroupBind* Group::BindToInstance(InstanceSave* save, bool permanent, boo InstanceGroupBind& bind = m_boundInstances[save->GetDifficulty()][save->GetMapId()]; if (!load && (!bind.save || permanent != bind.perm || save != bind.save)) - CharacterDatabase.PExecute("REPLACE INTO group_instance (guid, instance, permanent) VALUES (%u, %u, %u)", m_dbStoreId, save->GetInstanceId(), permanent); + { + PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_ADD_GROUP_INSTANCE); + + stmt->setUInt32(0, m_dbStoreId); + stmt->setUInt32(1, save->GetInstanceId()); + stmt->setBool(2, permanent); + + CharacterDatabase.Execute(stmt); + } if (bind.save != save) { @@ -1736,7 +1837,15 @@ void Group::UnbindInstance(uint32 mapid, uint8 difficulty, bool unload) if (itr != m_boundInstances[difficulty].end()) { if (!unload) - CharacterDatabase.PExecute("DELETE FROM group_instance WHERE guid=%u AND instance=%u", m_dbStoreId, itr->second.save->GetInstanceId()); + { + PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_GROUP_INSTANCE_BY_GUID); + + stmt->setUInt32(0, m_dbStoreId); + stmt->setUInt32(1, itr->second.save->GetInstanceId()); + + CharacterDatabase.Execute(stmt); + } + itr->second.save->RemoveGroup(this); // save can become invalid m_boundInstances[difficulty].erase(itr); } @@ -1965,7 +2074,12 @@ void Group::SetGroupMemberFlag(uint64 guid, bool apply, GroupMemberFlags flag) ToggleGroupMemberFlag(slot, flag, apply); // Preserve the new setting in the db - CharacterDatabase.PExecute("UPDATE group_member SET memberFlags='%u' WHERE memberGuid='%u'", slot->flags, GUID_LOPART(guid)); + PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPDATE_GROUP_MEMBER_FLAG); + + stmt->setUInt8(0, slot->flags); + stmt->setUInt32(0, GUID_LOPART(guid)); + + CharacterDatabase.Execute(stmt); // Broadcast the changes to the group SendUpdate(); |