Hi i need a little of your expertise again.
I decided to use libcod to get mysql function. I used this version https://github.com/voron00/libcod. I set up the database and create the table. Along with the "login, playername, challenge, response" colums i added some more to store the player stats. So far so good. I modified the createnewaccount() function to fil up the rest of the columns and it works ok i think. Also I modified the updatestats() as shown below and it also seem to work ok. The only thing i cannot get to work is to load the values back to self.stats array. The loadtstats() function i got is shown below. Please point me in the right direction.
Code:
createnewaccount()
{
created = false;
str = "";
chl = "";
chl_resp = "";
while(!created)
{
str = "";
src = "abcdefghijklmnopqrstuvwxyz0123456789";
chl = "Challenge_";
chl_resp = "";
for(i = 0; i < 30; i++)
{
str += src[randomint(src.size)];
chl += src[randomint(src.size)];
chl_resp += src[randomint(src.size)];
}
self.izno["login_challenge"] = chl;
self.izno["login_response"] = chl_resp;
result = [[level.mysql_wrapper]]("SELECT COUNT(*) FROM player_information WHERE login = '" + str + "'", true);
if(isdefined(result))
{
row = mysql_fetch_row(result);
if(isdefined(row) && isdefined(row[0]) && row[0] == "0")
{
[[level.mysql_wrapper]]("INSERT IGNORE INTO player_information (login, playername, challenge, response) VALUES ('" + str + "', '" + maps\mp\gametypes\_mysql::stripstring(self.name) + "', '" + chl + "', '" + chl_resp + "')", false);
for(i=0;i<level.stats.size;i++)
{
[[level.mysql_wrapper]]("UPDATE player_information set " + level.stats[i] +"= 0 WHERE login = '" + str + "'",false);
}
created = true;
}
mysql_free_result(result);
}
}
self.izno["login"] = str;
self thread monitorsave(str, chl, chl_resp);
}
Code:
updatestats()
{
result = [[level.mysql_wrapper]]("SELECT COUNT(*) FROM player_information WHERE login = '" + self.izno["login"] + "'", true);
if(isdefined(result))
{
{
for(i=0;i<level.stats.size;i++)
{
[[level.mysql_wrapper]]("UPDATE player_information set " + level.stats[i] +"="+self.stats[level.stats[i]]+" WHERE login = '" + self.izno["login"] + "'",false);
}
}
mysql_free_result(result);
}
self notify("update_playerhud_score");
self maps\mp\gametypes\_myhud::updatePlayerScoreHUD();
}
Code:
loadstats()
{
result = [[level.mysql_wrapper]]("SELECT COUNT(*) FROM player_information WHERE login = '" + self.izno["login"] + "'", true);
if(isdefined(result))
{
{
for(i=0;i<level.stats.size;i++)
{
self.stats[i]=[[level.mysql_wrapper]]("Select "+self.stats[level.stats[i]]+" from player_information WHERE login = '" + self.izno["login"] + "'",true);
}
}
mysql_free_result(result);
}
self checkrank();
self thread counter();
self thread checkban();
}