* added missing files from #136. thx bLuma!
This commit is contained in:
parent
25c2f09525
commit
381edc0a3a
59
src/Client/ControlSocket.cpp
Normal file
59
src/Client/ControlSocket.cpp
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
#include "common.h"
|
||||||
|
#include "PseuWoW.h"
|
||||||
|
#include "RemoteController.h"
|
||||||
|
#include "ControlSocket.h"
|
||||||
|
|
||||||
|
ControlSocket::ControlSocket(SocketHandler& h) : TcpSocket(h)
|
||||||
|
{
|
||||||
|
_ok = false;
|
||||||
|
DEBUG(logdebug("ControlSocket created"));
|
||||||
|
}
|
||||||
|
|
||||||
|
void ControlSocket::OnAccept(void)
|
||||||
|
{
|
||||||
|
logdetail("ControlSocket: Incoming connection from %s:%u [host:%s]",GetRemoteAddress().c_str(),GetRemotePort(),GetRemoteHostname().c_str());
|
||||||
|
|
||||||
|
// must perform some crappy ptr conversion here, doesnt want to typecast SocketHandler -> ControlSocketHandler directly
|
||||||
|
SocketHandler& hnd = Handler();
|
||||||
|
ControlSocketHandler *chnd = static_cast<ControlSocketHandler*>(&hnd);
|
||||||
|
_instance = chnd->GetInstance();
|
||||||
|
DEBUG(logdebug("ControlSocket: setting instance = %X",_instance));
|
||||||
|
|
||||||
|
// accept only connections from one host for now, if set
|
||||||
|
if(_instance->GetConf()->rmcontrolhost.length()
|
||||||
|
&& !(GetRemoteAddress() == _instance->GetConf()->rmcontrolhost || GetRemoteHostname() == _instance->GetConf()->rmcontrolhost))
|
||||||
|
{
|
||||||
|
logdetail("ControlSocket: connection rejected. closing.");
|
||||||
|
SetCloseAndDelete(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_ok = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ControlSocket::OnRead(void)
|
||||||
|
{
|
||||||
|
if(!_ok)
|
||||||
|
return;
|
||||||
|
TcpSocket::OnRead();
|
||||||
|
uint32 len = ibuf.GetLength();
|
||||||
|
if(!len)
|
||||||
|
{
|
||||||
|
logdetail("ControlSocket: connection to %s:%u closed.",GetRemoteAddress().c_str(),GetRemotePort());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *buf = new char[len];
|
||||||
|
ibuf.Read(buf,len);
|
||||||
|
if(buf[0]==0)
|
||||||
|
{
|
||||||
|
// reserved for future applications
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(_instance && _instance->GetScripts())
|
||||||
|
_instance->GetScripts()->RunSingleLine(&buf[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
delete [] buf;
|
||||||
|
}
|
||||||
23
src/Client/ControlSocket.h
Normal file
23
src/Client/ControlSocket.h
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
#ifndef CONTROLSOCKET_H
|
||||||
|
#define CONTROLSOCKET_H
|
||||||
|
|
||||||
|
#include "Network/TcpSocket.h"
|
||||||
|
#include "RemoteController.h"
|
||||||
|
|
||||||
|
class ControlSocket : public TcpSocket
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
ControlSocket(SocketHandler& h);
|
||||||
|
|
||||||
|
void SetInstance(PseuInstance *in) { _instance = in; }
|
||||||
|
|
||||||
|
void OnAccept();
|
||||||
|
void OnRead();
|
||||||
|
|
||||||
|
private:
|
||||||
|
PseuInstance *_instance;
|
||||||
|
bool _ok;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
38
src/Client/RemoteController.cpp
Normal file
38
src/Client/RemoteController.cpp
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
#include "common.h"
|
||||||
|
#include "log.h"
|
||||||
|
#include "ControlSocket.h"
|
||||||
|
#include "Network/ListenSocket.h"
|
||||||
|
#include "RemoteController.h"
|
||||||
|
|
||||||
|
RemoteController::RemoteController(PseuInstance *in,uint32 port)
|
||||||
|
{
|
||||||
|
DEBUG(logdebug("RemoteController: setting instance = %X",in));
|
||||||
|
h.SetInstance(in);
|
||||||
|
_mustdie = false;
|
||||||
|
_instance = in;
|
||||||
|
ListenSocket<ControlSocket> *ls = new ListenSocket<ControlSocket>(h);
|
||||||
|
if(ls->Bind(port))
|
||||||
|
{
|
||||||
|
logerror("RemoteController: Can't bind to port %u",port);
|
||||||
|
_mustdie = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
h.Add(ls);
|
||||||
|
log("RemoteController: listening on port %u",port);
|
||||||
|
}
|
||||||
|
|
||||||
|
RemoteController::~RemoteController()
|
||||||
|
{
|
||||||
|
DEBUG(logdebug("~RemoteController()"));
|
||||||
|
}
|
||||||
|
|
||||||
|
void RemoteController::Update(void)
|
||||||
|
{
|
||||||
|
if(_mustdie)
|
||||||
|
return;
|
||||||
|
h.Select(0,0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
37
src/Client/RemoteController.h
Normal file
37
src/Client/RemoteController.h
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
#ifndef REMOTECONTROLLER_H
|
||||||
|
#define REMOTECONTROLLER_H
|
||||||
|
|
||||||
|
#include "Network/SocketHandler.h"
|
||||||
|
|
||||||
|
class PseuInstance;
|
||||||
|
class ControlSocket;
|
||||||
|
|
||||||
|
class ControlSocketHandler : public SocketHandler
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
void SetInstance(PseuInstance *in) { _instance = in; }
|
||||||
|
PseuInstance *GetInstance(void) { return _instance; }
|
||||||
|
private:
|
||||||
|
PseuInstance *_instance;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class RemoteController
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
RemoteController(PseuInstance*,uint32 port);
|
||||||
|
~RemoteController();
|
||||||
|
void SetPermission(uint8 p) { _perm = p; }
|
||||||
|
void Update(void);
|
||||||
|
bool MustDie(void) { return _mustdie; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
ControlSocketHandler h;
|
||||||
|
bool _mustdie;
|
||||||
|
PseuInstance *_instance;
|
||||||
|
uint8 _perm;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
Loading…
x
Reference in New Issue
Block a user