autoexecconfig.inc
Original include source with line numbers.
| 1 | stock auto_exec_config(const szName[], bool:bAutoCreate=true) |
| 2 | { |
| 3 | new szFileName[32] |
| 4 | new iLen = copy(szFileName, charsmax(szFileName), szName) |
| 5 | if( iLen <= 4 || !equal(szFileName[iLen-4], ".cfg") ) |
| 6 | { |
| 7 | add(szFileName, charsmax(szFileName), ".cfg") |
| 8 | } |
| 9 | |
| 10 | new szConfigPath[96] |
| 11 | get_localinfo("amxx_configsdir", szConfigPath, charsmax(szConfigPath)) |
| 12 | format(szConfigPath, charsmax(szConfigPath), "%s/%s", szConfigPath, szFileName) |
| 13 | |
| 14 | if( file_exists(szConfigPath) ) |
| 15 | { |
| 16 | server_cmd("exec %s", szConfigPath) |
| 17 | server_exec() |
| 18 | return 1 |
| 19 | } |
| 20 | else if( bAutoCreate ) |
| 21 | { |
| 22 | new fp = fopen(szConfigPath, "wt") |
| 23 | if( !fp ) |
| 24 | { |
| 25 | return -1 |
| 26 | } |
| 27 | new szPluginFileName[96], szPluginName[64], szAuthor[32], szVersion[32], szStatus[2] |
| 28 | new iPlugin = get_plugin(-1, |
| 29 | szPluginFileName, charsmax(szPluginFileName), |
| 30 | szPluginName, charsmax(szPluginName), |
| 31 | szVersion, charsmax(szVersion), |
| 32 | szAuthor, charsmax(szAuthor), |
| 33 | szStatus, charsmax(szStatus) ) |
| 34 | |
| 35 | server_print("Plugin id is %d", iPlugin) |
| 36 | fprintf(fp, "; ^"%s^" configuration file^n", szPluginName) |
| 37 | fprintf(fp, "; Author : ^"%s^"^n", szAuthor) |
| 38 | fprintf(fp, "; Version : ^"%s^"^n", szVersion) |
| 39 | fprintf(fp, "; File : ^"%s^"^n", szPluginFileName) |
| 40 | |
| 41 | new iMax, i, szCommand[64], iCommandAccess, szCmdInfo[128], szFlags[32] |
| 42 | iMax = get_concmdsnum(-1, -1) |
| 43 | fprintf(fp, "^n; Console Commands :^n") |
| 44 | for(i=0; i<iMax; i++) |
| 45 | { |
| 46 | if( get_concmd_plid(i, -1, -1) == iPlugin ) |
| 47 | { |
| 48 | get_concmd(i, |
| 49 | szCommand, charsmax(szCommand), |
| 50 | iCommandAccess, |
| 51 | szCmdInfo, charsmax(szCmdInfo), |
| 52 | -1, -1) |
| 53 | get_flags(iCommandAccess, szFlags, charsmax(szFlags)) |
| 54 | fprintf(fp, "; %s | Access:^"%s^" | ^"%s^"^n", szCommand, szFlags, szCmdInfo) |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | iMax = get_plugins_cvarsnum() |
| 59 | new iTempId, iPcvar, szCvarName[256], szCvarValue[128] |
| 60 | fprintf(fp, "^n; Cvars :^n") |
| 61 | for(new i; i<iMax; i++) |
| 62 | { |
| 63 | get_plugins_cvar(i, szCvarName, charsmax(szCvarName), _, iTempId, iPcvar) |
| 64 | if( iTempId == iPlugin ) |
| 65 | { |
| 66 | get_pcvar_string(iPcvar, szCvarValue, charsmax(szCvarValue)) |
| 67 | fprintf(fp, "%s ^"%s^"^n", szCvarName, szCvarValue) |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | fclose(fp) |
| 72 | } |
| 73 | return 0 |
| 74 | } |