mirror of
https://github.com/OpenFusionProject/OpenFusion.git
synced 2024-11-24 22:11:04 +00:00
[refactor] Validate all inbound packets before handling them
This commit is contained in:
parent
7c7d9f1be8
commit
ef7d0148c6
1
Makefile
1
Makefile
@ -78,6 +78,7 @@ CXXHDR=\
|
||||
src/core/CNProtocol.hpp\
|
||||
src/core/CNShared.hpp\
|
||||
src/core/CNStructs.hpp\
|
||||
src/core/Packets.hpp\
|
||||
src/core/Defines.hpp\
|
||||
src/core/Core.hpp\
|
||||
src/servers/CNLoginServer.hpp\
|
||||
|
@ -59,7 +59,8 @@ int CNSocketEncryption::decryptData(uint8_t* buffer, uint8_t* key, int size) {
|
||||
|
||||
// ========================================================[[ CNPacketData ]]========================================================
|
||||
|
||||
CNPacketData::CNPacketData(void* b, uint32_t t, int l): buf(b), size(l), type(t) {}
|
||||
CNPacketData::CNPacketData(void *b, uint32_t t, int l, int trnum, void *trs):
|
||||
buf(b), size(l), type(t), trCnt(trnum), trailers(trs) {}
|
||||
|
||||
// ========================================================[[ CNSocket ]]========================================================
|
||||
|
||||
@ -157,6 +158,55 @@ void CNSocket::setActiveKey(ACTIVEKEY key) {
|
||||
activeKey = key;
|
||||
}
|
||||
|
||||
inline void CNSocket::parsePacket(uint8_t *buf, size_t size) {
|
||||
uint32_t type = *((uint32_t*)buf);
|
||||
uint8_t *body = buf + 4;
|
||||
size_t pktSize = size - 4;
|
||||
|
||||
if (Packets::packets.find(type) == Packets::packets.end()) {
|
||||
std::cerr << "OpenFusion: UNKNOWN PACKET: " << (int)type << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
PacketDesc& desc = Packets::packets[type];
|
||||
|
||||
/*
|
||||
* Some packet structs with no meaningful contents have length 1, but
|
||||
* the client doesn't transmit that byte at all, so we special-case that.
|
||||
* It's important that we do that by zeroing that byte, as the server could
|
||||
* bypothetically try and read from it and get a byte of the previous
|
||||
* packet's contents.
|
||||
*
|
||||
* Assigning a zero byte to the body like this is safe, since there's a
|
||||
* huge empty buffer behind that pointer.
|
||||
*/
|
||||
if (!desc.variadic && desc.size == 1 && pktSize == 0) {
|
||||
pktSize = 1;
|
||||
*body = 0;
|
||||
}
|
||||
|
||||
int32_t ntrailers = 0;
|
||||
if (desc.variadic) {
|
||||
ntrailers = *(int32_t*)(body + desc.cntMembOfs);
|
||||
if (!validInVarPacket(desc.size, ntrailers, desc.trailerSize, pktSize)) {
|
||||
std::cerr << "[WARN] Received invalid variadic packet: " << desc.name << " (" << type << ")" << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
} else if (!desc.variadic && pktSize != desc.size) {
|
||||
std::cerr << "[WARN] Received " << desc.name << " (" << type << ") of wrong size ("
|
||||
<< (int)pktSize << " vs " << desc.size << ")" << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
void *trailers = nullptr;
|
||||
if (desc.variadic)
|
||||
trailers = body + desc.size;
|
||||
|
||||
CNPacketData pkt(body, type, pktSize, ntrailers, trailers);
|
||||
pHandler(this, &pkt);
|
||||
}
|
||||
|
||||
void CNSocket::step() {
|
||||
// read step
|
||||
|
||||
@ -206,11 +256,7 @@ void CNSocket::step() {
|
||||
// decrypt readBuffer and copy to CNPacketData
|
||||
CNSocketEncryption::decryptData((uint8_t*)&readBuffer, (uint8_t*)(&EKey), readSize);
|
||||
|
||||
void* tmpBuf = readBuffer+sizeof(uint32_t);
|
||||
CNPacketData tmp(tmpBuf, *((uint32_t*)readBuffer), readSize-sizeof(int32_t));
|
||||
|
||||
// call packet handler!!
|
||||
pHandler(this, &tmp);
|
||||
parsePacket(readBuffer, readSize);
|
||||
|
||||
// reset vars :)
|
||||
readSize = 0;
|
||||
@ -447,7 +493,7 @@ void CNServer::kill() {
|
||||
connections.clear();
|
||||
}
|
||||
|
||||
void CNServer::printPacket(CNPacketData *data, int type) {
|
||||
void CNServer::printPacket(CNPacketData *data) {
|
||||
if (settings::VERBOSITY < 2)
|
||||
return;
|
||||
|
||||
@ -466,7 +512,7 @@ void CNServer::printPacket(CNPacketData *data, int type) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::cout << "OpenFusion: received " << Packets::p2str(type, data->type) << " (" << data->type << ")" << std::endl;
|
||||
std::cout << "OpenFusion: received " << Packets::p2str(data->type) << " (" << data->type << ")" << std::endl;
|
||||
}
|
||||
|
||||
bool CNServer::checkExtraSockets(int i) { return false; } // stubbed
|
||||
|
@ -53,6 +53,7 @@
|
||||
#include <algorithm>
|
||||
|
||||
#include "Defines.hpp"
|
||||
#include "Packets.hpp"
|
||||
#include "settings.hpp"
|
||||
|
||||
#if defined(__MINGW32__) && !defined(_GLIBCXX_HAS_GTHREADS)
|
||||
@ -84,7 +85,7 @@ inline void* xmalloc(size_t sz) {
|
||||
|
||||
// overflow-safe validation of variable-length packets
|
||||
// for outbound packets
|
||||
inline bool validOutVarPacket(size_t base, int32_t npayloads, size_t plsize) {
|
||||
inline constexpr bool validOutVarPacket(size_t base, int32_t npayloads, size_t plsize) {
|
||||
// check for multiplication overflow
|
||||
if (npayloads > 0 && (CN_PACKET_BUFFER_SIZE - 8) / (size_t)npayloads < plsize)
|
||||
return false;
|
||||
@ -101,7 +102,7 @@ inline bool validOutVarPacket(size_t base, int32_t npayloads, size_t plsize) {
|
||||
}
|
||||
|
||||
// for inbound packets
|
||||
inline bool validInVarPacket(size_t base, int32_t npayloads, size_t plsize, size_t datasize) {
|
||||
inline constexpr bool validInVarPacket(size_t base, int32_t npayloads, size_t plsize, size_t datasize) {
|
||||
// check for multiplication overflow
|
||||
if (npayloads > 0 && (CN_PACKET_BUFFER_SIZE - 8) / (size_t)npayloads < plsize)
|
||||
return false;
|
||||
@ -137,8 +138,10 @@ struct CNPacketData {
|
||||
void *buf;
|
||||
int size;
|
||||
uint32_t type;
|
||||
int trCnt;
|
||||
void *trailers;
|
||||
|
||||
CNPacketData(void* b, uint32_t t, int l);
|
||||
CNPacketData(void* b, uint32_t t, int l, int trnum, void *trs);
|
||||
};
|
||||
|
||||
enum ACTIVEKEY {
|
||||
@ -164,6 +167,8 @@ private:
|
||||
bool sendData(uint8_t* data, int size);
|
||||
int recvData(buffer_t* data, int size);
|
||||
|
||||
inline void parsePacket(uint8_t *buf, size_t size);
|
||||
|
||||
public:
|
||||
SOCKET sock;
|
||||
sockaddr_in sockaddr;
|
||||
@ -225,7 +230,7 @@ public:
|
||||
|
||||
void start();
|
||||
void kill();
|
||||
static void printPacket(CNPacketData *data, int type);
|
||||
static void printPacket(CNPacketData *data);
|
||||
virtual bool checkExtraSockets(int i);
|
||||
virtual void newConnection(CNSocket* cns);
|
||||
virtual void killConnection(CNSocket* cns);
|
||||
|
@ -940,7 +940,3 @@ enum {
|
||||
|
||||
N_PACKETS = N_CL2LS + N_CL2FE + N_FE2CL + N_LS2CL
|
||||
};
|
||||
|
||||
namespace Packets {
|
||||
std::string p2str(int type, int val);
|
||||
}
|
||||
|
@ -1,220 +1,199 @@
|
||||
#include <string>
|
||||
|
||||
#include "Defines.hpp"
|
||||
#include "Packets.hpp"
|
||||
#include "CNStructs.hpp"
|
||||
|
||||
#define STRINGIFY(x) PacketMap(x, #x)
|
||||
#define PACKET(id) {id, {id, sizeof(s##id), #id}}
|
||||
#define VAR_PACKET(id, memb, tr) {id, {id, sizeof(s##id), #id, offsetof(s##id, memb), sizeof(tr)}}
|
||||
|
||||
/*
|
||||
* Turns out there isn't better way to do this...
|
||||
* We'll only support CL2* packets for now, since we only
|
||||
* need to print those.
|
||||
*/
|
||||
struct PacketMap {
|
||||
int val;
|
||||
std::string name;
|
||||
std::map<uint32_t, PacketDesc> Packets::packets = {
|
||||
// CL2LS
|
||||
PACKET(P_CL2LS_REQ_LOGIN),
|
||||
PACKET(P_CL2LS_REQ_CHECK_CHAR_NAME),
|
||||
PACKET(P_CL2LS_REQ_SAVE_CHAR_NAME),
|
||||
PACKET(P_CL2LS_REQ_CHAR_CREATE),
|
||||
PACKET(P_CL2LS_REQ_CHAR_SELECT),
|
||||
PACKET(P_CL2LS_REQ_CHAR_DELETE),
|
||||
PACKET(P_CL2LS_REQ_SHARD_SELECT),
|
||||
PACKET(P_CL2LS_REQ_SHARD_LIST_INFO),
|
||||
PACKET(P_CL2LS_CHECK_NAME_LIST),
|
||||
PACKET(P_CL2LS_REQ_SAVE_CHAR_TUTOR),
|
||||
PACKET(P_CL2LS_REQ_PC_EXIT_DUPLICATE),
|
||||
PACKET(P_CL2LS_REP_LIVE_CHECK),
|
||||
PACKET(P_CL2LS_REQ_CHANGE_CHAR_NAME),
|
||||
PACKET(P_CL2LS_REQ_SERVER_SELECT),
|
||||
|
||||
PacketMap(int v, std::string n) : val(v), name(n) {};
|
||||
// CL2FE
|
||||
PACKET(P_CL2FE_REQ_PC_ENTER),
|
||||
PACKET(P_CL2FE_REQ_PC_EXIT),
|
||||
PACKET(P_CL2FE_REQ_PC_MOVE),
|
||||
PACKET(P_CL2FE_REQ_PC_STOP),
|
||||
PACKET(P_CL2FE_REQ_PC_JUMP),
|
||||
VAR_PACKET(P_CL2FE_REQ_PC_ATTACK_NPCs, iNPCCnt, int32_t),
|
||||
PACKET(P_CL2FE_REQ_SEND_FREECHAT_MESSAGE),
|
||||
PACKET(P_CL2FE_REQ_SEND_MENUCHAT_MESSAGE),
|
||||
PACKET(P_CL2FE_REQ_PC_REGEN),
|
||||
PACKET(P_CL2FE_REQ_ITEM_MOVE),
|
||||
PACKET(P_CL2FE_REQ_PC_TASK_START),
|
||||
PACKET(P_CL2FE_REQ_PC_TASK_END),
|
||||
PACKET(P_CL2FE_REQ_NANO_EQUIP),
|
||||
PACKET(P_CL2FE_REQ_NANO_UNEQUIP),
|
||||
PACKET(P_CL2FE_REQ_NANO_ACTIVE),
|
||||
PACKET(P_CL2FE_REQ_NANO_TUNE),
|
||||
VAR_PACKET(P_CL2FE_REQ_NANO_SKILL_USE, iTargetCnt, int32_t),
|
||||
PACKET(P_CL2FE_REQ_PC_TASK_STOP),
|
||||
PACKET(P_CL2FE_REQ_PC_TASK_CONTINUE),
|
||||
PACKET(P_CL2FE_REQ_PC_GOTO),
|
||||
PACKET(P_CL2FE_REQ_CHARGE_NANO_STAMINA),
|
||||
PACKET(P_CL2FE_REQ_PC_KILL_QUEST_NPCs),
|
||||
PACKET(P_CL2FE_REQ_PC_VENDOR_ITEM_BUY),
|
||||
PACKET(P_CL2FE_REQ_PC_VENDOR_ITEM_SELL),
|
||||
PACKET(P_CL2FE_REQ_PC_ITEM_DELETE),
|
||||
PACKET(P_CL2FE_REQ_PC_GIVE_ITEM),
|
||||
PACKET(P_CL2FE_REQ_PC_ROCKET_STYLE_READY),
|
||||
PACKET(P_CL2FE_REQ_PC_ROCKET_STYLE_FIRE),
|
||||
VAR_PACKET(P_CL2FE_REQ_PC_ROCKET_STYLE_HIT, iTargetCnt, int64_t),
|
||||
PACKET(P_CL2FE_REQ_PC_GRENADE_STYLE_READY),
|
||||
PACKET(P_CL2FE_REQ_PC_GRENADE_STYLE_FIRE),
|
||||
PACKET(P_CL2FE_REQ_PC_GRENADE_STYLE_HIT),
|
||||
PACKET(P_CL2FE_REQ_PC_NANO_CREATE),
|
||||
PACKET(P_CL2FE_REQ_PC_TRADE_OFFER),
|
||||
PACKET(P_CL2FE_REQ_PC_TRADE_OFFER_CANCEL),
|
||||
PACKET(P_CL2FE_REQ_PC_TRADE_OFFER_ACCEPT),
|
||||
PACKET(P_CL2FE_REQ_PC_TRADE_OFFER_REFUSAL),
|
||||
PACKET(P_CL2FE_REQ_PC_TRADE_OFFER_ABORT),
|
||||
PACKET(P_CL2FE_REQ_PC_TRADE_CONFIRM),
|
||||
PACKET(P_CL2FE_REQ_PC_TRADE_CONFIRM_CANCEL),
|
||||
PACKET(P_CL2FE_REQ_PC_TRADE_CONFIRM_ABORT),
|
||||
PACKET(P_CL2FE_REQ_PC_TRADE_ITEM_REGISTER),
|
||||
PACKET(P_CL2FE_REQ_PC_TRADE_ITEM_UNREGISTER),
|
||||
PACKET(P_CL2FE_REQ_PC_TRADE_CASH_REGISTER),
|
||||
PACKET(P_CL2FE_REQ_PC_TRADE_EMOTES_CHAT),
|
||||
PACKET(P_CL2FE_REQ_PC_BANK_OPEN),
|
||||
PACKET(P_CL2FE_REQ_PC_BANK_CLOSE),
|
||||
PACKET(P_CL2FE_REQ_PC_VENDOR_START),
|
||||
PACKET(P_CL2FE_REQ_PC_VENDOR_TABLE_UPDATE),
|
||||
PACKET(P_CL2FE_REQ_PC_VENDOR_ITEM_RESTORE_BUY),
|
||||
PACKET(P_CL2FE_REQ_PC_COMBAT_BEGIN),
|
||||
PACKET(P_CL2FE_REQ_PC_COMBAT_END),
|
||||
PACKET(P_CL2FE_REQ_REQUEST_MAKE_BUDDY),
|
||||
PACKET(P_CL2FE_REQ_ACCEPT_MAKE_BUDDY),
|
||||
PACKET(P_CL2FE_REQ_SEND_BUDDY_FREECHAT_MESSAGE),
|
||||
PACKET(P_CL2FE_REQ_SEND_BUDDY_MENUCHAT_MESSAGE),
|
||||
PACKET(P_CL2FE_REQ_GET_BUDDY_STYLE),
|
||||
PACKET(P_CL2FE_REQ_SET_BUDDY_BLOCK),
|
||||
PACKET(P_CL2FE_REQ_REMOVE_BUDDY),
|
||||
PACKET(P_CL2FE_REQ_GET_BUDDY_STATE),
|
||||
PACKET(P_CL2FE_REQ_PC_JUMPPAD),
|
||||
PACKET(P_CL2FE_REQ_PC_LAUNCHER),
|
||||
PACKET(P_CL2FE_REQ_PC_ZIPLINE),
|
||||
PACKET(P_CL2FE_REQ_PC_MOVEPLATFORM),
|
||||
PACKET(P_CL2FE_REQ_PC_SLOPE),
|
||||
PACKET(P_CL2FE_REQ_PC_STATE_CHANGE),
|
||||
PACKET(P_CL2FE_REQ_PC_MAP_WARP),
|
||||
PACKET(P_CL2FE_REQ_PC_GIVE_NANO),
|
||||
PACKET(P_CL2FE_REQ_NPC_SUMMON),
|
||||
PACKET(P_CL2FE_REQ_NPC_UNSUMMON),
|
||||
PACKET(P_CL2FE_REQ_ITEM_CHEST_OPEN),
|
||||
PACKET(P_CL2FE_REQ_PC_GIVE_NANO_SKILL),
|
||||
PACKET(P_CL2FE_DOT_DAMAGE_ONOFF),
|
||||
PACKET(P_CL2FE_REQ_PC_VENDOR_BATTERY_BUY),
|
||||
PACKET(P_CL2FE_REQ_PC_WARP_USE_NPC),
|
||||
PACKET(P_CL2FE_REQ_PC_GROUP_INVITE),
|
||||
PACKET(P_CL2FE_REQ_PC_GROUP_INVITE_REFUSE),
|
||||
PACKET(P_CL2FE_REQ_PC_GROUP_JOIN),
|
||||
PACKET(P_CL2FE_REQ_PC_GROUP_LEAVE),
|
||||
PACKET(P_CL2FE_REQ_PC_AVATAR_EMOTES_CHAT),
|
||||
PACKET(P_CL2FE_REQ_PC_BUDDY_WARP),
|
||||
PACKET(P_CL2FE_REQ_GET_MEMBER_STYLE),
|
||||
PACKET(P_CL2FE_REQ_GET_GROUP_STYLE),
|
||||
PACKET(P_CL2FE_REQ_PC_CHANGE_MENTOR),
|
||||
PACKET(P_CL2FE_REQ_GET_BUDDY_LOCATION),
|
||||
PACKET(P_CL2FE_REQ_NPC_GROUP_SUMMON),
|
||||
PACKET(P_CL2FE_REQ_PC_WARP_TO_PC),
|
||||
PACKET(P_CL2FE_REQ_EP_RANK_GET_LIST),
|
||||
PACKET(P_CL2FE_REQ_EP_RANK_GET_DETAIL),
|
||||
PACKET(P_CL2FE_REQ_EP_RANK_GET_PC_INFO),
|
||||
PACKET(P_CL2FE_REQ_EP_RACE_START),
|
||||
PACKET(P_CL2FE_REQ_EP_RACE_END),
|
||||
PACKET(P_CL2FE_REQ_EP_RACE_CANCEL),
|
||||
PACKET(P_CL2FE_REQ_EP_GET_RING),
|
||||
PACKET(P_CL2FE_REQ_IM_CHANGE_SWITCH_STATUS),
|
||||
PACKET(P_CL2FE_REQ_SHINY_PICKUP),
|
||||
PACKET(P_CL2FE_REQ_SHINY_SUMMON),
|
||||
PACKET(P_CL2FE_REQ_PC_MOVETRANSPORTATION),
|
||||
PACKET(P_CL2FE_REQ_SEND_ALL_GROUP_FREECHAT_MESSAGE),
|
||||
PACKET(P_CL2FE_REQ_SEND_ANY_GROUP_FREECHAT_MESSAGE),
|
||||
PACKET(P_CL2FE_REQ_BARKER),
|
||||
PACKET(P_CL2FE_REQ_SEND_ALL_GROUP_MENUCHAT_MESSAGE),
|
||||
PACKET(P_CL2FE_REQ_SEND_ANY_GROUP_MENUCHAT_MESSAGE),
|
||||
PACKET(P_CL2FE_REQ_REGIST_TRANSPORTATION_LOCATION),
|
||||
PACKET(P_CL2FE_REQ_PC_WARP_USE_TRANSPORTATION),
|
||||
PACKET(P_CL2FE_GM_REQ_PC_SPECIAL_STATE_SWITCH),
|
||||
PACKET(P_CL2FE_GM_REQ_PC_SET_VALUE),
|
||||
PACKET(P_CL2FE_GM_REQ_KICK_PLAYER),
|
||||
PACKET(P_CL2FE_GM_REQ_TARGET_PC_TELEPORT),
|
||||
PACKET(P_CL2FE_GM_REQ_PC_LOCATION),
|
||||
PACKET(P_CL2FE_GM_REQ_PC_ANNOUNCE),
|
||||
PACKET(P_CL2FE_REQ_SET_PC_BLOCK),
|
||||
PACKET(P_CL2FE_REQ_REGIST_RXCOM),
|
||||
PACKET(P_CL2FE_GM_REQ_PC_MOTD_REGISTER),
|
||||
PACKET(P_CL2FE_REQ_ITEM_USE),
|
||||
PACKET(P_CL2FE_REQ_WARP_USE_RECALL),
|
||||
PACKET(P_CL2FE_REP_LIVE_CHECK),
|
||||
PACKET(P_CL2FE_REQ_PC_MISSION_COMPLETE),
|
||||
PACKET(P_CL2FE_REQ_PC_TASK_COMPLETE),
|
||||
PACKET(P_CL2FE_REQ_NPC_INTERACTION),
|
||||
PACKET(P_CL2FE_DOT_HEAL_ONOFF),
|
||||
PACKET(P_CL2FE_REQ_PC_SPECIAL_STATE_SWITCH),
|
||||
PACKET(P_CL2FE_REQ_PC_EMAIL_UPDATE_CHECK),
|
||||
PACKET(P_CL2FE_REQ_PC_READ_EMAIL),
|
||||
PACKET(P_CL2FE_REQ_PC_RECV_EMAIL_PAGE_LIST),
|
||||
PACKET(P_CL2FE_REQ_PC_DELETE_EMAIL),
|
||||
PACKET(P_CL2FE_REQ_PC_SEND_EMAIL),
|
||||
PACKET(P_CL2FE_REQ_PC_RECV_EMAIL_ITEM),
|
||||
PACKET(P_CL2FE_REQ_PC_RECV_EMAIL_CANDY),
|
||||
PACKET(P_CL2FE_GM_REQ_TARGET_PC_SPECIAL_STATE_ONOFF),
|
||||
PACKET(P_CL2FE_REQ_PC_SET_CURRENT_MISSION_ID),
|
||||
PACKET(P_CL2FE_REQ_NPC_GROUP_INVITE),
|
||||
PACKET(P_CL2FE_REQ_NPC_GROUP_KICK),
|
||||
PACKET(P_CL2FE_REQ_PC_FIRST_USE_FLAG_SET),
|
||||
PACKET(P_CL2FE_REQ_PC_TRANSPORT_WARP),
|
||||
PACKET(P_CL2FE_REQ_PC_TIME_TO_GO_WARP),
|
||||
PACKET(P_CL2FE_REQ_PC_RECV_EMAIL_ITEM_ALL),
|
||||
PACKET(P_CL2FE_REQ_CHANNEL_INFO),
|
||||
PACKET(P_CL2FE_REQ_PC_CHANNEL_NUM),
|
||||
PACKET(P_CL2FE_REQ_PC_WARP_CHANNEL),
|
||||
PACKET(P_CL2FE_REQ_PC_LOADING_COMPLETE),
|
||||
PACKET(P_CL2FE_REQ_PC_FIND_NAME_MAKE_BUDDY),
|
||||
PACKET(P_CL2FE_REQ_PC_FIND_NAME_ACCEPT_BUDDY),
|
||||
VAR_PACKET(P_CL2FE_REQ_PC_ATTACK_CHARs, iTargetCnt, sGM_PVPTarget),
|
||||
PACKET(P_CL2FE_PC_STREETSTALL_REQ_READY),
|
||||
PACKET(P_CL2FE_PC_STREETSTALL_REQ_CANCEL),
|
||||
PACKET(P_CL2FE_PC_STREETSTALL_REQ_REGIST_ITEM),
|
||||
PACKET(P_CL2FE_PC_STREETSTALL_REQ_UNREGIST_ITEM),
|
||||
PACKET(P_CL2FE_PC_STREETSTALL_REQ_SALE_START),
|
||||
PACKET(P_CL2FE_PC_STREETSTALL_REQ_ITEM_LIST),
|
||||
PACKET(P_CL2FE_PC_STREETSTALL_REQ_ITEM_BUY),
|
||||
PACKET(P_CL2FE_REQ_PC_ITEM_COMBINATION),
|
||||
PACKET(P_CL2FE_GM_REQ_SET_PC_SKILL),
|
||||
PACKET(P_CL2FE_REQ_PC_SKILL_ADD),
|
||||
PACKET(P_CL2FE_REQ_PC_SKILL_DEL),
|
||||
PACKET(P_CL2FE_REQ_PC_SKILL_USE),
|
||||
PACKET(P_CL2FE_REQ_PC_ROPE),
|
||||
PACKET(P_CL2FE_REQ_PC_BELT),
|
||||
PACKET(P_CL2FE_REQ_PC_VEHICLE_ON),
|
||||
PACKET(P_CL2FE_REQ_PC_VEHICLE_OFF),
|
||||
PACKET(P_CL2FE_REQ_PC_REGIST_QUICK_SLOT),
|
||||
PACKET(P_CL2FE_REQ_PC_DISASSEMBLE_ITEM),
|
||||
PACKET(P_CL2FE_GM_REQ_REWARD_RATE),
|
||||
PACKET(P_CL2FE_REQ_PC_ITEM_ENCHANT),
|
||||
};
|
||||
|
||||
PacketMap cl2ls_map[] = {
|
||||
STRINGIFY(P_CL2LS_REQ_LOGIN),
|
||||
STRINGIFY(P_CL2LS_REQ_CHECK_CHAR_NAME),
|
||||
STRINGIFY(P_CL2LS_REQ_SAVE_CHAR_NAME),
|
||||
STRINGIFY(P_CL2LS_REQ_CHAR_CREATE),
|
||||
STRINGIFY(P_CL2LS_REQ_CHAR_SELECT),
|
||||
STRINGIFY(P_CL2LS_REQ_CHAR_DELETE),
|
||||
STRINGIFY(P_CL2LS_REQ_SHARD_SELECT),
|
||||
STRINGIFY(P_CL2LS_REQ_SHARD_LIST_INFO),
|
||||
STRINGIFY(P_CL2LS_CHECK_NAME_LIST),
|
||||
STRINGIFY(P_CL2LS_REQ_SAVE_CHAR_TUTOR),
|
||||
STRINGIFY(P_CL2LS_REQ_PC_EXIT_DUPLICATE),
|
||||
STRINGIFY(P_CL2LS_REP_LIVE_CHECK),
|
||||
STRINGIFY(P_CL2LS_REQ_CHANGE_CHAR_NAME),
|
||||
STRINGIFY(P_CL2LS_REQ_SERVER_SELECT),
|
||||
};
|
||||
|
||||
PacketMap cl2fe_map[] = {
|
||||
STRINGIFY(P_CL2FE_REQ_PC_ENTER),
|
||||
STRINGIFY(P_CL2FE_REQ_PC_EXIT),
|
||||
STRINGIFY(P_CL2FE_REQ_PC_MOVE),
|
||||
STRINGIFY(P_CL2FE_REQ_PC_STOP),
|
||||
STRINGIFY(P_CL2FE_REQ_PC_JUMP),
|
||||
STRINGIFY(P_CL2FE_REQ_PC_ATTACK_NPCs),
|
||||
STRINGIFY(P_CL2FE_REQ_SEND_FREECHAT_MESSAGE),
|
||||
STRINGIFY(P_CL2FE_REQ_SEND_MENUCHAT_MESSAGE),
|
||||
STRINGIFY(P_CL2FE_REQ_PC_REGEN),
|
||||
STRINGIFY(P_CL2FE_REQ_ITEM_MOVE),
|
||||
STRINGIFY(P_CL2FE_REQ_PC_TASK_START),
|
||||
STRINGIFY(P_CL2FE_REQ_PC_TASK_END),
|
||||
STRINGIFY(P_CL2FE_REQ_NANO_EQUIP),
|
||||
STRINGIFY(P_CL2FE_REQ_NANO_UNEQUIP),
|
||||
STRINGIFY(P_CL2FE_REQ_NANO_ACTIVE),
|
||||
STRINGIFY(P_CL2FE_REQ_NANO_TUNE),
|
||||
STRINGIFY(P_CL2FE_REQ_NANO_SKILL_USE),
|
||||
STRINGIFY(P_CL2FE_REQ_PC_TASK_STOP),
|
||||
STRINGIFY(P_CL2FE_REQ_PC_TASK_CONTINUE),
|
||||
STRINGIFY(P_CL2FE_REQ_PC_GOTO),
|
||||
STRINGIFY(P_CL2FE_REQ_CHARGE_NANO_STAMINA),
|
||||
STRINGIFY(P_CL2FE_REQ_PC_KILL_QUEST_NPCs),
|
||||
STRINGIFY(P_CL2FE_REQ_PC_VENDOR_ITEM_BUY),
|
||||
STRINGIFY(P_CL2FE_REQ_PC_VENDOR_ITEM_SELL),
|
||||
STRINGIFY(P_CL2FE_REQ_PC_ITEM_DELETE),
|
||||
STRINGIFY(P_CL2FE_REQ_PC_GIVE_ITEM),
|
||||
STRINGIFY(P_CL2FE_REQ_PC_ROCKET_STYLE_READY),
|
||||
STRINGIFY(P_CL2FE_REQ_PC_ROCKET_STYLE_FIRE),
|
||||
STRINGIFY(P_CL2FE_REQ_PC_ROCKET_STYLE_HIT),
|
||||
STRINGIFY(P_CL2FE_REQ_PC_GRENADE_STYLE_READY),
|
||||
STRINGIFY(P_CL2FE_REQ_PC_GRENADE_STYLE_FIRE),
|
||||
STRINGIFY(P_CL2FE_REQ_PC_GRENADE_STYLE_HIT),
|
||||
STRINGIFY(P_CL2FE_REQ_PC_NANO_CREATE),
|
||||
STRINGIFY(P_CL2FE_REQ_PC_TRADE_OFFER),
|
||||
STRINGIFY(P_CL2FE_REQ_PC_TRADE_OFFER_CANCEL),
|
||||
STRINGIFY(P_CL2FE_REQ_PC_TRADE_OFFER_ACCEPT),
|
||||
STRINGIFY(P_CL2FE_REQ_PC_TRADE_OFFER_REFUSAL),
|
||||
STRINGIFY(P_CL2FE_REQ_PC_TRADE_OFFER_ABORT),
|
||||
STRINGIFY(P_CL2FE_REQ_PC_TRADE_CONFIRM),
|
||||
STRINGIFY(P_CL2FE_REQ_PC_TRADE_CONFIRM_CANCEL),
|
||||
STRINGIFY(P_CL2FE_REQ_PC_TRADE_CONFIRM_ABORT),
|
||||
STRINGIFY(P_CL2FE_REQ_PC_TRADE_ITEM_REGISTER),
|
||||
STRINGIFY(P_CL2FE_REQ_PC_TRADE_ITEM_UNREGISTER),
|
||||
STRINGIFY(P_CL2FE_REQ_PC_TRADE_CASH_REGISTER),
|
||||
STRINGIFY(P_CL2FE_REQ_PC_TRADE_EMOTES_CHAT),
|
||||
STRINGIFY(P_CL2FE_REQ_PC_BANK_OPEN),
|
||||
STRINGIFY(P_CL2FE_REQ_PC_BANK_CLOSE),
|
||||
STRINGIFY(P_CL2FE_REQ_PC_VENDOR_START),
|
||||
STRINGIFY(P_CL2FE_REQ_PC_VENDOR_TABLE_UPDATE),
|
||||
STRINGIFY(P_CL2FE_REQ_PC_VENDOR_ITEM_RESTORE_BUY),
|
||||
STRINGIFY(P_CL2FE_REQ_PC_COMBAT_BEGIN),
|
||||
STRINGIFY(P_CL2FE_REQ_PC_COMBAT_END),
|
||||
STRINGIFY(P_CL2FE_REQ_REQUEST_MAKE_BUDDY),
|
||||
STRINGIFY(P_CL2FE_REQ_ACCEPT_MAKE_BUDDY),
|
||||
STRINGIFY(P_CL2FE_REQ_SEND_BUDDY_FREECHAT_MESSAGE),
|
||||
STRINGIFY(P_CL2FE_REQ_SEND_BUDDY_MENUCHAT_MESSAGE),
|
||||
STRINGIFY(P_CL2FE_REQ_GET_BUDDY_STYLE),
|
||||
STRINGIFY(P_CL2FE_REQ_SET_BUDDY_BLOCK),
|
||||
STRINGIFY(P_CL2FE_REQ_REMOVE_BUDDY),
|
||||
STRINGIFY(P_CL2FE_REQ_GET_BUDDY_STATE),
|
||||
STRINGIFY(P_CL2FE_REQ_PC_JUMPPAD),
|
||||
STRINGIFY(P_CL2FE_REQ_PC_LAUNCHER),
|
||||
STRINGIFY(P_CL2FE_REQ_PC_ZIPLINE),
|
||||
STRINGIFY(P_CL2FE_REQ_PC_MOVEPLATFORM),
|
||||
STRINGIFY(P_CL2FE_REQ_PC_SLOPE),
|
||||
STRINGIFY(P_CL2FE_REQ_PC_STATE_CHANGE),
|
||||
STRINGIFY(P_CL2FE_REQ_PC_MAP_WARP),
|
||||
STRINGIFY(P_CL2FE_REQ_PC_GIVE_NANO),
|
||||
STRINGIFY(P_CL2FE_REQ_NPC_SUMMON),
|
||||
STRINGIFY(P_CL2FE_REQ_NPC_UNSUMMON),
|
||||
STRINGIFY(P_CL2FE_REQ_ITEM_CHEST_OPEN),
|
||||
STRINGIFY(P_CL2FE_REQ_PC_GIVE_NANO_SKILL),
|
||||
STRINGIFY(P_CL2FE_DOT_DAMAGE_ONOFF),
|
||||
STRINGIFY(P_CL2FE_REQ_PC_VENDOR_BATTERY_BUY),
|
||||
STRINGIFY(P_CL2FE_REQ_PC_WARP_USE_NPC),
|
||||
STRINGIFY(P_CL2FE_REQ_PC_GROUP_INVITE),
|
||||
STRINGIFY(P_CL2FE_REQ_PC_GROUP_INVITE_REFUSE),
|
||||
STRINGIFY(P_CL2FE_REQ_PC_GROUP_JOIN),
|
||||
STRINGIFY(P_CL2FE_REQ_PC_GROUP_LEAVE),
|
||||
STRINGIFY(P_CL2FE_REQ_PC_AVATAR_EMOTES_CHAT),
|
||||
STRINGIFY(P_CL2FE_REQ_PC_BUDDY_WARP),
|
||||
STRINGIFY(P_CL2FE_REQ_GET_MEMBER_STYLE),
|
||||
STRINGIFY(P_CL2FE_REQ_GET_GROUP_STYLE),
|
||||
STRINGIFY(P_CL2FE_REQ_PC_CHANGE_MENTOR),
|
||||
STRINGIFY(P_CL2FE_REQ_GET_BUDDY_LOCATION),
|
||||
STRINGIFY(P_CL2FE_REQ_NPC_GROUP_SUMMON),
|
||||
STRINGIFY(P_CL2FE_REQ_PC_WARP_TO_PC),
|
||||
STRINGIFY(P_CL2FE_REQ_EP_RANK_GET_LIST),
|
||||
STRINGIFY(P_CL2FE_REQ_EP_RANK_GET_DETAIL),
|
||||
STRINGIFY(P_CL2FE_REQ_EP_RANK_GET_PC_INFO),
|
||||
STRINGIFY(P_CL2FE_REQ_EP_RACE_START),
|
||||
STRINGIFY(P_CL2FE_REQ_EP_RACE_END),
|
||||
STRINGIFY(P_CL2FE_REQ_EP_RACE_CANCEL),
|
||||
STRINGIFY(P_CL2FE_REQ_EP_GET_RING),
|
||||
STRINGIFY(P_CL2FE_REQ_IM_CHANGE_SWITCH_STATUS),
|
||||
STRINGIFY(P_CL2FE_REQ_SHINY_PICKUP),
|
||||
STRINGIFY(P_CL2FE_REQ_SHINY_SUMMON),
|
||||
STRINGIFY(P_CL2FE_REQ_PC_MOVETRANSPORTATION),
|
||||
STRINGIFY(P_CL2FE_REQ_SEND_ALL_GROUP_FREECHAT_MESSAGE),
|
||||
STRINGIFY(P_CL2FE_REQ_SEND_ANY_GROUP_FREECHAT_MESSAGE),
|
||||
STRINGIFY(P_CL2FE_REQ_BARKER),
|
||||
STRINGIFY(P_CL2FE_REQ_SEND_ALL_GROUP_MENUCHAT_MESSAGE),
|
||||
STRINGIFY(P_CL2FE_REQ_SEND_ANY_GROUP_MENUCHAT_MESSAGE),
|
||||
STRINGIFY(P_CL2FE_REQ_REGIST_TRANSPORTATION_LOCATION),
|
||||
STRINGIFY(P_CL2FE_REQ_PC_WARP_USE_TRANSPORTATION),
|
||||
STRINGIFY(P_CL2FE_GM_REQ_PC_SPECIAL_STATE_SWITCH),
|
||||
STRINGIFY(P_CL2FE_GM_REQ_PC_SET_VALUE),
|
||||
STRINGIFY(P_CL2FE_GM_REQ_KICK_PLAYER),
|
||||
STRINGIFY(P_CL2FE_GM_REQ_TARGET_PC_TELEPORT),
|
||||
STRINGIFY(P_CL2FE_GM_REQ_PC_LOCATION),
|
||||
STRINGIFY(P_CL2FE_GM_REQ_PC_ANNOUNCE),
|
||||
STRINGIFY(P_CL2FE_REQ_SET_PC_BLOCK),
|
||||
STRINGIFY(P_CL2FE_REQ_REGIST_RXCOM),
|
||||
STRINGIFY(P_CL2FE_GM_REQ_PC_MOTD_REGISTER),
|
||||
STRINGIFY(P_CL2FE_REQ_ITEM_USE),
|
||||
STRINGIFY(P_CL2FE_REQ_WARP_USE_RECALL),
|
||||
STRINGIFY(P_CL2FE_REP_LIVE_CHECK),
|
||||
STRINGIFY(P_CL2FE_REQ_PC_MISSION_COMPLETE),
|
||||
STRINGIFY(P_CL2FE_REQ_PC_TASK_COMPLETE),
|
||||
STRINGIFY(P_CL2FE_REQ_NPC_INTERACTION),
|
||||
STRINGIFY(P_CL2FE_DOT_HEAL_ONOFF),
|
||||
STRINGIFY(P_CL2FE_REQ_PC_SPECIAL_STATE_SWITCH),
|
||||
STRINGIFY(P_CL2FE_REQ_PC_EMAIL_UPDATE_CHECK),
|
||||
STRINGIFY(P_CL2FE_REQ_PC_READ_EMAIL),
|
||||
STRINGIFY(P_CL2FE_REQ_PC_RECV_EMAIL_PAGE_LIST),
|
||||
STRINGIFY(P_CL2FE_REQ_PC_DELETE_EMAIL),
|
||||
STRINGIFY(P_CL2FE_REQ_PC_SEND_EMAIL),
|
||||
STRINGIFY(P_CL2FE_REQ_PC_RECV_EMAIL_ITEM),
|
||||
STRINGIFY(P_CL2FE_REQ_PC_RECV_EMAIL_CANDY),
|
||||
STRINGIFY(P_CL2FE_GM_REQ_TARGET_PC_SPECIAL_STATE_ONOFF),
|
||||
STRINGIFY(P_CL2FE_REQ_PC_SET_CURRENT_MISSION_ID),
|
||||
STRINGIFY(P_CL2FE_REQ_NPC_GROUP_INVITE),
|
||||
STRINGIFY(P_CL2FE_REQ_NPC_GROUP_KICK),
|
||||
STRINGIFY(P_CL2FE_REQ_PC_FIRST_USE_FLAG_SET),
|
||||
STRINGIFY(P_CL2FE_REQ_PC_TRANSPORT_WARP),
|
||||
STRINGIFY(P_CL2FE_REQ_PC_TIME_TO_GO_WARP),
|
||||
STRINGIFY(P_CL2FE_REQ_PC_RECV_EMAIL_ITEM_ALL),
|
||||
STRINGIFY(P_CL2FE_REQ_CHANNEL_INFO),
|
||||
STRINGIFY(P_CL2FE_REQ_PC_CHANNEL_NUM),
|
||||
STRINGIFY(P_CL2FE_REQ_PC_WARP_CHANNEL),
|
||||
STRINGIFY(P_CL2FE_REQ_PC_LOADING_COMPLETE),
|
||||
STRINGIFY(P_CL2FE_REQ_PC_FIND_NAME_MAKE_BUDDY),
|
||||
STRINGIFY(P_CL2FE_REQ_PC_FIND_NAME_ACCEPT_BUDDY),
|
||||
STRINGIFY(P_CL2FE_REQ_PC_ATTACK_CHARs),
|
||||
STRINGIFY(P_CL2FE_PC_STREETSTALL_REQ_READY),
|
||||
STRINGIFY(P_CL2FE_PC_STREETSTALL_REQ_CANCEL),
|
||||
STRINGIFY(P_CL2FE_PC_STREETSTALL_REQ_REGIST_ITEM),
|
||||
STRINGIFY(P_CL2FE_PC_STREETSTALL_REQ_UNREGIST_ITEM),
|
||||
STRINGIFY(P_CL2FE_PC_STREETSTALL_REQ_SALE_START),
|
||||
STRINGIFY(P_CL2FE_PC_STREETSTALL_REQ_ITEM_LIST),
|
||||
STRINGIFY(P_CL2FE_PC_STREETSTALL_REQ_ITEM_BUY),
|
||||
STRINGIFY(P_CL2FE_REQ_PC_ITEM_COMBINATION),
|
||||
STRINGIFY(P_CL2FE_GM_REQ_SET_PC_SKILL),
|
||||
STRINGIFY(P_CL2FE_REQ_PC_SKILL_ADD),
|
||||
STRINGIFY(P_CL2FE_REQ_PC_SKILL_DEL),
|
||||
STRINGIFY(P_CL2FE_REQ_PC_SKILL_USE),
|
||||
STRINGIFY(P_CL2FE_REQ_PC_ROPE),
|
||||
STRINGIFY(P_CL2FE_REQ_PC_BELT),
|
||||
STRINGIFY(P_CL2FE_REQ_PC_VEHICLE_ON),
|
||||
STRINGIFY(P_CL2FE_REQ_PC_VEHICLE_OFF),
|
||||
STRINGIFY(P_CL2FE_REQ_PC_REGIST_QUICK_SLOT),
|
||||
STRINGIFY(P_CL2FE_REQ_PC_DISASSEMBLE_ITEM),
|
||||
STRINGIFY(P_CL2FE_GM_REQ_REWARD_RATE),
|
||||
STRINGIFY(P_CL2FE_REQ_PC_ITEM_ENCHANT),
|
||||
};
|
||||
|
||||
std::string Packets::p2str(int type, int val) {
|
||||
switch (type) {
|
||||
case CL2LS:
|
||||
val = val - CL2LS - 1;
|
||||
if (val > N_CL2LS || val < 0)
|
||||
break;
|
||||
|
||||
return cl2ls_map[val].name;
|
||||
case CL2FE:
|
||||
val = val - CL2FE - 1;
|
||||
if (val > N_CL2FE || val < 0)
|
||||
break;
|
||||
|
||||
return cl2fe_map[val].name;
|
||||
}
|
||||
|
||||
std::string Packets::p2str(int val) {
|
||||
if (packets.find(val) == packets.end())
|
||||
return "UNKNOWN";
|
||||
|
||||
return packets[val].name;
|
||||
}
|
||||
|
63
src/core/Packets.hpp
Normal file
63
src/core/Packets.hpp
Normal file
@ -0,0 +1,63 @@
|
||||
#pragma once
|
||||
|
||||
#include "CNStructs.hpp"
|
||||
|
||||
#include <map>
|
||||
|
||||
// Packet Descriptor
|
||||
struct PacketDesc {
|
||||
uint32_t val;
|
||||
std::string name;
|
||||
size_t size;
|
||||
bool variadic;
|
||||
size_t cntMembOfs;
|
||||
size_t trailerSize;
|
||||
|
||||
PacketDesc() {}
|
||||
|
||||
PacketDesc(const PacketDesc& other) {
|
||||
val = other.val;
|
||||
name = other.name;
|
||||
size = other.size;
|
||||
variadic = other.variadic;
|
||||
cntMembOfs = other.cntMembOfs;
|
||||
trailerSize = other.trailerSize;
|
||||
}
|
||||
|
||||
PacketDesc(PacketDesc&& other) {
|
||||
val = other.val;
|
||||
name = std::move(other.name);
|
||||
size = other.size;
|
||||
variadic = other.variadic;
|
||||
cntMembOfs = other.cntMembOfs;
|
||||
trailerSize = other.trailerSize;
|
||||
}
|
||||
|
||||
// non-variadic constructor
|
||||
PacketDesc(uint32_t v, size_t s, std::string n) :
|
||||
val(v), name(n), size(s), variadic(false) {}
|
||||
|
||||
// variadic constructor
|
||||
PacketDesc(uint32_t v, size_t s, std::string n, size_t ofs, size_t ts) :
|
||||
val(v), name(n), size(s), variadic(true), cntMembOfs(ofs), trailerSize(ts) {}
|
||||
};
|
||||
|
||||
/*
|
||||
* Extra trailer structs for places where the client doesn't have any, but
|
||||
* really should.
|
||||
*/
|
||||
struct sGM_PVPTarget {
|
||||
uint32_t eCT;
|
||||
uint32_t iID;
|
||||
};
|
||||
|
||||
struct sSkillResult_Leech {
|
||||
sSkillResult_Heal_HP Heal;
|
||||
sSkillResult_Damage Damage;
|
||||
};
|
||||
|
||||
namespace Packets {
|
||||
extern std::map<uint32_t, PacketDesc> packets;
|
||||
|
||||
std::string p2str(int val);
|
||||
}
|
@ -17,7 +17,7 @@ CNLoginServer::CNLoginServer(uint16_t p) {
|
||||
}
|
||||
|
||||
void CNLoginServer::handlePacket(CNSocket* sock, CNPacketData* data) {
|
||||
printPacket(data, CL2LS);
|
||||
printPacket(data);
|
||||
|
||||
switch (data->type) {
|
||||
case P_CL2LS_REQ_LOGIN: {
|
||||
@ -62,7 +62,7 @@ void CNLoginServer::handlePacket(CNSocket* sock, CNPacketData* data) {
|
||||
}
|
||||
default:
|
||||
if (settings::VERBOSITY)
|
||||
std::cerr << "OpenFusion: LOGIN UNIMPLM ERR. PacketType: " << Packets::p2str(CL2LS, data->type) << " (" << data->type << ")" << std::endl;
|
||||
std::cerr << "OpenFusion: LOGIN UNIMPLM ERR. PacketType: " << Packets::p2str(data->type) << " (" << data->type << ")" << std::endl;
|
||||
break;
|
||||
/*
|
||||
* Unimplemented CL2LS packets:
|
||||
|
@ -27,12 +27,12 @@ CNShardServer::CNShardServer(uint16_t p) {
|
||||
}
|
||||
|
||||
void CNShardServer::handlePacket(CNSocket* sock, CNPacketData* data) {
|
||||
printPacket(data, CL2FE);
|
||||
printPacket(data);
|
||||
|
||||
if (ShardPackets.find(data->type) != ShardPackets.end())
|
||||
ShardPackets[data->type](sock, data);
|
||||
else if (settings::VERBOSITY > 0)
|
||||
std::cerr << "OpenFusion: SHARD UNIMPLM ERR. PacketType: " << Packets::p2str(CL2FE, data->type) << " (" << data->type << ")" << std::endl;
|
||||
std::cerr << "OpenFusion: SHARD UNIMPLM ERR. PacketType: " << Packets::p2str(data->type) << " (" << data->type << ")" << std::endl;
|
||||
|
||||
if (PlayerManager::players.find(sock) != PlayerManager::players.end())
|
||||
PlayerManager::players[sock]->lastHeartbeat = getTime();
|
||||
|
Loading…
Reference in New Issue
Block a user