diff options
-rwxr-xr-x | src/server/game/Calendar/Calendar.cpp | 2 | ||||
-rwxr-xr-x | src/server/game/Calendar/Calendar.h | 55 | ||||
-rw-r--r-- | src/server/game/Calendar/CalendarMgr.cpp | 80 | ||||
-rw-r--r-- | src/server/game/Calendar/CalendarMgr.h | 71 | ||||
-rwxr-xr-x | src/server/game/Handlers/CalendarHandler.cpp | 288 | ||||
-rwxr-xr-x | src/server/game/Server/WorldSession.h | 3 |
6 files changed, 404 insertions, 95 deletions
diff --git a/src/server/game/Calendar/Calendar.cpp b/src/server/game/Calendar/Calendar.cpp index 2c4ad943dd6..2dadd66f64c 100755 --- a/src/server/game/Calendar/Calendar.cpp +++ b/src/server/game/Calendar/Calendar.cpp @@ -15,3 +15,5 @@ * You should have received a copy of the GNU General Public License along * with this program. If not, see <http://www.gnu.org/licenses/>. */ + +#include "Calendar.h" diff --git a/src/server/game/Calendar/Calendar.h b/src/server/game/Calendar/Calendar.h index dfc88e477f9..c53ba8bf113 100755 --- a/src/server/game/Calendar/Calendar.h +++ b/src/server/game/Calendar/Calendar.h @@ -19,8 +19,61 @@ #ifndef TRINITY_CALENDAR_H #define TRINITY_CALENDAR_H -class Calendar +#include "Common.h" + +// TODO - Get correct values +enum CalendarEventType +{ + CALENDARTYPE_RAID = 0, + CALENDARTYPE_DUNGEON, + CALENDARTYPE_PVP, + CALENDARTYPE_MEETING, + CALENDARTYPE_OTHER, +}; + +// TODO - Get correct values +enum CalendarInviteStatus { + CALENDARSTATUS_INVITED = 0, + CALENDARSTATUS_ACCEPTED, + CALENDARSTATUS_DECLINED, + CALENDARSTATUS_TENTATIVE, + CALENDARSTATUS_OUT, + CALENDARSTATUS_STANDBY, + CALENDARSTATUS_CONFIRMED, +}; +struct CalendarEvent +{ + uint64 Id; + uint64 CreatorGuid; + std::string Name; + std::string Description; + uint8 Type; + uint8 Unk; + uint32 DungeonId; + uint32 UnkTime; + uint32 Time; + uint32 Flags; + uint32 GuildId; }; + +struct CalendarInvite +{ + uint64 Id; + uint64 Event; + uint8 Status; + uint8 Rank; + uint8 Unk1; + uint8 Unk2; + uint8 Unk3; + std::string Text; + uint64 CreatorGuid; + uint32 Time; + uint64 TargetGuid; +}; + +typedef UNORDERED_MAP<uint64, CalendarInvite> CalendarInviteMap; +typedef UNORDERED_MAP<uint64, CalendarEvent> CalendarEventMap; + #endif diff --git a/src/server/game/Calendar/CalendarMgr.cpp b/src/server/game/Calendar/CalendarMgr.cpp new file mode 100644 index 00000000000..d947faed42f --- /dev/null +++ b/src/server/game/Calendar/CalendarMgr.cpp @@ -0,0 +1,80 @@ +/* + * Copyright (C) 2008-2012 Trinity <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, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "CalendarMgr.h" +#include "QueryResult.h" + +CalendarMgr::CalendarMgr() : _currentEventId(0), _currentInviteId(0) +{ +} + +CalendarMgr::~CalendarMgr() +{ +} + +void CalendarMgr::AppendInvitesToCalendarPacketForPlayer(WorldPacket& data, Player* player) +{ + size_t pCounter = data.wpos(); + data << uint32(0); + uint32 counter = 0; + for (CalendarInviteMap::iterator itr = _inviteMap.begin(); itr != _inviteMap.end(); ++itr) + { + CalendarInvite invite = itr->second; + if (invite.TargetGuid == player->GetGUID()) + { + data << uint64(invite.Id); // Invite ID + data << uint64(invite.Event); // Event ID + data << uint8(invite.Rank); // rank + data << uint8(0); // unk - TODO: Figure out what this is + data << uint8(0); // unk + data.appendPackGUID(invite.CreatorGuid); // creator's guid + counter++; + } + } + data.put<uint32>(pCounter, counter); // update number of invites +} + +void CalendarMgr::AppendEventsToCalendarPacketForPlayer(WorldPacket& data, Player* player) +{ + // TODO: There's gotta be a better way to do this + size_t pCounter = data.wpos(); + data << uint32(0); + uint32 counter = 0; + std::set<uint64> alreadyAdded; + for (CalendarInviteMap::iterator itr = _inviteMap.begin(); itr != _inviteMap.end(); ++itr) + { + CalendarInvite invite = itr->second; + if (invite.TargetGuid == player->GetGUID()) + { + if (alreadyAdded.find(invite.Event) == alreadyAdded.end()) + { + CalendarEvent const* event = GetEvent(invite.Event); + data << uint64(event->Id); // event ID + data << event->Name; // event title + data << uint32(event->Type); // event type + data << uint32(event->Time); // event time as time bit field + data << uint32(event->Flags); // event flags + data << uint32(event->DungeonId); // dungeon ID + data.appendPackGUID(event->CreatorGuid); // creator guid + alreadyAdded.insert(invite.Event); + counter++; + } + } + } + data.put<uint32>(pCounter, counter); // update number of invites +} diff --git a/src/server/game/Calendar/CalendarMgr.h b/src/server/game/Calendar/CalendarMgr.h new file mode 100644 index 00000000000..50acde647cc --- /dev/null +++ b/src/server/game/Calendar/CalendarMgr.h @@ -0,0 +1,71 @@ +/* + * Copyright (C) 2008-2012 Trinity <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, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef TRINITY_CALENDARMGR_H +#define TRINITY_CALENDARMGR_H + +#include <ace/Singleton.h> +#include "Calendar.h" +#include "Player.h" + +class CalendarMgr +{ + friend class ACE_Singleton<CalendarMgr, ACE_Null_Mutex>; + +public: + CalendarMgr(); + ~CalendarMgr(); + + CalendarInvite const* GetInvite(uint64 inviteId) + { + CalendarInviteMap::const_iterator itr = _inviteMap.find(inviteId); + if(itr != _inviteMap.end()) + return &itr->second; + return NULL; + } + + void AddInvite(CalendarInvite invite) { _inviteMap[invite.Id] = invite; } + void RemoveInvite(uint64 inviteId) { _inviteMap.erase(inviteId); } + + CalendarEvent const* GetEvent(uint64 eventId) + { + CalendarEventMap::const_iterator itr = _eventMap.find(eventId); + if(itr != _eventMap.end()) + return &itr->second; + return NULL; + } + + void AddEvent(CalendarEvent event) { _eventMap[event.Id] = event; } + void RemoveEvent(uint64 eventId) { _eventMap.erase(eventId); } + + void AppendInvitesToCalendarPacketForPlayer(WorldPacket& data, Player* player); + void AppendEventsToCalendarPacketForPlayer(WorldPacket& data, Player* player); + + uint64 GetNextEventId() { return ++_currentEventId; } + uint64 GetNextInviteId() { return ++_currentInviteId; } + +private: + CalendarInviteMap _inviteMap; + CalendarEventMap _eventMap; + uint64 _currentEventId; + uint64 _currentInviteId; +}; + +#define sCalendarMgr ACE_Singleton<CalendarMgr, ACE_Null_Mutex>::instance() + +#endif diff --git a/src/server/game/Handlers/CalendarHandler.cpp b/src/server/game/Handlers/CalendarHandler.cpp index 820079a90e1..33ecbf8cac5 100755 --- a/src/server/game/Handlers/CalendarHandler.cpp +++ b/src/server/game/Handlers/CalendarHandler.cpp @@ -20,6 +20,7 @@ #include "WorldPacket.h" #include "WorldSession.h" +#include "CalendarMgr.h" #include "InstanceSaveMgr.h" #include "Log.h" #include "Opcodes.h" @@ -33,45 +34,25 @@ void WorldSession::HandleCalendarGetCalendar(WorldPacket& /*recv_data*/) time_t cur_time = time_t(time(NULL)); sLog->outDebug(LOG_FILTER_NETWORKIO, "SMSG_CALENDAR_SEND_CALENDAR [" UI64FMTD "]", guid); + // we can't really get the real size of this packet... WorldPacket data(SMSG_CALENDAR_SEND_CALENDAR, 4+4*0+4+4*0+4+4); - data << uint32(0); // invite count - /* - for (;;) - { - uint64 inviteId; - uint64 unkGuid0; - uint8 unk1, unk2, unk3; - uint64 creatorGuid; - } - */ - - data << uint32(0); // event count - /* - for (;;) - { - uint64 eventId; - std::string title; // 128 chars - uint32 type; - uint32 occurrenceTime; - uint32 flags; - uint32 unk4; -- possibly mapid for dungeon/raid - uint64 creatorGuid; - } - */ - - data << uint32(cur_time); // server time - data << uint32(secsToTimeBitFields(cur_time)); // server time + sCalendarMgr->AppendInvitesToCalendarPacketForPlayer(data, GetPlayer()); + sCalendarMgr->AppendEventsToCalendarPacketForPlayer(data, GetPlayer()); + data << uint32(cur_time); // current time + data << uint32(secsToTimeBitFields(cur_time)); // unknown packed time + + InstanceSave *save = NULL; uint32 counter = 0; size_t p_counter = data.wpos(); - data << uint32(counter); // instance save count + data << uint32(counter); // instance reset count for (uint8 i = 0; i < MAX_DIFFICULTY; ++i) for (Player::BoundInstancesMap::const_iterator itr = _player->m_boundInstances[i].begin(); itr != _player->m_boundInstances[i].end(); ++itr) if (itr->second.perm) { - InstanceSave const* save = itr->second.save; + save = itr->second.save; data << uint32(save->GetMapId()); data << uint32(save->GetDifficulty()); data << uint32(save->GetResetTime() - cur_time); @@ -111,83 +92,127 @@ void WorldSession::HandleCalendarGetCalendar(WorldPacket& /*recv_data*/) data.put<uint32>(p_counter, counter); - data << uint32(0); // holiday count? - /* - for (;;) + + // TODO: Fix this -- read from DBC? + std::string holidayName = ""; + uint32 holidayCount = 0; + data << uint32(holidayCount); // holiday count + for (uint32 i = 0; i < holidayCount; ++i) { - uint32 unk5, unk6, unk7, unk8, unk9; - for (uint32 j = 0; j < 26; ++j) - { - uint32 unk10; - } - for (uint32 j = 0; j < 10; ++j) - { - uint32 unk11; - } - for (uint32 j = 0; j < 10; ++j) - { - uint32 unk12; - } - std::string holidayName; // 64 chars + data << uint32(0); // Unk + data << uint32(0); // Unk + data << uint32(0); // Unk + data << uint32(0); // Unk + data << uint32(0); // Unk + for (uint8 j = 0; j < 26; ++j) + data << uint32(0); // Unk + for (uint8 j = 0; j < 10; ++j) + data << uint32(0); // Unk + for (uint8 j = 0; j < 10; ++j) + data << uint32(0); // Unk + data << holidayName.c_str(); // holiday name } - */ SendPacket(&data); } void WorldSession::HandleCalendarGetEvent(WorldPacket& recv_data) { - sLog->outDebug(LOG_FILTER_NETWORKIO, "WORLD: CMSG_CALENDAR_GET_EVENT"); - recv_data.read_skip<uint64>(); // unk + uint64 eventId; + recv_data >> eventId; + if (!eventId) + return; + //SendCalendarEvent(eventId); } void WorldSession::HandleCalendarGuildFilter(WorldPacket& recv_data) { sLog->outDebug(LOG_FILTER_NETWORKIO, "WORLD: CMSG_CALENDAR_GUILD_FILTER"); - recv_data.read_skip<uint32>(); // unk1 - recv_data.read_skip<uint32>(); // unk2 - recv_data.read_skip<uint32>(); // unk3 + + uint32 unk1; + uint32 unk2; + uint32 unk3; + recv_data >> unk1; + recv_data >> unk2; + recv_data >> unk3; } void WorldSession::HandleCalendarArenaTeam(WorldPacket& recv_data) { sLog->outDebug(LOG_FILTER_NETWORKIO, "WORLD: CMSG_CALENDAR_ARENA_TEAM"); - recv_data.read_skip<uint32>(); // unk + + uint32 unk1; + recv_data >> unk1; } void WorldSession::HandleCalendarAddEvent(WorldPacket& recv_data) { sLog->outDebug(LOG_FILTER_NETWORKIO, "WORLD: CMSG_CALENDAR_ADD_EVENT"); - recv_data.rfinish(); // set to end to avoid warnings spam - - //std::string unk1, unk2; - //recv_data >> (std::string)unk1; - //recv_data >> (std::string)unk2; - - //uint8 unk3, unk4; - //uint32 unk5, unk6, unk7, unk8, unk9, count = 0; - //recv_data >> (uint8)unk3; - //recv_data >> (uint8)unk4; - //recv_data >> (uint32)unk5; - //recv_data >> (uint32)unk6; - //recv_data >> (uint32)unk7; - //recv_data >> (uint32)unk8; - //recv_data >> (uint32)unk9; - //if (!((unk9 >> 6) & 1)) - //{ - // recv_data >> (uint32)count; - // if (count) - // { - // uint8 unk12, unk13; - // uint64 guid; - // for (int i=0; i<count; i++) - // { - // recv_data.readPackGUID(guid); - // recv_data >> (uint8)unk12; - // recv_data >> (uint8)unk13; - // } - // } - //} + + std::string title; + std::string description; + uint8 type; + uint8 unkbyte; + uint32 maxInvites; + uint32 dungeonId; + uint32 eventPackedTime; + uint32 unkPackedTime; + uint32 flags; + + recv_data >> title; + recv_data >> description; + recv_data >> type; + recv_data >> unkbyte; + recv_data >> maxInvites; + recv_data >> dungeonId; + recv_data >> eventPackedTime; + recv_data >> unkPackedTime; + recv_data >> flags; + + CalendarEvent event; + event.Id = sCalendarMgr->GetNextEventId(); + event.Name = title; + event.Description = description; + event.Type = type; + event.Unk = unkbyte; + event.DungeonId = dungeonId; + event.Flags = flags; + event.Time = eventPackedTime; + event.UnkTime = unkPackedTime; + event.CreatorGuid = GetPlayer()->GetGUID(); + + sCalendarMgr->AddEvent(event); + + if (((flags >> 6) & 1)) + return; + + uint32 inviteCount; + recv_data >> inviteCount; + + if (!inviteCount) + return; + + uint64 guid; + uint8 status; + uint8 rank; + for (int32 i = 0; i < inviteCount; ++i) + { + CalendarInvite invite; + invite.Id = sCalendarMgr->GetNextInviteId(); + recv_data.readPackGUID(guid); + recv_data >> status; + recv_data >> rank; + invite.Event = event.Id; + invite.CreatorGuid = GetPlayer()->GetGUID(); + invite.TargetGuid = guid; + invite.Status = status; + invite.Rank = rank; + invite.Time = event.Time; + invite.Text = ""; // hmm... + invite.Unk1 = invite.Unk2 = invite.Unk3 = 0; + sCalendarMgr->AddInvite(invite); + } + //SendCalendarEvent(eventId, true); } void WorldSession::HandleCalendarUpdateEvent(WorldPacket& recv_data) @@ -211,12 +236,14 @@ void WorldSession::HandleCalendarUpdateEvent(WorldPacket& recv_data) void WorldSession::HandleCalendarRemoveEvent(WorldPacket& recv_data) { sLog->outDebug(LOG_FILTER_NETWORKIO, "WORLD: CMSG_CALENDAR_REMOVE_EVENT"); - recv_data.rfinish(); // set to end to avoid warnings spam - //recv_data >> uint64 - //recv_data >> uint64 - //recv_data >> uint32 + uint64 eventId; + uint64 creatorGuid; + uint32 unk1; + recv_data >> eventId; + recv_data >> creatorGuid; + recv_data >> unk1; } void WorldSession::HandleCalendarCopyEvent(WorldPacket& recv_data) @@ -233,14 +260,22 @@ void WorldSession::HandleCalendarCopyEvent(WorldPacket& recv_data) void WorldSession::HandleCalendarEventInvite(WorldPacket& recv_data) { sLog->outDebug(LOG_FILTER_NETWORKIO, "WORLD: CMSG_CALENDAR_EVENT_INVITE"); - recv_data.rfinish(); // set to end to avoid warnings spam - //recv_data >> uint64 - //recv_data >> uint64 - //recv_data >> std::string - //recv_data >> uint8 - //recv_data >> uint8 + uint64 eventId; + uint64 inviteId; + std::string name; + uint8 status; + uint8 rank; + + recv_data >> eventId; + recv_data >> inviteId; + recv_data >> name; + recv_data >> status; + recv_data >> rank; + + //FIXME - Finish it + recv_data.rfinish(); // set to end to avoid warnings spam } void WorldSession::HandleCalendarEventRsvp(WorldPacket& recv_data) @@ -304,6 +339,71 @@ void WorldSession::HandleCalendarGetNumPending(WorldPacket& /*recv_data*/) sLog->outDebug(LOG_FILTER_NETWORKIO, "WORLD: CMSG_CALENDAR_GET_NUM_PENDING"); // empty WorldPacket data(SMSG_CALENDAR_SEND_NUM_PENDING, 4); - data << uint32(0); // 0 - no pending invites, 1 - some pending invites + data << uint32(0); // number of pending invites + SendPacket(&data); +} + +void WorldSession::SendCalendarEvent(uint64 eventId, bool added) +{ + sLog->outDebug(LOG_FILTER_NETWORKIO, "SMSG_CALENDAR_SEND_EVENT"); + WorldPacket data(SMSG_CALENDAR_SEND_EVENT); + data << uint8(added); // from add_event + data.appendPackGUID(0); // creator GUID + data << uint64(0); // event ID + data << uint8(0); // event name + data << uint8(0); // event description + data << uint8(0); // event type + data << uint8(0); // unk + data << uint32(100); // Max invites + data << int32(0); // dungeon ID + data << uint32(0); // unk time + data << uint32(0); // event time + data << uint32(0); // event flags + data << uint32(0); // event guild id + + if (false) // invites exist + { + data << uint32(0); // invite count + for (uint8 i = 0; i < 0; ++i) + { + data << uint64(0); // invite played guid + data << uint8(0); // unk + data << uint8(0); // status + data << uint8(0); // rank + data << uint8(0); // unk + data << uint64(0); // invite ID + data << uint32(0); // unk + data << uint8(0); // text + } + } + SendPacket(&data); +} + +void WorldSession::SendCalendarEventInviteAlert(uint64 eventId, uint64 inviteId) +{ + sLog->outDebug(LOG_FILTER_NETWORKIO, "SMSG_CALENDAR_EVENT_INVITE_ALERT"); + WorldPacket data(SMSG_CALENDAR_EVENT_INVITE_ALERT); + data << uint64(0); // event ID + data << uint8(0); // event title + data << uint32(0); // event time + uint32 unknum = 1; + data << uint32(unknum); + data << uint8(0); // event type + data << uint32(0); // dungeon id + data << uint64(0); // invite id + data << uint8(0); // invite status + data << uint8(0); // invite rank + data.appendPackGUID(0); // event creator + data.appendPackGUID(0); // invite sender + SendPacket(&data); +} + +void WorldSession::SendCalendarEventRemovedAlert(uint64 eventId) +{ + sLog->outDebug(LOG_FILTER_NETWORKIO, "SMSG_CALENDAR_EVENT_REMOVED_ALERT"); + WorldPacket data(SMSG_CALENDAR_EVENT_REMOVED_ALERT); + data << uint8(0); // unk + data << uint64(0); // invite id + data << uint32(0); // invite time SendPacket(&data); } diff --git a/src/server/game/Server/WorldSession.h b/src/server/game/Server/WorldSession.h index 90772bfeab9..47c48e96de0 100755 --- a/src/server/game/Server/WorldSession.h +++ b/src/server/game/Server/WorldSession.h @@ -878,6 +878,9 @@ class WorldSession void HandleCalendarEventModeratorStatus(WorldPacket& recv_data); void HandleCalendarComplain(WorldPacket& recv_data); void HandleCalendarGetNumPending(WorldPacket& recv_data); + void SendCalendarEvent(uint64 eventId, bool added = false); + void SendCalendarEventInviteAlert(uint64 eventId, uint64 inviteId); + void SendCalendarEventRemovedAlert(uint64 eventId); void HandleSpellClick(WorldPacket& recv_data); void HandleMirrorImageDataRequest(WorldPacket& recv_data); |