Raised This Month: $ Target: $400
 0% 

noob need help in mysql


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Hops
Junior Member
Join Date: Mar 2006
Old 08-26-2008 , 04:44   noob need help in mysql
Reply With Quote #1

Hi.
I have plugin that writes some info in to DB, like server name, mapname, timeleft, and info about players.
I have two problems:
1. plugin is crashing my server if connection to DB is lost.
example: my cs server and DB is on different pc, so if pc with cs server have no internet and it can't connect to DB then everything i fine, but if pc with DB have no internet connection then my cs server crashes after some while.

2. plugin is not writing correctly player names if there is lot of players playing, I have 5 sek. interval to write info in DB but it writes it after ~10 sek. but at same time info about server is writing with no problems.

Code:
/* Plugin generated by AMXX-Studio */ #include <amxmodx> #include <amxmisc> #include <sqlx> #define PLUGIN "Server status" #define VERSION "1.0" #define AUTHOR "Hops" // SQL Settings new Handle:g_SqlTuple new g_Cache[512] new sName[1024], Name[32]; new id, Players[32], karte[32], nextm[32], hostname[64], timelim[16], team[12], sTeam[1024], Frags[12], sFrags[1024], Deaths[12], sDeaths[1024], IsAlive[12], sIsAlive[1024]; new playerCount, i; public plugin_init() {     register_plugin(PLUGIN, VERSION, AUTHOR)     set_task(5.0, "info",id,"",0, "b");     set_task(0.1, "check_sql"); } public check_sql() {     new Host[64], User[32], Pass[32], Db[32];     Host = "localhost:3306";     User = "********";     Pass = "********";     Db = "sstatus";     // we tell the API that this is the information we want to connect to,     // just not yet. basically it's like storing it in global variables     g_SqlTuple = SQL_MakeDbTuple(Host,User,Pass,Db)         SQL_ThreadQuery(g_SqlTuple,"QueryHandle","CREATE TABLE IF NOT EXISTS `test_sinfo` (`serv` text(10) NOT NULL default '', `sname` varchar(100) NOT NULL default '', `karte` varchar(100) NOT NULL default '', `speletaji` varchar(100) NOT NULL default '', `maxpl` varchar(100) NOT NULL default '', `nextmap` varchar(100) NOT NULL default '', `timeleft` varchar( 100 ) NOT NULL default '', `timelimit` varchar( 100 ) NOT NULL default '')")     SQL_ThreadQuery(g_SqlTuple,"QueryHandle","CREATE TABLE IF NOT EXISTS `test_players` (`serv` text(10) NOT NULL default '', `name` text(700) NOT NULL default '', `kills` varchar(100) NOT NULL default '', `deaths` varchar(100) NOT NULL default '', `team` text(300) NOT NULL default '', `isalive` varchar(50) NOT NULL default '')")         console_print(0,"[AMXX SQL] Connected!")     return PLUGIN_CONTINUE } public info() {     get_players(Players, playerCount);     get_mapname(karte, 31);     new maxpl = get_maxplayers();     new timeleft = get_timeleft();     get_cvar_string("amx_nextmap",nextm,31);     get_cvar_string("hostname",hostname,63);     get_cvar_string("mp_timelimit",timelim,15);     format(g_Cache,511,"UPDATE `test_sinfo` SET sname='%s',karte='%s',speletaji='%d',maxpl='%d',nextmap='%s',timeleft='%d:%02d',timelimit='%s' WHERE serv='test'",hostname,karte,get_playersnum(1),maxpl,nextm,(timeleft / 60), (timeleft % 60),timelim)     SQL_ThreadQuery(g_SqlTuple,"QueryHandle",g_Cache)         //get player stats     sName = "";     sTeam = "";     sFrags = "";     sDeaths = "";     for(i = 1; i <=playerCount; i++)     {         //if(!is_user_connected(i))         //continue;             get_user_name(i, Name, 31);         get_user_team(i, team, 11);         format(Frags, 11, "%d",get_user_frags(i));         format(Deaths, 11, "%d",get_user_deaths(i));         format(IsAlive, 11, "%d", is_user_alive(i));                 if(strlen(sName) > 0) {             format(sName, 1023, "%s§%s", sName, Name);             format(sTeam, 1023, "%s§%s", sTeam, team);             format(sFrags, 1023, "%s§%s", sFrags, Frags);             format(sDeaths, 1023, "%s§%s", sDeaths, Deaths);             format(sIsAlive, 1023, "%s§%s", sIsAlive, IsAlive);         }         else {             copy(sName, 1023, Name);             copy(sTeam, 1023, team);             copy(sFrags, 1023, Frags);             copy(sDeaths, 1023, Deaths);             copy(sIsAlive, 1023, IsAlive);         }     }         format(g_Cache,511,"UPDATE `test_players` SET name='%s',kills='%s',deaths='%s', team='%s', isalive='%s' WHERE serv='test'",sName,sFrags,sDeaths,sTeam, sIsAlive)     SQL_ThreadQuery(g_SqlTuple,"QueryHandle",g_Cache)         return PLUGIN_CONTINUE } public QueryHandle(FailState,Handle:Query,Error[],Errcode,Data[],DataSize) {     if(FailState == TQUERY_CONNECT_FAILED)     return log_amx("ServerInfo: Could not connect to SQL database.")         else if(FailState == TQUERY_QUERY_FAILED)         return log_amx("ServerInfo: Query failed")             if(Errcode)         return log_amx("ServerInfo: Error on query: %s",Error)         /*new DataNum     while(SQL_MoreResults(Query))     {         DataNum = SQL_ReadResult(Query,0)         server_print("zomg, some data: %s",DataNum)         SQL_NextRow(Query)     }*/     return PLUGIN_CONTINUE } public plugin_end() {     SQL_FreeHandle(g_SqlTuple) }

sorry for my english
Hops is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 10:20.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode