mirror of
https://github.com/EQEmu/Server.git
synced 2026-07-06 08:57:15 +00:00
Integrating protobuffers
This commit is contained in:
@@ -50,19 +50,21 @@ 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)
|
||||
{
|
||||
auto msg_type = payload.GetInt32(0);
|
||||
LogF(Logs::General, Logs::Status, "On routed message with payload size {0}", payload.Length());
|
||||
|
||||
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;
|
||||
}
|
||||
//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);
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
|
||||
|
||||
SET(service_sources
|
||||
test1_service.cpp
|
||||
)
|
||||
|
||||
SET(service_headers
|
||||
test1_service.h
|
||||
)
|
||||
|
||||
ADD_EXECUTABLE(test1_service ${service_sources} ${service_headers})
|
||||
|
||||
INSTALL(TARGETS test1_service RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
|
||||
|
||||
TARGET_LINK_LIBRARIES(test1_service ${SERVER_LIBS})
|
||||
|
||||
SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
|
||||
@@ -0,0 +1,61 @@
|
||||
#include "test1_service.h"
|
||||
#include "../../common/eqemu_logsys.h"
|
||||
#include "../../common/eqemu_config.h"
|
||||
|
||||
EQ::Test1Service::Test1Service()
|
||||
: EQ::Service("Test1", 1, 1)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
struct TestPacket
|
||||
{
|
||||
int64_t f1;
|
||||
int64_t f2;
|
||||
int64_t f3;
|
||||
int64_t f4;
|
||||
int64_t f5;
|
||||
int64_t f6;
|
||||
int64_t f7;
|
||||
char f8[4092];
|
||||
|
||||
template <class Archive>
|
||||
void serialize(Archive &ar)
|
||||
{
|
||||
ar(f1, f2, f3, f4, f5, f6, f7, f8);
|
||||
}
|
||||
};
|
||||
|
||||
EQ::Test1Service::~Test1Service() {
|
||||
|
||||
}
|
||||
|
||||
void EQ::Test1Service::OnStart() {
|
||||
|
||||
}
|
||||
|
||||
void EQ::Test1Service::OnStop() {
|
||||
}
|
||||
|
||||
void EQ::Test1Service::OnHeartbeat(double time_since_last) {
|
||||
TestPacket p;
|
||||
p.f1 = 33;
|
||||
p.f2 = 43;
|
||||
p.f3 = 56;
|
||||
p.f4 = 90;
|
||||
|
||||
EQ::Net::DynamicPacket out;
|
||||
out.PutInt32(0, 1234);
|
||||
out.PutSerialize(4, p);
|
||||
|
||||
for (int i = 0; i < 250; ++i) {
|
||||
RouteMessage("Test2", "", out);
|
||||
}
|
||||
}
|
||||
|
||||
void EQ::Test1Service::OnRoutedMessage(const std::string& filter, const std::string& identifier, const std::string& id, const EQ::Net::Packet& payload)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
EQRegisterService(EQ::Test1Service);
|
||||
@@ -0,0 +1,19 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../common/service.h"
|
||||
|
||||
namespace EQ
|
||||
{
|
||||
class Test1Service : public EQ::Service
|
||||
{
|
||||
public:
|
||||
Test1Service();
|
||||
virtual ~Test1Service();
|
||||
|
||||
protected:
|
||||
virtual void OnStart();
|
||||
virtual void OnStop();
|
||||
virtual void OnHeartbeat(double time_since_last);
|
||||
virtual void OnRoutedMessage(const std::string& filter, const std::string& identifier, const std::string& id, const EQ::Net::Packet& payload);
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
|
||||
|
||||
SET(service_sources
|
||||
test2_service.cpp
|
||||
)
|
||||
|
||||
SET(service_headers
|
||||
test2_service.h
|
||||
)
|
||||
|
||||
ADD_EXECUTABLE(test2_service ${service_sources} ${service_headers})
|
||||
|
||||
INSTALL(TARGETS test2_service RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
|
||||
|
||||
TARGET_LINK_LIBRARIES(test2_service ${SERVER_LIBS})
|
||||
|
||||
SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
|
||||
@@ -0,0 +1,40 @@
|
||||
#include "test2_service.h"
|
||||
#include "../../common/eqemu_logsys.h"
|
||||
#include "../../common/eqemu_config.h"
|
||||
|
||||
EQ::Test2Service::Test2Service()
|
||||
: EQ::Service("Test2", 3000, 1)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
EQ::Test2Service::~Test2Service() {
|
||||
|
||||
}
|
||||
|
||||
void EQ::Test2Service::OnStart() {
|
||||
bytes = 0;
|
||||
packets = 0;
|
||||
}
|
||||
|
||||
void EQ::Test2Service::OnStop() {
|
||||
}
|
||||
|
||||
void EQ::Test2Service::OnHeartbeat(double time_since_last) {
|
||||
|
||||
auto bytes_per_sec = bytes / time_since_last;
|
||||
auto packets_per_sec = packets / time_since_last;
|
||||
printf("Transfer rate %.2f KB/sec %.2f Packets/sec\n", bytes_per_sec / 1000.0, packets_per_sec);
|
||||
|
||||
bytes = 0;
|
||||
packets = 0;
|
||||
}
|
||||
|
||||
void EQ::Test2Service::OnRoutedMessage(const std::string& filter, const std::string& identifier, const std::string& id, const EQ::Net::Packet& payload)
|
||||
{
|
||||
bytes += sizeof(RouteToMessage);
|
||||
bytes += payload.Length();
|
||||
packets++;
|
||||
}
|
||||
|
||||
EQRegisterService(EQ::Test2Service);
|
||||
@@ -0,0 +1,23 @@
|
||||
#pragma once
|
||||
|
||||
#include "../../common/service.h"
|
||||
|
||||
namespace EQ
|
||||
{
|
||||
class Test2Service : public EQ::Service
|
||||
{
|
||||
public:
|
||||
Test2Service();
|
||||
virtual ~Test2Service();
|
||||
|
||||
protected:
|
||||
virtual void OnStart();
|
||||
virtual void OnStop();
|
||||
virtual void OnHeartbeat(double time_since_last);
|
||||
virtual void OnRoutedMessage(const std::string& filter, const std::string& identifier, const std::string& id, const EQ::Net::Packet& payload);
|
||||
|
||||
private:
|
||||
size_t bytes;
|
||||
size_t packets;
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user