mirror of
https://github.com/CraftyBoss/SuperMarioOdysseyOnline.git
synced 2024-11-22 03:05:16 +00:00
Merge pull request #13 from VelocityRa/serverconfig-fixes
Server Config fixes
This commit is contained in:
commit
4b83934a47
7 changed files with 63 additions and 48 deletions
|
@ -32,7 +32,7 @@ class SocketBase {
|
|||
const char *sock_ip;
|
||||
|
||||
u16 port;
|
||||
u8 socket_log_state;
|
||||
u8 socket_log_state = SOCKET_LOG_UNINITIALIZED;
|
||||
s32 socket_log_socket;
|
||||
|
||||
int sock_flags;
|
||||
|
|
|
@ -252,6 +252,7 @@ class Client {
|
|||
|
||||
int mServerPort = 0;
|
||||
|
||||
bool waitForGameInit = true;
|
||||
bool isFirstConnect = true;
|
||||
|
||||
// --- Game Layouts ---
|
||||
|
|
|
@ -22,12 +22,16 @@ while True:
|
|||
print(f'Switch Connected! IP: {client_address[0]} Port: {client_address[1]}')
|
||||
while True:
|
||||
data = connection.recv(1024)
|
||||
|
||||
if data:
|
||||
print(data.decode("utf-8"), end='', flush=True)
|
||||
else:
|
||||
print(f'Connection Terminated.')
|
||||
break
|
||||
|
||||
except ConnectionResetError:
|
||||
print("Connection reset")
|
||||
|
||||
finally:
|
||||
# Clean up the connection
|
||||
connection.close()
|
|
@ -137,6 +137,7 @@ void drawMainHook(HakoniwaSequence *curSequence, sead::Viewport *viewport, sead:
|
|||
gTextWriter->printf("Is in Capture: %s\n", curPupInfo->isCaptured ? "True" : "False");
|
||||
gTextWriter->printf("Puppet Stage: %s\n", curPupInfo->stageName);
|
||||
gTextWriter->printf("Puppet Scenario: %u\n", curPupInfo->scenarioNo);
|
||||
gTextWriter->printf("Puppet Costume: H: %s B: %s\n", curPupInfo->costumeHead, curPupInfo->costumeBody);
|
||||
//gTextWriter->printf("Packet Coords:\nX: %f\nY: %f\nZ: %f\n", curPupInfo->playerPos.x, curPupInfo->playerPos.y, curPupInfo->playerPos.z);
|
||||
// if (curModel) {
|
||||
// sead::Vector3f* pupPos = al::getTrans(curModel);
|
||||
|
|
|
@ -215,14 +215,16 @@ bool Client::startConnection() {
|
|||
Client::openKeyboardPort();
|
||||
}
|
||||
|
||||
bool result = mSocket->init(mServerIP.cstr(), mServerPort).isSuccess();
|
||||
bool socketConnected = mSocket->isConnected();
|
||||
if (!socketConnected) {
|
||||
socketConnected = mSocket->init(mServerIP.cstr(), mServerPort).isSuccess();
|
||||
}
|
||||
|
||||
if (result) {
|
||||
bool clientConnected = false;
|
||||
if (socketConnected) {
|
||||
// wait for client init packet
|
||||
while (true) {
|
||||
|
||||
if (mSocket->RECV()) {
|
||||
|
||||
Packet* curPacket = mSocket->mPacketQueue.popFront();
|
||||
|
||||
if (curPacket->mType == PacketType::CLIENTINIT) {
|
||||
|
@ -232,21 +234,20 @@ bool Client::startConnection() {
|
|||
|
||||
maxPuppets = initPacket->maxPlayers - 1;
|
||||
|
||||
clientConnected = true;
|
||||
} else {
|
||||
Logger::log("First Packet was not Init!\n");
|
||||
result = false;
|
||||
clientConnected = false;
|
||||
}
|
||||
|
||||
free(curPacket);
|
||||
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return result;
|
||||
return clientConnected;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -317,9 +318,10 @@ void Client::openKeyboardPort() {
|
|||
*/
|
||||
void Client::readFunc() {
|
||||
|
||||
if (isFirstConnect) {
|
||||
if (waitForGameInit) {
|
||||
nn::os::YieldThread(); // sleep the thread for the first thing we do so that game init can finish
|
||||
nn::os::SleepThread(nn::TimeSpan::FromSeconds(2));
|
||||
waitForGameInit = false;
|
||||
}
|
||||
|
||||
// we can use the start of readFunc to display an al::WindowConfirmWait while the server
|
||||
|
@ -398,7 +400,8 @@ void Client::readFunc() {
|
|||
mSocket->SEND(&initPacket); // re-send init packet as reconnect packet
|
||||
mConnectionWait->tryEnd();
|
||||
continue;
|
||||
|
||||
} else {
|
||||
Logger::log("%s: not reconnected\n", __func__);
|
||||
}
|
||||
|
||||
nn::os::YieldThread(); // if we're currently waiting on the socket to be initialized, wait until it is
|
||||
|
@ -449,7 +452,7 @@ void Client::readFunc() {
|
|||
updateShineInfo((ShineCollect*)curPacket);
|
||||
break;
|
||||
case PacketType::PLAYERDC:
|
||||
Logger::log("Recieved Player Disconnect!\n");
|
||||
Logger::log("Received Player Disconnect!\n");
|
||||
curPacket->mUserID.print();
|
||||
disconnectPlayer((PlayerDC*)curPacket);
|
||||
break;
|
||||
|
@ -780,19 +783,19 @@ void Client::updatePlayerInfo(PlayerInf *packet) {
|
|||
|
||||
if (packet->actName != PlayerAnims::Type::Unknown) {
|
||||
strcpy(curInfo->curAnimStr, PlayerAnims::FindStr(packet->actName));
|
||||
if (curInfo->curAnimStr[0] == '\0')
|
||||
Logger::log("[ERROR] %s: actName was out of bounds: %d\n", __func__, packet->actName);
|
||||
} else {
|
||||
strcpy(curInfo->curAnimStr, "Wait");
|
||||
}
|
||||
if (strlen(curInfo->curAnimStr) == 0)
|
||||
Logger::log("[ERROR] %s: actName was out of bounds: %d", __func__, packet->actName);
|
||||
|
||||
if(packet->subActName != PlayerAnims::Type::Unknown) {
|
||||
strcpy(curInfo->curSubAnimStr, PlayerAnims::FindStr(packet->subActName));
|
||||
if (curInfo->curSubAnimStr[0] == '\0')
|
||||
Logger::log("[ERROR] %s: subActName was out of bounds: %d\n", __func__, packet->subActName);
|
||||
} else {
|
||||
strcpy(curInfo->curSubAnimStr, "");
|
||||
}
|
||||
if (strlen(curInfo->curSubAnimStr) == 0)
|
||||
Logger::log("[ERROR] %s: subActName was out of bounds: %d", __func__, packet->subActName);
|
||||
|
||||
curInfo->curAnim = packet->actName;
|
||||
curInfo->curSubAnim = packet->subActName;
|
||||
|
|
|
@ -17,8 +17,7 @@ nn::Result SocketClient::init(const char* ip, u16 port) {
|
|||
in_addr hostAddress = { 0 };
|
||||
sockaddr serverAddress = { 0 };
|
||||
|
||||
if (socket_log_state != SOCKET_LOG_UNINITIALIZED && socket_log_state != SOCKET_LOG_DISCONNECTED)
|
||||
return -1;
|
||||
Logger::log("SocketClient::init: %s:%d sock %s\n", ip, port, getStateChar());
|
||||
|
||||
nn::nifm::Initialize();
|
||||
nn::nifm::SubmitNetworkRequest();
|
||||
|
|
|
@ -183,7 +183,7 @@ void StageSceneStateServerConfig::exeOpenKeyboardPort() {
|
|||
|
||||
Client::getKeyboard()->setHeaderText(u"Set a Server Port Below.");
|
||||
Client::getKeyboard()->setSubText(u"");
|
||||
Client::openKeyboardIP();
|
||||
Client::openKeyboardPort();
|
||||
// anything that happens after this will be ran after the keyboard closes
|
||||
al::startHitReaction(mCurrentMenu, "リセット", 0);
|
||||
al::setNerve(this, &nrvStageSceneStateServerConfigMainMenu);
|
||||
|
@ -193,14 +193,21 @@ void StageSceneStateServerConfig::exeOpenKeyboardPort() {
|
|||
void StageSceneStateServerConfig::exeRestartServer() {
|
||||
if (al::isFirstStep(this)) {
|
||||
mCurrentList->deactivate();
|
||||
Logger::log("Stopping connection\n");
|
||||
Client::stopConnection();
|
||||
}
|
||||
|
||||
if (Client::isSocketActive()) {
|
||||
auto* client = Client::sInstance;
|
||||
|
||||
if (client) {
|
||||
Logger::log("%s: Socket state: %s\n", __func__, client->mSocket->getStateChar());
|
||||
|
||||
client->StartThreads();
|
||||
}
|
||||
|
||||
al::startHitReaction(mCurrentMenu, "リセット", 0);
|
||||
al::setNerve(this, &nrvStageSceneStateServerConfigMainMenu);
|
||||
}
|
||||
}
|
||||
|
||||
void StageSceneStateServerConfig::exeGamemodeConfig() {
|
||||
if (al::isFirstStep(this)) {
|
||||
|
|
Loading…
Reference in a new issue