summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authormrb0nk500 <b0nk@b0nk.xyz>2023-02-26 19:20:47 -0400
committermrb0nk500 <b0nk@b0nk.xyz>2023-02-26 19:20:47 -0400
commit115fe1992e2c50fd108f7bc7cc31d7d2b1f5c6b8 (patch)
tree677098b566ba5beaac4b486943d6b8664d695315 /src
parent91a5937ef11f0503dde9d6f62e9d1f21e6f8a78f (diff)
TSocket: Start work on, and match most of `TSocket`
Still need to implement, and match `resolve_domain()`, but it's a good starting point for decompiling the netcode.
Diffstat (limited to 'src')
-rw-r--r--src/pso/TSocket.cpp59
1 files changed, 59 insertions, 0 deletions
diff --git a/src/pso/TSocket.cpp b/src/pso/TSocket.cpp
new file mode 100644
index 0000000..f9e954d
--- /dev/null
+++ b/src/pso/TSocket.cpp
@@ -0,0 +1,59 @@
+#include <global_types.h>
+#include <string.h>
+#include "pso/macros.h"
+#include "pso/TArray.h"
+#include "pso/TObject.h"
+#include "pso/TSocket.h"
+
+u16 bswap_word(u16 val);
+
+int TSocket::is_empty() {
+ if (all_parents_unqueued_for_destruction()) {
+ return !m_size;
+ } else {
+ return true;
+ }
+}
+
+const u8 TSocket::next() {
+ const u8 val = m_packet_buffer[m_buffer_offset++];
+ if (m_buffer_offset >= m_size) {
+ m_buffer_offset = 0;
+ m_size = 0;
+ }
+ return val;
+}
+
+void TSocket::set_port(u32 port) {
+ m_dst_port = bswap_word(port);
+}
+
+void TSocket::set_ip_address(u32 addr) {
+ m_dst_addr.addr_bytes.fast_copy_reverse<u32>(addr);
+}
+
+int TSocket::resolve_domain(char *domain) {
+ /* TODO: Implement, and match this. */
+ return 0;
+}
+
+TSocket::TSocket(TObject *parent) : TObject(parent) {
+ m_dst_addr.addr_bytes.fast_fill_with(0);
+ m_dst_port = 0;
+ m_src_port = 0;
+ m_sock_fd = -1;
+ m_sock_flags = 0;
+ m_size = 0;
+ m_buffer_offset = 0;
+ m_buffer_cleared = true;
+ m_callback = nullptr;
+}
+
+u16 bswap_word(u16 val) {
+ u8 *ptr = reinterpret_cast<u8 *>(&val);
+ return ptr[1] + (ptr[0] << 8);
+}
+
+TSocket::~TSocket() {
+
+}