SEGS  0.6.1-develop [d2cac982]
Super Entity Game Server
Shortcuts.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 // if this file is included stand-alone this will pull in common definitions
10 #include "MapEventTypes.h"
11 #include "MapSessionReference.h"
12 #include "BitStream.h"
13 
14 namespace SEGSEvents
15 {
16 // [[ev_def:type]]
17 class Shortcuts : public MapLinkEvent
18 {
19 public:
20 explicit Shortcuts():MapLinkEvent(MapEventTypes::evShortcuts) {}
22  {
23  }
24  void serializeto(BitStream &bs) const override
25  {
26  bs.StorePackedBits(1,4); // opcode
27  for(uint32_t i=0; i<m_commands.size(); i++)
28  {
29  bs.StorePackedBits(1,i+1);
30  bs.StoreString(m_commands[i]);
31  }
32  bs.StorePackedBits(1,~0u); // end of command list
33  }
34  void serializefrom(BitStream &bs) override
35  {
36  int idx=0;
37  // while more commands available and the size is sane
38  while(-1!=(idx=bs.GetPackedBits(1)) && m_commands.size()<200)
39  {
40  int cmd_idx = bs.GetPackedBits(1);
41  assert(cmd_idx>0 && cmd_idx<200);
42  m_commands.resize(std::max<int>(m_commands.size(),cmd_idx));
43  bs.GetString(m_commands[cmd_idx-1]);
44  }
45  }
46  // [[ev_def:field]]
48  // [[ev_def:field]]
49  std::vector<QString> m_commands;
51 };
52 } // end of SEGSEvents namespace
53 
std::vector< QString > m_commands
Definition: Shortcuts.h:49
Definition: MapClientSession.h:32
void serializeto(BitStream &bs) const override
Definition: Shortcuts.h:24
int32_t GetPackedBits(uint32_t minbits)
Definition: BitStream.cpp:290
Definition: BitStream.h:34
Definition: LinkLevelEvent.h:13
void serializefrom(BitStream &bs) override
Definition: Shortcuts.h:34
MapEventTypes
Definition: MapEventTypes.h:14
void StorePackedBits(uint32_t nBits, uint32_t dataBits)
Definition: BitStream.cpp:161
Definition: Shortcuts.h:17
Definition: MapSessionReference.h:5
SessionReference m_session
Definition: Shortcuts.h:47
void StoreString(const char *str)
Definition: BitStream.cpp:204
#define EVENT_IMPL(name)
Definition: SEGSEvent.h:77
void GetString(QString &str)
Retrieves a null-terminated C-style string from the bit stream.
Definition: BitStream.cpp:331
Shortcuts()
Definition: Shortcuts.h:20
Shortcuts(MapClientSession *sess)
Definition: Shortcuts.h:21