summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormrb0nk500 <b0nk@b0nk.xyz>2023-05-30 14:20:53 -0300
committermrb0nk500 <b0nk@b0nk.xyz>2023-05-30 14:23:02 -0300
commit569acdac5cb8e8ab352e2fbbae9660d9ad29c41a (patch)
tree6f7a02cc0cc36d7ded88e8dee3e920aa1f395350
parenta77eec717e08422876315fbd81afb5d492b75315 (diff)
TProtocol: Add (and match) recv_pso_regist_{connect,check}()
-rw-r--r--context.h80
-rw-r--r--include/pso/TProtocol.h12
-rw-r--r--include/pso/packet_classes.h68
-rw-r--r--src/pso/TProtocol.cpp40
4 files changed, 173 insertions, 27 deletions
diff --git a/context.h b/context.h
index 8d4e3d0..dd9c539 100644
--- a/context.h
+++ b/context.h
@@ -188,7 +188,7 @@ typedef long ptrdiff_t;
o(handle_66_recv_exit_game, int client_id, int leader_id, int disable_udp) \
o(handle_68_recv_burst_lobby, TPlyJoinLobbyEntry *entries, int leader_id) \
o(handle_69_recv_exit_lobby, int client_id, int leader_id) \
- o(handle_18_90_9A_login_response_packet, void) \
+ o(handle_18_90_9A_recv_pso_regist_check, u8 state) \
o(handle_92_9C_register_response_packet, void) \
o(unused10, void) \
o(handle_95_request_character_data_packet, void) \
@@ -898,6 +898,27 @@ struct send_buffs {
};
// pso/packet_classes.h
+#define _gc_tag_packet_templ(name, members) \
+template<bool has_gc_tag = false> \
+struct name { \
+ packet_header header; \
+ members \
+}; \
+ \
+template<> \
+struct name<true> { \
+ packet_header header; \
+ TPlyGuildCardTag tag; \
+ members \
+}
+
+_gc_tag_packet_templ(regist,
+ TPlySmth smth;
+ u32 sub_version;
+ u8 is_extended;
+ u8 language;
+);
+
struct game_command_header {
char command;
char size;
@@ -1467,6 +1488,45 @@ public:
};
};
+class TSendPsoRegist : public regist<false> {
+public:
+ char serial_number[48];
+ char access_key[48];
+ char password[48];
+public:
+ void bswap() {
+ header.bswap();
+ smth.bswap();
+ bswap_32(&sub_version);
+ };
+};
+
+class TSendPsoRegistConnect {
+public:
+ packet_header header;
+ char serial_number[17];
+ char access_key[17];
+ u16 padding;
+public:
+ void bswap() {
+ header.bswap();
+ };
+};
+
+class TRecvPsoRegistConnect {
+public:
+ packet_header header;
+ char copyright[64];
+ u32 server_key;
+ u32 client_key;
+public:
+ void bswap() {
+ header.bswap();
+ bswap_32(&server_key);
+ bswap_32(&client_key);
+ };
+};
+
template<bool is_lobby>
class TRecvExit {
public:
@@ -1480,14 +1540,8 @@ public:
};
};
-class TRegister {
+class TRegister : public regist<false> {
public:
- packet_header header;
- TPlySmth smth;
- u32 sub_version;
- u8 is_extended;
- u8 language;
- u16 unknown;
char serial_number[16];
char access_key[16];
public:
@@ -1792,7 +1846,7 @@ public:
TPlySmth m_smth;
TPlyGuildCardTag m_guildcard_tag;
u16 m_sub_version;
- int m_login_response_state;
+ int m_regist_state;
int m_connected;
int m_joined_game;
int m_has_meet_user_settings;
@@ -1811,8 +1865,8 @@ public:
LobbyListEntry m_lobby_entries[16];
QuestListEntry m_quest_entries[30];
u8 m_unused5[128];
- char m_serial_number3[17];
- char m_password2[17];
+ char m_serial_number_v1[17];
+ char m_access_key_v1[17];
char m_serial_number[48];
char m_access_key[48];
char m_password[64];
@@ -1917,6 +1971,10 @@ public:
void recv_burst_lobby(packet &pkt);
// 0x69
void recv_exit_lobby(packet &pkt);
+ // 0x91
+ void recv_pso_regist_connect(packet &pkt);
+ // 0x18/0x90
+ void recv_pso_regist_check(packet &pkt);
// Send command handlers.
// 0x03
diff --git a/include/pso/TProtocol.h b/include/pso/TProtocol.h
index 041cd56..886965c 100644
--- a/include/pso/TProtocol.h
+++ b/include/pso/TProtocol.h
@@ -69,7 +69,7 @@ struct packet : public flex_packet<0x7c00> {};
o(handle_66_recv_exit_game, int client_id, int leader_id, int disable_udp) \
o(handle_68_recv_burst_lobby, TPlyJoinLobbyEntry *entries, int leader_id) \
o(handle_69_recv_exit_lobby, int client_id, int leader_id) \
- o(handle_18_90_9A_login_response_packet, void) \
+ o(handle_18_90_9A_recv_pso_regist_check, u8 state) \
o(handle_92_9C_register_response_packet, void) \
o(unused10, void) \
o(handle_95_request_character_data_packet, void) \
@@ -126,7 +126,7 @@ public:
TPlySmth m_smth;
TPlyGuildCardTag m_guildcard_tag;
u16 m_sub_version;
- int m_login_response_state;
+ int m_regist_state;
int m_connected;
int m_joined_game;
int m_has_meet_user_settings;
@@ -145,8 +145,8 @@ public:
LobbyListEntry m_lobby_entries[16];
QuestListEntry m_quest_entries[30];
u8 m_unused5[128];
- char m_serial_number3[17];
- char m_password2[17];
+ char m_serial_number_v1[17];
+ char m_access_key_v1[17];
char m_serial_number[48];
char m_access_key[48];
char m_password[64];
@@ -251,6 +251,10 @@ public:
void recv_burst_lobby(packet &pkt);
// 0x69
void recv_exit_lobby(packet &pkt);
+ // 0x91
+ void recv_pso_regist_connect(packet &pkt);
+ // 0x18/0x90
+ void recv_pso_regist_check(packet &pkt);
// Send command handlers.
// 0x03
diff --git a/include/pso/packet_classes.h b/include/pso/packet_classes.h
index 9cd9800..f0e2fcc 100644
--- a/include/pso/packet_classes.h
+++ b/include/pso/packet_classes.h
@@ -14,6 +14,27 @@
#include <pso/TPlyGuildCardTag.h>
#include <pso/TPlySmth.h>
+#define _gc_tag_packet_templ(name, members) \
+template<bool has_gc_tag = false> \
+struct name { \
+ packet_header header; \
+ members \
+}; \
+ \
+template<> \
+struct name<true> { \
+ packet_header header; \
+ TPlyGuildCardTag tag; \
+ members \
+}
+
+_gc_tag_packet_templ(regist,
+ TPlySmth smth;
+ u32 sub_version;
+ u8 is_extended;
+ u8 language;
+);
+
template<size_t size>
struct TPlyText {
packet_header header;
@@ -233,6 +254,45 @@ _TSendAction(3,
#undef _TSendAction
#endif
+class TSendPsoRegist : public regist<false> {
+public:
+ char serial_number[48];
+ char access_key[48];
+ char password[48];
+public:
+ void bswap() {
+ header.bswap();
+ smth.bswap();
+ bswap_32(&sub_version);
+ };
+};
+
+class TSendPsoRegistConnect {
+public:
+ packet_header header;
+ char serial_number[17];
+ char access_key[17];
+ u16 padding;
+public:
+ void bswap() {
+ header.bswap();
+ };
+};
+
+class TRecvPsoRegistConnect {
+public:
+ packet_header header;
+ char copyright[64];
+ u32 server_key;
+ u32 client_key;
+public:
+ void bswap() {
+ header.bswap();
+ bswap_32(&server_key);
+ bswap_32(&client_key);
+ };
+};
+
template<bool is_lobby>
class TRecvExit {
public:
@@ -246,14 +306,8 @@ public:
};
};
-class TRegister {
+class TRegister : public regist<false> {
public:
- packet_header header;
- TPlySmth smth;
- u32 sub_version;
- u8 is_extended;
- u8 language;
- u16 unknown;
char serial_number[16];
char access_key[16];
public:
diff --git a/src/pso/TProtocol.cpp b/src/pso/TProtocol.cpp
index e876e02..c4b42b5 100644
--- a/src/pso/TProtocol.cpp
+++ b/src/pso/TProtocol.cpp
@@ -19,11 +19,41 @@ u32 new_ip_addr;
u16 new_port;
TPlyMeetUserExtension meet_user_settings;
u32 game_variations[16][2];
+const char *port_map_copyright = "DreamCast Port Map. Copyright SEGA Enterprises. 1999";
void copy_packet(struct packet *pkt) {
}
+void TProtocol::recv_pso_regist_check(packet &pkt) {
+ packet_header tmp = pkt.pkt.header;
+ tmp.bswap();
+ m_regist_state = tmp.flags;
+ if (m_recv_handlers.handle_18_90_9A_recv_pso_regist_check != nullptr) {
+ m_recv_handlers.handle_18_90_9A_recv_pso_regist_check(tmp.flags);
+ }
+}
+
+void TProtocol::recv_pso_regist_connect(packet &pkt) {
+ TRecvPsoRegistConnect tmp = as(TRecvPsoRegistConnect &, pkt);
+ tmp.bswap();
+ if (!strcmp(port_map_copyright, tmp.copyright)) {
+ TSendPsoRegistConnect tmp2;
+ m_recv_crypt.reset(tmp.server_key);
+ m_send_crypt.reset(tmp.client_key);
+ m_is_encrypted = true;
+ memset(&tmp2, 0, sizeof(tmp2));
+ tmp2.header.command = 0x90;
+ tmp2.header.size = sizeof(tmp2);
+ strncpy(tmp2.serial_number, m_serial_number_v1, sizeof(tmp2.serial_number)-1);
+ strncpy(tmp2.access_key, m_access_key_v1, sizeof(tmp2.access_key)-1);
+ tmp2.bswap();
+ send(as(u8 *, &tmp2), sizeof(tmp2));
+ } else {
+ close();
+ }
+}
+
void TProtocol::recv_exit_lobby(packet &pkt) {
TRecvExit<true> tmp = as(TRecvExit<true> &, pkt);
tmp.bswap();
@@ -838,7 +868,7 @@ void TProtocol::recv_login(packet &pkt) {
void TProtocol::recv_regist(packet &pkt) {
packet_header tmp = pkt.pkt.header;
tmp.bswap();
- m_login_response_state = tmp.flags;
+ m_regist_state = tmp.flags;
if (m_recv_handlers.handle_03_recv_regist != nullptr) {
m_recv_handlers.handle_03_recv_regist(tmp.flags);
}
@@ -876,7 +906,7 @@ int TProtocol::handle_command(struct packet *pkt) {
{ 0x13, &recv_download },
{ 0x14, &recv_upload },
{ 0x11, &recv_message },
- // 0x18
+ { 0x18, &recv_pso_regist_check },
// 0x17
{ 0x19, &recv_port },
{ 0x1A, &recv_text },
@@ -898,8 +928,8 @@ int TProtocol::handle_command(struct packet *pkt) {
{ 0x66, &recv_exit_game },
{ 0x68, &recv_burst_lobby },
{ 0x69, &recv_exit_lobby },
- // 0x90
- // 0x91
+ { 0x90, &recv_pso_regist_check },
+ { 0x91, &recv_pso_regist_connect },
// 0x92
// 0x95
{ 0xA0, &recv_dir_list },
@@ -1037,7 +1067,7 @@ TProtocol::TProtocol(TObject *parent, u16 sub_version, int language, char *seria
m_smth.m_smth1[i++] = thing[j++];
}
m_guildcard_tag = TPlyGuildCardTag(-1, -1);
- m_login_response_state = 0;
+ m_regist_state = 0;
m_connected = 0;
m_joined_game = 0;
m_has_meet_user_settings = 0;