View Single Post
[Godmin] Gonzo
SourceMod Donor
Join Date: Jul 2004
Location: Godmins World
Old 09-08-2005 , 00:55  
Reply With Quote #10

Quote:
Originally Posted by LoWe
This plugin has an issue with big files. If a file is to big the server will crash at when it loads the files, ill try to find time to fix it.
Try this modifyed version:

Code:
/* AMX Mod X script. * * (c) Copyright 2002, Noplay * This file is provided as is (no warranties). * This plugin fetches the name of files and the content of each file from a mysqlserver and then it creates the files on the server, all paths in the filename isrelative to the mod-directory. The files are loaded at mapstart, or by the command: amx_reloadfiles (require ADMIN_RCON access) Currently, the maxlength of the content of the file is around: 3000 symbols and letters. This AMXX plugin requires a dbi-module to be running and configured to use your mysqlserver. To configure your MySQL information, go to the addons/amxmodx/configs/sql.cfg file and edit it. Files specified with the serverid 0 will be loaded at all servers, files with a special serverid will only be loaded at the servers configured with that serverid. To set your servers serverid, type this in your server config: amx_serverid X // Replace X with your servers id; eg. amx_serverid 1 amx_mysqlfiles_table "name" // Sets the name of the "files-table"; eg. amx_mysqlfiles_table "amx_files" Version History: :: 3.00 lowe took over the development Updated for amxmodx 1.0 added amx_reloadfiles command Changed the error handling code. :: 3.01 Changed accesslevel to ADMIN_RCON, thanks to BigBaller and lantz69. :: 3.10 improved the amx_reloadfiles a lot. multilanguage support! Fixed a error with sql-config execution :: 3.20 You may now choice what name you want the "files-table" in the database to have by setting the amx_mysqlfiles_table cvar to the name of the table. The "files-table" will be created automatically (if it doesnt exists), only thing you gotta do is adding "files" too it! Note's by FeliX: This plugin was original developed by NoPlay, and re-written for multiply server support by FeliX. Thanks to GeekGod for help. Note's by lowe: I wish to thank the amxmodx developing team, I sometimes look in the admin.sma and admincmd.sma when i doesn't know how to do ;) . Thanks to the translators: FeliX */ #include <amxmodx> #include <amxmisc> #include <dbi> #pragma dynamic 32768 public plugin_init() {     register_plugin("MySQL Files","3.20","NoPlay/FeliX/lowe")     register_dictionary("mysqlfiles.txt")     register_cvar("amx_sql_host","127.0.0.1")     register_cvar("amx_sql_user","root")     register_cvar("amx_sql_pass","")     register_cvar("amx_sql_db","amx")     register_cvar("amx_serverid","1")     register_cvar("amx_mysqlfiles_table","amx_files")     register_concmd("amx_reloadfiles","load_files",ADMIN_RCON," - Reloads all the textfiles from the mysql database.")     server_cmd("exec addons/amxmodx/configs/sql.cfg")     server_cmd("amx_reloadfiles")     server_cmd("exec server.cfg") } public plugin_modules() {     require_module("DBI") } public load_files(id,level,cid) {     if (!cmd_access(id,level,cid,0))         return PLUGIN_HANDLED     new Sql:SqLlink,cnt     new file[65]     new content[8193]     new error[257]     new host[65]     new user[33]     new pass[33]     new db[33]     new table[33]     new string[98]     get_cvar_string("amx_sql_host",host,64)     get_cvar_string("amx_sql_user",user,32)     get_cvar_string("amx_sql_pass",pass,32)     get_cvar_string("amx_sql_db",db,32)     get_cvar_string("amx_mysqlfiles_table",table,32)     SqLlink = dbi_connect(host,user,pass,db,error,256)     if(SqLlink <= SQL_FAILED)     {         if (!id)         {             server_print("[Mysql Files] %L",LANG_SERVER,"SQL_ERROR",error)         }         else         {             client_print(id,print_console,"[Mysql Files] %L",LANG_PLAYER,"SQL_ERROR",error)         }     }     else     {         dbi_query(SqLlink,"CREATE TABLE IF NOT EXISTS `%s` ( `id` int(11) NOT NULL auto_increment, `serverid` int(11) NOT NULL default '0', `file` varchar(64) NOT NULL default '', `content` text NOT NULL, PRIMARY KEY  (`id`) ) COMMENT = 'AMX Mod X Configuration Files' TYPE=MyISAM",table)         format(string,98,"SELECT file,content FROM %s where serverid = '0' OR serverid = '%d' order by serverid ASC",table,get_cvar_num("amx_serverid"))         new Result:Res = dbi_query(SqLlink,string)         if (Res == RESULT_FAILED || Res == RESULT_NONE)         {             if (dbi_error(SqLlink,error,256))             {                 if (!id)                 {                     server_print("[Mysql Files] %L",LANG_SERVER,"SQL_ERROR",error)                 }                 else                 {                     client_print(id,print_console,"[Mysql Files] %L",LANG_PLAYER,"SQL_ERROR",error)                 }             }             else             {                 if (!id)                 {                     server_print("[Mysql Files] %L",LANG_SERVER,"NO_FILES")                 }                 else                 {                     client_print(id,print_console,"[Mysql Files] %L",LANG_PLAYER,"NO_FILES")                 }             }         }         else         {             cnt = 0             while( dbi_nextrow(Res) > 0)             {                 dbi_result(Res, "file",file,32)                 dbi_result(Res,"content",content,8192)                 if (file_exists(file) && !(delete_file(file)))                 {                     if (!id)                     {                         server_print("[Mysql Files] %L",LANG_SERVER,"DELETE_ERROR",file)                     }                     else                     {                         client_print(id,print_console,"[Mysql Files] %L",LANG_PLAYER,"DELETE_ERROR",file)                     }                     cnt--                 }                 else                 {                     if (!(write_file(file,content)))                     {                         if (!id)                         {                             server_print("[Mysql Files] %L",LANG_SERVER,"WRITE_ERROR",file)                         }                         else                         {                             client_print(id,print_console,"[Mysql Files] %L",LANG_PLAYER,"WRITE_ERROR",file)                         }                     }                 }                 cnt++             }             if (!id)             {                 server_print("[Mysql Files] %L",LANG_SERVER,"LOADED_NUM_FILES",cnt)             }             else             {                 client_print(id,print_console,"[Mysql Files] %L",LANG_PLAYER,"LOADED_NUM_FILES",cnt)             }         }         dbi_free_result(Res)         dbi_close(SqLlink)     }     return PLUGIN_HANDLED }

Note the bigger array/string sizes and #pragma dynamic 32768

Works fine for my server(s) now. Great Plugin, thanks a lot!
__________________
[Godmin] Gonzo is offline
Send a message via ICQ to [Godmin] Gonzo