SEGS  0.4.2
Super Entity Game Server
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AuthLink.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 
10 #include "LinkLevelEvent.h"
11 #include "Buffer.h"
12 #include "EventProcessor.h"
17 
18 #include <ace/ACE.h>
19 #include <ace/Synch.h>
20 #include <ace/SOCK_Stream.h>
21 #include <ace/Message_Queue.h>
22 #include <ace/Message_Block.h>
23 #include <ace/Thread_Mutex.h>
24 #include <ace/Event_Handler.h>
25 #include <ace/Svc_Handler.h>
26 #include <ace/Reactor_Notification_Strategy.h>
27 class SEGSEvent;
28 
29 enum class AuthLinkType
30 {
31  Server = 0,
32  Client = 1
33 };
34 
35 // AuthLinks are created when connection is accepted.
36 // They serve as one of the primary event sources in the system, the other being Timers
37 // Whenever new bytes are received, the AuthLink tries to convert them into proper higher level Events,
38 // And posts them to g_target
39 // Each AuthLink serves as a Client's connection context
40 class AuthLink final : public LinkBase
41 {
42  typedef EventProcessor super;
43  typedef ACE_Reactor_Notification_Strategy tNotifyStrategy;
44  friend class AuthHandler; // auth handler changes our m_state variable
45  enum eState
46  {
47  INITIAL,
48  CONNECTED,
49  AUTHORIZED,
50  CLIENT_SERVSELECT,
51  CLIENT_AWAITING_DISCONNECT,
52  DISCONNECTED
53  };
54 
55 public:
56  typedef ACE_SOCK_Stream stream_type;
57  typedef ACE_INET_Addr addr_type;
58 
59 
60  AuthLink();
62  ~AuthLink(void) override;
63 
64  int open(void * = nullptr) override;
65  int handle_input (ACE_HANDLE) override;
66  int handle_output(ACE_HANDLE fd = ACE_INVALID_HANDLE) override;
67  int handle_close(ACE_HANDLE handle,ACE_Reactor_Mask close_mask) override;
68  void dispatch(SEGSEvent *ev) override;
69  stream_type & peer() {return m_peer;}
71  void init_crypto(int vers,uint32_t seed);
72  ACE_HANDLE get_handle (void) const override {return m_peer.get_handle();}
73 protected:
74  EventProcessor *m_target; // Target handler of this link
78  tNotifyStrategy m_notifier;
81  ACE_Thread_Mutex *m_buffer_mutex;
83  eState m_state;
85 
86  bool send_buffer();
87  void encode_buffer(const AuthLinkEvent *ev,size_t start);
88  void set_protocol_version(int vers);
89  eAuthPacketType OpcodeToType(uint8_t opcode) const;
91 };
92 
93 
int handle_close(ACE_HANDLE handle, ACE_Reactor_Mask close_mask) override
Called when this handler is removed from the ACE_Reactor.
Definition: AuthLink.cpp:297
AuthLink()
Definition: AuthLink.cpp:18
Definition: SEGSEvent.h:32
void encode_buffer(const AuthLinkEvent *ev, size_t start)
Definition: AuthLink.cpp:217
int open(void *=nullptr) override
Called when we start to service a new connection, here we tell reactor to wake us when queue() is not...
Definition: AuthLink.cpp:132
void dispatch(SEGSEvent *ev) override
Definition: AuthLink.cpp:309
Definition: AuthPacketCodec.h:24
eAuthPacketType OpcodeToType(uint8_t opcode) const
Convert opcode byte to corresponding packet type.
Definition: AuthLink.cpp:56
SEGSEvent * bytes_to_event()
tries to convert the available bytes into a valid AuthHandler LinkLevelEvent.
Definition: AuthLink.cpp:89
Definition: ILink.h:14
Definition: Buffer.h:17
void set_protocol_version(int vers)
Definition: AuthLink.cpp:281
int handle_output(ACE_HANDLE fd=ACE_INVALID_HANDLE) override
Called from ACEReactor when there are events in our queue()
Definition: AuthLink.cpp:183
bool send_buffer()
Definition: AuthLink.cpp:244
int handle_input(ACE_HANDLE) override
Called when new bytes are available.
Definition: AuthLink.cpp:153
~AuthLink(void) override
Definition: AuthLink.cpp:41
Definition: EventProcessor.h:13
Definition: AuthEvents.h:15
eAuthPacketType
Definition: AuthOpcodes.h:10
void init_crypto(int vers, uint32_t seed)
Definition: AuthLink.cpp:45
Definition: AuthHandler.h:73