mirror of
https://github.com/EQEmu/Server.git
synced 2026-08-29 12:47:54 +00:00
svn -> git Migration
This commit is contained in:
+129
@@ -0,0 +1,129 @@
|
||||
#include "../common/debug.h"
|
||||
#include "ucs.h"
|
||||
#include "WorldConfig.h"
|
||||
#include "../common/logsys.h"
|
||||
#include "../common/logtypes.h"
|
||||
#include "../common/md5.h"
|
||||
#include "../common/EmuTCPConnection.h"
|
||||
#include "../common/packet_dump.h"
|
||||
|
||||
UCSConnection::UCSConnection()
|
||||
{
|
||||
Stream = 0;
|
||||
authenticated = false;
|
||||
}
|
||||
|
||||
void UCSConnection::SetConnection(EmuTCPConnection *inStream)
|
||||
{
|
||||
if(Stream)
|
||||
{
|
||||
_log(UCS__ERROR, "Incoming UCS Connection while we were already connected to a UCS.");
|
||||
Stream->Disconnect();
|
||||
}
|
||||
|
||||
Stream = inStream;
|
||||
|
||||
authenticated = false;
|
||||
}
|
||||
|
||||
bool UCSConnection::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(UCS__ERROR, "UCS 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(UCS__ERROR, "UCS authorization failed.");
|
||||
ServerPacket* pack = new ServerPacket(ServerOP_ZAAuthFailed);
|
||||
SendPacket(pack);
|
||||
delete pack;
|
||||
Disconnect();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_log(UCS__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 unauthroized zone access.");
|
||||
authenticated = true;
|
||||
}
|
||||
delete pack;
|
||||
continue;
|
||||
}
|
||||
switch(pack->opcode)
|
||||
{
|
||||
case 0:
|
||||
break;
|
||||
|
||||
case ServerOP_KeepAlive:
|
||||
{
|
||||
// ignore this
|
||||
break;
|
||||
}
|
||||
case ServerOP_ZAAuth:
|
||||
{
|
||||
_log(UCS__ERROR, "Got authentication from UCS when they are already authenticated.");
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
_log(UCS__ERROR, "Unknown ServerOPcode from UCS 0x%04x, size %d", pack->opcode, pack->size);
|
||||
DumpPacket(pack->pBuffer, pack->size);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
delete pack;
|
||||
}
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool UCSConnection::SendPacket(ServerPacket* pack)
|
||||
{
|
||||
if(!Stream)
|
||||
return false;
|
||||
|
||||
return Stream->SendPacket(pack);
|
||||
}
|
||||
|
||||
void UCSConnection::SendMessage(const char *From, const char *Message)
|
||||
{
|
||||
ServerPacket* pack = new ServerPacket(ServerOP_UCSMessage, strlen(From) + strlen(Message) + 2);
|
||||
|
||||
char *Buffer = (char *)pack->pBuffer;
|
||||
|
||||
VARSTRUCT_ENCODE_STRING(Buffer, From);
|
||||
VARSTRUCT_ENCODE_STRING(Buffer, Message);
|
||||
|
||||
SendPacket(pack);
|
||||
safe_delete(pack);
|
||||
}
|
||||
Reference in New Issue
Block a user