mirror of
https://github.com/CraftyBoss/SuperMarioOdysseyOnline.git
synced 2024-11-25 04:35:17 +00:00
server/logger: Support trying additional ports
This commit is contained in:
parent
62cc2a5102
commit
740f562906
1 changed files with 23 additions and 11 deletions
|
@ -2,6 +2,10 @@
|
|||
#include "helpers.hpp"
|
||||
#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;
|
||||
|
||||
void Logger::createInstance() {
|
||||
|
@ -51,17 +55,25 @@ nn::Result Logger::init(const char* ip, u16 port) {
|
|||
serverAddress.family = 2;
|
||||
|
||||
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;
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue