From 1204e27adb502d039d2805467101fdf367a8ab4e Mon Sep 17 00:00:00 2001 From: Jack Garrard Date: Tue, 30 Aug 2022 15:18:44 -0700 Subject: [PATCH 01/50] Attempt at full udp client --- include/server/SocketClient.hpp | 3 ++ source/server/SocketClient.cpp | 77 ++++++++++++++++++++++++++++++--- 2 files changed, 74 insertions(+), 6 deletions(-) diff --git a/include/server/SocketClient.hpp b/include/server/SocketClient.hpp index 42dad30..3037009 100644 --- a/include/server/SocketClient.hpp +++ b/include/server/SocketClient.hpp @@ -34,6 +34,9 @@ class SocketClient : public SocketBase { private: int maxBufSize = 100; + s32 udp_socket; + + /** * @param str a string containing an IPv4 address or a hostname that can be resolved via DNS * @param out IPv4 address diff --git a/source/server/SocketClient.cpp b/source/server/SocketClient.cpp index 407ac98..6aefcb9 100644 --- a/source/server/SocketClient.cpp +++ b/source/server/SocketClient.cpp @@ -16,6 +16,7 @@ nn::Result SocketClient::init(const char* ip, u16 port) { in_addr hostAddress = { 0 }; sockaddr serverAddress = { 0 }; + sockaddr udpAddress = { 0 }; Logger::log("SocketClient::init: %s:%d sock %s\n", ip, port, getStateChar()); @@ -65,6 +66,33 @@ nn::Result SocketClient::init(const char* ip, u16 port) { return result; } + if ((this->udp_socket = nn::socket::Socket(2, 2, 17)) <= 0) { + Logger::log("Udp Socket failed to create"); + this->socket_errno = nn::socket::GetLastErrno(); + this->socket_log_state = SOCKET_LOG_UNAVAILABLE; + return -1; + } + + udpAddress.address = 0; + udpAddress.port = 0; + udpAddress.family = 2; + + if ((nn::socket::Bind(this->udp_socket, &udpAddress, sizeof(serverAddress))).isFailure()){ + Logger::log("Udp Socket failed to bind"); + this->socket_errno = nn::socket::GetLastErrno(); + this->socket_log_state = SOCKET_LOG_UNAVAILABLE; + return -1; + } + + if((result = nn::socket::Connect(this->udp_socket, &serverAddress, sizeof(serverAddress))).isFailure()) { + Logger::log("Udp Socket Connection Failed!\n"); + this->socket_errno = nn::socket::GetLastErrno(); + this->socket_log_state = SOCKET_LOG_UNAVAILABLE; + return result; + } + + + this->socket_log_state = SOCKET_LOG_CONNECTED; Logger::log("Socket fd: %d\n", socket_log_socket); @@ -82,10 +110,22 @@ bool SocketClient::SEND(Packet *packet) { int valread = 0; - if (packet->mType != PLAYERINF && packet->mType != HACKCAPINF) - Logger::log("Sending packet: %s\n", packetNames[packet->mType]); + if (packet->mType != PLAYERINF && packet->mType != HACKCAPINF) { + Logger::log("Sending packet: %s\n", packetNames[packet->mType]); + } else { - if ((valread = nn::socket::Send(this->socket_log_socket, buffer, packet->mPacketSize + sizeof(Packet), 0) > 0)) { + if ((valread = nn::socket::Send(this->udp_socket, buffer, packet->mPacketSize + sizeof(Packet), 0) > 0)) { + return true; + } else { + Logger::log("Failed to Fully Send Packet! Result: %d Type: %s Packet Size: %d\n", valread, packetNames[packet->mType], packet->mPacketSize); + this->socket_errno = nn::socket::GetLastErrno(); + this->closeSocket(); + return false; + } + } + + + if ((valread = nn::socket::Send(this->socket_log_socket, buffer, packet->mPacketSize + sizeof(Packet), 0) > 0)) { return true; } else { Logger::log("Failed to Fully Send Packet! Result: %d Type: %s Packet Size: %d\n", valread, packetNames[packet->mType], packet->mPacketSize); @@ -108,9 +148,34 @@ bool SocketClient::RECV() { char headerBuf[sizeof(Packet)] = {}; int valread = 0; + const int fd_count = 2; + struct pollfd pfds[fd_count] = {0}; + pfds[0].fd = this->socket_log_socket; + pfds[0].events = 1; + pfds[0].revents = 0; + pfds[1].fd = this->udp_socket; + pfds[1].events = 1; + pfds[1].revents = 0; + + + if (poll(pfds, fd_count, -1) <= 0) { + return true; + } + + s32 fd = -1; + for (int i = 0; i < fd_count; i++){ + if (pfds[i].revents & 1) { + fd = pfds[i].fd; + } + } + + if (fd == -1) { + return true; + } + // read only the size of a header while(valread < headerSize) { - int result = nn::socket::Recv(this->socket_log_socket, headerBuf + valread, + int result = nn::socket::Recv(fd, headerBuf + valread, headerSize - valread, this->sock_flags); this->socket_errno = nn::socket::GetLastErrno(); @@ -155,10 +220,10 @@ bool SocketClient::RECV() { while (valread < fullSize) { - int result = nn::socket::Recv(this->socket_log_socket, packetBuf + valread, + int result = nn::socket::Recv(fd, packetBuf + valread, fullSize - valread, this->sock_flags); - this->socket_errno = nn::socket::GetLastErrno(); + this->socket_errno = nn::socket::GetLastErrno();revents if (result > 0) { valread += result; From 19c6d800bd8af2305467447ccec95beea8e02b16 Mon Sep 17 00:00:00 2001 From: Jack Garrard Date: Sat, 3 Sep 2022 01:57:57 -0700 Subject: [PATCH 02/50] More changes while testing --- include/nn/socket.h | 5 ++++ include/packets/Packet.h | 5 +++- include/packets/UdpPacket.h | 8 ++++++ include/server/SocketClient.hpp | 4 ++- source/server/Client.cpp | 8 +++++- source/server/SocketClient.cpp | 49 +++++++++++++++++++-------------- 6 files changed, 55 insertions(+), 24 deletions(-) create mode 100644 include/packets/UdpPacket.h diff --git a/include/nn/socket.h b/include/nn/socket.h index 3e8290b..c07732a 100644 --- a/include/nn/socket.h +++ b/include/nn/socket.h @@ -38,13 +38,18 @@ s32 Connect(s32 socket, const sockaddr* address, u32 addressLen); Result Close(s32 socket); s32 Send(s32 socket, const void* data, ulong dataLen, s32 flags); +s32 SendTo(s32 socket, const void* data, ulong dataLen, s32 flags, const struct sockaddr* to, u32 toLen); s32 Recv(s32 socket, void* out, ulong outLen, s32 flags); +s32 RecvFrom(s32 socket, void* out, ulong outLen, s32 flags, struct sockaddr* from, u32* fromLen); +s32 GetSockName(s32 socket, struct sockaddr* name, u32 dataLen); u16 InetHtons(u16 val); s32 InetAton(const char* addressStr, in_addr* addressOut); struct hostent* GetHostByName(const char* name); u32 GetLastErrno(); +s32 Bind(s32 fd, sockaddr* addr, u32 addrlen); +s32 Poll(struct pollfd* fd, u64 addr, s32 timeout); } } diff --git a/include/packets/Packet.h b/include/packets/Packet.h index 400ee46..b312da5 100644 --- a/include/packets/Packet.h +++ b/include/packets/Packet.h @@ -26,6 +26,7 @@ enum PacketType : short { CAPTUREINF, CHANGESTAGE, CMD, + UDPINIT, End // end of enum for bounds checking }; @@ -44,6 +45,7 @@ USED static const char *packetNames[] = { "Capture Info", "Change Stage", "Server Command" + "Udp Initialization" }; enum SenderType { @@ -83,4 +85,5 @@ struct PACKED Packet { #include "packets/CaptureInf.h" #include "packets/HackCapInf.h" #include "packets/ChangeStagePacket.h" -#include "packets/InitPacket.h" \ No newline at end of file +#include "packets/InitPacket.h" +#include "packets/UdpPacket.h" diff --git a/include/packets/UdpPacket.h b/include/packets/UdpPacket.h new file mode 100644 index 0000000..b4c4b37 --- /dev/null +++ b/include/packets/UdpPacket.h @@ -0,0 +1,8 @@ +#pragma once + +#include "Packet.h" + +struct PACKED UdpInit : Packet { + UdpInit() : Packet() {this->mType = PacketType::UDPINIT; mPacketSize = sizeof(UdpInit) - sizeof(Packet);}; + u16 port = 0; +}; diff --git a/include/server/SocketClient.hpp b/include/server/SocketClient.hpp index 3037009..bd68919 100644 --- a/include/server/SocketClient.hpp +++ b/include/server/SocketClient.hpp @@ -28,13 +28,15 @@ class SocketClient : public SocketBase { bool RECV(); void printPacket(Packet* packet); bool isConnected() {return socket_log_state == SOCKET_LOG_CONNECTED; } + u16 getUdpPort(); sead::PtrArray mPacketQueue; private: int maxBufSize = 100; - s32 udp_socket; + s32 udp_socket; + sockaddr udp_addr; /** diff --git a/source/server/Client.cpp b/source/server/Client.cpp index bd5dc6c..d68b2aa 100644 --- a/source/server/Client.cpp +++ b/source/server/Client.cpp @@ -243,6 +243,8 @@ bool Client::startConnection() { waitingForInitPacket = false; } } + + } return mIsConnectionActive; @@ -370,7 +372,11 @@ void Client::readFunc() { } mSocket->SEND(&initPacket); // send initial packet - + + UdpInit udp_init = UdpInit(); + udp_init.port = mSocket->getUdpPort(); + mSocket->SEND(&udp_init) + nn::os::SleepThread(nn::TimeSpan::FromNanoSeconds(500000000)); // sleep for 0.5 seconds to let connection layout fully show (probably should find a better way to do this) mConnectionWait->tryEnd(); diff --git a/source/server/SocketClient.cpp b/source/server/SocketClient.cpp index 6aefcb9..bd0da88 100644 --- a/source/server/SocketClient.cpp +++ b/source/server/SocketClient.cpp @@ -7,6 +7,7 @@ #include "nn/result.h" #include "nn/socket.h" #include "packets/Packet.h" +#include "packets/UdpPacket.h" #include "types.h" nn::Result SocketClient::init(const char* ip, u16 port) { @@ -73,25 +74,10 @@ nn::Result SocketClient::init(const char* ip, u16 port) { return -1; } - udpAddress.address = 0; - udpAddress.port = 0; + udpAddress.address = hostAddress; + udpAddress.port = nn::socket::InetHtons(41553); udpAddress.family = 2; - - if ((nn::socket::Bind(this->udp_socket, &udpAddress, sizeof(serverAddress))).isFailure()){ - Logger::log("Udp Socket failed to bind"); - this->socket_errno = nn::socket::GetLastErrno(); - this->socket_log_state = SOCKET_LOG_UNAVAILABLE; - return -1; - } - - if((result = nn::socket::Connect(this->udp_socket, &serverAddress, sizeof(serverAddress))).isFailure()) { - Logger::log("Udp Socket Connection Failed!\n"); - this->socket_errno = nn::socket::GetLastErrno(); - this->socket_log_state = SOCKET_LOG_UNAVAILABLE; - return result; - } - - + this->udp_addr = udpAddress; this->socket_log_state = SOCKET_LOG_CONNECTED; @@ -101,6 +87,15 @@ nn::Result SocketClient::init(const char* ip, u16 port) { } +u16 SocketClient::getUdpPort() { + sockaddr udpAddress = { 0 }; + if (nn::socket::GetSockName(this->udp_socket, &udpAddress, sizeof(udpAddress)) <= 0) { + return 0; + } + + return udpAddress.port; +} + bool SocketClient::SEND(Packet *packet) { if (this->socket_log_state != SOCKET_LOG_CONNECTED) @@ -114,7 +109,7 @@ bool SocketClient::SEND(Packet *packet) { Logger::log("Sending packet: %s\n", packetNames[packet->mType]); } else { - if ((valread = nn::socket::Send(this->udp_socket, buffer, packet->mPacketSize + sizeof(Packet), 0) > 0)) { + if ((valread = nn::socket::SendTo(this->udp_socket, buffer, packet->mPacketSize + sizeof(Packet), 0, this->udp_addr, sizeof(this->udp_addr)) > 0)) { return true; } else { Logger::log("Failed to Fully Send Packet! Result: %d Type: %s Packet Size: %d\n", valread, packetNames[packet->mType], packet->mPacketSize); @@ -163,20 +158,32 @@ bool SocketClient::RECV() { } s32 fd = -1; + s32 index = -1; for (int i = 0; i < fd_count; i++){ if (pfds[i].revents & 1) { fd = pfds[i].fd; + index = i; } } if (fd == -1) { return true; } + sockaddr udp_addr = {0}; + u32 udp_size = 0; // read only the size of a header while(valread < headerSize) { - int result = nn::socket::Recv(fd, headerBuf + valread, - headerSize - valread, this->sock_flags); + int result = 0; + if (index == 0) { + result = nn::socket::Recv(fd, headerBuf + valread, + headerSize - valread, this->sock_flags); + } else { + result = nn::socket::RecvFrom(fd, headerBuf + valread, + headerSize - valread, this->sock_flags, + &udp_addr, &udp_size); + Logger::log("Got udp packet: %s %s %s\n",udp_addr.family, udp_addr.port, udp_addr.address.data); + } this->socket_errno = nn::socket::GetLastErrno(); From 66c8bb9e1bfd3ed83f7b0f5f0891f75d6510de32 Mon Sep 17 00:00:00 2001 From: Jack Garrard Date: Mon, 5 Sep 2022 03:19:33 -0700 Subject: [PATCH 03/50] Closer to working --- include/nn/socket.h | 3 +- include/packets/HolePunchPacket.h | 7 ++ include/packets/Packet.h | 7 +- include/server/SocketClient.hpp | 2 + source/server/Client.cpp | 17 +++-- source/server/SocketClient.cpp | 114 +++++++++++++++++++++--------- 6 files changed, 111 insertions(+), 39 deletions(-) create mode 100644 include/packets/HolePunchPacket.h diff --git a/include/nn/socket.h b/include/nn/socket.h index c07732a..0ed1c7c 100644 --- a/include/nn/socket.h +++ b/include/nn/socket.h @@ -42,8 +42,9 @@ s32 SendTo(s32 socket, const void* data, ulong dataLen, s32 flags, const struct s32 Recv(s32 socket, void* out, ulong outLen, s32 flags); s32 RecvFrom(s32 socket, void* out, ulong outLen, s32 flags, struct sockaddr* from, u32* fromLen); -s32 GetSockName(s32 socket, struct sockaddr* name, u32 dataLen); +s32 GetSockName(s32 socket, struct sockaddr* name, u32* dataLen); u16 InetHtons(u16 val); +u16 InetNtohs(u16 val); s32 InetAton(const char* addressStr, in_addr* addressOut); struct hostent* GetHostByName(const char* name); diff --git a/include/packets/HolePunchPacket.h b/include/packets/HolePunchPacket.h new file mode 100644 index 0000000..28380f0 --- /dev/null +++ b/include/packets/HolePunchPacket.h @@ -0,0 +1,7 @@ +#pragma once + +#include "Packet.h" + +struct PACKED HolePunch : Packet { + HolePunch() : Packet() {this->mType = PacketType::HOLEPUNCH; mPacketSize = sizeof(HolePunch) - sizeof(Packet);}; +}; diff --git a/include/packets/Packet.h b/include/packets/Packet.h index b312da5..92fb053 100644 --- a/include/packets/Packet.h +++ b/include/packets/Packet.h @@ -27,6 +27,7 @@ enum PacketType : short { CHANGESTAGE, CMD, UDPINIT, + HOLEPUNCH, End // end of enum for bounds checking }; @@ -44,8 +45,9 @@ USED static const char *packetNames[] = { "Moon Collection", "Capture Info", "Change Stage", - "Server Command" - "Udp Initialization" + "Server Command", + "Udp Initialization", + "Hole punch", }; enum SenderType { @@ -87,3 +89,4 @@ struct PACKED Packet { #include "packets/ChangeStagePacket.h" #include "packets/InitPacket.h" #include "packets/UdpPacket.h" +#include "packets/HolePunchPacket.h" diff --git a/include/server/SocketClient.hpp b/include/server/SocketClient.hpp index bd68919..34a2449 100644 --- a/include/server/SocketClient.hpp +++ b/include/server/SocketClient.hpp @@ -29,6 +29,8 @@ class SocketClient : public SocketBase { void printPacket(Packet* packet); bool isConnected() {return socket_log_state == SOCKET_LOG_CONNECTED; } u16 getUdpPort(); + s32 setPeerUdpPort(u16 port); + sead::PtrArray mPacketQueue; diff --git a/source/server/Client.cpp b/source/server/Client.cpp index d68b2aa..e88370c 100644 --- a/source/server/Client.cpp +++ b/source/server/Client.cpp @@ -373,10 +373,6 @@ void Client::readFunc() { mSocket->SEND(&initPacket); // send initial packet - UdpInit udp_init = UdpInit(); - udp_init.port = mSocket->getUdpPort(); - mSocket->SEND(&udp_init) - nn::os::SleepThread(nn::TimeSpan::FromNanoSeconds(500000000)); // sleep for 0.5 seconds to let connection layout fully show (probably should find a better way to do this) mConnectionWait->tryEnd(); @@ -480,6 +476,19 @@ void Client::readFunc() { maxPuppets = initPacket->maxPlayers - 1; break; } + case PacketType::UDPINIT: { + UdpInit* udpInit = (UdpInit*)curPacket; + Logger::log("Setting udp port %u\n", udpInit->port); + this->mSocket->setPeerUdpPort(udpInit->port); + + HolePunch punch = HolePunch(); + this->mSocket->SEND(&punch); + + UdpInit udp_init = UdpInit(); + udp_init.port = mSocket->getUdpPort(); + mSocket->SEND(&udp_init); + break; + } default: break; } diff --git a/source/server/SocketClient.cpp b/source/server/SocketClient.cpp index bd0da88..1de20fb 100644 --- a/source/server/SocketClient.cpp +++ b/source/server/SocketClient.cpp @@ -67,17 +67,27 @@ nn::Result SocketClient::init(const char* ip, u16 port) { return result; } - if ((this->udp_socket = nn::socket::Socket(2, 2, 17)) <= 0) { + if ((this->udp_socket = nn::socket::Socket(2, 2, 17)) < 0) { Logger::log("Udp Socket failed to create"); this->socket_errno = nn::socket::GetLastErrno(); this->socket_log_state = SOCKET_LOG_UNAVAILABLE; return -1; } - udpAddress.address = hostAddress; udpAddress.port = nn::socket::InetHtons(41553); udpAddress.family = 2; - this->udp_addr = udpAddress; + this->udp_addr = udpAddress; + + udpAddress.address = hostAddress; + udpAddress.port = nn::socket::InetHtons(57734); + udpAddress.family = 2; + + if((result = nn::socket::Connect(this->udp_socket, &udpAddress, sizeof(udpAddress))).isFailure()) { + Logger::log("Udp Socket Connection Failed!\n"); + this->socket_errno = nn::socket::GetLastErrno(); + this->socket_log_state = SOCKET_LOG_UNAVAILABLE; + return result; + } this->socket_log_state = SOCKET_LOG_CONNECTED; @@ -88,12 +98,33 @@ nn::Result SocketClient::init(const char* ip, u16 port) { } u16 SocketClient::getUdpPort() { - sockaddr udpAddress = { 0 }; - if (nn::socket::GetSockName(this->udp_socket, &udpAddress, sizeof(udpAddress)) <= 0) { - return 0; - } + sockaddr udpAddress = { 0 }; + u32 size = sizeof(udpAddress); + + nn::Result result; + if((result = nn::socket::GetSockName(this->udp_socket, &udpAddress, &size)).isFailure()) { + this->socket_errno = nn::socket::GetLastErrno(); + return 0; + } + + return nn::socket::InetNtohs(udpAddress.port); +} + + +s32 SocketClient::setPeerUdpPort(u16 port) { + u16 net_port = nn::socket::InetHtons(port); + this->udp_addr.port = net_port; + + nn::Result result; + if((result = nn::socket::Connect(this->udp_socket, &this->udp_addr, sizeof(this->udp_addr))).isFailure()) { + Logger::log("Udp Socket Connection Failed!\n"); + this->socket_errno = nn::socket::GetLastErrno(); + this->socket_log_state = SOCKET_LOG_UNAVAILABLE; + return -1; + } + + return 0; - return udpAddress.port; } bool SocketClient::SEND(Packet *packet) { @@ -105,22 +136,17 @@ bool SocketClient::SEND(Packet *packet) { int valread = 0; - if (packet->mType != PLAYERINF && packet->mType != HACKCAPINF) { + int fd = -1; + if (packet->mType != PLAYERINF && packet->mType != HACKCAPINF && packet->mType != HOLEPUNCH) { Logger::log("Sending packet: %s\n", packetNames[packet->mType]); + fd = this->socket_log_socket; } else { - if ((valread = nn::socket::SendTo(this->udp_socket, buffer, packet->mPacketSize + sizeof(Packet), 0, this->udp_addr, sizeof(this->udp_addr)) > 0)) { - return true; - } else { - Logger::log("Failed to Fully Send Packet! Result: %d Type: %s Packet Size: %d\n", valread, packetNames[packet->mType], packet->mPacketSize); - this->socket_errno = nn::socket::GetLastErrno(); - this->closeSocket(); - return false; - } + fd = this->udp_socket; } - if ((valread = nn::socket::Send(this->socket_log_socket, buffer, packet->mPacketSize + sizeof(Packet), 0) > 0)) { + if ((valread = nn::socket::Send(fd, buffer, packet->mPacketSize + sizeof(Packet), 0) > 0)) { return true; } else { Logger::log("Failed to Fully Send Packet! Result: %d Type: %s Packet Size: %d\n", valread, packetNames[packet->mType], packet->mPacketSize); @@ -140,11 +166,11 @@ bool SocketClient::RECV() { } int headerSize = sizeof(Packet); - char headerBuf[sizeof(Packet)] = {}; + char headerBuf[MAXPACKSIZE * 2] = {}; int valread = 0; const int fd_count = 2; - struct pollfd pfds[fd_count] = {0}; + struct pollfd pfds[fd_count] = {{0}, {0}}; pfds[0].fd = this->socket_log_socket; pfds[0].events = 1; pfds[0].revents = 0; @@ -153,7 +179,7 @@ bool SocketClient::RECV() { pfds[1].revents = 0; - if (poll(pfds, fd_count, -1) <= 0) { + if (nn::socket::Poll(pfds, fd_count, -1) <= 0) { return true; } @@ -169,21 +195,45 @@ bool SocketClient::RECV() { if (fd == -1) { return true; } - sockaddr udp_addr = {0}; - u32 udp_size = 0; +if (index == 1) { + int result = nn::socket::Recv(fd, headerBuf, sizeof(headerBuf), this->sock_flags); + if (result < headerSize){ + return true; + } + + Packet* header = reinterpret_cast(headerBuf); + int fullSize = header->mPacketSize + sizeof(Packet); + + if (result < fullSize || result > MAXPACKSIZE || fullSize > MAXPACKSIZE){ + return true; + } + + char* packetBuf = (char*)malloc(fullSize); + + if (!(header->mType > PacketType::UNKNOWN && header->mType < PacketType::End)) { + Logger::log("Failed to acquire valid packet type! Packet Type: %d Full Packet Size %d valread size: %d", header->mType, fullSize, result); + free(packetBuf); + return true; + } + + memcpy(packetBuf, headerBuf, fullSize); + + + Packet *packet = reinterpret_cast(packetBuf); + + if(mPacketQueue.size() < maxBufSize - 1) { + mPacketQueue.pushBack(packet); + } else { + free(packetBuf); + } + return true; + } // read only the size of a header while(valread < headerSize) { int result = 0; - if (index == 0) { - result = nn::socket::Recv(fd, headerBuf + valread, - headerSize - valread, this->sock_flags); - } else { - result = nn::socket::RecvFrom(fd, headerBuf + valread, - headerSize - valread, this->sock_flags, - &udp_addr, &udp_size); - Logger::log("Got udp packet: %s %s %s\n",udp_addr.family, udp_addr.port, udp_addr.address.data); - } + result = nn::socket::Recv(fd, headerBuf + valread, + headerSize - valread, this->sock_flags); this->socket_errno = nn::socket::GetLastErrno(); From f417d39f3b514bb09b868c3db06b616c30e3b368 Mon Sep 17 00:00:00 2001 From: Jack Garrard Date: Mon, 5 Sep 2022 03:26:01 -0700 Subject: [PATCH 04/50] Comment out extra udpaddress --- source/server/SocketClient.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/source/server/SocketClient.cpp b/source/server/SocketClient.cpp index 1de20fb..2f6dae2 100644 --- a/source/server/SocketClient.cpp +++ b/source/server/SocketClient.cpp @@ -73,14 +73,15 @@ nn::Result SocketClient::init(const char* ip, u16 port) { this->socket_log_state = SOCKET_LOG_UNAVAILABLE; return -1; } + udpAddress.address = hostAddress; udpAddress.port = nn::socket::InetHtons(41553); udpAddress.family = 2; this->udp_addr = udpAddress; - udpAddress.address = hostAddress; - udpAddress.port = nn::socket::InetHtons(57734); - udpAddress.family = 2; + // udpAddress.address = hostAddress; + // udpAddress.port = nn::socket::InetHtons(57734); + // udpAddress.family = 2; if((result = nn::socket::Connect(this->udp_socket, &udpAddress, sizeof(udpAddress))).isFailure()) { Logger::log("Udp Socket Connection Failed!\n"); From 009755ceba08086e17a0c7d17ccb3cba8379ea5e Mon Sep 17 00:00:00 2001 From: Jack Garrard Date: Mon, 5 Sep 2022 03:26:14 -0700 Subject: [PATCH 05/50] Add pollfd to socket.h --- include/nn/socket.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/include/nn/socket.h b/include/nn/socket.h index 0ed1c7c..592c1bf 100644 --- a/include/nn/socket.h +++ b/include/nn/socket.h @@ -2,6 +2,12 @@ #include "../types.h" +struct pollfd +{ + s32 fd; + s16 events; + s16 revents; +}; struct in_addr { From b163749c777670cfb019fafd51430e94e500d890 Mon Sep 17 00:00:00 2001 From: Jack Garrard Date: Mon, 5 Sep 2022 03:28:27 -0700 Subject: [PATCH 06/50] Remove extra word --- source/server/SocketClient.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/server/SocketClient.cpp b/source/server/SocketClient.cpp index 2f6dae2..0a1f5ba 100644 --- a/source/server/SocketClient.cpp +++ b/source/server/SocketClient.cpp @@ -281,7 +281,7 @@ if (index == 1) { int result = nn::socket::Recv(fd, packetBuf + valread, fullSize - valread, this->sock_flags); - this->socket_errno = nn::socket::GetLastErrno();revents + this->socket_errno = nn::socket::GetLastErrno(); if (result > 0) { valread += result; From 2f5ed106fae955dd3cdcb8f40f5ac23eda3549b5 Mon Sep 17 00:00:00 2001 From: Jack Garrard Date: Mon, 5 Sep 2022 12:44:54 -0700 Subject: [PATCH 07/50] Hopefully fix emulators --- source/server/SocketClient.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/server/SocketClient.cpp b/source/server/SocketClient.cpp index 0a1f5ba..a330b68 100644 --- a/source/server/SocketClient.cpp +++ b/source/server/SocketClient.cpp @@ -180,7 +180,7 @@ bool SocketClient::RECV() { pfds[1].revents = 0; - if (nn::socket::Poll(pfds, fd_count, -1) <= 0) { + if (nn::socket::Poll(pfds, fd_count, 0) <= 0) { return true; } From 1fd02147b650e9de8725bce43fc7156bdb4eac02 Mon Sep 17 00:00:00 2001 From: Jack Garrard Date: Fri, 21 Oct 2022 12:27:01 -0700 Subject: [PATCH 08/50] Add a flag to only send udp if client has received udp packets --- include/server/SocketClient.hpp | 1 + source/server/SocketClient.cpp | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/include/server/SocketClient.hpp b/include/server/SocketClient.hpp index 34a2449..91fb96b 100644 --- a/include/server/SocketClient.hpp +++ b/include/server/SocketClient.hpp @@ -37,6 +37,7 @@ class SocketClient : public SocketBase { private: int maxBufSize = 100; + bool has_recv_udp; s32 udp_socket; sockaddr udp_addr; diff --git a/source/server/SocketClient.cpp b/source/server/SocketClient.cpp index a330b68..d782d04 100644 --- a/source/server/SocketClient.cpp +++ b/source/server/SocketClient.cpp @@ -138,7 +138,7 @@ bool SocketClient::SEND(Packet *packet) { int valread = 0; int fd = -1; - if (packet->mType != PLAYERINF && packet->mType != HACKCAPINF && packet->mType != HOLEPUNCH) { + if ((packet->mType != PLAYERINF && packet->mType != HACKCAPINF && packet->mType != HOLEPUNCH) || !this->has_recv_udp) { Logger::log("Sending packet: %s\n", packetNames[packet->mType]); fd = this->socket_log_socket; } else { @@ -196,7 +196,8 @@ bool SocketClient::RECV() { if (fd == -1) { return true; } -if (index == 1) { + + if (index == 1) { int result = nn::socket::Recv(fd, headerBuf, sizeof(headerBuf), this->sock_flags); if (result < headerSize){ return true; @@ -224,6 +225,7 @@ if (index == 1) { if(mPacketQueue.size() < maxBufSize - 1) { mPacketQueue.pushBack(packet); + this->has_recv_udp = true; } else { free(packetBuf); } From ba7612a304dd3bd269ecc61c10cac4196265e643 Mon Sep 17 00:00:00 2001 From: Jack Garrard Date: Fri, 21 Oct 2022 12:57:40 -0700 Subject: [PATCH 09/50] Fix a changed variable --- source/server/SocketClient.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/server/SocketClient.cpp b/source/server/SocketClient.cpp index b1f7f94..2bac52f 100644 --- a/source/server/SocketClient.cpp +++ b/source/server/SocketClient.cpp @@ -253,8 +253,8 @@ bool SocketClient::recv() { Packet *packet = reinterpret_cast(packetBuf); - if(mPacketQueue.size() < maxBufSize - 1) { - mPacketQueue.pushBack(packet); + if(!mRecvQueue.isFull()) { + mRecvQueue.push((s64)packet, sead::MessageQueue::BlockType::NonBlocking); this->has_recv_udp = true; } else { free(packetBuf); From 694c9e73d6dcefab43538a62a386ee75dced8e51 Mon Sep 17 00:00:00 2001 From: Jack Garrard Date: Sun, 23 Oct 2022 16:37:47 -0700 Subject: [PATCH 10/50] Allow for a udp handshake --- include/server/Client.hpp | 2 ++ include/server/SocketClient.hpp | 2 +- source/server/Client.cpp | 51 +++++++++++++++++++++++++++++++++ source/server/SocketClient.cpp | 35 +++++++++++----------- 4 files changed, 71 insertions(+), 19 deletions(-) diff --git a/include/server/Client.hpp b/include/server/Client.hpp index 16a2ca2..51edd92 100644 --- a/include/server/Client.hpp +++ b/include/server/Client.hpp @@ -197,6 +197,8 @@ class Client { void updateTagInfo(TagInf *packet); void updateCaptureInfo(CaptureInf* packet); void sendToStage(ChangeStagePacket* packet); + void sendUdpHolePunch(); + void sendUdpInit(); void disconnectPlayer(PlayerDC *packet); PuppetInfo* findPuppetInfo(const nn::account::Uid& id, bool isFindAvailable); diff --git a/include/server/SocketClient.hpp b/include/server/SocketClient.hpp index b579cd5..47ec8a6 100644 --- a/include/server/SocketClient.hpp +++ b/include/server/SocketClient.hpp @@ -44,7 +44,7 @@ class SocketClient : public SocketBase { void printPacket(Packet* packet); bool isConnected() { return socket_log_state == SOCKET_LOG_CONNECTED; } - u16 getUdpPort(); + u16 getLocalUdpPort(); s32 setPeerUdpPort(u16 port); u32 getSendCount() { return mSendQueue.getCount(); } diff --git a/source/server/Client.cpp b/source/server/Client.cpp index e2a3df4..418b092 100644 --- a/source/server/Client.cpp +++ b/source/server/Client.cpp @@ -383,6 +383,19 @@ void Client::readFunc() { maxPuppets = initPacket->maxPlayers - 1; break; } + case PacketType::UDPINIT: { + UdpInit* initPacket = (UdpInit*)curPacket; + Logger::log("Received udp init packet from server"); + + sInstance->mSocket->setPeerUdpPort(initPacket->port); + sendUdpHolePunch(); + sendUdpInit(); + + break; + } + case PacketType::HOLEPUNCH: + sendUdpHolePunch(); + break; default: Logger::log("Discarding Unknown Packet Type.\n"); break; @@ -939,7 +952,45 @@ void Client::sendToStage(ChangeStagePacket* packet) { GameDataFunction::tryChangeNextStage(accessor, &info); } } +/** + * @brief + * Send a udp holepunch packet to the server + */ +void Client::sendUdpHolePunch() { + if (!sInstance) { + Logger::log("Static Instance is Null!\n"); + return; + } + + sead::ScopedCurrentHeapSetter setter(sInstance->mHeap); + + HolePunch *packet = new HolePunch(); + + packet->mUserID = sInstance->mUserID; + + sInstance->mSocket->queuePacket(packet); +} +/** + * @brief + * Send a udp init packet to server + */ +void Client::sendUdpInit() { + + if (!sInstance) { + Logger::log("Static Instance is Null!\n"); + return; + } + + sead::ScopedCurrentHeapSetter setter(sInstance->mHeap); + + UdpInit *packet = new UdpInit(); + + packet->mUserID = sInstance->mUserID; + packet->port = sInstance->mSocket->getLocalUdpPort(); + + sInstance->mSocket->queuePacket(packet); +} /** * @brief * diff --git a/source/server/SocketClient.cpp b/source/server/SocketClient.cpp index 0091cbd..8ceffec 100644 --- a/source/server/SocketClient.cpp +++ b/source/server/SocketClient.cpp @@ -91,10 +91,7 @@ nn::Result SocketClient::init(const char* ip, u16 port) { udpAddress.port = nn::socket::InetHtons(41553); udpAddress.family = 2; this->udp_addr = udpAddress; - - // udpAddress.address = hostAddress; - // udpAddress.port = nn::socket::InetHtons(57734); - // udpAddress.family = 2; + this->has_recv_udp = false; if((result = nn::socket::Connect(this->udp_socket, &udpAddress, sizeof(udpAddress))).isFailure()) { Logger::log("Udp Socket Connection Failed!\n"); @@ -128,7 +125,7 @@ nn::Result SocketClient::init(const char* ip, u16 port) { } -u16 SocketClient::getUdpPort() { +u16 SocketClient::getLocalUdpPort() { sockaddr udpAddress = { 0 }; u32 size = sizeof(udpAddress); @@ -235,30 +232,32 @@ bool SocketClient::recv() { Packet* header = reinterpret_cast(headerBuf); int fullSize = header->mPacketSize + sizeof(Packet); - + // Verify packet size is appropriate if (result < fullSize || result > MAXPACKSIZE || fullSize > MAXPACKSIZE){ return true; } - - char* packetBuf = (char*)malloc(fullSize); - + + // Verify type of packet if (!(header->mType > PacketType::UNKNOWN && header->mType < PacketType::End)) { Logger::log("Failed to acquire valid packet type! Packet Type: %d Full Packet Size %d valread size: %d", header->mType, fullSize, result); - free(packetBuf); return true; } - memcpy(packetBuf, headerBuf, fullSize); + this->has_recv_udp = true; + + char* packetBuf = (char*)mHeap->alloc(fullSize); + if (packetBuf){ + memcpy(packetBuf, headerBuf, fullSize); - Packet *packet = reinterpret_cast(packetBuf); + Packet *packet = reinterpret_cast(packetBuf); - if(!mRecvQueue.isFull()) { - mRecvQueue.push((s64)packet, sead::MessageQueue::BlockType::NonBlocking); - this->has_recv_udp = true; - } else { - free(packetBuf); - } + if(!mRecvQueue.isFull()) { + mRecvQueue.push((s64)packet, sead::MessageQueue::BlockType::NonBlocking); + } else { + mHeap->free(packetBuf); + } + } return true; } From 2654650804f6ed71717cb9eff352fa216883b667 Mon Sep 17 00:00:00 2001 From: Jack Garrard Date: Sun, 23 Oct 2022 17:52:34 -0700 Subject: [PATCH 11/50] Reset recv udp flag on connection close --- source/server/SocketClient.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/source/server/SocketClient.cpp b/source/server/SocketClient.cpp index 8ceffec..867df48 100644 --- a/source/server/SocketClient.cpp +++ b/source/server/SocketClient.cpp @@ -381,6 +381,7 @@ bool SocketClient::closeSocket() { Logger::log("Closing Socket.\n"); + has_recv_udp = false; bool result = false; if (!(result = SocketBase::closeSocket())) { From ed83827cc12dfdbe9554af1e61f238a25e329106 Mon Sep 17 00:00:00 2001 From: Jack Garrard Date: Sun, 23 Oct 2022 18:37:08 -0700 Subject: [PATCH 12/50] Add udp status to debug menu --- include/server/SocketClient.hpp | 1 + source/main.cpp | 1 + source/server/SocketClient.cpp | 13 ++++++++++++- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/include/server/SocketClient.hpp b/include/server/SocketClient.hpp index 47ec8a6..53d9b34 100644 --- a/include/server/SocketClient.hpp +++ b/include/server/SocketClient.hpp @@ -46,6 +46,7 @@ class SocketClient : public SocketBase { u16 getLocalUdpPort(); s32 setPeerUdpPort(u16 port); + const char* getUdpStateChar(); u32 getSendCount() { return mSendQueue.getCount(); } u32 getSendMaxCount() { return mSendQueue.getMaxCount(); } diff --git a/source/main.cpp b/source/main.cpp index 39f2810..2ab620f 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -118,6 +118,7 @@ void drawMainHook(HakoniwaSequence *curSequence, sead::Viewport *viewport, sead: } gTextWriter->printf("Client Socket Connection Status: %s\n", Client::instance()->mSocket->getStateChar()); + gTextWriter->printf("Udp socket status: %s\n", Client::instance()->mSocket->getUdpStateChar()); //gTextWriter->printf("nn::socket::GetLastErrno: 0x%x\n", Client::instance()->mSocket->socket_errno); gTextWriter->printf("Connected Players: %d/%d\n", Client::getConnectCount() + 1, Client::getMaxPlayerCount()); diff --git a/source/server/SocketClient.cpp b/source/server/SocketClient.cpp index 867df48..5a5f51c 100644 --- a/source/server/SocketClient.cpp +++ b/source/server/SocketClient.cpp @@ -88,7 +88,7 @@ nn::Result SocketClient::init(const char* ip, u16 port) { } udpAddress.address = hostAddress; - udpAddress.port = nn::socket::InetHtons(41553); + udpAddress.port = nn::socket::InetHtons(0); udpAddress.family = 2; this->udp_addr = udpAddress; this->has_recv_udp = false; @@ -155,6 +155,17 @@ s32 SocketClient::setPeerUdpPort(u16 port) { } +const char* SocketClient::getUdpStateChar() { + if (this->udp_addr.port == 0) { + return "Waiting for handshake"; + } + + if (!this->has_recv_udp) { + return "Waiting for holepunch"; + } + + return "Utilizing UDP"; +} bool SocketClient::send(Packet *packet) { if (this->socket_log_state != SOCKET_LOG_CONNECTED) From 655368241fc835fae5d0fcefaf42fe168f2c328d Mon Sep 17 00:00:00 2001 From: Jack Garrard Date: Tue, 25 Oct 2022 18:07:26 -0700 Subject: [PATCH 13/50] Made default port be a higher port --- source/server/SocketClient.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/source/server/SocketClient.cpp b/source/server/SocketClient.cpp index 5a5f51c..f34633d 100644 --- a/source/server/SocketClient.cpp +++ b/source/server/SocketClient.cpp @@ -87,8 +87,9 @@ nn::Result SocketClient::init(const char* ip, u16 port) { return -1; } + // TODO Find a way around the 41553 constant port udpAddress.address = hostAddress; - udpAddress.port = nn::socket::InetHtons(0); + udpAddress.port = nn::socket::InetHtons(41553); udpAddress.family = 2; this->udp_addr = udpAddress; this->has_recv_udp = false; @@ -156,7 +157,7 @@ s32 SocketClient::setPeerUdpPort(u16 port) { } const char* SocketClient::getUdpStateChar() { - if (this->udp_addr.port == 0) { + if (this->udp_addr.port == 41553) { return "Waiting for handshake"; } From 93c750ccf7c999e35eb595e811d9f9995366ee3e Mon Sep 17 00:00:00 2001 From: Jack Garrard Date: Tue, 25 Oct 2022 19:33:58 -0700 Subject: [PATCH 14/50] Remove tabs --- source/server/SocketClient.cpp | 118 ++++++++++++++++----------------- 1 file changed, 59 insertions(+), 59 deletions(-) diff --git a/source/server/SocketClient.cpp b/source/server/SocketClient.cpp index f34633d..ecb3af1 100644 --- a/source/server/SocketClient.cpp +++ b/source/server/SocketClient.cpp @@ -80,19 +80,19 @@ nn::Result SocketClient::init(const char* ip, u16 port) { return result; } - if ((this->udp_socket = nn::socket::Socket(2, 2, 17)) < 0) { + if ((this->udp_socket = nn::socket::Socket(2, 2, 17)) < 0) { Logger::log("Udp Socket failed to create"); this->socket_errno = nn::socket::GetLastErrno(); this->socket_log_state = SOCKET_LOG_UNAVAILABLE; return -1; - } + } - // TODO Find a way around the 41553 constant port + // TODO Find a way around the 41553 constant port udpAddress.address = hostAddress; udpAddress.port = nn::socket::InetHtons(41553); udpAddress.family = 2; this->udp_addr = udpAddress; - this->has_recv_udp = false; + this->has_recv_udp = false; if((result = nn::socket::Connect(this->udp_socket, &udpAddress, sizeof(udpAddress))).isFailure()) { Logger::log("Udp Socket Connection Failed!\n"); @@ -157,15 +157,15 @@ s32 SocketClient::setPeerUdpPort(u16 port) { } const char* SocketClient::getUdpStateChar() { - if (this->udp_addr.port == 41553) { - return "Waiting for handshake"; - } - - if (!this->has_recv_udp) { - return "Waiting for holepunch"; - } - - return "Utilizing UDP"; + if (this->udp_addr.port == 41553) { + return "Waiting for handshake"; + } + + if (!this->has_recv_udp) { + return "Waiting for holepunch"; + } + + return "Utilizing UDP"; } bool SocketClient::send(Packet *packet) { @@ -176,17 +176,17 @@ bool SocketClient::send(Packet *packet) { int valread = 0; - int fd = -1; + int fd = -1; if ((packet->mType != PLAYERINF && packet->mType != HACKCAPINF && packet->mType != HOLEPUNCH) || !this->has_recv_udp) { - Logger::log("Sending packet: %s\n", packetNames[packet->mType]); - fd = this->socket_log_socket; - } else { + Logger::log("Sending packet: %s\n", packetNames[packet->mType]); + fd = this->socket_log_socket; + } else { - fd = this->udp_socket; - } + fd = this->udp_socket; + } - if ((valread = nn::socket::Send(fd, buffer, packet->mPacketSize + sizeof(Packet), 0) > 0)) { + if ((valread = nn::socket::Send(fd, buffer, packet->mPacketSize + sizeof(Packet), 0) > 0)) { return true; } else { Logger::log("Failed to Fully Send Packet! Result: %d Type: %s Packet Size: %d\n", valread, packetNames[packet->mType], packet->mPacketSize); @@ -209,34 +209,34 @@ bool SocketClient::recv() { char headerBuf[MAXPACKSIZE * 2] = {}; int valread = 0; - const int fd_count = 2; - struct pollfd pfds[fd_count] = {{0}, {0}}; - pfds[0].fd = this->socket_log_socket; - pfds[0].events = 1; - pfds[0].revents = 0; - pfds[1].fd = this->udp_socket; - pfds[1].events = 1; - pfds[1].revents = 0; + const int fd_count = 2; + struct pollfd pfds[fd_count] = {{0}, {0}}; + pfds[0].fd = this->socket_log_socket; + pfds[0].events = 1; + pfds[0].revents = 0; + pfds[1].fd = this->udp_socket; + pfds[1].events = 1; + pfds[1].revents = 0; - if (nn::socket::Poll(pfds, fd_count, 0) <= 0) { - return true; - } + if (nn::socket::Poll(pfds, fd_count, 0) <= 0) { + return true; + } - s32 fd = -1; - s32 index = -1; - for (int i = 0; i < fd_count; i++){ - if (pfds[i].revents & 1) { - fd = pfds[i].fd; - index = i; - } - } + s32 fd = -1; + s32 index = -1; + for (int i = 0; i < fd_count; i++){ + if (pfds[i].revents & 1) { + fd = pfds[i].fd; + index = i; + } + } - if (fd == -1) { - return true; - } + if (fd == -1) { + return true; + } - if (index == 1) { + if (index == 1) { int result = nn::socket::Recv(fd, headerBuf, sizeof(headerBuf), this->sock_flags); if (result < headerSize){ return true; @@ -244,40 +244,40 @@ bool SocketClient::recv() { Packet* header = reinterpret_cast(headerBuf); int fullSize = header->mPacketSize + sizeof(Packet); - // Verify packet size is appropriate + // Verify packet size is appropriate if (result < fullSize || result > MAXPACKSIZE || fullSize > MAXPACKSIZE){ return true; } - - // Verify type of packet + + // Verify type of packet if (!(header->mType > PacketType::UNKNOWN && header->mType < PacketType::End)) { Logger::log("Failed to acquire valid packet type! Packet Type: %d Full Packet Size %d valread size: %d", header->mType, fullSize, result); return true; } - this->has_recv_udp = true; - + this->has_recv_udp = true; + char* packetBuf = (char*)mHeap->alloc(fullSize); if (packetBuf){ - memcpy(packetBuf, headerBuf, fullSize); + memcpy(packetBuf, headerBuf, fullSize); - Packet *packet = reinterpret_cast(packetBuf); + Packet *packet = reinterpret_cast(packetBuf); - if(!mRecvQueue.isFull()) { - mRecvQueue.push((s64)packet, sead::MessageQueue::BlockType::NonBlocking); - } else { - mHeap->free(packetBuf); - } - } + if(!mRecvQueue.isFull()) { + mRecvQueue.push((s64)packet, sead::MessageQueue::BlockType::NonBlocking); + } else { + mHeap->free(packetBuf); + } + } return true; } // read only the size of a header while(valread < headerSize) { int result = 0; - result = nn::socket::Recv(fd, headerBuf + valread, - headerSize - valread, this->sock_flags); + result = nn::socket::Recv(fd, headerBuf + valread, + headerSize - valread, this->sock_flags); this->socket_errno = nn::socket::GetLastErrno(); @@ -393,7 +393,7 @@ bool SocketClient::closeSocket() { Logger::log("Closing Socket.\n"); - has_recv_udp = false; + has_recv_udp = false; bool result = false; if (!(result = SocketBase::closeSocket())) { From 4655b0755e14d3a07c9a9aba5455e11b1436c244 Mon Sep 17 00:00:00 2001 From: Jack Garrard Date: Tue, 25 Oct 2022 19:41:09 -0700 Subject: [PATCH 15/50] Remove udp connection attempt in init and leave default port at 0 --- source/server/SocketClient.cpp | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/source/server/SocketClient.cpp b/source/server/SocketClient.cpp index ecb3af1..0f944b3 100644 --- a/source/server/SocketClient.cpp +++ b/source/server/SocketClient.cpp @@ -89,18 +89,11 @@ nn::Result SocketClient::init(const char* ip, u16 port) { // TODO Find a way around the 41553 constant port udpAddress.address = hostAddress; - udpAddress.port = nn::socket::InetHtons(41553); + udpAddress.port = 0; udpAddress.family = 2; this->udp_addr = udpAddress; this->has_recv_udp = false; - if((result = nn::socket::Connect(this->udp_socket, &udpAddress, sizeof(udpAddress))).isFailure()) { - Logger::log("Udp Socket Connection Failed!\n"); - this->socket_errno = nn::socket::GetLastErrno(); - this->socket_log_state = SOCKET_LOG_UNAVAILABLE; - return result; - } - this->socket_log_state = SOCKET_LOG_CONNECTED; Logger::log("Socket fd: %d\n", socket_log_socket); @@ -157,7 +150,7 @@ s32 SocketClient::setPeerUdpPort(u16 port) { } const char* SocketClient::getUdpStateChar() { - if (this->udp_addr.port == 41553) { + if (this->udp_addr.port == 0) { return "Waiting for handshake"; } @@ -394,6 +387,7 @@ bool SocketClient::closeSocket() { Logger::log("Closing Socket.\n"); has_recv_udp = false; + udp_addr.port = 0; bool result = false; if (!(result = SocketBase::closeSocket())) { From a9c3ec4006a2297c7c3050ef15bedb9eb89c15bc Mon Sep 17 00:00:00 2001 From: Jack Garrard Date: Wed, 26 Oct 2022 02:43:02 -0700 Subject: [PATCH 16/50] Fix a stack exhausion bug --- source/server/SocketClient.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/server/SocketClient.cpp b/source/server/SocketClient.cpp index 0f944b3..dc31092 100644 --- a/source/server/SocketClient.cpp +++ b/source/server/SocketClient.cpp @@ -199,7 +199,7 @@ bool SocketClient::recv() { } int headerSize = sizeof(Packet); - char headerBuf[MAXPACKSIZE * 2] = {}; + char headerBuf[MAXPACKSIZE + 1] = {0}; int valread = 0; const int fd_count = 2; From 53f91b86952f0438ac3933639a22c622812814fb Mon Sep 17 00:00:00 2001 From: Jack Garrard Date: Wed, 26 Oct 2022 02:44:09 -0700 Subject: [PATCH 17/50] Clean up --- source/server/SocketClient.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/source/server/SocketClient.cpp b/source/server/SocketClient.cpp index dc31092..ee582ac 100644 --- a/source/server/SocketClient.cpp +++ b/source/server/SocketClient.cpp @@ -30,7 +30,7 @@ nn::Result SocketClient::init(const char* ip, u16 port) { in_addr hostAddress = { 0 }; sockaddr serverAddress = { 0 }; - sockaddr udpAddress = { 0 }; + sockaddr udpAddress = { 0 }; Logger::log("SocketClient::init: %s:%d sock %s\n", ip, port, getStateChar()); @@ -87,7 +87,6 @@ nn::Result SocketClient::init(const char* ip, u16 port) { return -1; } - // TODO Find a way around the 41553 constant port udpAddress.address = hostAddress; udpAddress.port = 0; udpAddress.family = 2; From bf646b2b3da60ed70ce0aca81b76c0bba9eb984d Mon Sep 17 00:00:00 2001 From: Jack Garrard Date: Wed, 26 Oct 2022 03:31:32 -0700 Subject: [PATCH 18/50] Add a newline to debug statement --- source/server/Client.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/server/Client.cpp b/source/server/Client.cpp index 418b092..33abed1 100644 --- a/source/server/Client.cpp +++ b/source/server/Client.cpp @@ -385,7 +385,7 @@ void Client::readFunc() { } case PacketType::UDPINIT: { UdpInit* initPacket = (UdpInit*)curPacket; - Logger::log("Received udp init packet from server"); + Logger::log("Received udp init packet from server\n"); sInstance->mSocket->setPeerUdpPort(initPacket->port); sendUdpHolePunch(); From 4a5a10f910337e9d189dcf8b0400d051fb90ce82 Mon Sep 17 00:00:00 2001 From: Jack Garrard Date: Wed, 26 Oct 2022 03:33:42 -0700 Subject: [PATCH 19/50] Convert receive buffer to be on heap --- include/packets/Packet.h | 2 +- include/server/SocketClient.hpp | 1 + source/server/SocketClient.cpp | 14 +++++++------- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/include/packets/Packet.h b/include/packets/Packet.h index 92fb053..77a9016 100644 --- a/include/packets/Packet.h +++ b/include/packets/Packet.h @@ -10,7 +10,7 @@ #define PACKBUFSIZE 0x30 #define COSTUMEBUFSIZE 0x20 -#define MAXPACKSIZE 0x100 +#define MAXPACKSIZE 0x50 enum PacketType : short { UNKNOWN, diff --git a/include/server/SocketClient.hpp b/include/server/SocketClient.hpp index 53d9b34..218d518 100644 --- a/include/server/SocketClient.hpp +++ b/include/server/SocketClient.hpp @@ -64,6 +64,7 @@ class SocketClient : public SocketBase { sead::MessageQueue mRecvQueue; sead::MessageQueue mSendQueue; + char* recvBuf = nullptr; int maxBufSize = 100; bool mIsFirstConnect = true; diff --git a/source/server/SocketClient.cpp b/source/server/SocketClient.cpp index ee582ac..a801480 100644 --- a/source/server/SocketClient.cpp +++ b/source/server/SocketClient.cpp @@ -21,6 +21,7 @@ SocketClient::SocketClient(const char* name, sead::Heap* heap) : mHeap(heap), So mRecvQueue.allocate(maxBufSize, mHeap); mSendQueue.allocate(maxBufSize, mHeap); + recvBuf = (char*)mHeap->alloc(MAXPACKSIZE+1); }; nn::Result SocketClient::init(const char* ip, u16 port) { @@ -198,7 +199,6 @@ bool SocketClient::recv() { } int headerSize = sizeof(Packet); - char headerBuf[MAXPACKSIZE + 1] = {0}; int valread = 0; const int fd_count = 2; @@ -229,12 +229,12 @@ bool SocketClient::recv() { } if (index == 1) { - int result = nn::socket::Recv(fd, headerBuf, sizeof(headerBuf), this->sock_flags); + int result = nn::socket::Recv(fd, recvBuf, sizeof(MAXPACKSIZE), this->sock_flags); if (result < headerSize){ return true; } - Packet* header = reinterpret_cast(headerBuf); + Packet* header = reinterpret_cast(recvBuf); int fullSize = header->mPacketSize + sizeof(Packet); // Verify packet size is appropriate if (result < fullSize || result > MAXPACKSIZE || fullSize > MAXPACKSIZE){ @@ -251,7 +251,7 @@ bool SocketClient::recv() { char* packetBuf = (char*)mHeap->alloc(fullSize); if (packetBuf){ - memcpy(packetBuf, headerBuf, fullSize); + memcpy(packetBuf, recvBuf, fullSize); Packet *packet = reinterpret_cast(packetBuf); @@ -268,7 +268,7 @@ bool SocketClient::recv() { // read only the size of a header while(valread < headerSize) { int result = 0; - result = nn::socket::Recv(fd, headerBuf + valread, + result = nn::socket::Recv(fd, recvBuf + valread, headerSize - valread, this->sock_flags); this->socket_errno = nn::socket::GetLastErrno(); @@ -286,7 +286,7 @@ bool SocketClient::recv() { } if(valread > 0) { - Packet* header = reinterpret_cast(headerBuf); + Packet* header = reinterpret_cast(recvBuf); int fullSize = header->mPacketSize + sizeof(Packet); @@ -307,7 +307,7 @@ bool SocketClient::recv() { if (packetBuf) { - memcpy(packetBuf, headerBuf, sizeof(Packet)); + memcpy(packetBuf, recvBuf, sizeof(Packet)); while (valread < fullSize) { From 28c7f92453ad832b7597f4ea9c29d3d7244dd1e6 Mon Sep 17 00:00:00 2001 From: Jack Garrard Date: Thu, 27 Oct 2022 00:25:37 -0700 Subject: [PATCH 20/50] Refactor member variable names --- include/server/SocketClient.hpp | 13 ++++++------- source/server/SocketClient.cpp | 28 ++++++++++++++-------------- 2 files changed, 20 insertions(+), 21 deletions(-) diff --git a/include/server/SocketClient.hpp b/include/server/SocketClient.hpp index 218d518..54c0939 100644 --- a/include/server/SocketClient.hpp +++ b/include/server/SocketClient.hpp @@ -44,8 +44,8 @@ class SocketClient : public SocketBase { void printPacket(Packet* packet); bool isConnected() { return socket_log_state == SOCKET_LOG_CONNECTED; } - u16 getLocalUdpPort(); - s32 setPeerUdpPort(u16 port); + u16 getLocalUdpPort(); + s32 setPeerUdpPort(u16 port); const char* getUdpStateChar(); u32 getSendCount() { return mSendQueue.getCount(); } @@ -66,12 +66,11 @@ class SocketClient : public SocketBase { sead::MessageQueue mSendQueue; char* recvBuf = nullptr; - int maxBufSize = 100; - bool mIsFirstConnect = true; + int mMaxBufSize = 100; - bool has_recv_udp; - s32 udp_socket; - sockaddr udp_addr; + bool mHasRecvUdp; + s32 mUdpSocket; + sockaddr mUdpAddress; /** diff --git a/source/server/SocketClient.cpp b/source/server/SocketClient.cpp index a801480..3c0042d 100644 --- a/source/server/SocketClient.cpp +++ b/source/server/SocketClient.cpp @@ -81,7 +81,7 @@ nn::Result SocketClient::init(const char* ip, u16 port) { return result; } - if ((this->udp_socket = nn::socket::Socket(2, 2, 17)) < 0) { + if ((this->ket = nn::socket::Socket(2, 2, 17)) < 0) { Logger::log("Udp Socket failed to create"); this->socket_errno = nn::socket::GetLastErrno(); this->socket_log_state = SOCKET_LOG_UNAVAILABLE; @@ -91,8 +91,8 @@ nn::Result SocketClient::init(const char* ip, u16 port) { udpAddress.address = hostAddress; udpAddress.port = 0; udpAddress.family = 2; - this->udp_addr = udpAddress; - this->has_recv_udp = false; + this->mUdpAddress = udpAddress; + this->mHasRecvUdp = false; this->socket_log_state = SOCKET_LOG_CONNECTED; @@ -124,7 +124,7 @@ u16 SocketClient::getLocalUdpPort() { u32 size = sizeof(udpAddress); nn::Result result; - if((result = nn::socket::GetSockName(this->udp_socket, &udpAddress, &size)).isFailure()) { + if((result = nn::socket::GetSockName(this->ket, &udpAddress, &size)).isFailure()) { this->socket_errno = nn::socket::GetLastErrno(); return 0; } @@ -135,10 +135,10 @@ u16 SocketClient::getLocalUdpPort() { s32 SocketClient::setPeerUdpPort(u16 port) { u16 net_port = nn::socket::InetHtons(port); - this->udp_addr.port = net_port; + this->mUdpAddress.port = net_port; nn::Result result; - if((result = nn::socket::Connect(this->udp_socket, &this->udp_addr, sizeof(this->udp_addr))).isFailure()) { + if((result = nn::socket::Connect(this->ket, &this->mUdpAddress, sizeof(this->mUdpAddress))).isFailure()) { Logger::log("Udp Socket Connection Failed!\n"); this->socket_errno = nn::socket::GetLastErrno(); this->socket_log_state = SOCKET_LOG_UNAVAILABLE; @@ -150,11 +150,11 @@ s32 SocketClient::setPeerUdpPort(u16 port) { } const char* SocketClient::getUdpStateChar() { - if (this->udp_addr.port == 0) { + if (this->mUdpAddress.port == 0) { return "Waiting for handshake"; } - if (!this->has_recv_udp) { + if (!this->mHasRecvUdp) { return "Waiting for holepunch"; } @@ -170,12 +170,12 @@ bool SocketClient::send(Packet *packet) { int valread = 0; int fd = -1; - if ((packet->mType != PLAYERINF && packet->mType != HACKCAPINF && packet->mType != HOLEPUNCH) || !this->has_recv_udp) { + if ((packet->mType != PLAYERINF && packet->mType != HACKCAPINF && packet->mType != HOLEPUNCH) || !this->mHasRecvUdp) { Logger::log("Sending packet: %s\n", packetNames[packet->mType]); fd = this->socket_log_socket; } else { - fd = this->udp_socket; + fd = this->ket; } @@ -206,7 +206,7 @@ bool SocketClient::recv() { pfds[0].fd = this->socket_log_socket; pfds[0].events = 1; pfds[0].revents = 0; - pfds[1].fd = this->udp_socket; + pfds[1].fd = this->ket; pfds[1].events = 1; pfds[1].revents = 0; @@ -247,7 +247,7 @@ bool SocketClient::recv() { return true; } - this->has_recv_udp = true; + this->mHasRecvUdp = true; char* packetBuf = (char*)mHeap->alloc(fullSize); if (packetBuf){ @@ -385,8 +385,8 @@ bool SocketClient::closeSocket() { Logger::log("Closing Socket.\n"); - has_recv_udp = false; - udp_addr.port = 0; + mHasRecvUdp = false; + mUdpAddress.port = 0; bool result = false; if (!(result = SocketBase::closeSocket())) { From 24e724a824dc7e037adc9e372786d510cba4e373 Mon Sep 17 00:00:00 2001 From: Jack Garrard Date: Thu, 27 Oct 2022 00:26:26 -0700 Subject: [PATCH 21/50] Hopefully prevent close socket race condition --- source/server/SocketBase.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/source/server/SocketBase.cpp b/source/server/SocketBase.cpp index 4f82d95..b9c408a 100644 --- a/source/server/SocketBase.cpp +++ b/source/server/SocketBase.cpp @@ -72,12 +72,13 @@ s32 SocketBase::getFd() { bool SocketBase::closeSocket() { - this->socket_log_state = SOCKET_LOG_DISCONNECTED; // probably not safe to assume socket will be closed + if (this->socket_log_state != SOCKET_LOG_DISCONNECTED) { + nn::Result result = nn::socket::Close(this->socket_log_socket); + if (result.isSuccess()) { + this->socket_log_state = SOCKET_LOG_DISCONNECTED; + } + return result.isSuccess(); + } - nn::Result result = nn::socket::Close(this->socket_log_socket); - - return result.isSuccess(); + return true; } - - - From e6871da878a8f3c9ea6569076902720940fa3564 Mon Sep 17 00:00:00 2001 From: Jack Garrard Date: Thu, 27 Oct 2022 00:27:29 -0700 Subject: [PATCH 22/50] Readd missing variable --- include/server/SocketClient.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/include/server/SocketClient.hpp b/include/server/SocketClient.hpp index 54c0939..8ab5e2b 100644 --- a/include/server/SocketClient.hpp +++ b/include/server/SocketClient.hpp @@ -67,6 +67,7 @@ class SocketClient : public SocketBase { char* recvBuf = nullptr; int mMaxBufSize = 100; + bool mIsFirstConnect = true; bool mHasRecvUdp; s32 mUdpSocket; From efef24fbbe11b1f007b815b42cac9af5017078f5 Mon Sep 17 00:00:00 2001 From: Jack Garrard Date: Thu, 27 Oct 2022 02:09:59 -0700 Subject: [PATCH 23/50] Fix variable names again --- include/server/SocketClient.hpp | 2 +- source/server/SocketClient.cpp | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/include/server/SocketClient.hpp b/include/server/SocketClient.hpp index a79b388..ff41816 100644 --- a/include/server/SocketClient.hpp +++ b/include/server/SocketClient.hpp @@ -70,7 +70,7 @@ class SocketClient : public SocketBase { sead::MessageQueue mSendQueue; char* recvBuf = nullptr; - int mMaxBufSize = 100; + int maxBufSize = 100; bool mIsFirstConnect = true; bool mPacketQueueOpen = true; diff --git a/source/server/SocketClient.cpp b/source/server/SocketClient.cpp index 6d5e5d3..2a207e7 100644 --- a/source/server/SocketClient.cpp +++ b/source/server/SocketClient.cpp @@ -81,7 +81,7 @@ nn::Result SocketClient::init(const char* ip, u16 port) { return result; } - if ((this->ket = nn::socket::Socket(2, 2, 17)) < 0) { + if ((this->mUdpSocket = nn::socket::Socket(2, 2, 17)) < 0) { Logger::log("Udp Socket failed to create"); this->socket_errno = nn::socket::GetLastErrno(); this->socket_log_state = SOCKET_LOG_UNAVAILABLE; @@ -125,7 +125,7 @@ u16 SocketClient::getLocalUdpPort() { u32 size = sizeof(udpAddress); nn::Result result; - if((result = nn::socket::GetSockName(this->ket, &udpAddress, &size)).isFailure()) { + if((result = nn::socket::GetSockName(this->mUdpSocket, &udpAddress, &size)).isFailure()) { this->socket_errno = nn::socket::GetLastErrno(); return 0; } @@ -176,7 +176,7 @@ bool SocketClient::send(Packet *packet) { fd = this->socket_log_socket; } else { - fd = this->ket; + fd = this->mUdpSocket; } @@ -207,7 +207,7 @@ bool SocketClient::recv() { pfds[0].fd = this->socket_log_socket; pfds[0].events = 1; pfds[0].revents = 0; - pfds[1].fd = this->ket; + pfds[1].fd = this->mUdpSocket; pfds[1].events = 1; pfds[1].revents = 0; @@ -341,7 +341,7 @@ bool SocketClient::recv() { } } } else { - Logger::log("Failed to acquire valid data! Packet Type: %d Full Packet Size %d valread size: %d", header->mType, fullSize, valread); + Logger::log("Failed to acquire valid data! Packet Type: %d Full Packet Size %d valread size: %d\n", header->mType, fullSize, valread); } return true; From 78b532a316f55fdb6050849adc5e912a02d4dd19 Mon Sep 17 00:00:00 2001 From: Jack Garrard Date: Thu, 27 Oct 2022 02:10:44 -0700 Subject: [PATCH 24/50] Prevent udp error from killing tcp connection --- source/server/SocketClient.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/source/server/SocketClient.cpp b/source/server/SocketClient.cpp index 2a207e7..25ea74e 100644 --- a/source/server/SocketClient.cpp +++ b/source/server/SocketClient.cpp @@ -139,10 +139,9 @@ s32 SocketClient::setPeerUdpPort(u16 port) { this->mUdpAddress.port = net_port; nn::Result result; - if((result = nn::socket::Connect(this->ket, &this->mUdpAddress, sizeof(this->mUdpAddress))).isFailure()) { - Logger::log("Udp Socket Connection Failed!\n"); + if((result = nn::socket::Connect(this->mUdpSocket, &this->mUdpAddress, sizeof(this->mUdpAddress))).isFailure()) { + Logger::log("Udp socket connection failed to connect to port %d!\n", port); this->socket_errno = nn::socket::GetLastErrno(); - this->socket_log_state = SOCKET_LOG_UNAVAILABLE; return -1; } From 000d24a7dbc664372dcdcfad085ceb00040dda32 Mon Sep 17 00:00:00 2001 From: Jack Garrard Date: Thu, 27 Oct 2022 02:11:28 -0700 Subject: [PATCH 25/50] Made makefile use python3 instead of python3.8 --- Makefile | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index d1b8bfa..1018f35 100644 --- a/Makefile +++ b/Makefile @@ -45,15 +45,15 @@ emu: mv $(shell basename $(CURDIR))$(SMOVER).nso starlight_patch_$(SMOVER)/yuzu/subsdk1 # builds and sends project to FTP server hosted on provided IP send: all - python3.8 scripts/sendPatch.py $(IP) $(PROJNAME) + python3 scripts/sendPatch.py $(IP) $(PROJNAME) log: all - python3.8 scripts/tcpServer.py $(SERVERIP) + python3 scripts/tcpServer.py $(SERVERIP) sendlog: all - python3.8 scripts/sendPatch.py $(IP) $(PROJNAME) $(USER) $(PASS) - python3.8 scripts/tcpServer.py $(SERVERIP) + python3 scripts/sendPatch.py $(IP) $(PROJNAME) $(USER) $(PASS) + python3 scripts/tcpServer.py $(SERVERIP) clean: $(MAKE) clean -f MakefileNSO - @rm -fr starlight_patch_* \ No newline at end of file + @rm -fr starlight_patch_* From 0147f4d7381934ea32daf9dedfcca429586a1a75 Mon Sep 17 00:00:00 2001 From: Jack Garrard Date: Thu, 27 Oct 2022 02:12:00 -0700 Subject: [PATCH 26/50] Change send patch to follow make file rules --- scripts/sendPatch.py | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/scripts/sendPatch.py b/scripts/sendPatch.py index 15d14b3..4d74074 100644 --- a/scripts/sendPatch.py +++ b/scripts/sendPatch.py @@ -35,36 +35,37 @@ if '.' not in consoleIP: print(sys.argv[0], "ERROR: Please specify with `IP=[Your console's IP]`") sys.exit(-1) -isNeedOtherSwitch = True - -altSwitchIP = sys.argv[2] -if '.' not in altSwitchIP: - isNeedOtherSwitch = False +isNeedOtherSwitch = False consolePort = 5000 -if len(sys.argv) < 4: +if len(sys.argv) < 3: projName = 'StarlightBase' else: - projName = sys.argv[3] + projName = sys.argv[2] + +if len(sys.argv) < 5: + user = 'crafty' + passwd = 'boss' +else: + user = sys.argv[3] + passwd = sys.argv[4] curDir = os.curdir ftp = FTP() -otherftp = FTP() - print(f'Connecting to {consoleIP}... ', end='') ftp.connect(consoleIP, consolePort) print('logging into server...', end='') -ftp.login('crafty','boss') +ftp.login(user,passwd) print('Connected!') if isNeedOtherSwitch: print(f'Connecting to {altSwitchIP}... ', end='') otherftp.connect(altSwitchIP, consolePort) print('logging into server...', end='') - otherftp.login('crafty','boss') + otherftp.login(user,passwd) print('Connected!') patchDirectories = [] From a58471c19f6b12abb4e2d97b5b697c65d2b7230c Mon Sep 17 00:00:00 2001 From: Jack Garrard Date: Thu, 27 Oct 2022 03:21:54 -0700 Subject: [PATCH 27/50] New lines for logger output --- source/server/SocketClient.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/server/SocketClient.cpp b/source/server/SocketClient.cpp index 25ea74e..7170bbc 100644 --- a/source/server/SocketClient.cpp +++ b/source/server/SocketClient.cpp @@ -243,7 +243,7 @@ bool SocketClient::recv() { // Verify type of packet if (!(header->mType > PacketType::UNKNOWN && header->mType < PacketType::End)) { - Logger::log("Failed to acquire valid packet type! Packet Type: %d Full Packet Size %d valread size: %d", header->mType, fullSize, result); + Logger::log("Failed to acquire valid packet type! Packet Type: %d Full Packet Size %d valread size: %d\n", header->mType, fullSize, result); return true; } @@ -326,7 +326,7 @@ bool SocketClient::recv() { } if (!(header->mType > PacketType::UNKNOWN && header->mType < PacketType::End)) { - Logger::log("Failed to acquire valid packet type! Packet Type: %d Full Packet Size %d valread size: %d", header->mType, fullSize, valread); + Logger::log("Failed to acquire valid packet type! Packet Type: %d Full Packet Size %d valread size: %d\n", header->mType, fullSize, valread); mHeap->free(packetBuf); return true; } From 04fc8cb309cac02241110b7c49e1b03cfea744a9 Mon Sep 17 00:00:00 2001 From: Jack Garrard Date: Thu, 27 Oct 2022 03:22:01 -0700 Subject: [PATCH 28/50] Increased max packet size again --- include/packets/Packet.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/packets/Packet.h b/include/packets/Packet.h index 77a9016..92fb053 100644 --- a/include/packets/Packet.h +++ b/include/packets/Packet.h @@ -10,7 +10,7 @@ #define PACKBUFSIZE 0x30 #define COSTUMEBUFSIZE 0x20 -#define MAXPACKSIZE 0x50 +#define MAXPACKSIZE 0x100 enum PacketType : short { UNKNOWN, From 5c04bb10065ea3e840d5e4150edd69c8d7525336 Mon Sep 17 00:00:00 2001 From: Jack Garrard Date: Thu, 27 Oct 2022 04:46:36 -0700 Subject: [PATCH 29/50] Use if guard for alloc in udp recv --- source/server/SocketClient.cpp | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/source/server/SocketClient.cpp b/source/server/SocketClient.cpp index 7170bbc..7a724fa 100644 --- a/source/server/SocketClient.cpp +++ b/source/server/SocketClient.cpp @@ -250,18 +250,21 @@ bool SocketClient::recv() { this->mHasRecvUdp = true; char* packetBuf = (char*)mHeap->alloc(fullSize); - if (packetBuf){ - memcpy(packetBuf, recvBuf, fullSize); - - - Packet *packet = reinterpret_cast(packetBuf); - - if(!mRecvQueue.isFull()) { - mRecvQueue.push((s64)packet, sead::MessageQueue::BlockType::NonBlocking); - } else { - mHeap->free(packetBuf); - } + if (!packetBuf) { + return true } + + memcpy(packetBuf, recvBuf, fullSize); + + + Packet *packet = reinterpret_cast(packetBuf); + + if(!mRecvQueue.isFull()) { + mRecvQueue.push((s64)packet, sead::MessageQueue::BlockType::NonBlocking); + } else { + mHeap->free(packetBuf); + } + return true; } From 4171390f421c9c2e52dbeb0d0824edbd14ae5676 Mon Sep 17 00:00:00 2001 From: Jack Garrard Date: Thu, 27 Oct 2022 04:51:36 -0700 Subject: [PATCH 30/50] Allow hole punch packets to get through before udp fully recved --- source/server/SocketClient.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/source/server/SocketClient.cpp b/source/server/SocketClient.cpp index 7a724fa..c3ff1b9 100644 --- a/source/server/SocketClient.cpp +++ b/source/server/SocketClient.cpp @@ -170,8 +170,14 @@ bool SocketClient::send(Packet *packet) { int valread = 0; int fd = -1; - if ((packet->mType != PLAYERINF && packet->mType != HACKCAPINF && packet->mType != HOLEPUNCH) || !this->mHasRecvUdp) { - Logger::log("Sending packet: %s\n", packetNames[packet->mType]); + if ((packet->mType != PLAYERINF && packet->mType != HACKCAPINF && packet->mType != HOLEPUNCH) + || (!this->mHasRecvUdp && packet->mType != HOLEPUNCH) + || this->mUdpAddress.port == 0) { + + if (packet->mType != PLAYERINF && packet->mType != HACKCAPINF) { + Logger::log("Sending packet: %s\n", packetNames[packet->mType]); + } + fd = this->socket_log_socket; } else { From 57333d71e92d618e48f70b1de70851b958315bfe Mon Sep 17 00:00:00 2001 From: Jack Garrard Date: Thu, 27 Oct 2022 04:52:27 -0700 Subject: [PATCH 31/50] Fix recv buf size calculation --- source/server/SocketClient.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/server/SocketClient.cpp b/source/server/SocketClient.cpp index c3ff1b9..65a4f53 100644 --- a/source/server/SocketClient.cpp +++ b/source/server/SocketClient.cpp @@ -235,7 +235,7 @@ bool SocketClient::recv() { } if (index == 1) { - int result = nn::socket::Recv(fd, recvBuf, sizeof(MAXPACKSIZE), this->sock_flags); + int result = nn::socket::Recv(fd, recvBuf, MAXPACKSIZE, this->sock_flags); if (result < headerSize){ return true; } From 627e07cd6598674e56b31ea572481050aa65e3e9 Mon Sep 17 00:00:00 2001 From: Jack Garrard Date: Thu, 27 Oct 2022 04:54:30 -0700 Subject: [PATCH 32/50] Fix missing semicolon --- source/server/SocketClient.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/server/SocketClient.cpp b/source/server/SocketClient.cpp index 65a4f53..01d0f33 100644 --- a/source/server/SocketClient.cpp +++ b/source/server/SocketClient.cpp @@ -257,7 +257,7 @@ bool SocketClient::recv() { char* packetBuf = (char*)mHeap->alloc(fullSize); if (!packetBuf) { - return true + return true; } memcpy(packetBuf, recvBuf, fullSize); From 1fc3a78943f8edcd08401ac59bb1accbaba1487b Mon Sep 17 00:00:00 2001 From: Jack Garrard Date: Sat, 29 Oct 2022 17:17:38 -0700 Subject: [PATCH 33/50] Shutdown send/recv threads before socket reinit --- include/server/SocketClient.hpp | 3 ++- source/server/Client.cpp | 10 +++++-- source/server/SocketClient.cpp | 47 ++++++++++++++++++++++----------- 3 files changed, 41 insertions(+), 19 deletions(-) diff --git a/include/server/SocketClient.hpp b/include/server/SocketClient.hpp index ff41816..26f1191 100644 --- a/include/server/SocketClient.hpp +++ b/include/server/SocketClient.hpp @@ -29,12 +29,13 @@ class SocketClient : public SocketBase { bool startThreads(); void endThreads(); + void waitForThreads(); bool send(Packet* packet); bool recv(); bool queuePacket(Packet *packet); - void trySendQueue(); + bool trySendQueue(); void sendFunc(); void recvFunc(); diff --git a/source/server/Client.cpp b/source/server/Client.cpp index ffe444e..4422e43 100644 --- a/source/server/Client.cpp +++ b/source/server/Client.cpp @@ -109,6 +109,7 @@ bool Client::startThread() { */ void Client::restartConnection() { + Logger::log("Restarting connection.\n"); if (!sInstance) { Logger::log("Static Instance is null!\n"); return; @@ -134,8 +135,12 @@ void Client::restartConnection() { Logger::log("Sucessfully Closed Socket.\n"); } + Logger::log("Waiting for send/recv threads to finish.\n"); + sInstance->mSocket->waitForThreads(); + sInstance->mConnectCount = 0; + Logger::log("Reinitializing connection\n"); sInstance->mIsConnectionActive = sInstance->mSocket->init(sInstance->mServerIP.cstr(), sInstance->mServerPort).isSuccess(); if(sInstance->mSocket->getLogState() == SOCKET_LOG_CONNECTED) { @@ -409,8 +414,9 @@ void Client::readFunc() { mHeap->free(curPacket); - }else { // if false, socket has errored or disconnected, so close the socket and end this thread. - Logger::log("Client Socket Encountered an Error! Errno: 0x%x\n", mSocket->socket_errno); + }else { // if false, socket has errored or disconnected, so restart the connection + Logger::log("Client Socket Encountered an Error, restarting connection! Errno: 0x%x\n", mSocket->socket_errno); + this->restartConnection(); } } diff --git a/source/server/SocketClient.cpp b/source/server/SocketClient.cpp index 01d0f33..7c734ec 100644 --- a/source/server/SocketClient.cpp +++ b/source/server/SocketClient.cpp @@ -162,7 +162,7 @@ const char* SocketClient::getUdpStateChar() { } bool SocketClient::send(Packet *packet) { - if (this->socket_log_state != SOCKET_LOG_CONNECTED) + if (this->socket_log_state != SOCKET_LOG_CONNECTED || packet == nullptr) return false; char* buffer = reinterpret_cast(packet); @@ -190,7 +190,7 @@ bool SocketClient::send(Packet *packet) { } else { Logger::log("Failed to Fully Send Packet! Result: %d Type: %s Packet Size: %d\n", valread, packetNames[packet->mType], packet->mPacketSize); this->socket_errno = nn::socket::GetLastErrno(); - this->tryReconnect(); + this->closeSocket(); return false; } return true; @@ -201,7 +201,8 @@ bool SocketClient::recv() { if (this->socket_log_state != SOCKET_LOG_CONNECTED) { Logger::log("Unable To Receive! Socket Not Connected.\n"); this->socket_errno = nn::socket::GetLastErrno(); - return this->tryReconnect(); + this->closeSocket(); + return false; } int headerSize = sizeof(Packet); @@ -209,9 +210,13 @@ bool SocketClient::recv() { const int fd_count = 2; struct pollfd pfds[fd_count] = {{0}, {0}}; + + // TCP Connection pfds[0].fd = this->socket_log_socket; pfds[0].events = 1; pfds[0].revents = 0; + + // UDP Connection pfds[1].fd = this->mUdpSocket; pfds[1].events = 1; pfds[1].revents = 0; @@ -289,7 +294,8 @@ bool SocketClient::recv() { return true; } else { Logger::log("Header Read Failed! Value: %d Total Read: %d\n", result, valread); - return this->tryReconnect(); // if we sucessfully reconnect, we dont want + this->closeSocket(); + return false; } } } @@ -330,7 +336,8 @@ bool SocketClient::recv() { } else { mHeap->free(packetBuf); Logger::log("Packet Read Failed! Value: %d\nPacket Size: %d\nPacket Type: %s\n", result, header->mPacketSize, packetNames[header->mType]); - return this->tryReconnect(); + this->closeSocket(); + return false; } } @@ -356,7 +363,8 @@ bool SocketClient::recv() { } else { // if we error'd, close the socket Logger::log("valread was zero! Disconnecting.\n"); this->socket_errno = nn::socket::GetLastErrno(); - return this->tryReconnect(); + this->closeSocket(); + return false; } } @@ -454,14 +462,18 @@ void SocketClient::endThreads() { mSendThread->mDelegateThread->destroy(); } +void SocketClient::waitForThreads() { + while (!mRecvThread->isDone()){} + while (!mSendThread->isDone()){} +} + void SocketClient::sendFunc() { Logger::log("Starting Send Thread.\n"); - while (true) { - trySendQueue(); - } + while (trySendQueue() || socket_log_state != SOCKET_LOG_DISCONNECTED) {} + Logger::log("Sending packet failed!\n"); Logger::log("Ending Send Thread.\n"); } @@ -471,12 +483,13 @@ void SocketClient::recvFunc() { Logger::log("Starting Recv Thread.\n"); - while (true) { - if (!recv()) { - Logger::log("Receiving Packet Failed!\n"); - } - } + while (recv() || socket_log_state != SOCKET_LOG_DISCONNECTED) {} + // Free up all blocked threads + mSendQueue.push(0, sead::MessageQueue::BlockType::NonBlocking); + mRecvQueue.push(0, sead::MessageQueue::BlockType::NonBlocking); + + Logger::log("Receiving Packet Failed!\n"); Logger::log("Ending Recv Thread.\n"); } @@ -492,13 +505,15 @@ bool SocketClient::queuePacket(Packet* packet) { } } -void SocketClient::trySendQueue() { +bool SocketClient::trySendQueue() { Packet* curPacket = (Packet*)mSendQueue.pop(sead::MessageQueue::BlockType::Blocking); - send(curPacket); + bool successful = send(curPacket); mHeap->free(curPacket); + + return successful; } Packet* SocketClient::tryGetPacket(sead::MessageQueue::BlockType blockType) { From 7e128679abbc8af2616c2484f6e7662f889222a0 Mon Sep 17 00:00:00 2001 From: Jack Garrard Date: Sat, 29 Oct 2022 17:32:23 -0700 Subject: [PATCH 34/50] Split apart tcp and udp recv functions --- include/server/SocketClient.hpp | 2 + source/server/SocketClient.cpp | 114 +++++++++++++++++++------------- 2 files changed, 69 insertions(+), 47 deletions(-) diff --git a/include/server/SocketClient.hpp b/include/server/SocketClient.hpp index 26f1191..28c155c 100644 --- a/include/server/SocketClient.hpp +++ b/include/server/SocketClient.hpp @@ -80,6 +80,8 @@ class SocketClient : public SocketBase { s32 mUdpSocket; sockaddr mUdpAddress; + bool recvTcp(); + bool recvUdp(); /** * @param str a string containing an IPv4 address or a hostname that can be resolved via DNS diff --git a/source/server/SocketClient.cpp b/source/server/SocketClient.cpp index 7c734ec..740a6ce 100644 --- a/source/server/SocketClient.cpp +++ b/source/server/SocketClient.cpp @@ -205,9 +205,6 @@ bool SocketClient::recv() { return false; } - int headerSize = sizeof(Packet); - int valread = 0; - const int fd_count = 2; struct pollfd pfds[fd_count] = {{0}, {0}}; @@ -222,62 +219,41 @@ bool SocketClient::recv() { pfds[1].revents = 0; - if (nn::socket::Poll(pfds, fd_count, 0) <= 0) { + int result = nn::socket::Poll(pfds, fd_count, 0); + + if (result == 0) { return true; + } else if (result < 0) { + Logger::log("Error occurred when polling for packets\n"); + this->socket_errno = nn::socket::GetLastErrno(); + this->closeSocket(); + return false; } - s32 fd = -1; s32 index = -1; for (int i = 0; i < fd_count; i++){ if (pfds[i].revents & 1) { - fd = pfds[i].fd; index = i; + break; } } - if (fd == -1) { + switch (index) { + case 0: + return recvTcp(); + case 1: + return recvUdp(); + default: return true; } - if (index == 1) { - int result = nn::socket::Recv(fd, recvBuf, MAXPACKSIZE, this->sock_flags); - if (result < headerSize){ - return true; - } - Packet* header = reinterpret_cast(recvBuf); - int fullSize = header->mPacketSize + sizeof(Packet); - // Verify packet size is appropriate - if (result < fullSize || result > MAXPACKSIZE || fullSize > MAXPACKSIZE){ - return true; - } +} - // Verify type of packet - if (!(header->mType > PacketType::UNKNOWN && header->mType < PacketType::End)) { - Logger::log("Failed to acquire valid packet type! Packet Type: %d Full Packet Size %d valread size: %d\n", header->mType, fullSize, result); - return true; - } - - this->mHasRecvUdp = true; - - char* packetBuf = (char*)mHeap->alloc(fullSize); - if (!packetBuf) { - return true; - } - - memcpy(packetBuf, recvBuf, fullSize); - - - Packet *packet = reinterpret_cast(packetBuf); - - if(!mRecvQueue.isFull()) { - mRecvQueue.push((s64)packet, sead::MessageQueue::BlockType::NonBlocking); - } else { - mHeap->free(packetBuf); - } - - return true; - } +bool SocketClient::recvTcp() { + int headerSize = sizeof(Packet); + int valread = 0; + s32 fd = this->socket_log_socket; // read only the size of a header while(valread < headerSize) { @@ -286,7 +262,7 @@ bool SocketClient::recv() { headerSize - valread, this->sock_flags); this->socket_errno = nn::socket::GetLastErrno(); - + if(result > 0) { valread += result; } else { @@ -321,7 +297,7 @@ bool SocketClient::recv() { char* packetBuf = (char*)mHeap->alloc(fullSize); if (packetBuf) { - + memcpy(packetBuf, recvBuf, sizeof(Packet)); while (valread < fullSize) { @@ -358,7 +334,7 @@ bool SocketClient::recv() { } else { Logger::log("Failed to acquire valid data! Packet Type: %d Full Packet Size %d valread size: %d\n", header->mType, fullSize, valread); } - + return true; } else { // if we error'd, close the socket Logger::log("valread was zero! Disconnecting.\n"); @@ -368,6 +344,50 @@ bool SocketClient::recv() { } } +bool SocketClient::recvUdp() { + int headerSize = sizeof(Packet); + int valread = 0; + s32 fd = this->mUdpSocket; + + int result = nn::socket::Recv(fd, recvBuf, MAXPACKSIZE, this->sock_flags); + if (result < headerSize){ + return true; + } + + Packet* header = reinterpret_cast(recvBuf); + int fullSize = header->mPacketSize + sizeof(Packet); + // Verify packet size is appropriate + if (result < fullSize || result > MAXPACKSIZE || fullSize > MAXPACKSIZE){ + return true; + } + + // Verify type of packet + if (!(header->mType > PacketType::UNKNOWN && header->mType < PacketType::End)) { + Logger::log("Failed to acquire valid packet type! Packet Type: %d Full Packet Size %d valread size: %d\n", header->mType, fullSize, result); + return true; + } + + this->mHasRecvUdp = true; + + char* packetBuf = (char*)mHeap->alloc(fullSize); + if (!packetBuf) { + return true; + } + + memcpy(packetBuf, recvBuf, fullSize); + + + Packet *packet = reinterpret_cast(packetBuf); + + if(!mRecvQueue.isFull()) { + mRecvQueue.push((s64)packet, sead::MessageQueue::BlockType::NonBlocking); + } else { + mHeap->free(packetBuf); + } + + return true; +} + // prints packet to debug logger void SocketClient::printPacket(Packet *packet) { packet->mUserID.print(); From 158f782a2a6e076e4efb6f578f0108b59681fccc Mon Sep 17 00:00:00 2001 From: Jack Garrard Date: Sat, 29 Oct 2022 17:41:54 -0700 Subject: [PATCH 35/50] Change socket client recvTcp to use if guards --- source/server/SocketClient.cpp | 124 +++++++++++++++++---------------- 1 file changed, 63 insertions(+), 61 deletions(-) diff --git a/source/server/SocketClient.cpp b/source/server/SocketClient.cpp index 740a6ce..2838b6f 100644 --- a/source/server/SocketClient.cpp +++ b/source/server/SocketClient.cpp @@ -276,72 +276,74 @@ bool SocketClient::recvTcp() { } } - if(valread > 0) { - Packet* header = reinterpret_cast(recvBuf); - - int fullSize = header->mPacketSize + sizeof(Packet); - - if (fullSize <= MAXPACKSIZE && fullSize > 0 && valread == sizeof(Packet)) { - - if (header->mType != PLAYERINF && header->mType != HACKCAPINF) { - Logger::log("Received packet (from %02X%02X):", header->mUserID.data[0], - header->mUserID.data[1]); - Logger::disableName(); - Logger::log(" Size: %d", header->mPacketSize); - Logger::log(" Type: %d", header->mType); - if(packetNames[header->mType]) - Logger::log(" Type String: %s\n", packetNames[header->mType]); - Logger::enableName(); - } - - char* packetBuf = (char*)mHeap->alloc(fullSize); - - if (packetBuf) { - - memcpy(packetBuf, recvBuf, sizeof(Packet)); - - while (valread < fullSize) { - - int result = nn::socket::Recv(fd, packetBuf + valread, - fullSize - valread, this->sock_flags); - - this->socket_errno = nn::socket::GetLastErrno(); - - if (result > 0) { - valread += result; - } else { - mHeap->free(packetBuf); - Logger::log("Packet Read Failed! Value: %d\nPacket Size: %d\nPacket Type: %s\n", result, header->mPacketSize, packetNames[header->mType]); - this->closeSocket(); - return false; - } - } - - if (!(header->mType > PacketType::UNKNOWN && header->mType < PacketType::End)) { - Logger::log("Failed to acquire valid packet type! Packet Type: %d Full Packet Size %d valread size: %d\n", header->mType, fullSize, valread); - mHeap->free(packetBuf); - return true; - } - - Packet *packet = reinterpret_cast(packetBuf); - - if (!mRecvQueue.isFull() && mPacketQueueOpen) { - mRecvQueue.push((s64)packet, sead::MessageQueue::BlockType::NonBlocking); - } else { - mHeap->free(packetBuf); - } - } - } else { - Logger::log("Failed to acquire valid data! Packet Type: %d Full Packet Size %d valread size: %d\n", header->mType, fullSize, valread); - } - - return true; - } else { // if we error'd, close the socket + if(valread <= 0) { // if we error'd, close the socket Logger::log("valread was zero! Disconnecting.\n"); this->socket_errno = nn::socket::GetLastErrno(); this->closeSocket(); return false; } + + Packet* header = reinterpret_cast(recvBuf); + + int fullSize = header->mPacketSize + sizeof(Packet); + + if (!(fullSize <= MAXPACKSIZE && fullSize > 0 && valread == sizeof(Packet))) { + Logger::log("Failed to acquire valid data! Packet Type: %d Full Packet Size %d valread size: %d\n", header->mType, fullSize, valread); + return true; + } + + if (header->mType != PLAYERINF && header->mType != HACKCAPINF) { + Logger::log("Received packet (from %02X%02X):", header->mUserID.data[0], + header->mUserID.data[1]); + Logger::disableName(); + Logger::log(" Size: %d", header->mPacketSize); + Logger::log(" Type: %d", header->mType); + if(packetNames[header->mType]) + Logger::log(" Type String: %s\n", packetNames[header->mType]); + Logger::enableName(); + } + + char* packetBuf = (char*)mHeap->alloc(fullSize); + + if (!packetBuf) { + return true; + } + + + memcpy(packetBuf, recvBuf, sizeof(Packet)); + + while (valread < fullSize) { + + int result = nn::socket::Recv(fd, packetBuf + valread, + fullSize - valread, this->sock_flags); + + this->socket_errno = nn::socket::GetLastErrno(); + + if (result > 0) { + valread += result; + } else { + mHeap->free(packetBuf); + Logger::log("Packet Read Failed! Value: %d\nPacket Size: %d\nPacket Type: %s\n", result, header->mPacketSize, packetNames[header->mType]); + this->closeSocket(); + return false; + } + } + + if (!(header->mType > PacketType::UNKNOWN && header->mType < PacketType::End)) { + Logger::log("Failed to acquire valid packet type! Packet Type: %d Full Packet Size %d valread size: %d\n", header->mType, fullSize, valread); + mHeap->free(packetBuf); + return true; + } + + Packet *packet = reinterpret_cast(packetBuf); + + if (!mRecvQueue.isFull() && mPacketQueueOpen) { + mRecvQueue.push((s64)packet, sead::MessageQueue::BlockType::NonBlocking); + } else { + mHeap->free(packetBuf); + } + + return true; } bool SocketClient::recvUdp() { From 4ab6b56598065082172bade4cfbaec4470a89f10 Mon Sep 17 00:00:00 2001 From: Jack Garrard Date: Sat, 29 Oct 2022 17:46:20 -0700 Subject: [PATCH 36/50] Use valread and check if it returns zero for udp --- source/server/SocketClient.cpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/source/server/SocketClient.cpp b/source/server/SocketClient.cpp index 2838b6f..b1905f9 100644 --- a/source/server/SocketClient.cpp +++ b/source/server/SocketClient.cpp @@ -284,7 +284,6 @@ bool SocketClient::recvTcp() { } Packet* header = reinterpret_cast(recvBuf); - int fullSize = header->mPacketSize + sizeof(Packet); if (!(fullSize <= MAXPACKSIZE && fullSize > 0 && valread == sizeof(Packet))) { @@ -348,24 +347,30 @@ bool SocketClient::recvTcp() { bool SocketClient::recvUdp() { int headerSize = sizeof(Packet); - int valread = 0; s32 fd = this->mUdpSocket; - int result = nn::socket::Recv(fd, recvBuf, MAXPACKSIZE, this->sock_flags); - if (result < headerSize){ + int valread = nn::socket::Recv(fd, recvBuf, MAXPACKSIZE, this->sock_flags); + + if (valread == 0) { + Logger::log("Udp connection valread was zero. Disconnecting.\n"); + this->closeSocket(); + return false; + } + + if (valread < headerSize){ return true; } Packet* header = reinterpret_cast(recvBuf); int fullSize = header->mPacketSize + sizeof(Packet); // Verify packet size is appropriate - if (result < fullSize || result > MAXPACKSIZE || fullSize > MAXPACKSIZE){ + if (valread < fullSize || valread > MAXPACKSIZE || fullSize > MAXPACKSIZE){ return true; } // Verify type of packet if (!(header->mType > PacketType::UNKNOWN && header->mType < PacketType::End)) { - Logger::log("Failed to acquire valid packet type! Packet Type: %d Full Packet Size %d valread size: %d\n", header->mType, fullSize, result); + Logger::log("Failed to acquire valid packet type! Packet Type: %d Full Packet Size %d valread size: %d\n", header->mType, fullSize, valread); return true; } From 477f1c9e7d515300cf8263e6e9837065b814df2f Mon Sep 17 00:00:00 2001 From: Jack Garrard Date: Sat, 29 Oct 2022 18:12:53 -0700 Subject: [PATCH 37/50] Add a poll time to wait properly --- include/server/SocketClient.hpp | 1 + source/server/SocketClient.cpp | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/include/server/SocketClient.hpp b/include/server/SocketClient.hpp index 28c155c..da2bb7f 100644 --- a/include/server/SocketClient.hpp +++ b/include/server/SocketClient.hpp @@ -74,6 +74,7 @@ class SocketClient : public SocketBase { int maxBufSize = 100; bool mIsFirstConnect = true; bool mPacketQueueOpen = true; + int pollTime = 0; bool mHasRecvUdp; diff --git a/source/server/SocketClient.cpp b/source/server/SocketClient.cpp index b1905f9..3754ea0 100644 --- a/source/server/SocketClient.cpp +++ b/source/server/SocketClient.cpp @@ -15,6 +15,11 @@ #include "types.h" SocketClient::SocketClient(const char* name, sead::Heap* heap) : mHeap(heap), SocketBase(name) { +#if EMU + this->pollTime = 0; +#else + this->pollTime = -1; +#endif mRecvThread = new al::AsyncFunctorThread("SocketRecvThread", al::FunctorV0M(this, &SocketClient::recvFunc), 0, 0x1000, {0}); mSendThread = new al::AsyncFunctorThread("SocketSendThread", al::FunctorV0M(this, &SocketClient::sendFunc), 0, 0x1000, {0}); @@ -219,7 +224,7 @@ bool SocketClient::recv() { pfds[1].revents = 0; - int result = nn::socket::Poll(pfds, fd_count, 0); + int result = nn::socket::Poll(pfds, fd_count, this->pollTime); if (result == 0) { return true; From 8c992649fd45ec2b118b2ac61552682be2c1265f Mon Sep 17 00:00:00 2001 From: Jack Garrard Date: Sat, 29 Oct 2022 18:16:43 -0700 Subject: [PATCH 38/50] Remove tabs --- source/server/SocketBase.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/source/server/SocketBase.cpp b/source/server/SocketBase.cpp index b9c408a..9c79758 100644 --- a/source/server/SocketBase.cpp +++ b/source/server/SocketBase.cpp @@ -72,13 +72,13 @@ s32 SocketBase::getFd() { bool SocketBase::closeSocket() { - if (this->socket_log_state != SOCKET_LOG_DISCONNECTED) { - nn::Result result = nn::socket::Close(this->socket_log_socket); - if (result.isSuccess()) { - this->socket_log_state = SOCKET_LOG_DISCONNECTED; - } - return result.isSuccess(); - } + if (this->socket_log_state != SOCKET_LOG_DISCONNECTED) { + nn::Result result = nn::socket::Close(this->socket_log_socket); + if (result.isSuccess()) { + this->socket_log_state = SOCKET_LOG_DISCONNECTED; + } + return result.isSuccess(); + } - return true; + return true; } From 76d61a8067f6a2bf078dcee2ce6dd3aef36f94a3 Mon Sep 17 00:00:00 2001 From: Jack Garrard Date: Sat, 29 Oct 2022 18:21:58 -0700 Subject: [PATCH 39/50] Success and receive spelling --- include/game/System/GameSystemInfo.h | 4 ++-- include/server/Client.hpp | 2 +- source/puppets/PuppetHolder.cpp | 4 ++-- source/server/Client.cpp | 14 +++++++------- source/server/SocketClient.cpp | 6 +++--- source/server/logger.cpp | 4 ++-- 6 files changed, 17 insertions(+), 17 deletions(-) diff --git a/include/game/System/GameSystemInfo.h b/include/game/System/GameSystemInfo.h index b187ac6..49aaa24 100644 --- a/include/game/System/GameSystemInfo.h +++ b/include/game/System/GameSystemInfo.h @@ -37,8 +37,8 @@ namespace al { al::GameDrawInfo *mDrawInfo; // 0x38 from Application::sInstance + 0x30 ProjectNfpDirector *mProjNfpDirector; // 0x48 al::HtmlViewer *mHtmlViewer; // 0x50 - ApplicationMessageReceiver *mMessageReciever; // 0x58 + ApplicationMessageReceiver *mMessageReceiver; // 0x58 al::WaveVibrationHolder *mWaveVibrationHolder; // 0x60 void *gap2; }; -} \ No newline at end of file +} diff --git a/include/server/Client.hpp b/include/server/Client.hpp index 51edd92..188c9b5 100644 --- a/include/server/Client.hpp +++ b/include/server/Client.hpp @@ -219,7 +219,7 @@ class Client { // --- Server Syncing Members --- - // array of shine IDs for checking if multiple shines have been collected in quick sucession, all moons within the players stage that match the ID will be deleted + // array of shine IDs for checking if multiple shines have been collected in quick succession, all moons within the players stage that match the ID will be deleted sead::SafeArray curCollectedShines; int collectedShineCount = 0; diff --git a/source/puppets/PuppetHolder.cpp b/source/puppets/PuppetHolder.cpp index f730c7b..ebfb672 100644 --- a/source/puppets/PuppetHolder.cpp +++ b/source/puppets/PuppetHolder.cpp @@ -17,7 +17,7 @@ PuppetHolder::PuppetHolder(int size) { * @brief resizes puppet ptr array by creating a new ptr array and storing previous ptrs in it, before freeing the previous array * * @param size the size of the new ptr array - * @return returns true if resizing was sucessful + * @return returns true if resizing was successful */ bool PuppetHolder::resizeHolder(int size) { @@ -106,4 +106,4 @@ bool PuppetHolder::checkInfoIsInStage(PuppetInfo *info) { void PuppetHolder::setStageInfo(const char *stageName, u8 scenarioNo) { mStageName = stageName; mScenarioNo = scenarioNo; -} \ No newline at end of file +} diff --git a/source/server/Client.cpp b/source/server/Client.cpp index 4422e43..36bc2d7 100644 --- a/source/server/Client.cpp +++ b/source/server/Client.cpp @@ -90,13 +90,13 @@ void Client::init(al::LayoutInitInfo const &initInfo, GameDataHolderAccessor hol /** * @brief starts client read thread * - * @return true if read thread was sucessfully started + * @return true if read thread was succesfully started * @return false if read thread was unable to start, or thread was already started. */ bool Client::startThread() { if(mReadThread->isDone() ) { mReadThread->start(); - Logger::log("Read Thread Sucessfully Started.\n"); + Logger::log("Read Thread Successfully Started.\n"); return true; }else { Logger::log("Read Thread has already started! Or other unknown reason.\n"); @@ -132,7 +132,7 @@ void Client::restartConnection() { sInstance->mHeap->free(playerDC); if (sInstance->mSocket->closeSocket()) { - Logger::log("Sucessfully Closed Socket.\n"); + Logger::log("Succesfully Closed Socket.\n"); } Logger::log("Waiting for send/recv threads to finish.\n"); @@ -145,7 +145,7 @@ void Client::restartConnection() { if(sInstance->mSocket->getLogState() == SOCKET_LOG_CONNECTED) { - Logger::log("Reconnect Sucessful!\n"); + Logger::log("Reconnect Succesful!\n"); } else { Logger::log("Reconnect Unsuccessful.\n"); @@ -187,7 +187,7 @@ bool Client::startConnection() { if (mIsConnectionActive) { - Logger::log("Sucessful Connection. Waiting to recieve init packet.\n"); + Logger::log("Succesful Connection. Waiting to receive init packet.\n"); bool waitingForInitPacket = true; // wait for client init packet @@ -211,7 +211,7 @@ bool Client::startConnection() { mHeap->free(curPacket); } else { - Logger::log("Recieve failed! Stopping Connection.\n"); + Logger::log("Receive failed! Stopping Connection.\n"); mIsConnectionActive = false; waitingForInitPacket = false; } @@ -336,7 +336,7 @@ void Client::readFunc() { while(mIsConnectionActive) { - Packet *curPacket = mSocket->tryGetPacket(); // will block until a packet has been recieved, or socket disconnected + Packet *curPacket = mSocket->tryGetPacket(); // will block until a packet has been received, or socket disconnected if (curPacket) { diff --git a/source/server/SocketClient.cpp b/source/server/SocketClient.cpp index 3754ea0..d959140 100644 --- a/source/server/SocketClient.cpp +++ b/source/server/SocketClient.cpp @@ -104,7 +104,7 @@ nn::Result SocketClient::init(const char* ip, u16 port) { Logger::log("Socket fd: %d\n", socket_log_socket); - startThreads(); // start recv and send threads after sucessful connection + startThreads(); // start recv and send threads after succesful connection // send init packet to server once we connect (an issue with the server prevents this from working properly, waiting for a fix to implement) @@ -470,7 +470,7 @@ bool SocketClient::stringToIPAddress(const char* str, in_addr* out) { /** * @brief starts client read thread * - * @return true if read thread was sucessfully started + * @return true if read thread was successfully started * @return false if read thread was unable to start, or thread was already started. */ bool SocketClient::startThreads() { @@ -481,7 +481,7 @@ bool SocketClient::startThreads() { if(this->mRecvThread->isDone() && this->mSendThread->isDone()) { this->mRecvThread->start(); this->mSendThread->start(); - Logger::log("Socket threads sucessfully started.\n"); + Logger::log("Socket threads succesfully started.\n"); return true; }else { Logger::log("Socket threads failed to start.\n"); diff --git a/source/server/logger.cpp b/source/server/logger.cpp index 99fd356..038c18a 100644 --- a/source/server/logger.cpp +++ b/source/server/logger.cpp @@ -111,7 +111,7 @@ void Logger::log(const char* fmt, ...) { } bool Logger::pingSocket() { - return socket_log("ping") > 0; // if value is greater than zero, than the socket recieved our message, otherwise the connection was lost. + return socket_log("ping") > 0; // if value is greater than zero, than the socket received our message, otherwise the connection was lost. } void tryInitSocket() { @@ -119,4 +119,4 @@ void tryInitSocket() { #if DEBUGLOG Logger::createInstance(); // creates a static instance for debug logger #endif -} \ No newline at end of file +} From cd8bf4e257f2fe2b3f8e1a039ed91ac11a8edcf4 Mon Sep 17 00:00:00 2001 From: piplup <100526773+piplup55@users.noreply.github.com> Date: Mon, 5 Jun 2023 20:54:14 +0100 Subject: [PATCH 40/50] Update dev-release.yml --- .github/workflows/dev-release.yml | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/.github/workflows/dev-release.yml b/.github/workflows/dev-release.yml index 000ffea..44affa2 100644 --- a/.github/workflows/dev-release.yml +++ b/.github/workflows/dev-release.yml @@ -21,12 +21,11 @@ jobs: build: strategy: matrix: - emu : [ Switch, Ryujinx, yuzu ] + emu : [ Switch, Emulators ] runs-on: ubuntu-latest outputs: filename1: ${{ steps.set-output.outputs.filename-Switch }} - filename2: ${{ steps.set-output.outputs.filename-Ryujinx }} - filename3: ${{ steps.set-output.outputs.filename-yuzu }} + filename2: ${{ steps.set-output.outputs.filename-Emulators }}} steps: - name : Checkout @@ -73,19 +72,12 @@ jobs: upload_url : ${{ steps.release.outputs.upload_url }} GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }} - - name : Attach build artifacts to release (Ryujinx) + name : Attach build artifacts to release (Emulators) uses : ./.github/actions/attach with: filename : ${{ needs.build.outputs.filename2 }} upload_url : ${{ steps.release.outputs.upload_url }} GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }} - - - name : Attach build artifacts to release (yuzu) - uses : ./.github/actions/attach - with: - filename : ${{ needs.build.outputs.filename3 }} - upload_url : ${{ steps.release.outputs.upload_url }} - GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }} move: needs: attach From f8a3deefc4e63ad7d9a21963a3b8950f595099d8 Mon Sep 17 00:00:00 2001 From: piplup <100526773+piplup55@users.noreply.github.com> Date: Mon, 5 Jun 2023 20:58:28 +0100 Subject: [PATCH 41/50] a --- .github/workflows/build.yml | 2 +- .github/workflows/release.yml | 14 +++----------- 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 76179ae..66c84d8 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -22,7 +22,7 @@ jobs: build: strategy: matrix: - emu : [ Switch, Ryujinx, yuzu ] + emu : [ Switch, Emulator ] runs-on: ubuntu-latest steps: - diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 859a4d7..498101a 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -14,12 +14,11 @@ jobs: build: strategy: matrix: - emu : [ Switch, Ryujinx, yuzu ] + emu : [ Switch, Emulator ] runs-on: ubuntu-latest outputs: filename1: ${{ steps.set-output.outputs.filename-Switch }} - filename2: ${{ steps.set-output.outputs.filename-Ryujinx }} - filename3: ${{ steps.set-output.outputs.filename-yuzu }} + filename2: ${{ steps.set-output.outputs.filename-Emulator }} steps: - name : Checkout @@ -60,16 +59,9 @@ jobs: upload_url : ${{ steps.release.outputs.upload_url }} GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }} - - name : Attach build artifacts to release (Ryujinx) + name : Attach build artifacts to release (Emulator) uses : ./.github/actions/attach with: filename : ${{ needs.build.outputs.filename2 }} upload_url : ${{ steps.release.outputs.upload_url }} GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }} - - - name : Attach build artifacts to release (yuzu) - uses : ./.github/actions/attach - with: - filename : ${{ needs.build.outputs.filename3 }} - upload_url : ${{ steps.release.outputs.upload_url }} - GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }} From 41719e1f9f34a103a747c2c13cff75762c72bb33 Mon Sep 17 00:00:00 2001 From: piplup <100526773+piplup55@users.noreply.github.com> Date: Mon, 5 Jun 2023 21:02:29 +0100 Subject: [PATCH 42/50] a --- .github/actions/build/action.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/actions/build/action.yml b/.github/actions/build/action.yml index ec64178..3448e6d 100644 --- a/.github/actions/build/action.yml +++ b/.github/actions/build/action.yml @@ -11,7 +11,7 @@ inputs: required : false default : '' emu: - description : 'what system the build is for: Switch, Ryujinx or yuzu' + description : 'what system the build is for: Switch or Emulator' required : false default : 'Switch' @@ -64,7 +64,7 @@ runs: - name : Yuzu shell : bash - if : ${{ inputs.emu == 'yuzu' }} + if : ${{ inputs.emu == 'Emulator' }} run: | cd ./starlight_patch_100/ mkdir ./SMOO/ From 4d242a5e443038d5809ee2d5dfa98ddddd52d3c3 Mon Sep 17 00:00:00 2001 From: piplup <100526773+piplup55@users.noreply.github.com> Date: Mon, 5 Jun 2023 21:06:58 +0100 Subject: [PATCH 43/50] forgot to rename --- .github/actions/build/action.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/actions/build/action.yml b/.github/actions/build/action.yml index 3448e6d..454f7f2 100644 --- a/.github/actions/build/action.yml +++ b/.github/actions/build/action.yml @@ -50,7 +50,7 @@ runs: cache-from : type=gha,scope=smoo-build-env cache-to : type=gha,scope=smoo-build-env,mode=max - - name : Build mod + name : Switch shell : bash run: | docker run --rm \ @@ -62,7 +62,7 @@ runs: ; cp -r ./romfs/ ./starlight_patch_100/atmosphere/contents/0100000000010000/. - - name : Yuzu + name : Emulator shell : bash if : ${{ inputs.emu == 'Emulator' }} run: | From 936e0fd49ffe74ff1a264acbe0059af1cf2b8f1a Mon Sep 17 00:00:00 2001 From: piplup <100526773+piplup55@users.noreply.github.com> Date: Mon, 5 Jun 2023 21:56:27 +0100 Subject: [PATCH 44/50] addressed feedback --- .github/actions/build/action.yml | 8 ++++---- .github/workflows/build.yml | 2 +- .github/workflows/release.yml | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/actions/build/action.yml b/.github/actions/build/action.yml index 454f7f2..f82cf2f 100644 --- a/.github/actions/build/action.yml +++ b/.github/actions/build/action.yml @@ -11,7 +11,7 @@ inputs: required : false default : '' emu: - description : 'what system the build is for: Switch or Emulator' + description : 'what system the build is for: Switch or Emulators' required : false default : 'Switch' @@ -50,7 +50,7 @@ runs: cache-from : type=gha,scope=smoo-build-env cache-to : type=gha,scope=smoo-build-env,mode=max - - name : Switch + name : Build mod shell : bash run: | docker run --rm \ @@ -62,9 +62,9 @@ runs: ; cp -r ./romfs/ ./starlight_patch_100/atmosphere/contents/0100000000010000/. - - name : Emulator + name : Emulators shell : bash - if : ${{ inputs.emu == 'Emulator' }} + if : ${{ inputs.emu == 'Emulators' }} run: | cd ./starlight_patch_100/ mkdir ./SMOO/ diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 66c84d8..25259ca 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -22,7 +22,7 @@ jobs: build: strategy: matrix: - emu : [ Switch, Emulator ] + emu : [ Switch, Emulators ] runs-on: ubuntu-latest steps: - diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 498101a..9a4dad0 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -14,7 +14,7 @@ jobs: build: strategy: matrix: - emu : [ Switch, Emulator ] + emu : [ Switch, Emulators ] runs-on: ubuntu-latest outputs: filename1: ${{ steps.set-output.outputs.filename-Switch }} @@ -59,7 +59,7 @@ jobs: upload_url : ${{ steps.release.outputs.upload_url }} GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }} - - name : Attach build artifacts to release (Emulator) + name : Attach build artifacts to release (Emulators) uses : ./.github/actions/attach with: filename : ${{ needs.build.outputs.filename2 }} From b86322f346dbaf51c6aac9de28e71324205c66b7 Mon Sep 17 00:00:00 2001 From: Piplup <100526773+piplup55@users.noreply.github.com> Date: Tue, 6 Jun 2023 14:35:44 +0100 Subject: [PATCH 45/50] z --- .github/workflows/release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 9a4dad0..1d72252 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -18,7 +18,7 @@ jobs: runs-on: ubuntu-latest outputs: filename1: ${{ steps.set-output.outputs.filename-Switch }} - filename2: ${{ steps.set-output.outputs.filename-Emulator }} + filename2: ${{ steps.set-output.outputs.filename-Emulators }} steps: - name : Checkout From 83a1d70e01d942a7e58d287662cf89c5149f7829 Mon Sep 17 00:00:00 2001 From: Jack Garrard Date: Sat, 2 Sep 2023 20:37:05 -0700 Subject: [PATCH 46/50] Update readme to mention website --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ffaeefb..ed3b503 100644 --- a/README.md +++ b/README.md @@ -17,8 +17,10 @@ Welcome to the official repository for the Super Mario Odyssey Online mod! Have * 1.0 -## Installation Tutorial +## Installation +The following instructions are not through and complete as the website, as such please visit the [Super Mario Odyssey website](https://smoo.it). The old instructions are listed below for documentation sake. If you're having any trouble or issues, please make sure you've checked through the website. +## Installation Tutorial [DEPRECATED] Before installing, Ensure that your switch is hacked. If not, follow [This Guide](https://switch.homebrew.guide/) to get your switch setup for modding. Make sure you set up a way to block Nintendo's servers as you will need to have your switch connected to the internet for this mod to work! 1. Download the latest mod build from either [Gamebanana](https://gamebanana.com/mods/384214) or from the [Releases](https://github.com/CraftyBoss/SuperMarioOdysseyOnline/releases) tab. (Alternatively, build from source) From f27875f65f30aa081e7f12dd9806b3c398dcc4e7 Mon Sep 17 00:00:00 2001 From: Jack Garrard Date: Sun, 3 Sep 2023 18:39:03 -0700 Subject: [PATCH 47/50] Fix extra curly bracket --- .github/workflows/dev-release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/dev-release.yml b/.github/workflows/dev-release.yml index 44affa2..92bb0aa 100644 --- a/.github/workflows/dev-release.yml +++ b/.github/workflows/dev-release.yml @@ -25,7 +25,7 @@ jobs: runs-on: ubuntu-latest outputs: filename1: ${{ steps.set-output.outputs.filename-Switch }} - filename2: ${{ steps.set-output.outputs.filename-Emulators }}} + filename2: ${{ steps.set-output.outputs.filename-Emulators }} steps: - name : Checkout From b4d90d1d856ed32c660eec9e4e3308d572d0d130 Mon Sep 17 00:00:00 2001 From: "Robin C. Ladiges" Date: Thu, 7 Sep 2023 19:30:57 +0200 Subject: [PATCH 48/50] fix: add auto reconnect again --- source/server/SocketClient.cpp | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/source/server/SocketClient.cpp b/source/server/SocketClient.cpp index 24021a7..ecadc36 100644 --- a/source/server/SocketClient.cpp +++ b/source/server/SocketClient.cpp @@ -217,8 +217,7 @@ bool SocketClient::send(Packet *packet) { } else { Logger::log("Failed to Fully Send Packet! Result: %d Type: %s Packet Size: %d\n", valread, packetNames[packet->mType], packet->mPacketSize); this->socket_errno = nn::socket::GetLastErrno(); - this->closeSocket(); - return false; + return this->tryReconnect(); } return true; } @@ -228,8 +227,7 @@ bool SocketClient::recv() { if (this->socket_log_state != SOCKET_LOG_CONNECTED) { Logger::log("Unable To Receive! Socket Not Connected.\n"); this->socket_errno = nn::socket::GetLastErrno(); - this->closeSocket(); - return false; + return this->tryReconnect(); } const int fd_count = 2; @@ -253,8 +251,7 @@ bool SocketClient::recv() { } else if (result < 0) { Logger::log("Error occurred when polling for packets\n"); this->socket_errno = nn::socket::GetLastErrno(); - this->closeSocket(); - return false; + return this->tryReconnect(); } s32 index = -1; @@ -297,8 +294,7 @@ bool SocketClient::recvTcp() { return true; } else { Logger::log("Header Read Failed! Value: %d Total Read: %d\n", result, valread); - this->closeSocket(); - return false; + return this->tryReconnect(); } } } @@ -306,8 +302,7 @@ bool SocketClient::recvTcp() { if(valread <= 0) { // if we error'd, close the socket Logger::log("valread was zero! Disconnecting.\n"); this->socket_errno = nn::socket::GetLastErrno(); - this->closeSocket(); - return false; + return this->tryReconnect(); } Packet* header = reinterpret_cast(recvBuf); @@ -350,8 +345,7 @@ bool SocketClient::recvTcp() { } else { mHeap->free(packetBuf); Logger::log("Packet Read Failed! Value: %d\nPacket Size: %d\nPacket Type: %s\n", result, header->mPacketSize, packetNames[header->mType]); - this->closeSocket(); - return false; + return this->tryReconnect(); } } @@ -380,8 +374,7 @@ bool SocketClient::recvUdp() { if (valread == 0) { Logger::log("Udp connection valread was zero. Disconnecting.\n"); - this->closeSocket(); - return false; + return this->tryReconnect(); } if (valread < headerSize){ From d0dfb635199fbb081b6d8afd126ad93753236352 Mon Sep 17 00:00:00 2001 From: Jack Garrard Date: Mon, 11 Sep 2023 00:28:32 -0700 Subject: [PATCH 49/50] Simplify the readme for the average user and direct to website --- README.md | 70 ++++++++++++++++++++----------------------------------- 1 file changed, 25 insertions(+), 45 deletions(-) diff --git a/README.md b/README.md index ed3b503..f8d0c64 100644 --- a/README.md +++ b/README.md @@ -10,65 +10,45 @@ Welcome to the official repository for the Super Mario Odyssey Online mod! Have * Moon Collection is shared between all players * Custom Configuration Menu (Accessible by holding ZL and selecting any option in the pause/start menu) * Support for custom gamemodes (WIP) -### Available Gamemodes -* Hide and Seek + -## SMO Version Support +## Installation and Usage +For the typical installation along with how to setup and use muliplayer/hide and seek, please visit the [Super Mario Odyssey website](https://smoo.it). -* 1.0 +
-## Installation -The following instructions are not through and complete as the website, as such please visit the [Super Mario Odyssey website](https://smoo.it). The old instructions are listed below for documentation sake. If you're having any trouble or issues, please make sure you've checked through the website. +Developer build instructions -## Installation Tutorial [DEPRECATED] -Before installing, Ensure that your switch is hacked. If not, follow [This Guide](https://switch.homebrew.guide/) to get your switch setup for modding. Make sure you set up a way to block Nintendo's servers as you will need to have your switch connected to the internet for this mod to work! + ### Building Prerequisites -1. Download the latest mod build from either [Gamebanana](https://gamebanana.com/mods/384214) or from the [Releases](https://github.com/CraftyBoss/SuperMarioOdysseyOnline/releases) tab. (Alternatively, build from source) -2. Extract the downloaded zip onto the root of your Switch's SD card. -3. If you need to host an online server, head over to the [Super Mario Odyssey Online Server](https://github.com/Sanae6/SmoOnlineServer) repository and follow the instructions there to set up the server. -4. Launch the game! Upon first time bootup, the mod should ask for a server IP to save to the games common save file. This IP address will be the server you wish to connect to every time you launch the game with the mod installed. (Note: un-installing the mod and launching the game will remove the server IP from the common save file.) + - [devkitPro](https://devkitpro.org/) + - Python 3 + - The [Keystone-Engine](https://www.keystone-engine.org/) Python Module -## Gamemode Info -### Hide and Seek -* Depending on Group size, select who will start as seekers at the beginning of each round and a kingdom to hide in. -* Each player has a timer on the top right of the screen that will increase while they are hiding during a round. -* When a seeker gets close enough to a player, the player will die and respawn as a seeker. -* During the round, hiders who die by other means will also become seekers upon respawning. -* If a hider loads into a new stage (via a pipe, door, etc.) the hider will get 5 seconds of tag invincibility to prevent spawn point camping. -* The player with the most time at the end of a round (or set of rounds) is considered the winner. -* While not a concrete rule, it's generally agreed upon that hiding should not be done out of bounds, inside objects that don't sync across games yet, and inside objects that completely conceal a player from others (such as trees). + ### Building -## Gamemode Controls -### Hide and Seek -- Left D-Pad: Decrease time -- Right D-Pad: Increase Time -- L + D-Pad Down: Reset Time -- D-Pad Up: Switch from Hider/Seeker + Build has only been tested on WSL2 running Ubuntu 20.04.1. -## Building Prerequisites + Just run: + ``` + DEVKITPRO={path_to_devkitpro} make + ``` -- [devkitPro](https://devkitpro.org/) -- Python 3 -- The [Keystone-Engine](https://www.keystone-engine.org/) Python Module + On Ubuntu (and other Debian-based systems), devkitPro will be installed to `/opt/devkitpro` by default: -## Building + ``` + DEVKITPRO=/opt/devkitpro/ make + ``` -Build has only been tested on WSL2 running Ubuntu 20.04.1. + ### Installing (Atmosphère) -Just run: -``` -DEVKITPRO={path_to_devkitpro} make -``` + After a successful build, simply transfer the `atmosphere` folder located inside `starlight_patch_100` to the root of your switch's SD card. +
-On Ubuntu (and other Debian-based systems), devkitPro will be installed to `/opt/devkitpro` by default: +## Troubleshooting -``` -DEVKITPRO=/opt/devkitpro/ make -``` - -## Installing (Atmosphère) - -After a successful build, simply transfer the `atmosphere` folder located inside `starlight_patch_100` to the root of your switch's SD card. +The [Super Mario Odyssey website](https://smoo.it) has a FAQ section that should solve many issues. +However, for any further questions or help not covered by the site, please visit the [CraftyBoss Community Discord Server](discord.gg/jYCueK2BqD) and ask in the `help`/`help-2` channel. --- From 800ade78426ee25f0cccd60c0b20c5460ce9a307 Mon Sep 17 00:00:00 2001 From: Jack Garrard Date: Mon, 11 Sep 2023 12:51:47 -0700 Subject: [PATCH 50/50] Update website link to say online instead of implying smo directly --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f8d0c64..be15b4d 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ Welcome to the official repository for the Super Mario Odyssey Online mod! Have ## Installation and Usage -For the typical installation along with how to setup and use muliplayer/hide and seek, please visit the [Super Mario Odyssey website](https://smoo.it). +For the typical installation along with how to setup and use muliplayer/hide and seek, please visit the [Super Mario Odyssey Online website](https://smoo.it).
@@ -47,7 +47,7 @@ For the typical installation along with how to setup and use muliplayer/hide and ## Troubleshooting -The [Super Mario Odyssey website](https://smoo.it) has a FAQ section that should solve many issues. +The [Super Mario Odyssey Online website](https://smoo.it) has a FAQ section that should solve many issues. However, for any further questions or help not covered by the site, please visit the [CraftyBoss Community Discord Server](discord.gg/jYCueK2BqD) and ask in the `help`/`help-2` channel. ---