SEGS  0.6.1-develop [d2cac982]
Super Entity Game Server
MapClientSession.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 "FixedPointValue.h"
10 #include "NetCommandManager.h"
12 
13 #include <map>
14 #include <memory>
15 
16 
17 class MapHandler;
18 class MapInstance;
19 class NetCommand;
20 struct MapLink;
21 class GamePacket;
22 class SEGSTimer;
23 class Entity;
24 
26 {
27  const Entity *m_entity = nullptr; // this is the entity this belief is linked to.
28  Vector3_FPV position; // we think client considers m_entity to be located here.
29  bool m_is_logging_out = false;
30 };
31 
33 {
34  using mNetCommands = std::map<int, NetCommand *>;
35  using vBelief = std::map<int, ClientEntityStateBelief>;
36  using vStoredCommands = std::vector<std::unique_ptr<SEGSEvents::GameCommandEvent>>;
37  friend class CharacterDatabase;
38 
39  uint64_t m_session_token= 0; // a back-link to owning session, used in serialization
40  uint32_t m_client_id = 0;
41  uint8_t m_access_level = 0;
42  uint16_t m_requested_slot_idx=0;
43  uint16_t m_max_slots;
46  MapInstance * m_current_map = nullptr;
47  Entity * m_ent = nullptr;
48  QString m_name; // current character name, stored here for quick lookups
49  SEGSTimer * m_tick_source = nullptr;
51  bool m_in_map = false;
52 
53  // The values below might be needed for map<->map handover ?
54  uint32_t is_connected_to_game_server_id = 0;
55  uint32_t is_connected_to_map_server_id = 0;
56  uint32_t is_connected_to_map_instance_id = 0;
57  void addCommandToSendNextUpdate(std::unique_ptr<SEGSEvents::GameCommandEvent> &&v);
58  void AddShortcut(int index, NetCommand *command);
59 
60  uint32_t auth_id() const { return m_client_id; }
61  // TODO: for now session reuse does not retain any data, should it ?
62  void reset() { *this = {}; }
63  // Map sessions do not support temporary ones right now.
64  void set_temporary(bool v) { assert(v==false); }
65  bool is_temporary() const { return false; }
66  MapLink * link() { return m_link; }
68  void link(MapLink *l) { m_link = l; }
69  template<class T, typename... Args>
70  void addCommand(Args&&... args)
71  {
72  addCommandToSendNextUpdate(std::make_unique<T>(std::forward<Args>(args)...));
73  }
74 
75 protected:
76  MapLink * m_link = nullptr;
77 };
78 template<class T, typename... Args>
79 void addSessionCommand(MapClientSession &sess,Args&&... args)
80 {
81  sess.addCommand(std::make_unique<T>(std::forward<Args>(args)...));
82 }
Instances of SEGSTimer class are used to schedule events in the future.
Definition: SEGSTimer.h:18
Definition: MapClientSession.h:32
void addSessionCommand(MapClientSession &sess, Args &&... args)
Definition: MapClientSession.h:79
Vector3_FPV position
Definition: MapClientSession.h:28
Definition: MapClientSession.h:25
void link(MapLink *l)
Definition: MapClientSession.h:68
void reset()
Definition: MapClientSession.h:62
std::map< int, NetCommand * > mNetCommands
Definition: MapClientSession.h:34
void addCommand(Args &&... args)
Definition: MapClientSession.h:70
Definition: MapInstance.h:132
void set_temporary(bool v)
Definition: MapClientSession.h:64
uint32_t auth_id() const
Definition: MapClientSession.h:60
const Entity * m_entity
Definition: MapClientSession.h:27
Definition: Entity.h:134
QString m_name
Definition: MapClientSession.h:48
Definition: NetCommandManager.h:20
Definition: FixedPointValue.h:28
vStoredCommands m_contents
Definition: MapClientSession.h:45
MapLink * link()
Definition: MapClientSession.h:66
bool is_temporary() const
Definition: MapClientSession.h:65
bool m_is_logging_out
Definition: MapClientSession.h:29
std::vector< std::unique_ptr< SEGSEvents::GameCommandEvent > > vStoredCommands
Definition: MapClientSession.h:36
vBelief m_worldstate_belief
Definition: MapClientSession.h:50
uint16_t m_max_slots
Definition: MapClientSession.h:43
std::map< int, ClientEntityStateBelief > vBelief
Definition: MapClientSession.h:35
mNetCommands m_shortcuts
Definition: MapClientSession.h:44