Project SkyFire Core
SkyFire 5.4.8 server core API documentation
Loading...
Searching...
No Matches
CalendarMgr.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#include "CalendarMgr.h"
7#include "DatabaseEnv.h"
8#include "GuildMgr.h"
9#include "Log.h"
10#include "ObjectAccessor.h"
11#include "Opcodes.h"
12#include "Player.h"
13#include "QueryResult.h"
14
20
25
27{
28 for (CalendarEventStore::iterator itr = _events.begin(); itr != _events.end(); ++itr)
29 delete* itr;
30
31 for (CalendarEventInviteStore::iterator itr = _invites.begin(); itr != _invites.end(); ++itr)
32 for (CalendarInviteStore::iterator itr2 = itr->second.begin(); itr2 != itr->second.end(); ++itr2)
33 delete* itr2;
34}
35
37{
38 uint32 count = 0;
39 // 0 1 2 3 4 5 6 7
40 if (QueryResult result = CharacterDatabase.Query("SELECT id, creator, title, description, type, dungeon, eventtime, flags FROM calendar_events"))
41 do
42 {
43 Field* fields = result->Fetch();
44
45 uint64 eventId = fields[0].GetUInt64();
46 uint64 creatorGUID = MAKE_NEW_GUID(fields[1].GetUInt32(), 0, HIGHGUID_PLAYER);
47 std::string title = fields[2].GetString();
48 std::string description = fields[3].GetString();
49 CalendarEventType type = CalendarEventType(fields[4].GetUInt8());
50 int32 dungeonId = fields[5].GetInt32();
51 uint32 eventTime = fields[6].GetUInt32();
52 uint32 flags = fields[7].GetUInt32();
53 uint32 guildId = 0;
54
56 guildId = Player::GetGuildIdFromDB(creatorGUID);
57
58 CalendarEvent* calendarEvent = new CalendarEvent(eventId, creatorGUID, guildId, type, dungeonId, time_t(eventTime), flags, title, description);
59 _events.insert(calendarEvent);
60
61 _maxEventId = std::max(_maxEventId, eventId);
62
63 ++count;
64 } while (result->NextRow());
65
66 SF_LOG_INFO("server.loading", ">> Loaded %u calendar events", count);
67 count = 0;
68
69 // 0 1 2 3 4 5 6 7
70 if (QueryResult result = CharacterDatabase.Query("SELECT id, event, invitee, sender, status, statustime, mod_rank, text FROM calendar_invites"))
71 do
72 {
73 Field* fields = result->Fetch();
74
75 uint64 inviteId = fields[0].GetUInt64();
76 uint64 eventId = fields[1].GetUInt64();
77 uint64 invitee = MAKE_NEW_GUID(fields[2].GetUInt32(), 0, HIGHGUID_PLAYER);
78 uint64 senderGUID = MAKE_NEW_GUID(fields[3].GetUInt32(), 0, HIGHGUID_PLAYER);
79 CalendarInviteStatus status = CalendarInviteStatus(fields[4].GetUInt8());
80 uint32 statusTime = fields[5].GetUInt32();
81 CalendarModerationRank rank = CalendarModerationRank(fields[6].GetUInt8());
82 std::string text = fields[7].GetString();
83
84 CalendarInvite* invite = new CalendarInvite(inviteId, eventId, invitee, senderGUID, time_t(statusTime), status, rank, text);
85 _invites[eventId].push_back(invite);
86
87 _maxInviteId = std::max(_maxInviteId, inviteId);
88
89 ++count;
90 } while (result->NextRow());
91
92 SF_LOG_INFO("server.loading", ">> Loaded %u calendar invites", count);
93
94 for (uint64 i = 1; i < _maxEventId; ++i)
95 if (!GetEvent(i))
96 _freeEventIds.push_back(i);
97
98 for (uint64 i = 1; i < _maxInviteId; ++i)
99 if (!GetInvite(i))
100 _freeInviteIds.push_back(i);
101}
102
104{
105 _events.insert(calendarEvent);
106 UpdateEvent(calendarEvent);
107 SendCalendarEvent(calendarEvent->GetCreatorGUID(), *calendarEvent, sendType);
108}
109
110void CalendarMgr::AddInvite(CalendarEvent* calendarEvent, CalendarInvite* invite, bool sendEventInvitePacket /*= true*/, bool forceEventInviteAlertPacket /*= false*/)
111{
112 if (sendEventInvitePacket)
114
115 if (!calendarEvent->IsGuildEvent() || forceEventInviteAlertPacket)
116 SendCalendarEventInviteAlert(*calendarEvent, *invite, (calendarEvent->IsGuildEvent() && calendarEvent->GetCreatorGUID() == invite->GetInviteeGUID()) || calendarEvent->IsGuildAnnouncement());
117
118 if (!calendarEvent->IsGuildAnnouncement())
119 {
120 _invites[invite->GetEventId()].push_back(invite);
121 UpdateInvite(invite);
122 }
123}
124
126{
127 CalendarEvent* calendarEvent = GetEvent(eventId);
128
129 if (!calendarEvent)
130 {
132 return;
133 }
134
135 SendCalendarEventRemovedAlert(*calendarEvent);
136
137 SQLTransaction trans = CharacterDatabase.BeginTransaction();
138 PreparedStatement* stmt;
139 MailDraft mail(calendarEvent->BuildCalendarMailSubject(remover), calendarEvent->BuildCalendarMailBody());
140
141 CalendarInviteStore& eventInvites = _invites[eventId];
142 for (size_t i = 0; i < eventInvites.size(); ++i)
143 {
144 CalendarInvite* invite = eventInvites[i];
145 stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_CALENDAR_INVITE);
146 stmt->setUInt64(0, invite->GetInviteId());
147 trans->Append(stmt);
148
149 // guild events only? check invite status here?
150 // When an event is deleted, all invited (accepted/declined? - verify) guildies are notified via in-game mail. (wowwiki)
151 if (remover && invite->GetInviteeGUID() != remover)
152 mail.SendMailTo(trans, MailReceiver(invite->GetInviteeGUID()), calendarEvent, MAIL_CHECK_MASK_COPIED);
153
154 delete invite;
155 }
156
157 _invites.erase(eventId);
158
159 stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_CALENDAR_EVENT);
160 stmt->setUInt64(0, eventId);
161 trans->Append(stmt);
162 CharacterDatabase.CommitTransaction(trans);
163
164 _events.erase(calendarEvent);
165 delete calendarEvent;
166}
167
168void CalendarMgr::RemoveInvite(uint64 inviteId, uint64 eventId, uint64 /*remover*/)
169{
170 CalendarEvent* calendarEvent = GetEvent(eventId);
171
172 if (!calendarEvent)
173 return;
174
175 CalendarInviteStore::iterator itr = _invites[eventId].begin();
176 for (; itr != _invites[eventId].end(); ++itr)
177 if ((*itr)->GetInviteId() == inviteId)
178 break;
179
180 if (itr == _invites[eventId].end())
181 return;
182
183 SQLTransaction trans = CharacterDatabase.BeginTransaction();
185 stmt->setUInt64(0, (*itr)->GetInviteId());
186 trans->Append(stmt);
187 CharacterDatabase.CommitTransaction(trans);
188
189 if (!calendarEvent->IsGuildEvent())
190 SendCalendarEventInviteRemoveAlert((*itr)->GetInviteeGUID(), *calendarEvent, CALENDAR_STATUS_REMOVED);
191
192 SendCalendarEventInviteRemove(*calendarEvent, **itr, calendarEvent->GetFlags());
193
194 // we need to find out how to use CALENDAR_INVITE_REMOVED_MAIL_SUBJECT to force client to display different mail
195 //if ((*itr)->GetInviteeGUID() != remover)
196 // MailDraft(calendarEvent->BuildCalendarMailSubject(remover), calendarEvent->BuildCalendarMailBody())
197 // .SendMailTo(trans, MailReceiver((*itr)->GetInvitee()), calendarEvent, MAIL_CHECK_MASK_COPIED);
198
199 _invites[eventId].erase(itr);
200 delete* itr;
201}
202
204{
205 SQLTransaction trans = CharacterDatabase.BeginTransaction();
206 PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_REP_CALENDAR_EVENT);
207 stmt->setUInt64(0, calendarEvent->GetEventId());
208 stmt->setUInt32(1, GUID_LOPART(calendarEvent->GetCreatorGUID()));
209 stmt->setString(2, calendarEvent->GetTitle());
210 stmt->setString(3, calendarEvent->GetDescription());
211 stmt->setUInt8(4, calendarEvent->GetType());
212 stmt->setInt32(5, calendarEvent->GetDungeonId());
213 stmt->setUInt32(6, uint32(calendarEvent->GetEventTime()));
214 stmt->setUInt32(7, calendarEvent->GetFlags());
215 trans->Append(stmt);
216 CharacterDatabase.CommitTransaction(trans);
217}
218
220{
221 SQLTransaction trans = CharacterDatabase.BeginTransaction();
223 stmt->setUInt64(0, invite->GetInviteId());
224 stmt->setUInt64(1, invite->GetEventId());
225 stmt->setUInt32(2, GUID_LOPART(invite->GetInviteeGUID()));
226 stmt->setUInt32(3, GUID_LOPART(invite->GetSenderGUID()));
227 stmt->setUInt8(4, invite->GetStatus());
228 stmt->setUInt32(5, uint32(invite->GetStatusTime()));
229 stmt->setUInt8(6, invite->GetRank());
230 stmt->setString(7, invite->GetText());
231 trans->Append(stmt);
232 CharacterDatabase.CommitTransaction(trans);
233}
234
236{
237 for (CalendarEventStore::const_iterator itr = _events.begin(); itr != _events.end(); ++itr)
238 if ((*itr)->GetCreatorGUID() == guid)
239 RemoveEvent((*itr)->GetEventId(), 0); // don't send mail if removing a character
240
241 CalendarInviteStore playerInvites = GetPlayerInvites(guid);
242 for (CalendarInviteStore::const_iterator itr = playerInvites.begin(); itr != playerInvites.end(); ++itr)
243 RemoveInvite((*itr)->GetInviteId(), (*itr)->GetEventId(), guid);
244}
245
247{
248 for (CalendarEventStore::const_iterator itr = _events.begin(); itr != _events.end(); ++itr)
249 if ((*itr)->GetCreatorGUID() == guid && ((*itr)->IsGuildEvent() || (*itr)->IsGuildAnnouncement()))
250 RemoveEvent((*itr)->GetEventId(), guid);
251
252 CalendarInviteStore playerInvites = GetPlayerInvites(guid);
253 for (CalendarInviteStore::const_iterator itr = playerInvites.begin(); itr != playerInvites.end(); ++itr)
254 if (CalendarEvent* calendarEvent = GetEvent((*itr)->GetEventId()))
255 if (calendarEvent->IsGuildEvent() && calendarEvent->GetGuildId() == guildId)
256 RemoveInvite((*itr)->GetInviteId(), (*itr)->GetEventId(), guid);
257}
258
260{
261 for (CalendarEventStore::const_iterator itr = _events.begin(); itr != _events.end(); ++itr)
262 if ((*itr)->GetEventId() == eventId)
263 return *itr;
264
265 SF_LOG_DEBUG("calendar", "CalendarMgr::GetEvent: [" UI64FMTD "] not found!", eventId);
266 return NULL;
267}
268
270{
271 for (CalendarEventInviteStore::const_iterator itr = _invites.begin(); itr != _invites.end(); ++itr)
272 for (CalendarInviteStore::const_iterator itr2 = itr->second.begin(); itr2 != itr->second.end(); ++itr2)
273 if ((*itr2)->GetInviteId() == inviteId)
274 return *itr2;
275
276 SF_LOG_DEBUG("calendar", "CalendarMgr::GetInvite: [" UI64FMTD "] not found!", inviteId);
277 return NULL;
278}
279
281{
282 if (id == _maxEventId)
283 --_maxEventId;
284 else
285 _freeEventIds.push_back(id);
286}
287
289{
290 if (_freeEventIds.empty())
291 return ++_maxEventId;
292
293 uint64 eventId = _freeEventIds.front();
294 _freeEventIds.pop_front();
295 return eventId;
296}
297
299{
300 if (id == _maxInviteId)
301 --_maxInviteId;
302 else
303 _freeInviteIds.push_back(id);
304}
305
307{
308 if (_freeInviteIds.empty())
309 return ++_maxInviteId;
310
311 uint64 inviteId = _freeInviteIds.front();
312 _freeInviteIds.pop_front();
313 return inviteId;
314}
315
317{
318 CalendarEventStore events;
319
320 for (CalendarEventInviteStore::const_iterator itr = _invites.begin(); itr != _invites.end(); ++itr)
321 for (CalendarInviteStore::const_iterator itr2 = itr->second.begin(); itr2 != itr->second.end(); ++itr2)
322 if ((*itr2)->GetInviteeGUID() == guid)
323 events.insert(GetEvent(itr->first));
324
325 if (Player* player = ObjectAccessor::FindPlayer(guid))
326 for (CalendarEventStore::const_iterator itr = _events.begin(); itr != _events.end(); ++itr)
327 if ((*itr)->GetGuildId() == player->GetGuildId())
328 events.insert(*itr);
329
330 return events;
331}
332
334{
335 return _invites[eventId];
336}
337
339{
340 CalendarInviteStore invites;
341
342 for (CalendarEventInviteStore::const_iterator itr = _invites.begin(); itr != _invites.end(); ++itr)
343 for (CalendarInviteStore::const_iterator itr2 = itr->second.begin(); itr2 != itr->second.end(); ++itr2)
344 if ((*itr2)->GetInviteeGUID() == guid)
345 invites.push_back(*itr2);
346
347 return invites;
348}
349
351{
352 CalendarInviteStore const& invites = GetPlayerInvites(guid);
353
354 uint32 pendingNum = 0;
355 for (CalendarInviteStore::const_iterator itr = invites.begin(); itr != invites.end(); ++itr)
356 {
357 switch ((*itr)->GetStatus())
358 {
362 ++pendingNum;
363 break;
364 default:
365 break;
366 }
367 }
368
369 return pendingNum;
370}
371
373{
374 std::ostringstream strm;
375 strm << remover << ':' << _title;
376 return strm.str();
377}
378
380{
381 WorldPacket data;
382 uint32 time;
383 std::ostringstream strm;
384
385 // we are supposed to send PackedTime so i used WorldPacket to pack it
387 data >> time;
388 strm << time;
389 return strm.str();
390}
391
393{
394 CalendarEvent* calendarEvent = GetEvent(invite.GetEventId());
395 time_t statusTime = invite.GetStatusTime();
396
397 ObjectGuid invitee = invite.GetInviteeGUID();
398 Player* player = ObjectAccessor::FindPlayer(invitee);
399
400 uint8 level = player ? player->getLevel() : Player::GetLevelFromDB(invitee);
401
402 WorldPacket data(SMSG_CALENDAR_EVENT_INVITE, 8 + 8 + 8 + 1 + 1 + 1 + (statusTime ? 4 : 0) + 1);
403 data << uint8(invite.GetSenderGUID() == invite.GetInviteeGUID()); // true only if the invite is sign-up
404 data << uint8(invite.GetStatus());
405 data << uint64(invite.GetInviteId());
406 data << uint8(level);
407 data << uint64(invite.GetEventId());
408
409 data.WriteBit(invitee[6]);
410 data.WriteBit(invitee[4]);
411 data.WriteBit(invitee[1]);
412 data.WriteBit(invitee[3]);
413 data.WriteBit(invitee[7]);
414 data.WriteBit(invitee[0]);
415 data.WriteBit(invitee[2]);
416 data.WriteBit(invitee[5]);
417 data.WriteBit(!statusTime);
418 data.WriteBit(1); // FIXME: Clear pendings
419 data.FlushBits();
420
421 data.WriteByteSeq(invitee[7]);
422 data.WriteByteSeq(invitee[0]);
423 data.WriteByteSeq(invitee[5]);
424 if (statusTime)
425 data.AppendPackedTime(statusTime);
426 data.WriteByteSeq(invitee[2]);
427 data.WriteByteSeq(invitee[3]);
428 data.WriteByteSeq(invitee[4]);
429 data.WriteByteSeq(invitee[1]);
430 data.WriteByteSeq(invitee[6]);
431
432 if (!calendarEvent) // Pre-invite
433 {
434 if (Player* player = ObjectAccessor::FindPlayer(invite.GetSenderGUID()))
435 player->SendDirectMessage(&data);
436 }
437 else
438 {
439 if (calendarEvent->GetCreatorGUID() != invite.GetInviteeGUID()) // correct?
440 SendPacketToAllEventRelatives(data, *calendarEvent);
441 }
442}
443
444void CalendarMgr::SendCalendarEventUpdateAlert(CalendarEvent const& calendarEvent, time_t oldEventTime)
445{
446 WorldPacket data(SMSG_CALENDAR_EVENT_UPDATED_ALERT, 4 + 1 + 4 + 4 + 8 + 4 + 4 + 3 +
447 calendarEvent.GetTitle().size() + calendarEvent.GetDescription().size());
448
449 data << uint32(calendarEvent.GetFlags());
450 data << uint8(calendarEvent.GetType());
451 data << uint32(0); // Lock Date?
452 data.AppendPackedTime(oldEventTime);
453 data << uint64(calendarEvent.GetEventId());
454 data.AppendPackedTime(calendarEvent.GetEventTime());
455 data << int32(calendarEvent.GetDungeonId());
456 data.WriteBit(1); // FIXME: Clear pendings
457 data.WriteBits(calendarEvent.GetDescription().size(), 11);
458 data.WriteBits(calendarEvent.GetTitle().size(), 8);
459 data.FlushBits();
460
461 data.WriteString(calendarEvent.GetTitle());
462 data.WriteString(calendarEvent.GetDescription());
463
464 SendPacketToAllEventRelatives(data, calendarEvent);
465}
466
468{
469 ObjectGuid guid = invite.GetInviteeGUID();
470 WorldPacket data(SMSG_CALENDAR_EVENT_INVITE_STATUS, 8 + 8 + 4 + 4 + 1 + 4);
471 data.WriteBit(guid[5]);
472 data.WriteBit(guid[0]);
473 data.WriteBit(1); // FIXME: Clear pendings
474 data.WriteBit(guid[2]);
475 data.WriteBit(guid[1]);
476 data.WriteBit(guid[4]);
477 data.WriteBit(guid[6]);
478 data.WriteBit(guid[7]);
479 data.WriteBit(guid[3]);
480 data.FlushBits();
481
482 data.WriteByteSeq(guid[1]);
483 data.WriteByteSeq(guid[6]);
484 data.WriteByteSeq(guid[7]);
485 if (invite.GetStatusTime())
486 data.AppendPackedTime(invite.GetStatusTime());
487 else
488 data << uint32(0);
489 data.WriteByteSeq(guid[2]);
490 data.WriteByteSeq(guid[4]);
491 data << uint64(calendarEvent.GetEventId());
492 data.WriteByteSeq(guid[0]);
493 data.WriteByteSeq(guid[3]);
494 data.WriteByteSeq(guid[5]);
495 data << uint8(invite.GetStatus());
496 data << uint32(calendarEvent.GetFlags());
497 data.AppendPackedTime(calendarEvent.GetEventTime());
498
499 SendPacketToAllEventRelatives(data, calendarEvent);
500}
501
503{
504 if (Player* player = ObjectAccessor::FindPlayer(invite.GetInviteeGUID()))
505 {
507 data << uint64(calendarEvent.GetEventId());
508 data << uint32(calendarEvent.GetFlags());
509 data << uint8(invite.GetStatus());
510 data.AppendPackedTime(calendarEvent.GetEventTime());
511
512 player->SendDirectMessage(&data);
513 }
514}
515
517{
519 data << uint64(calendarEvent.GetEventId());
520 data.AppendPackedTime(calendarEvent.GetEventTime());
521 data.WriteBit(1); // FIXME: Clear pendings
522 data.FlushBits();
523
524 SendPacketToAllEventRelatives(data, calendarEvent);
525}
526
528{
529 ObjectGuid guid = invite.GetInviteeGUID();
531 data.WriteBit(guid[6]);
532 data.WriteBit(guid[7]);
533 data.WriteBit(guid[3]);
534 data.WriteBit(guid[0]);
535 data.WriteBit(guid[2]);
536 data.WriteBit(guid[4]);
537 data.WriteBit(guid[1]);
538 data.WriteBit(guid[5]);
539 data.WriteBit(1); // FIXME: Clear pendings
540 data.FlushBits();
541
542 data.WriteByteSeq(guid[0]);
543 data.WriteByteSeq(guid[4]);
544 data.WriteByteSeq(guid[3]);
545 data.WriteByteSeq(guid[5]);
546 data << uint64(invite.GetEventId());
547 data.WriteByteSeq(guid[7]);
548 data.WriteByteSeq(guid[1]);
549 data.WriteByteSeq(guid[2]);
550 data << uint32(flags);
551 data.WriteByteSeq(guid[6]);
552
553 SendPacketToAllEventRelatives(data, calendarEvent);
554}
555
557{
558 ObjectGuid guid = invite.GetInviteeGUID();
560 data.WriteBit(guid[3]);
561 data.WriteBit(guid[7]);
562 data.WriteBit(guid[2]);
563 data.WriteBit(guid[4]);
564 data.WriteBit(guid[1]);
565 data.WriteBit(guid[6]);
566 data.WriteBit(guid[5]);
567 data.WriteBit(1); // FIXME: Clear pendings
568 data.WriteBit(guid[0]);
569 data.FlushBits();
570
571 data.WriteByteSeq(guid[5]);
572 data.WriteByteSeq(guid[4]);
573 data.WriteByteSeq(guid[6]);
574 data.WriteByteSeq(guid[1]);
575 data.WriteByteSeq(guid[7]);
576 data.WriteByteSeq(guid[2]);
577 data.WriteByteSeq(guid[3]);
578 data << uint8(invite.GetRank());
579 data << uint64(invite.GetEventId());
580 data.WriteByteSeq(guid[0]);
581
582 SendPacketToAllEventRelatives(data, calendarEvent);
583}
584
585void CalendarMgr::SendCalendarEventInviteAlert(CalendarEvent const& calendarEvent, CalendarInvite const& invite, bool broadcast)
586{
587 Guild* guild = sGuildMgr->GetGuildById(calendarEvent.GetGuildId());
588 ObjectGuid guildId = guild ? guild->GetGUID() : 0;
589 ObjectGuid guid = calendarEvent.GetCreatorGUID();
590 ObjectGuid guid2 = invite.GetSenderGUID();
592 data << uint64(calendarEvent.GetEventId());
593 data << int32(calendarEvent.GetDungeonId());
594 data << uint8(calendarEvent.GetType());
595 data << uint64(invite.GetInviteId());
596 data << uint32(calendarEvent.GetFlags());
597 data << uint8(invite.GetStatus());
598 data.AppendPackedTime(calendarEvent.GetEventTime());
599 data << uint8(invite.GetRank());
600
601 data.WriteBit(guildId[7]);
602 data.WriteBit(guid[6]);
603 data.WriteBit(guildId[4]);
604 data.WriteBit(guildId[0]);
605 data.WriteBit(guid[3]);
606 data.WriteBit(guid2[1]);
607 data.WriteBit(guildId[5]);
608 data.WriteBit(guid[2]);
609 data.WriteBit(guid[0]);
610 data.WriteBit(guildId[1]);
611 data.WriteBit(guid[5]);
612 data.WriteBit(guildId[6]);
613 data.WriteBit(guildId[3]);
614 data.WriteBit(guid2[6]);
615 data.WriteBit(guid2[2]);
616 data.WriteBit(guid[4]);
617 data.WriteBit(guid[7]);
618 data.WriteBit(guid2[4]);
619 data.WriteBit(guid[1]);
620 data.WriteBit(guid2[3]);
621 data.WriteBit(guildId[2]);
622 data.WriteBit(guid2[0]);
623 data.WriteBits(calendarEvent.GetTitle().size(), 8);
624 data.WriteBit(guid2[5]);
625 data.WriteBit(guid2[7]);
626 data.FlushBits();
627
628 data.WriteByteSeq(guid[5]);
629 data.WriteByteSeq(guildId[6]);
630 data.WriteByteSeq(guildId[0]);
631 data.WriteByteSeq(guid[6]);
632 data.WriteByteSeq(guid2[5]);
633 data.WriteByteSeq(guid2[4]);
634 data.WriteString(calendarEvent.GetTitle());
635 data.WriteByteSeq(guid[0]);
636 data.WriteByteSeq(guid[1]);
637 data.WriteByteSeq(guildId[2]);
638 data.WriteByteSeq(guildId[7]);
639 data.WriteByteSeq(guid2[6]);
640 data.WriteByteSeq(guildId[1]);
641 data.WriteByteSeq(guid[2]);
642 data.WriteByteSeq(guid2[3]);
643 data.WriteByteSeq(guid2[7]);
644 data.WriteByteSeq(guid2[0]);
645 data.WriteByteSeq(guid[3]);
646 data.WriteByteSeq(guid2[2]);
647 data.WriteByteSeq(guid[7]);
648 data.WriteByteSeq(guildId[5]);
649 data.WriteByteSeq(guildId[4]);
650 data.WriteByteSeq(guildId[3]);
651 data.WriteByteSeq(guid2[1]);
652 data.WriteByteSeq(guid[4]);
653
654 if (broadcast)
655 {
656 if (guild)
657 guild->BroadcastPacket(&data);
658 }
659 else if (Player* player = ObjectAccessor::FindPlayer(invite.GetInviteeGUID()))
660 player->SendDirectMessage(&data);
661}
662
663void CalendarMgr::SendCalendarEvent(uint64 playerGuid, CalendarEvent const& calendarEvent, CalendarSendEventType sendType)
664{
665 Player* player = ObjectAccessor::FindPlayer(playerGuid);
666 if (!player)
667 return;
668
669 CalendarInviteStore const& eventInviteeList = _invites[calendarEvent.GetEventId()];
670
671 Guild* guild = sGuildMgr->GetGuildById(calendarEvent.GetGuildId());
672 ObjectGuid creatorGuid = calendarEvent.GetCreatorGUID();
673 ObjectGuid guildGuid = guild ? guild->GetGUID() : 0;
674 ByteBuffer inviteeData;
675 WorldPacket data(SMSG_CALENDAR_SEND_EVENT, 60 + eventInviteeList.size() * 32);
676 data.WriteBits(eventInviteeList.size(), 20);
677
678 for (CalendarInviteStore::const_iterator iter = eventInviteeList.begin(); iter != eventInviteeList.end(); ++iter)
679 {
680 CalendarInvite const* invitee = (*iter);
681 ObjectGuid guid = invitee->GetInviteeGUID();
683 uint8 inviteeLevel = player ? player->getLevel() : Player::GetLevelFromDB(invitee->GetInviteeGUID());
684 uint32 inviteeGuildId = player ? player->GetGuildId() : Player::GetGuildIdFromDB(invitee->GetInviteeGUID());
685
686 data.WriteBit(guid[1]);
687 data.WriteBit(guid[2]);
688 data.WriteBit(guid[0]);
689 data.WriteBit(guid[7]);
690 data.WriteBit(guid[3]);
691 data.WriteBit(guid[5]);
692 data.WriteBit(guid[6]);
693 data.WriteBits(invitee->GetText().size(), 8);
694 data.WriteBit(guid[4]);
695
696 if (invitee->GetStatusTime())
697 inviteeData.AppendPackedTime(invitee->GetStatusTime());
698 else
699 inviteeData << uint32(0);
700 inviteeData.WriteByteSeq(guid[5]);
701 inviteeData << uint8(calendarEvent.IsGuildEvent() && calendarEvent.GetGuildId() == inviteeGuildId ? 1 : 0);
702 inviteeData.WriteByteSeq(guid[1]);
703 inviteeData.WriteByteSeq(guid[2]);
704 inviteeData.WriteByteSeq(guid[6]);
705 inviteeData.WriteString(invitee->GetText());
706 inviteeData << uint8(inviteeLevel);
707 inviteeData.WriteByteSeq(guid[7]);
708 inviteeData << uint8(invitee->GetRank());
709 inviteeData << uint64(invitee->GetInviteId());
710 inviteeData.WriteByteSeq(guid[0]);
711 inviteeData.WriteByteSeq(guid[3]);
712 inviteeData.WriteByteSeq(guid[4]);
713 inviteeData << uint8(invitee->GetStatus());
714 }
715
716 data.WriteBits(calendarEvent.GetTitle().size(), 8);
717 data.WriteBit(creatorGuid[2]);
718 data.WriteBit(creatorGuid[0]);
719 data.WriteBit(guildGuid[4]);
720 data.WriteBit(guildGuid[5]);
721 data.WriteBit(creatorGuid[1]);
722 data.WriteBit(creatorGuid[5]);
723 data.WriteBit(creatorGuid[3]);
724 data.WriteBit(guildGuid[6]);
725 data.WriteBits(calendarEvent.GetDescription().size(), 11);
726 data.WriteBit(guildGuid[1]);
727 data.WriteBit(guildGuid[7]);
728 data.WriteBit(creatorGuid[6]);
729 data.WriteBit(guildGuid[2]);
730 data.WriteBit(guildGuid[0]);
731 data.WriteBit(creatorGuid[4]);
732 data.WriteBit(guildGuid[3]);
733 data.WriteBit(creatorGuid[7]);
734 data.FlushBits();
735
736 data.append(inviteeData);
737 data.WriteByteSeq(creatorGuid[0]);
738 data.WriteByteSeq(creatorGuid[5]);
739 data << uint32(calendarEvent.GetFlags());
740 data.WriteByteSeq(guildGuid[1]);
741 data.WriteByteSeq(creatorGuid[7]);
742 data.WriteByteSeq(creatorGuid[3]);
743 data.AppendPackedTime(calendarEvent.GetEventTime());
744 data.WriteByteSeq(guildGuid[6]);
745 data.WriteByteSeq(creatorGuid[4]);
746 data << int32(calendarEvent.GetDungeonId());
747 data << uint32(0); // Lock Date? Always 0
748 data.WriteByteSeq(guildGuid[4]);
749 data << uint8(calendarEvent.GetType());
750 data.WriteString(calendarEvent.GetTitle());
751 data.WriteByteSeq(creatorGuid[6]);
752 data.WriteByteSeq(guildGuid[3]);
753 data.WriteByteSeq(creatorGuid[2]);
754 data.WriteByteSeq(guildGuid[7]);
755 data.WriteByteSeq(creatorGuid[1]);
756 data.WriteString(calendarEvent.GetDescription());
757 data.WriteByteSeq(guildGuid[2]);
758 data.WriteByteSeq(guildGuid[5]);
759 data.WriteByteSeq(guildGuid[0]);
760 data << uint64(calendarEvent.GetEventId());
761 data << uint8(sendType);
762
763 player->SendDirectMessage(&data);
764}
765
767{
768 if (Player* player = ObjectAccessor::FindPlayer(guid))
769 {
771 data << uint32(calendarEvent.GetFlags());
772 data << uint8(status);
773 data << uint64(calendarEvent.GetEventId());
774 data.AppendPackedTime(calendarEvent.GetEventTime());
775
776 player->SendDirectMessage(&data);
777 }
778}
779
781{
782 if (Player* player = ObjectAccessor::FindPlayer(guid))
783 {
785 player->SendDirectMessage(&data);
786 }
787}
788
790{
791 if (Player* player = ObjectAccessor::FindPlayer(guid))
792 {
793 size_t length = param.length();
794 WorldPacket data(SMSG_CALENDAR_COMMAND_RESULT, 2 + 1 + 1 + length);
795 data.WriteBits(length / 2, 8);
796 data.WriteBit(length % 2);
797 data.FlushBits();
798
799 data << uint8(0); // FIXME: Command
800 data << uint8(err);
801 switch (err)
802 {
806 data.WriteString(param);
807 break;
808 default:
809 break;
810 }
811
812 player->SendDirectMessage(&data);
813 }
814}
815
817{
818 // Send packet to all guild members
819 if (calendarEvent.IsGuildEvent() || calendarEvent.IsGuildAnnouncement())
820 if (Guild* guild = sGuildMgr->GetGuildById(calendarEvent.GetGuildId()))
821 guild->BroadcastPacket(&packet);
822
823 // Send packet to all invitees if event is non-guild, in other case only to non-guild invitees (packet was broadcasted for them)
824 CalendarInviteStore invites = _invites[calendarEvent.GetEventId()];
825 for (CalendarInviteStore::iterator itr = invites.begin(); itr != invites.end(); ++itr)
826 if (Player* player = ObjectAccessor::FindPlayer((*itr)->GetInviteeGUID()))
827 if (!calendarEvent.IsGuildEvent() || (calendarEvent.IsGuildEvent() && player->GetGuildId() != calendarEvent.GetGuildId()))
828 player->SendDirectMessage(&packet);
829}
std::set< CalendarEvent * > CalendarEventStore
#define sCalendarMgr
CalendarError
Definition CalendarMgr.h:76
@ CALENDAR_ERROR_OTHER_INVITES_EXCEEDED
Definition CalendarMgr.h:81
@ CALENDAR_ERROR_ALREADY_INVITED_TO_EVENT_S
Definition CalendarMgr.h:87
@ CALENDAR_ERROR_IGNORING_YOU_S
Definition CalendarMgr.h:90
@ CALENDAR_ERROR_EVENT_INVALID
Definition CalendarMgr.h:83
CalendarModerationRank
Definition CalendarMgr.h:30
@ CALENDAR_FLAG_WITHOUT_INVITES
Definition CalendarMgr.h:25
@ CALENDAR_FLAG_GUILD_EVENT
Definition CalendarMgr.h:26
std::vector< CalendarInvite * > CalendarInviteStore
CalendarSendEventType
Definition CalendarMgr.h:37
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_REMOVED
Definition CalendarMgr.h:72
@ CHAR_REP_CALENDAR_EVENT
@ CHAR_DEL_CALENDAR_INVITE
@ CHAR_DEL_CALENDAR_EVENT
@ CHAR_REP_CALENDAR_INVITE
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
#define sGuildMgr
Definition GuildMgr.h:53
#define SF_LOG_DEBUG(filterType__,...)
Definition Log.h:134
#define SF_LOG_INFO(filterType__,...)
Definition Log.h:137
@ MAIL_CHECK_MASK_COPIED
This mail was returned. Do not allow returning mail back again.
Definition Mail.h:37
uint32 GUID_LOPART(uint64 x)
@ HIGHGUID_PLAYER
uint64 MAKE_NEW_GUID(uint32 l, uint32 e, uint32 h)
Skyfire::AutoPtr< ResultSet, Skyfire::Mutex > QueryResult
Definition QueryResult.h:48
Skyfire::AutoPtr< Transaction, Skyfire::Mutex > SQLTransaction
Definition Transaction.h:42
bool WriteBit(uint32 bit)
Definition ByteBuffer.h:164
void WriteString(std::string const &str)
Definition ByteBuffer.h:578
void append(T value)
Definition ByteBuffer.h:147
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 SendCalendarEventUpdateAlert(CalendarEvent const &calendarEvent, time_t oldEventTime)
void UpdateEvent(CalendarEvent *calendarEvent)
uint64 _maxInviteId
uint64 GetFreeEventId()
void FreeInviteId(uint64 id)
CalendarEventInviteStore _invites
void SendPacketToAllEventRelatives(WorldPacket packet, CalendarEvent const &calendarEvent)
std::deque< uint64 > _freeEventIds
CalendarEventStore GetPlayerEvents(uint64 guid)
void FreeEventId(uint64 id)
void SendCalendarEventInviteAlert(CalendarEvent const &calendarEvent, CalendarInvite const &invite, bool broadcast)
uint64 GetFreeInviteId()
CalendarEventStore _events
void RemoveEvent(uint64 eventId, uint64 remover)
void SendCalendarEventModeratorStatus(CalendarEvent const &calendarEvent, CalendarInvite const &invite)
void SendCalendarEventInviteRemove(CalendarEvent const &calendarEvent, CalendarInvite const &invite, uint32 flags)
void SendCalendarEventRemovedAlert(CalendarEvent const &calendarEvent)
void SendCalendarEventStatusAlert(CalendarEvent const &calendarEvent, CalendarInvite const &invite)
void SendCalendarClearPendingAction(uint64 guid)
CalendarInvite * GetInvite(uint64 inviteId) const
uint32 GetPlayerNumPending(uint64 guid)
void SendCalendarEventStatus(CalendarEvent const &calendarEvent, CalendarInvite const &invite)
void RemovePlayerGuildEventsAndSignups(uint64 guid, uint32 guildId)
void SendCalendarEventInviteRemoveAlert(uint64 guid, CalendarEvent const &calendarEvent, CalendarInviteStatus status)
void UpdateInvite(CalendarInvite *invite)
void LoadFromDB()
void SendCalendarCommandResult(uint64 guid, CalendarError err, std::string param="")
uint64 _maxEventId
std::deque< uint64 > _freeInviteIds
void AddInvite(CalendarEvent *calendarEvent, CalendarInvite *invite, bool sendEventInvitePacket=true, bool forceEventInviteAlertPacket=false)
CalendarEvent * GetEvent(uint64 eventId) const
CalendarInviteStore const & GetEventInvites(uint64 eventId)
void RemoveAllPlayerEventsAndInvites(uint64 guid)
void RemoveInvite(uint64 inviteId, uint64 eventId, uint64 remover)
void SendCalendarEventInvite(CalendarInvite const &invite)
void AddEvent(CalendarEvent *calendarEvent, CalendarSendEventType sendType)
CalendarInviteStore GetPlayerInvites(uint64 guid)
void SendCalendarEvent(uint64 playerGuid, CalendarEvent const &calendarEvent, CalendarSendEventType sendType)
Definition Field.h:16
std::string GetString() const
Definition Field.h:228
uint64 GetUInt64() const
Definition Field.h:141
uint32 GetUInt32() const
Definition Field.h:105
int32 GetInt32() const
Definition Field.h:123
Definition Guild.h:324
void BroadcastPacket(WorldPacket *packet) const
Definition Guild.cpp:2766
uint64 GetGUID() const
Definition Guild.h:758
void SendMailTo(SQLTransaction &trans, MailReceiver const &receiver, MailSender const &sender, MailCheckMask checked=MAIL_CHECK_MASK_NONE, uint32 deliver_delay=0)
Definition Mail.cpp:162
static Player * FindPlayer(uint64)
static uint32 GetGuildIdFromDB(uint64 guid)
Definition Player.cpp:8020
uint32 GetGuildId() const
Definition Player.h:2291
void SendDirectMessage(WorldPacket *data)
Definition Player.cpp:6904
static uint32 GetLevelFromDB(uint64 guid)
Definition Player.cpp:8086
void setString(const uint8 index, const std::string &value)
void setUInt64(const uint8 index, const uint64 value)
void setUInt32(const uint8 index, const uint32 value)
void setUInt8(const uint8 index, const uint8 value)
void setInt32(const uint8 index, const int32 value)
uint8 getLevel() const
Definition Unit.h:1528
CharacterDatabaseWorkerPool CharacterDatabase
Accessor to the character database.
Definition Main.cpp:41
@ SMSG_CALENDAR_SEND_EVENT
Definition Opcodes.h:590
@ SMSG_CALENDAR_CLEAR_PENDING_ACTION
Definition Opcodes.h:574
@ SMSG_CALENDAR_COMMAND_RESULT
Definition Opcodes.h:575
@ SMSG_CALENDAR_EVENT_UPDATED_ALERT
Definition Opcodes.h:585
@ SMSG_CALENDAR_EVENT_INVITE
Definition Opcodes.h:577
@ SMSG_CALENDAR_EVENT_INVITE_REMOVED
Definition Opcodes.h:579
@ SMSG_CALENDAR_EVENT_REMOVED_ALERT
Definition Opcodes.h:584
@ SMSG_CALENDAR_EVENT_INVITE_REMOVED_ALERT
Definition Opcodes.h:580
@ SMSG_CALENDAR_EVENT_INVITE_STATUS
Definition Opcodes.h:581
@ SMSG_CALENDAR_EVENT_MODERATOR_STATUS
Definition Opcodes.h:583
@ SMSG_CALENDAR_EVENT_INVITE_STATUS_ALERT
Definition Opcodes.h:582
@ SMSG_CALENDAR_EVENT_INVITE_ALERT
Definition Opcodes.h:578
std::string BuildCalendarMailSubject(uint64 remover) const
bool IsGuildAnnouncement() const
CalendarEventType GetType() const
bool IsGuildEvent() const
uint64 GetEventId() const
time_t _eventTime
std::string _title
uint64 GetCreatorGUID() const
int32 GetDungeonId() const
std::string GetTitle() const
std::string BuildCalendarMailBody() const
uint32 GetGuildId() const
time_t GetEventTime() const
std::string GetDescription() const
uint32 GetFlags() const
CalendarModerationRank GetRank() const
CalendarInviteStatus GetStatus() const
uint64 GetInviteId() const
uint64 GetSenderGUID() const
uint64 GetInviteeGUID() const
time_t GetStatusTime() const
std::string GetText() const
uint64 GetEventId() const