Core/Calendar: WIP Calendar.

This commit is contained in:
Spp
2012-02-24 20:11:29 +01:00
parent a934abbbb7
commit 32eab3dca7
8 changed files with 1758 additions and 391 deletions
+303
View File
@@ -17,3 +17,306 @@
*/
#include "Calendar.h"
CalendarInvite::CalendarInvite(uint64 _inviteId /* = 0 */): inviteId(_inviteId),
eventId(0), invitee(0), senderGUID(0), statusTime(0), status(0), rank(0)
{
}
CalendarInvite::~CalendarInvite()
{
}
void CalendarInvite::SetInviteId(uint64 _inviteId)
{
inviteId = _inviteId;
}
uint64 CalendarInvite::GetInviteId() const
{
return inviteId;
}
void CalendarInvite::SetEventId(uint64 _eventId)
{
eventId = _eventId;
}
uint64 CalendarInvite::GetEventId() const
{
return eventId;
}
void CalendarInvite::SetSenderGUID(uint64 _guid)
{
senderGUID = _guid;
}
uint64 CalendarInvite::GetSenderGUID() const
{
return senderGUID;
}
void CalendarInvite::SetInvitee(uint64 _guid)
{
invitee = _guid;
}
uint64 CalendarInvite::GetInvitee() const
{
return invitee;
}
void CalendarInvite::SetStatusTime(uint32 _statusTime)
{
statusTime = _statusTime;
}
uint32 CalendarInvite::GetStatusTime() const
{
return statusTime;
}
void CalendarInvite::SetText(std::string _text)
{
text = _text;
}
std::string CalendarInvite::GetText() const
{
return text;
}
void CalendarInvite::SetStatus(uint8 _status)
{
status = _status;
}
uint8 CalendarInvite::GetStatus() const
{
return status;
}
void CalendarInvite::SetRank(uint8 _rank)
{
rank = _rank;
}
uint8 CalendarInvite::GetRank() const
{
return rank;
}
CalendarEvent::CalendarEvent(uint64 _eventId /* = 0 */) : eventId(_eventId),
creatorGUID(0), guildId(0), type(CALENDAR_TYPE_OTHER), dungeonId(-1),
maxInvites(0), eventTime(0), flags(0), repeatable(false), timezoneTime(0),
title(""), description("")
{
}
CalendarEvent::~CalendarEvent()
{
}
void CalendarEvent::SetEventId(uint64 _eventId)
{
eventId = _eventId;
}
uint64 CalendarEvent::GetEventId() const
{
return eventId;
}
void CalendarEvent::SetCreatorGUID(uint64 _guid)
{
creatorGUID = _guid;
}
uint64 CalendarEvent::GetCreatorGUID() const
{
return creatorGUID;
}
void CalendarEvent::SetGuildId(uint32 _guildId)
{
guildId = _guildId;
}
uint32 CalendarEvent::GetGuildId() const
{
return guildId;
}
void CalendarEvent::SetTitle(std::string _title)
{
title = _title;
}
std::string CalendarEvent::GetTitle() const
{
return title;
}
void CalendarEvent::SetDescription(std::string _description)
{
description = _description;
}
std::string CalendarEvent::GetDescription() const
{
return description;
}
void CalendarEvent::SetType(uint8 _type)
{
type = _type;
}
uint8 CalendarEvent::GetType() const
{
return type;
}
void CalendarEvent::SetMaxInvites(uint32 max)
{
maxInvites = max;
}
uint32 CalendarEvent::GetMaxInvites() const
{
return maxInvites;
}
void CalendarEvent::SetDungeonId(int32 _dungeonId)
{
dungeonId = _dungeonId;
}
int32 CalendarEvent::GetDungeonId() const
{
return dungeonId;
}
void CalendarEvent::SetTime(uint32 _eventTime)
{
eventTime = _eventTime;
}
uint32 CalendarEvent::GetTime() const
{
return eventTime;
}
void CalendarEvent::SetFlags(uint32 _flags)
{
flags = _flags;
}
uint32 CalendarEvent::GetFlags() const
{
return flags;
}
void CalendarEvent::SetRepeatable(bool _repeatable)
{
repeatable = _repeatable;
}
uint8 CalendarEvent::GetRepeatable() const
{
return repeatable;
}
void CalendarEvent::SetTimeZoneTime(uint32 _timezoneTime)
{
timezoneTime = _timezoneTime;
}
uint32 CalendarEvent::GetTimeZoneTime() const
{
return timezoneTime;
}
void CalendarEvent::AddInvite(uint64 inviteId)
{
if (inviteId)
_invites.insert(inviteId);
}
void CalendarEvent::RemoveInvite(uint64 inviteId)
{
_invites.erase(inviteId);
}
bool CalendarEvent::HasInvite(uint64 inviteId) const
{
return _invites.find(inviteId) != _invites.end();
}
CalendarinviteIdList const& CalendarEvent::GetInviteIdList() const
{
return _invites;
}
void CalendarEvent::SetInviteIdList(CalendarinviteIdList const& list)
{
_invites = list;
}
void CalendarEvent::ClearInviteIdList()
{
_invites.clear();
}
std::string CalendarInvite::GetDebugString() const
{
std::ostringstream data;
data << "CalendarInvite::"
<< " inviteId: " << inviteId
<< " EventId: " << eventId
<< " Status: " << uint32(status)
<< " Invitee: " << invitee
<< " Sender: " << senderGUID
<< " Rank: " << uint32(rank)
<< " Text: " << text;
return data.str();
}
std::string CalendarEvent::GetDebugString() const
{
std::ostringstream data;
data << "CalendarEvent::"
<< " EventId: " << eventId
<< " Title: " << title
<< " Description" << description
<< " Type: " << uint32(type)
<< " Max Invites: " << maxInvites
<< " Creator: " << creatorGUID
<< " Flags: " << flags
<< " Guild: " << guildId
<< " Time: " << eventTime
<< " Time2: " << timezoneTime
<< " Repeatable: " << uint32(repeatable)
<< " DungeonId: " << dungeonId;
return data.str();
}
std::string CalendarAction::GetDebugString() const
{
std::ostringstream data;
data << "CalendarAction::"
<< " Action: " << GetAction()
<< " Guid: " << GetGUID()
<< " Invite Id: " << GetInviteId()
<< " Extra data: " << GetExtraData()
<< " Event: " << Event.GetDebugString()
<< " Invite: " << Invite.GetDebugString();
return data.str();
}
+160 -59
View File
@@ -20,86 +20,187 @@
#define TRINITY_CALENDAR_H
#include "Common.h"
#include <map>
enum CalendarEventType
enum CalendarFlags
{
CALENDARTYPE_RAID = 0,
CALENDARTYPE_DUNGEON,
CALENDARTYPE_PVP,
CALENDARTYPE_MEETING,
CALENDARTYPE_OTHER,
CALENDAR_FLAG_ALL_ALLOWED = 0x001,
CALENDAR_FLAG_INVITES_LOCKED = 0x010,
CALENDAR_FLAG_WITHOUT_INVITES = 0x040,
CALENDAR_FLAG_GUILD_ONLY = 0x400,
};
enum CalendarActionData
{
CALENDAR_ACTION_NONE,
CALENDAR_ACTION_ADD_EVENT,
CALENDAR_ACTION_MODIFY_EVENT,
CALENDAR_ACTION_REMOVE_EVENT,
CALENDAR_ACTION_COPY_EVENT,
CALENDAR_ACTION_ADD_EVENT_INVITE,
CALENDAR_ACTION_MODIFY_EVENT_INVITE,
CALENDAR_ACTION_MODIFY_MODERATOR_EVENT_INVITE,
CALENDAR_ACTION_REMOVE_EVENT_INVITE,
CALENDAR_ACTION_SIGNUP_TO_EVENT,
};
enum CalendarRanks
{
CALENDAR_RANK_PLAYER,
CALENDAR_RANK_MODERATOR,
CALENDAR_RANK_OWNER,
};
enum CalendarSendEventType
{
CALENDARSENDEVENTTYPE_GET = 0,
CALENDARSENDEVENTTYPE_ADD,
CALENDARSENDEVENTTYPE_COPY
CALENDAR_SENDTYPE_GET,
CALENDAR_SENDTYPE_ADD,
CALENDAR_SENDTYPE_COPY,
};
enum CalendarModerationRank
enum CalendarEventType
{
CALENDARMODERATIONRANK_PLAYER = 0,
CALENDARMODERATIONRANK_MODERATOR,
CALENDARMODERATIONRANK_OWNER
CALENDAR_TYPE_RAID,
CALENDAR_TYPE_DUNGEON,
CALENDAR_TYPE_PVP,
CALENDAR_TYPE_MEETING,
CALENDAR_TYPE_OTHER,
};
enum CalendarEventStatus
enum CalendarInviteStatus
{
CALENDARSTATUS_INVITED = 0,
CALENDARSTATUS_ACCEPTED,
CALENDARSTATUS_DECLINED,
CALENDARSTATUS_TENTATIVE,
CALENDARSTATUS_OUT,
CALENDARSTATUS_STANDBY,
CALENDARSTATUS_CONFIRMED,
// CALENDARSTATUS_UNK7
// CALENDARSTATUS_UNK8
// CALENDARSTATUS_UNK9
CALENDAR_STATUS_INVITED,
CALENDAR_STATUS_ACCEPTED,
CALENDAR_STATUS_DECLINED,
CALENDAR_STATUS_TENTATIVE,
CALENDAR_STATUS_OUT,
CALENDAR_STATUS_STANDBY,
CALENDAR_STATUS_CONFIRMED,
CALENDAR_STATUS_NO_OWNER,
CALENDAR_STATUS_8,
CALENDAR_STATUS_9,
};
enum CalendarFlags
class CalendarInvite
{
CALENDARFLAG_NONE = 0x000000,
CALENDARFLAG_NORMAL = 0x000001,
CALENDARFLAG_INVITES_LOCKED = 0x000010,
CALENDARFLAG_WITHOUT_INVITES = 0x000040,
CALENDARFLAG_GUILD_EVENT = 0x000400
// CALENDARFLAG_Unk10000 = 0x010000,
// CALENDARFLAG_Unk400000 = 0x400000
public:
CalendarInvite(uint64 _inviteId = 0);
~CalendarInvite();
void SetInviteId(uint64 inviteId);
uint64 GetInviteId() const;
void SetEventId(uint64 eventId);
uint64 GetEventId() const;
void SetSenderGUID(uint64 guid);
uint64 GetSenderGUID() const;
void SetInvitee(uint64 guid);
uint64 GetInvitee() const;
void SetStatusTime(uint32 statusTime);
uint32 GetStatusTime() const;
void SetText(std::string text);
std::string GetText() const;
void SetStatus(uint8 _status);
uint8 GetStatus() const;
void SetRank(uint8 _rank);
uint8 GetRank() const;
std::string GetDebugString() const;
private:
uint64 inviteId;
uint64 eventId;
uint64 invitee;
uint64 senderGUID;
uint32 statusTime;
uint8 status;
uint8 rank;
std::string text;
};
struct CalendarEvent
typedef std::set<uint64> CalendarinviteIdList;
class CalendarEvent
{
uint64 Id;
uint64 CreatorGuid;
std::string Name;
std::string Description;
CalendarEventType Type;
uint8 Unk;
uint32 DungeonId;
uint32 UnkTime;
uint32 Time;
CalendarFlags Flags;
uint32 GuildId;
public:
CalendarEvent(uint64 _eventId = 0);
~CalendarEvent();
void SetEventId(uint64 eventId);
uint64 GetEventId() const;
void SetCreatorGUID(uint64 guid);
uint64 GetCreatorGUID() const;
void SetGuildId(uint32 guild);
uint32 GetGuildId() const;
void SetTitle(std::string title);
std::string GetTitle() const;
void SetDescription(std::string description);
std::string GetDescription() const;
void SetType(uint8 type);
uint8 GetType() const;
void SetMaxInvites(uint32 max);
uint32 GetMaxInvites() const;
void SetDungeonId(int32 dungeonId);
int32 GetDungeonId() const;
void SetTime(uint32 eventTime);
uint32 GetTime() const;
void SetFlags(uint32 flags);
uint32 GetFlags() const;
void SetRepeatable(bool repeatable);
uint8 GetRepeatable() const;
void SetTimeZoneTime(uint32 time);
uint32 GetTimeZoneTime() const;
void AddInvite(uint64 inviteId);
void RemoveInvite(uint64 inviteId);
bool HasInvite(uint64 inviteId) const;
CalendarinviteIdList const& GetInviteIdList() const;
void SetInviteIdList(CalendarinviteIdList const& list);
void ClearInviteIdList();
std::string GetDebugString() const;
private:
uint64 eventId;
uint64 creatorGUID;
uint32 guildId;
uint8 type;
int32 dungeonId;
uint32 maxInvites;
uint32 eventTime;
uint32 flags;
uint8 repeatable;
uint32 timezoneTime;
std::string title;
std::string description;
CalendarinviteIdList _invites;
};
struct CalendarInvite
typedef std::set<uint64> CalendarEventIdList;
typedef std::map<uint64, CalendarinviteIdList> CalendarPlayerinviteIdMap;
typedef std::map<uint64, CalendarEventIdList> CalendarPlayerEventIdMap;
typedef std::map<uint64, CalendarInvite> CalendarInviteMap;
typedef std::map<uint64, CalendarEvent> CalendarEventMap;
struct CalendarAction
{
uint64 Id;
uint64 Event;
CalendarEventStatus Status;
CalendarModerationRank Rank;
uint8 Unk1;
uint8 Unk2;
uint8 Unk3;
std::string Text;
uint64 CreatorGuid;
uint32 Time;
uint64 TargetGuid;
};
CalendarAction(): _action(CALENDAR_ACTION_NONE), _guid(0), _inviteId(0), _data(0) {};
std::string GetDebugString() const;
typedef UNORDERED_MAP<uint64, CalendarInvite> CalendarInviteMap;
typedef UNORDERED_MAP<uint64, CalendarEvent> CalendarEventMap;
void SetAction(CalendarActionData data) { _action = data; }
void SetGUID(uint64 guid) { _guid = guid; }
void SetInviteId(uint64 id) { _inviteId = id; }
void SetExtraData(uint32 data) { _data = data; }
uint64 GetGUID() const { return _guid; }
CalendarActionData GetAction() const { return _action; }
uint64 GetInviteId() const { return _inviteId; }
uint32 GetExtraData() const { return _data; }
CalendarEvent Event;
CalendarInvite Invite;
private:
CalendarActionData _action;
uint64 _guid;
uint64 _inviteId;
uint32 _data;
};
#endif
+546 -59
View File
@@ -1,25 +1,61 @@
/*
* Copyright (C) 2008-2012 Trinity <http://www.trinitycore.org/>
* Copyright (C) 2008-2012 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 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.
* 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
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*
DROP TABLE IF EXISTS `calendar_events`;
CREATE TABLE IF NOT EXISTS `calendar_events` (
`id` int(11) unsigned NOT NULL DEFAULT '0',
`creator` int(11) unsigned NOT NULL DEFAULT '0',
`title` varchar(255) NOT NULL DEFAULT '',
`description` varchar(255) NOT NULL DEFAULT '',
`type` tinyint(1) unsigned NOT NULL DEFAULT '4',
`dungeon` tinyint(3) NOT NULL DEFAULT '-1',
`eventtime` int(10) unsigned NOT NULL DEFAULT '0',
`flags` int(10) unsigned NOT NULL DEFAULT '0',
`repeatable` tinyint(1) unsigned NOT NULL DEFAULT '0',
`time2` int(10) unsigned NOT NULL DEFAULT '0',
PRIMARY KEY (`id`)
);
DROP TABLE IF EXISTS `calendar_invites`;
CREATE TABLE IF NOT EXISTS `calendar_invites` (
`id` int(11) unsigned NOT NULL DEFAULT '0',
`event` int(11) unsigned NOT NULL DEFAULT '0',
`invitee` int(11) unsigned NOT NULL DEFAULT '0',
`sender` int(11) unsigned NOT NULL DEFAULT '0',
`status` tinyint(1) unsigned NOT NULL DEFAULT '0',
`statustime` int(10) unsigned NOT NULL DEFAULT '0',
`rank` tinyint(1) unsigned NOT NULL DEFAULT '0',
`text` varchar(255) NOT NULL DEFAULT '',
PRIMARY KEY (`id`)
);
*/
#include "CalendarMgr.h"
#include "QueryResult.h"
#include "DatabaseEnv.h"
#include "Log.h"
#include "Player.h"
#include "ObjectAccessor.h"
CalendarMgr::CalendarMgr() : _currentEventId(0), _currentInviteId(0)
CalendarMgr::CalendarMgr()
: eventNum(0)
, InviteNum(0)
{
}
@@ -27,54 +63,505 @@ CalendarMgr::~CalendarMgr()
{
}
void CalendarMgr::AppendInvitesToCalendarPacketForPlayer(WorldPacket& data, Player* player)
uint32 CalendarMgr::GetPlayerNumPending(uint64 guid)
{
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
if (!guid)
return 0;
CalendarPlayerinviteIdMap::const_iterator itr = _playerInvites.find(guid);
if (itr == _playerInvites.end())
return 0;
uint32 pendingNum = 0;
for (CalendarinviteIdList::const_iterator it = itr->second.begin(); it != itr->second.end(); ++it)
if (CalendarInvite* invite = GetInvite(*it))
if (invite->GetRank() != CALENDAR_RANK_OWNER
&& invite->GetStatus() != CALENDAR_STATUS_CONFIRMED
&& invite->GetStatus() != CALENDAR_STATUS_8
&& invite->GetStatus() != CALENDAR_STATUS_9) // FIXME Check the proper value
++pendingNum;
return pendingNum;
}
void CalendarMgr::AppendEventsToCalendarPacketForPlayer(WorldPacket& data, Player* player)
CalendarinviteIdList const& CalendarMgr::GetPlayerInvites(uint64 guid)
{
// 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
return _playerInvites[guid];
}
CalendarEventIdList const& CalendarMgr::GetPlayerEvents(uint64 guid)
{
return _playerEvents[guid];
}
CalendarInvite* CalendarMgr::GetInvite(uint64 inviteId)
{
CalendarInviteMap::iterator it = _invites.find(inviteId);
if (it != _invites.end())
return &(it->second);
sLog->outError("SPP: CalendarMgr::GetInvite: [" UI64FMTD "] not found!", inviteId);
return NULL;
}
CalendarEvent* CalendarMgr::GetEvent(uint64 eventId)
{
CalendarEventMap::iterator it = _events.find(eventId);
if (it != _events.end())
return &(it->second);
sLog->outError("SPP: CalendarMgr::GetEvent: [" UI64FMTD "] not found!", eventId);
return NULL;
}
uint64 CalendarMgr::GetFreeEventId()
{
return ++eventNum;
}
uint64 CalendarMgr::GetFreeInviteId()
{
return ++InviteNum;
}
void CalendarMgr::LoadFromDB()
{
/*
uint32 count = 0;
// 0 1 2 3 4 5 6 7 8 9
if (QueryResult result = CharacterDatabase.Query("SELECT id, creator, title, description, type, dungeon, eventtime, flags, repeatable, time2 FROM calendar_events"))
do
{
Field * fields = result->Fetch();
uint64 eventId = fields[0].GetUInt64();
CalendarEvent& calendarEvent = _events[eventId];
calendarEvent.SetEventId(eventId);
calendarEvent.SetCreatorGUID(fields[1].GetUInt64());
calendarEvent.SetTitle(fields[2].GetString());
calendarEvent.SetDescription(fields[3].GetString());
calendarEvent.SetType(fields[4].GetUInt8());
calendarEvent.SetDungeonId(fields[5].GetInt32());
calendarEvent.SetTime(fields[6].GetUInt32());
calendarEvent.SetFlags(fields[7].GetUInt32());
calendarEvent.SetRepeatable(fields[8].GetBool());
calendarEvent.SetTimeZoneTime(fields[9].GetUInt32());
++count;
}
while (result->NextRow());
sLog->outString(">> Loaded %u calendar events", count);
count = 0;
// 0 1 2 3 4 5 6 7
if (QueryResult result = CharacterDatabase.Query("SELECT id, event, invitee, sender, status, statustime, rank, text FROM calendar_invites"))
do
{
Field * fields = result->Fetch();
uint64 inviteId = fields[0].GetUInt64();
uint64 eventId = fields[1].GetUInt64();
CalendarInvite& invite = _invites[inviteId];
invite.SetEventId(eventId);
invite.SetInvitee(fields[2].GetUInt64());
invite.SetSenderGUID(fields[3].GetUInt64());
invite.SetStatus(fields[4].GetUInt8());
invite.SetStatusTime(fields[5].GetUInt32());
invite.SetRank(fields[6].GetUInt8());
invite.SetText(fields[7].GetString());
CalendarEvent& calendarEvent = _events[eventId];
calendarEvent.AddInvite(inviteId);
}
while (result->NextRow());
sLog->outString(">> Loaded %u calendar Invites", count);
*/
}
CalendarEvent* CalendarMgr::CheckPermisions(uint64 eventId, uint64 guid, uint64 inviteId, CalendarRanks minRank)
{
if (CalendarEvent* calendarEvent = GetEvent(eventId))
if (CalendarInvite* invite = GetInvite(inviteId))
if (calendarEvent->HasInvite(inviteId)
&& invite->GetEventId() == calendarEvent->GetEventId()
&& invite->GetInvitee() == guid
&& invite->GetRank() >= minRank)
return calendarEvent;
return NULL;
}
void CalendarMgr::AddAction(CalendarAction const& action)
{
switch (action.GetAction())
{
case CALENDAR_ACTION_ADD_EVENT:
{
if (addEvent(action.Event) && addInvite(action.Invite))
{
SendCalendarEventInviteAlert(action.Event, action.Invite);
SendCalendarEvent(action.Event, CALENDAR_SENDTYPE_ADD);
}
break;
}
case CALENDAR_ACTION_MODIFY_EVENT:
{
uint64 eventId = action.Event.GetEventId();
CalendarEvent* calendarEvent = CheckPermisions(eventId,
action.GetGUID(), action.GetInviteId(), CALENDAR_RANK_MODERATOR);
if (!calendarEvent)
return;
calendarEvent->SetEventId(action.Event.GetEventId());
calendarEvent->SetType(action.Event.GetType());
calendarEvent->SetFlags(action.Event.GetFlags());
calendarEvent->SetTime(action.Event.GetTime());
calendarEvent->SetTimeZoneTime(action.Event.GetTimeZoneTime());
calendarEvent->SetRepeatable(action.Event.GetRepeatable());
calendarEvent->SetDungeonId(action.Event.GetDungeonId());
calendarEvent->SetTitle(action.Event.GetTitle());
calendarEvent->SetDescription(action.Event.GetDescription());
calendarEvent->SetMaxInvites(action.Event.GetMaxInvites());
CalendarinviteIdList const& invites = calendarEvent->GetInviteIdList();
for (CalendarinviteIdList::const_iterator itr = invites.begin(); itr != invites.end(); ++itr)
if (CalendarInvite* invite = GetInvite(*itr))
SendCalendarEventUpdateAlert(invite->GetInvitee(), *calendarEvent, CALENDAR_SENDTYPE_ADD);
break;
}
case CALENDAR_ACTION_COPY_EVENT:
{
CalendarEvent* calendarEvent = CheckPermisions(action.Event.GetEventId(),
action.GetGUID(), action.GetInviteId(), CALENDAR_RANK_OWNER);
if (!calendarEvent)
return;
uint64 eventId = GetFreeEventId();
CalendarEvent newEvent(eventId);
newEvent.SetType(calendarEvent->GetType());
newEvent.SetFlags(calendarEvent->GetFlags());
newEvent.SetTime(action.Event.GetTime());
newEvent.SetTimeZoneTime(calendarEvent->GetTimeZoneTime());
newEvent.SetRepeatable(calendarEvent->GetRepeatable());
newEvent.SetDungeonId(calendarEvent->GetDungeonId());
newEvent.SetTitle(calendarEvent->GetTitle());
newEvent.SetDescription(calendarEvent->GetDescription());
newEvent.SetMaxInvites(calendarEvent->GetMaxInvites());
newEvent.SetCreatorGUID(calendarEvent->GetCreatorGUID());
newEvent.SetGuildId(calendarEvent->GetGuildId());
CalendarinviteIdList const invites = calendarEvent->GetInviteIdList();
for (CalendarinviteIdList::const_iterator itr = invites.begin(); itr != invites.end(); ++itr)
if (CalendarInvite* invite = GetInvite(*itr))
{
uint64 inviteId = GetFreeInviteId();
CalendarInvite newInvite(inviteId);
newInvite.SetEventId(eventId);
newInvite.SetSenderGUID(action.GetGUID());
newInvite.SetInvitee(invite->GetInvitee());
newInvite.SetStatus(invite->GetStatus());
newInvite.SetStatusTime(invite->GetStatusTime());
newInvite.SetText(invite->GetText());
newInvite.SetRank(invite->GetRank());
if (addInvite(newInvite))
{
SendCalendarEventInviteAlert(newEvent, newInvite);
newEvent.AddInvite(inviteId);
}
}
if (addEvent(newEvent))
SendCalendarEvent(newEvent, CALENDAR_SENDTYPE_COPY);
break;
}
case CALENDAR_ACTION_REMOVE_EVENT:
{
uint64 eventId = action.Event.GetEventId();
uint32 flags = action.Event.GetFlags();
sLog->outError("CalendarMgr::AddAction:: Flags %u", flags);
// FIXME - Use of Flags here!
CalendarEvent* calendarEvent = CheckPermisions(eventId,
action.GetGUID(), action.GetInviteId(), CALENDAR_RANK_OWNER);
if (!calendarEvent)
return;
CalendarinviteIdList const& inviteIds = calendarEvent->GetInviteIdList();
for (CalendarinviteIdList::const_iterator it = inviteIds.begin(); it != inviteIds.end(); ++it)
if (uint64 invitee = removeInvite(*it))
SendCalendarEventRemovedAlert(invitee, *calendarEvent);
removeEvent(eventId);
break;
}
case CALENDAR_ACTION_ADD_EVENT_INVITE:
{
uint64 eventId = action.Invite.GetEventId();
CalendarEvent* calendarEvent = CheckPermisions(eventId,
action.GetGUID(), action.GetInviteId(), CALENDAR_RANK_MODERATOR);
if (!calendarEvent)
return;
if (addInvite(action.Invite))
{
calendarEvent->AddInvite(action.Invite.GetInviteId());
SendCalendarEventInvite(action.Invite, (!(calendarEvent->GetFlags() & CALENDAR_FLAG_INVITES_LOCKED) &&
!action.Invite.GetStatusTime()));
SendCalendarEventInviteAlert(*calendarEvent, action.Invite);
}
break;
}
case CALENDAR_ACTION_SIGNUP_TO_EVENT:
{
uint64 eventId = action.Event.GetEventId();
CalendarEvent* calendarEvent = GetEvent(eventId);
CheckPermisions(eventId,
action.GetGUID(), action.GetInviteId(), CALENDAR_RANK_MODERATOR);
if (!calendarEvent || !(calendarEvent->GetFlags() & CALENDAR_FLAG_GUILD_ONLY)
|| !calendarEvent->GetGuildId() || calendarEvent->GetGuildId() != action.GetExtraData())
return;
uint8 status = action.Invite.GetStatus();
if (status == CALENDAR_STATUS_INVITED)
status = CALENDAR_STATUS_CONFIRMED;
else if (status == CALENDAR_STATUS_ACCEPTED)
status = CALENDAR_STATUS_8;
CalendarInvite newInvite(GetFreeInviteId());
newInvite.SetStatus(status);
newInvite.SetStatusTime(uint32(time(NULL)));
newInvite.SetEventId(eventId);
newInvite.SetInvitee(action.GetGUID());
newInvite.SetSenderGUID(action.GetGUID());
if (addInvite(newInvite))
SendCalendarEventInvite(newInvite, false);
break;
}
case CALENDAR_ACTION_MODIFY_EVENT_INVITE:
{
uint64 eventId = action.Invite.GetEventId();
uint64 inviteId = action.Invite.GetInviteId();
CalendarEvent* calendarEvent;
if (action.GetInviteId() != action.Invite.GetInviteId())
calendarEvent = CheckPermisions(eventId, action.GetGUID(), action.GetInviteId(), CALENDAR_RANK_MODERATOR);
else
calendarEvent = GetEvent(eventId);
CalendarInvite* invite = GetInvite(inviteId);
if (!calendarEvent || !invite || !calendarEvent->HasInvite(inviteId))
return;
invite->SetStatus(action.Invite.GetStatus());
SendCalendarEventStatus(invite->GetSenderGUID(), *calendarEvent, *invite);
break;
}
case CALENDAR_ACTION_MODIFY_MODERATOR_EVENT_INVITE:
{
uint64 eventId = action.Invite.GetEventId();
uint64 inviteId = action.Invite.GetInviteId();
CalendarEvent* calendarEvent;
if (action.GetInviteId() != action.Invite.GetInviteId())
calendarEvent = CheckPermisions(eventId, action.GetGUID(), action.GetInviteId(), CALENDAR_RANK_OWNER);
else
calendarEvent = GetEvent(eventId);
CalendarInvite* invite = GetInvite(inviteId);
if (!calendarEvent || !invite || !calendarEvent->HasInvite(inviteId))
return;
sLog->outError("SPP: CALENDAR_ACTION_MODIFY_MODERATOR_EVENT_INVITE: All OK");
invite->SetStatus(action.Invite.GetStatus());
SendCalendarEventModeratorStatusAlert(*invite);
break;
}
case CALENDAR_ACTION_REMOVE_EVENT_INVITE:
{
uint64 eventId = action.Invite.GetEventId();
uint64 inviteId = action.Invite.GetInviteId();
CalendarEvent* calendarEvent = CheckPermisions(eventId,
action.GetGUID(), action.GetInviteId(), CALENDAR_RANK_MODERATOR);
if (!calendarEvent)
return;
if (uint64 invitee = removeInvite(inviteId))
{
SendCalendarEventInviteRemoveAlert(invitee, *calendarEvent, CALENDAR_STATUS_9);
SendCalendarEventInviteRemove(action.GetGUID(), action.Invite, calendarEvent->GetFlags());
}
break;
}
default:
break;
}
}
bool CalendarMgr::addEvent(CalendarEvent const& newEvent)
{
uint64 eventId = newEvent.GetEventId();
if (_events.find(eventId) != _events.end())
{
sLog->outError("CalendarMgr::addEvent: Event [" UI64FMTD "] exists", eventId);
return false;
}
_events[eventId] = newEvent;
return true;
}
bool CalendarMgr::removeEvent(uint64 eventId)
{
CalendarEventMap::iterator itr = _events.find(eventId);
if (itr == _events.end())
{
sLog->outError("CalendarMgr::removeEvent: Event [" UI64FMTD "] does not exist", eventId);
return false;
}
_events.erase(itr);
bool val = true;
CalendarinviteIdList const& invites = itr->second.GetInviteIdList();
for (CalendarinviteIdList::const_iterator itr = invites.begin(); itr != invites.end(); ++itr)
{
CalendarInvite* invite = GetInvite(*itr);
if (!invite || !removePlayerEvent(invite->GetInvitee(), eventId))
val = false;
}
return val;
}
bool CalendarMgr::addPlayerEvent(uint64 guid, uint64 eventId)
{
_playerEvents[guid].insert(eventId);
return true;
}
bool CalendarMgr::removePlayerEvent(uint64 guid, uint64 eventId)
{
_playerEvents[guid].erase(eventId);
return true;
}
bool CalendarMgr::addInvite(CalendarInvite const& newInvite)
{
uint64 inviteId = newInvite.GetInviteId();
if (!inviteId)
{
sLog->outError("CalendarMgr::addInvite: Cant add Invite 0");
return false;
}
if (_invites.find(inviteId) != _invites.end())
{
sLog->outError("CalendarMgr::addInvite: Invite [" UI64FMTD "] exists", inviteId);
return false;
}
_invites[inviteId] = newInvite;
uint64 guid = newInvite.GetInvitee();
bool inviteAdded = addPlayerInvite(guid, inviteId);
bool eventAdded = addPlayerEvent(guid, newInvite.GetEventId());
return eventAdded && inviteAdded;
}
uint64 CalendarMgr::removeInvite(uint64 inviteId)
{
CalendarInviteMap::iterator itr = _invites.find(inviteId);
if (itr == _invites.end())
{
sLog->outError("CalendarMgr::removeInvite: Invite [" UI64FMTD "] does not exist", inviteId);
return 0;
}
uint64 invitee = itr->second.GetInvitee();
_invites.erase(itr);
return removePlayerInvite(invitee, inviteId) ? invitee : 0;
}
bool CalendarMgr::addPlayerInvite(uint64 guid, uint64 inviteId)
{
_playerInvites[guid].insert(inviteId);
return true;
}
bool CalendarMgr::removePlayerInvite(uint64 guid, uint64 inviteId)
{
_playerInvites[guid].erase(inviteId);
return true;
}
void CalendarMgr::SendCalendarEvent(CalendarEvent const& calendarEvent, CalendarSendEventType type)
{
if (Player* player = ObjectAccessor::FindPlayer(calendarEvent.GetCreatorGUID()))
player->GetSession()->SendCalendarEvent(calendarEvent, type);
}
void CalendarMgr::SendCalendarEventInvite(CalendarInvite const& invite, bool pending)
{
if (Player* player = ObjectAccessor::FindPlayer(invite.GetSenderGUID()))
player->GetSession()->SendCalendarEventInvite(invite, pending);
}
void CalendarMgr::SendCalendarEventInviteAlert(CalendarEvent const& calendarEvent, CalendarInvite const& invite)
{
if (Player* player = ObjectAccessor::FindPlayer(invite.GetInvitee()))
player->GetSession()->SendCalendarEventInviteAlert(calendarEvent, invite);
}
void CalendarMgr::SendCalendarEventUpdateAlert(uint64 guid, CalendarEvent const& calendarEvent, CalendarSendEventType type)
{
if (Player* player = ObjectAccessor::FindPlayer(guid))
player->GetSession()->SendCalendarEventUpdateAlert(calendarEvent, type);
}
void CalendarMgr::SendCalendarEventStatus(uint64 guid, CalendarEvent const& calendarEvent, CalendarInvite const& invite)
{
if (Player* player = ObjectAccessor::FindPlayer(guid))
player->GetSession()->SendCalendarEventStatus(calendarEvent, invite);
}
void CalendarMgr::SendCalendarEventRemovedAlert(uint64 guid, CalendarEvent const& calendarEvent)
{
if (Player* player = ObjectAccessor::FindPlayer(guid))
player->GetSession()->SendCalendarEventRemovedAlert(calendarEvent);
}
void CalendarMgr::SendCalendarEventInviteRemoveAlert(uint64 guid, CalendarEvent const& calendarEvent, uint8 status)
{
if (Player* player = ObjectAccessor::FindPlayer(guid))
player->GetSession()->SendCalendarEventInviteRemoveAlert(calendarEvent, status);
}
void CalendarMgr::SendCalendarEventInviteRemove(uint64 guid, CalendarInvite const& invite, uint32 flags)
{
if (Player* player = ObjectAccessor::FindPlayer(guid))
player->GetSession()->SendCalendarEventInviteRemove(invite, flags);
}
void CalendarMgr::SendCalendarEventModeratorStatusAlert(CalendarInvite const& invite)
{
if (Player* player = ObjectAccessor::FindPlayer(invite.GetInvitee()))
player->GetSession()->SendCalendarEventModeratorStatusAlert(invite);
}
+50 -43
View File
@@ -1,19 +1,18 @@
/*
* Copyright (C) 2008-2012 Trinity <http://www.trinitycore.org/>
* Copyright (C) 2008-2012 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 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.
* 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
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef TRINITY_CALENDARMGR_H
@@ -21,49 +20,57 @@
#include <ace/Singleton.h>
#include "Calendar.h"
#include "Player.h"
class CalendarMgr
{
friend class ACE_Singleton<CalendarMgr, ACE_Null_Mutex>;
public:
void LoadFromDB();
public:
CalendarMgr();
~CalendarMgr();
CalendarInvite* GetInvite(uint64 inviteId);
CalendarEvent* GetEvent(uint64 eventId);
CalendarInvite const* GetInvite(uint64 inviteId)
{
CalendarInviteMap::const_iterator itr = _inviteMap.find(inviteId);
if(itr != _inviteMap.end())
return &itr->second;
return NULL;
}
CalendarinviteIdList const& GetPlayerInvites(uint64 guid);
CalendarEventIdList const& GetPlayerEvents(uint64 guid);
void AddInvite(CalendarInvite invite) { _inviteMap[invite.Id] = invite; }
void RemoveInvite(uint64 inviteId) { _inviteMap.erase(inviteId); }
uint32 GetPlayerNumPending(uint64 guid);
uint64 GetFreeEventId();
uint64 GetFreeInviteId();
CalendarEvent const* GetEvent(uint64 eventId)
{
CalendarEventMap::const_iterator itr = _eventMap.find(eventId);
if(itr != _eventMap.end())
return &itr->second;
return NULL;
}
void AddAction(CalendarAction const& action);
void AddEvent(CalendarEvent event) { _eventMap[event.Id] = event; }
void RemoveEvent(uint64 eventId) { _eventMap.erase(eventId); }
void SendCalendarEvent(CalendarEvent const& calendarEvent, CalendarSendEventType type);
void SendCalendarEventInvite(CalendarInvite const& invite, bool pending);
void SendCalendarEventInviteAlert(CalendarEvent const& calendarEvent, CalendarInvite const& invite);
void SendCalendarEventInviteRemove(uint64 guid, CalendarInvite const& invite, uint32 flags);
void SendCalendarEventInviteRemoveAlert(uint64 guid, CalendarEvent const& calendarEvent, uint8 status);
void SendCalendarEventUpdateAlert(uint64 guid, CalendarEvent const& calendarEvent, CalendarSendEventType type);
void SendCalendarEventStatus(uint64 guid, CalendarEvent const& calendarEvent, CalendarInvite const& invite);
void SendCalendarEventRemovedAlert(uint64 guid, CalendarEvent const& calendarEvent);
void SendCalendarEventModeratorStatusAlert(CalendarInvite const& invite);
void AppendInvitesToCalendarPacketForPlayer(WorldPacket& data, Player* player);
void AppendEventsToCalendarPacketForPlayer(WorldPacket& data, Player* player);
private:
CalendarMgr();
~CalendarMgr();
CalendarEvent* CheckPermisions(uint64 eventId, uint64 guid, uint64 invitateId, CalendarRanks minRank);
uint64 GetNextEventId() { return ++_currentEventId; }
uint64 GetNextInviteId() { return ++_currentInviteId; }
bool addEvent(CalendarEvent const& calendarEvent);
bool removeEvent(uint64 eventId);
bool addPlayerEvent(uint64 guid, uint64 eventId);
bool removePlayerEvent(uint64 guid, uint64 eventId);
private:
CalendarInviteMap _inviteMap;
CalendarEventMap _eventMap;
uint64 _currentEventId;
uint64 _currentInviteId;
bool addInvite(CalendarInvite const& invite);
uint64 removeInvite(uint64 inviteId);
bool addPlayerInvite(uint64 guid, uint64 inviteId);
bool removePlayerInvite(uint64 guid, uint64 inviteId);
CalendarEventMap _events;
CalendarInviteMap _invites;
CalendarPlayerinviteIdMap _playerInvites;
CalendarPlayerEventIdMap _playerEvents;
uint64 eventNum;
uint64 InviteNum;
};
#define sCalendarMgr ACE_Singleton<CalendarMgr, ACE_Null_Mutex>::instance()
File diff suppressed because it is too large Load Diff
+1 -1
View File
@@ -1236,7 +1236,7 @@ OpcodeHandler opcodeTable[NUM_MSG_TYPES] =
/*0x4B7*/ { "SMSG_CORPSE_MAP_POSITION_QUERY_RESPONSE", STATUS_NEVER, PROCESS_INPLACE, &WorldSession::Handle_ServerSide },
/*0x4B8*/ { "CMSG_UNUSED5", STATUS_LOGGEDIN, PROCESS_THREADUNSAFE, &WorldSession::Handle_NULL },
/*0x4B9*/ { "CMSG_UNUSED6", STATUS_NEVER, PROCESS_INPLACE, &WorldSession::Handle_NULL },
/*0x4BA*/ { "CMSG_CALENDAR_EVENT_SIGNUP", STATUS_NEVER, PROCESS_INPLACE, &WorldSession::Handle_NULL },
/*0x4BA*/ { "CMSG_CALENDAR_EVENT_SIGNUP", STATUS_LOGGEDIN, PROCESS_THREADUNSAFE, &WorldSession::HandleCalendarEventSignup },
/*0x4BB*/ { "SMSG_CALENDAR_CLEAR_PENDING_ACTION", STATUS_NEVER, PROCESS_INPLACE, &WorldSession::Handle_ServerSide },
/*0x4BC*/ { "SMSG_EQUIPMENT_SET_LIST", STATUS_NEVER, PROCESS_INPLACE, &WorldSession::Handle_ServerSide },
/*0x4BD*/ { "CMSG_EQUIPMENT_SET_SAVE", STATUS_LOGGEDIN, PROCESS_THREADUNSAFE, &WorldSession::HandleEquipmentSetSave },
+18 -3
View File
@@ -56,6 +56,8 @@ struct LfgProposal;
struct LfgReward;
struct LfgRoleCheck;
struct LfgUpdateData;
class CalendarEvent;
class CalendarInvite;
enum AccountDataType
{
@@ -878,9 +880,22 @@ 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 HandleCalendarEventSignup(WorldPacket& recv_data);
void SendCalendarEvent(CalendarEvent const& calendarEvent, uint8 sendEventType);
void SendCalendarEventInvite(CalendarInvite const& invite, bool pending);
void SendCalendarEventInviteAlert(CalendarEvent const& calendarEvent, CalendarInvite const& calendarInvite);
void SendCalendarEventInviteRemove(CalendarInvite const& invite, uint32 flags);
void SendCalendarEventInviteRemoveAlert(CalendarEvent const& calendarEvent, uint8 status);
void SendCalendarEventRemovedAlert(CalendarEvent const& calendarEvent);
void SendCalendarEventUpdateAlert(CalendarEvent const& calendarEvent, uint8 sendEventType);
void SendCalendarEventStatus(CalendarEvent const& calendarEvent, CalendarInvite const& invite);
void SendCalendarEventModeratorStatusAlert(CalendarInvite const& invite);
void SendCalendarClearPendingAction();
void SendCalendarRaildLockoutAdded(InstanceSave const* save);
void SendCalendarRaildLockoutRemoved(InstanceSave const* save);
void SendCalendarRaildLockoutUpdated(InstanceSave const* save);
void SendCalendarCommandResult(uint32 value);
void SendCalendarRaidLockout(InstanceSave* save, bool add);
void HandleSpellClick(WorldPacket& recv_data);
+4
View File
@@ -76,6 +76,7 @@
#include "Channel.h"
#include "WardenCheckMgr.h"
#include "Warden.h"
#include "CalendarMgr.h"
volatile bool World::m_stopEvent = false;
uint8 World::m_ExitCode = SHUTDOWN_EXIT_CODE;
@@ -1659,6 +1660,9 @@ void World::SetInitialWorldSettings()
sLog->outString("Loading SmartAI scripts...");
sSmartScriptMgr->LoadSmartAIFromDB();
sLog->outString("Loading Calendar data...");
sCalendarMgr->LoadFromDB();
///- Initialize game time and timers
sLog->outString("Initialize game time and timers");
m_gameTime = time(NULL);