diff options
author | mrb0nk500 <b0nk@b0nk.xyz> | 2023-03-22 15:34:08 -0300 |
---|---|---|
committer | mrb0nk500 <b0nk@b0nk.xyz> | 2023-03-22 15:34:49 -0300 |
commit | 0b0f3da43d281b75cc04a9333332f2abc1eff0c7 (patch) | |
tree | 7d7aaf7326b6501383c66d8fbc0341f47bed1fea | |
parent | 769c041207521e8b5fd46a616b499fe21088c9a7 (diff) |
TProtocol: Add (and match) more command senders
-rw-r--r-- | context.h | 59 | ||||
-rw-r--r-- | include/pso/TProtocol.h | 9 | ||||
-rw-r--r-- | include/pso/packet_classes.h | 47 | ||||
-rw-r--r-- | src/pso/TProtocol.cpp | 158 |
4 files changed, 273 insertions, 0 deletions
@@ -234,6 +234,23 @@ public: \ members \ } __packed__ +// pso/packet_classes.h +#if !defined(__GNUC__) && !defined(__clang__) +#define _TSendAction(action_type, members) \ +template<> \ +class TSendAction<action_type> { \ +public: \ + packet_header header; \ + TPlyGuildCardTag tag; \ + members \ +public: \ + void bswap() { \ + header.bswap(); \ + tag.bswap(); \ + }; \ +} +#endif + // pso/forward.h // Class forward. class TTcpSocket; @@ -510,6 +527,39 @@ TMenuListEntry(QuestListEntry, char short_description[112]; ); +template<int action_type = 0> +class TSendAction { +public: + packet_header header; + TPlyGuildCardTag tag; + #if defined(__GNUC__) || defined(__clang__) + char name[(action_type & 1) ? 16 : 0]; + char password[(action_type & 2) ? 16 : 0]; + #endif +public: + void bswap() { + header.bswap(); + tag.bswap(); + }; +}; + +#if !defined(__GNUC__) && !defined(__clang__) +_TSendAction(1, + char name[16]; +); + +_TSendAction(2, + char password[16]; +); + +_TSendAction(3, + char name[16]; + char password[16]; +); + +#undef _TSendAction +#endif + // pso/TProtocol.h // NOTE: This is only here because of the ordering of this. // In Reality, the definition of `_packet` is above `flex_packet`. @@ -1655,4 +1705,13 @@ public: void send_logout(); // 0x06 void send_chat(TPlyGuildCardTag &tag, char *mesg); + // 0x10 + void send_action(GameListEntry &selection, char *action_name, char *password); + void send_action(GameListEntry &selection, u8 flags, char *action_name, char *password); + // 0x09 + void send_info(TPlyGuildCardTag &tag); + // 0x08 + void send_game_list(); + // 0x1F + void send_text_list(); }; diff --git a/include/pso/TProtocol.h b/include/pso/TProtocol.h index 31e6eab..b970998 100644 --- a/include/pso/TProtocol.h +++ b/include/pso/TProtocol.h @@ -255,6 +255,15 @@ public: void send_logout(); // 0x06 void send_chat(TPlyGuildCardTag &tag, char *mesg); + // 0x10 + void send_action(GameListEntry &selection, char *action_name, char *password); + void send_action(GameListEntry &selection, u8 flags, char *action_name, char *password); + // 0x09 + void send_info(TPlyGuildCardTag &tag); + // 0x08 + void send_game_list(); + // 0x1F + void send_text_list(); }; #endif diff --git a/include/pso/packet_classes.h b/include/pso/packet_classes.h index 98f45bc..268ac40 100644 --- a/include/pso/packet_classes.h +++ b/include/pso/packet_classes.h @@ -83,6 +83,53 @@ union game_command_union { u8 bytes[1024]; }; +template<int action_type = 0> +class TSendAction { +public: + packet_header header; + TPlyGuildCardTag tag; + #if defined(__GNUC__) || defined(__clang__) + char name[(action_type & 1) ? 16 : 0]; + char password[(action_type & 2) ? 16 : 0]; + #endif +public: + void bswap() { + header.bswap(); + tag.bswap(); + }; +}; + +#if !defined(__GNUC__) && !defined(__clang__) +#define _TSendAction(action_type, members) \ +template<> \ +class TSendAction<action_type> { \ +public: \ + packet_header header; \ + TPlyGuildCardTag tag; \ + members \ +public: \ + void bswap() { \ + header.bswap(); \ + tag.bswap(); \ + }; \ +} + +_TSendAction(1, + char name[16]; +); + +_TSendAction(2, + char password[16]; +); + +_TSendAction(3, + char name[16]; + char password[16]; +); + +#undef _TSendAction +#endif + class TRegister { public: packet_header header; diff --git a/src/pso/TProtocol.cpp b/src/pso/TProtocol.cpp index 5638a4d..1a992e3 100644 --- a/src/pso/TProtocol.cpp +++ b/src/pso/TProtocol.cpp @@ -24,6 +24,163 @@ void copy_packet(struct packet *pkt) { } +void TProtocol::send_text_list() { + if (m_connected) { + packet_header tmp; + + tmp.command = 0x1F; + tmp.flags = 0; + tmp.size = sizeof(tmp); + + tmp.bswap(); + send(as(u8 *, &tmp), sizeof(tmp)); + } +} + +void TProtocol::send_game_list() { + if (m_connected) { + packet_header tmp; + + tmp.command = 0x08; + tmp.flags = 0; + tmp.size = sizeof(tmp); + + tmp.bswap(); + send(as(u8 *, &tmp), sizeof(tmp)); + } +} + +void TProtocol::send_info(TPlyGuildCardTag &tag) { + if (m_connected) { + TSendAction<0> tmp; + + tmp.header.command = 0x09; + tmp.header.flags = 0; + tmp.header.size = sizeof(tmp); + tmp.tag = tag; + + tmp.bswap(); + send(as(u8 *, &tmp), sizeof(tmp)); + } +} +void TProtocol::send_action(GameListEntry &selection, u8 flags, char *action_name, char *password) { + if (m_connected) { + switch (selection.flags & 3) { + case 0: { + TSendAction<0> action; + + action.header.command = 0x10; + action.header.flags = flags; + action.header.size = sizeof(action); + action.tag = selection.tag; + + action.bswap(); + send(as(u8 *, &action), sizeof(action)); + break; + } + case 1: { + TSendAction<1> action; + + action.header.command = 0x10; + action.header.flags = 1; + action.header.size = sizeof(action); + action.tag = selection.tag; + strncpy(action.name, action_name, sizeof(action.name)); + + action.bswap(); + send(as(u8 *, &action), sizeof(action)); + break; + } + case 2: { + TSendAction<2> action; + + action.header.command = 0x10; + action.header.flags = 2; + action.header.size = sizeof(action); + action.tag = selection.tag; + strncpy(action.password, password, sizeof(action.password)); + + action.bswap(); + send(as(u8 *, &action), sizeof(action)); + break; + } + case 3: { + TSendAction<3> action; + + action.header.command = 0x10; + action.header.flags = 3; + action.header.size = sizeof(action); + action.tag = selection.tag; + strncpy(action.name, action_name, sizeof(action.name)); + strncpy(action.password, password, sizeof(action.password)); + + action.bswap(); + send(as(u8 *, &action), sizeof(action)); + break; + } + } + } +} + +void TProtocol::send_action(GameListEntry &selection, char *action_name, char *password) { + if (m_connected) { + switch (selection.flags & 3) { + case 0: { + TSendAction<0> action; + + action.header.command = 0x10; + action.header.flags = 0; + action.header.size = sizeof(action); + action.tag = selection.tag; + + action.bswap(); + send(as(u8 *, &action), sizeof(action)); + break; + } + case 1: { + TSendAction<1> action; + + action.header.command = 0x10; + action.header.flags = 1; + action.header.size = sizeof(action); + action.tag = selection.tag; + strncpy(action.name, action_name, sizeof(action.name)); + + action.bswap(); + send(as(u8 *, &action), sizeof(action)); + break; + } + case 2: { + TSendAction<2> action; + + action.header.command = 0x10; + action.header.flags = 2; + action.header.size = sizeof(action); + action.tag = selection.tag; + strncpy(action.password, password, sizeof(action.password)); + + action.bswap(); + send(as(u8 *, &action), sizeof(action)); + break; + } + case 3: { + TSendAction<3> action; + + action.header.command = 0x10; + action.header.flags = 3; + action.header.size = sizeof(action); + action.tag = selection.tag; + strncpy(action.name, action_name, sizeof(action.name)); + strncpy(action.password, password, sizeof(action.password)); + + action.bswap(); + send(as(u8 *, &action), sizeof(action)); + break; + } + } + } +} + void TProtocol::send_chat(TPlyGuildCardTag &tag, char *mesg) { if (m_connected) { TMessageBox tmp; @@ -43,6 +200,7 @@ void TProtocol::send_chat(TPlyGuildCardTag &tag, char *mesg) { send(as(u8 *, &tmp), size); } } + void TProtocol::send_logout() { packet_header tmp; tmp.command = 0x05; |