SEGS  0.4.2
Super Entity Game Server
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 - 2018 SEGS Team (see Authors.txt)
5  * This software is licensed! (See License.txt 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 struct RetrieveAccountResponse;
24 struct ValidatePasswordResponse;
25 
27 {
29  //AUTH_OK = 0,
32  AUTH_INVALID_ACCOUNT = 2, // no client side message
35  // 5- SSN not available
36  // 6 - no server list
45 }; // this is a public type so other servers can pass us valid errors
46 
48 {
50  {
56  };
57  std::unique_ptr<RetrieveAccountResponseData> m_auth_data;
58  uint32_t m_auth_id=0;
61 
62  uint32_t auth_id() const { return m_auth_id; }
63  // those functions store temporariness state of the link in the lowest bit of the pointer
64  void set_temporary(bool v) { (intptr_t &)(m_link) = (intptr_t(m_link) & ~1) | intptr_t(v); }
65  bool is_temporary() const { return intptr_t(m_link) & 1; }
66  AuthLink * link() { return (AuthLink *)(intptr_t(m_link) & ~1); }
68  void link(AuthLink *l) { m_link = l; }
69 
70 protected:
71  AuthLink * m_link = nullptr;
72 };
74 {
76  using MTGuard = ACE_Guard<ACE_Thread_Mutex>;
77  using ServerMap = std::map<uint8_t,GameServerStatusData>;
78 protected:
79  static uint64_t s_last_session_id;
82  AuthServer *m_authserv = nullptr;
83  ACE_Thread_Mutex m_server_mutex;
85 
86  bool isClientConnectedAnywhere(uint32_t client_id);
87  void reap_stale_links();
88 
90  // internal events
91  void on_timeout(TimerEvent *ev);
93  // Message bus subscriptions
94  void on_server_status_change(GameServerStatusMessage *ev);
96  // function that send messages into the link
97  void auth_error(EventProcessor *lnk,uint32_t code);
99  // incoming link level event handlers
100  void on_connect(ConnectEvent *ev);
101  void on_disconnect(DisconnectEvent *ev);
102  void on_login( LoginRequest *ev );
105 
107  // Server <-> server event handlers
108  void on_retrieve_account_response(RetrieveAccountResponse *msg);
109  void on_client_expected(ExpectClientResponse *ev);
110  void on_client_connected_to_other_server(ClientConnectedMessage *ev);
111  void on_client_disconnected_from_other_server(ClientDisconnectedMessage *ev);
112  void on_db_error(AuthDbErrorMessage *ev);
113 
114  void dispatch(SEGSEvent *ev) override;
115 public:
116  AuthHandler(AuthServer *our_server);
117 };
Instances of SEGSTimer class are used to schedule events in the future.
Definition: SEGSTimer.h:18
Definition: AuthHandler.h:34
eClientState
Definition: AuthHandler.h:49
Definition: AuthHandler.h:51
Definition: AuthHandler.h:44
void link(AuthLink *l)
Definition: AuthHandler.h:68
ACE_Thread_Mutex m_server_mutex
Definition: AuthHandler.h:83
Definition: AuthHandler.h:55
eClientState m_state
Definition: AuthHandler.h:59
Definition: SEGSEvent.h:32
void on_retrieve_account_response(RetrieveAccountResponse *msg)
This function handles database server informing us about account details.
Definition: AuthHandler.cpp:188
bool isClientConnectedAnywhere(uint32_t client_id)
Definition: AuthHandler.cpp:171
Definition: AuthHandler.h:38
eAuthError
Definition: AuthHandler.h:26
uint32_t m_auth_id
Definition: AuthHandler.h:58
Definition: LinkLevelEvent.h:28
uint32_t auth_id() const
Definition: AuthHandler.h:62
Definition: AuthHandler.h:53
Definition: AuthHandler.h:41
Definition: AuthHandler.h:47
Definition: AuthHandler.h:52
Definition: ServerListRequest.h:11
void on_server_selected(ServerSelectRequest *ev)
Definition: AuthHandler.cpp:367
void on_login(LoginRequest *ev)
Definition: AuthHandler.cpp:270
AuthServer * m_authserv
Definition: AuthHandler.h:82
Definition: AuthHandler.h:54
void on_client_expected(ExpectClientResponse *ev)
Definition: AuthHandler.cpp:391
Definition: AuthHandler.h:33
void auth_error(EventProcessor *lnk, uint32_t code)
Definition: AuthHandler.cpp:166
void dispatch(SEGSEvent *ev) override
Definition: AuthHandler.cpp:49
void on_timeout(TimerEvent *ev)
Definition: AuthHandler.cpp:111
void reap_stale_links()
Definition: AuthHandler.cpp:425
static uint64_t s_last_session_id
Monotonically incrementing session ids, starting at 1, to make 0 special.
Definition: AuthHandler.h:79
void on_server_status_change(GameServerStatusMessage *ev)
Definition: AuthHandler.cpp:431
void on_client_disconnected_from_other_server(ClientDisconnectedMessage *ev)
Definition: AuthHandler.cpp:415
Definition: AuthHandler.h:32
Definition: LinkLevelEvent.h:13
MessageBusEndpoint m_message_bus_endpoint
Definition: AuthHandler.h:80
Definition: AuthHandler.h:40
void on_server_list_request(ServerListRequest *ev)
Definition: AuthHandler.cpp:330
The MessageBusEndpoint class is responsible for:
Definition: MessageBusEndpoint.h:18
AuthLink * link()
Definition: AuthHandler.h:66
uint32_t is_connected_to_game_server_id
Definition: AuthHandler.h:60
void set_temporary(bool v)
Definition: AuthHandler.h:64
void on_client_connected_to_other_server(ClientConnectedMessage *ev)
Definition: AuthHandler.cpp:404
Definition: AuthHandler.h:39
ServerMap m_known_game_servers
Definition: AuthHandler.h:84
Definition: LoginRequest.h:18
Definition: EventProcessor.h:13
Definition: AuthHandler.h:43
SessionStore m_sessions
Definition: AuthHandler.h:81
AuthLink * m_link
Definition: AuthHandler.h:71
void on_connect(ConnectEvent *ev)
Definition: AuthHandler.cpp:121
Definition: ServerSelectRequest.h:11
Definition: AuthHandler.h:37
main class of the authentication server, it controls the AuthHandler instances
Definition: AuthServer.h:20
void on_disconnect(DisconnectEvent *ev)
Definition: AuthHandler.cpp:138
Definition: AuthHandler.h:42
void on_db_error(AuthDbErrorMessage *ev)
Definition: AuthHandler.cpp:437
std::unique_ptr< RetrieveAccountResponseData > m_auth_data
Definition: AuthHandler.h:57
Definition: AuthHandler.h:30
Definition: AuthHandler.h:28
Definition: SEGSEvent.h:69
AuthHandler(AuthServer *our_server)
Definition: AuthHandler.cpp:103
bool is_temporary() const
Definition: AuthHandler.h:65
Definition: AuthHandler.h:31
Definition: AuthHandler.h:73