Project SkyFire Core
SkyFire 5.4.8 server core API documentation
Loading...
Searching...
No Matches
CalendarHandler.cpp
Go to the documentation of this file.
1/*
2* This file is part of Project SkyFire https://www.projectskyfire.org.
3* See LICENSE.md file for Copyright information
4*/
5
6/*
7----- Opcodes Not Used yet -----
8
9SMSG_CALENDAR_EVENT_INVITE_NOTES [ packguid(Invitee), uint64(inviteId), string(Text), Boolean(Unk) ]
10?CMSG_CALENDAR_EVENT_INVITE_NOTES [ uint32(unk1), uint32(unk2), uint32(unk3), uint32(unk4), uint32(unk5) ]
11SMSG_CALENDAR_EVENT_INVITE_NOTES_ALERT [ uint64(inviteId), string(Text) ]
12SMSG_CALENDAR_RAID_LOCKOUT_UPDATED SendCalendarRaidLockoutUpdated(InstanceSave const* save)
13
14@todo
15
16Finish complains' handling - what to do with received complains and how to respond?
17Find out what to do with all "not used yet" opcodes
18Correct errors sending (event/invite not found, invites exceeded, event already passed, permissions etc.)
19Fix locked events to be displayed properly and response time shouldn't be shown for people that haven't respond yet
20Copied events should probably have a new owner
21
22*/
23
24#include "InstanceSaveMgr.h"
25#include "Log.h"
26#include "Opcodes.h"
27#include "Player.h"
28#include "SocialMgr.h"
29#include "CalendarMgr.h"
30#include "ObjectMgr.h"
31#include "ObjectAccessor.h"
32#include "DatabaseEnv.h"
33#include "GuildMgr.h"
34#include "ArenaTeamMgr.h"
35#include "WorldSession.h"
36
38{
39 uint64 guid = _player->GetGUID();
40 SF_LOG_DEBUG("network", "CMSG_CALENDAR_GET_CALENDAR [" UI64FMTD "]", guid);
41
42 time_t currTime = time(NULL);
43 uint32 counter = 0;
44 CalendarInviteStore invites = sCalendarMgr->GetPlayerInvites(guid);
45 CalendarEventStore playerEvents = sCalendarMgr->GetPlayerEvents(guid);
46 ResetTimeByMapDifficultyMap const& resets = sInstanceSaveMgr->GetResetTimeMap();
47
48 ByteBuffer lockoutInfoBuffer;
49 ByteBuffer invitesInfoBuffer;
50 ByteBuffer eventsInfoBuffer;
51 WorldPacket data(SMSG_CALENDAR_SEND_CALENDAR, 1000); // Average size if no instance
52 size_t resetPos = data.bitwpos();
53 data.WriteBits(0, 20); // Reset placeholder
54 data.WriteBits(0, 16); // Holidays -> fuck that shit... Necessary to find out when this should be sent
55 size_t lockoutPos = data.bitwpos();
56 data.WriteBits(0, 20); // Lockout placeholder
57
58 for (uint8 i = 0; i < 15; ++i)
59 {
60 Player::BoundInstancesMap boundInstances = _player->GetBoundInstances(DifficultyID(i));
61 for (Player::BoundInstancesMap::const_iterator itr = boundInstances.begin(); itr != boundInstances.end(); ++itr)
62 {
63 if (itr->second.perm)
64 {
65 InstanceSave const* save = itr->second.save;
66 ObjectGuid guid = save->GetInstanceId();
67 data.WriteBit(guid[6]);
68 data.WriteBit(guid[7]);
69 data.WriteBit(guid[2]);
70 data.WriteBit(guid[1]);
71 data.WriteBit(guid[5]);
72 data.WriteBit(guid[4]);
73 data.WriteBit(guid[0]);
74 data.WriteBit(guid[3]);
75
76 lockoutInfoBuffer << uint32(save->GetDifficulty());
77 lockoutInfoBuffer.WriteByteSeq(guid[3]);
78 lockoutInfoBuffer.WriteByteSeq(guid[0]);
79 lockoutInfoBuffer.WriteByteSeq(guid[1]);
80 lockoutInfoBuffer.WriteByteSeq(guid[5]);
81 lockoutInfoBuffer << uint32(save->GetResetTime() - currTime);
82 lockoutInfoBuffer << uint32(save->GetMapId());
83 lockoutInfoBuffer.WriteByteSeq(guid[2]);
84 lockoutInfoBuffer.WriteByteSeq(guid[7]);
85 lockoutInfoBuffer.WriteByteSeq(guid[6]);
86 lockoutInfoBuffer.WriteByteSeq(guid[4]);
87
88 ++counter;
89 }
90 }
91 }
92
93 data.WriteBits(invites.size(), 19);
94 for (CalendarInviteStore::const_iterator itr = invites.begin(); itr != invites.end(); ++itr)
95 {
96 CalendarEvent* calendarEvent = sCalendarMgr->GetEvent((*itr)->GetEventId());
97 ObjectGuid guid = (*itr)->GetSenderGUID();
98 data.WriteBit(guid[1]);
99 data.WriteBit(guid[2]);
100 data.WriteBit(guid[6]);
101 data.WriteBit(guid[7]);
102 data.WriteBit(guid[3]);
103 data.WriteBit(guid[0]);
104 data.WriteBit(guid[4]);
105 data.WriteBit(guid[5]);
106
107 invitesInfoBuffer.WriteByteSeq(guid[2]);
108 invitesInfoBuffer << uint64((*itr)->GetInviteId());
109 invitesInfoBuffer << uint8((*itr)->GetStatus());
110 invitesInfoBuffer.WriteByteSeq(guid[6]);
111 invitesInfoBuffer.WriteByteSeq(guid[3]);
112 invitesInfoBuffer.WriteByteSeq(guid[4]);
113 invitesInfoBuffer.WriteByteSeq(guid[1]);
114 invitesInfoBuffer.WriteByteSeq(guid[0]);
115 invitesInfoBuffer << uint64((*itr)->GetEventId());
116 invitesInfoBuffer.WriteByteSeq(guid[7]);
117 invitesInfoBuffer.WriteByteSeq(guid[5]);
118
119 invitesInfoBuffer << uint8((*itr)->GetRank());
120 invitesInfoBuffer << uint8((calendarEvent && calendarEvent->IsGuildEvent() && calendarEvent->GetGuildId() == _player->GetGuildId()) ? 1 : 0);
121 }
122
123 data.WriteBits(playerEvents.size(), 19);
124 for (CalendarEventStore::const_iterator itr = playerEvents.begin(); itr != playerEvents.end(); ++itr)
125 {
126 CalendarEvent* calendarEvent = *itr;
127 Guild* guild = sGuildMgr->GetGuildById(calendarEvent->GetGuildId());
128 ObjectGuid guildGuid = guild ? guild->GetGUID() : 0;
129 ObjectGuid creatorGuid = calendarEvent->GetCreatorGUID();
130
131 data.WriteBit(creatorGuid[2]);
132 data.WriteBit(guildGuid[1]);
133 data.WriteBit(guildGuid[7]);
134 data.WriteBit(creatorGuid[4]);
135 data.WriteBit(guildGuid[5]);
136 data.WriteBit(guildGuid[6]);
137 data.WriteBit(guildGuid[3]);
138 data.WriteBit(guildGuid[4]);
139 data.WriteBit(creatorGuid[7]);
140 data.WriteBits(calendarEvent->GetTitle().size(), 8);
141 data.WriteBit(creatorGuid[1]);
142 data.WriteBit(guildGuid[2]);
143 data.WriteBit(guildGuid[0]);
144 data.WriteBit(creatorGuid[0]);
145 data.WriteBit(creatorGuid[3]);
146 data.WriteBit(creatorGuid[6]);
147 data.WriteBit(creatorGuid[5]);
148
149 eventsInfoBuffer.WriteByteSeq(creatorGuid[5]);
150 eventsInfoBuffer.WriteByteSeq(guildGuid[3]);
151 eventsInfoBuffer.WriteString(calendarEvent->GetTitle());
152 eventsInfoBuffer.WriteByteSeq(guildGuid[7]);
153 eventsInfoBuffer << int32(calendarEvent->GetDungeonId());
154 eventsInfoBuffer.WriteByteSeq(creatorGuid[0]);
155 eventsInfoBuffer.WriteByteSeq(creatorGuid[4]);
156 eventsInfoBuffer.WriteByteSeq(guildGuid[2]);
157 eventsInfoBuffer.WriteByteSeq(creatorGuid[7]);
158 eventsInfoBuffer.WriteByteSeq(creatorGuid[2]);
159 eventsInfoBuffer.AppendPackedTime(calendarEvent->GetEventTime());
160 eventsInfoBuffer.WriteByteSeq(creatorGuid[3]);
161 eventsInfoBuffer.WriteByteSeq(creatorGuid[1]);
162 eventsInfoBuffer.WriteByteSeq(guildGuid[6]);
163 eventsInfoBuffer.WriteByteSeq(guildGuid[1]);
164 eventsInfoBuffer.WriteByteSeq(creatorGuid[6]);
165 eventsInfoBuffer << uint32(calendarEvent->GetFlags());
166 eventsInfoBuffer.WriteByteSeq(guildGuid[4]);
167 eventsInfoBuffer.WriteByteSeq(guildGuid[5]);
168 eventsInfoBuffer.WriteByteSeq(guildGuid[0]);
169 eventsInfoBuffer << uint64(calendarEvent->GetEventId());
170 eventsInfoBuffer << uint8(calendarEvent->GetType());
171 }
172
173 data.FlushBits();
174 data.PutBits(lockoutPos, counter, 20);
175 data.append(eventsInfoBuffer);
176 data.append(lockoutInfoBuffer);
177 data.append(invitesInfoBuffer);
178 data.AppendPackedTime(currTime); // zone time
179
180 counter = 0;
181 std::set<uint32> sentMaps;
182 for (ResetTimeByMapDifficultyMap::const_iterator itr = resets.begin(); itr != resets.end(); ++itr)
183 {
184 uint32 mapId = PAIR32_LOPART(itr->first);
185 if (sentMaps.find(mapId) != sentMaps.end())
186 continue;
187
188 MapEntry const* mapEntry = sMapStore.LookupEntry(mapId);
189 if (!mapEntry || !mapEntry->IsRaid())
190 continue;
191
192 sentMaps.insert(mapId);
193
194 data << int32(mapId);
195 data << int32(itr->second - currTime);
196 data << int32(0); // offset => found it different only once
197 counter++;
198 }
199
200 data.PutBits(resetPos, counter, 20);
201 data << uint32(1135753200); // Constant date, unk (28.12.2005 07:00)
202 data << uint32(currTime); // server time
203
204 SendPacket(&data);
205}
206
208{
209 uint64 eventId;
210 recvData >> eventId;
211
212 SF_LOG_DEBUG("network", "CMSG_CALENDAR_GET_EVENT. Player ["
213 UI64FMTD "] Event [" UI64FMTD "]", _player->GetGUID(), eventId);
214
215 if (CalendarEvent* calendarEvent = sCalendarMgr->GetEvent(eventId))
216 sCalendarMgr->SendCalendarEvent(_player->GetGUID(), *calendarEvent, CALENDAR_SENDTYPE_GET);
217 else
218 sCalendarMgr->SendCalendarCommandResult(_player->GetGUID(), CALENDAR_ERROR_EVENT_INVALID);
219}
220
222{
223 SF_LOG_DEBUG("network", "CMSG_CALENDAR_GUILD_FILTER [" UI64FMTD "]", _player->GetGUID());
224
225 uint32 minLevel;
226 uint32 maxLevel;
227 uint32 minRank;
228
229 recvData >> minLevel >> maxLevel >> minRank;
230
231 if (Guild* guild = sGuildMgr->GetGuildById(_player->GetGuildId()))
232 guild->MassInviteToEvent(this, minLevel, maxLevel, minRank);
233
234 SF_LOG_DEBUG("network", "CMSG_CALENDAR_GUILD_FILTER: Min level [%d], Max level [%d], Min rank [%d]", minLevel, maxLevel, minRank);
235}
236/*
237void WorldSession::HandleCalendarArenaTeam(WorldPacket& recvData)
238{
239 SF_LOG_DEBUG("network", "CMSG_CALENDAR_ARENA_TEAM [" UI64FMTD "]", _player->GetGUID());
240
241 uint32 arenaTeamId;
242 recvData >> arenaTeamId;
243
244 if (ArenaTeam* team = sArenaTeamMgr->GetArenaTeamById(arenaTeamId))
245 team->MassInviteToEvent(this);
246}
247*/
249{
250 uint64 guid = _player->GetGUID();
251
252 std::string title;
253 std::string description;
254 uint8 type;
255 int32 dungeonId;
256 uint32 eventPackedTime;
257 uint32 maxInvites; // always 100, necesary? Not find the way how to change it
258 uint32 flags;
259 uint32 inviteeCount;
260 uint16 descriptionLength, titleLength;
261
262 recvData >> maxInvites >> flags >> dungeonId;
263 recvData.ReadPackedTime(eventPackedTime);
264 recvData >> type;
265 inviteeCount = recvData.ReadBits(22);
266 descriptionLength = recvData.ReadBits(11);
267
268 std::list<CalendarInvitePacketInfo> calendarInviteList;
269 for (uint32 i = 0; i < inviteeCount; i++)
270 {
272 info.Guid[7] = recvData.ReadBit();
273 info.Guid[2] = recvData.ReadBit();
274 info.Guid[6] = recvData.ReadBit();
275 info.Guid[3] = recvData.ReadBit();
276 info.Guid[5] = recvData.ReadBit();
277 info.Guid[1] = recvData.ReadBit();
278 info.Guid[0] = recvData.ReadBit();
279 info.Guid[4] = recvData.ReadBit();
280 calendarInviteList.push_back(info);
281 }
282
283 titleLength = recvData.ReadBits(8);
284
285 for (std::list<CalendarInvitePacketInfo>::iterator iter = calendarInviteList.begin(); iter != calendarInviteList.end(); ++iter)
286 {
287 recvData.ReadByteSeq(iter->Guid[4]);
288 recvData.ReadByteSeq(iter->Guid[2]);
289 recvData.ReadByteSeq(iter->Guid[3]);
290 recvData.ReadByteSeq(iter->Guid[1]);
291 recvData.ReadByteSeq(iter->Guid[0]);
292 recvData.ReadByteSeq(iter->Guid[6]);
293 recvData.ReadByteSeq(iter->Guid[7]);
294 recvData >> iter->Status;
295 recvData.ReadByteSeq(iter->Guid[5]);
296 recvData >> iter->ModerationRank;
297 }
298
299 title = recvData.ReadString(titleLength);
300 description = recvData.ReadString(descriptionLength);
301
302 CalendarEvent* calendarEvent = new CalendarEvent(sCalendarMgr->GetFreeEventId(), guid, 0, CalendarEventType(type), dungeonId,
303 time_t(eventPackedTime), flags, title, description);
304
305 if (calendarEvent->IsGuildEvent() || calendarEvent->IsGuildAnnouncement())
306 if (Player* creator = ObjectAccessor::FindPlayer(guid))
307 calendarEvent->SetGuildId(creator->GetGuildId());
308
309 if (calendarEvent->IsGuildAnnouncement())
310 {
311 CalendarInvite* invite = new CalendarInvite(0, calendarEvent->GetEventId(), 0, guid, 946684800, CALENDAR_STATUS_NOT_SIGNED_UP, CALENDAR_RANK_PLAYER, "");
312 sCalendarMgr->AddInvite(calendarEvent, invite);
313 }
314 else
315 {
316 uint32 inviteCount;
317 recvData >> inviteCount;
318
319 for (uint32 i = 0; i < inviteCount; ++i)
320 {
321 uint64 invitee = 0;
322 uint8 status = 0;
323 uint8 rank = 0;
324 recvData.readPackGUID(invitee);
325 recvData >> status >> rank;
326
327 CalendarInvite* invite = new CalendarInvite(sCalendarMgr->GetFreeInviteId(), calendarEvent->GetEventId(), invitee, guid, 946684800, CalendarInviteStatus(status), CalendarModerationRank(rank), "");
328 sCalendarMgr->AddInvite(calendarEvent, invite);
329 }
330 }
331
332 sCalendarMgr->AddEvent(calendarEvent, CALENDAR_SENDTYPE_ADD);
333}
334
336{
337 uint64 guid = _player->GetGUID();
338
339 ObjectGuid eventId;
340 ObjectGuid inviteId;
341 std::string title;
342 std::string description;
343 uint8 type;
344 uint32 maxInvites;
345 int32 dungeonId;
346 uint32 eventPackedTime;
347 uint32 flags;
348 uint16 descriptionLength;
349 uint16 titleLength;
350
351 recvData >> maxInvites >> dungeonId;
352 recvData.ReadPackedTime(eventPackedTime);
353 recvData >> flags >> type;
354 eventId[4] = recvData.ReadBit();
355 eventId[5] = recvData.ReadBit();
356 eventId[2] = recvData.ReadBit();
357 inviteId[4] = recvData.ReadBit();
358 eventId[7] = recvData.ReadBit();
359 eventId[0] = recvData.ReadBit();
360 inviteId[5] = recvData.ReadBit();
361 inviteId[3] = recvData.ReadBit();
362 eventId[6] = recvData.ReadBit();
363 eventId[1] = recvData.ReadBit();
364 inviteId[6] = recvData.ReadBit();
365 inviteId[2] = recvData.ReadBit();
366 inviteId[7] = recvData.ReadBit();
367 inviteId[1] = recvData.ReadBit();
368 inviteId[0] = recvData.ReadBit();
369 descriptionLength = recvData.ReadBits(11);
370 titleLength = recvData.ReadBits(8);
371 eventId[3] = recvData.ReadBit();
372
373 recvData.ReadByteSeq(inviteId[6]);
374 recvData.ReadByteSeq(eventId[0]);
375 recvData.ReadByteSeq(inviteId[7]);
376 recvData.ReadByteSeq(inviteId[3]);
377 recvData.ReadByteSeq(eventId[6]);
378 recvData.ReadByteSeq(inviteId[1]);
379 recvData.ReadByteSeq(eventId[2]);
380 title = recvData.ReadString(titleLength);
381 recvData.ReadByteSeq(inviteId[5]);
382 recvData.ReadByteSeq(inviteId[4]);
383 recvData.ReadByteSeq(eventId[5]);
384 recvData.ReadByteSeq(eventId[3]);
385 recvData.ReadByteSeq(inviteId[0]);
386 recvData.ReadByteSeq(eventId[4]);
387 description = recvData.ReadString(descriptionLength);
388 recvData.ReadByteSeq(eventId[1]);
389 recvData.ReadByteSeq(inviteId[2]);
390 recvData.ReadByteSeq(eventId[7]);
391
392 SF_LOG_DEBUG("network", "CMSG_CALENDAR_UPDATE_EVENT [" UI64FMTD "] EventId [" UI64FMTD
393 "], InviteId [" UI64FMTD "] Title %s, Description %s, type %u "
394 "MaxInvites %u, Dungeon ID %d, Time %u, Flags %u",
395 guid, (uint64)eventId, (uint64)inviteId, title.c_str(),
396 description.c_str(), type, maxInvites, dungeonId,
397 eventPackedTime, flags);
398
399 if (CalendarEvent* calendarEvent = sCalendarMgr->GetEvent(eventId))
400 {
401 calendarEvent->SetType(CalendarEventType(type));
402 calendarEvent->SetFlags(flags);
403 calendarEvent->SetEventTime(time_t(eventPackedTime));
404 calendarEvent->SetDungeonId(dungeonId);
405 calendarEvent->SetTitle(title);
406 calendarEvent->SetDescription(description);
407
408 sCalendarMgr->UpdateEvent(calendarEvent);
409 sCalendarMgr->SendCalendarEventUpdateAlert(*calendarEvent, calendarEvent->GetEventTime());
410 }
411 else
412 sCalendarMgr->SendCalendarCommandResult(guid, CALENDAR_ERROR_EVENT_INVALID);
413}
414
416{
417 uint64 guid = _player->GetGUID();
418 recvData.read_skip<uint64>(); // Skip InviteId
419 uint64 eventId;
420
421 recvData >> eventId;
422 recvData.rfinish(); // Skip flags
423
424 sCalendarMgr->RemoveEvent(eventId, guid);
425}
426
428{
429 uint64 guid = _player->GetGUID();
430 uint64 eventId;
431 uint64 inviteId;
432 uint32 time;
433
434 recvData >> eventId >> inviteId;
435 recvData.ReadPackedTime(time);
436 SF_LOG_DEBUG("network", "CMSG_CALENDAR_COPY_EVENT [" UI64FMTD "], EventId [" UI64FMTD
437 "] inviteId [" UI64FMTD "] Time: %u", guid, eventId, inviteId, time);
438
439 if (CalendarEvent* oldEvent = sCalendarMgr->GetEvent(eventId))
440 {
441 CalendarEvent* newEvent = new CalendarEvent(*oldEvent, sCalendarMgr->GetFreeEventId(), guid);
442 newEvent->SetEventTime(time_t(time));
443 CalendarInviteStore invites = sCalendarMgr->GetEventInvites(eventId);
444
445 for (CalendarInviteStore::const_iterator itr = invites.begin(); itr != invites.end(); ++itr)
446 sCalendarMgr->AddInvite(newEvent, new CalendarInvite(**itr, sCalendarMgr->GetFreeInviteId(), newEvent->GetEventId(), guid), false);
447
448 sCalendarMgr->AddEvent(newEvent, CALENDAR_SENDTYPE_COPY);
449 }
450 else
451 sCalendarMgr->SendCalendarCommandResult(guid, CALENDAR_ERROR_EVENT_INVALID);
452}
453
455{
456 SF_LOG_DEBUG("network", "CMSG_CALENDAR_EVENT_INVITE");
457
458 uint64 playerGuid = _player->GetGUID();
459
460 uint64 eventId;
461 uint64 inviteId;
462 std::string name;
463 uint16 length;
464 bool isPreInvite;
465 bool isGuildEvent;
466
467 uint64 inviteeGuid = 0;
468 uint32 inviteeTeam = 0;
469 uint32 inviteeGuildId = 0;
470
471 recvData >> eventId >> inviteId;
472 isPreInvite = recvData.ReadBit();
473 length = recvData.ReadBits(9);
474 isGuildEvent = recvData.ReadBit();
475 name = recvData.ReadString(length);
476
477 Player* player = sObjectAccessor->FindPlayerByName(name.c_str());
478 if (player)
479 {
480 // Invitee is online
481 inviteeGuid = player->GetGUID();
482 inviteeTeam = player->GetTeam();
483 inviteeGuildId = player->GetGuildId();
484 }
485 else
486 {
487 // Invitee offline, get data from database
489 stmt->setString(0, name);
490 if (PreparedQueryResult result = CharacterDatabase.Query(stmt))
491 {
492 Field* fields = result->Fetch();
493 inviteeGuid = MAKE_NEW_GUID(fields[0].GetUInt32(), 0, HIGHGUID_PLAYER);
494 inviteeTeam = Player::TeamForRace(fields[1].GetUInt8());
495 inviteeGuildId = Player::GetGuildIdFromDB(inviteeGuid);
496 }
497 }
498
499 if (!inviteeGuid)
500 {
501 sCalendarMgr->SendCalendarCommandResult(playerGuid, CALENDAR_ERROR_PLAYER_NOT_FOUND);
502 return;
503 }
504
505 if (_player->GetTeam() != inviteeTeam && !sWorld->GetBoolConfig(WorldBoolConfigs::CONFIG_ALLOW_TWO_SIDE_INTERACTION_CALENDAR))
506 {
507 sCalendarMgr->SendCalendarCommandResult(playerGuid, CALENDAR_ERROR_NOT_ALLIED);
508 return;
509 }
510
511 if (QueryResult result = CharacterDatabase.PQuery("SELECT flags FROM character_social WHERE guid = " UI64FMTD " AND friend = " UI64FMTD, inviteeGuid, playerGuid))
512 {
513 Field* fields = result->Fetch();
514 if (fields[0].GetUInt8() & SOCIAL_FLAG_IGNORED)
515 {
516 sCalendarMgr->SendCalendarCommandResult(playerGuid, CALENDAR_ERROR_IGNORING_YOU_S, name.c_str());
517 return;
518 }
519 }
520
521 if (!isPreInvite)
522 {
523 if (CalendarEvent* calendarEvent = sCalendarMgr->GetEvent(eventId))
524 {
525 if (calendarEvent->GetEventTime() < time(NULL))
526 {
527 sCalendarMgr->SendCalendarCommandResult(playerGuid, CALENDAR_ERROR_EVENT_PASSED);
528 return;
529 }
530
531 // we probably can invite them, but we have to send them some different info about that invite
532 if (calendarEvent->IsGuildEvent() && calendarEvent->GetGuildId() == inviteeGuildId)
533 {
534 sCalendarMgr->SendCalendarCommandResult(playerGuid, CALENDAR_ERROR_NO_GUILD_INVITES);
535 return;
536 }
537
538 CalendarInvite* invite = new CalendarInvite(sCalendarMgr->GetFreeInviteId(), eventId, inviteeGuid, playerGuid, 0, CALENDAR_STATUS_INVITED, CALENDAR_RANK_PLAYER, "");
539 sCalendarMgr->AddInvite(calendarEvent, invite, true, player && player->GetGuildId() != calendarEvent->GetGuildId());
540 }
541 else
542 sCalendarMgr->SendCalendarCommandResult(playerGuid, CALENDAR_ERROR_EVENT_INVALID);
543 }
544 else
545 {
546 // we probably can invite them, but we have to send them some different info about that invite
547 if (isGuildEvent && _player->GetGuildId() == inviteeGuildId)
548 {
549 sCalendarMgr->SendCalendarCommandResult(playerGuid, CALENDAR_ERROR_NO_GUILD_INVITES);
550 return;
551 }
552
553 CalendarInvite invite(0, 0, inviteeGuid, playerGuid, 0, CALENDAR_STATUS_INVITED, CALENDAR_RANK_PLAYER, "");
554 sCalendarMgr->SendCalendarEventInvite(invite);
555 }
556}
557
559{
560 uint64 guid = _player->GetGUID();
561 uint64 eventId;
562 bool tentative;
563
564 recvData >> eventId;
565 tentative = recvData.ReadBit();
566
567 SF_LOG_DEBUG("network", "CMSG_CALENDAR_EVENT_SIGNUP [" UI64FMTD "] EventId [" UI64FMTD "] Tentative %u", guid, eventId, tentative);
568
569 if (CalendarEvent* calendarEvent = sCalendarMgr->GetEvent(eventId))
570 {
571 if (calendarEvent->IsGuildEvent() && calendarEvent->GetGuildId() != _player->GetGuildId())
572 {
573 sCalendarMgr->SendCalendarCommandResult(guid, CALENDAR_ERROR_GUILD_PLAYER_NOT_IN_GUILD);
574 return;
575 }
576
578 CalendarInvite* invite = new CalendarInvite(sCalendarMgr->GetFreeInviteId(), eventId, guid, guid, time(NULL), status, CALENDAR_RANK_PLAYER, "");
579 sCalendarMgr->AddInvite(calendarEvent, invite);
580 sCalendarMgr->SendCalendarClearPendingAction(guid);
581 }
582 else
583 sCalendarMgr->SendCalendarCommandResult(guid, CALENDAR_ERROR_EVENT_INVALID);
584}
585
587{
588 uint64 guid = _player->GetGUID();
589 uint64 eventId;
590 uint64 inviteId;
591 uint8 status;
592
593 recvData >> eventId >> inviteId >> status;
594 SF_LOG_DEBUG("network", "CMSG_CALENDAR_EVENT_RSVP [" UI64FMTD "] EventId ["
595 UI64FMTD "], InviteId [" UI64FMTD "], status %u", guid, eventId,
596 inviteId, status);
597
598 if (CalendarEvent* calendarEvent = sCalendarMgr->GetEvent(eventId))
599 {
600 // i think we still should be able to remove self from locked events
601 if (status != CALENDAR_STATUS_REMOVED && calendarEvent->GetFlags() & CALENDAR_FLAG_INVITES_LOCKED)
602 {
603 sCalendarMgr->SendCalendarCommandResult(guid, CALENDAR_ERROR_EVENT_LOCKED);
604 return;
605 }
606
607 if (CalendarInvite* invite = sCalendarMgr->GetInvite(inviteId))
608 {
609 invite->SetStatus(CalendarInviteStatus(status));
610 invite->SetStatusTime(time(NULL));
611
612 sCalendarMgr->UpdateInvite(invite);
613 sCalendarMgr->SendCalendarEventStatus(*calendarEvent, *invite);
614 sCalendarMgr->SendCalendarEventStatusAlert(*calendarEvent, *invite);
615 sCalendarMgr->SendCalendarClearPendingAction(guid);
616 }
617 else
618 sCalendarMgr->SendCalendarCommandResult(guid, CALENDAR_ERROR_NO_INVITE); // correct?
619 }
620 else
621 sCalendarMgr->SendCalendarCommandResult(guid, CALENDAR_ERROR_EVENT_INVALID);
622}
623
625{
626 uint64 guid = _player->GetGUID();
627 ObjectGuid invitee;
628 uint64 eventId;
629 uint64 senderId;
630 uint64 inviteId;
631
632 recvData >> inviteId >> senderId >> eventId;
633
634 recvData.ReadGuidMask(invitee, 6, 3, 2, 4, 5, 7, 0, 1);
635 recvData.ReadGuidBytes(invitee, 0, 4, 7, 3, 5, 1, 2, 6);
636
637 SF_LOG_DEBUG("network", "CMSG_CALENDAR_EVENT_REMOVE_INVITE ["
638 UI64FMTD "] EventId [" UI64FMTD "], senderId ["
639 UI64FMTD "], Invitee ([" UI64FMTD "] id: [" UI64FMTD "])",
640 guid, eventId, senderId, (uint64)invitee, inviteId);
641
642 if (CalendarEvent* calendarEvent = sCalendarMgr->GetEvent(eventId))
643 {
644 if (calendarEvent->GetCreatorGUID() == invitee)
645 {
646 sCalendarMgr->SendCalendarCommandResult(guid, CALENDAR_ERROR_DELETE_CREATOR_FAILED);
647 return;
648 }
649
650 sCalendarMgr->RemoveInvite(inviteId, eventId, guid);
651 }
652 else
653 sCalendarMgr->SendCalendarCommandResult(guid, CALENDAR_ERROR_NO_INVITE);
654}
655
657{
658 uint64 guid = _player->GetGUID();
659 ObjectGuid invitee;
660 uint64 eventId;
661 uint64 inviteId;
662 uint64 senderId;
663 uint8 status;
664
665 recvData >> senderId >> eventId >> inviteId >> status;
666
667 recvData.ReadGuidMask(invitee, 4, 3, 7, 6, 2, 0, 5, 1);
668 recvData.ReadGuidBytes(invitee, 7, 5, 2, 1, 4, 6, 0, 3);
669
670 SF_LOG_DEBUG("network", "CMSG_CALENDAR_EVENT_STATUS [" UI64FMTD"] EventId ["
671 UI64FMTD "] senderId [" UI64FMTD "], Invitee ([" UI64FMTD "] id: ["
672 UI64FMTD "], status %u", guid, eventId, senderId, (uint64)invitee, inviteId, status);
673
674 if (CalendarEvent* calendarEvent = sCalendarMgr->GetEvent(eventId))
675 {
676 if (CalendarInvite* invite = sCalendarMgr->GetInvite(inviteId))
677 {
678 invite->SetStatus((CalendarInviteStatus)status);
679
680 sCalendarMgr->UpdateInvite(invite);
681 sCalendarMgr->SendCalendarEventStatus(*calendarEvent, *invite);
682 sCalendarMgr->SendCalendarEventStatusAlert(*calendarEvent, *invite);
683 sCalendarMgr->SendCalendarClearPendingAction(invitee);
684 }
685 else
686 sCalendarMgr->SendCalendarCommandResult(guid, CALENDAR_ERROR_NO_INVITE); // correct?
687 }
688 else
689 sCalendarMgr->SendCalendarCommandResult(guid, CALENDAR_ERROR_EVENT_INVALID);
690}
691
693{
694 uint64 guid = _player->GetGUID();
695 ObjectGuid invitee;
696 uint64 eventId;
697 uint64 inviteId;
698 uint64 senderId;
699 uint8 rank;
700
701 recvData >> rank >> eventId >> senderId >> inviteId;
702
703 recvData.ReadGuidMask(invitee, 6, 5, 1, 3, 4, 7, 0, 2);
704 recvData.ReadGuidBytes(invitee, 7, 5, 0, 4, 1, 3, 2, 6);
705
706 SF_LOG_DEBUG("network", "CMSG_CALENDAR_EVENT_MODERATOR_STATUS [" UI64FMTD "] EventId ["
707 UI64FMTD "] senderId [" UI64FMTD "], Invitee ([" UI64FMTD "] id: ["
708 UI64FMTD "], rank %u", guid, eventId, senderId, (uint64)invitee, inviteId, rank);
709
710 if (CalendarEvent* calendarEvent = sCalendarMgr->GetEvent(eventId))
711 {
712 if (calendarEvent->IsGuildEvent())
713 {
714 sCalendarMgr->SendCalendarCommandResult(guid, CALENDAR_ERROR_NO_MODERATOR);
715 return;
716 }
717
718 if (CalendarInvite* invite = sCalendarMgr->GetInvite(inviteId))
719 {
720 invite->SetRank(CalendarModerationRank(rank));
721 sCalendarMgr->UpdateInvite(invite);
722 sCalendarMgr->SendCalendarEventModeratorStatus(*calendarEvent, *invite);
723 }
724 else
725 sCalendarMgr->SendCalendarCommandResult(guid, CALENDAR_ERROR_NO_INVITE); // correct?
726 }
727 else
728 sCalendarMgr->SendCalendarCommandResult(guid, CALENDAR_ERROR_EVENT_INVALID);
729}
730
732{
733 uint64 guid = _player->GetGUID();
734 uint64 eventId;
735 ObjectGuid complainGUID;
736 uint64 inviteId;
737
738 recvData >> inviteId >> eventId;
739 recvData.ReadGuidMask(complainGUID, 4, 6, 2, 7, 1, 5, 3, 0);
740 recvData.ReadGuidBytes(complainGUID, 6, 7, 1, 0, 4, 2, 3, 5);
741
742 SF_LOG_DEBUG("network", "CMSG_CALENDAR_COMPLAIN [" UI64FMTD "] EventId ["
743 UI64FMTD "] guid [" UI64FMTD "] InviteId [" UI64FMTD "]", guid, eventId, (uint64)complainGUID, inviteId);
744
745 // what to do with complains?
746}
747
749{
750 uint64 guid = _player->GetGUID();
751 uint32 pending = sCalendarMgr->GetPlayerNumPending(guid);
752
753 SF_LOG_DEBUG("network", "CMSG_CALENDAR_GET_NUM_PENDING: [" UI64FMTD
754 "] Pending: %u", guid, pending);
755
757 data << uint32(pending);
758 SendPacket(&data);
759}
760
762{
763 uint32 mapId, difficulty;
764 uint8 toggleExtend;
765 recvData >> mapId >> difficulty >> toggleExtend;
766 SF_LOG_DEBUG("network", "CMSG_SET_SAVED_INSTANCE_EXTEND - MapId: %u, DifficultyID: %u, ToggleExtend: %s", mapId, difficulty, toggleExtend ? "On" : "Off");
767
768 /*
769 InstancePlayerBind* instanceBind = _player->GetBoundInstance(mapId, Difficulty(difficulty));
770 if (!instanceBind || !instanceBind->save)
771 return;
772
773 InstanceSave* save = instanceBind->save;
774 // http://www.wowwiki.com/Instance_Lock_Extension
775 // SendCalendarRaidLockoutUpdated(save);
776 */
777}
778
779// ----------------------------------- SEND ------------------------------------
780
782{
783 SF_LOG_DEBUG("network", "%s", add ? "SMSG_CALENDAR_RAID_LOCKOUT_ADDED" : "SMSG_CALENDAR_RAID_LOCKOUT_REMOVED");
784 time_t currTime = time(NULL);
785
786 ObjectGuid guid = save->GetInstanceId();
787 if (add)
788 {
789 WorldPacket data(SMSG_CALENDAR_RAID_LOCKOUT_ADDED, 4 + 4 + 4 + 4 + 8);
790 data.WriteBit(guid[3]);
791 data.WriteBit(guid[1]);
792 data.WriteBit(guid[2]);
793 data.WriteBit(guid[0]);
794 data.WriteBit(guid[4]);
795 data.WriteBit(guid[7]);
796 data.WriteBit(guid[5]);
797 data.WriteBit(guid[6]);
798 data.FlushBits();
799
800 data.WriteByteSeq(guid[6]);
801 data << uint32(save->GetDifficulty());
802 data.WriteByteSeq(guid[0]);
803 data.WriteByteSeq(guid[4]);
804 data.WriteByteSeq(guid[5]);
805 data.WriteByteSeq(guid[3]);
806 data.WriteByteSeq(guid[2]);
807 data << uint32(save->GetMapId());
808 data.WriteByteSeq(guid[1]);
809 data.AppendPackedTime(currTime);
810 data << uint32(save->GetResetTime() - currTime);
811 data.WriteByteSeq(guid[7]);
812
813 SendPacket(&data);
814 }
815 else
816 {
818 data << uint32(save->GetDifficulty());
819 data << uint32(save->GetMapId());
820
821 data.WriteBit(guid[2]);
822 data.WriteBit(guid[0]);
823 data.WriteBit(guid[4]);
824 data.WriteBit(guid[6]);
825 data.WriteBit(guid[5]);
826 data.WriteBit(guid[7]);
827 data.WriteBit(guid[3]);
828 data.WriteBit(guid[1]);
829 data.FlushBits();
830
831 data.WriteByteSeq(guid[6]);
832 data.WriteByteSeq(guid[1]);
833 data.WriteByteSeq(guid[7]);
834 data.WriteByteSeq(guid[3]);
835 data.WriteByteSeq(guid[4]);
836 data.WriteByteSeq(guid[5]);
837 data.WriteByteSeq(guid[0]);
838 data.WriteByteSeq(guid[2]);
839
840 SendPacket(&data);
841 }
842}
843
845{
846 if (!save)
847 return;
848
849 uint64 guid = _player->GetGUID();
850 SF_LOG_DEBUG("network", "SMSG_CALENDAR_RAID_LOCKOUT_UPDATED [" UI64FMTD
851 "] Map: %u, DifficultyID %u", guid, save->GetMapId(), save->GetDifficulty());
852
853 time_t currTime = time(NULL);
854
855 WorldPacket data(SMSG_CALENDAR_RAID_LOCKOUT_UPDATED, 4 + 4 + 4 + 4 + 8);
856 data << uint32(save->GetResetTime() - currTime); // New remaining time? => found only same values as the possible old time
857 data << uint32(save->GetMapId());
858 data << uint32(save->GetDifficulty());
859 data.AppendPackedTime(currTime);
860 data << uint32(save->GetResetTime() - currTime); // Old remaining time? => found only same values as the possible new time
861 SendPacket(&data);
862}
std::set< CalendarEvent * > CalendarEventStore
#define sCalendarMgr
@ CALENDAR_ERROR_NO_INVITE
@ CALENDAR_ERROR_EVENT_PASSED
Definition CalendarMgr.h:96
@ CALENDAR_ERROR_EVENT_LOCKED
Definition CalendarMgr.h:97
@ CALENDAR_ERROR_NOT_ALLIED
Definition CalendarMgr.h:89
@ CALENDAR_ERROR_NO_GUILD_INVITES
@ CALENDAR_ERROR_DELETE_CREATOR_FAILED
Definition CalendarMgr.h:98
@ CALENDAR_ERROR_NO_MODERATOR
@ CALENDAR_ERROR_IGNORING_YOU_S
Definition CalendarMgr.h:90
@ CALENDAR_ERROR_PLAYER_NOT_FOUND
Definition CalendarMgr.h:88
@ CALENDAR_ERROR_EVENT_INVALID
Definition CalendarMgr.h:83
@ CALENDAR_ERROR_GUILD_PLAYER_NOT_IN_GUILD
Definition CalendarMgr.h:86
CalendarModerationRank
Definition CalendarMgr.h:30
@ CALENDAR_RANK_PLAYER
Definition CalendarMgr.h:31
@ CALENDAR_FLAG_INVITES_LOCKED
Definition CalendarMgr.h:24
std::vector< CalendarInvite * > CalendarInviteStore
@ CALENDAR_SENDTYPE_GET
Definition CalendarMgr.h:38
@ CALENDAR_SENDTYPE_COPY
Definition CalendarMgr.h:40
@ CALENDAR_SENDTYPE_ADD
Definition CalendarMgr.h:39
CalendarEventType
Definition CalendarMgr.h:44
CalendarInviteStatus
Definition CalendarMgr.h:62
@ CALENDAR_STATUS_TENTATIVE
Definition CalendarMgr.h:71
@ CALENDAR_STATUS_NOT_SIGNED_UP
Definition CalendarMgr.h:70
@ CALENDAR_STATUS_INVITED
Definition CalendarMgr.h:63
@ CALENDAR_STATUS_SIGNED_UP
Definition CalendarMgr.h:69
@ CALENDAR_STATUS_REMOVED
Definition CalendarMgr.h:72
@ CHAR_SEL_GUID_RACE_ACC_BY_NAME
DifficultyID
Definition DBCEnums.h:330
DBCStorage< MapEntry > sMapStore(MapEntryfmt)
std::int32_t int32
Definition Define.h:73
#define UI64FMTD
Definition Define.h:64
std::uint8_t uint8
Definition Define.h:79
std::uint32_t uint32
Definition Define.h:77
std::uint64_t uint64
Definition Define.h:76
std::uint16_t uint16
Definition Define.h:78
#define sGuildMgr
Definition GuildMgr.h:53
UNORDERED_MAP< uint32, time_t > ResetTimeByMapDifficultyMap
#define sInstanceSaveMgr
#define SF_LOG_DEBUG(filterType__,...)
Definition Log.h:134
#define sObjectAccessor
@ HIGHGUID_PLAYER
uint64 MAKE_NEW_GUID(uint32 l, uint32 e, uint32 h)
uint16 PAIR32_LOPART(uint32 x)
Skyfire::AutoPtr< PreparedResultSet, Skyfire::Mutex > PreparedQueryResult
Definition QueryResult.h:94
Skyfire::AutoPtr< ResultSet, Skyfire::Mutex > QueryResult
Definition QueryResult.h:48
@ SOCIAL_FLAG_IGNORED
Definition SocialMgr.h:30
bool WriteBit(uint32 bit)
Definition ByteBuffer.h:164
void read_skip()
Definition ByteBuffer.h:502
size_t bitwpos() const
Returns position of last written bit.
Definition ByteBuffer.h:492
void WriteString(std::string const &str)
Definition ByteBuffer.h:578
uint32 ReadBits(size_t bits)
Definition ByteBuffer.h:198
void ReadGuidBytes(ObjectGuid &guid, Offsets... offsets)
Definition ByteBuffer.h:256
void ReadByteSeq(uint8 &b)
Definition ByteBuffer.h:215
void append(T value)
Definition ByteBuffer.h:147
void rfinish()
Definition ByteBuffer.h:478
std::string ReadString(size_t length)
Definition ByteBuffer.h:565
void PutBits(size_t pos, T value, uint32 bitCount)
Definition ByteBuffer.h:283
void ReadGuidMask(ObjectGuid &guid, Offsets... offsets)
Definition ByteBuffer.h:240
void WriteBits(T value, size_t bits)
Definition ByteBuffer.h:192
void AppendPackedTime(time_t time)
Definition ByteBuffer.h:700
void WriteByteSeq(uint8 b)
Definition ByteBuffer.h:227
void FlushBits()
Definition ByteBuffer.h:154
void readPackGUID(uint64 &guid)
Definition ByteBuffer.h:541
uint32 ReadPackedTime()
Definition ByteBuffer.h:584
bool ReadBit()
Definition ByteBuffer.h:180
Definition Field.h:16
Definition Guild.h:324
uint64 GetGUID() const
Definition Guild.h:758
DifficultyID GetDifficulty() const
uint32 GetInstanceId() const
uint32 GetMapId() const
time_t GetResetTime() const
static Player * FindPlayer(uint64)
uint64 GetGUID() const
Definition Object.h:119
static uint32 GetGuildIdFromDB(uint64 guid)
Definition Player.cpp:8020
uint32 GetTeam() const
Definition Player.h:2527
uint32 GetGuildId() const
Definition Player.h:2291
static uint32 TeamForRace(uint8 race)
Definition Player.cpp:7072
UNORDERED_MAP< uint32, InstancePlayerBind > BoundInstancesMap
Definition Player.h:2917
void setString(const uint8 index, const std::string &value)
void HandleCalendarGetEvent(WorldPacket &recvData)
void HandleCalendarEventRsvp(WorldPacket &recvData)
void HandleCalendarGetCalendar(WorldPacket &recvData)
void HandleCalendarEventInvite(WorldPacket &recvData)
void HandleCalendarEventSignup(WorldPacket &recvData)
void HandleCalendarEventModeratorStatus(WorldPacket &recvData)
void HandleCalendarUpdateEvent(WorldPacket &recvData)
void SendCalendarRaidLockoutUpdated(InstanceSave const *save)
void HandleCalendarComplain(WorldPacket &recvData)
void HandleCalendarAddEvent(WorldPacket &recvData)
void HandleCalendarEventRemoveInvite(WorldPacket &recvData)
void SendPacket(WorldPacket const *packet, bool forced=false)
Send a packet to the client.
void SendCalendarRaidLockout(InstanceSave const *save, bool add)
Player * _player
void HandleCalendarCopyEvent(WorldPacket &recvData)
void HandleSetSavedInstanceExtend(WorldPacket &recvData)
void HandleCalendarGuildFilter(WorldPacket &recvData)
void HandleCalendarRemoveEvent(WorldPacket &recvData)
void HandleCalendarGetNumPending(WorldPacket &recvData)
void HandleCalendarEventStatus(WorldPacket &recvData)
CharacterDatabaseWorkerPool CharacterDatabase
Accessor to the character database.
Definition Main.cpp:41
@ SMSG_CALENDAR_SEND_NUM_PENDING
Definition Opcodes.h:591
@ SMSG_CALENDAR_SEND_CALENDAR
Definition Opcodes.h:589
@ SMSG_CALENDAR_RAID_LOCKOUT_ADDED
Definition Opcodes.h:586
@ SMSG_CALENDAR_RAID_LOCKOUT_UPDATED
Definition Opcodes.h:588
@ SMSG_CALENDAR_RAID_LOCKOUT_REMOVED
Definition Opcodes.h:587
#define sWorld
Definition World.h:910
@ CONFIG_ALLOW_TWO_SIDE_INTERACTION_CALENDAR
Definition World.h:96
bool IsGuildAnnouncement() const
void SetGuildId(uint32 guildId)
CalendarEventType GetType() const
bool IsGuildEvent() const
void SetEventTime(time_t eventTime)
uint64 GetEventId() const
uint64 GetCreatorGUID() const
int32 GetDungeonId() const
std::string GetTitle() const
uint32 GetGuildId() const
time_t GetEventTime() const
uint32 GetFlags() const
bool IsRaid() const