Empezado a escribir datos de estadisticas en el servidor

This commit is contained in:
2022-11-19 12:07:36 +01:00
parent bc84968b23
commit c35be7d21c
5 changed files with 50 additions and 12 deletions

View File

@@ -1,11 +1,13 @@
#include "stats.h"
#include "common/jscore.h"
#include <iostream>
#include <fstream>
#include <sstream>
// Constructor
Stats::Stats(std::string file)
Stats::Stats(std::string file, options_t *options)
{
this->options = options;
filePath = file;
list.clear();
loadFromFile();
@@ -17,6 +19,7 @@ Stats::~Stats()
#ifndef DEBUG
saveToFile();
#endif
saveToServer();
list.clear();
}
@@ -131,6 +134,15 @@ bool Stats::loadFromFile()
return success;
}
// Carga las estadisticas desde un servidor
bool Stats::loadFromServer()
{
if (options->online.enabled)
{
jscore::getUserData(options->online.gameID, options->online.jailerID);
}
}
// Guarda las estadisticas en un fichero
void Stats::saveToFile()
{
@@ -155,4 +167,17 @@ void Stats::saveToFile()
// Cierra el fichero
file.close();
}
// Guarda las estadisticas en un servidor
void Stats::saveToServer()
{
if (options->online.enabled)
{
for (auto item : list)
{
const std::string data = item.name + ";" + std::to_string(item.visited) + ";" + std::to_string(item.died);
jscore::setUserData(options->online.gameID, options->online.jailerID, data);
}
}
}