diff --git a/common/net/packet.cpp b/common/net/packet.cpp index deaa07843..63040a438 100644 --- a/common/net/packet.cpp +++ b/common/net/packet.cpp @@ -276,6 +276,11 @@ std::string EQ::Net::Packet::GetCString(size_t offset) const return std::string(str); } +EQ::Net::StaticPacket EQ::Net::Packet::GetPacket(size_t offset, size_t length) const +{ + return EQ::Net::StaticPacket((char*)Data() + offset, length); +} + char ToSafePrint(unsigned char in) { if (std::isprint(in)) { return in; diff --git a/common/net/packet.h b/common/net/packet.h index 1ce173a10..3dbf8effa 100644 --- a/common/net/packet.h +++ b/common/net/packet.h @@ -10,6 +10,7 @@ namespace EQ { namespace Net { + class StaticPacket; class Packet { public: @@ -77,6 +78,7 @@ namespace EQ { double GetDouble(size_t offset) const; std::string GetString(size_t offset, size_t length) const; std::string GetCString(size_t offset) const; + StaticPacket GetPacket(size_t offset, size_t length) const; std::string ToString() const; std::string ToString(size_t line_length) const; @@ -127,4 +129,4 @@ namespace EQ { std::vector m_data; }; } -} \ No newline at end of file +} diff --git a/common/servertalk.h b/common/servertalk.h index 99ed1fe9c..1b157d7da 100644 --- a/common/servertalk.h +++ b/common/servertalk.h @@ -15,209 +15,201 @@ #define LoginServer_AuthStale 60000 #define AUTHCHANGE_TIMEOUT 900 // in seconds -#define ServerOP_KeepAlive 0x0001 // packet to test if port is still open -#define ServerOP_ChannelMessage 0x0002 // broadcast/guildsay -#define ServerOP_SetZone 0x0003 // client -> server zoneinfo -#define ServerOP_ShutdownAll 0x0004 // exit(0); -#define ServerOP_ZoneShutdown 0x0005 // unload all data, goto sleep mode -#define ServerOP_ZoneBootup 0x0006 // come out of sleep mode and load zone specified -#define ServerOP_ZoneStatus 0x0007 // Shows status of all zones -#define ServerOP_SetConnectInfo 0x0008 // Tells server address and port # -#define ServerOP_EmoteMessage 0x0009 // Worldfarts -#define ServerOP_ClientList 0x000A // Update worldserver's client list, for #whos -#define ServerOP_Who 0x000B // #who -#define ServerOP_ZonePlayer 0x000C // #zone, or #summon -#define ServerOP_KickPlayer 0x000D // #kick - -#define ServerOP_RefreshGuild 0x000E // Notice to all zoneservers to refresh their guild cache for ID# in packet (ServerGuildRefresh_Struct) -#define ServerOP_VoiceMacro 0x000F -//#define ServerOP_GuildInvite 0x0010 -#define ServerOP_DeleteGuild 0x0011 // ServerGuildID_Struct -#define ServerOP_GuildRankUpdate 0x0012 -#define ServerOP_GuildCharRefresh 0x0013 -#define ServerOP_GuildMemberUpdate 0x0014 -#define ServerOP_RequestOnlineGuildMembers 0x0015 -#define ServerOP_OnlineGuildMembersResponse 0x0016 -#define ServerOP_LFGuildUpdate 0x0017 - -#define ServerOP_FlagUpdate 0x0018 // GM Flag updated for character, refresh the memory cache -#define ServerOP_GMGoto 0x0019 -#define ServerOP_MultiLineMsg 0x001A -#define ServerOP_Lock 0x001B // For #lock/#unlock inside server -#define ServerOP_Motd 0x001C // For changing MoTD inside server. -#define ServerOP_Uptime 0x001D -#define ServerOP_Petition 0x001E -#define ServerOP_KillPlayer 0x001F -#define ServerOP_UpdateGM 0x0020 -#define ServerOP_RezzPlayer 0x0021 -#define ServerOP_ZoneReboot 0x0022 -#define ServerOP_ZoneToZoneRequest 0x0023 -#define ServerOP_AcceptWorldEntrance 0x0024 -#define ServerOP_ZAAuth 0x0025 -#define ServerOP_ZAAuthFailed 0x0026 -#define ServerOP_ZoneIncClient 0x0027 // Incoming client -#define ServerOP_ClientListKA 0x0028 -#define ServerOP_ChangeWID 0x0029 -#define ServerOP_IPLookup 0x002A -#define ServerOP_LockZone 0x002B -#define ServerOP_ItemStatus 0x002C -#define ServerOP_OOCMute 0x002D -#define ServerOP_Revoke 0x002E -#define ServerOP_WebInterfaceCall 0x002F -#define ServerOP_GroupIDReq 0x0030 -#define ServerOP_GroupIDReply 0x0031 -#define ServerOP_GroupLeave 0x0032 // for disbanding out of zone folks -#define ServerOP_RezzPlayerAccept 0x0033 -#define ServerOP_SpawnCondition 0x0034 -#define ServerOP_SpawnEvent 0x0035 -#define ServerOP_SetLaunchName 0x0036 -#define ServerOP_RezzPlayerReject 0x0037 -#define ServerOP_SpawnPlayerCorpse 0x0038 -#define ServerOP_Consent 0x0039 -#define ServerOP_Consent_Response 0x003a -#define ServerOP_ForceGroupUpdate 0x003b -#define ServerOP_OOZGroupMessage 0x003c -#define ServerOP_DisbandGroup 0x003d //for disbanding a whole group cross zone -#define ServerOP_GroupJoin 0x003e //for joining ooz folks -#define ServerOP_UpdateSpawn 0x003f -#define ServerOP_SpawnStatusChange 0x0040 -#define ServerOP_ReloadTasks 0x0060 -#define ServerOP_DepopAllPlayersCorpses 0x0061 -#define ServerOP_ReloadTitles 0x0062 -#define ServerOP_QGlobalUpdate 0x0063 -#define ServerOP_QGlobalDelete 0x0064 -#define ServerOP_DepopPlayerCorpse 0x0065 -#define ServerOP_RequestTellQueue 0x0066 // client asks for it's tell queues -#define ServerOP_ChangeSharedMem 0x0067 -#define ServerOP_WebInterfaceEvent 0x0068 -#define ServerOP_WebInterfaceSubscribe 0x0069 -#define ServerOP_WebInterfaceUnsubscribe 0x0070 - -#define ServerOP_RaidAdd 0x0100 //in use -#define ServerOP_RaidRemove 0x0101 //in use -#define ServerOP_RaidDisband 0x0102 //in use -#define ServerOP_RaidLockFlag 0x0103 //in use -#define ServerOP_RaidGroupLeader 0x0104 //in use -#define ServerOP_RaidLeader 0x0105 //in use -#define ServerOP_RaidGroupSay 0x0106 //in use -#define ServerOP_RaidSay 0x0107 //in use -#define ServerOP_DetailsChange 0x0108 //in use - -#define ServerOP_UpdateGroup 0x010A //in use -#define ServerOP_RaidGroupDisband 0x010B //in use -#define ServerOP_RaidChangeGroup 0x010C //in use -#define ServerOP_RaidGroupAdd 0x010D -#define ServerOP_RaidGroupRemove 0x010E -#define ServerOP_GroupInvite 0x010F -#define ServerOP_GroupFollow 0x0110 -#define ServerOP_GroupFollowAck 0x0111 -#define ServerOP_GroupCancelInvite 0x0112 -#define ServerOP_RaidMOTD 0x0113 - -#define ServerOP_InstanceUpdateTime 0x014F -#define ServerOP_AdventureRequest 0x0150 -#define ServerOP_AdventureRequestAccept 0x0151 -#define ServerOP_AdventureRequestDeny 0x0152 -#define ServerOP_AdventureRequestCreate 0x0153 -#define ServerOP_AdventureData 0x0154 -#define ServerOP_AdventureDataClear 0x0155 -#define ServerOP_AdventureCreateDeny 0x0156 -#define ServerOP_AdventureDataRequest 0x0157 -#define ServerOP_AdventureClickDoor 0x0158 -#define ServerOP_AdventureClickDoorReply 0x0159 -#define ServerOP_AdventureClickDoorError 0x015a -#define ServerOP_AdventureLeave 0x015b -#define ServerOP_AdventureLeaveReply 0x015c -#define ServerOP_AdventureLeaveDeny 0x015d -#define ServerOP_AdventureCountUpdate 0x015e -#define ServerOP_AdventureZoneData 0x015f -#define ServerOP_AdventureAssaCountUpdate 0x0160 -#define ServerOP_AdventureFinish 0x0161 -#define ServerOP_AdventureLeaderboard 0x0162 - -#define ServerOP_WhoAll 0x0210 -#define ServerOP_FriendsWho 0x0211 -#define ServerOP_LFGMatches 0x0212 -#define ServerOP_LFPUpdate 0x0213 -#define ServerOP_LFPMatches 0x0214 -#define ServerOP_ClientVersionSummary 0x0215 -#define ServerOP_LSInfo 0x1000 -#define ServerOP_LSStatus 0x1001 +//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_ListWorlds 0x1006 -#define ServerOP_PeerConnect 0x1007 -#define ServerOP_NewLSInfo 0x1008 #define ServerOP_LSRemoteAddr 0x1009 -#define ServerOP_LSAccountUpdate 0x100A +#define ServerOP_LSAccountUpdate 0x100A +#define ServerOP_NewLSInfo 0x1008 +#define ServerOP_LSInfo 0x1000 +#define ServerOP_LSStatus 0x1001 -#define ServerOP_TaskRequest 0x0300 // zone -> world. Player trying to get task -#define ServerOP_TaskGrant 0x0301 // world -> zone. World verified everything is good -#define ServerOP_TaskReject 0x0302 // world -> zone. Something failed ABORT -#define ServerOP_TaskAddPlayer 0x0303 // bidirectional. /taskaddplayer request zone -> world. success world -> zone -#define ServerOP_TaskRemovePlayer 0x0304 // .. /taskremoveplayer .. -#define ServerOP_TaskZoneCreated 0x0305 // zone -> world. Something didn't go wrong creating the new task! Now World needs to tell other players to join world -> zone response to tell someone to join -#define ServerOP_TaskZoneFailed 0x0306 // zone -> world. Something went wrong above ABORT +enum ServerOpcode : int +{ + ServerOP_ChannelMessage, + ServerOP_SetZone, + ServerOP_ShutdownAll, + ServerOP_ZoneShutdown, + ServerOP_ZoneBootup, + ServerOP_ZoneStatus, + ServerOP_SetConnectInfo, + ServerOP_EmoteMessage, + ServerOP_ClientList, + ServerOP_Who, + ServerOP_ZonePlayer, + ServerOP_KickPlayer, + ServerOP_RefreshGuild, + ServerOP_VoiceMacro, + //ServerOP_GuildInvite, + ServerOP_DeleteGuild, + ServerOP_GuildRankUpdate, + ServerOP_GuildCharRefresh, + ServerOP_GuildMemberUpdate, + ServerOP_RequestOnlineGuildMembers, + ServerOP_OnlineGuildMembersResponse, + ServerOP_LFGuildUpdate, + ServerOP_FlagUpdate, + ServerOP_GMGoto, + ServerOP_MultiLineMsg, + ServerOP_Lock, + ServerOP_Motd, + ServerOP_Uptime, + ServerOP_Petition, + ServerOP_KillPlayer, + ServerOP_UpdateGM, + ServerOP_RezzPlayer, + ServerOP_ZoneReboot, + ServerOP_ZoneToZoneRequest, + ServerOP_AcceptWorldEntrance, + ServerOP_ZAAuth, + ServerOP_ZAAuthFailed, + ServerOP_ZoneIncClient, + ServerOP_ClientListKA, + ServerOP_ChangeWID, + ServerOP_IPLookup, + ServerOP_LockZone, + ServerOP_ItemStatus, + ServerOP_OOCMute, + ServerOP_Revoke, + ServerOP_WebInterfaceCall, + ServerOP_GroupIDReq, + ServerOP_GroupIDReply, + ServerOP_GroupLeave, + ServerOP_RezzPlayerAccept, + ServerOP_SpawnCondition, + ServerOP_SpawnEvent, + ServerOP_SetLaunchName, + ServerOP_RezzPlayerReject, + ServerOP_SpawnPlayerCorpse, + ServerOP_Consent, + ServerOP_Consent_Response, + ServerOP_ForceGroupUpdate, + ServerOP_OOZGroupMessage, + ServerOP_DisbandGroup, + ServerOP_GroupJoin, + ServerOP_UpdateSpawn, + ServerOP_SpawnStatusChange, + ServerOP_ReloadTasks, + ServerOP_DepopAllPlayersCorpses, + ServerOP_ReloadTitles, + ServerOP_QGlobalUpdate, + ServerOP_QGlobalDelete, + ServerOP_DepopPlayerCorpse, + ServerOP_RequestTellQueue, + ServerOP_ChangeSharedMem, + ServerOP_WebInterfaceEvent, + ServerOP_WebInterfaceSubscribe, + ServerOP_WebInterfaceUnsubscribe, + ServerOP_RaidAdd, + ServerOP_RaidRemove, + ServerOP_RaidDisband, + ServerOP_RaidLockFlag, + ServerOP_RaidGroupLeader, + ServerOP_RaidLeader, + ServerOP_RaidGroupSay, + ServerOP_RaidSay, + ServerOP_DetailsChange, + ServerOP_UpdateGroup, + ServerOP_RaidGroupDisband, + ServerOP_RaidChangeGroup, + ServerOP_RaidGroupAdd, + ServerOP_RaidGroupRemove, + ServerOP_GroupInvite, + ServerOP_GroupFollow, + ServerOP_GroupFollowAck, + ServerOP_GroupCancelInvite, + ServerOP_RaidMOTD, + ServerOP_InstanceUpdateTime, + ServerOP_AdventureRequest, + ServerOP_AdventureRequestAccept, + ServerOP_AdventureRequestDeny, + ServerOP_AdventureRequestCreate, + ServerOP_AdventureData, + ServerOP_AdventureDataClear, + ServerOP_AdventureCreateDeny, + ServerOP_AdventureDataRequest, + ServerOP_AdventureClickDoor, + ServerOP_AdventureClickDoorReply, + ServerOP_AdventureClickDoorError, + ServerOP_AdventureLeave, + ServerOP_AdventureLeaveReply, + ServerOP_AdventureLeaveDeny, + ServerOP_AdventureCountUpdate, + ServerOP_AdventureZoneData, + ServerOP_AdventureAssaCountUpdate, + ServerOP_AdventureFinish, + ServerOP_AdventureLeaderboard, + ServerOP_WhoAll, + ServerOP_FriendsWho, + ServerOP_LFGMatches, + ServerOP_LFPUpdate, + ServerOP_LFPMatches, + ServerOP_ClientVersionSummary, + ServerOP_ListWorlds, + ServerOP_PeerConnect, + ServerOP_TaskRequest, + ServerOP_TaskGrant, + ServerOP_TaskReject, + ServerOP_TaskAddPlayer, + ServerOP_TaskRemovePlayer, + ServerOP_TaskZoneCreated, + ServerOP_TaskZoneFailed, + ServerOP_EncapPacket, + ServerOP_WorldListUpdate, + ServerOP_WorldListRemove, + ServerOP_TriggerWorldListRefresh, + ServerOP_WhoAllReply, + ServerOP_SetWorldTime, + ServerOP_GetWorldTime, + ServerOP_SyncWorldTime, + ServerOP_RefreshCensorship, + ServerOP_LSZoneInfo, + ServerOP_LSZoneStart, + ServerOP_LSZoneBoot, + ServerOP_LSZoneShutdown, + ServerOP_LSZoneSleep, + ServerOP_LSPlayerLeftWorld, + ServerOP_LSPlayerJoinWorld, + ServerOP_LSPlayerZoneChange, + ServerOP_LauncherConnectInfo, + ServerOP_LauncherZoneRequest, + ServerOP_LauncherZoneStatus, + ServerOP_DoZoneCommand, + ServerOP_UCSMessage, + ServerOP_UCSMailMessage, + ServerOP_ReloadRules, + ServerOP_ReloadRulesWorld, + ServerOP_CameraShake, + ServerOP_QueryServGeneric, + ServerOP_CZSignalClient, + ServerOP_CZSignalClientByName, + ServerOP_CZMessagePlayer, + ServerOP_ReloadWorld, + ServerOP_ReloadLogs, + ServerOP_ReloadPerlExportSettings, + ServerOP_CZSetEntityVariableByClientName, + ServerOP_UCSServerStatusRequest, + ServerOP_UCSServerStatusReply, + ServerOP_Speech, + ServerOP_QSPlayerLogTrades, + ServerOP_QSPlayerLogHandins, + ServerOP_QSPlayerLogNPCKills, + ServerOP_QSPlayerLogDeletes, + ServerOP_QSPlayerLogMoves, + ServerOP_QSPlayerLogMerchantTransactions, + ServerOP_QSSendQuery, + ServerOP_CZSignalNPC, + ServerOP_CZSetEntityVariableByNPCTypeID, + ServerOP_WWMarquee, + ServerOP_QSPlayerDropItem, + ServerOP_RouteTo +}; -#define ServerOP_EncapPacket 0x2007 // Packet within a packet -#define ServerOP_WorldListUpdate 0x2008 -#define ServerOP_WorldListRemove 0x2009 -#define ServerOP_TriggerWorldListRefresh 0x200A -#define ServerOP_WhoAllReply 0x2010 -#define ServerOP_SetWorldTime 0x200B -#define ServerOP_GetWorldTime 0x200C -#define ServerOP_SyncWorldTime 0x200E -#define ServerOP_RefreshCensorship 0x200F -#define ServerOP_LSZoneInfo 0x3001 -#define ServerOP_LSZoneStart 0x3002 -#define ServerOP_LSZoneBoot 0x3003 -#define ServerOP_LSZoneShutdown 0x3004 -#define ServerOP_LSZoneSleep 0x3005 -#define ServerOP_LSPlayerLeftWorld 0x3006 -#define ServerOP_LSPlayerJoinWorld 0x3007 -#define ServerOP_LSPlayerZoneChange 0x3008 -#define ServerOP_UsertoWorldReq 0xAB00 -#define ServerOP_UsertoWorldResp 0xAB01 - -#define ServerOP_LauncherConnectInfo 0x3000 -#define ServerOP_LauncherZoneRequest 0x3001 -#define ServerOP_LauncherZoneStatus 0x3002 -#define ServerOP_DoZoneCommand 0x3003 - -#define ServerOP_UCSMessage 0x4000 -#define ServerOP_UCSMailMessage 0x4001 -#define ServerOP_ReloadRules 0x4002 -#define ServerOP_ReloadRulesWorld 0x4003 -#define ServerOP_CameraShake 0x4004 -#define ServerOP_QueryServGeneric 0x4005 -#define ServerOP_CZSignalClient 0x4006 -#define ServerOP_CZSignalClientByName 0x4007 -#define ServerOP_CZMessagePlayer 0x4008 -#define ServerOP_ReloadWorld 0x4009 -#define ServerOP_ReloadLogs 0x4010 -#define ServerOP_ReloadPerlExportSettings 0x4011 -#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 -#define ServerOP_QSPlayerLogNPCKills 0x5012 -#define ServerOP_QSPlayerLogDeletes 0x5013 -#define ServerOP_QSPlayerLogMoves 0x5014 -#define ServerOP_QSPlayerLogMerchantTransactions 0x5015 -#define ServerOP_QSSendQuery 0x5016 -#define ServerOP_CZSignalNPC 0x5017 -#define ServerOP_CZSetEntityVariableByNPCTypeID 0x5018 -#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 }; @@ -1352,4 +1344,18 @@ struct ServerSharedTaskMember_Struct { // used for various things we just need t #pragma pack() +struct RouteToMessage +{ + std::string filter; + std::string identifier; + std::string id; + size_t payload_size; + + template + void serialize(Archive &ar) + { + ar(filter, identifier, id, payload_size); + } +}; + #endif diff --git a/common/service.cpp b/common/service.cpp index d66078e00..16d3e3a6f 100644 --- a/common/service.cpp +++ b/common/service.cpp @@ -30,11 +30,18 @@ EQ::Service::~Service() void EQ::Service::Run() { + _impl->running = true; + OnStart(); + //If start canceled our run then just quit, dont bother initializing everything else + if (!_impl->running) { + return; + } + _impl->world_connection.reset(new EQ::WorldConnection(_impl->identifier)); - _impl->world_connection->SetOnRoutedMessageHandler([this](const std::string& filter, const std::string& identifier, int type, const EQ::Net::Packet& p) { - OnRoutedMessage(identifier, type, p); + _impl->world_connection->SetOnRoutedMessageHandler([this](const std::string& filter, const std::string& identifier, const std::string& id, const EQ::Net::Packet& payload) { + OnRoutedMessage(filter, identifier, id, payload); }); _impl->last_time = std::chrono::steady_clock::now(); @@ -44,8 +51,6 @@ void EQ::Service::Run() OnHeartbeat(time_since.count()); })); - _impl->running = true; - auto &loop = EQ::EventLoop::Get(); auto sleep_duration = _impl->sleep_duration_ms; while (_impl->running) { @@ -59,7 +64,11 @@ void EQ::Service::Run() OnStop(); } -void EQ::Service::RouteMessage(const std::string &filter, int type, const EQ::Net::Packet &p) +void EQ::Service::RouteMessage(const std::string &filter, const std::string &id, const EQ::Net::Packet &p) { - _impl->world_connection->RouteMessage(filter, type, p); + _impl->world_connection->RouteMessage(filter, id, p); +} + +void EQ::Service::Stop() { + _impl->running = false; } diff --git a/common/service.h b/common/service.h index 90df9930b..412c89465 100644 --- a/common/service.h +++ b/common/service.h @@ -32,10 +32,10 @@ namespace EQ virtual void OnStart() = 0; virtual void OnStop() = 0; virtual void OnHeartbeat(double time_since_last) = 0; - virtual void OnRoutedMessage(const std::string& identifier, int type, const EQ::Net::Packet& p) = 0; + virtual void OnRoutedMessage(const std::string& filter, const std::string& identifier, const std::string& id, const EQ::Net::Packet& payload) = 0; - void RouteMessage(const std::string &filter, int type, const EQ::Net::Packet& p); - + void RouteMessage(const std::string &filter, const std::string &id, const EQ::Net::Packet& p); + void Stop(); private: struct Impl; std::unique_ptr _impl; diff --git a/common/world_connection.cpp b/common/world_connection.cpp index 5f7685cf9..1197bfc0e 100644 --- a/common/world_connection.cpp +++ b/common/world_connection.cpp @@ -36,7 +36,7 @@ bool EQ::WorldConnection::Connected() const { return m_connection->Connected(); } -void EQ::WorldConnection::RouteMessage(const std::string &filter, int type, const EQ::Net::Packet &p) +void EQ::WorldConnection::RouteMessage(const std::string &filter, const std::string &id, const EQ::Net::Packet& payload) { if (!m_connection->Connected()) { return; @@ -44,14 +44,15 @@ void EQ::WorldConnection::RouteMessage(const std::string &filter, int type, cons auto identifier = m_connection->GetIdentifier(); + RouteToMessage msg; + msg.filter = filter; + msg.identifier = identifier; + msg.id = id; + msg.payload_size = payload.Length(); + EQ::Net::DynamicPacket out; - out.PutUInt32(out.Length(), static_cast(filter.length())); - out.PutString(out.Length(), filter); - out.PutUInt32(out.Length(), static_cast(identifier.length())); - out.PutString(out.Length(), identifier); - out.PutInt32(out.Length(), type); - out.PutInt32(out.Length(), static_cast(p.Length())); - out.PutPacket(out.Length(), p); + out.PutSerialize(0, msg); + out.PutPacket(out.Length(), payload); m_connection->Send(ServerOP_RouteTo, out); } @@ -66,17 +67,10 @@ void EQ::WorldConnection::_HandleMessage(uint16 opcode, const EQ::Net::Packet &p void EQ::WorldConnection::_HandleRoutedMessage(uint16 opcode, const EQ::Net::Packet &p) { if (m_on_routed_message) { - auto idx = 0; - auto filter_length = p.GetInt32(idx); idx += sizeof(int32_t); - auto filter = p.GetString(idx, filter_length); idx += filter_length; - auto identifier_length = p.GetInt32(idx); idx += sizeof(int32_t); - auto identifier = p.GetString(idx, identifier_length); idx += identifier_length; - auto type = p.GetInt32(idx); idx += sizeof(int32_t); - auto packet_length = p.GetInt32(idx); idx += sizeof(int32_t); - auto packet = EQ::Net::StaticPacket( - (void*)((const uint8_t*)p.Data() + idx), - static_cast(packet_length)); - - m_on_routed_message(filter, identifier, type, packet); + auto msg = p.GetSerialize(0); + auto payload_offset = p.Length() - msg.payload_size; + auto payload = p.GetPacket(payload_offset, msg.payload_size); + + m_on_routed_message(msg.filter, msg.identifier, msg.id, payload); } } diff --git a/common/world_connection.h b/common/world_connection.h index 443de3099..b2c12f2d3 100644 --- a/common/world_connection.h +++ b/common/world_connection.h @@ -11,7 +11,7 @@ namespace EQ public: typedef std::function OnConnectedHandler; typedef std::function OnMessageHandler; - typedef std::function OnRoutedMessageHandler; + typedef std::function OnRoutedMessageHandler; WorldConnection(const std::string &type); virtual ~WorldConnection(); @@ -33,7 +33,7 @@ namespace EQ m_on_routed_message = handler; } - void RouteMessage(const std::string &filter, int type, const EQ::Net::Packet& p); + void RouteMessage(const std::string &filter, const std::string &id, const EQ::Net::Packet& payload); protected: OnConnectedHandler m_on_connected; diff --git a/eqlaunch/worldserver.cpp b/eqlaunch/worldserver.cpp index 3064ed51c..0a3fbb112 100644 --- a/eqlaunch/worldserver.cpp +++ b/eqlaunch/worldserver.cpp @@ -60,14 +60,6 @@ void WorldServer::HandleMessage(uint16 opcode, const EQ::Net::Packet &p) { ServerPacket *pack = &tpack; switch (opcode) { - case 0: { - break; - } - case ServerOP_EmoteMessage: - case ServerOP_KeepAlive: { - // ignore this - break; - } case ServerOP_LauncherZoneRequest: { if (pack->size != sizeof(LauncherZoneRequest)) { Log(Logs::Detail, Logs::Launcher, "Invalid size of LauncherZoneRequest: %d", pack->size); diff --git a/queryserv/worldserver.cpp b/queryserv/worldserver.cpp index 5a66faf19..515b052e8 100644 --- a/queryserv/worldserver.cpp +++ b/queryserv/worldserver.cpp @@ -55,12 +55,6 @@ WorldServer::~WorldServer() void WorldServer::HandleMessage(uint16 opcode, const EQ::Net::Packet &p) { switch (opcode) { - case 0: { - break; - } - case ServerOP_KeepAlive: { - break; - } case ServerOP_Speech: { Server_Speech_Struct *SSS = (Server_Speech_Struct*)p.Data(); std::string tmp1 = SSS->from; diff --git a/services/tasks/CMakeLists.txt b/services/tasks/CMakeLists.txt index 266e891ed..c9166c20f 100644 --- a/services/tasks/CMakeLists.txt +++ b/services/tasks/CMakeLists.txt @@ -1,10 +1,12 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.8) SET(service_sources + tasks_database.cpp tasks_service.cpp ) SET(service_headers + tasks_database.h tasks_service.h ) diff --git a/services/tasks/tasks_database.cpp b/services/tasks/tasks_database.cpp new file mode 100644 index 000000000..32fb237b7 --- /dev/null +++ b/services/tasks/tasks_database.cpp @@ -0,0 +1,17 @@ +#include "tasks_database.h" + +TasksDatabase::TasksDatabase() + : Database() +{ + +} + +TasksDatabase::TasksDatabase(const char* host, const char* user, const char* passwd, const char* database, uint32 port) + : Database(host, user, passwd, database, port) +{ + +} + +TasksDatabase::~TasksDatabase() { + +} diff --git a/services/tasks/tasks_database.h b/services/tasks/tasks_database.h new file mode 100644 index 000000000..557ec39d2 --- /dev/null +++ b/services/tasks/tasks_database.h @@ -0,0 +1,12 @@ +#pragma once + +#include "../../common/global_define.h" +#include "../../common/types.h" +#include "../../common/database.h" + +class TasksDatabase : public Database { +public: + TasksDatabase(); + TasksDatabase(const char* host, const char* user, const char* passwd, const char* database, uint32 port); + ~TasksDatabase(); +}; diff --git a/services/tasks/tasks_service.cpp b/services/tasks/tasks_service.cpp index bf80cdc49..0180d1738 100644 --- a/services/tasks/tasks_service.cpp +++ b/services/tasks/tasks_service.cpp @@ -1,5 +1,6 @@ #include "tasks_service.h" #include "../../common/eqemu_logsys.h" +#include "../../common/eqemu_config.h" EQ::TasksService::TasksService() : EQ::Service("Tasks", 100, 1) @@ -12,20 +13,42 @@ EQ::TasksService::~TasksService() { } void EQ::TasksService::OnStart() { + Log(Logs::General, Logs::Status, "Connecting to database..."); + auto config = EQEmuConfig::get(); + + m_db.reset(new TasksDatabase()); + + auto r = m_db->Connect( + config->DatabaseHost.c_str(), + config->DatabaseUsername.c_str(), + config->DatabasePassword.c_str(), + config->DatabaseDB.c_str(), + config->DatabasePort); + + if (false == r) { + Log(Logs::General, Logs::Status, "Unable to connect to database."); + Stop(); + return; + } + + Log(Logs::General, Logs::Status, "Connected to database."); + + m_db->LoadLogSettings(LogSys.log_settings); + LogSys.StartFileLogs(); } void EQ::TasksService::OnStop() { - + m_db.release(); } void EQ::TasksService::OnHeartbeat(double time_since_last) { } -void EQ::TasksService::OnRoutedMessage(const std::string& identifier, int type, const EQ::Net::Packet& p) +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::World_Server, "Routed message of type {0} with length {1}", type, p.Length()); + 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()); } EQRegisterService(EQ::TasksService); diff --git a/services/tasks/tasks_service.h b/services/tasks/tasks_service.h index fa83a666c..6e90cfb16 100644 --- a/services/tasks/tasks_service.h +++ b/services/tasks/tasks_service.h @@ -1,6 +1,7 @@ #pragma once #include "../../common/service.h" +#include "tasks_database.h" namespace EQ { @@ -14,6 +15,9 @@ namespace EQ virtual void OnStart(); virtual void OnStop(); virtual void OnHeartbeat(double time_since_last); - virtual void OnRoutedMessage(const std::string& identifier, int type, const EQ::Net::Packet& p); + virtual void OnRoutedMessage(const std::string& filter, const std::string& identifier, const std::string& id, const EQ::Net::Packet& payload); + + private: + std::unique_ptr m_db; }; } diff --git a/ucs/worldserver.cpp b/ucs/worldserver.cpp index 074a4d39a..b1b3a0b3c 100644 --- a/ucs/worldserver.cpp +++ b/ucs/worldserver.cpp @@ -65,13 +65,6 @@ void WorldServer::ProcessMessage(uint16 opcode, const EQ::Net::Packet &p) switch (opcode) { - case 0: { - break; - } - case ServerOP_KeepAlive: - { - break; - } case ServerOP_UCSMessage: { char *Buffer = (char *)pack->pBuffer; diff --git a/world/launcher_link.cpp b/world/launcher_link.cpp index 83c51947b..9e9f65ace 100644 --- a/world/launcher_link.cpp +++ b/world/launcher_link.cpp @@ -72,12 +72,6 @@ void LauncherLink::ProcessMessage(uint16 opcode, EQ::Net::Packet &p) ServerPacket *pack = &tpack; switch (opcode) { - case 0: - break; - case ServerOP_KeepAlive: { - // ignore this - break; - } case ServerOP_ZAAuth: { Log(Logs::Detail, Logs::World_Server, "Got authentication from %s when they are already authenticated.", m_name.c_str()); break; @@ -296,4 +290,4 @@ void LauncherLink::Shutdown() { auto pack = new ServerPacket(ServerOP_ShutdownAll); SendPacket(pack); delete pack; -} \ No newline at end of file +} diff --git a/world/router.cpp b/world/router.cpp index 03f2e9e9e..cb61017a7 100644 --- a/world/router.cpp +++ b/world/router.cpp @@ -11,7 +11,7 @@ Router::~Router() void Router::AddConnection(std::shared_ptr connection) { m_connections.push_back(connection); - connection->OnMessage(ServerOP_RouteTo, std::bind(&Router::OnRouterMessage, this, std::placeholders::_1, std::placeholders::_2)); + connection->OnMessage(ServerOP_RouteTo, std::bind(&Router::OnRouterMessage, this, connection, std::placeholders::_1, std::placeholders::_2)); } void Router::RemoveConnection(std::shared_ptr connection) @@ -27,19 +27,54 @@ void Router::RemoveConnection(std::shared_ptr connection, uint16 opcode, const EQ::Net::Packet &p) { - auto idx = 0; - auto filter_length = p.GetInt32(idx); idx += sizeof(int32_t); - auto filter = p.GetString(idx, filter_length); idx += filter_length; + auto msg = p.GetSerialize(0); + auto payload_offset = p.Length() - msg.payload_size; + auto payload = p.GetPacket(payload_offset, msg.payload_size); - printf("Recv router msg of size %i\n", p.Length()); + auto out_msg = msg; + out_msg.identifier = connection->GetIdentifier(); + out_msg.id = connection->GetUUID(); - for (auto &connection : m_connections) { - auto identifier = connection->GetIdentifier(); - auto pos = identifier.find(filter); - if (pos == 0) { - connection->Send(opcode, p); + EQ::Net::DynamicPacket out; + out.PutSerialize(0, out_msg); + out.PutPacket(out.Length(), payload); + + if (!msg.id.empty() && !msg.filter.empty()) { + for (auto &connection : m_connections) { + auto id = connection->GetUUID(); + if (id == msg.id) { + 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 (!msg.id.empty()) { + for (auto &connection : m_connections) { + auto id = connection->GetUUID(); + if (id == msg.id) { + connection->Send(ServerOP_RouteTo, out); + } + } + } else if (!msg.filter.empty()) { + for (auto &connection : m_connections) { + auto identifier = connection->GetIdentifier(); + auto pos = identifier.find(msg.filter); + if (pos == 0) { + connection->Send(ServerOP_RouteTo, out); + } + } + } + else { + for (auto &connection : m_connections) { + connection->Send(ServerOP_RouteTo, out); } } } diff --git a/world/router.h b/world/router.h index 8d7e92757..5c639aee0 100644 --- a/world/router.h +++ b/world/router.h @@ -15,5 +15,5 @@ public: private: std::list> m_connections; - void OnRouterMessage(uint16 opcode, const EQ::Net::Packet &p); + void OnRouterMessage(std::shared_ptr connection, uint16 opcode, const EQ::Net::Packet &p); }; diff --git a/world/ucs.cpp b/world/ucs.cpp index b745005d4..cfd8f6463 100644 --- a/world/ucs.cpp +++ b/world/ucs.cpp @@ -36,14 +36,6 @@ void UCSConnection::ProcessPacket(uint16 opcode, EQ::Net::Packet &p) switch (opcode) { - case 0: - break; - - case ServerOP_KeepAlive: - { - // ignore this - break; - } case ServerOP_ZAAuth: { Log(Logs::Detail, Logs::UCS_Server, "Got authentication from UCS when they are already authenticated."); diff --git a/world/zonelist.cpp b/world/zonelist.cpp index db831e941..c2d06c864 100644 --- a/world/zonelist.cpp +++ b/world/zonelist.cpp @@ -43,7 +43,6 @@ ZSList::ZSList() memset(pLockedZones, 0, sizeof(pLockedZones)); m_tick.reset(new EQ::Timer(5000, true, std::bind(&ZSList::OnTick, this, std::placeholders::_1))); - m_keepalive.reset(new EQ::Timer(2500, true, std::bind(&ZSList::OnKeepAlive, this, std::placeholders::_1))); } ZSList::~ZSList() { @@ -748,9 +747,3 @@ void ZSList::OnTick(EQ::Timer *t) web_interface.SendEvent(out); } -void ZSList::OnKeepAlive(EQ::Timer *t) -{ - for (auto &zone : list) { - zone->SendKeepAlive(); - } -} diff --git a/world/zonelist.h b/world/zonelist.h index c63e1686b..e0b69d692 100644 --- a/world/zonelist.h +++ b/world/zonelist.h @@ -63,7 +63,6 @@ public: private: void OnTick(EQ::Timer *t); - void OnKeepAlive(EQ::Timer *t); uint32 NextID; std::list> list; uint16 pLockedZones[MaxLockedZones]; diff --git a/world/zoneserver.cpp b/world/zoneserver.cpp index 295e7c710..10f2b1fac 100644 --- a/world/zoneserver.cpp +++ b/world/zoneserver.cpp @@ -188,12 +188,6 @@ void ZoneServer::HandleMessage(uint16 opcode, const EQ::Net::Packet &p) { ServerPacket *pack = &tpack; switch (opcode) { - case 0: - break; - case ServerOP_KeepAlive: { - // ignore this - break; - } case ServerOP_ZAAuth: { break; } @@ -1417,13 +1411,6 @@ void ZoneServer::SendGroupIDs() { delete pack; } - -void ZoneServer::SendKeepAlive() -{ - ServerPacket pack(ServerOP_KeepAlive, 0); - SendPacket(&pack); -} - void ZoneServer::ChangeWID(uint32 iCharID, uint32 iWID) { auto pack = new ServerPacket(ServerOP_ChangeWID, sizeof(ServerChangeWID_Struct)); ServerChangeWID_Struct* scw = (ServerChangeWID_Struct*)pack->pBuffer; diff --git a/world/zoneserver.h b/world/zoneserver.h index f5d7296df..1f9e9516c 100644 --- a/world/zoneserver.h +++ b/world/zoneserver.h @@ -39,7 +39,6 @@ public: void SendPacket(ServerPacket* pack) { tcpc->SendPacket(pack); } void SendEmoteMessage(const char* to, uint32 to_guilddbid, int16 to_minstatus, uint32 type, const char* message, ...); void SendEmoteMessageRaw(const char* to, uint32 to_guilddbid, int16 to_minstatus, uint32 type, const char* message); - void SendKeepAlive(); bool SetZone(uint32 iZoneID, uint32 iInstanceID = 0, bool iStaticZone = false); void TriggerBootup(uint32 iZoneID = 0, uint32 iInstanceID = 0, const char* iAdminName = 0, bool iMakeStatic = false); void Disconnect() { auto handle = tcpc->Handle(); if (handle) { handle->Disconnect(); } } diff --git a/zone/command.cpp b/zone/command.cpp index c0fdcfa87..c4b819633 100755 --- a/zone/command.cpp +++ b/zone/command.cpp @@ -2832,8 +2832,9 @@ void command_spawn(Client *c, const Seperator *sep) void command_test(Client *c, const Seperator *sep) { EQ::Net::DynamicPacket p; - p.PutCString(0, "TestPacket"); - worldserver.RouteMessage("Tasks", 1234, p); + p.PutInt32(0, 1234); + p.PutCString(p.Length(), "TestPacket"); + worldserver.RouteMessage("Tasks", "", p); //c->Message(15, "Triggering test command"); // diff --git a/zone/worldserver.cpp b/zone/worldserver.cpp index f8937a710..524f9e9b1 100644 --- a/zone/worldserver.cpp +++ b/zone/worldserver.cpp @@ -118,10 +118,10 @@ uint16 WorldServer::GetPort() const return 0; } -void WorldServer::RouteMessage(const std::string &filter, int type, const EQ::Net::Packet &p) +void WorldServer::RouteMessage(const std::string &filter, const std::string &id, const EQ::Net::Packet &p) { if (m_connection) { - m_connection->RouteMessage(filter, type, p); + m_connection->RouteMessage(filter, id, p); } } @@ -196,14 +196,7 @@ void WorldServer::HandleMessage(uint16 opcode, const EQ::Net::Packet &p) ServerPacket *pack = &tpack; switch (opcode) { - case 0: { - break; - } - case ServerOP_KeepAlive: { - // ignore this - break; - } - // World is tellins us what port to use. + // World is tellins us what port to use. case ServerOP_SetConnectInfo: { if (pack->size != sizeof(ServerConnectInfo)) break; diff --git a/zone/worldserver.h b/zone/worldserver.h index d04ed7bff..24aad0e93 100644 --- a/zone/worldserver.h +++ b/zone/worldserver.h @@ -35,7 +35,7 @@ public: void SendPacket(ServerPacket* pack); std::string GetIP() const; uint16 GetPort() const; - void RouteMessage(const std::string &filter, int type, const EQ::Net::Packet& p); + void RouteMessage(const std::string &filter, const std::string &id, const EQ::Net::Packet& p); void HandleMessage(uint16 opcode, const EQ::Net::Packet &p);