diff --git a/source/Map.cpp b/source/Map.cpp index 3dc9cc2..90492b2 100644 --- a/source/Map.cpp +++ b/source/Map.cpp @@ -9,6 +9,11 @@ #include #include +#include +#include +#include +#include +#include #include "Graphics/BasicVertices.h" #include "Graphics/LineRenderer.h" @@ -36,6 +41,12 @@ float lerp(float a, float b, float t) return a * (1.0 - t) + (b * t); } +bool IsApplet() +{ + AppletType at = appletGetAppletType(); + return (at != AppletType_Application && at != AppletType_SystemApplication); +} + void Map::Init() { Log("LoadFromJSON "); @@ -496,11 +507,25 @@ void Map::Render() } // Toggle QR code - if (padGetButtonsDown(m_Pad) & HidNpadButton_X) + if ((padGetButtonsDown(m_Pad) & HidNpadButton_X) && IsApplet()) // Fails to get local ip adress in application mode { if (!m_QrCodeImage.m_Show) { - u32 ip = gethostid(); + Log("Checking internet connection"); + + /*char *ipBuffer; + char hostbuffer[256]; + gethostname(hostbuffer, sizeof(hostbuffer)); + struct hostent* host_entry = gethostbyname(hostbuffer); + + ipBuffer = inet_ntoa(*((struct in_addr*) + host_entry->h_addr_list[0])); + + std::string ipAdress = ipBuffer;*/ + + + uint32_t ip = gethostid(); + if (ip == INADDR_LOOPBACK) { Log("Not connected to internet. Cant generate Qr code"); @@ -528,6 +553,7 @@ void Map::Render() m_Font.m_ViewMatrix = &m_ViewMatrix; + Log("Creating qr code and saving it"); std::string url = "http://" + ipString + ":1234/" + filename; std::string filepath = "sdmc:/switch/totk-unexplored/" + filename; SaveMapImage(filepath); @@ -559,15 +585,15 @@ void Map::Render() if (!m_Legend->m_IsOpen && !m_ObjectInfo->m_IsOpen && SavefileIO::Get().LoadedSavefile) m_Font.AddTextToBatch("Press B to open legend", glm::vec2(m_ScreenLeft + 20, m_ScreenTop - 30), 0.5f); - if (!m_QrCodeImage.m_Show && SavefileIO::Get().LoadedSavefile) + if (!m_QrCodeImage.m_Show && SavefileIO::Get().LoadedSavefile && IsApplet()) m_Font.AddTextToBatch("Press X show QR Code", glm::vec2(m_ScreenRight - 20, m_ScreenTop - 30), 0.5f, glm::vec3(1.0f), ALIGN_RIGHT); if (SavefileIO::Get().LoadedSavefile) { if (SavefileIO::Get().GameIsRunning) { - m_Font.AddTextToBatch("Totk is running.", glm::vec2(m_ScreenRight - 20, m_ScreenTop - 30), 0.5f, glm::vec3(1.0f), ALIGN_RIGHT); - m_Font.AddTextToBatch("Loaded older save", glm::vec2(m_ScreenRight - 20, m_ScreenTop - 60), 0.5f, glm::vec3(1.0f), ALIGN_RIGHT); + m_Font.AddTextToBatch("Totk is running.", glm::vec2(m_ScreenRight - 20, m_ScreenTop - 60), 0.5f, glm::vec3(1.0f), ALIGN_RIGHT); + m_Font.AddTextToBatch("Loaded older save", glm::vec2(m_ScreenRight - 20, m_ScreenTop - 90), 0.5f, glm::vec3(1.0f), ALIGN_RIGHT); } float bottomTextX = m_ScreenRight - 30; diff --git a/source/Network/HttpServer.cpp b/source/Network/HttpServer.cpp index f86ce88..4233f91 100644 --- a/source/Network/HttpServer.cpp +++ b/source/Network/HttpServer.cpp @@ -5,6 +5,13 @@ #include #include #include +#include +#include +#include +#include +#include +#include +#include #include #include @@ -32,8 +39,28 @@ void HttpServer::Stop() void HttpServer::ThreadEntryPoint(int port) { // Check if online - u32 ip = gethostid(); - if (ip == INADDR_LOOPBACK) // Offline + // char *ipBuffer; + // char hostbuffer[256]; + // gethostname(hostbuffer, sizeof(hostbuffer)); + // struct hostent* host_entry = gethostbyname(hostbuffer); + + // ipBuffer = inet_ntoa(*((struct in_addr*) + // host_entry->h_addr_list[0])); + + // std::string ipAdress = ipBuffer; + + + // std::cout << ipAdress << "\n"; + + // if (ipAdress == "127.0.0.1") + // { + // Log("Not connected to internet, not starting server"); + // return; + // } + + // Check if online + uint32_t ip = gethostid(); + if (ip == INADDR_LOOPBACK) return; // Create socket @@ -49,7 +76,7 @@ void HttpServer::ThreadEntryPoint(int port) Log("Error calling fcntl"); // handle the error. By the way, I've never seen fcntl fail in this way } - + // Prepare the sockaddr_in structure m_Server.sin_family = AF_INET; // TCP m_Server.sin_addr.s_addr = INADDR_ANY;