2013-02-16 16:14:39 -08:00
|
|
|
|
2015-01-19 04:12:09 -06:00
|
|
|
#include "global_define.h"
|
2015-01-12 21:45:49 -06:00
|
|
|
#include "eqemu_logsys.h"
|
2014-08-21 19:33:02 -07:00
|
|
|
#include "struct_strategy.h"
|
2015-01-18 04:03:45 -06:00
|
|
|
|
2016-09-29 22:21:39 -07:00
|
|
|
#include "eq_stream_intf.h"
|
|
|
|
|
#include "opcodemgr.h"
|
2013-02-16 16:14:39 -08:00
|
|
|
#include <map>
|
2015-01-27 21:12:44 -08:00
|
|
|
#include <memory>
|
2013-02-16 16:14:39 -08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
//note: all encoders and decoders must be valid functions.
|
|
|
|
|
//so if you specify set_defaults=false
|
|
|
|
|
StructStrategy::StructStrategy() {
|
|
|
|
|
int r;
|
|
|
|
|
for(r = 0; r < _maxEmuOpcode; r++) {
|
|
|
|
|
encoders[r] = PassEncoder;
|
|
|
|
|
decoders[r] = PassDecoder;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-24 22:43:29 -07:00
|
|
|
void StructStrategy::Encode(EQApplicationPacket **p, std::shared_ptr<EQStreamInterface> dest, bool ack_req) const {
|
2014-09-24 03:30:38 -07:00
|
|
|
if((*p)->GetOpcodeBypass() != 0) {
|
|
|
|
|
PassEncoder(p, dest, ack_req);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-16 16:14:39 -08:00
|
|
|
EmuOpcode op = (*p)->GetOpcode();
|
|
|
|
|
Encoder proc = encoders[op];
|
|
|
|
|
proc(p, dest, ack_req);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void StructStrategy::Decode(EQApplicationPacket *p) const {
|
|
|
|
|
EmuOpcode op = p->GetOpcode();
|
|
|
|
|
Decoder proc = decoders[op];
|
|
|
|
|
proc(p);
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-06 13:07:41 -04:00
|
|
|
|
2016-09-24 22:43:29 -07:00
|
|
|
void StructStrategy::ErrorEncoder(EQApplicationPacket **in_p, std::shared_ptr<EQStreamInterface> dest, bool ack_req) {
|
2013-02-16 16:14:39 -08:00
|
|
|
EQApplicationPacket *p = *in_p;
|
2013-05-04 18:06:58 -07:00
|
|
|
*in_p = nullptr;
|
2013-05-06 13:07:41 -04:00
|
|
|
|
2019-09-01 23:10:49 -05:00
|
|
|
LogNetcode("[STRUCTS] Error encoding opcode [{}]: no encoder provided. Dropping", OpcodeManager::EmuToName(p->GetOpcode()));
|
2013-05-06 13:07:41 -04:00
|
|
|
|
2013-02-16 16:14:39 -08:00
|
|
|
delete p;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void StructStrategy::ErrorDecoder(EQApplicationPacket *p) {
|
2019-09-01 23:10:49 -05:00
|
|
|
LogNetcode("[STRUCTS] Error decoding opcode [{}]: no decoder provided. Invalidating", OpcodeManager::EmuToName(p->GetOpcode()));
|
2013-02-16 16:14:39 -08:00
|
|
|
p->SetOpcode(OP_Unknown);
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-24 22:43:29 -07:00
|
|
|
void StructStrategy::PassEncoder(EQApplicationPacket **p, std::shared_ptr<EQStreamInterface> dest, bool ack_req) {
|
2013-02-16 16:14:39 -08:00
|
|
|
dest->FastQueuePacket(p, ack_req);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void StructStrategy::PassDecoder(EQApplicationPacket *p) {
|
|
|
|
|
//do nothing since we decode in place
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//effectively a singleton, but I decided to do it this way for no apparent reason.
|
|
|
|
|
namespace StructStrategyFactory {
|
2013-05-06 13:07:41 -04:00
|
|
|
|
2013-05-22 16:17:19 -04:00
|
|
|
static std::map<EmuOpcode, const StructStrategy *> strategies;
|
2013-05-06 13:07:41 -04:00
|
|
|
|
2013-02-16 16:14:39 -08:00
|
|
|
void RegisterPatch(EmuOpcode first_opcode, const StructStrategy *structs) {
|
|
|
|
|
strategies[first_opcode] = structs;
|
|
|
|
|
}
|
2013-05-06 13:07:41 -04:00
|
|
|
|
2013-02-16 16:14:39 -08:00
|
|
|
const StructStrategy *FindPatch(EmuOpcode first_opcode) {
|
2013-05-22 16:17:19 -04:00
|
|
|
std::map<EmuOpcode, const StructStrategy *>::const_iterator res;
|
2013-02-16 16:14:39 -08:00
|
|
|
res = strategies.find(first_opcode);
|
|
|
|
|
if(res == strategies.end())
|
2013-05-04 18:06:58 -07:00
|
|
|
return(nullptr);
|
2013-02-16 16:14:39 -08:00
|
|
|
return(res->second);
|
|
|
|
|
}
|
2013-05-06 13:07:41 -04:00
|
|
|
|
2013-02-16 16:14:39 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|