diff options
| author | click <none@none> | 2010-07-23 09:26:23 +0200 |
|---|---|---|
| committer | click <none@none> | 2010-07-23 09:26:23 +0200 |
| commit | 3f9ea75bfa990b2079c581052073fcf4962dd594 (patch) | |
| tree | 919ffc43bd81fd5b0949c9edac5a8c29b7918b3e /src/server/worldserver/RemoteAccess | |
| parent | 912a099d491a58e068994c63a1055ab17af37634 (diff) | |
Add SOAP-implementation (based on Benjys patch and adapted for latest core by xk1)
--HG--
branch : trunk
Diffstat (limited to 'src/server/worldserver/RemoteAccess')
| -rw-r--r-- | src/server/worldserver/RemoteAccess/RASocket.cpp | 68 | ||||
| -rw-r--r-- | src/server/worldserver/RemoteAccess/RASocket.h | 16 |
2 files changed, 30 insertions, 54 deletions
diff --git a/src/server/worldserver/RemoteAccess/RASocket.cpp b/src/server/worldserver/RemoteAccess/RASocket.cpp index 35c2514b377..98587c935d0 100644 --- a/src/server/worldserver/RemoteAccess/RASocket.cpp +++ b/src/server/worldserver/RemoteAccess/RASocket.cpp @@ -31,48 +31,28 @@ #include "Util.h" #include "World.h" -/// \todo Make this thread safe if in the future 2 admins should be able to log at the same time. -SOCKET r; - #define dropclient {Sendf("I'm busy right now, come back later."); \ SetCloseAndDelete(); \ return; \ } -uint32 iSession=0; ///< Session number (incremented each time a new connection is made) -unsigned int iUsers=0; ///< Number of active administrators - -typedef int(* pPrintf)(const char*,...); - -void ParseCommand(CliCommandHolder::Print*, char*command); - /// RASocket constructor RASocket::RASocket(ISocketHandler &h): TcpSocket(h) { - ///- Increment the session number - iSess =iSession++ ; - ///- Get the config parameters bSecure = sConfig.GetBoolDefault( "RA.Secure", true ); iMinLevel = sConfig.GetIntDefault( "RA.MinLevel", 3 ); ///- Initialize buffer and data iInputLength=0; - buff=new char[RA_BUFF_SIZE]; stage=NONE; } /// RASocket destructor RASocket::~RASocket() { - ///- Delete buffer and decrease active admins count - delete [] buff; - sLog.outRemote("Connection was closed.\n"); - - if(stage==OK) - iUsers--; } /// Accept an incoming connection @@ -80,12 +60,8 @@ void RASocket::OnAccept() { std::string ss=GetRemoteAddress(); sLog.outRemote("Incoming connection from %s.\n",ss.c_str()); - ///- If there is already an active admin, drop the connection - if(iUsers) - dropclient - - ///- Else print Motd - Sendf("%s\r\n",sWorld.GetMotd()); + ///- print Motd + Sendf("%s\r\n",sWorld.GetMotd()); } /// Read data from the network @@ -102,11 +78,7 @@ void RASocket::OnRead() return; } - ///- If there is already an active admin (other than you), drop the connection - if(stage!=OK && iUsers) - dropclient - - char *inp = new char [sz+1]; + char *inp = new char [sz+1]; ibuf.Read(inp,sz); /// \todo Can somebody explain this 'Linux bugfix'? @@ -209,9 +181,8 @@ void RASocket::OnRead() if(check) { - r=GetSocket(); + GetSocket(); stage=OK; - ++iUsers; Sendf("+Logged in.\r\n"); sLog.outRemote("User %s has logged in.\n",szLogin.c_str()); @@ -231,7 +202,10 @@ void RASocket::OnRead() if(strlen(buff)) { sLog.outRemote("Got '%s' cmd.\n",buff); - sWorld.QueueCliCommand(&RASocket::zprint , buff); + SetDeleteByHandler(false); + CliCommandHolder* cmd = new CliCommandHolder(this, buff, &RASocket::zprint, &RASocket::commandFinished); + sWorld.QueueCliCommand(cmd); + ++pendingCommands; } else Sendf("TC>"); @@ -243,23 +217,21 @@ void RASocket::OnRead() } /// Output function -void RASocket::zprint( const char * szText ) +void RASocket::zprint(void* callbackArg, const char * szText ) { if( !szText ) return; - #ifdef RA_CRYPT - - char *megabuffer=strdup(szText); - unsigned int sz=strlen(megabuffer); - Encrypt(megabuffer,sz); - send(r,megabuffer,sz,0); - free(megabuffer); - - #else - unsigned int sz=strlen(szText); - send(r,szText,sz,0); - - #endif + send(((RASocket*)callbackArg)->GetSocket(), szText, sz, 0); } + +void RASocket::commandFinished(void* callbackArg, bool success) +{ + RASocket* raSocket = (RASocket*)callbackArg; + raSocket->Sendf("TC>"); + uint64 remainingCommands = --raSocket->pendingCommands; + + if(remainingCommands == 0) + raSocket->SetDeleteByHandler(true); + } diff --git a/src/server/worldserver/RemoteAccess/RASocket.h b/src/server/worldserver/RemoteAccess/RASocket.h index 25a21d52044..4d491e5a436 100644 --- a/src/server/worldserver/RemoteAccess/RASocket.h +++ b/src/server/worldserver/RemoteAccess/RASocket.h @@ -28,11 +28,14 @@ #include "TcpSocket.h" #include "Common.h" +#include <ace/Synch_Traits.h> #define RA_BUFF_SIZE 1024 class ISocketHandler; +typedef ACE_Atomic_Op<ACE_SYNCH_MUTEX, uint64> AtomicInt; + /// Remote Administration socket class RASocket: public TcpSocket { @@ -44,14 +47,14 @@ class RASocket: public TcpSocket void OnAccept(); void OnRead(); - private: + AtomicInt pendingCommands; - char * buff; + private: + char buff[RA_BUFF_SIZE]; std::string szLogin; - uint32 iSess; + unsigned int iInputLength; - bool bLog; - bool bSecure; //kick on wrong pass, non exist. user, user with no priv + bool bSecure; //will protect from DOS, bruteforce attacks //some 'smart' protection must be added for more security uint8 iMinLevel; @@ -62,7 +65,8 @@ class RASocket: public TcpSocket OK, //both login and pass were given, and they are correct and user have enough priv. }stage; - static void zprint( const char * szText ); + static void zprint(void* callbackArg, const char * szText ); + static void commandFinished(void* callbackArg, bool success); }; #endif /// @} |
