summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormrb0nk500 <b0nk@b0nk.xyz>2023-03-12 14:34:47 -0300
committermrb0nk500 <b0nk@b0nk.xyz>2023-03-12 14:35:47 -0300
commitd7336127af97ed86778796fb3a9cd203ce8b9306 (patch)
tree1215e2c555f6a3e18213daefae03a516c512241c
parent8a0ac8490951429277e707607975424b6dcd12b8 (diff)
TProtocol: Add, and match more command handlers, along with some other
functions needed to get them working
-rw-r--r--context.h29
-rw-r--r--include/pso/TProtocol.h12
-rw-r--r--include/pso/TSocket.h2
-rw-r--r--include/pso/TTcpSocket.h2
-rw-r--r--include/pso/packet_classes.h13
-rw-r--r--src/pso/TProtocol.cpp97
-rw-r--r--src/pso/TTcpSocket.cpp2
7 files changed, 151 insertions, 6 deletions
diff --git a/context.h b/context.h
index 2baecea..e82c1da 100644
--- a/context.h
+++ b/context.h
@@ -517,6 +517,8 @@ extern TTcpSocket *tcp_socket_table[16];
// pso/TProtocol.h
EXTERN_OBJECT_NAME(TProtocol);
+extern u32 new_ip_addr;
+extern u16 new_port;
extern TPlyMeetUserExtension meet_user_settings;
extern u32 game_variations[16][2];
@@ -1072,7 +1074,7 @@ public:
TSocket(TObject *parent);
virtual ~TSocket();
- virtual short open() = 0;
+ virtual int open() = 0;
virtual short close() = 0;
virtual void recv() = 0;
virtual short send(u8 *data) = 0;
@@ -1098,7 +1100,7 @@ public:
virtual ~TTcpSocket();
- virtual short open();
+ virtual int open();
virtual short close();
virtual void recv();
virtual short send(u8 *data);
@@ -1170,6 +1172,19 @@ public:
};
// pso/packet_classes.h
+class TRecvPort {
+public:
+ packet_header header;
+ u32 ip_addr;
+ short port;
+public:
+ void bswap() {
+ header.bswap();
+ bswap_32(&ip_addr);
+ bswap_16(as(u16 *, &port));
+ };
+};
+
class TPlyMeetUserExtension {
public:
TPlyGuildCardTag tags[8];
@@ -1394,6 +1409,7 @@ public:
void some_stub();
int handle_command(struct packet *pkt);
void parse_packet();
+ void seq_jump(u8 *some_struct, TPlyMeetUserExtension &extension);
// Command handlers.
// 0x01
@@ -1436,4 +1452,13 @@ public:
void recv_upload(packet &pkt);
// 0x11
void recv_message(packet &pkt);
+ // 0x19
+ void recv_port(packet &pkt);
+ // 0x1B
+ void recv_battle_data(packet &pkt);
+ // 0x1C
+ void recv_system_file(packet &pkt);
+
+ // Send command handlers.
+ int send_login3();
};
diff --git a/include/pso/TProtocol.h b/include/pso/TProtocol.h
index bcc7386..bc0f27f 100644
--- a/include/pso/TProtocol.h
+++ b/include/pso/TProtocol.h
@@ -19,6 +19,8 @@
#include <pso/TTcpSocket.h>
EXTERN_OBJECT_NAME(TProtocol);
+extern u32 new_ip_addr;
+extern u16 new_port;
extern TPlyMeetUserExtension meet_user_settings;
extern u32 game_variations[16][2];
extern void copy_packet(struct packet *pkt);
@@ -154,6 +156,7 @@ public:
void some_stub();
int handle_command(struct packet *pkt);
void parse_packet();
+ void seq_jump(u8 *some_struct, TPlyMeetUserExtension &extension);
// Command handlers.
// 0x01
@@ -196,6 +199,15 @@ public:
void recv_upload(packet &pkt);
// 0x11
void recv_message(packet &pkt);
+ // 0x19
+ void recv_port(packet &pkt);
+ // 0x1B
+ void recv_battle_data(packet &pkt);
+ // 0x1C
+ void recv_system_file(packet &pkt);
+
+ // Send command handlers.
+ int send_login3();
};
#endif
diff --git a/include/pso/TSocket.h b/include/pso/TSocket.h
index 66df9dc..9ffaf9f 100644
--- a/include/pso/TSocket.h
+++ b/include/pso/TSocket.h
@@ -38,7 +38,7 @@ public:
TSocket(TObject *parent);
virtual ~TSocket();
- virtual short open() = 0;
+ virtual int open() = 0;
virtual short close() = 0;
virtual void recv() = 0;
virtual short send(u8 *data) = 0;
diff --git a/include/pso/TTcpSocket.h b/include/pso/TTcpSocket.h
index 1be39a4..aef01b2 100644
--- a/include/pso/TTcpSocket.h
+++ b/include/pso/TTcpSocket.h
@@ -24,7 +24,7 @@ public:
virtual ~TTcpSocket();
- virtual short open();
+ virtual int open();
virtual short close();
virtual void recv();
virtual short send(u8 *data);
diff --git a/include/pso/packet_classes.h b/include/pso/packet_classes.h
index df47979..0764388 100644
--- a/include/pso/packet_classes.h
+++ b/include/pso/packet_classes.h
@@ -35,6 +35,19 @@ TMenuListEntry(QuestListEntry,
char short_description[112];
);
+class TRecvPort {
+public:
+ packet_header header;
+ u32 ip_addr;
+ short port;
+public:
+ void bswap() {
+ header.bswap();
+ bswap_32(&ip_addr);
+ bswap_16(as(u16 *, &port));
+ };
+};
+
class TPlyMeetUserExtension {
public:
TPlyGuildCardTag tags[8];
diff --git a/src/pso/TProtocol.cpp b/src/pso/TProtocol.cpp
index 19b2672..35d8a54 100644
--- a/src/pso/TProtocol.cpp
+++ b/src/pso/TProtocol.cpp
@@ -14,6 +14,8 @@
OBJECT_NAME(TProtocol);
packet *server_packet = nullptr;
+u32 new_ip_addr;
+u16 new_port;
TPlyMeetUserExtension meet_user_settings;
u32 game_variations[16][2];
@@ -21,6 +23,52 @@ void copy_packet(struct packet *pkt) {
}
+int TProtocol::send_login3() {
+ int ret;
+ set_ip_address(new_ip_addr);
+ set_port((short)new_port);
+
+ if (open() >= 0) {
+ // Return 0 if we successfully opened the socket.
+ // NOTE: Using a variable for the return value is needed to match.
+ ret = 0;
+ } else {
+ // Return 1 if we failed to open the socket.
+ // NOTE: This return here is needed to match.
+ return 1;
+ }
+ return ret;
+}
+
+void TProtocol::recv_system_file(packet &pkt) {};
+
+void TProtocol::recv_battle_data(packet &pkt) {
+ packet_header tmp = pkt.pkt.header;
+ tmp.bswap();
+};
+
+void TProtocol::seq_jump(u8 *some_struct, TPlyMeetUserExtension &extension) {
+ // TODO: Implement, and match this.
+}
+
+void TProtocol::recv_port(packet &pkt) {
+ TRecvPort tmp = as(TRecvPort &, pkt);
+ tmp.bswap();
+
+ new_ip_addr = tmp.ip_addr;
+ new_port = tmp.port;
+
+ close();
+ m_connected = false;
+ m_packet_offset = 0;
+ m_packet_size = 0;
+
+ // Did we fail to reconnect?
+ if (send_login3()) {
+ m_is_invalid_packet = true;
+ }
+};
+
void TProtocol::recv_message(packet &pkt) {
TMessageBox tmp = as(TMessageBox &, pkt);
tmp.bswap();
@@ -279,14 +327,61 @@ int TProtocol::handle_command(struct packet *pkt) {
{ 0x13, &recv_download },
{ 0x14, &recv_upload },
{ 0x11, &recv_message },
- { 0x1F, &recv_text_list },
+ // 0x18
+ // 0x17
+ { 0x19, &recv_port },
{ 0x1A, &recv_text },
+ { 0x1B, &recv_battle_data },
+ { 0x1C, &recv_system_file },
+ // 0x60
+ // 0x62
+ // 0x6C
+ // 0x6D
+ // 0x81
+ // 0x41
+ // 0x88
+ // 0x8A
+ // 0x80
{ 0x67, &recv_start_lobby2 },
+ // 0x83
+ // 0x1D
+ // 0x65
+ // 0x66
+ // 0x68
+ // 0x69
+ // 0x90
+ // 0x91
+ // 0x92
+ // 0x95
{ 0xA0, &recv_dir_list },
{ 0xA1, &recv_dir_list },
+ // 0xA2
+ // 0xA3
+ // 0xA4
+ // 0xA5
{ 0xA6, &recv_vm_download_head },
{ 0xA7, &recv_vm_download },
+ // 0x97
+ // 0xB0
+ { 0x1F, &recv_text_list },
+ // 0xB1
+ // 0xC0
+ // 0xC4
+ // 0xB2
+ // 0x02
+ // 0x9A
+ // 0x9B
+ // 0x9C
+ // 0xD1
+ // 0xD2
+ // 0xD3
{ 0xD5, &recv_text },
+ // 0xD7
+ // 0xD8
+ // 0xDA
+ // 0x9F
+ // 0xAB
+ // 0xAC
{ 0, nullptr }
};
for (int i = 0; !handlers[i].command; ++i) {
diff --git a/src/pso/TTcpSocket.cpp b/src/pso/TTcpSocket.cpp
index 2288bf1..19e692e 100644
--- a/src/pso/TTcpSocket.cpp
+++ b/src/pso/TTcpSocket.cpp
@@ -225,7 +225,7 @@ short TTcpSocket::close() {
return m_sock_fd;
}
-short TTcpSocket::open() {
+int TTcpSocket::open() {
m_sock_fd = -1;
m_is_encrypted = 0;
m_size = 0;