HLMOD.HU Forrás Megtekintés - www.hlmod.hu
  1. /*
  2.   Fordította: BBk
  3. */
  4.  
  5. /**
  6.  * vim: set ts=4 :
  7.  * =============================================================================
  8.  * SourceMod Map Config Plugin
  9.  * Reads and loads map config cvars from file and then resets them on map end.
  10.  *
  11.  * SourceMod (C)2004-2007 AlliedModders LLC. All rights reserved.
  12.  * =============================================================================
  13.  *
  14.  * This program is free software; you can redistribute it and/or modify it under
  15.  * the terms of the GNU General Public License, version 3.0, as published by the
  16.  * Free Software Foundation.
  17.  *
  18.  * This program is distributed in the hope that it will be useful, but WITHOUT
  19.  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  20.  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  21.  * details.
  22.  *
  23.  * You should have received a copy of the GNU General Public License along with
  24.  * this program. If not, see <http://www.gnu.org/licenses/>.
  25.  *
  26.  * As a special exception, AlliedModders LLC gives you permission to link the
  27.  * code of this program (as well as its derivative works) to "Half-Life 2," the
  28.  * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
  29.  * by the Valve Corporation. You must obey the GNU General Public License in
  30.  * all respects for all other code used. Additionally, AlliedModders LLC grants
  31.  * this exception to all derivative works. AlliedModders LLC defines further
  32.  * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
  33.  * or <http://www.sourcemod.net/license.php>.
  34.  *
  35.  */
  36.  
  37. /*
  38.  * Code written by Liam on 2/16/2008.
  39.  * The purpose of this plugin was to expand upon
  40.  * the existing map config system that the Source
  41.  * and OrangeBox use currently.
  42.  *
  43.  * With the 'built-in' system, you have to be careful
  44.  * to reset all of the cvars to defaults in servers.cfg
  45.  * or the values will carry over after the map changes.
  46.  *
  47.  * This plugin keeps up with what has been loaded from
  48.  * the cfg file and then resets them all at the end of
  49.  * the map so that you don't have to fill your server.cfg
  50.  * up with default values just to cause them to reset.
  51.  *
  52.  * If you have any questions, please feel free to reply
  53.  * to this thread or find me in #sourcemod on irc.gamesurge.net.
  54.  *
  55.  */
  56.  
  57. #pragma semicolon 1
  58. #include <sourcemod>
  59. #include <files>
  60.  
  61. #define TYPE_INT 0
  62. #define TYPE_FLOAT 1
  63. #define TYPE_STRING 2
  64.  
  65. new String:g_MapName[128];
  66. new Handle:g_CvarList;
  67.  
  68. public Plugin:myinfo =
  69. {
  70. name = "Map Configs",
  71. author = "Liam",
  72. description = "Palya konfiguracio betoltese es eltavolitasa fajlbol",
  73. version = "1.2",
  74. url = "www.wcugaming.org"
  75. }
  76.  
  77. public OnPluginStart()
  78. {
  79. RegAdminCmd("sm_reloadconfigs", Command_ReloadConfigs, ADMFLAG_RCON);
  80. InitializeCvars();
  81. }
  82.  
  83. public OnPluginEnd( )
  84. {
  85. if(g_CvarList != INVALID_HANDLE)
  86. {
  87. CloseHandle(g_CvarList);
  88. g_CvarList = INVALID_HANDLE;
  89. }
  90. }
  91.  
  92. public OnMapStart()
  93. {
  94. GetCurrentMap(g_MapName, sizeof(g_MapName));
  95. }
  96.  
  97. public OnAutoConfigsBuffered( )
  98. {
  99. InitializeCvars( );
  100. LoadMapConfigs( );
  101. }
  102.  
  103. public OnMapEnd()
  104. {
  105. new MaxSize = GetArraySize(g_CvarList);
  106.  
  107. for(new i = 0; i < MaxSize; i++)
  108. {
  109. new Handle:cvar = GetArrayCell(g_CvarList, i);
  110.  
  111. ResetConVar(cvar);
  112. CloseHandle(cvar);
  113. cvar = INVALID_HANDLE;
  114. }
  115. CloseHandle(g_CvarList);
  116. g_CvarList = INVALID_HANDLE;
  117. }
  118.  
  119. InitializeCvars( )
  120. {
  121. if(g_CvarList == INVALID_HANDLE)
  122. g_CvarList = CreateArray( );
  123. ClearArray(g_CvarList);
  124. }
  125.  
  126.  
  127. public Action:Command_ReloadConfigs(client, args)
  128. {
  129. LoadMapConfigs( );
  130. return Plugin_Handled;
  131. }
  132.  
  133. LoadMapConfigs( )
  134. {
  135. decl String:filename[128];
  136.  
  137. BuildPath(Path_SM, filename, sizeof(filename), "configs/maps/%s.cfg", g_MapName);
  138.  
  139. if(!FileExists(filename, false))
  140. return;
  141.  
  142. new Handle:file = OpenFile(filename, "r");
  143.  
  144. if(file == INVALID_HANDLE)
  145. {
  146. LogError("LoadMapConfigs() %s fajl megnyitasa nem sikerult.", filename);
  147. return;
  148. }
  149.  
  150. while(IsEndOfFile(file) == false)
  151. {
  152. decl String:line[256];
  153. decl String:arg[128], String:arg2[128];
  154. new len, len2;
  155.  
  156. ReadFileLine(file, line, sizeof(line));
  157.  
  158. if(line[0] == '\0' || line[0] == ';')
  159. continue;
  160.  
  161. TrimString(line);
  162. len = BreakString(line, arg, sizeof(arg));
  163.  
  164. if(len == -1)
  165. {
  166. LogError("LoadMapConfigs: %s fajl tartalmaz egy hianyos sort '%s'.", filename, arg);
  167. continue;
  168. }
  169.  
  170. if(arg[0] == '\0' || arg[0] == '/')
  171. continue;
  172.  
  173. if(arg[0] != 'C' && arg[0] != 'P')
  174. {
  175. LogError("LoadMapConfigs: %s fajl nem tartalmaz jogot ebben a sorban '%s'.", filename, arg);
  176. continue;
  177. }
  178.  
  179. decl String:line2[128];
  180. Format(line2, sizeof(line2), "%s", line[len]);
  181. TrimString(line2);
  182. len2 = BreakString(line2, arg2, sizeof(arg2));
  183.  
  184. if(len2 == -1)
  185. {
  186. LogError("LoadMapConfigs: %s fajl tartalmaz egy hianyos sort '%s'.", filename, arg2);
  187. continue;
  188. }
  189.  
  190. switch(arg[0])
  191. {
  192. case 'C':
  193. {
  194. ParseCvar(arg2, line2[len2], filename);
  195. }
  196.  
  197. case 'P':
  198. {
  199. ParsePluginCommand(arg2, line2[len2]);
  200. }
  201. }
  202. }
  203. CloseHandle(file);
  204. file = INVALID_HANDLE;
  205. }
  206.  
  207. ParseCvar(String:cvar[], String:arg[], String:filename[])
  208. {
  209. new Handle:f_Cvar = INVALID_HANDLE;
  210.  
  211. f_Cvar = FindConVar(cvar);
  212.  
  213. if(f_Cvar == INVALID_HANDLE)
  214. {
  215. LogError("LoadMapConfigs: Rossz cvar '%s %s' a %s fajlban.", cvar, arg, filename);
  216. return;
  217. }
  218. PushArrayCell(g_CvarList, f_Cvar);
  219. ParsePluginCommand(cvar, arg);
  220. }
  221.  
  222. ParsePluginCommand(String:cmd[], String:args[])
  223. {
  224. ServerCommand("%s \"%s\"", cmd, args);
  225. }