mirror of
https://github.com/CraftyBoss/SuperMarioOdysseyOnline.git
synced 2024-11-22 11:15:15 +00:00
Merge pull request #2 from CraftyBoss/revert-1-dev
Revert "remove fixed buffer size from logger (+ run clang-format)"
This commit is contained in:
commit
063e20677f
1 changed files with 31 additions and 41 deletions
|
@ -1,8 +1,6 @@
|
||||||
#include "logger.hpp"
|
#include "logger.hpp"
|
||||||
#include "helpers.hpp"
|
#include "helpers.hpp"
|
||||||
#include "nn/result.h"
|
#include "nn/result.h"
|
||||||
#include "nn/util.h"
|
|
||||||
#include "nx/svc.h"
|
|
||||||
|
|
||||||
Logger* Logger::sInstance = nullptr;
|
Logger* Logger::sInstance = nullptr;
|
||||||
|
|
||||||
|
@ -15,6 +13,7 @@ void Logger::createInstance() {
|
||||||
}
|
}
|
||||||
|
|
||||||
nn::Result Logger::init(const char* ip, u16 port) {
|
nn::Result Logger::init(const char* ip, u16 port) {
|
||||||
|
|
||||||
sock_ip = ip;
|
sock_ip = ip;
|
||||||
|
|
||||||
this->port = port;
|
this->port = port;
|
||||||
|
@ -28,8 +27,7 @@ nn::Result Logger::init(const char* ip, u16 port) {
|
||||||
nn::nifm::Initialize();
|
nn::nifm::Initialize();
|
||||||
nn::nifm::SubmitNetworkRequest();
|
nn::nifm::SubmitNetworkRequest();
|
||||||
|
|
||||||
while (nn::nifm::IsNetworkRequestOnHold()) {
|
while (nn::nifm::IsNetworkRequestOnHold()) { }
|
||||||
}
|
|
||||||
|
|
||||||
// emulators make this return false always, so skip it during init
|
// emulators make this return false always, so skip it during init
|
||||||
#ifndef EMU
|
#ifndef EMU
|
||||||
|
@ -54,9 +52,7 @@ nn::Result Logger::init(const char* ip, u16 port) {
|
||||||
|
|
||||||
nn::Result result;
|
nn::Result result;
|
||||||
|
|
||||||
if ((result =
|
if ((result = nn::socket::Connect(this->socket_log_socket, &serverAddress, sizeof(serverAddress))).isFailure()) {
|
||||||
nn::socket::Connect(this->socket_log_socket, &serverAddress, sizeof(serverAddress)))
|
|
||||||
.isFailure()) {
|
|
||||||
this->socket_log_state = SOCKET_LOG_UNAVAILABLE;
|
this->socket_log_state = SOCKET_LOG_UNAVAILABLE;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -87,30 +83,23 @@ void Logger::log(const char* fmt, ...) {
|
||||||
va_list args;
|
va_list args;
|
||||||
va_start(args, fmt);
|
va_start(args, fmt);
|
||||||
|
|
||||||
size_t bufSize = nn::util::VSNPrintf(nullptr, 0, fmt, args);
|
char buf[0x500];
|
||||||
size_t prefixSize = bufSize += 3 /* "[] " */ + strlen(sInstance->sockName);
|
|
||||||
if (!sInstance->isDisableName)
|
|
||||||
bufSize += prefixSize;
|
|
||||||
char buf[bufSize];
|
|
||||||
|
|
||||||
if (sInstance->isDisableName)
|
|
||||||
nn::util::VSNPrintf(buf, bufSize, fmt, args);
|
|
||||||
else {
|
|
||||||
nn::util::VSNPrintf(buf + prefixSize, bufSize - prefixSize, fmt, args);
|
|
||||||
nn::util::SNPrintf(buf, prefixSize, "[%s] ", sInstance->sockName);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if (nn::util::VSNPrintf(buf, sizeof(buf), fmt, args) > 0) {
|
||||||
|
if (!sInstance->isDisableName) {
|
||||||
|
char prefix[0x510];
|
||||||
|
nn::util::SNPrintf(prefix, sizeof(prefix), "[%s] %s", sInstance->sockName, buf);
|
||||||
|
sInstance->socket_log(prefix);
|
||||||
|
} else {
|
||||||
sInstance->socket_log(buf);
|
sInstance->socket_log(buf);
|
||||||
#ifdef EMU
|
}
|
||||||
svcOutputDebugString(buf, bufSize);
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
va_end(args);
|
va_end(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Logger::pingSocket() {
|
bool Logger::pingSocket() {
|
||||||
return socket_log("ping") > 0; // if value is greater than zero, than the socket recieved our
|
return socket_log("ping") > 0; // if value is greater than zero, than the socket recieved our message, otherwise the connection was lost.
|
||||||
// message, otherwise the connection was lost.
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void tryInitSocket() {
|
void tryInitSocket() {
|
||||||
|
@ -119,3 +108,4 @@ void tryInitSocket() {
|
||||||
Logger::createInstance(); // creates a static instance for debug logger
|
Logger::createInstance(); // creates a static instance for debug logger
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue