Updated Copyright year to 2013
[getmangos.git] / src / mangosd / RASocket.h
blob83844bcedda947b67ea4492daa4b2930bdb3f260
1 /*
2 * Copyright (C) 2005-2013 MaNGOS <http://getmangos.com/>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 /// \addtogroup mangosd
20 /// @{
21 /// \file
23 #ifndef _RASOCKET_H
24 #define _RASOCKET_H
26 #include "Common.h"
27 #include <ace/Synch_Traits.h>
28 #include <ace/Svc_Handler.h>
29 #include <ace/SOCK_Acceptor.h>
30 #include <ace/Acceptor.h>
31 #include <ace/Thread_Mutex.h>
32 #include <ace/Semaphore.h>
34 #define RA_BUFF_SIZE 8192
37 /// Remote Administration socket
38 typedef ACE_Svc_Handler < ACE_SOCK_STREAM, ACE_NULL_SYNCH> RAHandler;
39 class RASocket: protected RAHandler
41 public:
42 ACE_Semaphore pendingCommands;
43 typedef ACE_Acceptor<RASocket, ACE_SOCK_ACCEPTOR > Acceptor;
44 friend class ACE_Acceptor<RASocket, ACE_SOCK_ACCEPTOR >;
46 int sendf(const char*);
48 protected:
49 /// things called by ACE framework.
50 RASocket(void);
51 virtual ~RASocket(void);
53 /// Called on open ,the void* is the acceptor.
54 virtual int open(void*) override;
56 /// Called on failures inside of the acceptor, don't call from your code.
57 virtual int close(int);
59 /// Called when we can read from the socket.
60 virtual int handle_input(ACE_HANDLE = ACE_INVALID_HANDLE) override;
62 /// Called when the socket can write.
63 virtual int handle_output(ACE_HANDLE = ACE_INVALID_HANDLE) override;
65 /// Called when connection is closed or error happens.
66 virtual int handle_close(ACE_HANDLE = ACE_INVALID_HANDLE,
67 ACE_Reactor_Mask = ACE_Event_Handler::ALL_EVENTS_MASK);
69 private:
70 bool outActive;
72 char inputBuffer[RA_BUFF_SIZE];
73 uint32 inputBufferLen;
75 ACE_Thread_Mutex outBufferLock;
76 char outputBuffer[RA_BUFF_SIZE];
77 uint32 outputBufferLen;
79 uint32 accId;
80 AccountTypes accAccessLevel;
81 bool bSecure; // kick on wrong pass, non exist. user OR user with no priv
82 // will protect from DOS, bruteforce attacks
83 bool bStricted; // not allow execute console only commands (SEC_CONSOLE) remotly
84 AccountTypes iMinLevel;
85 enum
87 NONE, // initial value
88 LG, // only login was entered
89 OK, // both login and pass were given, they were correct and user has enough priv.
90 } stage;
92 static void zprint(void* callbackArg, const char* szText);
93 static void commandFinished(void* callbackArg, bool success);
95 #endif
96 /// @}