Some changes to routing and boilerplate for task service

This commit is contained in:
KimLS 2019-06-10 21:51:18 -07:00
parent 65c9c86556
commit 8497042eef
5 changed files with 87 additions and 51 deletions

View File

@ -1,4 +1,5 @@
#include "servertalk_server.h" #include "servertalk_server.h"
#include <regex>
EQ::Net::ServertalkServer::ServertalkServer() EQ::Net::ServertalkServer::ServertalkServer()
{ {
@ -80,9 +81,12 @@ void EQ::Net::ServertalkServer::ConnectionIdentified(ServertalkServerConnection
auto iter = m_unident_connections.begin(); auto iter = m_unident_connections.begin();
while (iter != m_unident_connections.end()) { while (iter != m_unident_connections.end()) {
if (conn == iter->get()) { if (conn == iter->get()) {
auto on_ident = m_on_ident.find(conn->GetIdentifier()); for (auto &ident : m_on_ident) {
if (on_ident != m_on_ident.end()) { std::regex ident_regex(ident.first);
on_ident->second(*iter);
if (std::regex_match(conn->GetIdentifier(), ident_regex)) {
ident.second(*iter);
}
} }
if (m_on_any_ident) { if (m_on_any_ident) {

View File

@ -1,5 +1,4 @@
#ifndef EQ_SOPCODES_H #pragma once
#define EQ_SOPCODES_H
#include "../common/types.h" #include "../common/types.h"
#include "../common/packet_functions.h" #include "../common/packet_functions.h"
@ -9,23 +8,20 @@
#include <cereal/cereal.hpp> #include <cereal/cereal.hpp>
#include <cereal/types/string.hpp> #include <cereal/types/string.hpp>
#define SERVER_TIMEOUT 45000 // how often keepalive gets sent constexpr auto INTERSERVER_TIMER = 10000;
#define INTERSERVER_TIMER 10000 constexpr auto LoginServer_StatusUpdateInterval = 15000;
#define LoginServer_StatusUpdateInterval 15000
#define LoginServer_AuthStale 60000
#define AUTHCHANGE_TIMEOUT 900 // in seconds
//Defines for backwards compat with old LS //Certain ops needed for backwards compat with old LS can't enum without being really annoying.
#define ServerOP_UsertoWorldReq 0xAB00 constexpr auto ServerOP_UsertoWorldReq = 0xAB00;
#define ServerOP_UsertoWorldResp 0xAB01 constexpr auto ServerOP_UsertoWorldResp = 0xAB01;
#define ServerOP_LSClientAuth 0x1002 constexpr auto ServerOP_LSClientAuth = 0x1002;
#define ServerOP_LSFatalError 0x1003 constexpr auto ServerOP_LSFatalError = 0x1003;
#define ServerOP_SystemwideMessage 0x1005 constexpr auto ServerOP_SystemwideMessage = 0x1005;
#define ServerOP_LSRemoteAddr 0x1009 constexpr auto ServerOP_LSRemoteAddr = 0x1009;
#define ServerOP_LSAccountUpdate 0x100A constexpr auto ServerOP_LSAccountUpdate = 0x100A;
#define ServerOP_NewLSInfo 0x1008 constexpr auto ServerOP_NewLSInfo = 0x1008;
#define ServerOP_LSInfo 0x1000 constexpr auto ServerOP_LSInfo = 0x1000;
#define ServerOP_LSStatus 0x1001 constexpr auto ServerOP_LSStatus = 0x1001;
enum ServerOpcode : int enum ServerOpcode : int
{ {
@ -205,7 +201,10 @@ enum ServerOpcode : int
ServerOP_CZSetEntityVariableByNPCTypeID, ServerOP_CZSetEntityVariableByNPCTypeID,
ServerOP_WWMarquee, ServerOP_WWMarquee,
ServerOP_QSPlayerDropItem, ServerOP_QSPlayerDropItem,
ServerOP_RouteTo ServerOP_RouteTo,
/*Tasks*/
ServerOP_GetClientTaskState
}; };
@ -1344,6 +1343,10 @@ struct ServerSharedTaskMember_Struct { // used for various things we just need t
#pragma pack() #pragma pack()
/*
* Routing
*/
struct RouteToMessage struct RouteToMessage
{ {
std::string filter; std::string filter;
@ -1358,4 +1361,22 @@ struct RouteToMessage
} }
}; };
#endif /*
* Tasks
*/
enum TaskMessageTypes
{
TaskGetClientTaskState = 1
};
struct GetClientTaskStateRequest
{
uint32 client_id;
template <class Archive>
void serialize(Archive &ar)
{
ar(client_id);
}
};

View File

@ -36,6 +36,8 @@ void EQ::TasksService::OnStart() {
m_db->LoadLogSettings(LogSys.log_settings); m_db->LoadLogSettings(LogSys.log_settings);
LogSys.StartFileLogs(); LogSys.StartFileLogs();
//Load task info here
} }
void EQ::TasksService::OnStop() { void EQ::TasksService::OnStop() {
@ -48,7 +50,19 @@ void EQ::TasksService::OnHeartbeat(double time_since_last) {
void EQ::TasksService::OnRoutedMessage(const std::string& filter, const std::string& identifier, const std::string& id, const EQ::Net::Packet& payload) void EQ::TasksService::OnRoutedMessage(const std::string& filter, const std::string& identifier, const std::string& id, const EQ::Net::Packet& payload)
{ {
LogF(Logs::General, Logs::Status, "Routed message from filter {0}, identifier {1}, id {2} with a payload of size {3}", filter, identifier, id, payload.Length()); auto msg_type = payload.GetInt32(0);
switch (msg_type) {
case TaskGetClientTaskState:
{
Log(Logs::General, Logs::Status, "Task state request");
auto req = payload.GetSerialize<GetClientTaskStateRequest>(4);
//Get the task state request
break;
}
default:
break;
}
} }
EQRegisterService(EQ::TasksService); EQRegisterService(EQ::TasksService);

View File

@ -1,4 +1,5 @@
#include "router.h" #include "router.h"
#include <regex>
Router::Router() Router::Router()
{ {
@ -42,32 +43,35 @@ void Router::OnRouterMessage(std::shared_ptr<EQ::Net::ServertalkServerConnection
out.PutPacket(out.Length(), payload); out.PutPacket(out.Length(), payload);
if (!msg.id.empty() && !msg.filter.empty()) { if (!msg.id.empty() && !msg.filter.empty()) {
auto id_regex = std::regex(msg.id);
auto filter_regex = std::regex(msg.filter);
for (auto &connection : m_connections) { for (auto &connection : m_connections) {
auto id = connection->GetUUID(); auto id = connection->GetUUID();
if (id == msg.id) { auto identifier = connection->GetIdentifier();
if (std::regex_match(id, id_regex)) {
connection->Send(ServerOP_RouteTo, out); connection->Send(ServerOP_RouteTo, out);
} }
else { else if (std::regex_match(identifier, filter_regex)) {
auto identifier = connection->GetIdentifier(); connection->Send(ServerOP_RouteTo, out);
auto pos = identifier.find(msg.filter);
if (pos == 0) {
connection->Send(ServerOP_RouteTo, out);
}
} }
} }
} }
else if (!msg.id.empty()) { else if (!msg.id.empty()) {
auto id_regex = std::regex(msg.id);
for (auto &connection : m_connections) { for (auto &connection : m_connections) {
auto id = connection->GetUUID(); auto id = connection->GetUUID();
if (id == msg.id) { if (std::regex_match(id, id_regex)) {
connection->Send(ServerOP_RouteTo, out); connection->Send(ServerOP_RouteTo, out);
} }
} }
} else if (!msg.filter.empty()) { } else if (!msg.filter.empty()) {
auto filter_regex = std::regex(msg.filter);
for (auto &connection : m_connections) { for (auto &connection : m_connections) {
auto identifier = connection->GetIdentifier(); auto identifier = connection->GetIdentifier();
auto pos = identifier.find(msg.filter); if (std::regex_match(identifier, filter_regex)) {
if (pos == 0) {
connection->Send(ServerOP_RouteTo, out); connection->Send(ServerOP_RouteTo, out);
} }
} }

View File

@ -471,29 +471,22 @@ bool TaskManager::SaveClientState(Client *c, ClientTaskState *state)
} }
void Client::LoadClientTaskState() { void Client::LoadClientTaskState() {
GetClientTaskStateRequest req;
req.client_id = CharacterID();
if(RuleB(TaskSystem, EnableTaskSystem) && taskmanager) { EQ::Net::DynamicPacket p;
if(taskstate) p.PutInt32(0, TaskGetClientTaskState);
safe_delete(taskstate); p.PutSerialize(4, req);
taskstate = new ClientTaskState;
if(!taskmanager->LoadClientState(this, taskstate)) {
safe_delete(taskstate);
}
else {
taskmanager->SendActiveTasksToClient(this);
taskmanager->SendCompletedTasksToClient(this, taskstate);
}
}
worldserver.RouteMessage("Tasks", "", p);
} }
void Client::RemoveClientTaskState() { void Client::RemoveClientTaskState() {
if(taskstate) { //if(taskstate) {
taskstate->CancelAllTasks(this); // taskstate->CancelAllTasks(this);
safe_delete(taskstate); // safe_delete(taskstate);
} //}
} }
bool TaskManager::LoadClientState(Client *c, ClientTaskState *state) bool TaskManager::LoadClientState(Client *c, ClientTaskState *state)