aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorShauren <shauren.trinity@gmail.com>2012-02-25 00:14:39 +0100
committerShauren <shauren.trinity@gmail.com>2012-02-25 00:14:39 +0100
commit8945d115b2bf68f440f3b0ca68bff16a38d7541c (patch)
treeeae30ded7cffc3b3afc8d58309c982c900ac3a58 /src
parent7a4d388e0467c8303137de543861b29d231e8a4f (diff)
Core/Calendar: Added some checks & error responses for calendar actions, many more to do still
Diffstat (limited to 'src')
-rwxr-xr-xsrc/server/game/Calendar/Calendar.cpp2
-rwxr-xr-xsrc/server/game/Calendar/Calendar.h12
-rw-r--r--src/server/game/Calendar/CalendarMgr.cpp81
-rw-r--r--src/server/game/Calendar/CalendarMgr.h2
-rwxr-xr-xsrc/server/game/Handlers/CalendarHandler.cpp46
5 files changed, 100 insertions, 43 deletions
diff --git a/src/server/game/Calendar/Calendar.cpp b/src/server/game/Calendar/Calendar.cpp
index 320f49e0ed4..22578ef2dcc 100755
--- a/src/server/game/Calendar/Calendar.cpp
+++ b/src/server/game/Calendar/Calendar.cpp
@@ -88,7 +88,7 @@ std::string CalendarAction::GetDebugString() const
data << "CalendarAction::"
<< " Action: " << GetAction()
- << " Guid: " << GetGUID()
+ << " Guid: " << GetPlayer()->GetGUID()
<< " Invite Id: " << GetInviteId()
<< " Extra data: " << GetExtraData()
<< " Event: " << Event.GetDebugString()
diff --git a/src/server/game/Calendar/Calendar.h b/src/server/game/Calendar/Calendar.h
index ad073ffbebf..0caf4fca0dc 100755
--- a/src/server/game/Calendar/Calendar.h
+++ b/src/server/game/Calendar/Calendar.h
@@ -19,7 +19,7 @@
#ifndef TRINITY_CALENDAR_H
#define TRINITY_CALENDAR_H
-#include "Common.h"
+#include "Errors.h"
#include <map>
enum CalendarFlags
@@ -212,17 +212,19 @@ typedef std::map<uint64, CalendarEventIdList> CalendarPlayerEventIdMap;
typedef std::map<uint64, CalendarInvite> CalendarInviteMap;
typedef std::map<uint64, CalendarEvent> CalendarEventMap;
+class Player;
+
struct CalendarAction
{
- CalendarAction(): _action(CALENDAR_ACTION_NONE), _guid(0), _inviteId(0), _data(0)
+ CalendarAction(): _action(CALENDAR_ACTION_NONE), _player(NULL), _guid(0), _inviteId(0), _data(0)
{
}
void SetAction(CalendarActionData data) { _action = data; }
CalendarActionData GetAction() const { return _action; }
- void SetGUID(uint64 guid) { _guid = guid; }
- uint64 GetGUID() const { return _guid; }
+ void SetPlayer(Player* player) { ASSERT(player); _player = player; }
+ Player* GetPlayer() const { return _player; }
void SetInviteId(uint64 id) { _inviteId = id; }
uint64 GetInviteId() const { return _inviteId; }
@@ -237,7 +239,7 @@ struct CalendarAction
private:
CalendarActionData _action;
- uint64 _guid;
+ Player* _player;
uint64 _inviteId;
uint32 _data;
};
diff --git a/src/server/game/Calendar/CalendarMgr.cpp b/src/server/game/Calendar/CalendarMgr.cpp
index e49976a48a1..aac26578c3e 100644
--- a/src/server/game/Calendar/CalendarMgr.cpp
+++ b/src/server/game/Calendar/CalendarMgr.cpp
@@ -180,17 +180,44 @@ void CalendarMgr::LoadFromDB()
*/
}
-CalendarEvent* CalendarMgr::CheckPermisions(uint64 eventId, uint64 guid, uint64 inviteId, CalendarRanks minRank)
+CalendarEvent* CalendarMgr::CheckPermisions(uint64 eventId, Player* player, 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;
+ if (!player)
+ return NULL; // CALENDAR_ERROR_INTERNAL
- return NULL;
+ CalendarEvent* calendarEvent = GetEvent(eventId);
+ if (!calendarEvent)
+ {
+ player->GetSession()->SendCalendarCommandResult(CALENDAR_ERROR_EVENT_INVALID);
+ return NULL;
+ }
+
+ CalendarInvite* invite = GetInvite(inviteId);
+ if (!invite)
+ {
+ player->GetSession()->SendCalendarCommandResult(CALENDAR_ERROR_NO_INVITE);
+ return NULL;
+ }
+
+ if (!calendarEvent->HasInvite(inviteId))
+ {
+ player->GetSession()->SendCalendarCommandResult(CALENDAR_ERROR_NOT_INVITED);
+ return NULL;
+ }
+
+ if (invite->GetEventId() != calendarEvent->GetEventId() || invite->GetInvitee() != player->GetGUID())
+ {
+ player->GetSession()->SendCalendarCommandResult(CALENDAR_ERROR_INTERNAL);
+ return NULL;
+ }
+
+ if (invite->GetRank() < minRank)
+ {
+ player->GetSession()->SendCalendarCommandResult(CALENDAR_ERROR_PERMISSIONS);
+ return NULL;
+ }
+
+ return calendarEvent;
}
void CalendarMgr::AddAction(CalendarAction const& action)
@@ -209,8 +236,7 @@ void CalendarMgr::AddAction(CalendarAction const& action)
case CALENDAR_ACTION_MODIFY_EVENT:
{
uint64 eventId = action.Event.GetEventId();
- CalendarEvent* calendarEvent = CheckPermisions(eventId, action.GetGUID(), action.GetInviteId(), CALENDAR_RANK_MODERATOR);
-
+ CalendarEvent* calendarEvent = CheckPermisions(eventId, action.GetPlayer(), action.GetInviteId(), CALENDAR_RANK_MODERATOR);
if (!calendarEvent)
return;
@@ -234,7 +260,7 @@ void CalendarMgr::AddAction(CalendarAction const& action)
}
case CALENDAR_ACTION_COPY_EVENT:
{
- CalendarEvent* calendarEvent = CheckPermisions(action.Event.GetEventId(), action.GetGUID(), action.GetInviteId(), CALENDAR_RANK_OWNER);
+ CalendarEvent* calendarEvent = CheckPermisions(action.Event.GetEventId(), action.GetPlayer(), action.GetInviteId(), CALENDAR_RANK_OWNER);
if (!calendarEvent)
return;
@@ -261,7 +287,7 @@ void CalendarMgr::AddAction(CalendarAction const& action)
uint64 inviteId = GetFreeInviteId();
CalendarInvite newInvite(inviteId);
newInvite.SetEventId(eventId);
- newInvite.SetSenderGUID(action.GetGUID());
+ newInvite.SetSenderGUID(action.GetPlayer()->GetGUID());
newInvite.SetInvitee(invite->GetInvitee());
newInvite.SetStatus(invite->GetStatus());
newInvite.SetStatusTime(invite->GetStatusTime());
@@ -286,8 +312,7 @@ void CalendarMgr::AddAction(CalendarAction const& action)
uint32 flags = action.Event.GetFlags();
// FIXME - Use of Flags here!
- CalendarEvent* calendarEvent = CheckPermisions(eventId, action.GetGUID(), action.GetInviteId(), CALENDAR_RANK_OWNER);
-
+ CalendarEvent* calendarEvent = CheckPermisions(eventId, action.GetPlayer(), action.GetInviteId(), CALENDAR_RANK_OWNER);
if (!calendarEvent)
return;
@@ -302,7 +327,7 @@ void CalendarMgr::AddAction(CalendarAction const& action)
case CALENDAR_ACTION_ADD_EVENT_INVITE:
{
uint64 eventId = action.Invite.GetEventId();
- CalendarEvent* calendarEvent = CheckPermisions(eventId, action.GetGUID(), action.GetInviteId(), CALENDAR_RANK_MODERATOR);
+ CalendarEvent* calendarEvent = CheckPermisions(eventId, action.GetPlayer(), action.GetInviteId(), CALENDAR_RANK_MODERATOR);
if (!calendarEvent)
return;
@@ -320,7 +345,7 @@ void CalendarMgr::AddAction(CalendarAction const& action)
{
uint64 eventId = action.Event.GetEventId();
CalendarEvent* calendarEvent = GetEvent(eventId);
- CheckPermisions(eventId, action.GetGUID(), action.GetInviteId(), CALENDAR_RANK_MODERATOR);
+ CheckPermisions(eventId, action.GetPlayer(), action.GetInviteId(), CALENDAR_RANK_MODERATOR);
if (!calendarEvent || !(calendarEvent->GetFlags() & CALENDAR_FLAG_GUILD_ONLY)
|| !calendarEvent->GetGuildId() || calendarEvent->GetGuildId() != action.GetExtraData())
@@ -332,12 +357,13 @@ void CalendarMgr::AddAction(CalendarAction const& action)
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());
+ newInvite.SetInvitee(action.GetPlayer()->GetGUID());
+ newInvite.SetSenderGUID(action.GetPlayer()->GetGUID());
if (AddInvite(newInvite))
SendCalendarEventInvite(newInvite, false);
@@ -351,7 +377,7 @@ void CalendarMgr::AddAction(CalendarAction const& action)
CalendarEvent* calendarEvent;
if (action.GetInviteId() != action.Invite.GetInviteId())
- calendarEvent = CheckPermisions(eventId, action.GetGUID(), action.GetInviteId(), CALENDAR_RANK_MODERATOR);
+ calendarEvent = CheckPermisions(eventId, action.GetPlayer(), action.GetInviteId(), CALENDAR_RANK_MODERATOR);
else
calendarEvent = GetEvent(eventId);
@@ -371,7 +397,7 @@ void CalendarMgr::AddAction(CalendarAction const& action)
CalendarEvent* calendarEvent;
if (action.GetInviteId() != action.Invite.GetInviteId())
- calendarEvent = CheckPermisions(eventId, action.GetGUID(), action.GetInviteId(), CALENDAR_RANK_OWNER);
+ calendarEvent = CheckPermisions(eventId, action.GetPlayer(), action.GetInviteId(), CALENDAR_RANK_OWNER);
else
calendarEvent = GetEvent(eventId);
@@ -388,15 +414,22 @@ void CalendarMgr::AddAction(CalendarAction const& action)
{
uint64 eventId = action.Invite.GetEventId();
uint64 inviteId = action.Invite.GetInviteId();
- CalendarEvent* calendarEvent = CheckPermisions(eventId, action.GetGUID(), action.GetInviteId(), CALENDAR_RANK_MODERATOR);
-
+ CalendarEvent* calendarEvent = CheckPermisions(eventId, action.GetPlayer(), action.GetInviteId(), CALENDAR_RANK_MODERATOR);
if (!calendarEvent)
return;
+ // already checked in CheckPermisions
+ CalendarInvite* invite = GetInvite(inviteId);
+ if (calendarEvent->GetCreatorGUID() == invite->GetInvitee())
+ {
+ action.GetPlayer()->GetSession()->SendCalendarCommandResult(CALENDAR_ERROR_DELETE_CREATOR_FAILED);
+ return;
+ }
+
if (uint64 invitee = RemoveInvite(inviteId))
{
SendCalendarEventInviteRemoveAlert(invitee, *calendarEvent, CALENDAR_STATUS_9);
- SendCalendarEventInviteRemove(action.GetGUID(), action.Invite, calendarEvent->GetFlags());
+ SendCalendarEventInviteRemove(action.GetPlayer()->GetGUID(), action.Invite, calendarEvent->GetFlags());
}
break;
}
diff --git a/src/server/game/Calendar/CalendarMgr.h b/src/server/game/Calendar/CalendarMgr.h
index 490e39ab300..0fb4362bc95 100644
--- a/src/server/game/Calendar/CalendarMgr.h
+++ b/src/server/game/Calendar/CalendarMgr.h
@@ -54,7 +54,7 @@ class CalendarMgr
void SendCalendarEventModeratorStatusAlert(CalendarInvite const& invite);
private:
- CalendarEvent* CheckPermisions(uint64 eventId, uint64 guid, uint64 invitateId, CalendarRanks minRank);
+ CalendarEvent* CheckPermisions(uint64 eventId, Player* player, uint64 inviteId, CalendarRanks minRank);
bool AddEvent(CalendarEvent const& calendarEvent);
bool RemoveEvent(uint64 eventId);
diff --git a/src/server/game/Handlers/CalendarHandler.cpp b/src/server/game/Handlers/CalendarHandler.cpp
index b5a77dd52e0..01838f815fb 100755
--- a/src/server/game/Handlers/CalendarHandler.cpp
+++ b/src/server/game/Handlers/CalendarHandler.cpp
@@ -44,6 +44,7 @@ SMSG_CALENDAR_EVENT_INVITE_STATUS_ALERT [ Structure unkown ]
#include "CalendarMgr.h"
#include "ObjectMgr.h"
#include "ObjectAccessor.h"
+#include "DatabaseEnv.h"
void WorldSession::HandleCalendarGetCalendar(WorldPacket& /*recv_data*/)
{
@@ -257,7 +258,7 @@ void WorldSession::HandleCalendarAddEvent(WorldPacket& recv_data)
CalendarAction action;
action.SetAction(CALENDAR_ACTION_ADD_EVENT);
- action.SetGUID(guid);
+ action.SetPlayer(_player);
action.Event.SetEventId(sCalendarMgr->GetFreeEventId());
action.Event.SetCreatorGUID(guid);
action.Event.SetType(type);
@@ -309,7 +310,7 @@ void WorldSession::HandleCalendarUpdateEvent(WorldPacket& recv_data)
CalendarAction action;
action.SetAction(CALENDAR_ACTION_MODIFY_EVENT);
- action.SetGUID(guid);
+ action.SetPlayer(_player);
action.SetInviteId(inviteId);
action.Event.SetEventId(eventId);
action.Event.SetType(type);
@@ -338,7 +339,7 @@ void WorldSession::HandleCalendarRemoveEvent(WorldPacket& recv_data)
CalendarAction action;
action.SetAction(CALENDAR_ACTION_REMOVE_EVENT);
- action.SetGUID(guid);
+ action.SetPlayer(_player);
action.SetInviteId(inviteId);
action.Event.SetEventId(eventId);
action.Event.SetFlags(flags);
@@ -359,7 +360,7 @@ void WorldSession::HandleCalendarCopyEvent(WorldPacket& recv_data)
CalendarAction action;
action.SetAction(CALENDAR_ACTION_COPY_EVENT);
- action.SetGUID(guid);
+ action.SetPlayer(_player);
action.SetInviteId(inviteId);
action.Event.SetEventId(eventId);
action.Event.SetTime(time);
@@ -375,13 +376,26 @@ void WorldSession::HandleCalendarEventInvite(WorldPacket& recv_data)
std::string name;
uint8 status;
uint8 rank;
+ uint64 invitee = 0;
+ uint32 team = 0;
recv_data >> eventId >> inviteId >> name >> status >> rank;
- uint64 invitee = 0;
if (Player* player = sObjectAccessor->FindPlayerByName(name.c_str()))
+ {
invitee = player->GetGUID();
+ team = player->GetTeam();
+ }
else
- invitee = sObjectMgr->GetPlayerGUIDByName(name.c_str());
+ {
+ PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_GUID_RACE_ACC_BY_NAME);
+ stmt->setString(0, name);
+ if (PreparedQueryResult result = CharacterDatabase.Query(stmt))
+ {
+ Field* fields = result->Fetch();
+ invitee = MAKE_NEW_GUID(fields[0].GetUInt32(), 0, HIGHGUID_PLAYER);
+ team = Player::TeamForRace(fields[1].GetUInt8());
+ }
+ }
sLog->outDebug(LOG_FILTER_NETWORKIO, "CMSG_CALENDAR_EVENT_INVITE [" UI64FMTD "], EventId ["
UI64FMTD "] InviteId [" UI64FMTD "] Name %s ([" UI64FMTD "]), status %u, "
@@ -393,9 +407,17 @@ void WorldSession::HandleCalendarEventInvite(WorldPacket& recv_data)
return;
}
+ if (_player->GetTeam() != team)
+ {
+ SendCalendarCommandResult(CALENDAR_ERROR_NOT_ALLIED);
+ return;
+ }
+
+ // TODO: Check ignore, even if offline (db query)
+
CalendarAction action;
action.SetAction(CALENDAR_ACTION_ADD_EVENT_INVITE);
- action.SetGUID(guid);
+ action.SetPlayer(_player);
action.SetInviteId(inviteId);
action.Invite.SetEventId(eventId);
action.Invite.SetInviteId(sCalendarMgr->GetFreeInviteId());
@@ -419,7 +441,7 @@ void WorldSession::HandleCalendarEventSignup(WorldPacket& recv_data)
CalendarAction action;
action.SetAction(CALENDAR_ACTION_SIGNUP_TO_EVENT);
- action.SetGUID(guid);
+ action.SetPlayer(_player);
action.SetExtraData(GetPlayer()->GetGuildId());
action.Event.SetEventId(eventId);
action.Invite.SetStatus(status);
@@ -440,7 +462,7 @@ void WorldSession::HandleCalendarEventRsvp(WorldPacket& recv_data)
CalendarAction action;
action.SetAction(CALENDAR_ACTION_MODIFY_EVENT_INVITE);
- action.SetGUID(guid);
+ action.SetPlayer(_player);
action.SetInviteId(inviteId);
action.Invite.SetInviteId(inviteId);
action.Invite.SetEventId(eventId);
@@ -467,7 +489,7 @@ void WorldSession::HandleCalendarEventRemoveInvite(WorldPacket& recv_data)
CalendarAction action;
action.SetAction(CALENDAR_ACTION_REMOVE_EVENT_INVITE);
- action.SetGUID(guid);
+ action.SetPlayer(_player);
action.SetInviteId(owninviteId);
action.Invite.SetInviteId(inviteId);
action.Invite.SetEventId(eventId);
@@ -493,7 +515,7 @@ void WorldSession::HandleCalendarEventStatus(WorldPacket& recv_data)
CalendarAction action;
action.SetAction(CALENDAR_ACTION_MODIFY_EVENT_INVITE);
- action.SetGUID(guid);
+ action.SetPlayer(_player);
action.SetInviteId(owninviteId);
action.Invite.SetInviteId(inviteId);
action.Invite.SetEventId(eventId);
@@ -520,7 +542,7 @@ void WorldSession::HandleCalendarEventModeratorStatus(WorldPacket& recv_data)
CalendarAction action;
action.SetAction(CALENDAR_ACTION_MODIFY_MODERATOR_EVENT_INVITE);
- action.SetGUID(guid);
+ action.SetPlayer(_player);
action.SetInviteId(owninviteId);
action.Invite.SetInviteId(inviteId);
action.Invite.SetEventId(eventId);