Converted all the EQStreams into EQStreamInterfaces, dear god help us.

This commit is contained in:
KimLS
2016-09-24 22:43:29 -07:00
parent 4cb7d9a352
commit 751e61d6e5
24 changed files with 77 additions and 59 deletions
+4 -16
View File
@@ -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);
};
+3 -3
View File
@@ -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<EQStream> &eqs) {
void EQStreamIdentifier::AddStream(std::shared_ptr<EQStreamInterface> &eqs) {
m_streams.push_back(Record(eqs));
eqs = nullptr;
}
@@ -157,7 +157,7 @@ EQStreamInterface *EQStreamIdentifier::PopIdentified() {
return(res);
}
EQStreamIdentifier::Record::Record(std::shared_ptr<EQStream> s)
EQStreamIdentifier::Record::Record(std::shared_ptr<EQStreamInterface> s)
: stream(std::move(s)),
expire(STREAM_IDENT_WAIT_MS)
{
+5 -5
View File
@@ -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<EQStream> &eqs);
void AddStream(std::shared_ptr<EQStreamInterface> &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<EQStream> s);
std::shared_ptr<EQStream> stream; //we own this
Record(std::shared_ptr<EQStreamInterface> s);
std::shared_ptr<EQStreamInterface> stream; //we own this
Timer expire;
};
std::vector<Record> m_streams; //we own these objects, and the streams contained in them.
+18
View File
@@ -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; }
+11 -1
View File
@@ -5,7 +5,7 @@
#include "struct_strategy.h"
EQStreamProxy::EQStreamProxy(std::shared_ptr<EQStream> &stream, const StructStrategy *structs, OpcodeManager **opcodes)
EQStreamProxy::EQStreamProxy(std::shared_ptr<EQStreamInterface> &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;
+5 -3
View File
@@ -14,7 +14,7 @@ class EQApplicationPacket;
class EQStreamProxy : public EQStreamInterface {
public:
//takes ownership of the stream.
EQStreamProxy(std::shared_ptr<EQStream> &stream, const StructStrategy *structs, OpcodeManager **opcodes);
EQStreamProxy(std::shared_ptr<EQStreamInterface> &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<EQStream> const m_stream; //we own this stream object.
const StructStrategy *const m_structs; //we do not own this object.
std::shared_ptr<EQStreamInterface> 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.
+1 -1
View File
@@ -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.
+1 -1
View File
@@ -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.
+1 -1
View File
@@ -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.
+1 -1
View File
@@ -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.
+1 -1
View File
@@ -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<EQStream> dest, bool ack_req);
#define E(x) static void Encode_##x(EQApplicationPacket **p, std::shared_ptr<EQStreamInterface> dest, bool ack_req);
#define D(x) static void Decode_##x(EQApplicationPacket *p);
+1 -1
View File
@@ -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<EQStream> dest, bool ack_req)
#define ENCODE(x) void Strategy::Encode_##x(EQApplicationPacket **p, std::shared_ptr<EQStreamInterface> dest, bool ack_req)
#define DECODE(x) void Strategy::Decode_##x(EQApplicationPacket *__packet)
#define StructDist(in, f1, f2) (uint32(&in->f2)-uint32(&in->f1))
+1 -1
View File
@@ -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.
+1 -1
View File
@@ -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.
+3 -3
View File
@@ -18,7 +18,7 @@ StructStrategy::StructStrategy() {
}
}
void StructStrategy::Encode(EQApplicationPacket **p, std::shared_ptr<EQStream> dest, bool ack_req) const {
void StructStrategy::Encode(EQApplicationPacket **p, std::shared_ptr<EQStreamInterface> 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<EQStream> dest, bool ack_req) {
void StructStrategy::ErrorEncoder(EQApplicationPacket **in_p, std::shared_ptr<EQStreamInterface> 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<EQStream> dest, bool ack_req) {
void StructStrategy::PassEncoder(EQApplicationPacket **p, std::shared_ptr<EQStreamInterface> dest, bool ack_req) {
dest->FastQueuePacket(p, ack_req);
}
+5 -5
View File
@@ -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<EQStream> dest, bool ack_req);
typedef void(*Encoder)(EQApplicationPacket **p, std::shared_ptr<EQStreamInterface> 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<EQStream> dest, bool ack_req) const;
void Encode(EQApplicationPacket **p, std::shared_ptr<EQStreamInterface> 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<EQStream> dest, bool ack_req);
static void ErrorEncoder(EQApplicationPacket **p, std::shared_ptr<EQStreamInterface> 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<EQStream> dest, bool ack_req);
static void PassEncoder(EQApplicationPacket **p, std::shared_ptr<EQStreamInterface> dest, bool ack_req);
static void PassDecoder(EQApplicationPacket *p);
Encoder encoders[_maxEmuOpcode];