SEGS  0.6.1-develop [d2cac982]
Super Entity Game Server
EmailHeaders.h
Go to the documentation of this file.
1 /*
2  * SEGS - Super Entity Game Server
3  * http://www.segs.io/
4  * Copyright (c) 2006 - 2019 SEGS Team (see AUTHORS.md)
5  * This software is licensed under the terms of the 3-clause BSD License. See LICENSE.md for details.
6  */
7 
8 #pragma once
9 #include "GameCommand.h"
10 #include "MapEventTypes.h"
11 #include "BitStream.h"
12 
13 namespace SEGSEvents
14 {
15 
16 // [[ev_def:type]]
17 class EmailHeaders final : public GameCommandEvent
18 {
19 public:
20  struct EmailHeader
21  {
22  uint32_t id;
23  QString sender;
24  QString subject;
25  uint32_t timestamp;
26  template<class Archive>
27  void serialize(Archive &ar)
28  {
29  ar(id,sender,subject,timestamp);
30  }
31  };
32 
33  explicit EmailHeaders() : GameCommandEvent(MapEventTypes::evEmailHeaders) {}
34  /*Send multiple emails*/
35  EmailHeaders(const std::vector<EmailHeader> &email) : GameCommandEvent(MapEventTypes::evEmailHeaders),
36  m_fullupdate(true),
37  m_emails(email)
38  {
39  }
40 
41  /*Defines a single email header to send*/
42  EmailHeaders(const uint32_t &id, const QString &sender, const QString &subject, const uint32_t &timestamp)
43  : GameCommandEvent(evEmailHeaders), m_fullupdate(false)
44  {
45  m_emails.push_back(EmailHeader{ id, sender, subject, timestamp });
46  }
47 
48  void serializeto(BitStream &bs) const override
49  {
50  bs.StorePackedBits(1, type()-evFirstServerToClient);
52  bs.StorePackedBits(1, m_emails.size());
53 
54  for(const EmailHeader &hdr : m_emails)
55  {
56  bs.StoreBits(1, true); //"valid" flag
57  bs.StoreBits(32, hdr.id);
58  bs.StoreString(hdr.sender);
59  bs.StoreString(hdr.subject);
60  bs.StoreBits(32, hdr.timestamp);
61  }
62  }
63 
64  // [[ev_def:field]]
65  bool m_fullupdate; //Forces a refresh of the email window
66  // [[ev_def:field]]
67  std::vector<EmailHeader> m_emails;
68 
70 };
71 
72 } // end of SEGSEvents namespace
73 
void StoreBits(uint32_t nBits, uint32_t dataBits)
Definition: BitStream.cpp:114
Definition: GameCommand.h:16
void serializeto(BitStream &bs) const override
Definition: EmailHeaders.h:48
bool m_fullupdate
Definition: EmailHeaders.h:65
Definition: BitStream.h:34
Definition: LinkLevelEvent.h:13
EmailHeaders(const uint32_t &id, const QString &sender, const QString &subject, const uint32_t &timestamp)
Definition: EmailHeaders.h:42
MapEventTypes
Definition: MapEventTypes.h:14
QString sender
Definition: EmailHeaders.h:23
void StorePackedBits(uint32_t nBits, uint32_t dataBits)
Definition: BitStream.cpp:161
uint32_t id
Definition: EmailHeaders.h:22
void StoreString(const char *str)
Definition: BitStream.cpp:204
EmailHeaders()
Definition: EmailHeaders.h:33
Definition: EmailHeaders.h:20
Definition: EmailHeaders.h:17
uint32_t type() const
Definition: SEGSEvent.h:66
#define EVENT_IMPL(name)
Definition: SEGSEvent.h:77
QString subject
Definition: EmailHeaders.h:24
uint32_t timestamp
Definition: EmailHeaders.h:25
void serialize(Archive &ar)
Definition: EmailHeaders.h:27
std::vector< EmailHeader > m_emails
Definition: EmailHeaders.h:67
EmailHeaders(const std::vector< EmailHeader > &email)
Definition: EmailHeaders.h:35