SEGS  0.4.2
Super Entity Game Server
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 - 2018 SEGS Team (see Authors.txt)
5  * This software is licensed! (See License.txt for details)
6  */
7 
8 #pragma once
9 #include "GameLink.h"
10 #include "GameEvents.h"
11 #include "EventProcessor.h"
14 
15 #include <unordered_set>
16 class CharacterClient;
17 class GameServer;
18 class SEGSTimer;
19 
21 {
23  {
26  };
28  uint32_t m_auth_account_id=0;
32  uint8_t m_access_level=0;
33 
34  uint32_t auth_id() const { return m_auth_account_id; }
35  void reset()
36  {
37  *this = {}; // just use default constructed value
38  }
39  // those functions store temporariness state of the link in the lowest bit of the pointer
40  void set_temporary(bool v) { (intptr_t &)(m_link) = (intptr_t(m_link) & ~1) | intptr_t(v); }
41  bool is_temporary() const { return intptr_t(m_link) & 1; }
42  GameLink * link() { return (GameLink *)(intptr_t(m_link) & ~1); }
44  void link(GameLink *l) { m_link = l; }
45 
46 protected:
47  GameLink * m_link = nullptr;
48 };
49 
50 class GameHandler final : public EventProcessor
51 {
52 
53  using sIds = std::unordered_set<uint32_t>;
55 
56  SessionStore m_session_store;
57  std::unique_ptr<SEGSTimer> m_link_checker;
58  std::unique_ptr<SEGSTimer> m_service_status_timer;
59 
60 public:
61  GameHandler();
62  ~GameHandler();
64  void start();
65 protected:
66  void dispatch(SEGSEvent *ev) override;
67 
69  // Link events
70  void on_idle(IdleEvent *ev);
71  void on_link_lost(SEGSEvent *ev);
74 
81  // Server <-> Server events
82  void on_expect_client(ExpectClientRequest *ev); // from AuthServer
83  void on_client_expected(ExpectMapClientResponse *ev); // from MapServer
84  void on_client_connected_to_other_server(ClientConnectedMessage *ev);
85  void on_client_disconnected_from_other_server(ClientDisconnectedMessage *ev);
86 
88  // Internal events
89  void on_check_links();
90  void reap_stale_links();
91  void report_service_status();
92  void on_timeout(TimerEvent *ev);
93 
94  void on_game_db_error(GameDbErrorMessage *ev);
95  void on_account_data(GameAccountResponse *ev);
96  void on_character_deleted(RemoveCharacterResponse *ev);
98  sIds waiting_for_client; // this hash_set holds all client cookies we wait for
100 };
Definition: GameEvents.h:211
Instances of SEGSTimer class are used to schedule events in the future.
Definition: SEGSTimer.h:18
sIds waiting_for_client
Definition: GameHandler.h:98
Definition: GameHandler.h:20
void set_server(GameServer *s)
Definition: GameHandler.h:63
Definition: GameEvents.h:158
void on_check_links()
Definition: GameHandler.cpp:204
void start()
Definition: GameHandler.cpp:47
uint32_t is_connected_to_map_instance_id
Definition: GameHandler.h:30
Definition: SEGSEvent.h:32
GameHandler()
Definition: GameHandler.cpp:41
Definition: GameEvents.h:108
GameLink * m_link
Definition: GameHandler.h:47
GameAccountResponseData m_game_account
Definition: GameHandler.h:27
void on_unknown_link_event(GameUnknownRequest *ev)
Definition: GameHandler.cpp:396
void on_idle(IdleEvent *ev)
Definition: GameHandler.cpp:197
GameLink * link()
Definition: GameHandler.h:42
uint32_t m_auth_account_id
Definition: GameHandler.h:28
void on_delete_character(DeleteCharacter *ev)
Definition: GameHandler.cpp:316
eTravelDirection m_direction
Definition: GameHandler.h:31
void on_game_db_error(GameDbErrorMessage *ev)
Definition: GameHandler.cpp:123
void on_client_disconnected_from_other_server(ClientDisconnectedMessage *ev)
Definition: GameHandler.cpp:424
void on_link_lost(SEGSEvent *ev)
Definition: GameHandler.cpp:281
Definition: GameDBSyncEvents.h:172
Definition: GameEvents.h:130
Definition: CRUD_Events.h:84
void on_update_server(UpdateServer *ev)
Definition: GameHandler.cpp:156
void on_disconnect(DisconnectRequest *ev)
Definition: GameHandler.cpp:254
void link(GameLink *l)
Definition: GameHandler.h:44
void on_expect_client(ExpectClientRequest *ev)
Definition: GameHandler.cpp:401
bool is_temporary() const
Definition: GameHandler.h:41
uint32_t auth_id() const
Definition: GameHandler.h:34
void on_account_data(GameAccountResponse *ev)
This handler is called when we get the account information for a.
Definition: GameHandler.cpp:133
void on_timeout(TimerEvent *ev)
Definition: GameHandler.cpp:230
void on_character_deleted(RemoveCharacterResponse *ev)
Definition: GameHandler.cpp:308
void on_map_req(MapServerAddrRequest *ev)
Definition: GameHandler.cpp:345
void dispatch(SEGSEvent *ev) override
Definition: GameHandler.cpp:55
Definition: GameHandler.h:25
Definition: GameHandler.h:24
void on_client_expected(ExpectMapClientResponse *ev)
Definition: GameHandler.cpp:334
void report_service_status()
Definition: GameHandler.cpp:223
uint32_t is_connected_to_map_server_id
Definition: GameHandler.h:29
void reap_stale_links()
Definition: GameHandler.cpp:435
void on_connection_request(ConnectRequest *ev)
Definition: GameHandler.cpp:149
Definition: EventProcessor.h:13
void reset()
Definition: GameHandler.h:35
void on_update_character(UpdateCharacter *ev)
Definition: GameHandler.cpp:185
Definition: GameHandler.h:50
uint8_t m_access_level
Definition: GameHandler.h:32
eTravelDirection
Definition: GameHandler.h:22
void on_client_connected_to_other_server(ClientConnectedMessage *ev)
Definition: GameHandler.cpp:410
Definition: CRUD_Events.h:54
Definition: GameEvents.h:42
Definition: SEGSEvent.h:69
void set_temporary(bool v)
Definition: GameHandler.h:40
GameServer * m_server
Definition: GameHandler.h:99
Definition: CRUD_Events.h:114
Definition: GameServer.h:18