mirror of
https://github.com/CraftyBoss/SuperMarioOdysseyOnline.git
synced 2024-11-25 12:45:17 +00:00
Merge pull request #14 from VelocityRa/fixes0
Sync more info on connect, logging/debugging improvements, etc
This commit is contained in:
commit
dc07fa96a2
6 changed files with 52 additions and 24 deletions
|
@ -241,10 +241,10 @@ class Client {
|
||||||
|
|
||||||
int lastCollectedShine = -1;
|
int lastCollectedShine = -1;
|
||||||
|
|
||||||
PlayerInf lastPlayerInfPacket =
|
// Backups for our last player/game packets, used for example to re-send them for newly connected clients
|
||||||
PlayerInf(); // Info struct for storing our currently logged player information
|
PlayerInf lastPlayerInfPacket = PlayerInf();
|
||||||
|
|
||||||
GameInf lastGameInfPacket = GameInf();
|
GameInf lastGameInfPacket = GameInf();
|
||||||
|
CostumeInf lastCostumeInfPacket = CostumeInf();
|
||||||
|
|
||||||
Keyboard* mKeyboard = nullptr; // keyboard for setting server IP
|
Keyboard* mKeyboard = nullptr; // keyboard for setting server IP
|
||||||
|
|
||||||
|
|
|
@ -6,8 +6,12 @@ import sys
|
||||||
# Create a TCP/IP socket
|
# Create a TCP/IP socket
|
||||||
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
|
|
||||||
|
port = 3080
|
||||||
|
if len(sys.argv) == 3:
|
||||||
|
port = int(sys.argv[2])
|
||||||
|
|
||||||
# Bind the socket to the port
|
# Bind the socket to the port
|
||||||
server_address = (sys.argv[1], 3080)
|
server_address = (sys.argv[1], port)
|
||||||
print(f"Starting TCP Server with IP {server_address[0]} and Port {server_address[1]}.")
|
print(f"Starting TCP Server with IP {server_address[0]} and Port {server_address[1]}.")
|
||||||
sock.bind(server_address)
|
sock.bind(server_address)
|
||||||
|
|
||||||
|
@ -35,3 +39,4 @@ while True:
|
||||||
finally:
|
finally:
|
||||||
# Clean up the connection
|
# Clean up the connection
|
||||||
connection.close()
|
connection.close()
|
||||||
|
|
||||||
|
|
|
@ -346,7 +346,7 @@ bool hakoniwaSequenceHook(HakoniwaSequence* sequence) {
|
||||||
if(debugPuppetIndex < 0) {
|
if(debugPuppetIndex < 0) {
|
||||||
debugPuppetIndex = playBufSize - 2;
|
debugPuppetIndex = playBufSize - 2;
|
||||||
}
|
}
|
||||||
if (debugPuppetIndex >= playBufSize)
|
if (debugPuppetIndex >= playBufSize - 1)
|
||||||
debugPuppetIndex = 0;
|
debugPuppetIndex = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -435,15 +435,20 @@ void Client::readFunc() {
|
||||||
break;
|
break;
|
||||||
case PacketType::PLAYERCON:
|
case PacketType::PLAYERCON:
|
||||||
updatePlayerConnect((PlayerConnect*)curPacket);
|
updatePlayerConnect((PlayerConnect*)curPacket);
|
||||||
// send game info packet when client recieves connection
|
|
||||||
|
|
||||||
if (lastGameInfPacket.mUserID != mUserID) {
|
// Send relevant info packets when another client is connected
|
||||||
// assume game info packet is empty from first connection
|
|
||||||
|
// Assume game packets are empty from first connection
|
||||||
|
if (lastGameInfPacket.mUserID != mUserID)
|
||||||
lastGameInfPacket.mUserID = mUserID;
|
lastGameInfPacket.mUserID = mUserID;
|
||||||
// leave rest blank
|
|
||||||
}
|
|
||||||
|
|
||||||
mSocket->SEND(&lastGameInfPacket);
|
mSocket->SEND(&lastGameInfPacket);
|
||||||
|
|
||||||
|
// No need to send player/costume packets if they're empty
|
||||||
|
if (lastPlayerInfPacket.mUserID == mUserID)
|
||||||
|
mSocket->SEND(&lastPlayerInfPacket);
|
||||||
|
if (lastCostumeInfPacket.mUserID == mUserID)
|
||||||
|
mSocket->SEND(&lastCostumeInfPacket);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case PacketType::COSTUMEINF:
|
case PacketType::COSTUMEINF:
|
||||||
updateCostumeInfo((CostumeInf*)curPacket);
|
updateCostumeInfo((CostumeInf*)curPacket);
|
||||||
|
@ -698,6 +703,7 @@ void Client::sendCostumeInfPacket(const char* body, const char* cap) {
|
||||||
CostumeInf packet = CostumeInf(body, cap);
|
CostumeInf packet = CostumeInf(body, cap);
|
||||||
packet.mUserID = sInstance->mUserID;
|
packet.mUserID = sInstance->mUserID;
|
||||||
sInstance->mSocket->SEND(&packet);
|
sInstance->mSocket->SEND(&packet);
|
||||||
|
sInstance->lastCostumeInfPacket = packet;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -77,7 +77,8 @@ bool SocketClient::SEND(Packet *packet) {
|
||||||
|
|
||||||
int valread = 0;
|
int valread = 0;
|
||||||
|
|
||||||
//Logger::log("Sending Packet Size: %d Sending Type: %s\n", packet->mPacketSize, packetNames[packet->mType]);
|
if (packet->mType != PLAYERINF && packet->mType != HACKCAPINF)
|
||||||
|
Logger::log("Sending packet: %s\n", packetNames[packet->mType]);
|
||||||
|
|
||||||
if ((valread = nn::socket::Send(this->socket_log_socket, buffer, packet->mPacketSize + sizeof(Packet), this->sock_flags) > 0)) {
|
if ((valread = nn::socket::Send(this->socket_log_socket, buffer, packet->mPacketSize + sizeof(Packet), this->sock_flags) > 0)) {
|
||||||
return true;
|
return true;
|
||||||
|
@ -93,7 +94,7 @@ bool SocketClient::SEND(Packet *packet) {
|
||||||
bool SocketClient::RECV() {
|
bool SocketClient::RECV() {
|
||||||
|
|
||||||
if (this->socket_log_state != SOCKET_LOG_CONNECTED) {
|
if (this->socket_log_state != SOCKET_LOG_CONNECTED) {
|
||||||
Logger::log("Unable To Recieve! Socket Not Connected.\n");
|
Logger::log("Unable To Receive! Socket Not Connected.\n");
|
||||||
this->socket_errno = nn::socket::GetLastErrno();
|
this->socket_errno = nn::socket::GetLastErrno();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -122,6 +123,10 @@ bool SocketClient::RECV() {
|
||||||
|
|
||||||
if (header->mType != PacketType::UNKNOWN && fullSize <= MAXPACKSIZE && fullSize > 0) {
|
if (header->mType != PacketType::UNKNOWN && fullSize <= MAXPACKSIZE && fullSize > 0) {
|
||||||
|
|
||||||
|
if (header->mType != PLAYERINF && header->mType != HACKCAPINF)
|
||||||
|
Logger::log("Received packet (from %02X%02X): %s\n",
|
||||||
|
header->mUserID.data[0], header->mUserID.data[1], packetNames[header->mType]);
|
||||||
|
|
||||||
char* packetBuf = (char*)malloc(fullSize);
|
char* packetBuf = (char*)malloc(fullSize);
|
||||||
|
|
||||||
if (packetBuf) {
|
if (packetBuf) {
|
||||||
|
|
|
@ -2,6 +2,10 @@
|
||||||
#include "helpers.hpp"
|
#include "helpers.hpp"
|
||||||
#include "nn/result.h"
|
#include "nn/result.h"
|
||||||
|
|
||||||
|
// If connection fails, try X ports above the specified one
|
||||||
|
// Useful for debugging multple clients on the same machine
|
||||||
|
constexpr u32 ADDITIONAL_LOG_PORT_COUNT = 2;
|
||||||
|
|
||||||
Logger* Logger::sInstance = nullptr;
|
Logger* Logger::sInstance = nullptr;
|
||||||
|
|
||||||
void Logger::createInstance() {
|
void Logger::createInstance() {
|
||||||
|
@ -51,17 +55,25 @@ nn::Result Logger::init(const char* ip, u16 port) {
|
||||||
serverAddress.family = 2;
|
serverAddress.family = 2;
|
||||||
|
|
||||||
nn::Result result;
|
nn::Result result;
|
||||||
|
bool connected = false;
|
||||||
|
for (u32 i = 0; i < ADDITIONAL_LOG_PORT_COUNT + 1; ++i) {
|
||||||
|
result = nn::socket::Connect(this->socket_log_socket, &serverAddress, sizeof(serverAddress));
|
||||||
|
if (result.isSuccess()) {
|
||||||
|
connected = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
this->port++;
|
||||||
|
serverAddress.port = nn::socket::InetHtons(this->port);
|
||||||
|
}
|
||||||
|
|
||||||
if ((result = nn::socket::Connect(this->socket_log_socket, &serverAddress, sizeof(serverAddress))).isFailure()) {
|
if (connected) {
|
||||||
|
this->socket_log_state = SOCKET_LOG_CONNECTED;
|
||||||
|
this->isDisableName = false;
|
||||||
|
return 0;
|
||||||
|
} else {
|
||||||
this->socket_log_state = SOCKET_LOG_UNAVAILABLE;
|
this->socket_log_state = SOCKET_LOG_UNAVAILABLE;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
this->socket_log_state = SOCKET_LOG_CONNECTED;
|
|
||||||
|
|
||||||
this->isDisableName = false;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Logger::log(const char *fmt, va_list args) { // impl for replacing seads system::print
|
void Logger::log(const char *fmt, va_list args) { // impl for replacing seads system::print
|
||||||
|
|
Loading…
Reference in a new issue