diff --git a/common/eq_stream.h b/common/eq_stream.h index d5e78c085..6f43cc337 100644 --- a/common/eq_stream.h +++ b/common/eq_stream.h @@ -241,7 +241,7 @@ class EQStream : public EQStreamInterface { virtual bool CheckState(EQStreamState state) { return GetState() == state; } virtual std::string Describe() const { return("Direct EQStream"); } - void SetOpcodeManager(OpcodeManager **opm) { OpMgr = opm; } + virtual void SetOpcodeManager(OpcodeManager **opm) { OpMgr = opm; } void CheckTimeout(uint32 now, uint32 timeout=30); bool HasOutgoingData(); @@ -250,13 +250,13 @@ class EQStream : public EQStreamInterface { void Write(int eq_fd); // whether or not the stream has been assigned (we passed our stream match) - void SetActive(bool val) { streamactive = val; } + virtual void SetActive(bool val) { streamactive = val; } // inline bool IsInUse() { bool flag; MInUse.lock(); flag=(active_users>0); MInUse.unlock(); return flag; } inline void PutInUse() { MInUse.lock(); active_users++; MInUse.unlock(); } - inline EQStreamState GetState() { EQStreamState s; MState.lock(); s=State; MState.unlock(); return s; } + virtual EQStreamState GetState() { EQStreamState s; MState.lock(); s=State; MState.unlock(); return s; } static SeqOrder CompareSequence(uint16 expected_seq , uint16 seq); @@ -306,19 +306,7 @@ class EQStream : public EQStreamInterface { const uint64 GetPacketsReceived() { return received_packet_count; } //used for dynamic stream identification - class Signature { - public: - //this object could get more complicated if needed... - uint16 ignore_eq_opcode; //0=dont ignore - uint16 first_eq_opcode; - uint32 first_length; //0=dont check length - }; - typedef enum { - MatchNotReady, - MatchSuccessful, - MatchFailed - } MatchState; - MatchState CheckSignature(const Signature *sig); + virtual MatchState CheckSignature(const Signature *sig); }; diff --git a/common/eq_stream_ident.cpp b/common/eq_stream_ident.cpp index cb0810467..fa7435910 100644 --- a/common/eq_stream_ident.cpp +++ b/common/eq_stream_ident.cpp @@ -26,7 +26,7 @@ EQStreamIdentifier::~EQStreamIdentifier() { } } -void EQStreamIdentifier::RegisterPatch(const EQStream::Signature &sig, const char *name, OpcodeManager ** opcodes, const StructStrategy *structs) { +void EQStreamIdentifier::RegisterPatch(const EQStreamInterface::Signature &sig, const char *name, OpcodeManager ** opcodes, const StructStrategy *structs) { auto p = new Patch; p->signature = sig; p->name = name; @@ -144,7 +144,7 @@ void EQStreamIdentifier::Process() { } //end foreach stream } -void EQStreamIdentifier::AddStream(std::shared_ptr &eqs) { +void EQStreamIdentifier::AddStream(std::shared_ptr &eqs) { m_streams.push_back(Record(eqs)); eqs = nullptr; } @@ -157,7 +157,7 @@ EQStreamInterface *EQStreamIdentifier::PopIdentified() { return(res); } -EQStreamIdentifier::Record::Record(std::shared_ptr s) +EQStreamIdentifier::Record::Record(std::shared_ptr s) : stream(std::move(s)), expire(STREAM_IDENT_WAIT_MS) { diff --git a/common/eq_stream_ident.h b/common/eq_stream_ident.h index 3b6a63ed9..e26857292 100644 --- a/common/eq_stream_ident.h +++ b/common/eq_stream_ident.h @@ -18,11 +18,11 @@ public: ~EQStreamIdentifier(); //registration interface. - void RegisterPatch(const EQStream::Signature &sig, const char *name, OpcodeManager ** opcodes, const StructStrategy *structs); + void RegisterPatch(const EQStreamInterface::Signature &sig, const char *name, OpcodeManager ** opcodes, const StructStrategy *structs); //main processing interface void Process(); - void AddStream(std::shared_ptr &eqs); + void AddStream(std::shared_ptr &eqs); EQStreamInterface *PopIdentified(); protected: @@ -31,7 +31,7 @@ protected: class Patch { public: std::string name; - EQStream::Signature signature; + EQStreamInterface::Signature signature; OpcodeManager ** opcodes; const StructStrategy *structs; }; @@ -40,8 +40,8 @@ protected: //pending streams.. class Record { public: - Record(std::shared_ptr s); - std::shared_ptr stream; //we own this + Record(std::shared_ptr s); + std::shared_ptr stream; //we own this Timer expire; }; std::vector m_streams; //we own these objects, and the streams contained in them. diff --git a/common/eq_stream_intf.h b/common/eq_stream_intf.h index 917a13a86..5c62c0b39 100644 --- a/common/eq_stream_intf.h +++ b/common/eq_stream_intf.h @@ -15,11 +15,25 @@ typedef enum { } EQStreamState; class EQApplicationPacket; +class OpcodeManager; class EQStreamInterface { public: virtual ~EQStreamInterface() {} + class Signature { + public: + //this object could get more complicated if needed... + uint16 ignore_eq_opcode; //0=dont ignore + uint16 first_eq_opcode; + uint32 first_length; //0=dont check length + }; + typedef enum { + MatchNotReady, + MatchSuccessful, + MatchFailed + } MatchState; + virtual void QueuePacket(const EQApplicationPacket *p, bool ack_req=true) = 0; virtual void FastQueuePacket(EQApplicationPacket **p, bool ack_req=true) = 0; virtual EQApplicationPacket *PopPacket() = 0; @@ -30,6 +44,10 @@ public: virtual uint16 GetRemotePort() const = 0; virtual bool CheckState(EQStreamState state) = 0; virtual std::string Describe() const = 0; + virtual void SetActive(bool val) { } + virtual MatchState CheckSignature(const Signature *sig) { return MatchFailed; } + virtual EQStreamState GetState() = 0; + virtual void SetOpcodeManager(OpcodeManager **opm) = 0; virtual const uint32 GetBytesSent() const { return 0; } virtual const uint32 GetBytesRecieved() const { return 0; } diff --git a/common/eq_stream_proxy.cpp b/common/eq_stream_proxy.cpp index 0c41988e4..0817edbd2 100644 --- a/common/eq_stream_proxy.cpp +++ b/common/eq_stream_proxy.cpp @@ -5,7 +5,7 @@ #include "struct_strategy.h" -EQStreamProxy::EQStreamProxy(std::shared_ptr &stream, const StructStrategy *structs, OpcodeManager **opcodes) +EQStreamProxy::EQStreamProxy(std::shared_ptr &stream, const StructStrategy *structs, OpcodeManager **opcodes) : m_stream(stream), m_structs(structs), m_opcodes(opcodes) @@ -26,6 +26,16 @@ const EQEmu::versions::ClientVersion EQStreamProxy::ClientVersion() const return m_structs->ClientVersion(); } +EQStreamState EQStreamProxy::GetState() +{ + return m_stream->GetState(); +} + +void EQStreamProxy::SetOpcodeManager(OpcodeManager **opm) +{ + return m_stream->SetOpcodeManager(opm); +} + void EQStreamProxy::QueuePacket(const EQApplicationPacket *p, bool ack_req) { if(p == nullptr) return; diff --git a/common/eq_stream_proxy.h b/common/eq_stream_proxy.h index def543b34..e0a2327ca 100644 --- a/common/eq_stream_proxy.h +++ b/common/eq_stream_proxy.h @@ -14,7 +14,7 @@ class EQApplicationPacket; class EQStreamProxy : public EQStreamInterface { public: //takes ownership of the stream. - EQStreamProxy(std::shared_ptr &stream, const StructStrategy *structs, OpcodeManager **opcodes); + EQStreamProxy(std::shared_ptr &stream, const StructStrategy *structs, OpcodeManager **opcodes); virtual ~EQStreamProxy(); //EQStreamInterface: @@ -29,6 +29,8 @@ public: virtual bool CheckState(EQStreamState state); virtual std::string Describe() const; virtual const EQEmu::versions::ClientVersion ClientVersion() const; + virtual EQStreamState GetState(); + virtual void SetOpcodeManager(OpcodeManager **opm); virtual const uint32 GetBytesSent() const; virtual const uint32 GetBytesRecieved() const; @@ -36,8 +38,8 @@ public: virtual const uint32 GetBytesRecvPerSecond() const; protected: - std::shared_ptr const m_stream; //we own this stream object. - const StructStrategy *const m_structs; //we do not own this object. + std::shared_ptr const m_stream; //we own this stream object. + const StructStrategy *const m_structs; //we do not own this object. //this is a pointer to a pointer to make it less likely that a packet will //reference an invalid opcode manager when they are being reloaded. OpcodeManager **const m_opcodes; //we do not own this object. diff --git a/common/patches/rof.cpp b/common/patches/rof.cpp index 8ab38905f..1f5a86b83 100644 --- a/common/patches/rof.cpp +++ b/common/patches/rof.cpp @@ -87,7 +87,7 @@ namespace RoF //ok, now we have what we need to register. - EQStream::Signature signature; + EQStreamInterface::Signature signature; std::string pname; //register our world signature. diff --git a/common/patches/rof2.cpp b/common/patches/rof2.cpp index aedd7b592..4077d2419 100644 --- a/common/patches/rof2.cpp +++ b/common/patches/rof2.cpp @@ -87,7 +87,7 @@ namespace RoF2 //ok, now we have what we need to register. - EQStream::Signature signature; + EQStreamInterface::Signature signature; std::string pname; //register our world signature. diff --git a/common/patches/sod.cpp b/common/patches/sod.cpp index c1d573020..0eba65e8d 100644 --- a/common/patches/sod.cpp +++ b/common/patches/sod.cpp @@ -83,7 +83,7 @@ namespace SoD //ok, now we have what we need to register. - EQStream::Signature signature; + EQStreamInterface::Signature signature; std::string pname; //register our world signature. diff --git a/common/patches/sof.cpp b/common/patches/sof.cpp index bfad8d296..a944cd4e2 100644 --- a/common/patches/sof.cpp +++ b/common/patches/sof.cpp @@ -83,7 +83,7 @@ namespace SoF //ok, now we have what we need to register. - EQStream::Signature signature; + EQStreamInterface::Signature signature; std::string pname; //register our world signature. diff --git a/common/patches/ss_declare.h b/common/patches/ss_declare.h index b4059f640..4ea05d25b 100644 --- a/common/patches/ss_declare.h +++ b/common/patches/ss_declare.h @@ -17,5 +17,5 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#define E(x) static void Encode_##x(EQApplicationPacket **p, std::shared_ptr dest, bool ack_req); +#define E(x) static void Encode_##x(EQApplicationPacket **p, std::shared_ptr dest, bool ack_req); #define D(x) static void Decode_##x(EQApplicationPacket *p); diff --git a/common/patches/ss_define.h b/common/patches/ss_define.h index c5815eac8..f5c6ab361 100644 --- a/common/patches/ss_define.h +++ b/common/patches/ss_define.h @@ -17,7 +17,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#define ENCODE(x) void Strategy::Encode_##x(EQApplicationPacket **p, std::shared_ptr dest, bool ack_req) +#define ENCODE(x) void Strategy::Encode_##x(EQApplicationPacket **p, std::shared_ptr dest, bool ack_req) #define DECODE(x) void Strategy::Decode_##x(EQApplicationPacket *__packet) #define StructDist(in, f1, f2) (uint32(&in->f2)-uint32(&in->f1)) diff --git a/common/patches/titanium.cpp b/common/patches/titanium.cpp index 72b492eeb..e1f3140c1 100644 --- a/common/patches/titanium.cpp +++ b/common/patches/titanium.cpp @@ -82,7 +82,7 @@ namespace Titanium //ok, now we have what we need to register. - EQStream::Signature signature; + EQStreamInterface::Signature signature; std::string pname; //register our world signature. diff --git a/common/patches/uf.cpp b/common/patches/uf.cpp index ba5bf7622..d2e6c1867 100644 --- a/common/patches/uf.cpp +++ b/common/patches/uf.cpp @@ -83,7 +83,7 @@ namespace UF //ok, now we have what we need to register. - EQStream::Signature signature; + EQStreamInterface::Signature signature; std::string pname; //register our world signature. diff --git a/common/struct_strategy.cpp b/common/struct_strategy.cpp index ea50c9158..52442cee6 100644 --- a/common/struct_strategy.cpp +++ b/common/struct_strategy.cpp @@ -18,7 +18,7 @@ StructStrategy::StructStrategy() { } } -void StructStrategy::Encode(EQApplicationPacket **p, std::shared_ptr dest, bool ack_req) const { +void StructStrategy::Encode(EQApplicationPacket **p, std::shared_ptr dest, bool ack_req) const { if((*p)->GetOpcodeBypass() != 0) { PassEncoder(p, dest, ack_req); return; @@ -36,7 +36,7 @@ void StructStrategy::Decode(EQApplicationPacket *p) const { } -void StructStrategy::ErrorEncoder(EQApplicationPacket **in_p, std::shared_ptr dest, bool ack_req) { +void StructStrategy::ErrorEncoder(EQApplicationPacket **in_p, std::shared_ptr dest, bool ack_req) { EQApplicationPacket *p = *in_p; *in_p = nullptr; @@ -50,7 +50,7 @@ void StructStrategy::ErrorDecoder(EQApplicationPacket *p) { p->SetOpcode(OP_Unknown); } -void StructStrategy::PassEncoder(EQApplicationPacket **p, std::shared_ptr dest, bool ack_req) { +void StructStrategy::PassEncoder(EQApplicationPacket **p, std::shared_ptr dest, bool ack_req) { dest->FastQueuePacket(p, ack_req); } diff --git a/common/struct_strategy.h b/common/struct_strategy.h index fdb596891..3c92cf060 100644 --- a/common/struct_strategy.h +++ b/common/struct_strategy.h @@ -2,7 +2,7 @@ #define STRUCTSTRATEGY_H_ class EQApplicationPacket; -class EQStream; +class EQStreamInterface; #include "emu_opcodes.h" #include "emu_versions.h" @@ -12,7 +12,7 @@ class EQStream; class StructStrategy { public: //the encoder takes ownership of the supplied packet, and may enqueue multiple resulting packets into the stream - typedef void(*Encoder)(EQApplicationPacket **p, std::shared_ptr dest, bool ack_req); + typedef void(*Encoder)(EQApplicationPacket **p, std::shared_ptr dest, bool ack_req); //the decoder may only edit the supplied packet, producing a single packet for eqemu to consume. typedef void (*Decoder)(EQApplicationPacket *p); @@ -20,7 +20,7 @@ public: virtual ~StructStrategy() {} //this method takes an eqemu struct, and enqueues the produced structs into the stream. - void Encode(EQApplicationPacket **p, std::shared_ptr dest, bool ack_req) const; + void Encode(EQApplicationPacket **p, std::shared_ptr dest, bool ack_req) const; //this method takes an EQ wire struct, and converts it into an eqemu struct void Decode(EQApplicationPacket *p) const; @@ -30,10 +30,10 @@ public: protected: //some common coders: //Print an error saying unknown struct/opcode and drop it - static void ErrorEncoder(EQApplicationPacket **p, std::shared_ptr dest, bool ack_req); + static void ErrorEncoder(EQApplicationPacket **p, std::shared_ptr dest, bool ack_req); static void ErrorDecoder(EQApplicationPacket *p); //pass the packet through without modification (emu == EQ) (default) - static void PassEncoder(EQApplicationPacket **p, std::shared_ptr dest, bool ack_req); + static void PassEncoder(EQApplicationPacket **p, std::shared_ptr dest, bool ack_req); static void PassDecoder(EQApplicationPacket *p); Encoder encoders[_maxEmuOpcode]; diff --git a/loginserver/client.cpp b/loginserver/client.cpp index 9a6a81593..4e1449e91 100644 --- a/loginserver/client.cpp +++ b/loginserver/client.cpp @@ -24,7 +24,7 @@ extern EQEmuLogSys Log; extern LoginServer server; -Client::Client(std::shared_ptr c, LSClientVersion v) +Client::Client(std::shared_ptr c, LSClientVersion v) { connection = c; version = v; diff --git a/loginserver/client.h b/loginserver/client.h index 0f5efb1f1..872b5189c 100644 --- a/loginserver/client.h +++ b/loginserver/client.h @@ -59,7 +59,7 @@ public: /** * Constructor, sets our connection to c and version to v */ - Client(std::shared_ptr c, LSClientVersion v); + Client(std::shared_ptr c, LSClientVersion v); /** * Destructor. @@ -129,11 +129,11 @@ public: /** * Gets the connection for this client. */ - std::shared_ptr GetConnection() { return connection; } + std::shared_ptr GetConnection() { return connection; } EQEmu::Random random; private: - std::shared_ptr connection; + std::shared_ptr connection; LSClientVersion version; LSClientStatus status; diff --git a/loginserver/client_manager.cpp b/loginserver/client_manager.cpp index c600d58f5..e19cb220f 100644 --- a/loginserver/client_manager.cpp +++ b/loginserver/client_manager.cpp @@ -95,7 +95,7 @@ ClientManager::~ClientManager() void ClientManager::Process() { ProcessDisconnect(); - std::shared_ptr cur = titanium_stream->Pop(); + std::shared_ptr cur = titanium_stream->Pop(); while(cur) { struct in_addr in; @@ -142,8 +142,8 @@ void ClientManager::ProcessDisconnect() list::iterator iter = clients.begin(); while(iter != clients.end()) { - std::shared_ptr c = (*iter)->GetConnection(); - if(c->CheckClosed()) + std::shared_ptr c = (*iter)->GetConnection(); + if(c->CheckState(CLOSED)) { Log.Out(Logs::General, Logs::Login_Server, "Client disconnected from the server, removing client."); delete (*iter); diff --git a/ucs/clientlist.cpp b/ucs/clientlist.cpp index f49e02986..bd4bdcb45 100644 --- a/ucs/clientlist.cpp +++ b/ucs/clientlist.cpp @@ -485,7 +485,7 @@ Clientlist::Clientlist(int ChatPort) { } } -Client::Client(std::shared_ptr eqs) { +Client::Client(std::shared_ptr eqs) { ClientStream = eqs; @@ -574,7 +574,7 @@ void Clientlist::CheckForStaleConnections(Client *c) { void Clientlist::Process() { - std::shared_ptr eqs; + std::shared_ptr eqs; while ((eqs = chatsf->Pop())) { struct in_addr in; @@ -592,7 +592,7 @@ void Clientlist::Process() auto it = ClientChatConnections.begin(); while (it != ClientChatConnections.end()) { (*it)->AccountUpdate(); - if ((*it)->ClientStream->CheckClosed()) { + if ((*it)->ClientStream->CheckState(CLOSED)) { struct in_addr in; in.s_addr = (*it)->ClientStream->GetRemoteIP(); diff --git a/ucs/clientlist.h b/ucs/clientlist.h index 79b1359b7..6fa0d49da 100644 --- a/ucs/clientlist.h +++ b/ucs/clientlist.h @@ -84,10 +84,10 @@ struct CharacterEntry { class Client { public: - Client(std::shared_ptr eqs); + Client(std::shared_ptr eqs); ~Client(); - std::shared_ptr ClientStream; + std::shared_ptr ClientStream; void AddCharacter(int CharID, const char *CharacterName, int Level); void ClearCharacters() { Characters.clear(); } void SendMailBoxes(); diff --git a/world/net.cpp b/world/net.cpp index 94a24205a..6354a6467 100644 --- a/world/net.cpp +++ b/world/net.cpp @@ -412,7 +412,7 @@ int main(int argc, char** argv) { Timer InterserverTimer(INTERSERVER_TIMER); // does MySQL pings and auto-reconnect InterserverTimer.Trigger(); uint8 ReconnectCounter = 100; - std::shared_ptr eqs; + std::shared_ptr eqs; EmuTCPConnection* tcpc; EQStreamInterface *eqsi; diff --git a/zone/client.h b/zone/client.h index da2188fc7..b8424f45c 100644 --- a/zone/client.h +++ b/zone/client.h @@ -207,7 +207,7 @@ struct ClientReward class ClientFactory { public: - Client *MakeClient(std::shared_ptr ieqs); + Client *MakeClient(std::shared_ptr ieqs); }; class Client : public Mob diff --git a/zone/net.cpp b/zone/net.cpp index 25d6f65df..20a37114d 100644 --- a/zone/net.cpp +++ b/zone/net.cpp @@ -425,7 +425,7 @@ int main(int argc, char** argv) { Timer quest_timers(100); UpdateWindowTitle(); bool worldwasconnected = worldserver.Connected(); - std::shared_ptr eqss; + std::shared_ptr eqss; EQStreamInterface *eqsi; uint8 IDLEZONEUPDATE = 200; uint8 ZONEUPDATE = 10;