mirror of
https://github.com/EQEmu/Server.git
synced 2025-12-30 15:01:29 +00:00
Some changes to routing and boilerplate for task service
This commit is contained in:
parent
65c9c86556
commit
8497042eef
@ -1,4 +1,5 @@
|
||||
#include "servertalk_server.h"
|
||||
#include <regex>
|
||||
|
||||
EQ::Net::ServertalkServer::ServertalkServer()
|
||||
{
|
||||
@ -80,9 +81,12 @@ void EQ::Net::ServertalkServer::ConnectionIdentified(ServertalkServerConnection
|
||||
auto iter = m_unident_connections.begin();
|
||||
while (iter != m_unident_connections.end()) {
|
||||
if (conn == iter->get()) {
|
||||
auto on_ident = m_on_ident.find(conn->GetIdentifier());
|
||||
if (on_ident != m_on_ident.end()) {
|
||||
on_ident->second(*iter);
|
||||
for (auto &ident : m_on_ident) {
|
||||
std::regex ident_regex(ident.first);
|
||||
|
||||
if (std::regex_match(conn->GetIdentifier(), ident_regex)) {
|
||||
ident.second(*iter);
|
||||
}
|
||||
}
|
||||
|
||||
if (m_on_any_ident) {
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
#ifndef EQ_SOPCODES_H
|
||||
#define EQ_SOPCODES_H
|
||||
#pragma once
|
||||
|
||||
#include "../common/types.h"
|
||||
#include "../common/packet_functions.h"
|
||||
@ -9,23 +8,20 @@
|
||||
#include <cereal/cereal.hpp>
|
||||
#include <cereal/types/string.hpp>
|
||||
|
||||
#define SERVER_TIMEOUT 45000 // how often keepalive gets sent
|
||||
#define INTERSERVER_TIMER 10000
|
||||
#define LoginServer_StatusUpdateInterval 15000
|
||||
#define LoginServer_AuthStale 60000
|
||||
#define AUTHCHANGE_TIMEOUT 900 // in seconds
|
||||
constexpr auto INTERSERVER_TIMER = 10000;
|
||||
constexpr auto LoginServer_StatusUpdateInterval = 15000;
|
||||
|
||||
//Defines for backwards compat with old LS
|
||||
#define ServerOP_UsertoWorldReq 0xAB00
|
||||
#define ServerOP_UsertoWorldResp 0xAB01
|
||||
#define ServerOP_LSClientAuth 0x1002
|
||||
#define ServerOP_LSFatalError 0x1003
|
||||
#define ServerOP_SystemwideMessage 0x1005
|
||||
#define ServerOP_LSRemoteAddr 0x1009
|
||||
#define ServerOP_LSAccountUpdate 0x100A
|
||||
#define ServerOP_NewLSInfo 0x1008
|
||||
#define ServerOP_LSInfo 0x1000
|
||||
#define ServerOP_LSStatus 0x1001
|
||||
//Certain ops needed for backwards compat with old LS can't enum without being really annoying.
|
||||
constexpr auto ServerOP_UsertoWorldReq = 0xAB00;
|
||||
constexpr auto ServerOP_UsertoWorldResp = 0xAB01;
|
||||
constexpr auto ServerOP_LSClientAuth = 0x1002;
|
||||
constexpr auto ServerOP_LSFatalError = 0x1003;
|
||||
constexpr auto ServerOP_SystemwideMessage = 0x1005;
|
||||
constexpr auto ServerOP_LSRemoteAddr = 0x1009;
|
||||
constexpr auto ServerOP_LSAccountUpdate = 0x100A;
|
||||
constexpr auto ServerOP_NewLSInfo = 0x1008;
|
||||
constexpr auto ServerOP_LSInfo = 0x1000;
|
||||
constexpr auto ServerOP_LSStatus = 0x1001;
|
||||
|
||||
enum ServerOpcode : int
|
||||
{
|
||||
@ -205,7 +201,10 @@ enum ServerOpcode : int
|
||||
ServerOP_CZSetEntityVariableByNPCTypeID,
|
||||
ServerOP_WWMarquee,
|
||||
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()
|
||||
|
||||
/*
|
||||
* Routing
|
||||
*/
|
||||
|
||||
struct RouteToMessage
|
||||
{
|
||||
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);
|
||||
}
|
||||
};
|
||||
|
||||
@ -36,6 +36,8 @@ void EQ::TasksService::OnStart() {
|
||||
|
||||
m_db->LoadLogSettings(LogSys.log_settings);
|
||||
LogSys.StartFileLogs();
|
||||
|
||||
//Load task info here
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
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);
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
#include "router.h"
|
||||
#include <regex>
|
||||
|
||||
Router::Router()
|
||||
{
|
||||
@ -42,32 +43,35 @@ void Router::OnRouterMessage(std::shared_ptr<EQ::Net::ServertalkServerConnection
|
||||
out.PutPacket(out.Length(), payload);
|
||||
|
||||
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) {
|
||||
auto id = connection->GetUUID();
|
||||
if (id == msg.id) {
|
||||
auto identifier = connection->GetIdentifier();
|
||||
if (std::regex_match(id, id_regex)) {
|
||||
connection->Send(ServerOP_RouteTo, out);
|
||||
}
|
||||
else {
|
||||
auto identifier = connection->GetIdentifier();
|
||||
auto pos = identifier.find(msg.filter);
|
||||
if (pos == 0) {
|
||||
connection->Send(ServerOP_RouteTo, out);
|
||||
}
|
||||
else if (std::regex_match(identifier, filter_regex)) {
|
||||
connection->Send(ServerOP_RouteTo, out);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (!msg.id.empty()) {
|
||||
auto id_regex = std::regex(msg.id);
|
||||
|
||||
for (auto &connection : m_connections) {
|
||||
auto id = connection->GetUUID();
|
||||
if (id == msg.id) {
|
||||
if (std::regex_match(id, id_regex)) {
|
||||
connection->Send(ServerOP_RouteTo, out);
|
||||
}
|
||||
}
|
||||
} else if (!msg.filter.empty()) {
|
||||
auto filter_regex = std::regex(msg.filter);
|
||||
|
||||
for (auto &connection : m_connections) {
|
||||
auto identifier = connection->GetIdentifier();
|
||||
auto pos = identifier.find(msg.filter);
|
||||
if (pos == 0) {
|
||||
if (std::regex_match(identifier, filter_regex)) {
|
||||
connection->Send(ServerOP_RouteTo, out);
|
||||
}
|
||||
}
|
||||
|
||||
@ -471,29 +471,22 @@ bool TaskManager::SaveClientState(Client *c, ClientTaskState *state)
|
||||
}
|
||||
|
||||
void Client::LoadClientTaskState() {
|
||||
GetClientTaskStateRequest req;
|
||||
req.client_id = CharacterID();
|
||||
|
||||
if(RuleB(TaskSystem, EnableTaskSystem) && taskmanager) {
|
||||
if(taskstate)
|
||||
safe_delete(taskstate);
|
||||
|
||||
taskstate = new ClientTaskState;
|
||||
if(!taskmanager->LoadClientState(this, taskstate)) {
|
||||
safe_delete(taskstate);
|
||||
}
|
||||
else {
|
||||
taskmanager->SendActiveTasksToClient(this);
|
||||
taskmanager->SendCompletedTasksToClient(this, taskstate);
|
||||
}
|
||||
}
|
||||
EQ::Net::DynamicPacket p;
|
||||
p.PutInt32(0, TaskGetClientTaskState);
|
||||
p.PutSerialize(4, req);
|
||||
|
||||
worldserver.RouteMessage("Tasks", "", p);
|
||||
}
|
||||
|
||||
void Client::RemoveClientTaskState() {
|
||||
|
||||
if(taskstate) {
|
||||
taskstate->CancelAllTasks(this);
|
||||
safe_delete(taskstate);
|
||||
}
|
||||
//if(taskstate) {
|
||||
// taskstate->CancelAllTasks(this);
|
||||
// safe_delete(taskstate);
|
||||
//}
|
||||
}
|
||||
|
||||
bool TaskManager::LoadClientState(Client *c, ClientTaskState *state)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user