Added 'server ready' broadcast to UCS server so clients will reconnect after crash

This commit is contained in:
Uleat
2018-02-26 20:02:27 -05:00
parent c469571f62
commit e547a1e778
11 changed files with 122 additions and 20 deletions
+4 -2
View File
@@ -140,10 +140,12 @@ int main() {
worldserver = new WorldServer;
// now that we can send packets to world, see if there's a
// broadcast opcode that tells the client to relog into ucs
worldserver->ActivateBroadcastServerReadyTimer();
while(RunLoops) {
// this triggers clients to 'reconnect' to ucs after server crash
if (worldserver->HasBroadcastServerReadyTimer())
worldserver->ProcessBroadcastServerReady();
Timer::SetCurrentTime();
+36
View File
@@ -45,6 +45,8 @@ WorldServer::WorldServer()
{
m_connection.reset(new EQ::Net::ServertalkClient(Config->WorldIP, Config->WorldTCPPort, false, "UCS", Config->SharedKey));
m_connection->OnMessage(std::bind(&WorldServer::ProcessMessage, this, std::placeholders::_1, std::placeholders::_2));
m_bsr_timer = nullptr;
}
WorldServer::~WorldServer()
@@ -134,3 +136,37 @@ void WorldServer::ProcessClientVersionRequests(std::list<uint32>& id_list) {
}
id_list.clear();
}
void WorldServer::ProcessBroadcastServerReady() {
if (m_bsr_timer && (*m_bsr_timer) <= Timer::GetCurrentTime()) {
UCSBroadcastServerReady_Struct bsr;
memset(&bsr, 0, sizeof(UCSBroadcastServerReady_Struct));
sprintf(bsr.chat_prefix, "%s,%i,%s.",
Config->ChatHost.c_str(),
Config->ChatPort,
Config->ShortName.c_str()
);
sprintf(bsr.mail_prefix, "%s,%i,%s.",
Config->ChatHost.c_str(),
Config->MailPort,
Config->ShortName.c_str()
);
EQ::Net::DynamicPacket dp_bsr;
dp_bsr.PutData(0, &bsr, sizeof(UCSBroadcastServerReady_Struct));
m_connection->Send(ServerOP_UCSBroadcastServerReady, dp_bsr);
safe_delete(m_bsr_timer);
}
}
void WorldServer::ActivateBroadcastServerReadyTimer() {
safe_delete(m_bsr_timer);
m_bsr_timer = new uint32;
// clients do not drop their connection to ucs immediately...
// it can take upwards of 60 seconds to process the drop
// and clients will not re-connect to ucs until that occurs
*m_bsr_timer = (Timer::GetCurrentTime() + (RuleI(Chat, UCSBroadcastServerReadyDelay) * 1000));
}
+5
View File
@@ -30,8 +30,13 @@ public:
void ProcessMessage(uint16 opcode, EQ::Net::Packet &);
void ProcessClientVersionRequests(std::list<uint32>& id_list);
void ProcessBroadcastServerReady();
bool HasBroadcastServerReadyTimer() { return (m_bsr_timer != nullptr); }
void ActivateBroadcastServerReadyTimer();
private:
uint32* m_bsr_timer;
std::unique_ptr<EQ::Net::ServertalkClient> m_connection;
};