SEGS  0.6.1-develop [39915b3b]
Super Entity Game Server
AuthHandler.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
11 #include "AuthProtocol/AuthLink.h"
14 #include "Servers/ClientManager.h"
15 #include "EventProcessor.h"
16 
17 #include <ace/Thread_Mutex.h>
18 #include <ace/Guard_T.h>
19 #include <map>
20 
21 class AuthServer;
22 class SEGSTimer;
23 namespace SEGSEvents
24 {
25 struct RetrieveAccountResponse;
26 struct ValidatePasswordResponse;
27 class Timeout;
28 }
29 
31 {
33  //AUTH_OK = 0,
36  AUTH_INVALID_ACCOUNT = 2, // no client side message
39  // 5- SSN not available
40  // 6 - no server list
49 }; // this is a public type so other servers can pass us valid errors
50 
52 {
54  {
55  CLIENT_DISCONNECTED=0,
59  CLIENT_CONNECTED
60  };
61  std::unique_ptr<SEGSEvents::RetrieveAccountResponseData> m_auth_data;
62  uint32_t m_auth_id=0;
63  eClientState m_state = NOT_LOGGED_IN;
64  uint32_t is_connected_to_game_server_id=0;
65 
66  uint32_t auth_id() const { return m_auth_id; }
67  // those functions store temporariness state of the link in the lowest bit of the pointer
68  void set_temporary(bool v) { (intptr_t &)(m_link) = (intptr_t(m_link) & ~1) | intptr_t(v); }
69  bool is_temporary() const { return intptr_t(m_link) & 1; }
70  AuthLink * link() { return (AuthLink *)(intptr_t(m_link) & ~1); }
72  void link(AuthLink *l) { m_link = l; }
73 
74 protected:
75  AuthLink * m_link = nullptr;
76 };
78 {
80  using MTGuard = ACE_Guard<ACE_Thread_Mutex>;
81  using ServerMap = std::map<uint8_t,SEGSEvents::GameServerStatusData>;
82 protected:
84  static uint64_t s_last_session_id;
85  MessageBusEndpoint m_message_bus_endpoint;
86  SessionStore m_sessions;
87  AuthServer *m_authserv = nullptr;
88  ACE_Thread_Mutex m_server_mutex;
89  ServerMap m_known_game_servers;
90 
91  bool isClientConnectedAnywhere(uint32_t client_id);
92  void reap_stale_links();
93  void serialize_from(std::istream &is) override;
94  void serialize_to(std::ostream &is) override;
95 
97  // internal events
98  void on_timeout(SEGSEvents::Timeout *ev);
100  // Message bus subscriptions
101  void on_server_status_change(SEGSEvents::GameServerStatusMessage *ev);
103  // function that send messages into the link
104  void auth_error(EventSrc *lnk, uint32_t code);
106  // incoming link level event handlers
107  void on_connect(SEGSEvents::Connect *ev);
108  void on_disconnect(SEGSEvents::Disconnect *ev);
109  void on_login( SEGSEvents::LoginRequest *ev );
110  void on_server_list_request( SEGSEvents::ServerListRequest *ev );
111  void on_server_selected(SEGSEvents::ServerSelectRequest *ev);
112 
114  // Server <-> server event handlers
115  void on_retrieve_account_response(SEGSEvents::RetrieveAccountResponse *msg);
116  void on_client_expected(SEGSEvents::ExpectClientResponse *ev);
117  void on_client_connected_to_other_server(SEGSEvents::ClientConnectedMessage *ev);
118  void on_client_disconnected_from_other_server(SEGSEvents::ClientDisconnectedMessage *ev);
119  void on_db_error(SEGSEvents::AuthDbStatusMessage *ev);
120 
121  void dispatch(SEGSEvents::Event *ev) override;
122 public:
123  AuthHandler(AuthServer *our_server);
124 };
Instances of SEGSTimer class are used to schedule events in the future.
Definition: SEGSTimer.h:18
Definition: AuthHandler.h:38
eClientState
Definition: AuthHandler.h:53
std::unique_ptr< SEGSEvents::RetrieveAccountResponseData > m_auth_data
Definition: AuthHandler.h:61
Definition: AuthHandler.h:48
void link(AuthLink *l)
Definition: AuthHandler.h:72
Definition: EventProcessor.h:14
Definition: AuthHandler.h:42
eAuthError
Definition: AuthHandler.h:30
Definition: seq_definitions.h:23
Definition: AuthHandler.h:57
Definition: AuthHandler.h:45
Definition: LinkLevelEvent.h:13
Definition: AuthHandler.h:51
Definition: AuthHandler.h:56
uint32_t auth_id() const
Definition: AuthHandler.h:66
Definition: AuthHandler.h:58
Definition: AuthHandler.h:37
Definition: AuthHandler.h:36
Definition: AuthHandler.h:44
The MessageBusEndpoint class is responsible for:
Definition: MessageBusEndpoint.h:18
AuthLink * link()
Definition: AuthHandler.h:70
void set_temporary(bool v)
Definition: AuthHandler.h:68
bool is_temporary() const
Definition: AuthHandler.h:69
Definition: AuthHandler.h:43
Definition: EventProcessor.h:22
Definition: AuthHandler.h:47
Definition: AuthHandler.h:41
main class of the authentication server, it controls the AuthHandler instances
Definition: AuthServer.h:20
Definition: AuthHandler.h:46
Definition: AuthHandler.h:34
Definition: AuthHandler.h:32
#define IMPL_ID(EventProcessorChildType)
Definition: EventProcessor.h:44
Definition: AuthHandler.h:35
Definition: AuthHandler.h:77