From 3e7aeeedbf84987c386df057c9ce22deeb551403 Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Sun, 24 Sep 2023 10:02:03 +0200 Subject: [PATCH] =?UTF-8?q?FIX:=20Ya=20inicia=20la=20sesi=C3=B3n=20online?= =?UTF-8?q?=20correctamente=20tras=20cambiar=20el=20JailerID?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/enter_id.cpp | 72 ++++++++++++++++++++++++++++++++------------- source/enter_id.h | 3 +- source/title.cpp | 2 +- 3 files changed, 54 insertions(+), 23 deletions(-) diff --git a/source/enter_id.cpp b/source/enter_id.cpp index 8138a34..46679fe 100644 --- a/source/enter_id.cpp +++ b/source/enter_id.cpp @@ -5,12 +5,13 @@ #include // Constructor -EnterID::EnterID(SDL_Renderer *renderer, Screen *screen, Asset *asset, options_t *options, section_t *section) +EnterID::EnterID(SDL_Renderer *renderer, Screen *screen, Asset *asset, Lang *lang, options_t *options, section_t *section) { // Copia la dirección de los objetos this->renderer = renderer; this->screen = screen; this->asset = asset; + this->lang = lang; this->options = options; this->section = section; @@ -256,30 +257,59 @@ void EnterID::fillTexture() void EnterID::initOnline() { if (options->online.sessionEnabled) - { // Si ya ha iniciado la sesión, que no continue - return; - } - - if (options->online.jailerID == "") - { // Jailer ID no definido - options->online.enabled = false; - } - else - { // Jailer ID iniciado - options->online.enabled = options->online.sessionEnabled = true; - jscore::init(options->online.server, options->online.port); + { // Si ya ha iniciado la sesión, que no continue + return; + } + if (options->online.jailerID == "") + { // Jailer ID no definido + options->online.enabled = false; + } + else + { // Jailer ID iniciado + options->online.enabled = options->online.sessionEnabled = true; + // Establece el servidor y el puerto + jscore::init(options->online.server, options->online.port); #ifdef DEBUG - const std::string caption = "IS LOGGED IN (DEBUG)"; + const std::string caption = options->online.jailerID + " (DEBUG)"; #else - const std::string caption = "IS LOGGED IN"; + const std::string caption = options->online.jailerID; #endif - screen->showNotification(options->online.jailerID, caption, 12); - if (options->console) - { - std::cout << caption << std::endl; - } - } + screen->showNotification(caption, lang->getText(85), 12); + if (options->console) + { + std::cout << caption << std::endl; + } + + // Obtiene la información de puntuaciones online + if (!jscore::initOnlineScore(options->online.gameID)) + { + screen->showNotification(lang->getText(80), options->online.server); + if (options->console) + { + std::cout << "Can't connect to " << options->online.server << std::endl; + } + + options->online.enabled = false; + + return; + } + + // Obten la puntuación online para el jailerID + const int points = jscore::getUserPoints(options->online.gameID, options->online.jailerID); + if (points == 0) + { // Fallo de conexión o no hay registros + screen->showNotification(lang->getText(81), lang->getText(82)); + if (options->console) + { + std::cout << "Can't get online scores" << std::endl; + } + } + else + { + options->online.score = points; + } + } } // Termina la sección diff --git a/source/enter_id.h b/source/enter_id.h index d4a98c7..a6d098a 100644 --- a/source/enter_id.h +++ b/source/enter_id.h @@ -25,6 +25,7 @@ private: Asset *asset; // Objeto con los ficheros de recursos options_t *options; // Puntero a las opciones del juego Screen *screen; // Objeto encargado de dibujar en pantalla + Lang *lang; // Objeto para gestionar los textos en diferentes idiomas SDL_Event *eventHandler; // Manejador de eventos SDL_Renderer *renderer; // El renderizador de la ventana SDL_Texture *textTexture; // Textura para dibujar el texto @@ -70,7 +71,7 @@ private: public: // Constructor - EnterID(SDL_Renderer *renderer, Screen *screen, Asset *asset, options_t *options, section_t *section); + EnterID(SDL_Renderer *renderer, Screen *screen, Asset *asset, Lang *lang, options_t *options, section_t *section); // Destructor ~EnterID(); diff --git a/source/title.cpp b/source/title.cpp index f45ba03..aebaffb 100644 --- a/source/title.cpp +++ b/source/title.cpp @@ -1025,7 +1025,7 @@ void Title::runDemoGame() // Introduce el JailerID void Title::runEnterID() { - enterID = new EnterID(renderer, screen, asset, options, section); + enterID = new EnterID(renderer, screen, asset, lang, options, section); enterID->run(); delete enterID; }