SEGS  0.6.1-develop [d2cac982]
Super Entity Game Server
GameHandler.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 "EventProcessor.h"
12 
13 #include <unordered_set>
14 class CharacterClient;
15 class GameServer;
16 class SEGSTimer;
17 struct GameLink;
18 namespace SEGSEvents
19 {
20 class UpdateServer;
21 class UpdateCharacter;
22 class DeleteCharacter;
23 class MapServerAddrRequest;
24 class Timeout;
25 
26 // internal events
27 class Idle;
28 class DisconnectRequest;
29 class ConnectRequest;
30 class UnknownEvent;
31 }
33 {
35  {
36  EXITING_TO_MAP=0,
37  EXITING_TO_LOGIN=1,
38  };
40  uint32_t m_auth_account_id=0;
41  uint32_t is_connected_to_map_server_id=0;
42  uint32_t is_connected_to_map_instance_id=0;
44  uint8_t m_access_level=0;
45 
46  uint32_t auth_id() const { return m_auth_account_id; }
47  void reset()
48  {
49  *this = {}; // just use default constructed value
50  }
51  // those functions store temporariness state of the link in the lowest bit of the pointer
52  void set_temporary(bool v) { (intptr_t &)(m_link) = (intptr_t(m_link) & ~1) | intptr_t(v); }
53  bool is_temporary() const { return intptr_t(m_link) & 1; }
54  GameLink * link() { return (GameLink *)(intptr_t(m_link) & ~1); }
56  void link(GameLink *l) { m_link = l; }
57 
58 protected:
59  GameLink * m_link = nullptr;
60 };
61 
62 class GameHandler final : public EventProcessor
63 {
64 
65  using sIds = std::unordered_set<uint32_t>;
67 
68  SessionStore m_session_store;
69  std::unique_ptr<SEGSTimer> m_link_checker;
70  std::unique_ptr<SEGSTimer> m_service_status_timer;
71 
72 public:
74  GameHandler();
75  ~GameHandler() override;
76  void set_server(GameServer *s) {m_server=s;}
77  void start();
78 protected:
79  void dispatch(SEGSEvents::Event *ev) override;
80 
82  // Link events
83  void on_idle(SEGSEvents::Idle *ev);
84  void on_link_lost(SEGSEvents::Event *ev);
85  void on_disconnect(SEGSEvents::DisconnectRequest *ev);
86  void on_connection_request(SEGSEvents::ConnectRequest *ev);
87 
88  void on_update_server(SEGSEvents::UpdateServer *ev);
89  void on_update_character(SEGSEvents::UpdateCharacter *ev);
90  void on_delete_character(SEGSEvents::DeleteCharacter *ev);
91  void on_map_req(SEGSEvents::MapServerAddrRequest *ev);
92  void on_unknown_link_event(SEGSEvents::UnknownEvent *ev);
94  // Server <-> Server events
95  void on_expect_client(SEGSEvents::ExpectClientRequest *ev); // from AuthServer
96  void on_client_expected(SEGSEvents::ExpectMapClientResponse *ev); // from MapServer
97  void on_client_connected_to_other_server(SEGSEvents::ClientConnectedMessage *ev);
98  void on_client_disconnected_from_other_server(SEGSEvents::ClientDisconnectedMessage *ev);
99 
101  // Internal events
102  void on_check_links();
103  void reap_stale_links();
104  void report_service_status();
105  void on_timeout(SEGSEvents::Timeout *ev);
106 
107  void on_game_db_error(SEGSEvents::GameDbErrorMessage *ev);
108  void on_account_data(SEGSEvents::GameAccountResponse *ev);
109  void on_character_deleted(SEGSEvents::RemoveCharacterResponse *ev);
111  sIds waiting_for_client; // this hash_set holds all client cookies we wait for
113 
114  void serialize_from(std::istream &is) override;
115  void serialize_to(std::ostream &is) override;
116 };
Instances of SEGSTimer class are used to schedule events in the future.
Definition: SEGSTimer.h:18
sIds waiting_for_client
Definition: GameHandler.h:111
Definition: GameHandler.h:32
Definition: GameEvents.h:126
void set_server(GameServer *s)
Definition: GameHandler.h:76
uint32_t auth_id() const
Definition: GameHandler.h:46
Definition: GameEvents.h:152
Definition: SEGSEvent.h:35
GameLink * link()
Definition: GameHandler.h:54
Definition: LinkLevelEvent.h:13
Definition: CRUD_Events.h:84
SEGSEvents::GameAccountResponseData m_game_account
Definition: GameHandler.h:39
eTravelDirection m_direction
Definition: GameHandler.h:43
void link(GameLink *l)
Definition: GameHandler.h:56
Definition: TimeEvent.h:15
Definition: GameEvents.h:186
Definition: CRUD_Events.h:102
bool is_temporary() const
Definition: GameHandler.h:53
Definition: CRUD_Events.h:61
Definition: EventProcessor.h:22
void reset()
Definition: GameHandler.h:47
Definition: GameHandler.h:62
eTravelDirection
Definition: GameHandler.h:34
Definition: CRUD_Events.h:111
#define IMPL_ID(EventProcessorChildType)
Definition: EventProcessor.h:44
void set_temporary(bool v)
Definition: GameHandler.h:52
GameServer * m_server
Definition: GameHandler.h:112
Definition: GameDBSyncEvents.h:163
Definition: GameServer.h:17
Definition: GameEvents.h:44