UCS support decided to not rewrite it for now. Maybe later now that it's easier to work with

This commit is contained in:
KimLS
2017-01-06 00:21:59 -08:00
parent bf563e9c6a
commit 08e72bbbdd
6 changed files with 117 additions and 180 deletions
+28 -79
View File
@@ -11,109 +11,58 @@
UCSConnection::UCSConnection()
{
Stream = 0;
authenticated = false;
}
void UCSConnection::SetConnection(EmuTCPConnection *inStream)
void UCSConnection::SetConnection(std::shared_ptr<EQ::Net::ServertalkServerConnection> inStream)
{
if(Stream)
if(Stream && Stream->Handle())
{
Log.Out(Logs::Detail, Logs::UCS_Server, "Incoming UCS Connection while we were already connected to a UCS.");
Stream->Disconnect();
Stream->Handle()->Disconnect();
}
Stream = inStream;
authenticated = false;
Stream->OnMessage(std::bind(&UCSConnection::ProcessPacket, this, std::placeholders::_1, std::placeholders::_2));
}
bool UCSConnection::Process()
void UCSConnection::ProcessPacket(uint16 opcode, EQ::Net::Packet &p)
{
if (!Stream || !Stream->Connected())
return false;
if (!Stream)
return;
ServerPacket *pack = 0;
ServerPacket tpack(opcode, p);
ServerPacket *pack = &tpack;
while((pack = Stream->PopPacket()))
switch(opcode)
{
if (!authenticated)
case 0:
break;
case ServerOP_KeepAlive:
{
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.Out(Logs::Detail, Logs::UCS_Server, "UCS authorization failed.");
auto pack = new ServerPacket(ServerOP_ZAAuthFailed);
SendPacket(pack);
delete pack;
Disconnect();
return false;
}
}
else
{
struct in_addr in;
in.s_addr = GetIP();
Log.Out(Logs::Detail, Logs::UCS_Server, "UCS authorization failed.");
auto pack = new ServerPacket(ServerOP_ZAAuthFailed);
SendPacket(pack);
delete pack;
Disconnect();
return false;
}
}
else
{
Log.Out(Logs::Detail, Logs::UCS_Server,"**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;
// ignore this
break;
}
switch(pack->opcode)
case ServerOP_ZAAuth:
{
case 0:
break;
case ServerOP_KeepAlive:
{
// ignore this
break;
}
case ServerOP_ZAAuth:
{
Log.Out(Logs::Detail, Logs::UCS_Server, "Got authentication from UCS when they are already authenticated.");
break;
}
default:
{
Log.Out(Logs::Detail, Logs::UCS_Server, "Unknown ServerOPcode from UCS 0x%04x, size %d", pack->opcode, pack->size);
DumpPacket(pack->pBuffer, pack->size);
break;
}
Log.Out(Logs::Detail, Logs::UCS_Server, "Got authentication from UCS when they are already authenticated.");
break;
}
default:
{
Log.Out(Logs::Detail, Logs::UCS_Server, "Unknown ServerOPcode from UCS 0x%04x, size %d", opcode, pack->size);
DumpPacket(pack->pBuffer, pack->size);
break;
}
delete pack;
}
return(true);
}
bool UCSConnection::SendPacket(ServerPacket* pack)
void UCSConnection::SendPacket(ServerPacket* pack)
{
if(!Stream)
return false;
return;
return Stream->SendPacket(pack);
Stream->SendPacket(pack);
}
void UCSConnection::SendMessage(const char *From, const char *Message)