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
+14 -2
View File
@@ -437,6 +437,20 @@ int main(int argc, char** argv) {
QSLink.RemoveConnection(connection);
});
server_connection->OnConnectionIdentified("UCS", [](std::shared_ptr<EQ::Net::ServertalkServerConnection> connection) {
Log.OutF(Logs::General, Logs::World_Server, "New UCS Server connection from {2} at {0}:{1}",
connection->Handle()->RemoteIP(), connection->Handle()->RemotePort(), connection->GetUUID());
UCSLink.SetConnection(connection);
});
server_connection->OnConnectionRemoved("UCS", [](std::shared_ptr<EQ::Net::ServertalkServerConnection> connection) {
Log.OutF(Logs::General, Logs::World_Server, "UCS Query Server connection from {0}",
connection->GetUUID());
UCSLink.SetConnection(nullptr);
});
EQ::Net::EQStreamManagerOptions opts(9000, false, false);
EQ::Net::EQStreamManager eqsm(opts);
@@ -451,7 +465,6 @@ int main(int argc, char** argv) {
InterserverTimer.Trigger();
uint8 ReconnectCounter = 100;
std::shared_ptr<EQStreamInterface> eqs;
EmuTCPConnection* tcpc;
EQStreamInterface *eqsi;
eqsm.OnNewConnection([&stream_identifier](std::shared_ptr<EQ::Net::EQStream> stream) {
@@ -510,7 +523,6 @@ int main(int argc, char** argv) {
zoneserver_list.Process();
launcher_list.Process();
UCSLink.Process();
LFPGroupList.Process();
adventure_manager.Process();
+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)
+8 -8
View File
@@ -2,22 +2,22 @@
#define UCS_H
#include "../common/types.h"
#include "../common/emu_tcp_connection.h"
#include "../common/net/servertalk_server_connection.h"
#include "../common/servertalk.h"
#include <memory>
class UCSConnection
{
public:
UCSConnection();
void SetConnection(EmuTCPConnection *inStream);
bool Process();
bool SendPacket(ServerPacket* pack);
void Disconnect() { if(Stream) Stream->Disconnect(); }
void SetConnection(std::shared_ptr<EQ::Net::ServertalkServerConnection> connection);
void ProcessPacket(uint16 opcode, EQ::Net::Packet &p);
void SendPacket(ServerPacket* pack);
void Disconnect() { if(Stream && Stream->Handle()) Stream->Handle()->Disconnect(); }
void SendMessage(const char *From, const char *Message);
private:
inline uint32 GetIP() const { return Stream ? Stream->GetrIP() : 0; }
EmuTCPConnection *Stream;
bool authenticated;
inline std::string GetIP() const { return (Stream && Stream->Handle()) ? Stream->Handle()->RemoteIP() : 0; }
std::shared_ptr<EQ::Net::ServertalkServerConnection> Stream;
};
#endif /*UCS_H_*/