forked from jaildesigner-jailgames/jaildoctors_dilemma
Ya gestiona correctamente los datos online para diferentes usuarios
This commit is contained in:
@@ -9,36 +9,63 @@ Online::Online(options_t *options)
|
||||
{
|
||||
this->options = options;
|
||||
|
||||
if (options->console)
|
||||
{
|
||||
std::cout << "ONLINE object created\n"
|
||||
<< std::endl;
|
||||
}
|
||||
|
||||
allData = "";
|
||||
statsData = "";
|
||||
cheevosData = "";
|
||||
|
||||
STATS_FLAG_INI = "STATS_FLAG_INI";
|
||||
STATS_FLAG_END = "STATS_FLAG_END";
|
||||
CHEEVOS_FLAG_INI = "CHEEVOS_FLAG_INI";
|
||||
CHEEVOS_FLAG_END = "CHEEVOS_FLAG_END";
|
||||
STATS_FLAG_INI = ";STATS_FLAG_INI;";
|
||||
STATS_FLAG_END = ";STATS_FLAG_END;";
|
||||
CHEEVOS_FLAG_INI = ";CHEEVOS_FLAG_INI;";
|
||||
CHEEVOS_FLAG_END = ";CHEEVOS_FLAG_END;";
|
||||
|
||||
getAllData();
|
||||
std::cout << "allData: " << allData << std::endl;
|
||||
std::cout << "statsData: " << statsData << std::endl;
|
||||
std::cout << "cheevosData: " << cheevosData << std::endl;
|
||||
dataCached = false;
|
||||
dataSaved = "";
|
||||
getData();
|
||||
}
|
||||
|
||||
// Destructor
|
||||
Online::~Online()
|
||||
{
|
||||
sendData();
|
||||
}
|
||||
|
||||
// Obtiene todos los datos y los coloca en sus respectivas variables
|
||||
void Online::getAllData()
|
||||
void Online::getData()
|
||||
{
|
||||
if (!options->online.enabled)
|
||||
// Si el usuario es distinto del que hay cacheado, marca la cache como invalida y borra los datos
|
||||
if (jailerID.compare(options->online.jailerID) != 0)
|
||||
{
|
||||
allData = jscore::getUserData(options->online.gameID, options->online.jailerID);
|
||||
dataCached = false;
|
||||
clearData();
|
||||
}
|
||||
|
||||
// Si los datos ya estan cacheados, no hace nada
|
||||
if (dataCached)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Si las opciones online estan activadas, obtiene los datos desde el servidor
|
||||
if (options->online.enabled)
|
||||
{
|
||||
allData = jscore::getUserData(options->online.gameID, options->online.jailerID);
|
||||
jailerID = options->online.jailerID;
|
||||
}
|
||||
|
||||
// Si no ha podido obtener los datos del servidor, no hace nada
|
||||
if (allData.length() == 0)
|
||||
{
|
||||
if (options->console)
|
||||
{
|
||||
std::cout << "NO DATA\n"
|
||||
<< std::endl;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -59,44 +86,84 @@ void Online::getAllData()
|
||||
// Obtiene la cadena con los logros
|
||||
if (cheevosIni != std::string::npos && cheevosEnd != std::string::npos)
|
||||
cheevosData = allData.substr(cheevosIni, cheevosDataLenght);
|
||||
|
||||
dataCached = true;
|
||||
printData("LOADING");
|
||||
}
|
||||
|
||||
// Coloca todos los datos desde las variables en la cadena allData
|
||||
void Online::setAllData()
|
||||
void Online::sendData()
|
||||
{
|
||||
allData = STATS_FLAG_INI + statsData + STATS_FLAG_END + CHEEVOS_FLAG_INI + cheevosData + CHEEVOS_FLAG_END;
|
||||
if (options->online.enabled)
|
||||
const bool newData = allData.compare(dataSaved) == 0 ? false : true;
|
||||
if (options->online.enabled && newData)
|
||||
{
|
||||
jscore::setUserData(options->online.gameID, options->online.jailerID, allData);
|
||||
dataSaved = allData;
|
||||
printData("SAVING");
|
||||
}
|
||||
}
|
||||
|
||||
// Obtiene las estadísticas guardadas en el servidor
|
||||
std::string Online::getStats()
|
||||
{
|
||||
getAllData();
|
||||
getData();
|
||||
return statsData;
|
||||
}
|
||||
|
||||
// Guarda las estadísticas en el servidor
|
||||
void Online::setStats(std::string data)
|
||||
{
|
||||
getAllData();
|
||||
// getData();
|
||||
statsData = data;
|
||||
setAllData();
|
||||
// setAllData();
|
||||
}
|
||||
|
||||
// Obtiene los logros guardadas en el servidor
|
||||
std::string Online::getCheevos()
|
||||
{
|
||||
getAllData();
|
||||
getData();
|
||||
return cheevosData;
|
||||
}
|
||||
|
||||
// Guarda los logros en el servidor
|
||||
void Online::setCheevos(std::string data)
|
||||
{
|
||||
getAllData();
|
||||
getData();
|
||||
cheevosData = data;
|
||||
setAllData();
|
||||
sendData();
|
||||
}
|
||||
|
||||
// Imprime información de diagnóstico
|
||||
void Online::printData(std::string text)
|
||||
{
|
||||
static int counter = 0;
|
||||
if (options->console)
|
||||
{
|
||||
std::cout << "mode is: " << text << " (" << counter << ")" << std::endl;
|
||||
std::cout << "allData: " << allData << std::endl;
|
||||
std::cout << "statsData: " << statsData << std::endl;
|
||||
std::cout << "cheevosData: " << cheevosData << std::endl;
|
||||
std::cout << "options->online.jailerID: " << options->online.jailerID << std::endl;
|
||||
std::cout << "options->online.enabled: " << options->online.enabled << std::endl;
|
||||
std::cout << std::endl;
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
|
||||
// Elimina los datos del servidor
|
||||
void Online::eraseServerData()
|
||||
{
|
||||
if (options->online.enabled)
|
||||
{
|
||||
jscore::setUserData(options->online.gameID, options->online.jailerID, "");
|
||||
}
|
||||
}
|
||||
|
||||
// Limpia los datos almacenados en la caché
|
||||
void Online::clearData()
|
||||
{
|
||||
allData = "";
|
||||
statsData = "";
|
||||
cheevosData = "";
|
||||
}
|
||||
Reference in New Issue
Block a user