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

View File

@ -297,7 +297,7 @@ void EQ::Net::ServertalkClient::ProcessMessage(EQ::Net::Packet &p)
auto cb = m_message_callbacks.find(opcode); auto cb = m_message_callbacks.find(opcode);
if (cb != m_message_callbacks.end()) { if (cb != m_message_callbacks.end()) {
cb->second(opcode, packet); m_message_callback_any(opcode, packet);
} }
#endif #endif
} }

View File

@ -1,6 +1,7 @@
#include "servertalk_server_connection.h" #include "servertalk_server_connection.h"
#include "servertalk_server.h" #include "servertalk_server.h"
#include "../eqemu_logsys.h" #include "../eqemu_logsys.h"
#include "../util/uuid.h"
EQ::Net::ServertalkServerConnection::ServertalkServerConnection(std::shared_ptr<EQ::Net::TCPConnection> c, EQ::Net::ServertalkServer *parent, bool encrypted, bool allow_downgrade) EQ::Net::ServertalkServerConnection::ServertalkServerConnection(std::shared_ptr<EQ::Net::TCPConnection> c, EQ::Net::ServertalkServer *parent, bool encrypted, bool allow_downgrade)
{ {
@ -8,6 +9,7 @@ EQ::Net::ServertalkServerConnection::ServertalkServerConnection(std::shared_ptr<
m_parent = parent; m_parent = parent;
m_encrypted = encrypted; m_encrypted = encrypted;
m_allow_downgrade = allow_downgrade; m_allow_downgrade = allow_downgrade;
m_uuid = EQ::Util::UUID::Generate().ToString();
m_connection->OnRead(std::bind(&ServertalkServerConnection::OnRead, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)); m_connection->OnRead(std::bind(&ServertalkServerConnection::OnRead, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
m_connection->OnDisconnect(std::bind(&ServertalkServerConnection::OnDisconnect, this, std::placeholders::_1)); m_connection->OnDisconnect(std::bind(&ServertalkServerConnection::OnDisconnect, this, std::placeholders::_1));
m_connection->Start(); m_connection->Start();

View File

@ -25,6 +25,7 @@ namespace EQ
std::string GetIdentifier() const { return m_identifier; } std::string GetIdentifier() const { return m_identifier; }
std::shared_ptr<EQ::Net::TCPConnection> Handle() { return m_connection; } std::shared_ptr<EQ::Net::TCPConnection> Handle() { return m_connection; }
std::string GetUUID() const { return m_uuid; }
private: private:
void OnRead(TCPConnection* c, const unsigned char* data, size_t sz); void OnRead(TCPConnection* c, const unsigned char* data, size_t sz);
void ProcessReadBuffer(); void ProcessReadBuffer();
@ -41,6 +42,7 @@ namespace EQ
std::vector<char> m_buffer; std::vector<char> m_buffer;
std::unordered_map<uint16_t, std::function<void(uint16_t, EQ::Net::Packet&)>> m_message_callbacks; std::unordered_map<uint16_t, std::function<void(uint16_t, EQ::Net::Packet&)>> m_message_callbacks;
std::string m_identifier; std::string m_identifier;
std::string m_uuid;
bool m_encrypted; bool m_encrypted;
bool m_allow_downgrade; bool m_allow_downgrade;

View File

@ -4,6 +4,7 @@
#include "../common/types.h" #include "../common/types.h"
#include "../common/packet_functions.h" #include "../common/packet_functions.h"
#include "../common/eq_packet_structs.h" #include "../common/eq_packet_structs.h"
#include "../net/packet.h"
#include <cereal/cereal.hpp> #include <cereal/cereal.hpp>
#include <cereal/types/string.hpp> #include <cereal/types/string.hpp>
@ -223,6 +224,22 @@ public:
_wpos = 0; _wpos = 0;
_rpos = 0; _rpos = 0;
} }
ServerPacket(uint16 in_opcode, const EQ::Net::Packet &p) {
this->compressed = false;
size = p.Length();
opcode = in_opcode;
if (size == 0) {
pBuffer = 0;
}
else {
pBuffer = new uchar[size];
memcpy(pBuffer, p.Data(), size);
}
_wpos = 0;
_rpos = 0;
}
ServerPacket* Copy() { ServerPacket* Copy() {
if (this == 0) { if (this == 0) {
return 0; return 0;

View File

@ -52,40 +52,38 @@ WorldServer::~WorldServer()
void WorldServer::Connect() void WorldServer::Connect()
{ {
m_server.reset(new EQ::Net::ServertalkServer()); m_connection.reset(new EQ::Net::ServertalkClient(Config->WorldIP, Config->WorldTCPPort, false, "QueryServ", Config->SharedKey));
//Config->WorldIP, Config->WorldTCPPort, "QS", Config->SharedKey
m_link->OnMessageType(ServerOP_Speech, std::bind(&WorldServer::HandleMessage, this, ServerOP_Speech, std::placeholders::_1)); m_connection->OnMessage(ServerOP_Speech, std::bind(&WorldServer::HandleMessage, this, std::placeholders::_1, std::placeholders::_2));
m_link->OnMessageType(ServerOP_QSPlayerLogTrades, std::bind(&WorldServer::HandleMessage, this, ServerOP_QSPlayerLogTrades, std::placeholders::_1)); m_connection->OnMessage(ServerOP_QSPlayerLogTrades, std::bind(&WorldServer::HandleMessage, this, std::placeholders::_1, std::placeholders::_2));
m_link->OnMessageType(ServerOP_QSPlayerLogHandins, std::bind(&WorldServer::HandleMessage, this, ServerOP_QSPlayerLogHandins, std::placeholders::_1)); m_connection->OnMessage(ServerOP_QSPlayerLogHandins, std::bind(&WorldServer::HandleMessage, this, std::placeholders::_1, std::placeholders::_2));
m_link->OnMessageType(ServerOP_QSPlayerLogNPCKills, std::bind(&WorldServer::HandleMessage, this, ServerOP_QSPlayerLogNPCKills, std::placeholders::_1)); m_connection->OnMessage(ServerOP_QSPlayerLogNPCKills, std::bind(&WorldServer::HandleMessage, this, std::placeholders::_1, std::placeholders::_2));
m_link->OnMessageType(ServerOP_QSPlayerLogDeletes, std::bind(&WorldServer::HandleMessage, this, ServerOP_QSPlayerLogDeletes, std::placeholders::_1)); m_connection->OnMessage(ServerOP_QSPlayerLogDeletes, std::bind(&WorldServer::HandleMessage, this, std::placeholders::_1, std::placeholders::_2));
m_link->OnMessageType(ServerOP_QSPlayerLogMoves, std::bind(&WorldServer::HandleMessage, this, ServerOP_QSPlayerLogMoves, std::placeholders::_1)); m_connection->OnMessage(ServerOP_QSPlayerLogMoves, std::bind(&WorldServer::HandleMessage, this, std::placeholders::_1, std::placeholders::_2));
m_link->OnMessageType(ServerOP_QSPlayerLogMerchantTransactions, std::bind(&WorldServer::HandleMessage, this, ServerOP_QSPlayerLogMerchantTransactions, std::placeholders::_1)); m_connection->OnMessage(ServerOP_QSPlayerLogMerchantTransactions, std::bind(&WorldServer::HandleMessage, this, std::placeholders::_1, std::placeholders::_2));
m_link->OnMessageType(ServerOP_QueryServGeneric, std::bind(&WorldServer::HandleMessage, this, ServerOP_QueryServGeneric, std::placeholders::_1)); m_connection->OnMessage(ServerOP_QueryServGeneric, std::bind(&WorldServer::HandleMessage, this, std::placeholders::_1, std::placeholders::_2));
m_link->OnMessageType(ServerOP_QSSendQuery, std::bind(&WorldServer::HandleMessage, this, ServerOP_QSSendQuery, std::placeholders::_1)); m_connection->OnMessage(ServerOP_QSSendQuery, std::bind(&WorldServer::HandleMessage, this, std::placeholders::_1, std::placeholders::_2));
} }
bool WorldServer::SendPacket(ServerPacket *pack) bool WorldServer::SendPacket(ServerPacket *pack)
{ {
EQ::Net::ReadOnlyPacket p(pack->pBuffer, pack->size); m_connection->SendPacket(pack);
->SendPacket(pack->opcode, p);
return true; return true;
} }
std::string WorldServer::GetIP() const std::string WorldServer::GetIP() const
{ {
return m_link->GetIP(); return m_connection->Handle()->RemoteIP();
} }
uint16 WorldServer::GetPort() const uint16 WorldServer::GetPort() const
{ {
return m_link->GetPort(); return m_connection->Handle()->RemotePort();
} }
bool WorldServer::Connected() const bool WorldServer::Connected() const
{ {
return m_link->Connected(); return m_connection->Connected();
} }
void WorldServer::HandleMessage(uint16 opcode, const EQ::Net::Packet &p) void WorldServer::HandleMessage(uint16 opcode, const EQ::Net::Packet &p)
@ -118,7 +116,7 @@ void WorldServer::HandleMessage(uint16 opcode, const EQ::Net::Packet &p)
} }
case ServerOP_QSPlayerLogNPCKills: { case ServerOP_QSPlayerLogNPCKills: {
QSPlayerLogNPCKill_Struct *QS = (QSPlayerLogNPCKill_Struct*)p.Data(); QSPlayerLogNPCKill_Struct *QS = (QSPlayerLogNPCKill_Struct*)p.Data();
uint32 Members = p.Length() - sizeof(QSPlayerLogNPCKill_Struct); uint32 Members = (uint32)(p.Length() - sizeof(QSPlayerLogNPCKill_Struct));
if (Members > 0) Members = Members / sizeof(QSPlayerLogNPCKillsPlayers_Struct); if (Members > 0) Members = Members / sizeof(QSPlayerLogNPCKillsPlayers_Struct);
database.LogPlayerNPCKill(QS, Members); database.LogPlayerNPCKill(QS, Members);
break; break;
@ -170,7 +168,7 @@ void WorldServer::HandleMessage(uint16 opcode, const EQ::Net::Packet &p)
ServerPacket pack; ServerPacket pack;
pack.pBuffer = (uchar*)p.Data(); pack.pBuffer = (uchar*)p.Data();
pack.opcode = opcode; pack.opcode = opcode;
pack.size = p.Length(); pack.size = (uint32)p.Length();
lfguildmanager.HandlePacket(&pack); lfguildmanager.HandlePacket(&pack);
pack.pBuffer = nullptr; pack.pBuffer = nullptr;
break; break;
@ -186,7 +184,7 @@ void WorldServer::HandleMessage(uint16 opcode, const EQ::Net::Packet &p)
ServerPacket pack; ServerPacket pack;
pack.pBuffer = (uchar*)p.Data(); pack.pBuffer = (uchar*)p.Data();
pack.opcode = opcode; pack.opcode = opcode;
pack.size = p.Length(); pack.size = (uint32)p.Length();
database.GeneralQueryReceive(&pack); database.GeneralQueryReceive(&pack);
pack.pBuffer = nullptr; pack.pBuffer = nullptr;

View File

@ -19,7 +19,7 @@
#define WORLDSERVER_H #define WORLDSERVER_H
#include "../common/eq_packet_structs.h" #include "../common/eq_packet_structs.h"
#include "../common/net/servertalk_server.h" #include "../common/net/servertalk_client_connection.h"
class WorldServer class WorldServer
{ {
@ -35,7 +35,7 @@ class WorldServer
void HandleMessage(uint16 opcode, const EQ::Net::Packet &p); void HandleMessage(uint16 opcode, const EQ::Net::Packet &p);
private: private:
std::unique_ptr<EQ::Net::ServertalkServer> m_server; std::unique_ptr<EQ::Net::ServertalkClient> m_connection;
}; };
#endif #endif

View File

@ -7,7 +7,6 @@ SET(world_sources
cliententry.cpp cliententry.cpp
clientlist.cpp clientlist.cpp
CMakeLists.txt CMakeLists.txt
console.cpp
eql_config.cpp eql_config.cpp
eqw.cpp eqw.cpp
eqw_http_handler.cpp eqw_http_handler.cpp
@ -39,7 +38,6 @@ SET(world_headers
cliententry.h cliententry.h
clientlist.h clientlist.h
CMakeLists.txt CMakeLists.txt
console.h
eql_config.h eql_config.h
eqw.h eqw.h
eqw_http_handler.h eqw_http_handler.h

View File

@ -432,15 +432,11 @@ bool Client::HandleSendLoginInfoPacket(const EQApplicationPacket *app) {
} }
else else
id=atoi(name); id=atoi(name);
#ifdef IPBASED_AUTH_HACK
if ((cle = zoneserver_list.CheckAuth(inet_ntoa(tmpip), password)))
#else
if (loginserverlist.Connected() == false && !is_player_zoning) { if (loginserverlist.Connected() == false && !is_player_zoning) {
Log.Out(Logs::General, Logs::World_Server,"Error: Login server login while not connected to login server."); Log.Out(Logs::General, Logs::World_Server,"Error: Login server login while not connected to login server.");
return false; return false;
} }
if (((cle = client_list.CheckAuth(name, password)) || (cle = client_list.CheckAuth(id, password)))) if (((cle = client_list.CheckAuth(name, password)) || (cle = client_list.CheckAuth(id, password))))
#endif
{ {
if (cle->AccountID() == 0 || (!minilogin && cle->LSID()==0)) { if (cle->AccountID() == 0 || (!minilogin && cle->LSID()==0)) {
Log.Out(Logs::General, Logs::World_Server,"ID is 0. Is this server connected to minilogin?"); Log.Out(Logs::General, Logs::World_Server,"ID is 0. Is this server connected to minilogin?");
@ -1255,11 +1251,7 @@ void Client::Clearance(int8 response)
if(local_addr[0]) { if(local_addr[0]) {
zs_addr = local_addr; zs_addr = local_addr;
} else { } else {
struct in_addr in; if(strcmp(zs->GetIP().c_str(), "127.0.0.1") == 0)
in.s_addr = zs->GetIP();
zs_addr = inet_ntoa(in);
if(strcmp(zs_addr, "127.0.0.1") == 0)
{ {
Log.Out(Logs::Detail, Logs::World_Server, "Local zone address was %s, setting local address to: %s", zs_addr, WorldConfig::get()->LocalAddress.c_str()); Log.Out(Logs::Detail, Logs::World_Server, "Local zone address was %s, setting local address to: %s", zs_addr, WorldConfig::get()->LocalAddress.c_str());
zs_addr = WorldConfig::get()->LocalAddress.c_str(); zs_addr = WorldConfig::get()->LocalAddress.c_str();

View File

@ -33,7 +33,6 @@
#include <set> #include <set>
extern ConsoleList console_list;
extern ZSList zoneserver_list; extern ZSList zoneserver_list;
uint32 numplayers = 0; //this really wants to be a member variable of ClientList... uint32 numplayers = 0; //this really wants to be a member variable of ClientList...
@ -1113,7 +1112,6 @@ void ClientList::ConsoleSendWhoAll(const char* to, int16 admin, Who_All_Struct*
AppendAnyLenString(&output, &outsize, &outlen, "\r\n"); AppendAnyLenString(&output, &outsize, &outlen, "\r\n");
else else
AppendAnyLenString(&output, &outsize, &outlen, "\n"); AppendAnyLenString(&output, &outsize, &outlen, "\n");
console_list.SendConsoleWho(connection, to, admin, &output, &outsize, &outlen);
} }
if (output) if (output)
connection->SendEmoteMessageRaw(to, 0, 0, 10, output); connection->SendEmoteMessageRaw(to, 0, 0, 10, output);

View File

@ -241,32 +241,26 @@ bool Console::Process() {
if (tcpc->GetMode() == EmuTCPConnection::modePacket) { if (tcpc->GetMode() == EmuTCPConnection::modePacket) {
struct in_addr in; struct in_addr in;
in.s_addr = GetIP(); in.s_addr = GetIP();
if(tcpc->GetPacketMode() == EmuTCPConnection::packetModeZone) { //if(tcpc->GetPacketMode() == EmuTCPConnection::packetModeZone) {
auto zs = new ZoneServer(tcpc); // auto zs = new ZoneServer(tcpc);
Log.Out(Logs::Detail, Logs::World_Server,"New zoneserver #%d from %s:%d", zs->GetID(), inet_ntoa(in), GetPort()); // Log.Out(Logs::Detail, Logs::World_Server,"New zoneserver #%d from %s:%d", zs->GetID(), inet_ntoa(in), GetPort());
zoneserver_list.Add(zs); // zoneserver_list.Add(zs);
numzones++; // numzones++;
tcpc = 0; // tcpc = 0;
} else if(tcpc->GetPacketMode() == EmuTCPConnection::packetModeLauncher) { //} else if(tcpc->GetPacketMode() == EmuTCPConnection::packetModeLauncher) {
Log.Out(Logs::Detail, Logs::World_Server,"New launcher from %s:%d", inet_ntoa(in), GetPort()); // Log.Out(Logs::Detail, Logs::World_Server,"New launcher from %s:%d", inet_ntoa(in), GetPort());
launcher_list.Add(tcpc); // launcher_list.Add(tcpc);
tcpc = 0; // tcpc = 0;
} //}
else if(tcpc->GetPacketMode() == EmuTCPConnection::packetModeUCS) //else if(tcpc->GetPacketMode() == EmuTCPConnection::packetModeUCS)
{ //{
Log.Out(Logs::Detail, Logs::World_Server,"New UCS Connection from %s:%d", inet_ntoa(in), GetPort()); // Log.Out(Logs::Detail, Logs::World_Server,"New UCS Connection from %s:%d", inet_ntoa(in), GetPort());
UCSLink.SetConnection(tcpc); // UCSLink.SetConnection(tcpc);
tcpc = 0; // tcpc = 0;
} //}
else if(tcpc->GetPacketMode() == EmuTCPConnection::packetModeQueryServ) //else {
{ // Log.Out(Logs::Detail, Logs::World_Server,"Unsupported packet mode from %s:%d", inet_ntoa(in), GetPort());
Log.Out(Logs::Detail, Logs::World_Server,"New QS Connection from %s:%d", inet_ntoa(in), GetPort()); //}
QSLink.SetConnection(tcpc);
tcpc = 0;
}
else {
Log.Out(Logs::Detail, Logs::World_Server,"Unsupported packet mode from %s:%d", inet_ntoa(in), GetPort());
}
return false; return false;
} }
char* command = 0; char* command = 0;

View File

@ -107,8 +107,6 @@ bool holdzones = false;
const WorldConfig *Config; const WorldConfig *Config;
EQEmuLogSys Log; EQEmuLogSys Log;
extern ConsoleList console_list;
void CatchSignal(int sig_num); void CatchSignal(int sig_num);
int main(int argc, char** argv) { int main(int argc, char** argv) {
@ -338,10 +336,12 @@ int main(int argc, char** argv) {
} }
} }
} }
if(RuleB(World, ClearTempMerchantlist)){ if(RuleB(World, ClearTempMerchantlist)){
Log.Out(Logs::General, Logs::World_Server, "Clearing temporary merchant lists.."); Log.Out(Logs::General, Logs::World_Server, "Clearing temporary merchant lists..");
database.ClearMerchantTemp(); database.ClearMerchantTemp();
} }
Log.Out(Logs::General, Logs::World_Server, "Loading EQ time of day.."); Log.Out(Logs::General, Logs::World_Server, "Loading EQ time of day..");
TimeOfDay_Struct eqTime; TimeOfDay_Struct eqTime;
time_t realtime; time_t realtime;
@ -385,14 +385,43 @@ int main(int argc, char** argv) {
database.LoadCharacterCreateAllocations(); database.LoadCharacterCreateAllocations();
database.LoadCharacterCreateCombos(); database.LoadCharacterCreateCombos();
char errbuf[TCPConnection_ErrorBufferSize]; std::unique_ptr<EQ::Net::ServertalkServer> server_connection;
if (tcps.Open(Config->WorldTCPPort, errbuf)) { server_connection.reset(new EQ::Net::ServertalkServer());
Log.Out(Logs::General, Logs::World_Server,"Zone (TCP) listener started.");
} else { EQ::Net::ServertalkServerOptions server_opts;
Log.Out(Logs::General, Logs::World_Server,"Failed to start zone (TCP) listener on port %d:",Config->WorldTCPPort); server_opts.port = Config->WorldTCPPort;
Log.Out(Logs::General, Logs::World_Server," %s",errbuf); server_opts.ipv6 = false;
return 1; server_opts.credentials = Config->SharedKey;
} server_connection->Listen(server_opts);
Log.Out(Logs::General, Logs::World_Server, "Server (TCP) listener started.");
server_connection->OnConnectionIdentified("Zone", [](std::shared_ptr<EQ::Net::ServertalkServerConnection> connection) {
Log.OutF(Logs::General, Logs::World_Server, "New Zone Server connection from {2} at {0}:{1}",
connection->Handle()->RemoteIP(), connection->Handle()->RemotePort(), connection->GetUUID());
zoneserver_list.Add(new ZoneServer(connection));
});
server_connection->OnConnectionRemoved("Zone", [](std::shared_ptr<EQ::Net::ServertalkServerConnection> connection) {
Log.OutF(Logs::General, Logs::World_Server, "Removed Zone Server connection from {0}",
connection->GetUUID());
zoneserver_list.Remove(connection->GetUUID());
});
server_connection->OnConnectionIdentified("QueryServ", [](std::shared_ptr<EQ::Net::ServertalkServerConnection> connection) {
Log.OutF(Logs::General, Logs::World_Server, "New Query Server connection from {2} at {0}:{1}",
connection->Handle()->RemoteIP(), connection->Handle()->RemotePort(), connection->GetUUID());
QSLink.AddConnection(connection);
});
server_connection->OnConnectionRemoved("QueryServ", [](std::shared_ptr<EQ::Net::ServertalkServerConnection> connection) {
Log.OutF(Logs::General, Logs::World_Server, "Removed Query Server connection from {0}",
connection->GetUUID());
QSLink.RemoveConnection(connection);
});
EQ::Net::EQStreamManagerOptions opts(9000, false, false); EQ::Net::EQStreamManagerOptions opts(9000, false, false);
EQ::Net::EQStreamManager eqsm(opts); EQ::Net::EQStreamManager eqsm(opts);
@ -450,31 +479,31 @@ int main(int argc, char** argv) {
client_list.Process(); client_list.Process();
while ((tcpc = tcps.NewQueuePop())) { //while ((tcpc = tcps.NewQueuePop())) {
struct in_addr in; // struct in_addr in;
in.s_addr = tcpc->GetrIP(); // in.s_addr = tcpc->GetrIP();
//
/* World - Tell what is being connected */ // /* World - Tell what is being connected */
if (tcpc->GetMode() == EmuTCPConnection::modePacket) { // if (tcpc->GetMode() == EmuTCPConnection::modePacket) {
if (tcpc->GetPacketMode() == EmuTCPConnection::packetModeZone) { // if (tcpc->GetPacketMode() == EmuTCPConnection::packetModeZone) {
Log.Out(Logs::General, Logs::World_Server, "New Zone Server from %s:%d", inet_ntoa(in), tcpc->GetrPort()); // Log.Out(Logs::General, Logs::World_Server, "New Zone Server from %s:%d", inet_ntoa(in), tcpc->GetrPort());
} // }
else if (tcpc->GetPacketMode() == EmuTCPConnection::packetModeLauncher) { // else if (tcpc->GetPacketMode() == EmuTCPConnection::packetModeLauncher) {
Log.Out(Logs::General, Logs::World_Server, "New Launcher from %s:%d", inet_ntoa(in), tcpc->GetrPort()); // Log.Out(Logs::General, Logs::World_Server, "New Launcher from %s:%d", inet_ntoa(in), tcpc->GetrPort());
} // }
else if (tcpc->GetPacketMode() == EmuTCPConnection::packetModeUCS) { // else if (tcpc->GetPacketMode() == EmuTCPConnection::packetModeUCS) {
Log.Out(Logs::General, Logs::World_Server, "New UCS Connection from %s:%d", inet_ntoa(in), tcpc->GetrPort()); // Log.Out(Logs::General, Logs::World_Server, "New UCS Connection from %s:%d", inet_ntoa(in), tcpc->GetrPort());
} // }
else if (tcpc->GetPacketMode() == EmuTCPConnection::packetModeQueryServ) { // else if (tcpc->GetPacketMode() == EmuTCPConnection::packetModeQueryServ) {
Log.Out(Logs::General, Logs::World_Server, "New QS Connection from %s:%d", inet_ntoa(in), tcpc->GetrPort()); // Log.Out(Logs::General, Logs::World_Server, "New QS Connection from %s:%d", inet_ntoa(in), tcpc->GetrPort());
} // }
else { // else {
Log.Out(Logs::General, Logs::World_Server, "Unsupported packet mode from %s:%d", inet_ntoa(in), tcpc->GetrPort()); // Log.Out(Logs::General, Logs::World_Server, "Unsupported packet mode from %s:%d", inet_ntoa(in), tcpc->GetrPort());
} // }
} // }
//
console_list.Add(new Console(tcpc)); // console_list.Add(new Console(tcpc));
} //}
if(PurgeInstanceTimer.Check()) if(PurgeInstanceTimer.Check())
{ {
@ -491,11 +520,9 @@ int main(int argc, char** argv) {
Log.Out(Logs::Detail, Logs::World_Server, "EQTime successfully saved."); Log.Out(Logs::Detail, Logs::World_Server, "EQTime successfully saved.");
} }
console_list.Process();
zoneserver_list.Process(); zoneserver_list.Process();
launcher_list.Process(); launcher_list.Process();
UCSLink.Process(); UCSLink.Process();
QSLink.Process();
LFPGroupList.Process(); LFPGroupList.Process();
adventure_manager.Process(); adventure_manager.Process();
@ -508,12 +535,10 @@ int main(int argc, char** argv) {
Sleep(1); Sleep(1);
} }
Log.Out(Logs::General, Logs::World_Server, "World main loop completed."); Log.Out(Logs::General, Logs::World_Server, "World main loop completed.");
Log.Out(Logs::General, Logs::World_Server, "Shutting down console connections (if any).");
console_list.KillAll();
Log.Out(Logs::General, Logs::World_Server, "Shutting down zone connections (if any)."); Log.Out(Logs::General, Logs::World_Server, "Shutting down zone connections (if any).");
zoneserver_list.KillAll(); zoneserver_list.KillAll();
Log.Out(Logs::General, Logs::World_Server, "Zone (TCP) listener stopped."); Log.Out(Logs::General, Logs::World_Server, "Zone (TCP) listener stopped.");
tcps.Close(); //tcps.Close();
Log.Out(Logs::General, Logs::World_Server, "Signaling HTTP service to stop..."); Log.Out(Logs::General, Logs::World_Server, "Signaling HTTP service to stop...");
http_server.Stop(); http_server.Stop();
Log.CloseFileLogs(); Log.CloseFileLogs();

View File

@ -15,122 +15,41 @@ extern ZSList zoneserver_list;
QueryServConnection::QueryServConnection() QueryServConnection::QueryServConnection()
{ {
Stream = 0;
authenticated = false;
} }
void QueryServConnection::SetConnection(EmuTCPConnection *inStream) void QueryServConnection::AddConnection(std::shared_ptr<EQ::Net::ServertalkServerConnection> connection)
{ {
if(Stream) //Set handlers
{ connection->OnMessage(ServerOP_QueryServGeneric, std::bind(&QueryServConnection::HandleGenericMessage, this, std::placeholders::_1, std::placeholders::_2));
Log.Out(Logs::Detail, Logs::QS_Server, "Incoming QueryServ Connection while we were already connected to a QueryServ."); connection->OnMessage(ServerOP_LFGuildUpdate, std::bind(&QueryServConnection::HandleLFGuildUpdateMessage, this, std::placeholders::_1, std::placeholders::_2));
Stream->Disconnect(); m_streams.insert(std::make_pair(connection->GetUUID(), connection));
} }
Stream = inStream; void QueryServConnection::RemoveConnection(std::shared_ptr<EQ::Net::ServertalkServerConnection> connection)
authenticated = false;
}
bool QueryServConnection::Process()
{ {
if (!Stream || !Stream->Connected()) auto iter = m_streams.find(connection->GetUUID());
return false; if (iter != m_streams.end()) {
m_streams.erase(iter);
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; 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);
} }
return(true);
void QueryServConnection::HandleLFGuildUpdateMessage(uint16_t opcode, EQ::Net::Packet &p) {
ServerPacket pack(opcode, p);
zoneserver_list.SendPacket(&pack);
} }
bool QueryServConnection::SendPacket(ServerPacket* pack) bool QueryServConnection::SendPacket(ServerPacket* pack)
{ {
if(!Stream) for (auto &stream : m_streams) {
return false; stream.second->SendPacket(pack);
return Stream->SendPacket(pack);
} }
return true;
}

View File

@ -2,22 +2,20 @@
#define QueryServ_H #define QueryServ_H
#include "../common/types.h" #include "../common/types.h"
#include "../common/emu_tcp_connection.h" #include "../common/net/servertalk_server.h"
#include "../common/servertalk.h" #include "../common/servertalk.h"
class QueryServConnection class QueryServConnection
{ {
public: public:
QueryServConnection(); QueryServConnection();
void SetConnection(EmuTCPConnection *inStream); void AddConnection(std::shared_ptr<EQ::Net::ServertalkServerConnection> connection);
bool Process(); void RemoveConnection(std::shared_ptr<EQ::Net::ServertalkServerConnection> connection);
void HandleGenericMessage(uint16_t opcode, EQ::Net::Packet &p);
void HandleLFGuildUpdateMessage(uint16_t opcode, EQ::Net::Packet &p);
bool SendPacket(ServerPacket* pack); bool SendPacket(ServerPacket* pack);
void Disconnect() { if(Stream) Stream->Disconnect(); }
void SendMessage(const char *From, const char *Message);
private: private:
inline uint32 GetIP() const { return Stream ? Stream->GetrIP() : 0; } std::map<std::string, std::shared_ptr<EQ::Net::ServertalkServerConnection>> m_streams;
EmuTCPConnection *Stream;
bool authenticated;
}; };
#endif /*QueryServ_H_*/ #endif /*QueryServ_H_*/

View File

@ -28,7 +28,6 @@
extern uint32 numzones; extern uint32 numzones;
extern bool holdzones; extern bool holdzones;
extern ConsoleList console_list;
extern EQEmu::Random emu_random; extern EQEmu::Random emu_random;
void CatchSignal(int sig_num); void CatchSignal(int sig_num);
@ -61,17 +60,27 @@ void ZSList::ShowUpTime(WorldTCPConnection* con, const char* adminname) {
} }
void ZSList::Add(ZoneServer* zoneserver) { void ZSList::Add(ZoneServer* zoneserver) {
list.Insert(zoneserver); list.push_back(std::unique_ptr<ZoneServer>(zoneserver));
zoneserver->SendGroupIDs(); //send its initial set of group ids zoneserver->SendGroupIDs();
}
void ZSList::Remove(const std::string &uuid)
{
auto iter = list.begin();
while (iter != list.end()) {
if ((*iter)->GetUUID().compare(uuid) == 0) {
list.erase(iter);
return;
}
iter++;
}
} }
void ZSList::KillAll() { void ZSList::KillAll() {
LinkedListIterator<ZoneServer*> iterator(list); auto iterator = list.begin();
while(iterator != list.end()) {
iterator.Reset(); (*iterator)->Disconnect();
while(iterator.MoreElements()) { iterator = list.erase(iterator);
iterator.GetData()->Disconnect();
iterator.RemoveCurrent();
numzones--; numzones--;
} }
} }
@ -88,159 +97,120 @@ void ZSList::Process() {
Process(); Process();
CatchSignal(2); CatchSignal(2);
} }
if(reminder && reminder->Check() && shutdowntimer){ if(reminder && reminder->Check() && shutdowntimer){
SendEmoteMessage(0,0,0,15,"<SYSTEMWIDE MESSAGE>:SYSTEM MSG:World coming down, everyone log out now. World will shut down in %i minutes...", ((shutdowntimer->GetRemainingTime()/1000) / 60)); SendEmoteMessage(0,0,0,15,"<SYSTEMWIDE MESSAGE>:SYSTEM MSG:World coming down, everyone log out now. World will shut down in %i minutes...", ((shutdowntimer->GetRemainingTime()/1000) / 60));
} }
LinkedListIterator<ZoneServer*> iterator(list);
iterator.Reset();
while(iterator.MoreElements()) {
if (!iterator.GetData()->Process()) {
ZoneServer* zs = iterator.GetData();
struct in_addr in;
in.s_addr = zs->GetIP();
Log.Out(Logs::Detail, Logs::World_Server,"Removing zoneserver #%d at %s:%d",zs->GetID(),zs->GetCAddress(),zs->GetCPort());
zs->LSShutDownUpdate(zs->GetZoneID());
if (holdzones){
Log.Out(Logs::Detail, Logs::World_Server,"Hold Zones mode is ON - rebooting lost zone");
if(!zs->IsStaticZone())
RebootZone(inet_ntoa(in),zs->GetCPort(),zs->GetCAddress(),zs->GetID());
else
RebootZone(inet_ntoa(in),zs->GetCPort(),zs->GetCAddress(),zs->GetID(),database.GetZoneID(zs->GetZoneName()));
}
iterator.RemoveCurrent();
numzones--;
}
else {
iterator.Advance();
}
}
} }
bool ZSList::SendPacket(ServerPacket* pack) { bool ZSList::SendPacket(ServerPacket* pack) {
LinkedListIterator<ZoneServer*> iterator(list); auto iterator = list.begin();
while (iterator != list.end()) {
iterator.Reset(); (*iterator)->SendPacket(pack);
while(iterator.MoreElements()) { iterator++;
iterator.GetData()->SendPacket(pack);
iterator.Advance();
} }
return true; return true;
} }
bool ZSList::SendPacket(uint32 ZoneID, ServerPacket* pack) { bool ZSList::SendPacket(uint32 ZoneID, ServerPacket* pack) {
LinkedListIterator<ZoneServer*> iterator(list); auto iterator = list.begin();
while (iterator != list.end()) {
iterator.Reset(); if ((*iterator)->GetZoneID() == ZoneID) {
while(iterator.MoreElements()) { ZoneServer* tmp = (*iterator).get();
if (iterator.GetData()->GetZoneID() == ZoneID) { tmp->SendPacket(pack);
ZoneServer* tmp = iterator.GetData(); return true;
return(tmp->SendPacket(pack));
} }
iterator.Advance(); iterator++;
} }
return(false); return(false);
} }
bool ZSList::SendPacket(uint32 ZoneID, uint16 instanceID, ServerPacket* pack) { bool ZSList::SendPacket(uint32 ZoneID, uint16 instanceID, ServerPacket* pack) {
LinkedListIterator<ZoneServer*> iterator(list);
iterator.Reset();
if(instanceID != 0) if(instanceID != 0)
{ {
while(iterator.MoreElements()) { auto iterator = list.begin();
if(iterator.GetData()->GetInstanceID() == instanceID) { while (iterator != list.end()) {
ZoneServer* tmp = iterator.GetData(); if((*iterator)->GetInstanceID() == instanceID) {
return(tmp->SendPacket(pack)); ZoneServer* tmp = (*iterator).get();
tmp->SendPacket(pack);
return true;
} }
iterator.Advance(); iterator++;
} }
} }
else else
{ {
while(iterator.MoreElements()) { auto iterator = list.begin();
if (iterator.GetData()->GetZoneID() == ZoneID while (iterator != list.end()) {
&& iterator.GetData()->GetInstanceID() == 0) { if ((*iterator)->GetZoneID() == ZoneID
ZoneServer* tmp = iterator.GetData(); && (*iterator)->GetInstanceID() == 0) {
return(tmp->SendPacket(pack)); ZoneServer* tmp = (*iterator).get();
tmp->SendPacket(pack);
return true;
} }
iterator.Advance(); iterator++;
} }
} }
return(false); return(false);
} }
ZoneServer* ZSList::FindByName(const char* zonename) { ZoneServer* ZSList::FindByName(const char* zonename) {
LinkedListIterator<ZoneServer*> iterator(list); auto iterator = list.begin();
while (iterator != list.end()) {
iterator.Reset(); if (strcasecmp((*iterator)->GetZoneName(), zonename) == 0) {
while(iterator.MoreElements()) ZoneServer* tmp = (*iterator).get();
{
if (strcasecmp(iterator.GetData()->GetZoneName(), zonename) == 0) {
ZoneServer* tmp = iterator.GetData();
return tmp; return tmp;
} }
iterator.Advance(); iterator++;
} }
return 0; return 0;
} }
ZoneServer* ZSList::FindByID(uint32 ZoneID) { ZoneServer* ZSList::FindByID(uint32 ZoneID) {
LinkedListIterator<ZoneServer*> iterator(list); auto iterator = list.begin();
while (iterator != list.end()) {
iterator.Reset(); if ((*iterator)->GetID() == ZoneID) {
while(iterator.MoreElements()) { ZoneServer* tmp = (*iterator).get();
if (iterator.GetData()->GetID() == ZoneID) {
ZoneServer* tmp = iterator.GetData();
return tmp; return tmp;
} }
iterator.Advance(); iterator++;
} }
return 0; return 0;
} }
ZoneServer* ZSList::FindByZoneID(uint32 ZoneID) { ZoneServer* ZSList::FindByZoneID(uint32 ZoneID) {
LinkedListIterator<ZoneServer*> iterator(list); auto iterator = list.begin();
iterator.Reset(); while (iterator != list.end()) {
while(iterator.MoreElements()) ZoneServer* tmp = (*iterator).get();
{
ZoneServer* tmp = iterator.GetData();
if (tmp->GetZoneID() == ZoneID && tmp->GetInstanceID() == 0) { if (tmp->GetZoneID() == ZoneID && tmp->GetInstanceID() == 0) {
return tmp; return tmp;
} }
iterator.Advance(); iterator++;
} }
return 0; return 0;
} }
ZoneServer* ZSList::FindByPort(uint16 port) { ZoneServer* ZSList::FindByPort(uint16 port) {
LinkedListIterator<ZoneServer*> iterator(list); auto iterator = list.begin();
while (iterator != list.end()) {
iterator.Reset(); if ((*iterator)->GetCPort() == port) {
while(iterator.MoreElements()) ZoneServer* tmp = (*iterator).get();
{
if (iterator.GetData()->GetCPort() == port) {
ZoneServer* tmp = iterator.GetData();
return tmp; return tmp;
} }
iterator.Advance(); iterator++;
} }
return 0; return 0;
} }
ZoneServer* ZSList::FindByInstanceID(uint32 InstanceID) ZoneServer* ZSList::FindByInstanceID(uint32 InstanceID)
{ {
LinkedListIterator<ZoneServer*> iterator(list); auto iterator = list.begin();
while (iterator != list.end()) {
iterator.Reset(); if ((*iterator)->GetInstanceID() == InstanceID) {
while(iterator.MoreElements()) ZoneServer* tmp = (*iterator).get();
{
if (iterator.GetData()->GetInstanceID() == InstanceID) {
ZoneServer* tmp = iterator.GetData();
return tmp; return tmp;
} }
iterator.Advance(); iterator++;
} }
return 0; return 0;
} }
@ -283,11 +253,6 @@ void ZSList::ListLockedZones(const char* to, WorldTCPConnection* connection) {
} }
void ZSList::SendZoneStatus(const char* to, int16 admin, WorldTCPConnection* connection) { void ZSList::SendZoneStatus(const char* to, int16 admin, WorldTCPConnection* connection) {
LinkedListIterator<ZoneServer*> iterator(list);
struct in_addr in;
iterator.Reset();
char locked[4]; char locked[4];
if (WorldConfig::get()->Locked == true){ if (WorldConfig::get()->Locked == true){
strcpy(locked, "Yes"); strcpy(locked, "Yes");
@ -318,9 +283,10 @@ void ZSList::SendZoneStatus(const char* to, int16 admin, WorldTCPConnection* con
ZoneServer* zone_server_data = 0; ZoneServer* zone_server_data = 0;
while (iterator.MoreElements()) { auto iterator = list.begin();
zone_server_data = iterator.GetData(); while (iterator != list.end()) {
in.s_addr = zone_server_data->GetIP(); zone_server_data = (*iterator).get();
auto addr = zone_server_data->GetIP();
if (zone_server_data->IsStaticZone()){ if (zone_server_data->IsStaticZone()){
z++; z++;
@ -352,7 +318,7 @@ void ZSList::SendZoneStatus(const char* to, int16 admin, WorldTCPConnection* con
"#%-3i :: %s :: %15s:%-5i :: %2i :: %s:%i :: %s :: (%u)", "#%-3i :: %s :: %15s:%-5i :: %2i :: %s:%i :: %s :: (%u)",
zone_server_data->GetID(), zone_server_data->GetID(),
is_static_string, is_static_string,
inet_ntoa(in), addr.c_str(),
zone_server_data->GetPort(), zone_server_data->GetPort(),
zone_server_data->NumPlayers(), zone_server_data->NumPlayers(),
zone_server_data->GetCAddress(), zone_server_data->GetCAddress(),
@ -398,7 +364,7 @@ void ZSList::SendZoneStatus(const char* to, int16 admin, WorldTCPConnection* con
x++; x++;
} }
y++; y++;
iterator.Advance(); iterator++;
} }
if (connection->IsConsole()){ if (connection->IsConsole()){
@ -462,9 +428,7 @@ void ZSList::SendChannelMessageRaw(const char* from, const char* to, uint8 chan_
scm->language = language; scm->language = language;
scm->chan_num = chan_num; scm->chan_num = chan_num;
strcpy(&scm->message[0], message); strcpy(&scm->message[0], message);
if (scm->chan_num == 5 || scm->chan_num == 6 || scm->chan_num == 11) {
console_list.SendChannelMessage(scm);
}
pack->Deflate(); pack->Deflate();
SendPacket(pack); SendPacket(pack);
delete pack; delete pack;
@ -496,13 +460,6 @@ void ZSList::SendEmoteMessageRaw(const char* to, uint32 to_guilddbid, int16 to_m
ServerEmoteMessage_Struct* sem = (ServerEmoteMessage_Struct*) pack->pBuffer; ServerEmoteMessage_Struct* sem = (ServerEmoteMessage_Struct*) pack->pBuffer;
if (to) { if (to) {
if (to[0] == '*') {
Console* con = console_list.FindByAccountName(&to[1]);
if (con)
con->SendEmoteMessageRaw(to, to_guilddbid, to_minstatus, type, message);
delete pack;
return;
}
strcpy((char *) sem->to, to); strcpy((char *) sem->to, to);
} }
else { else {
@ -519,8 +476,6 @@ void ZSList::SendEmoteMessageRaw(const char* to, uint32 to_guilddbid, int16 to_m
pack->Deflate(); pack->Deflate();
if (tempto[0] == 0) { if (tempto[0] == 0) {
SendPacket(pack); SendPacket(pack);
if (to_guilddbid == 0)
console_list.SendEmoteMessageRaw(type, message);
} }
else { else {
ZoneServer* zs = FindByName(to); ZoneServer* zs = FindByName(to);
@ -579,23 +534,23 @@ void ZSList::SOPZoneBootup(const char* adminname, uint32 ZoneServerID, const cha
void ZSList::RebootZone(const char* ip1,uint16 port,const char* ip2, uint32 skipid, uint32 zoneid){ void ZSList::RebootZone(const char* ip1,uint16 port,const char* ip2, uint32 skipid, uint32 zoneid){
// get random zone // get random zone
LinkedListIterator<ZoneServer*> iterator(list);
uint32 x = 0; uint32 x = 0;
iterator.Reset(); auto iterator = list.begin();
while(iterator.MoreElements()) { while (iterator != list.end()) {
x++; x++;
iterator.Advance(); iterator++;
} }
if (x == 0) if (x == 0)
return; return;
auto tmp = new ZoneServer *[x]; auto tmp = new ZoneServer *[x];
uint32 y = 0; uint32 y = 0;
iterator.Reset();
while(iterator.MoreElements()) { iterator = list.begin();
if (!strcmp(iterator.GetData()->GetCAddress(),ip2) && !iterator.GetData()->IsBootingUp() && iterator.GetData()->GetID() != skipid) { while (iterator != list.end()) {
tmp[y++] = iterator.GetData(); if (!strcmp((*iterator)->GetCAddress(),ip2) && !(*iterator)->IsBootingUp() && (*iterator)->GetID() != skipid) {
tmp[y++] = (*iterator).get();
} }
iterator.Advance(); iterator++;
} }
if (y == 0) { if (y == 0) {
safe_delete_array(tmp); safe_delete_array(tmp);
@ -645,95 +600,56 @@ uint16 ZSList::GetAvailableZonePort()
uint32 ZSList::TriggerBootup(uint32 iZoneID, uint32 iInstanceID) { uint32 ZSList::TriggerBootup(uint32 iZoneID, uint32 iInstanceID) {
if(iInstanceID > 0) if(iInstanceID > 0)
{ {
LinkedListIterator<ZoneServer*> iterator(list); auto iterator = list.begin();
iterator.Reset(); while (iterator != list.end()) {
while(iterator.MoreElements()) { if((*iterator)->GetInstanceID() == iInstanceID)
if(iterator.GetData()->GetInstanceID() == iInstanceID)
{ {
return iterator.GetData()->GetID(); return (*iterator)->GetID();
} }
iterator.Advance(); iterator++;
} }
iterator.Reset(); iterator = list.begin();
while(iterator.MoreElements()) { while (iterator != list.end()) {
if (iterator.GetData()->GetZoneID() == 0 && !iterator.GetData()->IsBootingUp()) { if ((*iterator)->GetZoneID() == 0 && !(*iterator)->IsBootingUp()) {
ZoneServer* zone=iterator.GetData(); ZoneServer* zone=(*iterator).get();
zone->TriggerBootup(iZoneID, iInstanceID); zone->TriggerBootup(iZoneID, iInstanceID);
return zone->GetID(); return zone->GetID();
} }
iterator.Advance(); iterator++;
} }
return 0; return 0;
} }
else else
{ {
LinkedListIterator<ZoneServer*> iterator(list); auto iterator = list.begin();
iterator.Reset(); while (iterator != list.end()) {
while(iterator.MoreElements()) { if((*iterator)->GetZoneID() == iZoneID && (*iterator)->GetInstanceID() == 0)
if(iterator.GetData()->GetZoneID() == iZoneID && iterator.GetData()->GetInstanceID() == 0)
{ {
return iterator.GetData()->GetID(); return (*iterator)->GetID();
} }
iterator.Advance(); iterator++;
} }
iterator.Reset(); iterator = list.begin();
while(iterator.MoreElements()) { while (iterator != list.end()) {
if (iterator.GetData()->GetZoneID() == 0 && !iterator.GetData()->IsBootingUp()) { if ((*iterator)->GetZoneID() == 0 && !(*iterator)->IsBootingUp()) {
ZoneServer* zone=iterator.GetData(); ZoneServer* zone = (*iterator).get();
zone->TriggerBootup(iZoneID); zone->TriggerBootup(iZoneID);
return zone->GetID(); return zone->GetID();
} }
iterator.Advance(); iterator++;
} }
return 0; return 0;
} }
/*Old Random boot zones use this if your server is distributed across computers.
LinkedListIterator<ZoneServer*> iterator(list);
srand(time(nullptr));
uint32 x = 0;
iterator.Reset();
while(iterator.MoreElements()) {
x++;
iterator.Advance();
}
if (x == 0) {
return 0;
}
ZoneServer** tmp = new ZoneServer*[x];
uint32 y = 0;
iterator.Reset();
while(iterator.MoreElements()) {
if (iterator.GetData()->GetZoneID() == 0 && !iterator.GetData()->IsBootingUp()) {
tmp[y++] = iterator.GetData();
}
iterator.Advance();
}
if (y == 0) {
safe_delete(tmp);
return 0;
}
uint32 z = rand() % y;
tmp[z]->TriggerBootup(iZoneID);
uint32 ret = tmp[z]->GetID();
safe_delete(tmp);
return ret;
*/
} }
void ZSList::SendLSZones(){ void ZSList::SendLSZones(){
LinkedListIterator<ZoneServer*> iterator(list); auto iterator = list.begin();
iterator.Reset(); while(iterator != list.end()) {
while(iterator.MoreElements()) { ZoneServer* zs = (*iterator).get();
ZoneServer* zs = iterator.GetData();
zs->LSBootUpdate(zs->GetZoneID(),true); zs->LSBootUpdate(zs->GetZoneID(),true);
iterator.Advance(); iterator++;
} }
} }
@ -742,12 +658,11 @@ int ZSList::GetZoneCount() {
} }
void ZSList::GetZoneIDList(std::vector<uint32> &zones) { void ZSList::GetZoneIDList(std::vector<uint32> &zones) {
LinkedListIterator<ZoneServer*> iterator(list); auto iterator = list.begin();
iterator.Reset(); while (iterator != list.end()) {
while(iterator.MoreElements()) { ZoneServer* zs = (*iterator).get();
ZoneServer* zs = iterator.GetData();
zones.push_back(zs->GetID()); zones.push_back(zs->GetID());
iterator.Advance(); iterator++;
} }
} }

View File

@ -6,6 +6,7 @@
#include "../common/timer.h" #include "../common/timer.h"
#include "../common/linked_list.h" #include "../common/linked_list.h"
#include <vector> #include <vector>
#include <memory>
class WorldTCPConnection; class WorldTCPConnection;
class ServerPacket; class ServerPacket;
@ -35,6 +36,7 @@ public:
void SendTimeSync(); void SendTimeSync();
void Add(ZoneServer* zoneserver); void Add(ZoneServer* zoneserver);
void Remove(const std::string &uuid);
void Process(); void Process();
void KillAll(); void KillAll();
bool SendPacket(ServerPacket* pack); bool SendPacket(ServerPacket* pack);
@ -60,7 +62,7 @@ public:
protected: protected:
uint32 NextID; uint32 NextID;
LinkedList<ZoneServer*> list; std::list<std::unique_ptr<ZoneServer>> list;
uint16 pLockedZones[MaxLockedZones]; uint16 pLockedZones[MaxLockedZones];
uint32 CurGroupID; uint32 CurGroupID;
uint16 LastAllocatedPort; uint16 LastAllocatedPort;

View File

@ -40,7 +40,6 @@
extern ClientList client_list; extern ClientList client_list;
extern GroupLFPList LFPGroupList; extern GroupLFPList LFPGroupList;
extern ZSList zoneserver_list; extern ZSList zoneserver_list;
extern ConsoleList console_list;
extern LoginServerList loginserverlist; extern LoginServerList loginserverlist;
extern volatile bool RunLoops; extern volatile bool RunLoops;
extern AdventureManager adventure_manager; extern AdventureManager adventure_manager;
@ -48,11 +47,10 @@ extern UCSConnection UCSLink;
extern QueryServConnection QSLink; extern QueryServConnection QSLink;
void CatchSignal(int sig_num); void CatchSignal(int sig_num);
ZoneServer::ZoneServer(EmuTCPConnection* itcpc) ZoneServer::ZoneServer(std::shared_ptr<EQ::Net::ServertalkServerConnection> connection)
: WorldTCPConnection(), tcpc(itcpc), zone_boot_timer(5000) { : tcpc(connection), zone_boot_timer(5000) {
/* Set Process tracking variable defaults */ /* Set Process tracking variable defaults */
memset(zone_name, 0, sizeof(zone_name)); memset(zone_name, 0, sizeof(zone_name));
memset(compiled, 0, sizeof(compiled)); memset(compiled, 0, sizeof(compiled));
memset(client_address, 0, sizeof(client_address)); memset(client_address, 0, sizeof(client_address));
@ -67,12 +65,20 @@ ZoneServer::ZoneServer(EmuTCPConnection* itcpc)
is_authenticated = false; is_authenticated = false;
is_static_zone = false; is_static_zone = false;
zone_player_count = 0; zone_player_count = 0;
tcpc->OnAnyMessage(std::bind(&ZoneServer::HandleMessage, this, std::placeholders::_1, std::placeholders::_2));
boot_timer_obj.reset(new EQ::Timer(1000, true, [this](EQ::Timer *obj) {
if (zone_boot_timer.Check()) {
LSBootUpdate(GetZoneID(), true);
zone_boot_timer.Disable();
}
}));
} }
ZoneServer::~ZoneServer() { ZoneServer::~ZoneServer() {
if (RunLoops) if (RunLoops)
client_list.CLERemoveZSRef(this); client_list.CLERemoveZSRef(this);
tcpc->Free();
} }
bool ZoneServer::SetZone(uint32 iZoneID, uint32 iInstanceID, bool iStaticZone) { bool ZoneServer::SetZone(uint32 iZoneID, uint32 iInstanceID, bool iStaticZone) {
@ -173,53 +179,11 @@ void ZoneServer::LSSleepUpdate(uint32 zoneid){
} }
} }
bool ZoneServer::Process() { void ZoneServer::HandleMessage(uint16 opcode, const EQ::Net::Packet &p) {
if (!tcpc->Connected()) ServerPacket tpack(opcode, p);
return false; ServerPacket *pack = &tpack;
if(zone_boot_timer.Check()){
LSBootUpdate(GetZoneID(), true); switch(opcode) {
zone_boot_timer.Disable();
}
ServerPacket *pack = 0;
while((pack = tcpc->PopPacket())) {
if (!is_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) {
is_authenticated = true;
Log.Out(Logs::Detail, Logs::World_Server, "Zone process connected.");
}
else {
struct in_addr in;
in.s_addr = GetIP();
Log.Out(Logs::General, Logs::Error, "Zone authorization failed.");
auto pack = new ServerPacket(ServerOP_ZAAuthFailed);
SendPacket(pack);
safe_delete(pack);
Disconnect();
return false;
}
}
else {
struct in_addr in;
in.s_addr = GetIP();
Log.Out(Logs::General, Logs::Error, "Zone authorization failed.");
auto pack = new ServerPacket(ServerOP_ZAAuthFailed);
SendPacket(pack);
safe_delete(pack);
Disconnect();
return false;
}
}
else
{
Log.Out(Logs::General, Logs::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.");
is_authenticated = true;
}
}
switch(pack->opcode) {
case 0: case 0:
break; break;
case ServerOP_KeepAlive: { case ServerOP_KeepAlive: {
@ -449,13 +413,6 @@ bool ZoneServer::Process() {
break; break;
} }
if (scm->chan_num == 7 || scm->chan_num == 14) { if (scm->chan_num == 7 || scm->chan_num == 14) {
if (scm->deliverto[0] == '*') {
Console* con = 0;
con = console_list.FindByAccountName(&scm->deliverto[1]);
if (((!con) || (!con->SendChannelMessage(scm))) && (!scm->noreply))
zoneserver_list.SendEmoteMessage(scm->from, 0, 0, 0, "%s is not online at this time.", scm->to);
break;
}
ClientListEntry* cle = client_list.FindCharacter(scm->deliverto); ClientListEntry* cle = client_list.FindCharacter(scm->deliverto);
if (cle == 0 || cle->Online() < CLE_Status_Zoning || if (cle == 0 || cle->Online() < CLE_Status_Zoning ||
(cle->TellsOff() && ((cle->Anon() == 1 && scm->fromadmin < cle->Admin()) || scm->fromadmin < 80))) { (cle->TellsOff() && ((cle->Anon() == 1 && scm->fromadmin < cle->Admin()) || scm->fromadmin < 80))) {
@ -504,9 +461,6 @@ bool ZoneServer::Process() {
cle->Server()->SendPacket(pack); cle->Server()->SendPacket(pack);
} }
else { else {
if (scm->chan_num == 5 || scm->chan_num == 6 || scm->chan_num == 11) {
console_list.SendChannelMessage(scm);
}
zoneserver_list.SendPacket(pack); zoneserver_list.SendPacket(pack);
} }
break; break;
@ -1054,12 +1008,7 @@ bool ZoneServer::Process() {
SpawnPlayerCorpse_Struct* s = (SpawnPlayerCorpse_Struct*)pack->pBuffer; SpawnPlayerCorpse_Struct* s = (SpawnPlayerCorpse_Struct*)pack->pBuffer;
ZoneServer* zs = zoneserver_list.FindByZoneID(s->zone_id); ZoneServer* zs = zoneserver_list.FindByZoneID(s->zone_id);
if(zs) { if(zs) {
if (zs->SendPacket(pack)) { zs->SendPacket(pack);
Log.Out(Logs::Detail, Logs::World_Server,"Sent request to spawn player corpse id %i in zone %u.",s->player_corpse_id, s->zone_id);
}
else {
Log.Out(Logs::Detail, Logs::World_Server,"Could not send request to spawn player corpse id %i in zone %u.",s->player_corpse_id, s->zone_id);
}
} }
break; break;
} }
@ -1076,12 +1025,7 @@ bool ZoneServer::Process() {
{ {
zs = zoneserver_list.FindByInstanceID(cle->instance()); zs = zoneserver_list.FindByInstanceID(cle->instance());
if(zs) { if(zs) {
if(zs->SendPacket(pack)) { zs->SendPacket(pack);
Log.Out(Logs::Detail, Logs::World_Server, "Sent consent packet from player %s to player %s in zone %u.", s->ownername, s->grantname, cle->instance());
}
else {
Log.Out(Logs::Detail, Logs::World_Server, "Unable to locate zone record for instance id %u in zoneserver list for ServerOP_Consent operation.", s->instance_id);
}
} }
else else
{ {
@ -1095,8 +1039,7 @@ bool ZoneServer::Process() {
scs->message_string_id = 101; scs->message_string_id = 101;
zs = zoneserver_list.FindByInstanceID(s->instance_id); zs = zoneserver_list.FindByInstanceID(s->instance_id);
if(zs) { if(zs) {
if(!zs->SendPacket(pack)) zs->SendPacket(pack);
Log.Out(Logs::Detail, Logs::World_Server, "Unable to send consent response back to player %s in instance %u.", s->ownername, zs->GetInstanceID());
} }
else { else {
Log.Out(Logs::Detail, Logs::World_Server, "Unable to locate zone record for instance id %u in zoneserver list for ServerOP_Consent_Response operation.", s->instance_id); Log.Out(Logs::Detail, Logs::World_Server, "Unable to locate zone record for instance id %u in zoneserver list for ServerOP_Consent_Response operation.", s->instance_id);
@ -1108,12 +1051,7 @@ bool ZoneServer::Process() {
{ {
zs = zoneserver_list.FindByZoneID(cle->zone()); zs = zoneserver_list.FindByZoneID(cle->zone());
if(zs) { if(zs) {
if(zs->SendPacket(pack)) { zs->SendPacket(pack);
Log.Out(Logs::Detail, Logs::World_Server, "Sent consent packet from player %s to player %s in zone %u.", s->ownername, s->grantname, cle->zone());
}
else {
Log.Out(Logs::Detail, Logs::World_Server, "Unable to locate zone record for zone id %u in zoneserver list for ServerOP_Consent operation.", s->zone_id);
}
} }
else { else {
// send target not found back to requester // send target not found back to requester
@ -1126,8 +1064,7 @@ bool ZoneServer::Process() {
scs->message_string_id = 101; scs->message_string_id = 101;
zs = zoneserver_list.FindByZoneID(s->zone_id); zs = zoneserver_list.FindByZoneID(s->zone_id);
if(zs) { if(zs) {
if(!zs->SendPacket(pack)) zs->SendPacket(pack);
Log.Out(Logs::Detail, Logs::World_Server, "Unable to send consent response back to player %s in zone %s.", s->ownername, zs->GetZoneName());
} }
else { else {
Log.Out(Logs::Detail, Logs::World_Server, "Unable to locate zone record for zone id %u in zoneserver list for ServerOP_Consent_Response operation.", s->zone_id); Log.Out(Logs::Detail, Logs::World_Server, "Unable to locate zone record for zone id %u in zoneserver list for ServerOP_Consent_Response operation.", s->zone_id);
@ -1147,8 +1084,7 @@ bool ZoneServer::Process() {
scs->message_string_id = 397; scs->message_string_id = 397;
zs = zoneserver_list.FindByZoneID(s->zone_id); zs = zoneserver_list.FindByZoneID(s->zone_id);
if(zs) { if(zs) {
if(!zs->SendPacket(pack)) zs->SendPacket(pack);
Log.Out(Logs::Detail, Logs::World_Server, "Unable to send consent response back to player %s in zone %s.", s->ownername, zs->GetZoneName());
} }
else { else {
Log.Out(Logs::Detail, Logs::World_Server, "Unable to locate zone record for zone id %u in zoneserver list for ServerOP_Consent_Response operation.", s->zone_id); Log.Out(Logs::Detail, Logs::World_Server, "Unable to locate zone record for zone id %u in zoneserver list for ServerOP_Consent_Response operation.", s->zone_id);
@ -1167,8 +1103,7 @@ bool ZoneServer::Process() {
{ {
ZoneServer* zs = zoneserver_list.FindByInstanceID(s->instance_id); ZoneServer* zs = zoneserver_list.FindByInstanceID(s->instance_id);
if(zs) { if(zs) {
if(!zs->SendPacket(pack)) zs->SendPacket(pack);
Log.Out(Logs::Detail, Logs::World_Server, "Unable to send consent response back to player %s in instance %u.", s->ownername, zs->GetInstanceID());
} }
else { else {
Log.Out(Logs::Detail, Logs::World_Server, "Unable to locate zone record for instance id %u in zoneserver list for ServerOP_Consent_Response operation.", s->instance_id); Log.Out(Logs::Detail, Logs::World_Server, "Unable to locate zone record for instance id %u in zoneserver list for ServerOP_Consent_Response operation.", s->instance_id);
@ -1178,8 +1113,7 @@ bool ZoneServer::Process() {
{ {
ZoneServer* zs = zoneserver_list.FindByZoneID(s->zone_id); ZoneServer* zs = zoneserver_list.FindByZoneID(s->zone_id);
if(zs) { if(zs) {
if(!zs->SendPacket(pack)) zs->SendPacket(pack);
Log.Out(Logs::Detail, Logs::World_Server, "Unable to send consent response back to player %s in zone %s.", s->ownername, zs->GetZoneName());
} }
else { else {
Log.Out(Logs::Detail, Logs::World_Server, "Unable to locate zone record for zone id %u in zoneserver list for ServerOP_Consent_Response operation.", s->zone_id); Log.Out(Logs::Detail, Logs::World_Server, "Unable to locate zone record for zone id %u in zoneserver list for ServerOP_Consent_Response operation.", s->zone_id);
@ -1358,14 +1292,6 @@ bool ZoneServer::Process() {
break; break;
} }
} }
if (pack) {
safe_delete(pack);
}
else {
Log.Out(Logs::Detail, Logs::World_Server, "Zoneserver process attempted to delete pack when pack does not exist.");
}
}
return true;
} }
void ZoneServer::SendEmoteMessage(const char* to, uint32 to_guilddbid, int16 to_minstatus, uint32 type, const char* message, ...) { void ZoneServer::SendEmoteMessage(const char* to, uint32 to_guilddbid, int16 to_minstatus, uint32 type, const char* message, ...) {

View File

@ -19,7 +19,9 @@
#define ZONESERVER_H #define ZONESERVER_H
#include "world_tcp_connection.h" #include "world_tcp_connection.h"
#include "../common/emu_tcp_connection.h" #include "../net/servertalk_server.h"
#include "../event/timer.h"
#include "../timer.h"
#include <string.h> #include <string.h>
#include <string> #include <string>
@ -29,17 +31,16 @@ class ServerPacket;
class ZoneServer : public WorldTCPConnection { class ZoneServer : public WorldTCPConnection {
public: public:
ZoneServer(EmuTCPConnection* itcpc); ZoneServer(std::shared_ptr<EQ::Net::ServertalkServerConnection> connection);
~ZoneServer(); ~ZoneServer();
virtual inline bool IsZoneServer() { return true; } virtual inline bool IsZoneServer() { return true; }
bool Process(); void SendPacket(ServerPacket* pack) { tcpc->SendPacket(pack); }
bool SendPacket(ServerPacket* pack) { return tcpc->SendPacket(pack); }
void SendEmoteMessage(const char* to, uint32 to_guilddbid, int16 to_minstatus, uint32 type, const char* message, ...); void SendEmoteMessage(const char* to, uint32 to_guilddbid, int16 to_minstatus, uint32 type, const char* message, ...);
void SendEmoteMessageRaw(const char* to, uint32 to_guilddbid, int16 to_minstatus, uint32 type, const char* message); void SendEmoteMessageRaw(const char* to, uint32 to_guilddbid, int16 to_minstatus, uint32 type, const char* message);
bool SetZone(uint32 iZoneID, uint32 iInstanceID = 0, bool iStaticZone = false); bool SetZone(uint32 iZoneID, uint32 iInstanceID = 0, bool iStaticZone = false);
void TriggerBootup(uint32 iZoneID = 0, uint32 iInstanceID = 0, const char* iAdminName = 0, bool iMakeStatic = false); void TriggerBootup(uint32 iZoneID = 0, uint32 iInstanceID = 0, const char* iAdminName = 0, bool iMakeStatic = false);
void Disconnect() { tcpc->Disconnect(); } void Disconnect() { auto handle = tcpc->Handle(); if (handle) { handle->Disconnect(); } }
void IncomingClient(Client* client); void IncomingClient(Client* client);
void LSBootUpdate(uint32 zoneid, uint32 iInstanceID = 0, bool startup = false); void LSBootUpdate(uint32 zoneid, uint32 iInstanceID = 0, bool startup = false);
void LSSleepUpdate(uint32 zoneid); void LSSleepUpdate(uint32 zoneid);
@ -47,14 +48,15 @@ public:
uint32 GetPrevZoneID() { return zone_server_previous_zone_id; } uint32 GetPrevZoneID() { return zone_server_previous_zone_id; }
void ChangeWID(uint32 iCharID, uint32 iWID); void ChangeWID(uint32 iCharID, uint32 iWID);
void SendGroupIDs(); void SendGroupIDs();
void HandleMessage(uint16 opcode, const EQ::Net::Packet &p);
inline const char* GetZoneName() const { return zone_name; } inline const char* GetZoneName() const { return zone_name; }
inline const char* GetZoneLongName() const { return long_name; } inline const char* GetZoneLongName() const { return long_name; }
const char* GetCompileTime() const{ return compiled; } const char* GetCompileTime() const{ return compiled; }
void SetCompile(char* in_compile){ strcpy(compiled,in_compile); } void SetCompile(char* in_compile){ strcpy(compiled,in_compile); }
inline uint32 GetZoneID() const { return zone_server_zone_id; } inline uint32 GetZoneID() const { return zone_server_zone_id; }
inline uint32 GetIP() const { return tcpc->GetrIP(); } inline std::string GetIP() const { return tcpc->Handle() ? tcpc->Handle()->RemoteIP() : ""; }
inline uint16 GetPort() const { return tcpc->GetrPort(); } inline uint16 GetPort() const { return tcpc->Handle() ? tcpc->Handle()->RemotePort() : 0; }
inline const char* GetCAddress() const { return client_address; } inline const char* GetCAddress() const { return client_address; }
inline const char* GetCLocalAddress() const { return client_local_address; } inline const char* GetCLocalAddress() const { return client_local_address; }
inline uint16 GetCPort() const { return client_port; } inline uint16 GetCPort() const { return client_port; }
@ -66,6 +68,7 @@ public:
inline void RemovePlayer() { zone_player_count--; } inline void RemovePlayer() { zone_player_count--; }
inline const char * GetLaunchName() const { return(launcher_name.c_str()); } inline const char * GetLaunchName() const { return(launcher_name.c_str()); }
inline const char * GetLaunchedName() const { return(launched_name.c_str()); } inline const char * GetLaunchedName() const { return(launched_name.c_str()); }
std::string GetUUID() const { return tcpc->GetUUID(); }
inline uint32 GetInstanceID() { return instance_id; } inline uint32 GetInstanceID() { return instance_id; }
inline void SetInstanceID(uint32 i) { instance_id = i; } inline void SetInstanceID(uint32 i) { instance_id = i; }
@ -73,7 +76,8 @@ public:
inline uint32 GetZoneOSProcessID() { return zone_os_process_id; } inline uint32 GetZoneOSProcessID() { return zone_os_process_id; }
private: private:
EmuTCPConnection* const tcpc; std::shared_ptr<EQ::Net::ServertalkServerConnection> tcpc;
std::unique_ptr<EQ::Timer> boot_timer_obj;
uint32 zone_server_id; uint32 zone_server_id;
char client_address[250]; char client_address[250];

View File

@ -24,6 +24,7 @@
#include "../common/spdat.h" #include "../common/spdat.h"
#include "../common/string_util.h" #include "../common/string_util.h"
#include "../common/data_verification.h" #include "../common/data_verification.h"
#include "../common/misc_functions.h"
#include "queryserv.h" #include "queryserv.h"
#include "quest_parser_collection.h" #include "quest_parser_collection.h"
#include "string_ids.h" #include "string_ids.h"

View File

@ -172,7 +172,6 @@ int command_init(void)
command_add("chat", "[channel num] [message] - Send a channel message to all zones", 200, command_chat) || command_add("chat", "[channel num] [message] - Send a channel message to all zones", 200, command_chat) ||
command_add("checklos", "- Check for line of sight to your target", 50, command_checklos) || command_add("checklos", "- Check for line of sight to your target", 50, command_checklos) ||
command_add("clearinvsnapshots", "[use rule] - Clear inventory snapshot history (true - elapsed entries, false - all entries)", 200, command_clearinvsnapshots) || command_add("clearinvsnapshots", "[use rule] - Clear inventory snapshot history (true - elapsed entries, false - all entries)", 200, command_clearinvsnapshots) ||
command_add("connectworldserver", "- Make zone attempt to connect to worldserver", 200, command_connectworldserver) ||
command_add("corpse", "- Manipulate corpses, use with no arguments for help", 50, command_corpse) || command_add("corpse", "- Manipulate corpses, use with no arguments for help", 50, command_corpse) ||
command_add("crashtest", "- Crash the zoneserver", 255, command_crashtest) || command_add("crashtest", "- Crash the zoneserver", 255, command_crashtest) ||
command_add("cvs", "- Summary of client versions currently online.", 200, command_cvs) || command_add("cvs", "- Summary of client versions currently online.", 200, command_cvs) ||
@ -820,17 +819,6 @@ void command_setanim(Client *c, const Seperator *sep)
c->Message(0, "Usage: #setanim [animnum]"); c->Message(0, "Usage: #setanim [animnum]");
} }
void command_connectworldserver(Client *c, const Seperator *sep)
{
if(worldserver.Connected())
c->Message(0, "Error: Already connected to world server");
else
{
c->Message(0, "Attempting to connect to world server...");
worldserver.AsyncConnect();
}
}
void command_serverinfo(Client *c, const Seperator *sep) void command_serverinfo(Client *c, const Seperator *sep)
{ {
#ifdef _WINDOWS #ifdef _WINDOWS

View File

@ -19,6 +19,7 @@
#include "../common/global_define.h" #include "../common/global_define.h"
#include "../common/eqemu_logsys.h" #include "../common/eqemu_logsys.h"
#include "../common/spdat.h" #include "../common/spdat.h"
#include "../common/misc_functions.h"
#include "client.h" #include "client.h"
#include "entity.h" #include "entity.h"

View File

@ -18,6 +18,7 @@
#include "../common/spdat.h" #include "../common/spdat.h"
#include "../common/string_util.h" #include "../common/string_util.h"
#include "../common/misc_functions.h"
#include "quest_parser_collection.h" #include "quest_parser_collection.h"
#include "string_ids.h" #include "string_ids.h"

View File

@ -216,7 +216,6 @@ int main(int argc, char** argv) {
worldserver.SetLauncherName("NONE"); worldserver.SetLauncherName("NONE");
} }
worldserver.SetPassword(Config->SharedKey.c_str());
Log.Out(Logs::General, Logs::Zone_Server, "Connecting to MySQL..."); Log.Out(Logs::General, Logs::Zone_Server, "Connecting to MySQL...");
if (!database.Connect( if (!database.Connect(
@ -397,9 +396,7 @@ int main(int argc, char** argv) {
Log.Out(Logs::General, Logs::Zone_Server, "Loading quests"); Log.Out(Logs::General, Logs::Zone_Server, "Loading quests");
parse->ReloadQuests(); parse->ReloadQuests();
if (!worldserver.Connect()) { worldserver.Connect();
Log.Out(Logs::General, Logs::Error, "Worldserver Connection Failed :: worldserver.Connect()");
}
Timer InterserverTimer(INTERSERVER_TIMER); // does MySQL pings and auto-reconnect Timer InterserverTimer(INTERSERVER_TIMER); // does MySQL pings and auto-reconnect
#ifdef EQPROFILE #ifdef EQPROFILE
@ -440,8 +437,6 @@ int main(int argc, char** argv) {
//Advance the timer to our current point in time //Advance the timer to our current point in time
Timer::SetCurrentTime(); Timer::SetCurrentTime();
worldserver.Process();
if (!eqsf_open && Config->ZonePort != 0) { if (!eqsf_open && Config->ZonePort != 0) {
Log.Out(Logs::General, Logs::Zone_Server, "Starting EQ Network server on port %d", Config->ZonePort); Log.Out(Logs::General, Logs::Zone_Server, "Starting EQ Network server on port %d", Config->ZonePort);
@ -524,10 +519,7 @@ int main(int argc, char** argv) {
if (InterserverTimer.Check()) { if (InterserverTimer.Check()) {
InterserverTimer.Start(); InterserverTimer.Start();
database.ping(); database.ping();
// AsyncLoadVariables(dbasync, &database);
entity_list.UpdateWho(); entity_list.UpdateWho();
if (worldserver.TryReconnect() && (!worldserver.Connected()))
worldserver.AsyncConnect();
} }
}); });
@ -553,7 +545,6 @@ int main(int argc, char** argv) {
if (zone != 0) if (zone != 0)
Zone::Shutdown(true); Zone::Shutdown(true);
//Fix for Linux world server problem. //Fix for Linux world server problem.
worldserver.Disconnect();
safe_delete(taskmanager); safe_delete(taskmanager);
command_deinit(); command_deinit();
#ifdef BOTS #ifdef BOTS
@ -576,7 +567,6 @@ void Shutdown()
{ {
Zone::Shutdown(true); Zone::Shutdown(true);
RunLoops = false; RunLoops = false;
worldserver.Disconnect();
Log.Out(Logs::General, Logs::Zone_Server, "Shutting down..."); Log.Out(Logs::General, Logs::Zone_Server, "Shutting down...");
Log.CloseFileLogs(); Log.CloseFileLogs();
} }

View File

@ -25,6 +25,7 @@
#include "../common/skills.h" #include "../common/skills.h"
#include "../common/spdat.h" #include "../common/spdat.h"
#include "../common/data_verification.h" #include "../common/data_verification.h"
#include "../common/misc_functions.h"
#include "quest_parser_collection.h" #include "quest_parser_collection.h"
#include "string_ids.h" #include "string_ids.h"

View File

@ -76,6 +76,7 @@ Copyright (C) 2001-2002 EQEMu Development Team (http://eqemu.org)
#include "../common/spdat.h" #include "../common/spdat.h"
#include "../common/string_util.h" #include "../common/string_util.h"
#include "../common/data_verification.h" #include "../common/data_verification.h"
#include "../common/misc_functions.h"
#include "quest_parser_collection.h" #include "quest_parser_collection.h"
#include "string_ids.h" #include "string_ids.h"

View File

@ -18,6 +18,7 @@
#include "../common/eq_packet_structs.h" #include "../common/eq_packet_structs.h"
#include "../common/string_util.h" #include "../common/string_util.h"
#include "../common/misc_functions.h"
#include "client.h" #include "client.h"
#include "entity.h" #include "entity.h"

View File

@ -20,6 +20,7 @@
#include "../common/eqemu_logsys.h" #include "../common/eqemu_logsys.h"
#include "../common/rulesys.h" #include "../common/rulesys.h"
#include "../common/string_util.h" #include "../common/string_util.h"
#include "../common/misc_functions.h"
#include "client.h" #include "client.h"
#include "entity.h" #include "entity.h"

View File

@ -66,7 +66,6 @@ extern QuestParserCollection *parse;
// QuestParserCollection *parse = 0; // QuestParserCollection *parse = 0;
WorldServer::WorldServer() WorldServer::WorldServer()
: WorldConnection(EmuTCPConnection::packetModeZone)
{ {
cur_groupid = 0; cur_groupid = 0;
last_groupid = 0; last_groupid = 0;
@ -76,18 +75,37 @@ WorldServer::WorldServer()
WorldServer::~WorldServer() { WorldServer::~WorldServer() {
} }
/*void WorldServer::SendGuildJoin(GuildJoin_Struct* gj){ void WorldServer::Connect()
ServerPacket* pack = new ServerPacket(ServerOP_GuildJoin, sizeof(GuildJoin_Struct)); {
GuildJoin_Struct* wgj = (GuildJoin_Struct*)pack->pBuffer; m_connection.reset(new EQ::Net::ServertalkClient(Config->WorldIP, Config->WorldTCPPort, false, "Zone", Config->SharedKey));
wgj->class_=gj->class_; m_connection->OnConnect([this](EQ::Net::ServertalkClient *client) {
wgj->guild_id=gj->guild_id; OnConnected();
wgj->level=gj->level; });
strcpy(wgj->name,gj->name);
wgj->rank=gj->rank; //TODO FIX MKAY
wgj->zoneid=gj->zoneid; //m_connection->OnAnyMessage(std::bind(&WorldServer::HandleMessage, this, std::placeholders::_1, std::placeholders::_2));
SendPacket(pack); }
safe_delete(pack);
}*/ bool WorldServer::SendPacket(ServerPacket *pack)
{
m_connection->SendPacket(pack);
return true;
}
std::string WorldServer::GetIP() const
{
return m_connection->Handle()->RemoteIP();
}
uint16 WorldServer::GetPort() const
{
return m_connection->Handle()->RemotePort();
}
bool WorldServer::Connected() const
{
return m_connection->Connected();
}
void WorldServer::SetZoneData(uint32 iZoneID, uint32 iInstanceID) { void WorldServer::SetZoneData(uint32 iZoneID, uint32 iInstanceID) {
auto pack = new ServerPacket(ServerOP_SetZone, sizeof(SetZone_Struct)); auto pack = new ServerPacket(ServerOP_SetZone, sizeof(SetZone_Struct));
@ -102,7 +120,6 @@ void WorldServer::SetZoneData(uint32 iZoneID, uint32 iInstanceID) {
} }
void WorldServer::OnConnected() { void WorldServer::OnConnected() {
WorldConnection::OnConnected();
ServerPacket* pack; ServerPacket* pack;
/* Tell the launcher what our information is */ /* Tell the launcher what our information is */
@ -153,17 +170,13 @@ void WorldServer::OnConnected() {
SendPacket(pack); SendPacket(pack);
safe_delete(pack); safe_delete(pack);
} }
/* Zone Process Packets from World */ /* Zone Process Packets from World */
void WorldServer::Process() { void WorldServer::HandleMessage(uint16 opcode, const EQ::Net::Packet &p)
WorldConnection::Process(); {
ServerPacket tpack(opcode, p);
if (!Connected()) ServerPacket *pack = &tpack;
return; switch(opcode) {
ServerPacket *pack = 0;
while((pack = tcpc.PopPacket())) {
Log.Out(Logs::Detail, Logs::Zone_Server, "Got 0x%04x from world:", pack->opcode);
switch(pack->opcode) {
case 0: { case 0: {
break; break;
} }
@ -180,12 +193,6 @@ void WorldServer::Process() {
ZoneConfig::SetZonePort(sci->port); ZoneConfig::SetZonePort(sci->port);
break; break;
} }
case ServerOP_ZAAuthFailed: {
Log.Out(Logs::Detail, Logs::Zone_Server, "World server responded 'Not Authorized', disabling reconnect");
pTryReconnect = false;
Disconnect();
break;
}
case ServerOP_ChannelMessage: { case ServerOP_ChannelMessage: {
if (!is_zone_loaded) if (!is_zone_loaded)
break; break;
@ -761,7 +768,6 @@ void WorldServer::Process() {
entity_list.QueueClients(0, outapp, false); entity_list.QueueClients(0, outapp, false);
safe_delete(outapp); safe_delete(outapp);
/* Buffer garbage to generate debug message */
char time_message[255]; char time_message[255];
time_t current_time = time(nullptr); time_t current_time = time(nullptr);
TimeOfDay_Struct eq_time; TimeOfDay_Struct eq_time;
@ -806,19 +812,12 @@ void WorldServer::Process() {
SendEmoteMessage(rev->adminname, 0, 0, "%s: %srevoking %s", zone->GetShortName(), rev->toggle?"":"un", client->GetName()); SendEmoteMessage(rev->adminname, 0, 0, "%s: %srevoking %s", zone->GetShortName(), rev->toggle?"":"un", client->GetName());
client->SetRevoked(rev->toggle); client->SetRevoked(rev->toggle);
} }
#if EQDEBUG >= 6
else
SendEmoteMessage(rev->adminname, 0, 0, "%s: Can't find %s", zone->GetShortName(), rev->name);
#endif
break; break;
} }
case ServerOP_GroupIDReply: { case ServerOP_GroupIDReply: {
ServerGroupIDReply_Struct* ids = (ServerGroupIDReply_Struct*) pack->pBuffer; ServerGroupIDReply_Struct* ids = (ServerGroupIDReply_Struct*) pack->pBuffer;
cur_groupid = ids->start; cur_groupid = ids->start;
last_groupid = ids->end; last_groupid = ids->end;
#ifdef _EQDEBUG
printf("Got new group id set: %lu -> %lu\n", (unsigned long)cur_groupid, (unsigned long)last_groupid);
#endif
break; break;
} }
case ServerOP_GroupLeave: { case ServerOP_GroupLeave: {
@ -1913,10 +1912,6 @@ void WorldServer::Process() {
break; break;
} }
} }
safe_delete(pack);
}
return;
} }
bool WorldServer::SendChannelMessage(Client* from, const char* to, uint8 chan_num, uint32 guilddbid, uint8 language, const char* message, ...) { bool WorldServer::SendChannelMessage(Client* from, const char* to, uint8 chan_num, uint32 guilddbid, uint8 language, const char* message, ...) {

View File

@ -18,27 +18,31 @@
#ifndef WORLDSERVER_H #ifndef WORLDSERVER_H
#define WORLDSERVER_H #define WORLDSERVER_H
#include "../common/worldconn.h"
#include "../common/eq_packet_structs.h" #include "../common/eq_packet_structs.h"
#include "../common/net/servertalk_client_connection.h"
class ServerPacket; class ServerPacket;
class EQApplicationPacket; class EQApplicationPacket;
class Client; class Client;
class WorldServer : public WorldConnection { class WorldServer {
public: public:
WorldServer(); WorldServer();
virtual ~WorldServer(); ~WorldServer();
virtual void Process(); void Connect();
bool SendPacket(ServerPacket* pack);
std::string GetIP() const;
uint16 GetPort() const;
bool Connected() const;
void HandleMessage(uint16 opcode, const EQ::Net::Packet &p);
void SendGuildJoin(GuildJoin_Struct* gj);
bool SendChannelMessage(Client* from, const char* to, uint8 chan_num, uint32 guilddbid, uint8 language, const char* message, ...); bool SendChannelMessage(Client* from, const char* to, uint8 chan_num, uint32 guilddbid, uint8 language, const char* message, ...);
bool SendEmoteMessage(const char* to, uint32 to_guilddbid, uint32 type, const char* message, ...); bool SendEmoteMessage(const char* to, uint32 to_guilddbid, uint32 type, const char* message, ...);
bool SendEmoteMessage(const char* to, uint32 to_guilddbid, int16 to_minstatus, uint32 type, const char* message, ...); bool SendEmoteMessage(const char* to, uint32 to_guilddbid, int16 to_minstatus, uint32 type, const char* message, ...);
bool SendVoiceMacro(Client* From, uint32 Type, char* Target, uint32 MacroNumber, uint32 GroupOrRaidID = 0); bool SendVoiceMacro(Client* From, uint32 Type, char* Target, uint32 MacroNumber, uint32 GroupOrRaidID = 0);
void SetZoneData(uint32 iZoneID, uint32 iInstanceID = 0); void SetZoneData(uint32 iZoneID, uint32 iInstanceID = 0);
uint32 SendGroupIdRequest();
bool RezzPlayer(EQApplicationPacket* rpack, uint32 rezzexp, uint32 dbid, uint16 opcode); bool RezzPlayer(EQApplicationPacket* rpack, uint32 rezzexp, uint32 dbid, uint16 opcode);
bool IsOOCMuted() const { return(oocmuted); } bool IsOOCMuted() const { return(oocmuted); }
@ -67,6 +71,8 @@ private:
uint32 cur_groupid; uint32 cur_groupid;
uint32 last_groupid; uint32 last_groupid;
std::unique_ptr<EQ::Net::ServertalkClient> m_connection;
}; };
#endif #endif