Working on world <-> zone communication needs a ton of work really need to rewrite how world works with zones.

This commit is contained in:
KimLS
2017-01-02 22:38:47 -08:00
parent 0264c0d60a
commit 2447c38c82
28 changed files with 3080 additions and 3304 deletions
+25 -106
View File
@@ -15,122 +15,41 @@ extern ZSList zoneserver_list;
QueryServConnection::QueryServConnection()
{
Stream = 0;
authenticated = false;
}
void QueryServConnection::SetConnection(EmuTCPConnection *inStream)
void QueryServConnection::AddConnection(std::shared_ptr<EQ::Net::ServertalkServerConnection> connection)
{
if(Stream)
{
Log.Out(Logs::Detail, Logs::QS_Server, "Incoming QueryServ Connection while we were already connected to a QueryServ.");
Stream->Disconnect();
}
Stream = inStream;
authenticated = false;
//Set handlers
connection->OnMessage(ServerOP_QueryServGeneric, std::bind(&QueryServConnection::HandleGenericMessage, this, std::placeholders::_1, std::placeholders::_2));
connection->OnMessage(ServerOP_LFGuildUpdate, std::bind(&QueryServConnection::HandleLFGuildUpdateMessage, this, std::placeholders::_1, std::placeholders::_2));
m_streams.insert(std::make_pair(connection->GetUUID(), connection));
}
bool QueryServConnection::Process()
void QueryServConnection::RemoveConnection(std::shared_ptr<EQ::Net::ServertalkServerConnection> connection)
{
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.Out(Logs::Detail, Logs::QS_Server, "QueryServ 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::General, Logs::QS_Server, "QueryServ authorization failed.");
auto pack = new ServerPacket(ServerOP_ZAAuthFailed);
SendPacket(pack);
delete pack;
Disconnect();
return false;
}
}
else
{
Log.Out(Logs::Detail, Logs::QS_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;
}
switch(pack->opcode)
{
case 0:
break;
case ServerOP_KeepAlive:
{
// ignore this
break;
}
case ServerOP_ZAAuth:
{
Log.Out(Logs::Detail, Logs::QS_Server, "Got authentication from QueryServ when they are already authenticated.");
break;
}
case ServerOP_QueryServGeneric:
{
uint32 ZoneID = pack->ReadUInt32();
uint16 InstanceID = pack->ReadUInt32();
zoneserver_list.SendPacket(ZoneID, InstanceID, pack);
break;
}
case ServerOP_LFGuildUpdate:
{
zoneserver_list.SendPacket(pack);
break;
}
default:
{
Log.Out(Logs::Detail, Logs::QS_Server, "Unknown ServerOPcode from QueryServ 0x%04x, size %d", pack->opcode, pack->size);
DumpPacket(pack->pBuffer, pack->size);
break;
}
}
delete pack;
auto iter = m_streams.find(connection->GetUUID());
if (iter != m_streams.end()) {
m_streams.erase(iter);
}
return(true);
}
void QueryServConnection::HandleGenericMessage(uint16_t opcode, EQ::Net::Packet &p) {
uint32 ZoneID = p.GetUInt32(0);
uint16 InstanceID = p.GetUInt32(4);
ServerPacket pack(opcode, p);
zoneserver_list.SendPacket(ZoneID, InstanceID, &pack);
}
void QueryServConnection::HandleLFGuildUpdateMessage(uint16_t opcode, EQ::Net::Packet &p) {
ServerPacket pack(opcode, p);
zoneserver_list.SendPacket(&pack);
}
bool QueryServConnection::SendPacket(ServerPacket* pack)
{
if(!Stream)
return false;
for (auto &stream : m_streams) {
stream.second->SendPacket(pack);
}
return Stream->SendPacket(pack);
return true;
}