mirror of
https://github.com/EQEmu/Server.git
synced 2026-09-03 21:56:36 +00:00
Comms stuff
This commit is contained in:
@@ -54,6 +54,7 @@ SET(common_sources
|
||||
packet_functions.cpp
|
||||
perl_eqdb.cpp
|
||||
perl_eqdb_res.cpp
|
||||
platform.cpp
|
||||
proc_launcher.cpp
|
||||
profanity_manager.cpp
|
||||
ptimer.cpp
|
||||
@@ -71,8 +72,8 @@ SET(common_sources
|
||||
textures.cpp
|
||||
timer.cpp
|
||||
unix.cpp
|
||||
world_connection.cpp
|
||||
xml_parser.cpp
|
||||
platform.cpp
|
||||
json/jsoncpp.cpp
|
||||
net/console_server.cpp
|
||||
net/console_server_connection.cpp
|
||||
@@ -207,6 +208,7 @@ SET(common_headers
|
||||
unix.h
|
||||
useperl.h
|
||||
version.h
|
||||
world_connection.h
|
||||
xml_parser.h
|
||||
zone_numbers.h
|
||||
event/event_loop.h
|
||||
|
||||
@@ -26,6 +26,8 @@ namespace EQ
|
||||
bool Connected() const { return m_connecting != true; }
|
||||
|
||||
std::shared_ptr<EQ::Net::TCPConnection> Handle() { return m_connection; }
|
||||
|
||||
std::string GetIdentifier() const { return m_identifier; }
|
||||
private:
|
||||
void Connect();
|
||||
void ProcessData(EQ::Net::TCPConnection *c, const unsigned char *data, size_t length);
|
||||
|
||||
@@ -19,16 +19,26 @@ void EQ::Net::ServertalkServer::Listen(const ServertalkServerOptions& opts)
|
||||
});
|
||||
}
|
||||
|
||||
void EQ::Net::ServertalkServer::OnConnectionIdentified(const std::string &type, std::function<void(std::shared_ptr<ServertalkServerConnection>)> cb)
|
||||
void EQ::Net::ServertalkServer::OnConnectionIdentified(const std::string &type, IdentityCallback cb)
|
||||
{
|
||||
m_on_ident.insert(std::make_pair(type, cb));
|
||||
}
|
||||
|
||||
void EQ::Net::ServertalkServer::OnConnectionRemoved(const std::string &type, std::function<void(std::shared_ptr<ServertalkServerConnection>)> cb)
|
||||
void EQ::Net::ServertalkServer::OnConnectionRemoved(const std::string &type, IdentityCallback cb)
|
||||
{
|
||||
m_on_disc.insert(std::make_pair(type, cb));
|
||||
}
|
||||
|
||||
void EQ::Net::ServertalkServer::OnConnectionIdentified(IdentityCallback cb)
|
||||
{
|
||||
m_on_any_ident = cb;
|
||||
}
|
||||
|
||||
void EQ::Net::ServertalkServer::OnConnectionRemoved(IdentityCallback cb)
|
||||
{
|
||||
m_on_any_disc = cb;
|
||||
}
|
||||
|
||||
void EQ::Net::ServertalkServer::ConnectionDisconnected(ServertalkServerConnection *conn)
|
||||
{
|
||||
if (conn->GetIdentifier().empty()) {
|
||||
@@ -51,6 +61,11 @@ void EQ::Net::ServertalkServer::ConnectionDisconnected(ServertalkServerConnectio
|
||||
if (on_disc != m_on_disc.end()) {
|
||||
on_disc->second(*iter);
|
||||
}
|
||||
|
||||
if (m_on_any_disc) {
|
||||
m_on_any_disc(*iter);
|
||||
}
|
||||
|
||||
type->second.erase(iter);
|
||||
return;
|
||||
}
|
||||
@@ -70,6 +85,10 @@ void EQ::Net::ServertalkServer::ConnectionIdentified(ServertalkServerConnection
|
||||
on_ident->second(*iter);
|
||||
}
|
||||
|
||||
if (m_on_any_ident) {
|
||||
m_on_any_ident(*iter);
|
||||
}
|
||||
|
||||
if (m_ident_connections.count(conn->GetIdentifier()) > 0) {
|
||||
auto &vec = m_ident_connections[conn->GetIdentifier()];
|
||||
vec.push_back(*iter);
|
||||
|
||||
@@ -36,12 +36,16 @@ namespace EQ
|
||||
class ServertalkServer
|
||||
{
|
||||
public:
|
||||
typedef std::function<void(std::shared_ptr<ServertalkServerConnection>)> IdentityCallback;
|
||||
|
||||
ServertalkServer();
|
||||
~ServertalkServer();
|
||||
|
||||
void Listen(const ServertalkServerOptions& opts);
|
||||
void OnConnectionIdentified(const std::string &type, std::function<void(std::shared_ptr<ServertalkServerConnection>)> cb);
|
||||
void OnConnectionRemoved(const std::string &type, std::function<void(std::shared_ptr<ServertalkServerConnection>)> cb);
|
||||
void OnConnectionIdentified(const std::string &type, IdentityCallback cb);
|
||||
void OnConnectionRemoved(const std::string &type, IdentityCallback cb);
|
||||
void OnConnectionIdentified(IdentityCallback cb);
|
||||
void OnConnectionRemoved(IdentityCallback cb);
|
||||
|
||||
private:
|
||||
void ConnectionDisconnected(ServertalkServerConnection *conn);
|
||||
@@ -52,8 +56,10 @@ namespace EQ
|
||||
std::vector<std::shared_ptr<ServertalkServerConnection>> m_unident_connections;
|
||||
std::map<std::string, std::vector<std::shared_ptr<ServertalkServerConnection>>> m_ident_connections;
|
||||
|
||||
std::map<std::string, std::function<void(std::shared_ptr<ServertalkServerConnection>)>> m_on_ident;
|
||||
std::map<std::string, std::function<void(std::shared_ptr<ServertalkServerConnection>)>> m_on_disc;
|
||||
std::map<std::string, IdentityCallback> m_on_ident;
|
||||
std::map<std::string, IdentityCallback> m_on_disc;
|
||||
IdentityCallback m_on_any_ident;
|
||||
IdentityCallback m_on_any_disc;
|
||||
bool m_encrypted;
|
||||
bool m_allow_downgrade;
|
||||
std::string m_credentials;
|
||||
|
||||
+17
-2
@@ -202,6 +202,7 @@
|
||||
#define ServerOP_CZSetEntityVariableByClientName 0x4012
|
||||
#define ServerOP_UCSServerStatusRequest 0x4013
|
||||
#define ServerOP_UCSServerStatusReply 0x4014
|
||||
#define ServerOP_Speech 0x4513
|
||||
/* Query Server OP Codes */
|
||||
#define ServerOP_QSPlayerLogTrades 0x5010
|
||||
#define ServerOP_QSPlayerLogHandins 0x5011
|
||||
@@ -215,13 +216,14 @@
|
||||
#define ServerOP_WWMarquee 0x5019
|
||||
#define ServerOP_QSPlayerDropItem 0x5020
|
||||
|
||||
/* Routing System OP Code(s) */
|
||||
#define ServerOP_RouteTo 0x6000
|
||||
|
||||
/* Query Serv Generic Packet Flag/Type Enumeration */
|
||||
enum { QSG_LFGuild = 0 };
|
||||
enum { QSG_LFGuild_PlayerMatches = 0, QSG_LFGuild_UpdatePlayerInfo, QSG_LFGuild_RequestPlayerInfo, QSG_LFGuild_UpdateGuildInfo, QSG_LFGuild_GuildMatches,
|
||||
QSG_LFGuild_RequestGuildInfo };
|
||||
|
||||
#define ServerOP_Speech 0x4513
|
||||
|
||||
/************ PACKET RELATED STRUCT ************/
|
||||
class ServerPacket
|
||||
{
|
||||
@@ -1348,6 +1350,19 @@ struct ServerSharedTaskMember_Struct { // used for various things we just need t
|
||||
#define TASKJOINOOZ_LEVEL 3
|
||||
#define TASKJOINOOZ_TIMER 4
|
||||
|
||||
struct RouteToHeader
|
||||
{
|
||||
char filter[64];
|
||||
char type[128];
|
||||
|
||||
template <class Archive>
|
||||
void serialize(Archive & archive)
|
||||
{
|
||||
archive(filter,
|
||||
type);
|
||||
}
|
||||
};
|
||||
|
||||
#pragma pack()
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
#include "world_connection.h"
|
||||
#include "eqemu_config.h"
|
||||
#include "string_util.h"
|
||||
|
||||
EQ::WorldConnection::WorldConnection(const std::string &type) {
|
||||
auto config = EQEmuConfig::get();
|
||||
|
||||
m_connection.reset(new EQ::Net::ServertalkClient(config->WorldIP, config->WorldTCPPort, false, type, config->SharedKey));
|
||||
m_connection->OnConnect([this](EQ::Net::ServertalkClient *client) {
|
||||
if (m_on_connected) {
|
||||
m_on_connected();
|
||||
}
|
||||
});
|
||||
|
||||
m_connection->OnMessage(std::bind(&WorldConnection::_HandleMessage, this, std::placeholders::_1, std::placeholders::_2));
|
||||
m_connection->OnMessage(ServerOP_RouteTo, std::bind(&WorldConnection::_HandleRoutedMessage, this, std::placeholders::_1, std::placeholders::_2));
|
||||
}
|
||||
|
||||
EQ::WorldConnection::~WorldConnection() {
|
||||
|
||||
}
|
||||
|
||||
void EQ::WorldConnection::SendPacket(ServerPacket* pack) {
|
||||
m_connection->SendPacket(pack);
|
||||
}
|
||||
|
||||
std::string EQ::WorldConnection::GetIP() const {
|
||||
return m_connection->Handle()->RemoteIP();
|
||||
}
|
||||
|
||||
uint16 EQ::WorldConnection::GetPort() const {
|
||||
return m_connection->Handle()->RemotePort();
|
||||
}
|
||||
|
||||
bool EQ::WorldConnection::Connected() const {
|
||||
return m_connection->Connected();
|
||||
}
|
||||
|
||||
void EQ::WorldConnection::RouteMessage(const std::string &filter, const EQ::Net::Packet &p)
|
||||
{
|
||||
if (!m_connection->Connected()) {
|
||||
return;
|
||||
}
|
||||
|
||||
RouteToHeader header;
|
||||
strn0cpy(header.filter, filter.data(), 64);
|
||||
strn0cpy(header.type, m_connection->GetIdentifier().data(), 128);
|
||||
|
||||
EQ::Net::DynamicPacket out;
|
||||
out.PutSerialize(0, header);
|
||||
out.PutPacket(out.Length(), p);
|
||||
}
|
||||
|
||||
void EQ::WorldConnection::_HandleMessage(uint16 opcode, const EQ::Net::Packet &p)
|
||||
{
|
||||
if (m_on_message) {
|
||||
m_on_message(opcode, p);
|
||||
}
|
||||
}
|
||||
|
||||
void EQ::WorldConnection::_HandleRoutedMessage(uint16 opcode, const EQ::Net::Packet &p)
|
||||
{
|
||||
if (m_on_routed_message) {
|
||||
auto header = p.GetSerialize<RouteToHeader>(0);
|
||||
auto np = EQ::Net::StaticPacket((int8_t*)p.Data() + sizeof(RouteToHeader), p.Length() - sizeof(RouteToHeader));
|
||||
|
||||
m_on_routed_message(header.filter, header.type, np);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
#pragma once
|
||||
|
||||
#include "eq_packet_structs.h"
|
||||
#include "net/servertalk_client_connection.h"
|
||||
#include <functional>
|
||||
|
||||
namespace EQ
|
||||
{
|
||||
class WorldConnection
|
||||
{
|
||||
public:
|
||||
typedef std::function<void()> OnConnectedHandler;
|
||||
typedef std::function<void(uint16, const EQ::Net::Packet&)> OnMessageHandler;
|
||||
typedef std::function<void(const std::string&, const std::string&, EQ::Net::Packet&)> OnRoutedMessageHandler;
|
||||
|
||||
WorldConnection(const std::string &type);
|
||||
virtual ~WorldConnection();
|
||||
|
||||
void SendPacket(ServerPacket* pack);
|
||||
std::string GetIP() const;
|
||||
uint16 GetPort() const;
|
||||
bool Connected() const;
|
||||
|
||||
void SetOnConnectedHandler(OnConnectedHandler handler) {
|
||||
m_on_connected = handler;
|
||||
};
|
||||
|
||||
void SetOnMessageHandler(OnMessageHandler handler) {
|
||||
m_on_message = handler;
|
||||
};
|
||||
|
||||
void SetOnRoutedMessageHandler(OnRoutedMessageHandler handler) {
|
||||
m_on_routed_message = handler;
|
||||
}
|
||||
|
||||
void RouteMessage(const std::string &filter, const EQ::Net::Packet& p);
|
||||
|
||||
protected:
|
||||
OnConnectedHandler m_on_connected;
|
||||
OnMessageHandler m_on_message;
|
||||
OnRoutedMessageHandler m_on_routed_message;
|
||||
std::unique_ptr<EQ::Net::ServertalkClient> m_connection;
|
||||
|
||||
private:
|
||||
void _HandleMessage(uint16 opcode, const EQ::Net::Packet& p);
|
||||
void _HandleRoutedMessage(uint16 opcode, const EQ::Net::Packet& p);
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user