Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "statslog.h"
- #include <pthread.h>
- #include <stdio.h>
- #include <math.h>
- #include <gsql/gmysql.h>
- #include <gsql/gsql.h>
- pthread_mutex_t statsmutex;
- GText::String _mysql_user;
- GText::String _mysql_pass;
- GText::String _mysql_host;
- GText::String _mysql_port;
- GText::String _mysql_db;
- GText::String _degredation;
- //#define DEBUG_SQL_QUERIES 1
- int _mingames = 3;
- int _inactivedays = 30;
- pthread_t statsthreadid;
- void initDatabase()
- {
- static GSQL::GSQL *instance = NULL;
- instance = new GSQL::GMySQL(_mysql_host,_mysql_user,_mysql_pass,atoi(_mysql_port.data()));
- if(instance == NULL)
- return;
- if(!instance->does_database_exist(_mysql_db))
- instance->create_database(_mysql_db);
- instance->select_databse(_mysql_db);
- if(!instance->does_table_exist("ctf"))
- {
- instance->query("CREATE TABLE IF NOT EXISTS `ctf` (`id` bigint(20) unsigned NOT NULL auto_increment, `name` varchar(24) NOT NULL, `hwid` varchar(11) NOT NULL, `time_updated` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP, `killed` bigint(20) NOT NULL, `death` bigint(20) NOT NULL, `cap` bigint(20) NOT NULL, `teamcap` bigint(20) NOT NULL, `win` bigint(20) NOT NULL, `tie` bigint(20) NOT NULL, `lose` bigint(20) NOT NULL,`points` BIGINT( 20 ) NOT NULL DEFAULT '1000', PRIMARY KEY (`id`)) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=133");
- }
- if(!instance->does_table_exist("inf"))
- {
- instance->query("CREATE TABLE IF NOT EXISTS `inf` (`id` bigint(20) unsigned NOT NULL auto_increment, `name` varchar(24) NOT NULL, `hwid` varchar(11) NOT NULL, `time_updated` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP, `killed` bigint(20) NOT NULL, `death` bigint(20) NOT NULL, `cap` bigint(20) NOT NULL, `teamcap` bigint(20) NOT NULL, `win` bigint(20) NOT NULL, `tie` bigint(20) NOT NULL, `lose` bigint(20) NOT NULL,`points` BIGINT( 20 ) NOT NULL DEFAULT '1000', PRIMARY KEY (`id`)) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=133");
- }
- if(!instance->does_table_exist("htf"))
- {
- instance->query("CREATE TABLE IF NOT EXISTS `htf` (`id` bigint(20) unsigned NOT NULL auto_increment, `name` varchar(24) NOT NULL, `hwid` varchar(11) NOT NULL, `time_updated` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP, `killed` bigint(20) NOT NULL, `death` bigint(20) NOT NULL, `win` bigint(20) NOT NULL, `tie` bigint(20) NOT NULL, `lose` bigint(20) NOT NULL,`points` BIGINT( 20 ) NOT NULL DEFAULT '1000', PRIMARY KEY (`id`)) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=133");
- }
- if(!instance->does_table_exist("tdm"))
- {
- instance->query("CREATE TABLE IF NOT EXISTS `tdm` (`id` bigint(20) unsigned NOT NULL auto_increment, `name` varchar(24) NOT NULL, `hwid` varchar(11) NOT NULL, `time_updated` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP, `killed` bigint(20) NOT NULL, `death` bigint(20) NOT NULL, `win` bigint(20) NOT NULL, `tie` bigint(20) NOT NULL, `lose` bigint(20) NOT NULL,`points` BIGINT( 20 ) NOT NULL DEFAULT '1000', PRIMARY KEY (`id`)) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=133");
- }
- if(!instance->does_table_exist("dm"))
- {
- instance->query("CREATE TABLE IF NOT EXISTS `dm` (`id` bigint(20) unsigned NOT NULL auto_increment, `name` varchar(24) NOT NULL, `hwid` varchar(11) NOT NULL, `time_updated` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP, `killed` bigint(20) NOT NULL, `death` bigint(20) NOT NULL, `rank` bigint(20) NOT NULL, `played` bigint(20) NOT NULL, PRIMARY KEY (`id`)) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=133");
- }
- if(!instance->does_table_exist("pm"))
- {
- instance->query("CREATE TABLE IF NOT EXISTS `pm` (`id` bigint(20) unsigned NOT NULL auto_increment, `name` varchar(24) NOT NULL, `hwid` varchar(11) NOT NULL, `time_updated` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP, `killed` bigint(20) NOT NULL, `death` bigint(20) NOT NULL, `rank` bigint(20) NOT NULL, `played` bigint(20) NOT NULL, PRIMARY KEY (`id`)) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=133");
- }
- if(!instance->does_table_exist("rm"))
- {
- instance->query("CREATE TABLE IF NOT EXISTS `rm` (`id` bigint(20) unsigned NOT NULL auto_increment, `name` varchar(24) NOT NULL, `hwid` varchar(11) NOT NULL, `time_updated` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP, `killed` bigint(20) NOT NULL, `death` bigint(20) NOT NULL, `rank` bigint(20) NOT NULL, `played` bigint(20) NOT NULL, PRIMARY KEY (`id`)) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=133");
- }
- if(instance != NULL)
- delete instance;
- }
- static GText::String tds(const GText::String &str)
- {
- GText::String rets;
- int l;
- for(l=0;l<str.length();l++)
- if(str[l] == '\'')
- rets += "\\\'";
- else
- rets += str[l];
- // printf("tds %s -> %s\n",str.data(),rets.data());
- return rets;
- }
- void query(const GText::String &q, GSQL::GSQL::QueryResult *qr = NULL)
- {
- GSQL::GSQL *sql = NULL;
- sql = new GSQL::GMySQL(_mysql_host,_mysql_user,_mysql_pass,atoi(_mysql_port.data()));
- if(sql != NULL)
- {
- sql->select_databse(_mysql_db);
- #ifdef DEBUG_SQL_QUERIES
- printf("QUERY : %s\n",q.data());
- #endif // DEBUG_SQL_QUERIES
- sql->query(q,qr);
- delete sql;
- }
- }
- void degradeStats()
- {
- GSQL::GSQL::StoreQueryResult sqr;
- try
- {
- // DM
- query("UPDATE dm SET killed=FLOOR(killed*" + _degredation + "), death=FLOOR(death*" + _degredation + "), rank=FLOOR(rank*" + _degredation + "), played=FLOOR(played*" + _degredation + "), time_updated=time_updated", &sqr);
- // PM
- query("UPDATE pm SET killed=FLOOR(killed*" + _degredation + "), death=FLOOR(death*" + _degredation + "), rank=FLOOR(rank*" + _degredation + "), played=FLOOR(played*" + _degredation + "), time_updated=time_updated", &sqr);
- // RM
- query("UPDATE rm SET killed=FLOOR(killed*" + _degredation + "), death=FLOOR(death*" + _degredation + "), rank=FLOOR(rank*" + _degredation + "), played=FLOOR(played*" + _degredation + "), time_updated=time_updated", &sqr);
- // CTF
- query("UPDATE ctf SET killed=FLOOR(killed*" + _degredation + "), death=FLOOR(death*" + _degredation + "), cap=FLOOR(cap*" + _degredation + "), teamcap=FLOOR(teamcap*" + _degredation + "), win=FLOOR(win*" + _degredation + "), tie=FLOOR(tie*" + _degredation + "), lose=FLOOR(lose*" + _degredation + "), time_updated=time_updated", &sqr);
- // INF
- query("UPDATE inf SET killed=FLOOR(killed*" + _degredation + "), death=FLOOR(death*" + _degredation + "), cap=FLOOR(cap*" + _degredation + "), teamcap=FLOOR(teamcap*" + _degredation + "), win=FLOOR(win*" + _degredation + "), tie=FLOOR(tie*" + _degredation + "), lose=FLOOR(lose*" + _degredation + "), time_updated=time_updated", &sqr);
- // HTF
- query("UPDATE htf SET killed=FLOOR(killed*" + _degredation + "), death=FLOOR(death*" + _degredation + "), win=FLOOR(win*" + _degredation + "), tie=FLOOR(tie*" + _degredation + "), lose=FLOOR(lose*" + _degredation + "), time_updated=time_updated", &sqr);
- // TDM
- query("UPDATE tdm SET killed=FLOOR(killed*" + _degredation + "), death=FLOOR(death*" + _degredation + "), win=FLOOR(win*" + _degredation + "), tie=FLOOR(tie*" + _degredation + "), lose=FLOOR(lose*" + _degredation + "), time_updated=time_updated", &sqr);
- }
- catch(GException &exp)
- {
- fprintf(stderr,"Unhandled exception %s\n",exp.what());
- }
- }
- void saveLastUpdate(time_t update)
- {
- FILE * updatefile;
- updatefile = fopen("lastupdate.dat", "wb");
- if(updatefile != NULL)
- {
- fwrite(&update, sizeof(time_t), 1, updatefile);
- fclose(updatefile);
- }
- }
- time_t loadLastUpdate()
- {
- time_t update = 0;
- FILE * updatefile;
- updatefile = fopen("lastupdate.dat", "rb");
- if(updatefile != NULL)
- {
- fread(&update, sizeof(time_t), 1, updatefile);
- fclose(updatefile);
- }
- return update;
- }
- void * statsthread(void * arg)
- {
- time_t lastupdate = loadLastUpdate();
- time_t now;
- struct tm * timeinfo;
- while(1)
- {
- time(&now);
- // printf("Running Degrade Loop Now: %lu Update: %lu \n",(unsigned long)now, (unsigned long)lastupdate);
- timeinfo = localtime(&now);
- if(timeinfo->tm_hour == 4 && timeinfo->tm_wday == 6 && (now-lastupdate) > 7200)
- {
- // printf("Degrading Stats\n");
- degradeStats();
- lastupdate = now;
- saveLastUpdate(now);
- }
- sleep(10);
- }
- }
- void initStats()
- {
- pthread_create(&statsthreadid, NULL, statsthread, NULL);
- }
- void setStatsInfo(GText::String mysqluser,GText::String mysqlpass, GText::String mysqlhost, GText::String mysqlport, GText::String mysqldb, int inactivedays, int mingames, double degredation)
- {
- _mysql_user = mysqluser;
- _mysql_pass = mysqlpass;
- _mysql_host = mysqlhost;
- _mysql_port = mysqlport;
- _mysql_db = mysqldb;
- _inactivedays = inactivedays;
- _mingames = mingames;
- _degredation = GText::String(degredation);
- initDatabase();
- }
- void deinitStats()
- {
- }
- GText::String checkStats(GText::String name, int gamestyle)
- {
- GText::String line("");
- try
- {
- //printf("Checking Stats for %s\n", name.data());
- GSQL::GSQL::StoreQueryResult sqr;
- // CTF
- if(gamestyle == 3)
- {
- query("SELECT ROUND((COALESCE(killed/death,killed) * (COALESCE(win/(win+lose),0) + COALESCE(cap/teamcap,0)))*1000+points) AS score, COALESCE(ROUND(killed/death,2),\'Inf\') AS kpd, COALESCE(ROUND(cap/teamcap*100),0) AS capratio, win+tie+lose AS played, COALESCE(ROUND(win/(win+lose)*100),0) AS winratio, (SELECT COUNT(*)+1 FROM ctf WHERE time_updated > TIMESTAMPADD(DAY,-" + GText::String(_inactivedays) + ",NOW()) AND ROUND((COALESCE(killed/death,killed) * (COALESCE(win/(win+lose),0) + COALESCE(cap/teamcap,0)))*1000+points)>score AND (win+tie+lose) >= " + GText::String(_mingames) +") AS place, (time_updated > TIMESTAMPADD(DAY,-" + GText::String(_inactivedays) + ",NOW()) AND (win+tie+lose) >= " + GText::String(_mingames) +") AS ranked,id,name,time_updated,killed,death FROM ctf WHERE name LIKE \'%" + tds(name) + "%\' LIMIT 1",&sqr);
- if(sqr.rows() == 0) // didnt exist in the database
- {
- //line = "No stats for user: " + name;
- }
- else
- {
- if(sqr.data(sqr.col_id_from_name("ranked"),0) == "1")
- {
- line += "CTF Rank: " + sqr.data(sqr.col_id_from_name("place"),0) + " Score: " + sqr.data(sqr.col_id_from_name("score"),0) + " K/D: " + GText::String(atof(sqr.data(sqr.col_id_from_name("killed"),0).data())/atof(sqr.data(sqr.col_id_from_name("death"),0).data())) + " Cap: " + sqr.data(sqr.col_id_from_name("capratio"),0) + "% Win: " + sqr.data(sqr.col_id_from_name("winratio"),0) + "% Rounds: " + sqr.data(sqr.col_id_from_name("played"),0) + " - " + sqr.data(sqr.col_id_from_name("name"),0) + " ";
- }
- else
- {
- line += "CTF Rank: N/A K/D: " + GText::String(atof(sqr.data(sqr.col_id_from_name("killed"),0).data())/atof(sqr.data(sqr.col_id_from_name("death"),0).data())) + " Cap: " + sqr.data(sqr.col_id_from_name("capratio"),0) + "% Win: " + sqr.data(sqr.col_id_from_name("winratio"),0) + "% Rounds " + sqr.data(sqr.col_id_from_name("played"),0) + " - " + sqr.data(sqr.col_id_from_name("name"),0) + " ";
- }
- }
- }
- // INF
- if(gamestyle == 5)
- {
- query("SELECT ROUND((COALESCE(killed/death,killed) * (COALESCE(win/(win+lose),0) + COALESCE(cap/teamcap,0)))*1000+points) AS score, COALESCE(ROUND(killed/death,2),\'Inf\') AS kpd, COALESCE(ROUND(cap/teamcap*100),0) AS capratio, win+tie+lose AS played, COALESCE(ROUND(win/(win+lose)*100),0) AS winratio, (SELECT COUNT(*)+1 FROM inf WHERE time_updated > TIMESTAMPADD(DAY,-" + GText::String(_inactivedays) + ",NOW()) AND ROUND((COALESCE(killed/death,killed) * (COALESCE(win/(win+lose),0) + COALESCE(cap/teamcap,0)))*1000+points)>score AND (win+tie+lose) >= " + GText::String(_mingames) +") AS place, (time_updated > TIMESTAMPADD(DAY,-" + GText::String(_inactivedays) + ",NOW()) AND (win+tie+lose) >= " + GText::String(_mingames) +") AS ranked,id,name,time_updated,killed,death FROM inf WHERE name LIKE \'%" + tds(name) + "%\' LIMIT 1",&sqr);
- if(sqr.rows() == 0) // didnt exist in the database
- {
- //line = "No stats for user: " + name;
- }
- else
- {
- if(sqr.data(sqr.col_id_from_name("ranked"),0) == "1")
- {
- line += "INF Rank: " + sqr.data(sqr.col_id_from_name("place"),0) + " Score: " + sqr.data(sqr.col_id_from_name("score"),0) + " K/D: " + GText::String(atof(sqr.data(sqr.col_id_from_name("killed"),0).data())/atof(sqr.data(sqr.col_id_from_name("death"),0).data())) + " Cap: " + sqr.data(sqr.col_id_from_name("capratio"),0) + "% Win: " + sqr.data(sqr.col_id_from_name("winratio"),0) + "% Rounds: " + sqr.data(sqr.col_id_from_name("played"),0) + " - " + sqr.data(sqr.col_id_from_name("name"),0) + " ";
- }
- else
- {
- line += "INF Rank: N/A K/D: " + GText::String(atof(sqr.data(sqr.col_id_from_name("killed"),0).data())/atof(sqr.data(sqr.col_id_from_name("death"),0).data())) + " Cap: " + sqr.data(sqr.col_id_from_name("capratio"),0) + "% Win: " + sqr.data(sqr.col_id_from_name("winratio"),0) + "% Rounds: " + sqr.data(sqr.col_id_from_name("played"),0) + " - " + sqr.data(sqr.col_id_from_name("name"),0) + " ";
- }
- }
- }
- // HTF
- if(gamestyle == 6)
- {
- query("SELECT ROUND((COALESCE(killed/death,killed) * (COALESCE(win/(win+lose),0)))*1000+points) AS score, COALESCE(ROUND(killed/death,2),\'Inf\') AS kpd, win+tie+lose AS played, COALESCE(ROUND(win/(win+lose)*100),0) AS winratio, (SELECT COUNT(*)+1 FROM htf WHERE time_updated > TIMESTAMPADD(DAY,-" + GText::String(_inactivedays) + ",NOW()) AND ROUND((COALESCE(killed/death,killed) * (COALESCE(win/(win+lose),0)))*1000+points)>score AND (win+tie+lose) >= " + GText::String(_mingames) +") AS place, (time_updated > TIMESTAMPADD(DAY,-" + GText::String(_inactivedays) + ",NOW()) AND (win+tie+lose) >= " + GText::String(_mingames) +") AS ranked,id,name,time_updated,killed,death FROM htf WHERE name LIKE\'%" + tds(name) + "%\' LIMIT 1",&sqr);
- if(sqr.rows() == 0) // didnt exist in the database
- {
- //line = "No stats for user: " + name;
- }
- else
- {
- if(sqr.data(sqr.col_id_from_name("ranked"),0) == "1")
- {
- line += "HTF Rank: " + sqr.data(sqr.col_id_from_name("place"),0) + " Score: " + sqr.data(sqr.col_id_from_name("score"),0) + " K/D: " + GText::String(atof(sqr.data(sqr.col_id_from_name("killed"),0).data())/atof(sqr.data(sqr.col_id_from_name("death"),0).data())) + " Win: " + sqr.data(sqr.col_id_from_name("winratio"),0) + "% Rounds: " + sqr.data(sqr.col_id_from_name("played"),0) + " - " + sqr.data(sqr.col_id_from_name("name"),0) + " ";
- }
- else
- {
- line += "HTF Rank: N/A K/D: " + GText::String(atof(sqr.data(sqr.col_id_from_name("killed"),0).data())/atof(sqr.data(sqr.col_id_from_name("death"),0).data())) + " Win: " + sqr.data(sqr.col_id_from_name("winratio"),0) + "% Rounds: " + sqr.data(sqr.col_id_from_name("played"),0) + " - " + sqr.data(sqr.col_id_from_name("name"),0) + " ";
- }
- }
- }
- // TDM
- if(gamestyle == 2)
- {
- query("SELECT ROUND((COALESCE(killed/death,killed) * (COALESCE(win/(win+lose),0)))*1000+points) AS score, COALESCE(ROUND(killed/death,2),\'Inf\') AS kpd, win+tie+lose AS played, COALESCE(ROUND(win/(win+lose)*100),0) AS winratio, (SELECT COUNT(*)+1 FROM tdm WHERE time_updated > TIMESTAMPADD(DAY,-" + GText::String(_inactivedays) + ",NOW()) AND ROUND((COALESCE(killed/death,killed) * (COALESCE(win/(win+lose),0)))*1000+points)>score AND (win+tie+lose) >= " + GText::String(_mingames) +") AS place, (time_updated > TIMESTAMPADD(DAY,-" + GText::String(_inactivedays) + ",NOW()) AND (win+tie+lose) >= " + GText::String(_mingames) +") AS ranked,id,name,time_updated,killed,death FROM tdm WHERE name\'%" + tds(name) + "%\' LIMIT 1",&sqr);
- if(sqr.rows() == 0) // didnt exist in the database
- {
- //line = "No stats for user: " + name;
- }
- else
- {
- if(sqr.data(sqr.col_id_from_name("ranked"),0) == "1")
- {
- line += "TDM Rank: " + sqr.data(sqr.col_id_from_name("place"),0) + " Score: " + sqr.data(sqr.col_id_from_name("score"),0) + " K/D: " + GText::String(atof(sqr.data(sqr.col_id_from_name("killed"),0).data())/atof(sqr.data(sqr.col_id_from_name("death"),0).data())) + " Win: " + sqr.data(sqr.col_id_from_name("winratio"),0) + "% Rounds: " + sqr.data(sqr.col_id_from_name("played"),0) + " - " + sqr.data(sqr.col_id_from_name("name"),0) + " ";
- }
- else
- {
- line += "TDM Rank: N/A K/D: " + GText::String(atof(sqr.data(sqr.col_id_from_name("killed"),0).data())/atof(sqr.data(sqr.col_id_from_name("death"),0).data())) + " Win: " + sqr.data(sqr.col_id_from_name("winratio"),0) + "% Rounds: " + sqr.data(sqr.col_id_from_name("played"),0) + " - " + sqr.data(sqr.col_id_from_name("name"),0) + " ";
- }
- }
- }
- // DM
- if(gamestyle == 0)
- {
- query("SELECT ROUND((COALESCE(killed/death,killed) * (COALESCE(played/(rank+1),0)))*1000) AS score, COALESCE(ROUND(killed/death,2),\'Inf\') AS kpd, (SELECT COUNT(*)+1 FROM dm WHERE time_updated > TIMESTAMPADD(DAY,-" + GText::String(_inactivedays) + ",NOW()) AND ROUND((COALESCE(killed/death,killed) * (COALESCE(played/(rank+1),0)))*1000)>score AND (played) >= " + GText::String(_mingames) +") AS place, (time_updated > TIMESTAMPADD(DAY,-" + GText::String(_inactivedays) + ",NOW()) AND (played) >= " + GText::String(_mingames) +") AS ranked,id,name,time_updated,killed,death,played FROM dm WHERE name LIKE \'%" + tds(name) + "%\' LIMIT 1",&sqr);
- if(sqr.rows() == 0) // didnt exist in the database
- {
- //line = "No stats for user: " + name;
- }
- else
- {
- if(sqr.data(sqr.col_id_from_name("ranked"),0) == "1")
- {
- line += "DM Rank: " + sqr.data(sqr.col_id_from_name("place"),0) + " Score: " + sqr.data(sqr.col_id_from_name("score"),0) + " K/D: " + GText::String(atof(sqr.data(sqr.col_id_from_name("killed"),0).data())/atof(sqr.data(sqr.col_id_from_name("death"),0).data())) + " Rounds: " + sqr.data(sqr.col_id_from_name("played"),0) + " - " + sqr.data(sqr.col_id_from_name("name"),0) + " ";
- }
- else
- {
- line += "DM Rank: N/A K/D: " + GText::String(atof(sqr.data(sqr.col_id_from_name("killed"),0).data())/atof(sqr.data(sqr.col_id_from_name("death"),0).data())) + " Rounds: " + sqr.data(sqr.col_id_from_name("played"),0) + " - " + sqr.data(sqr.col_id_from_name("name"),0) + " ";
- }
- }
- }
- // PM
- if(gamestyle == 1)
- {
- query("SELECT ROUND((COALESCE(killed/death,killed) * (COALESCE(played/(rank+1),0)))*1000) AS score, COALESCE(ROUND(killed/death,2),\'Inf\') AS kpd, (SELECT COUNT(*)+1 FROM pm WHERE time_updated > TIMESTAMPADD(DAY,-" + GText::String(_inactivedays) + ",NOW()) AND ROUND((COALESCE(killed/death,killed) * (COALESCE(played/(rank+1),0)))*1000)>score AND (played) >= " + GText::String(_mingames) +") AS place, (time_updated > TIMESTAMPADD(DAY,-" + GText::String(_inactivedays) + ",NOW()) AND (played) >= " + GText::String(_mingames) +") AS ranked,id,name,time_updated,killed,death,played FROM pm WHERE name LIKE\'%" + tds(name) + "%\' LIMIT 1",&sqr);
- if(sqr.rows() == 0) // didnt exist in the database
- {
- //line = "No stats for user: " + name;
- }
- else
- {
- if(sqr.data(sqr.col_id_from_name("ranked"),0) == "1")
- {
- line += "PM Rank: " + sqr.data(sqr.col_id_from_name("place"),0) + " Score: " + sqr.data(sqr.col_id_from_name("score"),0) + " K/D: " + GText::String(atof(sqr.data(sqr.col_id_from_name("killed"),0).data())/atof(sqr.data(sqr.col_id_from_name("death"),0).data())) + " Rounds: " + sqr.data(sqr.col_id_from_name("played"),0) + " - " + sqr.data(sqr.col_id_from_name("name"),0) + " ";
- }
- else
- {
- line += "PM Rank: N/A K/D: " + GText::String(atof(sqr.data(sqr.col_id_from_name("killed"),0).data())/atof(sqr.data(sqr.col_id_from_name("death"),0).data())) + " Rounds: " + sqr.data(sqr.col_id_from_name("played"),0) + " - " + sqr.data(sqr.col_id_from_name("name"),0) + " ";
- }
- }
- }
- // RM
- if(gamestyle == 4)
- {
- query("SELECT ROUND((COALESCE(killed/death,killed) * (COALESCE(played/(rank+1),0)))*1000) AS score, COALESCE(ROUND(killed/death,2),\'Inf\') AS kpd, (SELECT COUNT(*)+1 FROM rm WHERE time_updated > TIMESTAMPADD(DAY,-" + GText::String(_inactivedays) + ",NOW()) AND ROUND((COALESCE(killed/death,killed) * (COALESCE(played/(rank+1),0)))*1000)>score AND (played) >= " + GText::String(_mingames) +") AS place, (time_updated > TIMESTAMPADD(DAY,-" + GText::String(_inactivedays) + ",NOW()) AND (played) >= " + GText::String(_mingames) +") AS ranked,id,name,time_updated,killed,death,played FROM rm WHERE name LIKE \'%" + tds(name) + "%\' LIMIT 1",&sqr);
- if(sqr.rows() == 0) // didnt exist in the database
- {
- //line = "No stats for user: " + name;
- }
- else
- {
- if(sqr.data(sqr.col_id_from_name("ranked"),0) == "1")
- {
- line += "RM Rank: " + sqr.data(sqr.col_id_from_name("place"),0) + " Score: " + sqr.data(sqr.col_id_from_name("score"),0) + " K/D: " + GText::String(atof(sqr.data(sqr.col_id_from_name("killed"),0).data())/atof(sqr.data(sqr.col_id_from_name("death"),0).data())) + " Rounds: " + sqr.data(sqr.col_id_from_name("played"),0) + " - " + sqr.data(sqr.col_id_from_name("name"),0) + " ";
- }
- else
- {
- line += "RM Rank: N/A K/D: " + GText::String(atof(sqr.data(sqr.col_id_from_name("killed"),0).data())/atof(sqr.data(sqr.col_id_from_name("death"),0).data())) + " Rounds: " + sqr.data(sqr.col_id_from_name("played"),0) + " - " + sqr.data(sqr.col_id_from_name("name"),0) + " ";
- }
- }
- }
- }
- catch(GException &exp)
- {
- fprintf(stderr,"Unhandled exception %s\n",exp.what());
- }
- if(line == "")
- {
- line = "No stats found for: " + name;
- }
- return line;
- }
- struct players
- {
- GText::String name;
- int kills;
- };
- std::vector <struct players> getRankedPlayers(struct refreshX * packet)
- {
- std::vector <struct players> list;
- struct players tempplayer;
- int loop = 0;
- int loop2 = 0;
- for(loop=0;loop < 32;loop++)
- {
- if(packet->players[loop].team != 255)
- {
- tempplayer.name = GText::String(packet->players[loop].name);
- tempplayer.kills = packet->players[loop].kills;
- list.push_back(tempplayer);
- }
- }
- for(loop=0;loop < list.size();loop++)
- {
- for(loop2=0;loop2 < list.size();loop2++)
- {
- if (list[loop].kills > list[loop2].kills) //comparing member of struct
- {
- tempplayer = list[loop];
- list[loop] = list[loop2];
- list[loop2] = tempplayer;
- }
- }
- }
- return list;
- }
- int getrank(GText::String name, std::vector <struct players> list)
- {
- int retur = 1;
- int loop = 0;
- for(loop=0;loop < list.size();loop++)
- {
- if(name == list[loop].name)
- {
- retur = loop+1;
- break;
- }
- }
- return retur;
- }
- struct teams
- {
- int team;
- int score;
- };
- int getWinner(int alphascore, int bravoscore, int charliescore, int deltascore)
- {
- //printf("A: %i B: %i C: %i D: %i\n",alphascore,bravoscore,charliescore,deltascore);
- std::vector<struct teams> list;
- struct teams tempteam;
- int loop,loop2;
- tempteam.team = 1;
- tempteam.score = alphascore;
- list.push_back(tempteam);
- tempteam.team = 2;
- tempteam.score = bravoscore;
- list.push_back(tempteam);
- tempteam.team = 3;
- tempteam.score = charliescore;
- list.push_back(tempteam);
- tempteam.team = 4;
- tempteam.score = deltascore;
- list.push_back(tempteam);
- for(loop=0;loop < list.size();loop++)
- {
- for(loop2=0;loop2 < list.size();loop2++)
- {
- if (list[loop].score > list[loop2].score) //comparing member of struct
- {
- tempteam = list[loop];
- list[loop] = list[loop2];
- list[loop2] = tempteam;
- }
- }
- }
- //printf("TEAM[0]: %i SCORE: %i\n", list[0].team,list[0].score);
- //printf("TEAM[1]: %i SCORE: %i\n", list[1].team,list[1].score);
- //printf("TEAM[2]: %i SCORE: %i\n", list[2].team,list[2].score);
- //printf("TEAM[3]: %i SCORE: %i\n", list[3].team,list[3].score);
- if(list[0].score == list[1].score)
- {
- return 0;
- }
- return list[0].team;
- }
- void updateStats(struct refreshX * packet)
- {
- //printf("Updating stats\n");
- if(_mysql_host == "")
- return;
- int loop = 0;
- int teams = 0;
- int alphawin = 0;
- int bravowin = 0;
- int charliewin = 0;
- int deltawin = 0;
- int alphaloose = 0;
- int bravoloose = 0;
- int charlieloose = 0;
- int deltaloose = 0;
- int alphaplayers = 0;
- int bravoplayers = 0;
- int charlieplayers = 0;
- int deltaplayers = 0;
- int alphapoints = 0;
- int bravopoints = 0;
- int charliepoints = 0;
- int deltapoints = 0;
- int newalphapoints = 0;
- int newbravopoints = 0;
- int newcharliepoints = 0;
- int newdeltapoints = 0;
- int points = 0;
- int tie = 0;
- double t=0;
- double n=0;
- int winner = getWinner(packet->alphascore,packet->bravoscore,packet->charliescore,packet->deltascore);
- std::vector <struct players> list = getRankedPlayers(packet);
- GSQL::GSQL::StoreQueryResult sqr;
- if(packet->gamestyle == 2) //TDM Special case
- {
- switch(winner)
- {
- case 0:
- tie = 1;
- break;
- case 1:
- alphawin = 1;
- bravoloose = 1;
- charlieloose = 1;
- deltaloose = 1;
- break;
- case 2:
- bravowin = 1;
- alphaloose = 1;
- charlieloose = 1;
- deltaloose = 1;
- break;
- case 3:
- charliewin = 1;
- alphaloose = 1;
- bravoloose = 1;
- deltaloose = 1;
- break;
- case 4:
- deltawin = 1;
- alphaloose = 1;
- bravoloose = 1;
- deltaloose = 1;
- break;
- default:
- tie = 1;
- break;
- }
- }
- else
- {
- if(packet->alphascore > packet->bravoscore) // alpha won
- {
- alphawin = 1;
- bravoloose = 1;
- }
- else if(packet->alphascore < packet->bravoscore) // bravo won
- {
- bravowin = 1;
- alphaloose = 1;
- }
- else if(packet->alphascore == packet->bravoscore)
- {
- tie = 1;
- }
- }
- // calculate skill poins for Team based gamestyles except tdm which is on the TODO list
- if(packet->gamestyle == 3 || packet->gamestyle == 5 || packet->gamestyle == 6 || packet->gamestyle == 2)
- {
- for(loop=0;loop < 32;loop++)
- {
- if(packet->players[loop].team == 1) // alpha
- {
- alphaplayers++;
- try
- {
- if(packet->gamestyle == 3) // CTF
- {
- query("SELECT * FROM ctf WHERE hwid=\'" + tds(GText::String(packet->players[loop].hwid)) +"\'",&sqr);
- if(sqr.rows() == 0) // user doesn't exist
- {
- alphapoints += 1000;
- }
- else // user exist
- {
- alphapoints += atoi(sqr.data(sqr.col_id_from_name("points"),0).data());
- }
- }
- else if(packet->gamestyle == 5) // INF
- {
- query("SELECT * FROM inf WHERE hwid=\'" + tds(GText::String(packet->players[loop].hwid)) +"\'",&sqr);
- if(sqr.rows() == 0) // user doesn't exist
- {
- alphapoints += 1000;
- }
- else // user exist
- {
- alphapoints += atoi(sqr.data(sqr.col_id_from_name("points"),0).data());
- }
- }
- else if(packet->gamestyle == 6) // HTF
- {
- query("SELECT * FROM htf WHERE hwid=\'" + tds(GText::String(packet->players[loop].hwid)) +"\'",&sqr);
- if(sqr.rows() == 0) // user doesn't exist
- {
- alphapoints += 1000;
- }
- else // user exist
- {
- alphapoints += atoi(sqr.data(sqr.col_id_from_name("points"),0).data());
- }
- }
- }
- catch(GException &exp)
- {
- fprintf(stderr,"Unhandled exception %s\n",exp.what());
- }
- }
- else if(packet->players[loop].team == 2) // bravo
- {
- try
- {
- if(packet->gamestyle == 3) // CTF
- {
- query("SELECT * FROM ctf WHERE hwid=\'" + tds(GText::String(packet->players[loop].hwid)) +"\'",&sqr);
- if(sqr.rows() == 0) // user doesn't exist
- {
- bravopoints += 1000;
- }
- else // user exist
- {
- bravopoints += atoi(sqr.data(sqr.col_id_from_name("points"),0).data());
- }
- }
- else if(packet->gamestyle == 5) // INF
- {
- query("SELECT * FROM inf WHERE hwid=\'" + tds(GText::String(packet->players[loop].hwid)) +"\'",&sqr);
- if(sqr.rows() == 0) // user doesn't exist
- {
- bravopoints += 1000;
- }
- else // user exist
- {
- bravopoints += atoi(sqr.data(sqr.col_id_from_name("points"),0).data());
- }
- }
- else if(packet->gamestyle == 6) // HTF
- {
- query("SELECT * FROM htf WHERE hwid=\'" + tds(GText::String(packet->players[loop].hwid)) +"\'",&sqr);
- if(sqr.rows() == 0) // user doesn't exist
- {
- bravopoints += 1000;
- }
- else // user exist
- {
- bravopoints += atoi(sqr.data(sqr.col_id_from_name("points"),0).data());
- }
- }
- }
- catch(GException &exp)
- {
- fprintf(stderr,"Unhandled exception %s\n",exp.what());
- }
- bravoplayers++;
- }
- else if(packet->players[loop].team == 3) // charlie
- {
- try
- {
- if(packet->gamestyle == 2) // TDM
- {
- query("SELECT * FROM tdm WHERE hwid=\'" + tds(GText::String(packet->players[loop].hwid)) +"\'",&sqr);
- if(sqr.rows() == 0) // user doesn't exist
- {
- charliepoints += 1000;
- }
- else // user exist
- {
- charliepoints += atoi(sqr.data(sqr.col_id_from_name("points"),0).data());
- }
- }
- }
- catch(GException &exp)
- {
- fprintf(stderr,"Unhandled exception %s\n",exp.what());
- }
- charlieplayers++;
- }
- else if(packet->players[loop].team == 4) // delta
- {
- try
- {
- if(packet->gamestyle == 2) // TDM
- {
- query("SELECT * FROM tdm WHERE hwid=\'" + tds(GText::String(packet->players[loop].hwid)) +"\'",&sqr);
- if(sqr.rows() == 0) // user doesn't exist
- {
- deltapoints += 1000;
- }
- else // user exist
- {
- deltapoints += atoi(sqr.data(sqr.col_id_from_name("points"),0).data());
- }
- }
- }
- catch(GException &exp)
- {
- fprintf(stderr,"Unhandled exception %s\n",exp.what());
- }
- deltaplayers++;
- }
- }
- if(alphaplayers != 0)
- {
- teams++;
- }
- if(bravoplayers != 0)
- {
- teams++;
- }
- if(charlieplayers != 0)
- {
- teams++;
- }
- if(deltaplayers != 0)
- {
- teams++;
- }
- if(alphawin == 1 && teams > 1) // alpha won
- {
- t = (double)50*((alphaplayers+bravoplayers+charlieplayers+deltaplayers)/teams);
- n = (double)1+pow((double)10,((double)(alphapoints)-(double)((bravopoints+charliepoints+deltapoints)/(teams-1)))/(double)(1000*((alphaplayers+bravoplayers+charlieplayers+deltaplayers)/teams)));
- points = (int)(t/n);
- newalphapoints += points/teams;
- newbravopoints -= points/teams;
- newcharliepoints -= points/teams;
- newdeltapoints -= points/teams;
- }
- else if(bravowin == 1 && teams > 1) // bravo won
- {
- t = (double)50*((alphaplayers+bravoplayers+charlieplayers+deltaplayers)/teams);
- n = (double)1+pow((double)10,((double)(bravopoints)-(double)((alphapoints+charliepoints+deltapoints)/(teams-1)))/(double)(1000*((alphaplayers+bravoplayers+charlieplayers+deltaplayers)/teams)));
- points = (int)(t/n);
- newalphapoints -= points/teams;
- newbravopoints += points/teams;
- newcharliepoints -= points/teams;
- newdeltapoints -= points/teams;
- }
- else if(charliewin == 1 && teams > 1) // charlie won
- {
- t = (double)50*((alphaplayers+bravoplayers+charlieplayers+deltaplayers)/teams);
- n = (double)1+pow((double)10,((double)(charliepoints)-(double)((alphapoints+bravopoints+deltapoints)/(teams-1)))/(double)(1000*((alphaplayers+bravoplayers+charlieplayers+deltaplayers)/teams)));
- points = (int)(t/n);
- newalphapoints -= points/teams;
- newbravopoints -= points/teams;
- newcharliepoints += points/teams;
- newdeltapoints -= points/teams;
- }
- else if(deltawin == 1 && teams > 1) // delta won
- {
- t = (double)50*((alphaplayers+bravoplayers+charlieplayers+deltaplayers)/teams);
- n = (double)1+pow((double)10,((double)(deltapoints)-(double)((alphapoints+bravopoints+charliepoints)/(teams-1)))/(double)(1000*((alphaplayers+bravoplayers+charlieplayers+deltaplayers)/teams)));
- points = (int)(t/n);
- newalphapoints -= points/teams;
- newbravopoints -= points/teams;
- newcharliepoints -= points/teams;
- newdeltapoints += points/teams;
- }
- }
- for(loop=0;loop < 32;loop++)
- {
- try
- {
- if(packet->players[loop].team == 1 && packet->gamestyle == 3) // alpha CTF
- {
- query("SELECT * FROM ctf WHERE hwid=\'" + tds(GText::String(packet->players[loop].hwid)) +"\'",&sqr);
- if(sqr.rows() == 0) // user doesn't exist
- {
- query("INSERT INTO ctf (name,hwid,killed,death,cap,teamcap,win,tie,lose,points) VALUES (\'" + tds(GText::String(packet->players[loop].name)) + "\', " + tds(GText::String(packet->players[loop].hwid)) + "\', " + tds(GText::String(packet->players[loop].kills)) + ", " + tds(GText::String(packet->players[loop].deaths)) + ", " + tds(GText::String(packet->players[loop].caps)) + ", " + tds(GText::String(packet->alphascore)) + ", " + tds(GText::String(alphawin)) + ", " + tds(GText::String(tie)) + ", "+ tds(GText::String(alphaloose)) + ", "+ tds(GText::String(1000+newalphapoints)) + ")",&sqr);
- }
- else // user exist so lets update it
- {
- query("UPDATE ctf SET name='" + tds(GText::String(packet->players[loop].name)) + "', killed=killed+" + tds(GText::String(packet->players[loop].kills)) + ", death=death+" + tds(GText::String(packet->players[loop].deaths)) + ", cap=cap+" + tds(GText::String(packet->players[loop].caps)) + ", teamcap=teamcap+" + tds(GText::String(packet->alphascore)) + ", win=win+" + tds(GText::String(alphawin)) + ", tie=tie+" + tds(GText::String(tie)) + ", lose=lose+" + tds(GText::String(alphaloose)) + ", points=points+" + tds(GText::String(newalphapoints)) + " WHERE hwid=\'" + tds(GText::String(packet->players[loop].hwid)) +"\'",&sqr);
- }
- }
- else if(packet->players[loop].team == 2 && packet->gamestyle == 3) // bravo CTF
- {
- query("SELECT * FROM ctf WHERE hwid=\'" + tds(GText::String(packet->players[loop].hwid)) +"\'",&sqr);
- if(sqr.rows() == 0) // user doesn't exist
- {
- query("INSERT INTO ctf (name,hwid,killed,death,cap,teamcap,win,tie,lose,points) VALUES (\'" + tds(GText::String(packet->players[loop].name)) + "\', " + tds(GText::String(packet->players[loop].hwid)) + "\', " + tds(GText::String(packet->players[loop].kills)) + ", " + tds(GText::String(packet->players[loop].deaths)) + ", " + tds(GText::String(packet->players[loop].caps)) + ", " + tds(GText::String(packet->bravoscore)) + ", " + tds(GText::String(bravowin)) + ", " + tds(GText::String(tie)) + ", "+ tds(GText::String(bravoloose)) + ", "+ tds(GText::String(1000+newbravopoints)) + ")",&sqr);
- }
- else // user exist so lets update it
- {
- query("UPDATE ctf SET name='" + tds(GText::String(packet->players[loop].name)) + "', killed=killed+" + tds(GText::String(packet->players[loop].kills)) + ", death=death+" + tds(GText::String(packet->players[loop].deaths)) + ", cap=cap+" + tds(GText::String(packet->players[loop].caps)) + ", teamcap=teamcap+" + tds(GText::String(packet->bravoscore)) + ", win=win+" + tds(GText::String(bravowin)) + ", tie=tie+" + tds(GText::String(tie)) + ", lose=lose+" + tds(GText::String(bravoloose)) + ", points=points+" + tds(GText::String(newbravopoints)) + " WHERE hwid=\'" + tds(GText::String(packet->players[loop].hwid)) + "\'",&sqr);
- }
- }
- else if(packet->players[loop].team == 1 && packet->gamestyle == 5) // alpha INF
- {
- query("SELECT * FROM inf WHERE hwid=\'" + tds(GText::String(packet->players[loop].hwid)) +"\'",&sqr);
- if(sqr.rows() == 0) // user doesn't exist
- {
- query("INSERT INTO inf (name,hwid,killed,death,cap,teamcap,win,tie,lose,points) VALUES (\'" + tds(GText::String(packet->players[loop].name)) + "\', " + tds(GText::String(packet->players[loop].hwid)) + "\', " + tds(GText::String(packet->players[loop].kills)) + ", " + tds(GText::String(packet->players[loop].deaths)) + ", " + tds(GText::String(packet->players[loop].caps*30)) + ", " + tds(GText::String(packet->alphascore)) + ", " + tds(GText::String(alphawin)) + ", " + tds(GText::String(tie)) + ", "+ tds(GText::String(alphaloose)) + ", " + tds(GText::String(1000+newalphapoints)) + ")",&sqr);
- }
- else // user exist so lets update it
- {
- query("UPDATE inf SET name='" + tds(GText::String(packet->players[loop].name)) + "', killed=killed+" + tds(GText::String(packet->players[loop].kills)) + ", death=death+" + tds(GText::String(packet->players[loop].deaths)) + ", cap=cap+" + tds(GText::String(packet->players[loop].caps*30)) + ", teamcap=teamcap+" + tds(GText::String(packet->alphascore)) + ", win=win+" + tds(GText::String(alphawin)) + ", tie=tie+" + tds(GText::String(tie)) + ", lose=lose+" + tds(GText::String(alphaloose)) + ", points=points+" + tds(GText::String(newalphapoints)) + " WHERE hwid=\'" + tds(GText::String(packet->players[loop].hwid)) + "\'",&sqr);
- }
- }
- else if(packet->players[loop].team == 2 && packet->gamestyle == 5) // bravo INF
- {
- query("SELECT * FROM inf WHERE hwid=\'" + tds(GText::String(packet->players[loop].hwid)) +"\'",&sqr);
- if(sqr.rows() == 0) // user doesn't exist
- {
- query("INSERT INTO inf (name,hwid,killed,death,cap,teamcap,win,tie,lose,points) VALUES (\'" + tds(GText::String(packet->players[loop].name)) + "\', " + tds(GText::String(packet->players[loop].hwid)) + "\', " + tds(GText::String(packet->players[loop].kills)) + ", " + tds(GText::String(packet->players[loop].deaths)) + ", " + tds(GText::String(0)) + ", " + tds(GText::String(0)) + ", " + tds(GText::String(bravowin)) + ", " + tds(GText::String(tie)) + ", "+ tds(GText::String(bravoloose)) + ", " + tds(GText::String(1000+newbravopoints)) + ")",&sqr);
- }
- else // user exist so lets update it
- {
- query("UPDATE inf SET name='" + tds(GText::String(packet->players[loop].name)) + "', killed=killed+" + tds(GText::String(packet->players[loop].kills)) + ", death=death+" + tds(GText::String(packet->players[loop].deaths)) + ", cap=cap+" + tds(GText::String(0)) + ", teamcap=teamcap+" + tds(GText::String(0)) + ", win=win+" + tds(GText::String(bravowin)) + ", tie=tie+" + tds(GText::String(tie)) + ", lose=lose+" + tds(GText::String(bravoloose)) + ", points=points+" + tds(GText::String(newbravopoints)) + " WHERE hwid=\'" + tds(GText::String(packet->players[loop].hwid)) + "\'",&sqr);
- }
- }
- else if(packet->players[loop].team == 1 && packet->gamestyle == 6) // alpha HTF
- {
- query("SELECT * FROM htf WHERE hwid=\'" + tds(GText::String(packet->players[loop].hwid)) +"\'",&sqr);
- if(sqr.rows() == 0) // user doesn't exist
- {
- query("INSERT INTO htf (name,hwid,killed,death,win,tie,lose,points) VALUES (\'" + tds(GText::String(packet->players[loop].name)) + "\', " + tds(GText::String(packet->players[loop].hwid)) + "\', " + tds(GText::String(packet->players[loop].kills)) + ", " + tds(GText::String(packet->players[loop].deaths)) + ", " + tds(GText::String(alphawin)) + ", " + tds(GText::String(tie)) + ", "+ tds(GText::String(alphaloose)) + ", " + tds(GText::String(1000+newalphapoints)) + ")",&sqr);
- }
- else // user exist so lets update it
- {
- query("UPDATE htf SET name='" + tds(GText::String(packet->players[loop].name)) + "', killed=killed+" + tds(GText::String(packet->players[loop].kills)) + ", death=death+" + tds(GText::String(packet->players[loop].deaths)) + ", win=win+" + tds(GText::String(alphawin)) + ", tie=tie+" + tds(GText::String(tie)) + ", lose=lose+" + tds(GText::String(alphaloose)) + ", points=points+" + tds(GText::String(newalphapoints)) + " WHERE hwid=\'" + tds(GText::String(packet->players[loop].hwid)) +"\'",&sqr);
- }
- }
- else if(packet->players[loop].team == 2 && packet->gamestyle == 6) // bravo HTF
- {
- query("SELECT * FROM htf WHERE hwid=\'" + tds(GText::String(packet->players[loop].hwid)) +"\'",&sqr);
- if(sqr.rows() == 0) // user doesn't exist
- {
- query("INSERT INTO htf (name,hwid,killed,death,win,tie,lose,points) VALUES (\'" + tds(GText::String(packet->players[loop].name)) + "\', " + tds(GText::String(packet->players[loop].hwid)) + "\', " + tds(GText::String(packet->players[loop].kills)) + ", " + tds(GText::String(packet->players[loop].deaths)) + ", " + tds(GText::String(bravowin)) + ", " + tds(GText::String(tie)) + ", "+ tds(GText::String(bravoloose)) + ", " + tds(GText::String(1000+newbravopoints)) + ")",&sqr);
- }
- else // user exist so lets update it
- {
- query("UPDATE htf SET name='" + tds(GText::String(packet->players[loop].name)) + "', killed=killed+" + tds(GText::String(packet->players[loop].kills)) + ", death=death+" + tds(GText::String(packet->players[loop].deaths)) + ", win=win+" + tds(GText::String(bravowin)) + ", tie=tie+" + tds(GText::String(tie)) + ", lose=lose+" + tds(GText::String(bravoloose)) + ", points=points+" + tds(GText::String(newbravopoints)) + " WHERE hwid=\'" + tds(GText::String(packet->players[loop].hwid)) + "\'",&sqr);
- }
- }
- else if(packet->players[loop].team == 1 && packet->gamestyle == 2) // alpha TDM
- {
- query("SELECT * FROM tdm WHERE hwid=\'" + tds(GText::String(packet->players[loop].hwid)) +"\'",&sqr);
- if(sqr.rows() == 0) // user doesn't exist
- {
- query("INSERT INTO tdm (name,hwid,killed,death,win,tie,lose,points) VALUES (\'" + tds(GText::String(packet->players[loop].name)) + "\', " + tds(GText::String(packet->players[loop].hwid)) + "\', " + tds(GText::String(packet->players[loop].kills)) + ", " + tds(GText::String(packet->players[loop].deaths)) + ", " + tds(GText::String(alphawin)) + ", " + tds(GText::String(tie)) + ", "+ tds(GText::String(alphaloose)) + ", " + tds(GText::String(1000+newalphapoints)) + ")",&sqr);
- }
- else // user exist so lets update it
- {
- query("UPDATE tdm SET name='" + tds(GText::String(packet->players[loop].name)) + "', killed=killed+" + tds(GText::String(packet->players[loop].kills)) + ", death=death+" + tds(GText::String(packet->players[loop].deaths)) + ", win=win+" + tds(GText::String(alphawin)) + ", tie=tie+" + tds(GText::String(tie)) + ", lose=lose+" + tds(GText::String(alphaloose)) + ", points=points+" + tds(GText::String(newalphapoints)) + " WHERE hwid=\'" + tds(GText::String(packet->players[loop].hwid)) +"\'",&sqr);
- }
- }
- else if(packet->players[loop].team == 2 && packet->gamestyle == 2) // bravo TDM
- {
- query("SELECT * FROM tdm WHERE hwid=\'" + tds(GText::String(packet->players[loop].hwid)) +"\'",&sqr);
- if(sqr.rows() == 0) // user doesn't exist
- {
- query("INSERT INTO tdm (name,hwid,killed,death,win,tie,lose,points) VALUES (\'" + tds(GText::String(packet->players[loop].name)) + "\', " + tds(GText::String(packet->players[loop].hwid)) + "\', " + tds(GText::String(packet->players[loop].kills)) + ", " + tds(GText::String(packet->players[loop].deaths)) + ", " + tds(GText::String(bravowin)) + ", " + tds(GText::String(tie)) + ", "+ tds(GText::String(bravoloose)) + ", " + tds(GText::String(1000+newbravopoints))+ ")",&sqr);
- }
- else // user exist so lets update it
- {
- query("UPDATE tdm SET name='" + tds(GText::String(packet->players[loop].name)) + "', killed=killed+" + tds(GText::String(packet->players[loop].kills)) + ", death=death+" + tds(GText::String(packet->players[loop].deaths)) + ", win=win+" + tds(GText::String(bravowin)) + ", tie=tie+" + tds(GText::String(tie)) + ", lose=lose+" + tds(GText::String(bravoloose)) + ", points=points+" + tds(GText::String(newbravopoints))+ " WHERE hwid=\'" + tds(GText::String(packet->players[loop].hwid)) + "\'",&sqr);
- }
- }
- else if(packet->players[loop].team == 3 && packet->gamestyle == 2) // charlie TDM
- {
- query("SELECT * FROM tdm WHERE hwid=\'" + tds(GText::String(packet->players[loop].hwid)) +"\'",&sqr);
- if(sqr.rows() == 0) // user doesn't exist
- {
- query("INSERT INTO tdm (name,hwid,killed,death,win,tie,lose,points) VALUES (\'" + tds(GText::String(packet->players[loop].name)) + "\', " + tds(GText::String(packet->players[loop].hwid)) + "\', " + tds(GText::String(packet->players[loop].kills)) + ", " + tds(GText::String(packet->players[loop].deaths)) + ", " + tds(GText::String(charliewin)) + ", " + tds(GText::String(tie)) + ", "+ tds(GText::String(charlieloose)) + ", " + tds(GText::String(1000+newcharliepoints)) + ")",&sqr);
- }
- else // user exist so lets update it
- {
- query("UPDATE tdm SET name='" + tds(GText::String(packet->players[loop].name)) + "', killed=killed+" + tds(GText::String(packet->players[loop].kills)) + ", death=death+" + tds(GText::String(packet->players[loop].deaths)) + ", win=win+" + tds(GText::String(charliewin)) + ", tie=tie+" + tds(GText::String(tie)) + ", lose=lose+" + tds(GText::String(charlieloose)) + ", points=points+" + tds(GText::String(newcharliepoints))+ " WHERE hwid=\'" + tds(GText::String(packet->players[loop].hwid)) + "\'",&sqr);
- }
- }
- else if(packet->players[loop].team == 4 && packet->gamestyle == 2) // delta TDM
- {
- query("SELECT * FROM tdm WHERE hwid=\'" + tds(GText::String(packet->players[loop].hwid)) +"\'",&sqr);
- if(sqr.rows() == 0) // user doesn't exist
- {
- query("INSERT INTO tdm (name,hwid,killed,death,win,tie,lose,points) VALUES (\'" + tds(GText::String(packet->players[loop].name)) + "\', " + tds(GText::String(packet->players[loop].hwid)) + "\', " + tds(GText::String(packet->players[loop].kills)) + ", " + tds(GText::String(packet->players[loop].deaths)) + ", " + tds(GText::String(deltawin)) + ", " + tds(GText::String(tie)) + ", "+ tds(GText::String(deltaloose)) + ", " + tds(GText::String(1000+newdeltapoints)) + ")",&sqr);
- }
- else // user exist so lets update it
- {
- query("UPDATE tdm SET name='" + tds(GText::String(packet->players[loop].name)) + "', killed=killed+" + tds(GText::String(packet->players[loop].kills)) + ", death=death+" + tds(GText::String(packet->players[loop].deaths)) + ", win=win+" + tds(GText::String(deltawin)) + ", tie=tie+" + tds(GText::String(tie)) + ", lose=lose+" + tds(GText::String(deltaloose)) + ", points=points+" + tds(GText::String(newdeltapoints))+ " WHERE hwid=\'" + tds(GText::String(packet->players[loop].hwid)) + "\'",&sqr);
- }
- }
- else if(packet->players[loop].team == 0 && packet->gamestyle == 0) // DM
- {
- query("SELECT * FROM dm WHERE hwid=\'" + tds(GText::String(packet->players[loop].hwid)) +"\'",&sqr);
- if(sqr.rows() == 0) // user doesn't exist
- {
- query("INSERT INTO dm (name,hwid,killed,death,rank,played) VALUES (\'" + tds(GText::String(packet->players[loop].name)) + "\', " + tds(GText::String(packet->players[loop].hwid)) + "\', " + tds(GText::String(packet->players[loop].kills)) + ", " + tds(GText::String(packet->players[loop].deaths)) + ", " + tds(GText::String(getrank(GText::String(packet->players[loop].name),list))) + ", 1)",&sqr);
- }
- else // user exist so lets update it
- {
- query("UPDATE dm SET name='" + tds(GText::String(packet->players[loop].name)) + "', killed=killed+" + tds(GText::String(packet->players[loop].kills)) + ", death=death+" + tds(GText::String(packet->players[loop].deaths)) + ", rank=rank+" + tds(GText::String(getrank(GText::String(packet->players[loop].name),list))) + ", played=played+1 WHERE hwid=\'" + tds(GText::String(packet->players[loop].hwid)) + "\'",&sqr);
- }
- }
- else if(packet->players[loop].team == 0 && packet->gamestyle == 1) // PM
- {
- query("SELECT * FROM pm WHERE hwid=\'" + tds(GText::String(packet->players[loop].hwid)) +"\'",&sqr);
- if(sqr.rows() == 0) // user doesn't exist
- {
- query("INSERT INTO pm (name,hwid,killed,death,rank,played) VALUES (\'" + tds(GText::String(packet->players[loop].name)) + "\', " + tds(GText::String(packet->players[loop].hwid)) + "\', " + tds(GText::String(packet->players[loop].kills)) + ", " + tds(GText::String(packet->players[loop].deaths)) + ", " + tds(GText::String(getrank(GText::String(packet->players[loop].name),list))) + ", 1)",&sqr);
- }
- else // user exist so lets update it
- {
- query("UPDATE pm SET name='" + tds(GText::String(packet->players[loop].name)) + "', killed=killed+" + tds(GText::String(packet->players[loop].kills)) + ", death=death+" + tds(GText::String(packet->players[loop].deaths)) + ", rank=rank+" + tds(GText::String(getrank(GText::String(packet->players[loop].name),list))) + ", played=played+1 WHERE hwid=\'" + tds(GText::String(packet->players[loop].hwid)) + "\'",&sqr);
- }
- }
- else if(packet->players[loop].team == 0 && packet->gamestyle == 4) // RM
- {
- query("SELECT * FROM rm WHERE hwid=\'" + tds(GText::String(packet->players[loop].hwid)) +"\'",&sqr);
- if(sqr.rows() == 0) // user doesn't exist
- {
- query("INSERT INTO rm (name,hwid,killed,death,rank,played) VALUES (\'" + tds(GText::String(packet->players[loop].name)) + "\', " + tds(GText::String(packet->players[loop].hwid)) + "\', " + tds(GText::String(packet->players[loop].kills)) + ", " + tds(GText::String(packet->players[loop].deaths)) + ", " + tds(GText::String(getrank(GText::String(packet->players[loop].name),list))) + ", 1)",&sqr);
- }
- else // user exist so lets update it
- {
- query("UPDATE rm SET name='" + tds(GText::String(packet->players[loop].name)) + "', killed=killed+" + tds(GText::String(packet->players[loop].kills)) + ", death=death+" + tds(GText::String(packet->players[loop].deaths)) + ", rank=rank+" + tds(GText::String(getrank(GText::String(packet->players[loop].name),list))) + ", played=played+1 WHERE hwid=\'" + tds(GText::String(packet->players[loop].hwid)) + "\'",&sqr);
- }
- }
- }
- catch(GException &exp)
- {
- fprintf(stderr,"Unhandled exception %s\n",exp.what());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement