Initial Socket Server implementation with CMakeLists.txt updated. Socket server will connect to world at this point.

This commit is contained in:
Chris M
2014-07-02 22:17:45 -05:00
committed by Arthur Ice
parent 6877e40b38
commit 3e0f6b8520
18 changed files with 735 additions and 6 deletions
+2
View File
@@ -23,6 +23,7 @@ SET(world_sources
perl_EQW.cpp
perl_HTTPRequest.cpp
queryserv.cpp
socket_server.cpp
ucs.cpp
wguild_mgr.cpp
world_logsys.cpp
@@ -53,6 +54,7 @@ SET(world_headers
LoginServerList.h
net.h
queryserv.h
socket_server.h
SoFCharCreateData.h
ucs.h
wguild_mgr.h
+13 -3
View File
@@ -46,6 +46,7 @@
#include "LauncherList.h"
#include "ucs.h"
#include "queryserv.h"
#include "socket_server.h"
#ifdef _WINDOWS
#define snprintf _snprintf
@@ -60,6 +61,7 @@ extern ClientList client_list;
extern LauncherList launcher_list;
extern UCSConnection UCSLink;
extern QueryServConnection QSLink;
extern Socket_Server_Connection SSLink;
extern volatile bool RunLoops;
ConsoleList console_list;
@@ -250,18 +252,26 @@ bool Console::Process() {
_log(WORLD__CONSOLE,"New launcher from %s:%d", inet_ntoa(in), GetPort());
launcher_list.Add(tcpc);
tcpc = 0;
} else if(tcpc->GetPacketMode() == EmuTCPConnection::packetModeUCS)
}
else if(tcpc->GetPacketMode() == EmuTCPConnection::packetModeUCS)
{
_log(WORLD__CONSOLE,"New UCS Connection from %s:%d", inet_ntoa(in), GetPort());
UCSLink.SetConnection(tcpc);
tcpc = 0;
}
else if(tcpc->GetPacketMode() == EmuTCPConnection::packetModeQueryServ)
else if(tcpc->GetPacketMode() == EmuTCPConnection::packetModeQueryServ)
{
_log(WORLD__CONSOLE,"New QS Connection from %s:%d", inet_ntoa(in), GetPort());
QSLink.SetConnection(tcpc);
tcpc = 0;
} else {
}
else if (tcpc->GetPacketMode() == EmuTCPConnection::packetModeSocket_Server)
{
_log(WORLD__CONSOLE, "New Socket Server Connection from %s:%d", inet_ntoa(in), GetPort());
SSLink.SetConnection(tcpc);
tcpc = 0;
}
else {
_log(WORLD__CONSOLE,"Unsupported packet mode from %s:%d", inet_ntoa(in), GetPort());
}
return false;
+4
View File
@@ -86,6 +86,7 @@
#include "AdventureManager.h"
#include "ucs.h"
#include "queryserv.h"
#include "socket_server.h"
TimeoutManager timeout_manager;
EQStreamFactory eqsf(WorldStream,9000);
@@ -97,6 +98,7 @@ LoginServerList loginserverlist;
EQWHTTPServer http_server;
UCSConnection UCSLink;
QueryServConnection QSLink;
Socket_Server_Connection SSLink;
LauncherList launcher_list;
AdventureManager adventure_manager;
DBAsync *dbasync = nullptr;
@@ -454,6 +456,8 @@ int main(int argc, char** argv) {
QSLink.Process();
SSLink.Process();
LFPGroupList.Process();
adventure_manager.Process();
+127
View File
@@ -0,0 +1,127 @@
#include "../common/debug.h"
#include "Socket_Server.h"
#include "WorldConfig.h"
#include "clientlist.h"
#include "zonelist.h"
#include "../common/logsys.h"
#include "../common/logtypes.h"
#include "../common/md5.h"
#include "../common/EmuTCPConnection.h"
#include "../common/packet_dump.h"
extern ClientList client_list;
extern ZSList zoneserver_list;
Socket_Server_Connection::Socket_Server_Connection()
{
Stream = 0;
authenticated = false;
}
void Socket_Server_Connection::SetConnection(EmuTCPConnection *inStream)
{
if(Stream)
{
_log(SOCKET_SERVER__ERROR, "Incoming Socket_Server Connection while we were already connected to a Socket_Server.");
Stream->Disconnect();
}
Stream = inStream;
authenticated = false;
}
bool Socket_Server_Connection::Process()
{
if (!Stream || !Stream->Connected())
return false;
ServerPacket *pack = 0;
while((pack = Stream->PopPacket()))
{
if (!authenticated)
{
if (WorldConfig::get()->SharedKey.length() > 0)
{
if (pack->opcode == ServerOP_ZAAuth && pack->size == 16)
{
uint8 tmppass[16];
MD5::Generate((const uchar*) WorldConfig::get()->SharedKey.c_str(), WorldConfig::get()->SharedKey.length(), tmppass);
if (memcmp(pack->pBuffer, tmppass, 16) == 0)
authenticated = true;
else
{
struct in_addr in;
in.s_addr = GetIP();
_log(SOCKET_SERVER__ERROR, "Socket_Server authorization failed.");
ServerPacket* pack = new ServerPacket(ServerOP_ZAAuthFailed);
SendPacket(pack);
delete pack;
Disconnect();
return false;
}
}
else
{
struct in_addr in;
in.s_addr = GetIP();
_log(SOCKET_SERVER__ERROR, "Socket_Server_ authorization failed.");
ServerPacket* pack = new ServerPacket(ServerOP_ZAAuthFailed);
SendPacket(pack);
delete pack;
Disconnect();
return false;
}
}
else
{
_log(SOCKET_SERVER__ERROR,"**WARNING** You have not configured a world shared key in your config file. You should add a <key>STRING</key> element to your <world> element to prevent unauthorized zone access.");
authenticated = true;
}
delete pack;
continue;
}
switch(pack->opcode)
{
case 0:
break;
case ServerOP_KeepAlive:
{
// ignore this
break;
}
case ServerOP_ZAAuth:
{
_log(SOCKET_SERVER__ERROR, "Got authentication from Socket_Server_ when they are already authenticated.");
break;
}
case ServerOP_LFGuildUpdate:
{
zoneserver_list.SendPacket(pack);
break;
}
default:
{
_log(SOCKET_SERVER__ERROR, "Unknown ServerOPcode from Socket_Server_ 0x%04x, size %d", pack->opcode, pack->size);
DumpPacket(pack->pBuffer, pack->size);
break;
}
}
delete pack;
}
return(true);
}
bool Socket_Server_Connection::SendPacket(ServerPacket* pack)
{
if(!Stream)
return false;
return Stream->SendPacket(pack);
}
+23
View File
@@ -0,0 +1,23 @@
#ifndef Socket_Server__H
#define Socket_Server__H
#include "../common/types.h"
#include "../common/EmuTCPConnection.h"
#include "../common/servertalk.h"
class Socket_Server_Connection
{
public:
Socket_Server_Connection();
void SetConnection(EmuTCPConnection *inStream);
bool Process();
bool SendPacket(ServerPacket* pack);
void Disconnect() { if(Stream) Stream->Disconnect(); }
void SendMessage(const char *From, const char *Message);
private:
inline uint32 GetIP() const { return Stream ? Stream->GetrIP() : 0; }
EmuTCPConnection *Stream;
bool authenticated;
};
#endif /*Socket_Server__H_*/