| closedMap Manager through MySQL |
| Started by F10-DEATHWish on 06-21-2010, 12:16 AM |
Threads: 1
Joined: Feb 2008
Hello all, rnrnI have been trying to find some information to help me with coding of a pluginrnthat uses a MySQL database.rnrnI will tell you what I'm wanting to achieve so if you can think of a better way of doing it just say.rnrnI want to use Deagles Map management for map rotation on my server.rnI wish to be able to enable and disable the maps through a web front,rnSo to save admins from touching the server files.rnrnI'm able to do the web page side fine, so don't need help there.rnrnI though of two ways do achieve this.rnrnFirst:rnMake a new plugin to wright over the existing .ini files with a command in serverrnlike "amx_reloadmaps"rnThat would get the plugin to read a table in the database and wright that table to a .ini replacing the existing file used by Deagles Map management.rnrnSecond:rnEdit the .sma file so that it is able to read straight from the necessary table for the list of maps.rnAlso i would like to edit the .sma so it would upload to a tables for some light stats,rnLike how many votes that map has had total, how many times a map has been nominated, rnand that's probably it, as i wish to show the admin how and what maps are liked by the players.rnrnThe second method is my preferred way as, it offers me the stats.rnrnAny help would be great.
Threads: 75
Joined: Nov 2007
Check these plugins, they mig give you an idea nnhttp://forums.alliedmods.net/showthread.php?p=123146nnhttp://forums.alliedmods.net/showthread.php?p=89510
Threads: 1
Joined: Feb 2008
Lolz,rnI searched all through there and never came across those plugins.rnrnAnother question is when fetching the cvar strings for the SQL it says to get the one i have setup for my AmxBans.rnrn
public sql_init() {rn new host[64], username[32], password[32], dbname[32], error[32]rn rn get_cvar_string("amx_sql_host",host,64)rn get_cvar_string("amx_sql_user",username,32)rn get_cvar_string("amx_sql_pass",password,32)rn get_cvar_string("amx_sql_db",dbname,32)rnrnBut am I able to change it to this and even put the cvar in the sql.cfg as well?rnrnpublic sql_init() {rn new host[64], username[32], password[32], dbname[32], error[32]rn rn get_cvar_string("amx_maps_sql_host",host,64)rn get_cvar_string("amx_maps_sql_user",username,32)rn get_cvar_string("amx_maps_sql_pass",password,32)rn get_cvar_string("amx_maps_sql_db",dbname,32)rnrnAlso how would I go about getting info from different tables in the database?rnrnThanks for your help.Threads: 75
Joined: Nov 2007
sql.cfg is just executed like amxx.cfg, as far as i know, so just add the new cvars.. Getting the info is the fun part. The best answer I think, would be to look at how others did in there plugins.rnrnrnThe two times Ive been using sqlx, Ive used this code to test the connection to the database before asking for any info, if you dont do so it can make the server hang and is a pain in the assrnrnrn
public do_connection() rn{rn if(!get_pcvar_num(p_on))rn return 0rn rn get_pcvar_string(p_host, host, sizeof host - 1)rn get_pcvar_string(p_user, user, sizeof user - 1)rn get_pcvar_string(p_pass, pass, sizeof pass - 1)rn get_pcvar_string(p_db, db, sizeof db - 1)rn get_pcvar_string(p_prefix, prefix, sizeof prefix - 1)rn rn sqlmakedbtuple = SQL_MakeDbTuple(host, user, pass, db)rn sqlconnect = SQL_Connect(sqlmakedbtuple, errorcode, error, sizeof error - 1)rn rn if(!sqlconnect) rn {rn sqlconnect = Empty_Handlern log_to_file(LOG_FILE, "Server cannot connect to database")rn log_to_file(LOG_FILE, "Error (%d): %s", errorcode, error)rn rn return 0rn }rn return 1rn}rnrn/* ...... */rnrnpublic BlahBlah(id)rn{rn if(do_connection())rn {rn /* run query ... */rn }rn}rnThreads: 1
Joined: Feb 2008
Whats the diffrence between the two includes?nnAs i found some of the database ones use the dbi & not sqlxnn
n#include <dbi>n#include <sqlx>nThreads: 75
Joined: Nov 2007
Sqlx is a newer set of natives and stocks, use it. See sqlx.inc
Threads: 75
Joined: Nov 2007
Here is a tutorial btw -> https://forums.alliedmods.net/showthread.php?t=46779
Threads: 1
Joined: Feb 2008
Thanks for your help so far!nnIts going to be like 3000 lines when im done,nShould i split the plugin up into smaller plugins?nWould this help with like any lagg?nnAlso i want to get the plugin to auto download the maps from thendatabase, every x amount of maps. nHow would I do this?nIm making a command of "amx_reloadmaps" to load the maps, I neednto issue that every x amount of maps right?nnThanks.
Threads: 75
Joined: Nov 2007
I would start by getting the info from the database and write it to a test file, just to see the output ofcource. And when thats done correct, just make a the part where it should replace the files used by the map manager... If i get your plan right... that will not be a script in 3000 lines.. start small and build up, be smart ;)
Threads: 1
Joined: Feb 2008
After I posted I decided to scrap that idea, as like you said "start small"nnWould single large plugin create more lagg over smaller ones, eg, if 3000 lines splitninto smaller plugins? (just wondering :P)nnSo far i have got it logging into the database and creating two different tablesnwith there fields.nnPlanning on filling these fields with something, then as you said "write it to a test file"nnSo will get back when i managed it, or if i get stuck :DnThanks
Threads: 75
Joined: Nov 2007
If your scripts make your server lag, something is wrong, or you have passed the limit, no matter if its 10 lines or 3000.nnFell free to ask if something comes up..nnGood luck

