diff --git a/NOTICE.txt b/NOTICE.txt deleted file mode 100644 index 09e18fe7..00000000 --- a/NOTICE.txt +++ /dev/null @@ -1,21 +0,0 @@ -We now use svn:keywords "Id" on all .c/.cpp/.h/.sp/.inc files. Please make sure your client is configured properly. - -WINDOWS: - Open your Application Data folder. - Windows XP/2000: C:\Documents and Settings\\Application Data - Windows Vista: C:\Users\\AppData\Roaming - - Now go to Subversion. Open the "config" file with a text editor. - -LINUX: - Open ~/.subversion/config with your favorite text editor. - -Under [miscellany], uncomment this line: -# enable-auto-props = yes - -Under [auto-props], add these lines: -*.c = svn:keywords=Id -*.cpp = svn:keywords=Id -*.h = svn:keywords=Id -*.sp = svn:keywords=Id -*.inc = svn:keywords=Id diff --git a/configs/admin_groups.cfg b/configs/admin_groups.cfg deleted file mode 100644 index d464d27c..00000000 --- a/configs/admin_groups.cfg +++ /dev/null @@ -1,36 +0,0 @@ -Groups -{ - /** - * Allowed properties for a group: - * - * "flags" - Flag string. - * "immunity" - Immunity level number, or a group name. - * If the group name is a number, prepend it with an - * '@' symbol similar to admins_simple.ini. Users - * will only inherit the level number if it's higher - * than their current value. - */ - "Default" - { - "immunity" "1" - } - - "Full Admins" - { - /** - * You can override commands and command groups here. - * Specify a command name or group and either "allow" or "deny" - * Examples: - * ":CSDM" "allow" - * "csdm_enable" "deny" - */ - Overrides - { - } - "flags" "abcdefghiz" - - /* Largish number for lots of in-between values. */ - "immunity" "99" - } -} - diff --git a/configs/admin_levels.cfg b/configs/admin_levels.cfg deleted file mode 100644 index 3c2c5769..00000000 --- a/configs/admin_levels.cfg +++ /dev/null @@ -1,49 +0,0 @@ -/** - * There is no reason to edit this file. Core uses this to map each named - * access type to a given ASCII character. The names are all pre-defined. - */ -Levels -{ - /** - * These are the default role flag mappings. - * You can assign new letters for custom purposes, however you should - * not change the default names, as SourceMod hardcodes these. - */ - Flags - { - "reservation" "a" //Reserved slots - "generic" "b" //Generic admin, required for admins - "kick" "c" //Kick other players - "ban" "d" //Banning other players - "unban" "e" //Removing bans - "slay" "f" //Slaying other players - "changemap" "g" //Changing the map - "cvars" "h" //Changing cvars - "config" "i" //Changing configs - "chat" "j" //Special chat privileges - "vote" "k" //Voting - "password" "l" //Password the server - "rcon" "m" //Remote console - "cheats" "n" //Change sv_cheats and related commands - - /** - * Custom flags can be used by plugins, but they can also be used to - * for you to expand on the previous groups, using Overrides. - */ - - "custom1" "o" - "custom2" "p" - "custom3" "q" - "custom4" "r" - "custom5" "s" - "custom6" "t" - - /** - * Root is a magic access flag that grants all permissions. - * This should only be given to trusted administrators. - * Root users can target anyone regardless of immunity, - * however, they themselves are not automatically immune. - */ - "root" "z" - } -} diff --git a/configs/admin_overrides.cfg b/configs/admin_overrides.cfg deleted file mode 100644 index 73404659..00000000 --- a/configs/admin_overrides.cfg +++ /dev/null @@ -1,21 +0,0 @@ -Overrides -{ - /** - * By default, commands are registered with three pieces of information: - * 1)Command Name (for example, "csdm_enable") - * 2)Command Group Name (for example, "CSDM") - * 3)Command Level (for example, "changemap") - * - * You can override the default flags assigned to individual commands or command groups in this way. - * To override a group, use the "@" character before the name. Example: - * Examples: - * "@CSDM" "b" // Override the CSDM group to 'b' flag - * "csdm_enable" "bgi" // Override the csdm_enable command to 'bgi' flags - * - * Note that for overrides, order is important. In the above example, csdm_enable overwrites - * any setting that csdm_enable previously had. - * - * You can make a command completely public by using an empty flag string. - */ -} - diff --git a/configs/adminmenu_cfgs.txt b/configs/adminmenu_cfgs.txt deleted file mode 100644 index 644c6d71..00000000 --- a/configs/adminmenu_cfgs.txt +++ /dev/null @@ -1,10 +0,0 @@ -/** - * List config files here (relative to moddir) to have them added to the exec config menu list - * Left side is the filename, right side is the text to be added to the menu - */ -Configs -{ - "cfg/server.cfg" "Standard Server Setup" - "cfg/sourcemod/sm_warmode_on.cfg" "War Mode On" - "cfg/sourcemod/sm_warmode_off.cfg" "War Mode Off" -} diff --git a/configs/adminmenu_maplist.ini b/configs/adminmenu_maplist.ini deleted file mode 100644 index ae9bdf57..00000000 --- a/configs/adminmenu_maplist.ini +++ /dev/null @@ -1,5 +0,0 @@ -// adminmenu_maplist.ini -// -// List maps here to be added to the map and votemap sections of the admin menu -// - diff --git a/configs/adminmenu_sorting.txt b/configs/adminmenu_sorting.txt deleted file mode 100644 index 8dc3a1cb..00000000 --- a/configs/adminmenu_sorting.txt +++ /dev/null @@ -1,34 +0,0 @@ -/** - * The default sorting is designed to look familiar to Mani's admin menu. - * You may re-order items here for your own menu. Any items not explicitly - * sorted will be sorted by their final translated phrases for each given client. - */ - -"Menu" -{ - "PlayerCommands" - { - "item" "sm_slay" - "item" "sm_slap" - "item" "sm_kick" - "item" "sm_ban" - "item" "sm_gag" - "item" "sm_burn" - } - - "ServerCommands" - { - "item" "sm_map" - "item" "sm_execcfg" - "item" "sm_reloadadmins" - } - - "VotingCommands" - { - "item" "sm_cancelvote" - "item" "sm_votemap" - "item" "sm_votekick" - "item" "sm_voteban" - } -} - diff --git a/configs/admins.cfg b/configs/admins.cfg deleted file mode 100644 index ed1e481f..00000000 --- a/configs/admins.cfg +++ /dev/null @@ -1,39 +0,0 @@ - -/** - * USE THIS SECTION TO DECLARE DETAILED ADMIN PROPERTIES. - * - * Each admin should have its own "Admin" section, followed by a name. - * The name does not have to be unique. - * - * Available properties: (Anything else is filtered as custom) - * "auth" - REQUIRED - Auth method to use. Built-in methods are: - * "steam" - Steam based authentication - * "name" - Name based authentication - * "ip" - IP based authentication - * Anything else is treated as custom. - * Note: Only one auth method is allowed per entry. - * - * "identity" - REQUIRED - Identification string, for example, a steamid or name. - * Note: Only one identity is allowed per entry. - * - * "password" - Optional password to require. - * "group" - Adds one group to the user's group table. - * "flags" - Adds one or more flags to the user's permissions. - * "immunity" - Sets the user's immunity level (0 = no immunity). - * Immunity can be any value. Admins with higher - * values cannot be targetted. See sm_immunity_mode - * to tweak the rules. Default value is 0. - * - * Example: - "BAILOPAN" - { - "auth" "steam" - "identity" "STEAM_0:1:16" - "flags" "abcdef" - } - * - */ -Admins -{ -} - diff --git a/configs/admins_simple.ini b/configs/admins_simple.ini deleted file mode 100644 index 9c88bbe6..00000000 --- a/configs/admins_simple.ini +++ /dev/null @@ -1,46 +0,0 @@ -// -// READ THIS CAREFULLY! SEE BOTTOM FOR EXAMPLES -// -// For each admin, you need three settings: -// "identity" "permissions" "password" -// -// For the Identity, you can use a SteamID or Name. To use an IP address, prepend a ! character. -// For the Permissions, you can use a flag string and an optional password. -// -// PERMISSIONS: -// Flag definitions are in "admin_levels.cfg" -// You can combine flags into a string like this: -// "abcdefgh" -// -// If you want to specify a group instead of a flag, use an @ symbol. Example: -// "@Full Admins" -// -// You can also specify immunity values. Two examples: -// "83:abcdefg" //Immunity is 83, flags are abcefgh -// "6:@Full Admins" //Immunity is 6, group is "Full Admins" -// -// Immunity values can be any number. An admin cannot target an admin with -// a higher access value (see sm_immunity_mode to tweak the rules). Default -// immunity value is 0 (no immunity). -// -// PASSWORDS: -// Passwords are generally not needed unless you have name-based authentication. -// In this case, admins must type this in their console: -// -// setinfo "KEY" "PASSWORD" -// -// Where KEY is the "PassInfoVar" setting in your core.cfg file, and "PASSWORD" -// is their password. With name based authentication, this must be done before -// changing names or connecting. Otherwise, SourceMod will automatically detect -// the password being set. -// -//////////////////////////////// -// Examples: (do not put // in front of real lines, as // means 'comment') -// -// "STEAM_0:1:16" "bce" //kick, ban, slay for this steam ID, no immunity -// "!127.0.0.1" "99:z" //all permissions for this ip, immunity value is 99 -// "BAILOPAN" "abc" "Gab3n" //name BAILOPAN, password "Gab3n": gets reservation, kick, ban -// -//////////////////////////////// - - diff --git a/configs/cfg/sm_warmode_off.cfg b/configs/cfg/sm_warmode_off.cfg deleted file mode 100644 index 278c925a..00000000 --- a/configs/cfg/sm_warmode_off.cfg +++ /dev/null @@ -1,4 +0,0 @@ -//This file re-enables a server from "war mode" by unlocking plugin loading -//and refreshing the plugins list. -sm plugins load_unlock -sm plugins refresh diff --git a/configs/cfg/sm_warmode_on.cfg b/configs/cfg/sm_warmode_on.cfg deleted file mode 100644 index ebc3c6f6..00000000 --- a/configs/cfg/sm_warmode_on.cfg +++ /dev/null @@ -1,9 +0,0 @@ -//This file unloads all plugins, re-loads a few "safe" ones, and then prevents -//any more plugins from being loaded. -sm plugins unload_all -sm plugins load basebans.smx -sm plugins load basecommands.smx -sm plugins load admin-flatfile.smx -sm plugins load adminhelp.smx -sm plugins load adminmenu.smx -sm plugins load_lock diff --git a/configs/cfg/sourcemod.cfg b/configs/cfg/sourcemod.cfg deleted file mode 100644 index b98133a6..00000000 --- a/configs/cfg/sourcemod.cfg +++ /dev/null @@ -1,109 +0,0 @@ -// SourceMod Configuration File -// This file is automatically executed by SourceMod every mapchange. - - -// Specifies how admin activity should be relayed to users. Add up the values -// below to get the functionality you want. -// 1: Show admin activity to non-admins anonymously. -// 2: If 1 is specified, admin names will be shown. -// 4: Show admin activity to admins anonymously. -// 8: If 4 is specified, admin names will be shown. -// 16: Always show admin names to root users. -// -- -// Default: 13 (1+4+8) -sm_show_activity 13 - -// Specifies whether menu sounds are enabled for menus created by SourceMod. -// Menu sounds can be further configured in addons/sourcemod/configs/core.cfg. -// -- -// Default: 1 -sm_menu_sounds 1 - -// Specifies how long of a delay, in seconds, should be used in between votes -// that are "public" or can be spammed. Whether or not this delay is obeyed -// is dependent on the menu/command. -// -- -// Default: 30 -sm_vote_delay 30 - -// Default datetime formatting rules when displaying to clients. -// For full options, see: http://www.opengroup.org/onlinepubs/007908799/xsh/strftime.html -// -- -// Default: %m/%d/%Y - %H:%M:%S -// 12 hour format: %m/%d/%Y - %I:%M:%S %p -sm_datetime_format "%m/%d/%Y - %H:%M:%S" - -// Sets how SourceMod should check immunity levels when administrators target -// each other. -// 0: Ignore immunity levels (except for specific group immunities). -// 1: Protect from admins of lower access only. -// 2: Protect from admins of equal to or lower access. -// 3: Same as 2, except admins with no immunity can affect each other. -// -- -// Default: 1 -sm_immunity_mode 1 - -// Sets how many seconds SourceMod should adjust time values for incorrect -// server clocks. This can be positive or negative and will affect every -// system time in SourceMod, including logging stamps. -// -- -// Default: 0 -sm_time_adjustment 0 - -// Specifies the amount of time that is allowed between chat messages. This -// includes the say and say_team commands. If a client sends a message faster -// than this time, they receive a flood token. When the client has accumulated -// 3 or more tokens, a warning message is shown instead of the chat message. -// -- -// Requires: antiflood.smx -// Default: 0.75 -sm_flood_time 0.75 - -// Specifies how the reserved slots plugin operates. Valid values are: -// 0 : Public slots are used in preference to reserved slots. Reserved slots are freed before public slots. -// 1 : If someone with reserve access joins into a reserved slot, the player with the highest latency and -// no reserved slot access (spectator players are selected first) is kicked to make room. Thus, the reserved -// slots always remains free. The only situation where the reserved slot(s) can become properly occupied is -// if the server is full with reserve slot access clients. -// -- -// Requires: reservedslots.smx -// Default: 0 -sm_reserve_type 0 - -// Specifies the number of reserved player slots. Users with the reservation -// admin flag set will be able to join the server when there are no public slots -// remaining. If someone does not have this flag, they will be kicked. -// (Public slots are defined as: maxplayers - number of reserved slots) -// -- -// Requires: reservedslots.smx -// Default: 0 -sm_reserved_slots 0 - -// Specifies whether or not reserved slots will be hidden (subtracted from max -// slot count). Valid values are 0 (visible) or 1 (hidden). -// -- -// Requires: reservedslots.smx -// Default: 0 -sm_hide_slots 0 - -// Specifies whether or not non-admins can send messages to admins using -// say_team @. Valid values are 0 (disabled) or 1 (enabled) -// -- -// Required: basechat.smx -// Default: 1 -sm_chat_mode 1 - -// Specifies whether or not "timeleft" will automaticly be triggered every -// x seconds. Valid values are 0 (disabled) to 1800 seconds. -// -- -// Required: basetriggers.smx -// Default: 0 -sm_timeleft_interval 0 - -// Specifies whether or not chat triggers are broadcast to the server or just -// the player who requested the info trigger. Valid values are 0 (Disabled) or -// 1 (Enabled) -// -- -// Required: basetriggers.smx -// Default: 1 -sm_trigger_show 1 diff --git a/configs/core.cfg b/configs/core.cfg deleted file mode 100644 index c0d83e91..00000000 --- a/configs/core.cfg +++ /dev/null @@ -1,82 +0,0 @@ -/** - * This file is used to set various options that are important to SourceMod's core. - * If this file is missing or an option in this file is missing, then the default values will be used. - */ -"Core" -{ - /** - * Relative path to SourceMod's base directory. This is relative to the game/mod directory. - * Only change this if you have installed SourceMod in a non-default location. - * - * The default value is "addons/sourcemod" - */ - "BasePath" "addons/sourcemod" - - /** - * This option determines if SourceMod logging is enabled. - * - * "on" - Logging is enabled (default) - * "off" - Logging is disabled - */ - "Logging" "on" - - /** - * This option determines how SourceMod logging should be handled. - * - * "daily" - New log file is created for each day (default) - * "map" - New log file is created for each map change - * "game" - Use game's log files - */ - "LogMode" "daily" - - /** - * Language that multilingual enabled plugins and extensions will use to print messages. - * Only languages listed in languages.cfg are valid. - * - * The default value is "en" - */ - "ServerLang" "en" - - /** - * String to use as the public chat trigger. Set an empty string to disable. - */ - "PublicChatTrigger" "!" - - /** - * String to use as the silent chat trigger. Set an empty string to disable. - */ - "SilentChatTrigger" "/" - - /** - * Password setinfo key that clients must set. You must change this in order for - * passwords to work, for security reasons. - */ - "PassInfoVar" "_password" - - /** - * Specifies the sound that gets played when an item is selected from a menu. - */ - "MenuItemSound" "buttons/button14.wav" - - /** - * Specifies the sound that gets played when an "Exit" button is selected - * from a menu. - */ - "MenuExitSound" "buttons/combine_button7.wav" - - /** - * Specifies the sound that gets played when an "Exit Back" button is selected - * from a menu. This is the special "Back" button that is intended to roll back - * to a previous menu. - */ - "MenuExitBackSound" "buttons/combine_button7.wav" - - /** - * Enables or disables whether SourceMod reads a client's cl_language cvar to set - * their language for server-side phrase translation. - * - * "on" - Translate using the client's language (default) - * "off" - Translate using default server's language - */ - "AllowClLanguageVar" "On" -} diff --git a/configs/databases.cfg b/configs/databases.cfg deleted file mode 100644 index 07faf188..00000000 --- a/configs/databases.cfg +++ /dev/null @@ -1,21 +0,0 @@ -"Databases" -{ - "driver_default" "mysql" - - "default" - { - "driver" "default" - "host" "localhost" - "database" "sourcemod" - "user" "root" - "pass" "" - //"timeout" "0" - //"port" "0" - } - - "storage-local" - { - "driver" "sqlite" - "database" "sourcemod-local" - } -} diff --git a/configs/dynamicmenu/adminmenu_grouping.txt b/configs/dynamicmenu/adminmenu_grouping.txt deleted file mode 100644 index 8c391211..00000000 --- a/configs/dynamicmenu/adminmenu_grouping.txt +++ /dev/null @@ -1,18 +0,0 @@ -/* Add group options to be added to 'group' or 'groupplayer' type submenus - * The left side is the name that will show in the menu, right is the command that will be fired - */ - -Groups -{ - "All" "@all" - "Bots" "@bots" - "Alive" "@alive" - "Dead" "@dead" - "Humans" "@humans" - "Current aim" "@aim" - - /* You can enable these if you are using Counter-Strike Source and running the cstrike extension */ -// "Terrorists" "@t" -// "Counter-Terrorists" "@ct" - -} \ No newline at end of file diff --git a/configs/dynamicmenu/menu.ini b/configs/dynamicmenu/menu.ini deleted file mode 100644 index 135520d8..00000000 --- a/configs/dynamicmenu/menu.ini +++ /dev/null @@ -1,389 +0,0 @@ -"Commands" -{ - "Fun Commands" - { - "admin" "sm_ban" - "Set Player Speed" - { - "cmd" "sm_speed #1 #2" - "execute" "player" - "1" - { - "type" "groupplayer" - "method" "name" - "title" "Player/Team to Edit" - - } - "2" - { - "type" "list" - "title" "Speed Multiplier" - "1" "1.0" - "1." "Normal" - "2" "0.8" - "2." "80%" - "3" "0.5" - "3." "Half" - "4" "1.5" - "4." "50% Boost" - "5" "2.0" - "5." "Double" - } - - } - "Give Player Weapon" - { - "cmd" "sm_weapon #1 #2" - "1" - { - "type" "player" - "title" "Player to Give to" - - } - "2" - { - "type" "list" - "title" "Weapon:" - "1" "weapon_ak47" - "1." "Ak-47" - "2" "weapon_m4a1" - "2." "M4A1" - "3" "weapon_deagle" - "3." "Desert Eagle" - "4" "weapon_mp5" - "4." "MP5" - } - - } - "Set Player Armour" - { - "cmd" "sm_armour #1 #2" - "execute" "player" - "1" - { - "type" "groupplayer" - "method" "name" - "title" "Player/Team to Edit" - - } - "2" - { - "type" "list" - "title" "Armour:" - "1" "0" - "2" "20" - "3" "50" - "4" "80" - "5" "100" - } - - } - "Set Player HP" - { - "cmd" "sm_hp #1 #2" - "execute" "player" - "1" - { - "type" "groupplayer" - "method" "name" - "title" "Player/Team to Edit" - - } - "2" - { - "type" "list" - "title" "HP:" - "1" "1" - "2" "20" - "3" "50" - "4" "80" - "5" "100" - "6" "150" - "7" "200" - } - - } - "Bury Player" - { - "cmd" "sm_bury #1" - "execute" "player" - "1" - { - "type" "groupplayer" - "method" "name" - "title" "Player/Team to Bury" - - } - } - "UnBury Player" - { - "cmd" "sm_unbury #1" - "execute" "player" - "1" - { - "type" "groupplayer" - "method" "name" - "title" "Player/Team to UnBury" - - } - } - "Respawn Player" - { - "cmd" "sm_respawn #1" - "execute" "player" - "1" - { - "type" "groupplayer" - "method" "name" - "title" "Player/Team to Respawn" - - } - } - "Disarm Player" - { - "cmd" "sm_disarm #1" - "execute" "player" - "1" - { - "type" "groupplayer" - "method" "name" - "title" "Player/Team to Disarm" - - } - } - "Burn and Disarm" - { - "cmd" "sm_burn #1 #2;sm_disarm #1" - "execute" "player" - "1" - { - "type" "groupplayer" - "method" "name" - "title" "Player/Team to Burn" - - } - "2" - { - "type" "list" - "title" "Time:" - "1" "0" - "2" "5" - "3" "10" - "4" "20" - "5" "30" - } - - } - "Set Player Gravity" - { - "cmd" "sm_gravity #1 #2" - "execute" "player" - "1" - { - "type" "groupplayer" - "method" "name" - "title" "Player/Team to Edit" - - } - "2" - { - "type" "list" - "title" "Speed Multiplier" - "1" "1.0" - "1." "Normal" - "2" "0.8" - "2." "80%" - "3" "0.5" - "3." "Half" - "4" "1.5" - "4." "50% Boost" - "5" "0.25" - "5." "Quarter" - } - - } - "Set Player No-Clip" - { - "cmd" "sm_noclip #1 #2" - "1" - { - "type" "groupplayer" - } - "2" - { - "type" "list" - "1" "1" - "1." "On" - "2" "0" - "2." "Off" - } - } - "Set Player God" - { - "cmd" "sm_god #1 #2" - "1" - { - "type" "groupplayer" - } - "2" - { - "type" "list" - "1" "1" - "1." "On" - "2" "0" - "2." "Off" - } - } - "Set Player NightVision" - { - "cmd" "sm_nv #1 #2" - "1" - { - "type" "groupplayer" - } - "2" - { - "type" "list" - "1" "1" - "1." "Give" - "2" "0" - "2." "Take" - } - } - "Set Player Helmet" - { - "cmd" "sm_helmet #1 #2" - "1" - { - "type" "groupplayer" - } - "2" - { - "type" "list" - "1" "1" - "1." "Give" - "2" "0" - "2." "Take" - } - } - "Set Player Defuse Kit" - { - "cmd" "sm_defuser #1 #2" - "1" - { - "type" "groupplayer" - } - "2" - { - "type" "list" - "1" "1" - "1." "Give" - "2" "0" - "2." "Take" - } - } - - - - } - "ServerCommands" - { - "Extend Map" - { - "cmd" "sm_extend #1" - "1" - { - "type" "list" - "title" "Extend for:" - "1" "5" - "1." "5 Minutes" - "2" "10" - "2." "10 Minutes" - "3" "15" - "3." "15 Minutes" - "4" "20" - "4." "20 Minutes" - "5" "30" - "5." "Half an Hour" - "6" "45" - "6." "45 Minutes" - "7" "60" - "7." "An Hour" - } - } - - } - "Cvars" - { - "admin" "sm_kick" - "Timelimit" - { - "cmd" "mp_timelimit #1" - "execute" "server" - "1" - { - "type" "list" - "title" "Timelimit:" - "1" "20" - "2" "40" - "3" "60" - - } - } - "Friendly Fire" - { - "cmd" "mp_friendlyfire #1" - "execute" "server" - "1" - { - "type" "list" - "title" "Friendly Fire:" - "1" "1" - "1." "On" - "2" "0" - "2." "Off" - } - } - "Show Damage Done" - { - "cmd" "sm_showdamage #1" - "admin" "sm_csay" - "execute" "server" - "1" - { - "type" "list" - "title" "Show Damage Done:" - "1" "1" - "1." "On" - "2" "0" - "2." "Off" - } - } - } - "Team management" - { - "Team Player" - { - "cmd" "sm_team #1 #2" - "1" - { - "type" "player" - } - "2" - { - "type" "list" - "title" "Team:" - "1" "1" - "1." "Spectators" - "2" "2" - "2." "Terrorists" - "3" "3" - "3." "Counter-Terrorists" - } - } - "Switch Team" - { - "cmd" "sm_teamswap" - } - } -} \ No newline at end of file diff --git a/configs/geoip/GeoIP.dat b/configs/geoip/GeoIP.dat deleted file mode 100644 index 0531b57c..00000000 Binary files a/configs/geoip/GeoIP.dat and /dev/null differ diff --git a/configs/languages.cfg b/configs/languages.cfg deleted file mode 100644 index 6bbce279..00000000 --- a/configs/languages.cfg +++ /dev/null @@ -1,6 +0,0 @@ -"Languages" -{ - "en" "English" - "es" "Español" -} - diff --git a/configs/plugin_settings.cfg b/configs/plugin_settings.cfg deleted file mode 100644 index 20212f7a..00000000 --- a/configs/plugin_settings.cfg +++ /dev/null @@ -1,31 +0,0 @@ -/** - * Each sub-section of "Plugins" should have a title which specifies a plugin filename. - * Filenames have a wildcard of *. Appending .smx is not required. - * If the filename has no explicit path, it will be patched to any sub-path in the plugins folder. - * - * Available properties for plugins are: - * "pause" - Whether or not the plugin should load paused - "yes" or "no" (defualt) - * "lifetime" - Lifetime of the plugin. Options: - * "mapsync" - Plugins should be reloaded on mapchange if changed (default) - * "global" - Plugin will never be unloaded or updated - * "blockload" - Plugin will always be blocked from loading. Implicit (automatic) loads - * produce no error, but explicit (manual) loads will show an error message. - * (Options are one of "yes" or "no") - * - * You can also have an "Options" section declaring options to pass onto the JIT: - * "debug" - Whether or not to load the plugin in debug mode - */ - -"Plugins" -{ - "*" - { - "pause" "no" - "lifetime" "mapsync" - - "Options" - { - "debug" "no" - } - } -} diff --git a/configs/sql-init-scripts/mysql/create_admins.sql b/configs/sql-init-scripts/mysql/create_admins.sql deleted file mode 100644 index 0791aa34..00000000 --- a/configs/sql-init-scripts/mysql/create_admins.sql +++ /dev/null @@ -1,56 +0,0 @@ - -CREATE TABLE sm_admins ( - id int(10) unsigned NOT NULL auto_increment, - authtype enum('steam','name','ip') NOT NULL, - identity varchar(65) NOT NULL, - password varchar(65), - flags varchar(30) NOT NULL, - name varchar(65) NOT NULL, - immunity int(10) unsigned NOT NULL, - PRIMARY KEY (id) -); - -CREATE TABLE sm_groups ( - id int(10) unsigned NOT NULL auto_increment, - flags varchar(30) NOT NULL, - name varchar(120) NOT NULL, - immunity_level int(1) unsigned NOT NULL, - PRIMARY KEY (id) -); - -CREATE TABLE sm_group_immunity ( - group_id int(10) unsigned NOT NULL, - other_id int(10) unsigned NOT NULL, - PRIMARY KEY (group_id, other_id) -); - -CREATE TABLE sm_group_overrides ( - group_id int(10) unsigned NOT NULL, - type enum('command','group') NOT NULL, - name varchar(32) NOT NULL, - access enum('allow','deny') NOT NULL, - PRIMARY KEY (group_id, type, name) -); - -CREATE TABLE sm_overrides ( - type enum('command','group') NOT NULL, - name varchar(32) NOT NULL, - flags varchar(30) NOT NULL, - PRIMARY KEY (type,name) -); - -CREATE TABLE sm_admins_groups ( - admin_id int(10) unsigned NOT NULL, - group_id int(10) unsigned NOT NULL, - inherit_order int(10) NOT NULL, - PRIMARY KEY (admin_id, group_id) -); - -CREATE TABLE IF NOT EXISTS sm_config ( - cfg_key varchar(32) NOT NULL, - cfg_value varchar(255) NOT NULL, - PRIMARY KEY (cfg_key) -); - -INSERT INTO sm_config (cfg_key, cfg_value) VALUES ('admin_version', '1.0.0.1409') ON DUPLICATE KEY UPDATE cfg_value = '1.0.0.1409'; - diff --git a/configs/sql-init-scripts/mysql/update_admins_r1409.sql b/configs/sql-init-scripts/mysql/update_admins_r1409.sql deleted file mode 100644 index 81c0992c..00000000 --- a/configs/sql-init-scripts/mysql/update_admins_r1409.sql +++ /dev/null @@ -1,15 +0,0 @@ - -ALTER TABLE sm_admins ADD immunity INT UNSIGNED NOT NULL; - -ALTER TABLE sm_groups ADD immunity_level INT UNSIGNED NOT NULL; -UPDATE sm_groups SET immunity_level = 2 WHERE immunity = 'default'; -UPDATE sm_groups SET immunity_level = 1 WHERE immunity = 'global'; -ALTER TABLE sm_groups DROP immunity; - -CREATE TABLE sm_config ( - cfg_key varchar(32) NOT NULL, - cfg_value varchar(255) NOT NULL, - PRIMARY KEY (cfg_key) -); -INSERT INTO sm_config (cfg_key, cfg_value) VALUES ('admin_version', '1.0.0.1409') ON DUPLICATE KEY UPDATE cfg_value = '1.0.0.1409'; - diff --git a/configs/sql-init-scripts/sqlite/admins-sqlite.sq3 b/configs/sql-init-scripts/sqlite/admins-sqlite.sq3 deleted file mode 100644 index c68bc42e..00000000 Binary files a/configs/sql-init-scripts/sqlite/admins-sqlite.sq3 and /dev/null differ diff --git a/configs/sql-init-scripts/sqlite/create_admins.sql b/configs/sql-init-scripts/sqlite/create_admins.sql deleted file mode 100644 index 1dfa91d6..00000000 --- a/configs/sql-init-scripts/sqlite/create_admins.sql +++ /dev/null @@ -1,54 +0,0 @@ - -CREATE TABLE sm_admins ( - id INTEGER PRIMARY KEY AUTOINCREMENT, - authtype varchar(16) NOT NULL CHECK(authtype IN ('steam', 'ip', 'name')), - identity varchar(65) NOT NULL, - password varchar(65), - flags varchar(30) NOT NULL, - name varchar(65) NOT NULL, - immunity INTEGER NOT NULL -); - -CREATE TABLE sm_groups ( - id INTEGER PRIMARY KEY AUTOINCREMENT, - flags varchar(30) NOT NULL, - name varchar(120) NOT NULL, - immunity_level INTEGER NOT NULL -); - -CREATE TABLE sm_group_immunity ( - group_id INTEGER NOT NULL, - other_id INTEGER NOT NULL, - PRIMARY KEY (group_id, other_id) -); - -CREATE TABLE sm_group_overrides ( - group_id INTEGER NOT NULL, - type varchar(16) NOT NULL CHECK (type IN ('command', 'group')), - name varchar(32) NOT NULL, - access varchar(16) NOT NULL CHECK (access IN ('allow', 'deny')), - PRIMARY KEY (group_id, type, name) -); - -CREATE TABLE sm_overrides ( - type varchar(16) NOT NULL CHECK (type IN ('command', 'group')), - name varchar(32) NOT NULL, - flags varchar(30) NOT NULL, - PRIMARY KEY (type,name) -); - -CREATE TABLE sm_admins_groups ( - admin_id INTEGER NOT NULL, - group_id INTEGER NOT NULL, - inherit_order int(10) NOT NULL, - PRIMARY KEY (admin_id, group_id) -); - -CREATE TABLE IF NOT EXISTS sm_config ( - cfg_key varchar(32) NOT NULL, - cfg_value varchar(255) NOT NULL, - PRIMARY KEY (cfg_key) -); - -REPLACE INTO sm_config (cfg_key, cfg_value) VALUES ('admin_version', '1.0.0.1409'); - diff --git a/configs/sql-init-scripts/sqlite/update_admins-r1409.sql b/configs/sql-init-scripts/sqlite/update_admins-r1409.sql deleted file mode 100644 index d3a85ec8..00000000 --- a/configs/sql-init-scripts/sqlite/update_admins-r1409.sql +++ /dev/null @@ -1,23 +0,0 @@ - -ALTER TABLE sm_admins ADD immunity INTEGER DEFAULT 0 NOT NULL; - -CREATE TABLE _sm_groups_temp ( - id INTEGER PRIMARY KEY AUTOINCREMENT, - flags varchar(30) NOT NULL, - name varchar(120) NOT NULL, - immunity_level INTEGER DEFAULT 0 NOT NULL -); -INSERT INTO _sm_groups_temp (id, flags, name) SELECT id, flags, name FROM sm_groups; -UPDATE _sm_groups_temp SET immunity_level = 2 WHERE id IN (SELECT g.id FROM sm_groups g WHERE g.immunity = 'global'); -UPDATE _sm_groups_temp SET immunity_level = 1 WHERE id IN (SELECT g.id FROM sm_groups g WHERE g.immunity = 'default'); -DROP TABLE sm_groups; -ALTER TABLE _sm_groups_temp RENAME TO sm_groups; - -CREATE TABLE IF NOT EXISTS sm_config ( - cfg_key varchar(32) NOT NULL, - cfg_value varchar(255) NOT NULL, - PRIMARY KEY (cfg_key) -); - -REPLACE INTO sm_config (cfg_key, cfg_value) VALUES ('admin_version', '1.0.0.1409'); - diff --git a/core/ADTFactory.cpp b/core/ADTFactory.cpp deleted file mode 100644 index c6630971..00000000 --- a/core/ADTFactory.cpp +++ /dev/null @@ -1,96 +0,0 @@ -/** - * vim: set ts=4 : - * ============================================================================= - * SourceMod - * Copyright (C) 2004-2007 AlliedModders LLC. All rights reserved. - * ============================================================================= - * - * This program is free software; you can redistribute it and/or modify it under - * the terms of the GNU General Public License, version 3.0, as published by the - * Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more - * details. - * - * You should have received a copy of the GNU General Public License along with - * this program. If not, see . - * - * As a special exception, AlliedModders LLC gives you permission to link the - * code of this program (as well as its derivative works) to "Half-Life 2," the - * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software - * by the Valve Corporation. You must obey the GNU General Public License in - * all respects for all other code used. Additionally, AlliedModders LLC grants - * this exception to all derivative works. AlliedModders LLC defines further - * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007), - * or . - * - * Version: $Id$ - */ - -#include "ADTFactory.h" -#include "sm_globals.h" -#include "ShareSys.h" - -ADTFactory g_AdtFactory; - -const char *ADTFactory::GetInterfaceName() -{ - return SMINTERFACE_ADTFACTORY_NAME; -} - -unsigned int ADTFactory::GetInterfaceVersion() -{ - return SMINTERFACE_ADTFACTORY_VERSION; -} - -void ADTFactory::OnSourceModAllInitialized() -{ - g_ShareSys.AddInterface(NULL, this); -} - -IBasicTrie *ADTFactory::CreateBasicTrie() -{ - return new BaseTrie(); -} - -BaseTrie::BaseTrie() -{ - m_pTrie = sm_trie_create(); -} - -BaseTrie::~BaseTrie() -{ - sm_trie_destroy(m_pTrie); -} - -bool BaseTrie::Insert(const char *key, void *value) -{ - return sm_trie_insert(m_pTrie, key, value); -} - -bool BaseTrie::Retrieve(const char *key, void **value) -{ - return sm_trie_retrieve(m_pTrie, key, value); -} - -bool BaseTrie::Delete(const char *key) -{ - return sm_trie_delete(m_pTrie, key); -} - -void BaseTrie::Clear() -{ - sm_trie_clear(m_pTrie); -} - -void BaseTrie::Destroy() -{ - delete this; -} - -bool BaseTrie::Replace(const char *key, void *value) -{ - return sm_trie_replace(m_pTrie, key, value); -} diff --git a/core/ADTFactory.h b/core/ADTFactory.h deleted file mode 100644 index 9c80a0de..00000000 --- a/core/ADTFactory.h +++ /dev/null @@ -1,70 +0,0 @@ -/** - * vim: set ts=4 : - * ============================================================================= - * SourceMod - * Copyright (C) 2004-2007 AlliedModders LLC. All rights reserved. - * ============================================================================= - * - * This program is free software; you can redistribute it and/or modify it under - * the terms of the GNU General Public License, version 3.0, as published by the - * Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more - * details. - * - * You should have received a copy of the GNU General Public License along with - * this program. If not, see . - * - * As a special exception, AlliedModders LLC gives you permission to link the - * code of this program (as well as its derivative works) to "Half-Life 2," the - * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software - * by the Valve Corporation. You must obey the GNU General Public License in - * all respects for all other code used. Additionally, AlliedModders LLC grants - * this exception to all derivative works. AlliedModders LLC defines further - * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007), - * or . - * - * Version: $Id$ - */ - -#ifndef _INCLUDE_SOURCEMOD_ADTFACTORY_H_ -#define _INCLUDE_SOURCEMOD_ADTFACTORY_H_ - -#include -#include "sm_globals.h" -#include "sm_trie.h" - -using namespace SourceMod; - -class BaseTrie : public IBasicTrie -{ -public: - BaseTrie(); - virtual ~BaseTrie(); - virtual bool Insert(const char *key, void *value); - virtual bool Replace(const char *key, void *value); - virtual bool Retrieve(const char *key, void **value); - virtual bool Delete(const char *key); - virtual void Clear(); - virtual void Destroy(); -private: - Trie *m_pTrie; -}; - -class ADTFactory : - public SMGlobalClass, - public IADTFactory -{ -public: //SMInterface - const char *GetInterfaceName(); - unsigned int GetInterfaceVersion(); -public: //SMGlobalClass - void OnSourceModAllInitialized(); -public: //IADTFactory - IBasicTrie *CreateBasicTrie(); -}; - -#endif //_INCLUDE_SOURCEMOD_ADTFACTORY_H_ - diff --git a/core/AdminCache.cpp b/core/AdminCache.cpp deleted file mode 100644 index f8c880e3..00000000 --- a/core/AdminCache.cpp +++ /dev/null @@ -1,1732 +0,0 @@ -/** - * vim: set ts=4 : - * ============================================================================= - * SourceMod - * Copyright (C) 2004-2007 AlliedModders LLC. All rights reserved. - * ============================================================================= - * - * This program is free software; you can redistribute it and/or modify it under - * the terms of the GNU General Public License, version 3.0, as published by the - * Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more - * details. - * - * You should have received a copy of the GNU General Public License along with - * this program. If not, see . - * - * As a special exception, AlliedModders LLC gives you permission to link the - * code of this program (as well as its derivative works) to "Half-Life 2," the - * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software - * by the Valve Corporation. You must obey the GNU General Public License in - * all respects for all other code used. Additionally, AlliedModders LLC grants - * this exception to all derivative works. AlliedModders LLC defines further - * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007), - * or . - * - * Version: $Id$ - */ - -#include -#include -#include -#include "AdminCache.h" -#include "ShareSys.h" -#include "ForwardSys.h" -#include "PlayerManager.h" -#include "ConCmdManager.h" -#include "Logger.h" -#include "sourcemod.h" -#include "sm_stringutil.h" -#include "sourcemm_api.h" - -#define LEVEL_STATE_NONE 0 -#define LEVEL_STATE_LEVELS 1 -#define LEVEL_STATE_FLAGS 2 - -AdminCache g_Admins; -AdminFlag g_FlagLetters[26]; -bool g_FlagSet[26]; - -ConVar sm_immunity_mode("sm_immunity_mode", "1", FCVAR_SPONLY|FCVAR_PROTECTED, "Mode for deciding immunity protection"); - -/* Default flags */ -AdminFlag g_DefaultFlags[26] = -{ - Admin_Reservation, Admin_Generic, Admin_Kick, Admin_Ban, Admin_Unban, - Admin_Slay, Admin_Changemap, Admin_Convars, Admin_Config, Admin_Chat, - Admin_Vote, Admin_Password, Admin_RCON, Admin_Cheats, Admin_Custom1, - Admin_Custom2, Admin_Custom3, Admin_Custom4, Admin_Custom5, Admin_Custom6, - Admin_Generic, Admin_Generic, Admin_Generic, Admin_Generic, Admin_Generic, - Admin_Root -}; - - -class FlagReader : public ITextListener_SMC -{ -public: - void LoadLevels() - { - if (!Parse()) - { - memcpy(g_FlagLetters, g_DefaultFlags, sizeof(AdminFlag) * 26); - for (unsigned int i=0; i<20; i++) - { - g_FlagSet[i] = true; - } - g_FlagSet[25] = true; - } - } -private: - bool Parse() - { - SMCStates states; - SMCError error; - - m_bFileNameLogged = false; - g_SourceMod.BuildPath(Path_SM, m_File, sizeof(m_File), "configs/admin_levels.cfg"); - - if ((error = textparsers->ParseFile_SMC(m_File, this, &states)) - != SMCError_Okay) - { - const char *err_string = textparsers->GetSMCErrorString(error); - if (!err_string) - { - err_string = "Unknown error"; - } - ParseError(NULL, "Error %d (%s)", error, err_string); - return false; - } - - return true; - } - void ReadSMC_ParseStart() - { - m_LevelState = LEVEL_STATE_NONE; - m_IgnoreLevel = 0; - memset(g_FlagSet, 0, sizeof(g_FlagSet)); - } - SMCResult ReadSMC_NewSection(const SMCStates *states, const char *name) - { - if (m_IgnoreLevel) - { - m_IgnoreLevel++; - return SMCResult_Continue; - } - - if (m_LevelState == LEVEL_STATE_NONE) - { - if (strcmp(name, "Levels") == 0) - { - m_LevelState = LEVEL_STATE_LEVELS; - } - else - { - m_IgnoreLevel++; - } - } else if (m_LevelState == LEVEL_STATE_LEVELS) { - if (strcmp(name, "Flags") == 0) - { - m_LevelState = LEVEL_STATE_FLAGS; - } - else - { - m_IgnoreLevel++; - } - } - else - { - m_IgnoreLevel++; - } - - return SMCResult_Continue; - } - SMCResult ReadSMC_KeyValue(const SMCStates *states, const char *key, const char *value) - { - if (m_LevelState != LEVEL_STATE_FLAGS || m_IgnoreLevel) - { - return SMCResult_Continue; - } - - unsigned char c = (unsigned)value[0]; - - if (c < (unsigned)'a' || c > (unsigned)'z') - { - ParseError(states, "Flag \"%c\" is not a lower-case ASCII letter", c); - return SMCResult_Continue; - } - - c -= (unsigned)'a'; - - assert(c >= 0 && c < 26); - - if (!g_Admins.FindFlag(key, &g_FlagLetters[c])) - { - ParseError(states, "Unrecognized admin level \"%s\"", key); - return SMCResult_Continue; - } - - g_FlagSet[c] = true; - - return SMCResult_Continue; - } - SMCResult ReadSMC_LeavingSection(const SMCStates *states) - { - if (m_IgnoreLevel) - { - m_IgnoreLevel--; - return SMCResult_Continue; - } - - if (m_LevelState == LEVEL_STATE_FLAGS) - { - m_LevelState = LEVEL_STATE_LEVELS; - return SMCResult_Halt; - } - else if (m_LevelState == LEVEL_STATE_LEVELS) - { - m_LevelState = LEVEL_STATE_NONE; - } - - return SMCResult_Continue; - } - void ParseError(const SMCStates *states, const char *message, ...) - { - va_list ap; - char buffer[256]; - - va_start(ap, message); - UTIL_FormatArgs(buffer, sizeof(buffer), message, ap); - va_end(ap); - - if (!m_bFileNameLogged) - { - g_Logger.LogError("[SM] Parse error(s) detected in file \"%s\":", m_File); - m_bFileNameLogged = true; - } - - g_Logger.LogError("[SM] (Line %d): %s", states ? states->line : 0, buffer); - } -private: - bool m_bFileNameLogged; - char m_File[PLATFORM_MAX_PATH]; - int m_LevelState; - int m_IgnoreLevel; -} s_FlagReader; - -AdminCache::AdminCache() -{ - m_pCmdOverrides = sm_trie_create(); - m_pCmdGrpOverrides = sm_trie_create(); - m_pStrings = new BaseStringTable(1024); - m_pMemory = m_pStrings->GetMemTable(); - m_FreeGroupList = m_FirstGroup = m_LastGroup = INVALID_GROUP_ID; - m_FreeUserList = m_FirstUser = m_LastUser = INVALID_ADMIN_ID; - m_pGroups = sm_trie_create(); - m_pCacheFwd = NULL; - m_FirstGroup = -1; - m_pAuthTables = sm_trie_create(); - m_InvalidatingAdmins = false; - m_destroying = false; - m_pLevelNames = sm_trie_create(); -} - -AdminCache::~AdminCache() -{ - m_destroying = true; - DumpAdminCache(AdminCache_Overrides, false); - DumpAdminCache(AdminCache_Groups, false); - - sm_trie_destroy(m_pCmdGrpOverrides); - sm_trie_destroy(m_pCmdOverrides); - - if (m_pGroups) - { - sm_trie_destroy(m_pGroups); - } - - List::iterator iter; - for (iter=m_AuthMethods.begin(); - iter!=m_AuthMethods.end(); - iter++) - { - sm_trie_destroy((*iter).table); - } - - sm_trie_destroy(m_pAuthTables); - - delete m_pStrings; - - sm_trie_destroy(m_pLevelNames); -} - -void AdminCache::OnSourceModStartup(bool late) -{ - RegisterAuthIdentType("steam"); - RegisterAuthIdentType("name"); - RegisterAuthIdentType("ip"); - - NameFlag("reservation", Admin_Reservation); - NameFlag("kick", Admin_Kick); - NameFlag("generic", Admin_Generic); - NameFlag("ban", Admin_Ban); - NameFlag("unban", Admin_Unban); - NameFlag("slay", Admin_Slay); - NameFlag("changemap", Admin_Changemap); - NameFlag("cvars", Admin_Convars); - NameFlag("config", Admin_Config); - NameFlag("chat", Admin_Chat); - NameFlag("vote", Admin_Vote); - NameFlag("password", Admin_Password); - NameFlag("rcon", Admin_RCON); - NameFlag("cheats", Admin_Cheats); - NameFlag("root", Admin_Root); - NameFlag("custom1", Admin_Custom1); - NameFlag("custom2", Admin_Custom2); - NameFlag("custom3", Admin_Custom3); - NameFlag("custom4", Admin_Custom4); - NameFlag("custom5", Admin_Custom5); - NameFlag("custom6", Admin_Custom6); -} - -void AdminCache::OnSourceModAllInitialized() -{ - m_pCacheFwd = g_Forwards.CreateForward("OnRebuildAdminCache", ET_Ignore, 1, NULL, Param_Cell); - g_ShareSys.AddInterface(NULL, this); -} - -void AdminCache::OnSourceModLevelChange(const char *mapName) -{ - /* For now, we only read these once per level. */ - s_FlagReader.LoadLevels(); -} - -void AdminCache::OnSourceModShutdown() -{ - g_Forwards.ReleaseForward(m_pCacheFwd); - m_pCacheFwd = NULL; -} - -void AdminCache::OnSourceModPluginsLoaded() -{ - DumpAdminCache(AdminCache_Overrides, true); - DumpAdminCache(AdminCache_Groups, true); -} - -void AdminCache::NameFlag(const char *str, AdminFlag flag) -{ - sm_trie_insert(m_pLevelNames, str, (void *)flag); -} - -bool AdminCache::FindFlag(const char *str, AdminFlag *pFlag) -{ - void *obj; - if (!sm_trie_retrieve(m_pLevelNames, str, &obj)) - { - return false; - } - - if (pFlag) - { - *pFlag = (AdminFlag)(int)obj; - } - - return true; -} - -void AdminCache::AddCommandOverride(const char *cmd, OverrideType type, FlagBits flags) -{ - Trie *pTrie = NULL; - if (type == Override_Command) - { - pTrie = m_pCmdOverrides; - } else if (type == Override_CommandGroup) { - pTrie = m_pCmdGrpOverrides; - } else { - return; - } - - sm_trie_insert(pTrie, cmd, (void *)(unsigned int)flags); - - g_ConCmds.UpdateAdminCmdFlags(cmd, type, flags, false); -} - -bool AdminCache::GetCommandOverride(const char *cmd, OverrideType type, FlagBits *pFlags) -{ - Trie *pTrie = NULL; - - if (type == Override_Command) - { - pTrie = m_pCmdOverrides; - } else if (type == Override_CommandGroup) { - pTrie = m_pCmdGrpOverrides; - } else { - return false; - } - - void *object; - if (sm_trie_retrieve(pTrie, cmd, &object)) - { - if (pFlags) - { - *pFlags = (FlagBits)object; - } - return true; - } - - return false; -} - -void AdminCache::UnsetCommandOverride(const char *cmd, OverrideType type) -{ - if (type == Override_Command) - { - return _UnsetCommandOverride(cmd); - } else if (type == Override_CommandGroup) { - return _UnsetCommandGroupOverride(cmd); - } -} - -void AdminCache::_UnsetCommandGroupOverride(const char *group) -{ - if (!m_pCmdGrpOverrides) - { - return; - } - - sm_trie_delete(m_pCmdGrpOverrides, group); - - g_ConCmds.UpdateAdminCmdFlags(group, Override_CommandGroup, 0, true); -} - -void AdminCache::_UnsetCommandOverride(const char *cmd) -{ - if (!m_pCmdOverrides) - { - return; - } - - sm_trie_delete(m_pCmdOverrides, cmd); - - g_ConCmds.UpdateAdminCmdFlags(cmd, Override_Command, 0, true); -} - -void AdminCache::DumpCommandOverrideCache(OverrideType type) -{ - if (type == Override_Command && m_pCmdOverrides) - { - sm_trie_clear(m_pCmdOverrides); - } else if (type == Override_CommandGroup && m_pCmdGrpOverrides) { - sm_trie_clear(m_pCmdGrpOverrides); - } -} - -AdminId AdminCache::CreateAdmin(const char *name) -{ - AdminId id; - AdminUser *pUser; - - if (m_FreeUserList != INVALID_ADMIN_ID) - { - pUser = (AdminUser *)m_pMemory->GetAddress(m_FreeUserList); - assert(pUser->magic == USR_MAGIC_UNSET); - id = m_FreeUserList; - m_FreeUserList = pUser->next_user; - } else { - id = m_pMemory->CreateMem(sizeof(AdminUser), (void **)&pUser); - pUser->grp_size = 0; - pUser->grp_table = -1; - } - - pUser->flags = 0; - pUser->eflags = 0; - pUser->grp_count = 0; - pUser->password = -1; - pUser->magic = USR_MAGIC_SET; - pUser->auth.identidx = -1; - pUser->auth.index = 0; - pUser->immunity_level = 0; - pUser->serialchange = 1; - - if (m_FirstUser == INVALID_ADMIN_ID) - { - m_FirstUser = id; - m_LastUser = id; - } else { - AdminUser *pPrev = (AdminUser *)m_pMemory->GetAddress(m_LastUser); - pPrev->next_user = id; - pUser->prev_user = m_LastUser; - m_LastUser = id; - } - - if (name && name[0] != '\0') - { - int nameidx = m_pStrings->AddString(name); - pUser = (AdminUser *)m_pMemory->GetAddress(id); - pUser->nameidx = nameidx; - } - - return id; -} - -GroupId AdminCache::AddGroup(const char *group_name) -{ - if (sm_trie_retrieve(m_pGroups, group_name, NULL)) - { - return INVALID_GROUP_ID; - } - - GroupId id; - AdminGroup *pGroup; - if (m_FreeGroupList != INVALID_GROUP_ID) - { - pGroup = (AdminGroup *)m_pMemory->GetAddress(m_FreeGroupList); - assert(pGroup->magic == GRP_MAGIC_UNSET); - id = m_FreeGroupList; - m_FreeGroupList = pGroup->next_grp; - } else { - id = m_pMemory->CreateMem(sizeof(AdminGroup), (void **)&pGroup); - } - - pGroup->immunity_level = 0; - pGroup->immune_table = -1; - pGroup->magic = GRP_MAGIC_SET; - pGroup->next_grp = INVALID_GROUP_ID; - pGroup->pCmdGrpTable = NULL; - pGroup->pCmdTable = NULL; - pGroup->addflags = 0; - - if (m_FirstGroup == INVALID_GROUP_ID) - { - m_FirstGroup = id; - m_LastGroup = id; - pGroup->prev_grp = INVALID_GROUP_ID; - } else { - AdminGroup *pPrev = (AdminGroup *)m_pMemory->GetAddress(m_LastGroup); - assert(pPrev->magic == GRP_MAGIC_SET); - pPrev->next_grp = id; - pGroup->prev_grp = m_LastGroup; - m_LastGroup = id; - } - - int nameidx = m_pStrings->AddString(group_name); - pGroup = (AdminGroup *)m_pMemory->GetAddress(id); - pGroup->nameidx = nameidx; - - sm_trie_insert(m_pGroups, group_name, (void *)id); - - return id; -} - -GroupId AdminCache::FindGroupByName(const char *group_name) -{ - void *object; - - if (!sm_trie_retrieve(m_pGroups, group_name, &object)) - { - return INVALID_GROUP_ID; - } - - GroupId id = (GroupId)object; - AdminGroup *pGroup = (AdminGroup *)m_pMemory->GetAddress(id); - - if (!pGroup || pGroup->magic != GRP_MAGIC_SET) - { - return INVALID_GROUP_ID; - } - - return id; -} - -void AdminCache::SetGroupAddFlag(GroupId id, AdminFlag flag, bool enabled) -{ - AdminGroup *pGroup = (AdminGroup *)m_pMemory->GetAddress(id); - if (!pGroup || pGroup->magic != GRP_MAGIC_SET) - { - return; - } - - if (flag < Admin_Reservation || flag >= AdminFlags_TOTAL) - { - return; - } - - FlagBits bits = (1<<(FlagBits)flag); - - if (enabled) - { - pGroup->addflags |= bits; - } else { - pGroup->addflags &= ~bits; - } -} - -bool AdminCache::GetGroupAddFlag(GroupId id, AdminFlag flag) -{ - AdminGroup *pGroup = (AdminGroup *)m_pMemory->GetAddress(id); - if (!pGroup || pGroup->magic != GRP_MAGIC_SET) - { - return false; - } - - if (flag < Admin_Reservation || flag >= AdminFlags_TOTAL) - { - return false; - } - - FlagBits bit = 1<<(FlagBits)flag; - return ((pGroup->addflags & bit) == bit); -} - -FlagBits AdminCache::GetGroupAddFlags(GroupId id) -{ - AdminGroup *pGroup = (AdminGroup *)m_pMemory->GetAddress(id); - if (!pGroup || pGroup->magic != GRP_MAGIC_SET) - { - return 0; - } - - return pGroup->addflags; -} - -const char *AdminCache::GetGroupName(GroupId gid) -{ - AdminGroup *pGroup = (AdminGroup *)m_pMemory->GetAddress(gid); - if (!pGroup || pGroup->magic != GRP_MAGIC_SET) - { - return NULL; - } - - return m_pStrings->GetString(pGroup->nameidx); -} - -void AdminCache::SetGroupGenericImmunity(GroupId id, ImmunityType type, bool enabled) -{ - AdminGroup *pGroup = (AdminGroup *)m_pMemory->GetAddress(id); - if (!pGroup || pGroup->magic != GRP_MAGIC_SET) - { - return; - } - - unsigned int level = 0; - - if (enabled) - { - if (type == Immunity_Default) - { - level = 1; - } else if (type == Immunity_Global) { - level = 2; - } - if (level > pGroup->immunity_level) - { - pGroup->immunity_level = level; - } - } else { - pGroup->immunity_level = 0; - } -} - -bool AdminCache::GetGroupGenericImmunity(GroupId id, ImmunityType type) -{ - AdminGroup *pGroup = (AdminGroup *)m_pMemory->GetAddress(id); - if (!pGroup || pGroup->magic != GRP_MAGIC_SET) - { - return false; - } - - if (type == Immunity_Default && pGroup->immunity_level >= 1) - { - return true; - } else if (type == Immunity_Global && pGroup->immunity_level >= 2) { - return true; - } - - return false; -} - -void AdminCache::AddGroupImmunity(GroupId id, GroupId other_id) -{ - AdminGroup *pGroup = (AdminGroup *)m_pMemory->GetAddress(other_id); - if (!pGroup || pGroup->magic != GRP_MAGIC_SET) - { - return; - } - - pGroup = (AdminGroup *)m_pMemory->GetAddress(id); - if (!pGroup || pGroup->magic != GRP_MAGIC_SET) - { - return; - } - - /* We always need to resize the immunity table */ - int *table, tblidx; - if (pGroup->immune_table == -1) - { - tblidx = m_pMemory->CreateMem(sizeof(int) * 2, (void **)&table); - pGroup = (AdminGroup *)m_pMemory->GetAddress(id); - table[0] = 0; - } else { - int *old_table = (int *)m_pMemory->GetAddress(pGroup->immune_table); - /* Break out if this group is already in the list */ - for (int i=0; iCreateMem(sizeof(int) * (old_table[0] + 2), (void **)&table); - /* Get the old address again in case of resize */ - pGroup = (AdminGroup *)m_pMemory->GetAddress(id); - old_table = (int *)m_pMemory->GetAddress(pGroup->immune_table); - table[0] = old_table[0]; - for (unsigned int i=1; i<=(unsigned int)old_table[0]; i++) - { - table[i] = old_table[i]; - } - } - - /* Assign */ - pGroup->immune_table = tblidx; - - /* Add to the array */ - table[0]++; - table[table[0]] = other_id; -} - -unsigned int AdminCache::GetGroupImmunityCount(GroupId id) -{ - AdminGroup *pGroup = (AdminGroup *)m_pMemory->GetAddress(id); - if (!pGroup || pGroup->magic != GRP_MAGIC_SET) - { - return 0; - } - - if (pGroup->immune_table == -1) - { - return 0; - } - - int *table = (int *)m_pMemory->GetAddress(pGroup->immune_table); - - return table[0]; -} - -GroupId AdminCache::GetGroupImmunity(GroupId id, unsigned int number) -{ - AdminGroup *pGroup = (AdminGroup *)m_pMemory->GetAddress(id); - if (!pGroup || pGroup->magic != GRP_MAGIC_SET) - { - return INVALID_GROUP_ID; - } - - if (pGroup->immune_table == -1) - { - return INVALID_GROUP_ID; - } - - int *table = (int *)m_pMemory->GetAddress(pGroup->immune_table); - if (number >= (unsigned int)table[0]) - { - return INVALID_GROUP_ID; - } - - return table[1 + number]; -} - -void AdminCache::AddGroupCommandOverride(GroupId id, const char *name, OverrideType type, OverrideRule rule) -{ - AdminGroup *pGroup = (AdminGroup *)m_pMemory->GetAddress(id); - if (!pGroup || pGroup->magic != GRP_MAGIC_SET) - { - return; - } - - Trie *pTrie = NULL; - if (type == Override_Command) - { - if (pGroup->pCmdTable == NULL) - { - pGroup->pCmdTable = sm_trie_create(); - } - pTrie = pGroup->pCmdTable; - } else if (type == Override_CommandGroup) { - if (pGroup->pCmdGrpTable == NULL) - { - pGroup->pCmdGrpTable = sm_trie_create(); - } - pTrie = pGroup->pCmdGrpTable; - } else { - return; - } - - sm_trie_insert(pTrie, name, (void *)(int)rule); -} - -bool AdminCache::GetGroupCommandOverride(GroupId id, const char *name, OverrideType type, OverrideRule *pRule) -{ - AdminGroup *pGroup = (AdminGroup *)m_pMemory->GetAddress(id); - if (!pGroup || pGroup->magic != GRP_MAGIC_SET) - { - return false; - } - - Trie *pTrie = NULL; - if (type == Override_Command) - { - if (pGroup->pCmdTable == NULL) - { - return false; - } - pTrie = pGroup->pCmdTable; - } else if (type == Override_CommandGroup) { - if (pGroup->pCmdGrpTable == NULL) - { - return false; - } - pTrie = pGroup->pCmdGrpTable; - } else { - return false; - } - - void *object; - if (!sm_trie_retrieve(pTrie, name, &object)) - { - return false; - } - - if (pRule) - { - *pRule = (OverrideRule)(int)object; - } - - return true; -} - -Trie *AdminCache::GetMethodByIndex(unsigned int index) -{ - List::iterator iter; - for (iter=m_AuthMethods.begin(); - iter!=m_AuthMethods.end(); - iter++) - { - if (index-- == 0) - { - return (*iter).table; - } - } - - return NULL; -} - -bool AdminCache::InvalidateAdmin(AdminId id) -{ - AdminUser *pUser = (AdminUser *)m_pMemory->GetAddress(id); - AdminUser *pOther; - if (!pUser || pUser->magic != USR_MAGIC_SET) - { - return false; - } - - if (!m_InvalidatingAdmins && !m_destroying) - { - g_Players.ClearAdminId(id); - } - - /* Unlink from the dbl link list */ - if (id == m_FirstUser && id == m_LastUser) - { - m_FirstUser = INVALID_ADMIN_ID; - m_LastUser = INVALID_ADMIN_ID; - } else if (id == m_FirstUser) { - m_FirstUser = pUser->next_user; - pOther = (AdminUser *)m_pMemory->GetAddress(m_FirstUser); - pOther->prev_user = INVALID_ADMIN_ID; - } else if (id == m_LastUser) { - m_LastUser = pUser->prev_user; - pOther = (AdminUser *)m_pMemory->GetAddress(m_LastUser); - pOther->next_user = INVALID_ADMIN_ID; - } else { - pOther = (AdminUser *)m_pMemory->GetAddress(pUser->prev_user); - pOther->next_user = pUser->next_user; - pOther = (AdminUser *)m_pMemory->GetAddress(pUser->next_user); - pOther->prev_user = pUser->prev_user; - } - - /* Unlink from auth tables */ - if (pUser->auth.identidx != -1) - { - Trie *pTrie = GetMethodByIndex(pUser->auth.index); - if (pTrie) - { - sm_trie_delete(pTrie, m_pStrings->GetString(pUser->auth.identidx)); - } - } - - /* Clear table counts */ - pUser->grp_count = 0; - - /* Link into free list */ - pUser->magic = USR_MAGIC_UNSET; - pUser->next_user = m_FreeUserList; - m_FreeUserList = id; - - /* Unset serial change */ - pUser->serialchange = 0; - - return true; -} - - -void AdminCache::InvalidateGroup(GroupId id) -{ - AdminGroup *pGroup = (AdminGroup *)m_pMemory->GetAddress(id); - AdminGroup *pOther; - - if (!pGroup || pGroup->magic != GRP_MAGIC_SET) - { - return; - } - - const char *str = m_pStrings->GetString(pGroup->nameidx); - sm_trie_delete(m_pGroups, str); - - /* Unlink from the live dbllink list */ - if (id == m_FirstGroup && id == m_LastGroup) - { - m_LastGroup = INVALID_GROUP_ID; - m_FirstGroup = INVALID_GROUP_ID; - } else if (id == m_FirstGroup) { - m_FirstGroup = pGroup->next_grp; - pOther = (AdminGroup *)m_pMemory->GetAddress(m_FirstGroup); - pOther->prev_grp = INVALID_GROUP_ID; - } else if (id == m_LastGroup) { - m_LastGroup = pGroup->prev_grp; - pOther = (AdminGroup *)m_pMemory->GetAddress(m_LastGroup); - pOther->next_grp = INVALID_GROUP_ID; - } else { - pOther = (AdminGroup *)m_pMemory->GetAddress(pGroup->prev_grp); - pOther->next_grp = pGroup->next_grp; - pOther = (AdminGroup *)m_pMemory->GetAddress(pGroup->next_grp); - pOther->prev_grp = pGroup->prev_grp; - } - - /* Free any used memory to be safe */ - if (pGroup->pCmdGrpTable) - { - sm_trie_destroy(pGroup->pCmdGrpTable); - pGroup->pCmdGrpTable = NULL; - } - if (pGroup->pCmdTable) - { - sm_trie_destroy(pGroup->pCmdTable); - pGroup->pCmdTable = NULL; - } - - /* Link into the free list */ - pGroup->magic = GRP_MAGIC_UNSET; - pGroup->next_grp = m_FreeGroupList; - m_FreeGroupList = id; - - int idx = m_FirstUser; - AdminUser *pUser; - int *table; - while (idx != INVALID_ADMIN_ID) - { - pUser = (AdminUser *)m_pMemory->GetAddress(idx); - if (pUser->grp_count > 0) - { - table = (int *)m_pMemory->GetAddress(pUser->grp_table); - for (unsigned int i=0; igrp_count; i++) - { - if (table[i] == id) - { - /* We have to remove this entry */ - for (unsigned int j=i+1; jgrp_count; j++) - { - /* Move everything down by one */ - table[j-1] = table[j]; - } - /* Decrease count */ - pUser->grp_count--; - /* Recalculate effective flags */ - pUser->eflags = pUser->flags; - for (unsigned int j=0; jgrp_count; j++) - { - pOther = (AdminGroup *)m_pMemory->GetAddress(table[j]); - pUser->eflags |= pOther->addflags; - } - /* Mark as changed */ - pUser->serialchange++; - /* Break now, duplicates aren't allowed */ - break; - } - } - } - idx = pUser->next_user; - } -} - -void AdminCache::InvalidateGroupCache() -{ - /* Nuke the free list */ - m_FreeGroupList = -1; - - /* Nuke reverse lookups */ - sm_trie_clear(m_pGroups); - - /* Free memory on groups */ - GroupId cur = m_FirstGroup; - AdminGroup *pGroup; - while (cur != INVALID_GROUP_ID) - { - pGroup = (AdminGroup *)m_pMemory->GetAddress(cur); - assert(pGroup->magic == GRP_MAGIC_SET); - if (pGroup->pCmdGrpTable) - { - sm_trie_destroy(pGroup->pCmdGrpTable); - } - if (pGroup->pCmdTable) - { - sm_trie_destroy(pGroup->pCmdTable); - } - cur = pGroup->next_grp; - } - - m_FirstGroup = INVALID_GROUP_ID; - m_LastGroup = INVALID_GROUP_ID; - - InvalidateAdminCache(false); - - /* Reset the memory table */ - m_pMemory->Reset(); -} - -void AdminCache::AddAdminListener(IAdminListener *pListener) -{ - m_hooks.push_back(pListener); -} - -void AdminCache::RemoveAdminListener(IAdminListener *pListener) -{ - m_hooks.remove(pListener); -} - -void AdminCache::RegisterAuthIdentType(const char *name) -{ - if (sm_trie_retrieve(m_pAuthTables, name, NULL)) - { - return; - } - - Trie *pAuth = sm_trie_create(); - - AuthMethod method; - method.name.assign(name); - method.table = pAuth; - - m_AuthMethods.push_back(method); - - sm_trie_insert(m_pAuthTables, name, pAuth); -} - -void AdminCache::InvalidateAdminCache(bool unlink_admins) -{ - m_InvalidatingAdmins = true; - if (!m_destroying) - { - g_Players.ClearAllAdmins(); - } - /* Wipe the identity cache first */ - List::iterator iter; - for (iter=m_AuthMethods.begin(); - iter!=m_AuthMethods.end(); - iter++) - { - sm_trie_clear((*iter).table); - } - - if (unlink_admins) - { - while (m_FirstUser != INVALID_ADMIN_ID) - { - InvalidateAdmin(m_FirstUser); - } - } else { - m_FirstUser = -1; - m_LastUser = -1; - m_FreeUserList = -1; - } - m_InvalidatingAdmins = false; -} - -void AdminCache::DumpAdminCache(AdminCachePart part, bool rebuild) -{ - List::iterator iter; - IAdminListener *pListener; - cell_t result; - - if (part == AdminCache_Overrides) - { - DumpCommandOverrideCache(Override_Command); - DumpCommandOverrideCache(Override_CommandGroup); - if (rebuild && !m_destroying) - { - for (iter=m_hooks.begin(); iter!=m_hooks.end(); iter++) - { - pListener = (*iter); - pListener->OnRebuildOverrideCache(); - } - m_pCacheFwd->PushCell(part); - m_pCacheFwd->Execute(&result); - } - } else if (part == AdminCache_Groups || part == AdminCache_Admins) { - if (part == AdminCache_Groups) - { - InvalidateGroupCache(); - if (rebuild && !m_destroying) - { - for (iter=m_hooks.begin(); iter!=m_hooks.end(); iter++) - { - pListener = (*iter); - pListener->OnRebuildGroupCache(); - } - m_pCacheFwd->PushCell(part); - m_pCacheFwd->Execute(&result); - } - } - InvalidateAdminCache(true); - if (rebuild && !m_destroying) - { - for (iter=m_hooks.begin(); iter!=m_hooks.end(); iter++) - { - pListener = (*iter); - pListener->OnRebuildAdminCache((part == AdminCache_Groups)); - } - m_pCacheFwd->PushCell(AdminCache_Admins); - m_pCacheFwd->Execute(&result); - g_Players.RecheckAnyAdmins(); - } - } -} - -const char *AdminCache::GetAdminName(AdminId id) -{ - AdminUser *pUser = (AdminUser *)m_pMemory->GetAddress(id); - if (!pUser || pUser->magic != USR_MAGIC_SET) - { - return NULL; - } - - return m_pStrings->GetString(pUser->nameidx); -} - -bool AdminCache::GetMethodIndex(const char *name, unsigned int *_index) -{ - List::iterator iter; - unsigned int index = 0; - for (iter=m_AuthMethods.begin(); - iter!=m_AuthMethods.end(); - iter++,index++) - { - if ((*iter).name.compare(name) == 0) - { - *_index = index; - return true; - } - } - - return false; -} - -bool AdminCache::BindAdminIdentity(AdminId id, const char *auth, const char *ident) -{ - AdminUser *pUser = (AdminUser *)m_pMemory->GetAddress(id); - if (!pUser || pUser->magic != USR_MAGIC_SET) - { - return false; - } - - Trie *pTable; - if (!sm_trie_retrieve(m_pAuthTables, auth, (void **)&pTable)) - { - return false; - } - - if (sm_trie_retrieve(pTable, ident, NULL)) - { - return false; - } - - int i_ident = m_pStrings->AddString(ident); - - pUser = (AdminUser *)m_pMemory->GetAddress(id); - pUser->auth.identidx = i_ident; - GetMethodIndex(auth, &pUser->auth.index); - - return sm_trie_insert(pTable, ident, (void **)id); -} - -AdminId AdminCache::FindAdminByIdentity(const char *auth, const char *identity) -{ - Trie *pTable; - if (!sm_trie_retrieve(m_pAuthTables, auth, (void **)&pTable)) - { - return INVALID_ADMIN_ID; - } - - void *object; - if (!sm_trie_retrieve(pTable, identity, &object)) - { - return INVALID_ADMIN_ID; - } - - return (AdminId)object; -} - -void AdminCache::SetAdminFlag(AdminId id, AdminFlag flag, bool enabled) -{ - AdminUser *pUser = (AdminUser *)m_pMemory->GetAddress(id); - if (!pUser || pUser->magic != USR_MAGIC_SET) - { - return; - } - - if (flag < Admin_Reservation - || flag >= AdminFlags_TOTAL) - { - return; - } - - FlagBits bits = (1<<(FlagBits)flag); - - if (enabled) - { - pUser->flags |= bits; - pUser->eflags |= bits; - } else { - pUser->flags &= ~bits; - pUser->eflags &= ~bits; - } - - pUser->serialchange++; -} - -bool AdminCache::GetAdminFlag(AdminId id, AdminFlag flag, AccessMode mode) -{ - AdminUser *pUser = (AdminUser *)m_pMemory->GetAddress(id); - if (!pUser || pUser->magic != USR_MAGIC_SET) - { - return false; - } - - if (flag < Admin_Reservation - || flag >= AdminFlags_TOTAL) - { - return false; - } - - FlagBits bit = (1<<(FlagBits)flag); - - if (mode == Access_Real) - { - return ((pUser->flags & bit) == bit); - } else if (mode == Access_Effective) { - bool has_bit = ((pUser->eflags & bit) == bit); - if (!has_bit && flag != Admin_Root && ((pUser->eflags & ADMFLAG_ROOT) == ADMFLAG_ROOT)) - { - has_bit = true; - } - return has_bit; - } - - return false; -} - -FlagBits AdminCache::GetAdminFlags(AdminId id, AccessMode mode) -{ - AdminUser *pUser = (AdminUser *)m_pMemory->GetAddress(id); - if (!pUser || pUser->magic != USR_MAGIC_SET) - { - return 0; - } - - if (mode == Access_Real) - { - return pUser->flags; - } else if (mode == Access_Effective) { - return pUser->eflags; - } - - return 0; -} - -void AdminCache::SetAdminFlags(AdminId id, AccessMode mode, FlagBits bits) -{ - AdminUser *pUser = (AdminUser *)m_pMemory->GetAddress(id); - if (!pUser || pUser->magic != USR_MAGIC_SET) - { - return; - } - - if (mode == Access_Real) - { - pUser->flags = bits; - pUser->eflags = bits; - } else if (mode == Access_Effective) { - pUser->eflags = bits; - } - - pUser->serialchange++; -} - -bool AdminCache::AdminInheritGroup(AdminId id, GroupId gid) -{ - AdminUser *pUser = (AdminUser *)m_pMemory->GetAddress(id); - if (!pUser || pUser->magic != USR_MAGIC_SET) - { - return false; - } - - AdminGroup *pGroup = (AdminGroup *)m_pMemory->GetAddress(gid); - if (!pGroup || pGroup->magic != GRP_MAGIC_SET) - { - return false; - } - - /* First check for duplicates */ - if (pUser->grp_count != 0) - { - int *temp_table = (int *)m_pMemory->GetAddress(pUser->grp_table); - for (unsigned int i=0; igrp_count; i++) - { - if (temp_table[i] == gid) - { - return false; - } - } - } - - int *table; - if (pUser->grp_count + 1 > pUser->grp_size) - { - int new_size = 0; - int tblidx; - - if (pUser->grp_size == 0) - { - new_size = 2; - } else { - new_size = pUser->grp_size * 2; - } - - /* Create and refresh pointers */ - tblidx = m_pMemory->CreateMem(new_size * sizeof(int), (void **)&table); - pUser = (AdminUser *)m_pMemory->GetAddress(id); - pGroup = (AdminGroup *)m_pMemory->GetAddress(gid); - - /* Copy old data if necessary */ - if (pUser->grp_table != -1) - { - int *old_table = (int *)m_pMemory->GetAddress(pUser->grp_table); - memcpy(table, old_table, sizeof(int) * pUser->grp_count); - } - pUser->grp_table = tblidx; - pUser->grp_size = new_size; - } else { - table = (int *)m_pMemory->GetAddress(pUser->grp_table); - } - - table[pUser->grp_count] = gid; - pUser->grp_count++; - - /* Compute new effective permissions */ - pUser->eflags |= pGroup->addflags; - - if (pGroup->immunity_level > pUser->immunity_level) - { - pUser->immunity_level = pGroup->immunity_level; - } - - pUser->serialchange++; - - return true; -} - -bool AdminCache::IsValidAdmin(AdminId id) -{ - AdminUser *pUser = (AdminUser *)m_pMemory->GetAddress(id); - return (pUser != NULL && pUser->magic == USR_MAGIC_SET); -} - -unsigned int AdminCache::GetAdminGroupCount(AdminId id) -{ - AdminUser *pUser = (AdminUser *)m_pMemory->GetAddress(id); - if (!pUser || pUser->magic != USR_MAGIC_SET) - { - return 0; - } - - return pUser->grp_count; -} - -GroupId AdminCache::GetAdminGroup(AdminId id, unsigned int index, const char **name) -{ - AdminUser *pUser = (AdminUser *)m_pMemory->GetAddress(id); - if (!pUser || pUser->magic != USR_MAGIC_SET || index >= pUser->grp_count) - { - return INVALID_GROUP_ID; - } - - int *table = (int *)m_pMemory->GetAddress(pUser->grp_table); - - GroupId gid = table[index]; - - if (name) - { - *name = GetGroupName(gid); - } - - return gid; -} - -const char *AdminCache::GetAdminPassword(AdminId id) -{ - AdminUser *pUser = (AdminUser *)m_pMemory->GetAddress(id); - if (!pUser || pUser->magic != USR_MAGIC_SET) - { - return NULL; - } - - return m_pStrings->GetString(pUser->password); -} - -void AdminCache::SetAdminPassword(AdminId id, const char *password) -{ - AdminUser *pUser = (AdminUser *)m_pMemory->GetAddress(id); - if (!pUser || pUser->magic != USR_MAGIC_SET) - { - return; - } - - int i_password = m_pStrings->AddString(password); - pUser = (AdminUser *)m_pMemory->GetAddress(id); - pUser->password = i_password; -} - -unsigned int AdminCache::FlagBitsToBitArray(FlagBits bits, bool array[], unsigned int maxSize) -{ - unsigned int i; - for (i=0; iGetAddress(id); - if (!pUser || pUser->magic != USR_MAGIC_SET) - { - return false; - } - - return ((pUser->eflags & bits) == bits); -} - -bool AdminCache::CanAdminTarget(AdminId id, AdminId target) -{ - /** - * Zeroth, if the targeting AdminId is INVALID_ADMIN_ID, targeting fails. - * First, if the targeted AdminId is INVALID_ADMIN_ID, targeting succeeds. - */ - - if (id == INVALID_ADMIN_ID) - { - return false; - } - - if (target == INVALID_ADMIN_ID) - { - return true; - } - - if (id == target) - { - return true; - } - - AdminUser *pUser = (AdminUser *)m_pMemory->GetAddress(id); - if (!pUser || pUser->magic != USR_MAGIC_SET) - { - return false; - } - - AdminUser *pTarget = (AdminUser *)m_pMemory->GetAddress(target); - if (!pTarget || pTarget->magic != USR_MAGIC_SET) - { - return false; - } - - /** - * Second, if the targeting admin is root, targeting succeeds. - */ - if (pUser->eflags & ADMFLAG_ROOT) - { - return true; - } - - /** Fourth, if the targeted admin is immune from targeting admin. */ - int mode = sm_immunity_mode.GetInt(); - switch (mode) - { - case 1: - { - if (pTarget->immunity_level > pUser->immunity_level) - { - return false; - } - break; - } - case 3: - { - /* If neither has any immunity, let this pass. */ - if (!pUser->immunity_level && !pTarget->immunity_level) - { - return true; - } - /* Don't break, go to the next case. */ - } - case 2: - { - if (pTarget->immunity_level >= pUser->immunity_level) - { - return false; - } - break; - } - } - - /** - * Fifth, if the targeted admin has specific immunity from the - * targeting admin via group immunities, targeting fails. - */ - //:TODO: speed this up... maybe with trie hacks. - //idea is to insert %d.%d in the trie after computing this and use it as a cache lookup. - //problem is the trie cannot delete prefixes, so we'd have a problem with invalidations. - if (pTarget->grp_count > 0 && pUser->grp_count > 0) - { - int *grp_table = (int *)m_pMemory->GetAddress(pTarget->grp_table); - int *src_table = (int *)m_pMemory->GetAddress(pUser->grp_table); - GroupId id, other; - unsigned int num; - for (unsigned int i=0; igrp_count; i++) - { - id = grp_table[i]; - num = GetGroupImmunityCount(id); - for (unsigned int j=0; jgrp_count; k++) - { - if (other == src_table[k]) - { - return false; - } - } - } - } - } - - return true; -} - -bool AdminCache::FindFlag(char c, AdminFlag *pAdmFlag) -{ - if (c < 'a' || c > 'z') - { - return false; - } - - if (pAdmFlag) - { - *pAdmFlag = g_FlagLetters[(unsigned)c - (unsigned)'a']; - } - - return true; -} - -FlagBits AdminCache::ReadFlagString(const char *flags, const char **end) -{ - FlagBits bits = 0; - - while (flags && (*flags != '\0')) - { - AdminFlag flag; - if (!FindFlag(*flags, &flag)) - { - break; - } - bits |= FlagArrayToBits(&flag, 1); - flags++; - } - - if (end) - { - *end = flags; - } - - return bits; -} - -unsigned int AdminCache::GetAdminSerialChange(AdminId id) -{ - AdminUser *pUser = (AdminUser *)m_pMemory->GetAddress(id); - if (!pUser || pUser->magic != USR_MAGIC_SET) - { - return 0; - } - - return pUser->serialchange; -} - -bool AdminCache::CanAdminUseCommand(int client, const char *cmd) -{ - FlagBits bits; - OverrideType otype = Override_Command; - - if (cmd[0] == '@') - { - otype = Override_CommandGroup; - cmd++; - } - - if (!g_ConCmds.LookForCommandAdminFlags(cmd, &bits)) - { - if (!GetCommandOverride(cmd, otype, &bits)) - { - bits = 0; - } - } - - return g_ConCmds.CheckCommandAccess(client, cmd, bits); -} - -unsigned int AdminCache::SetGroupImmunityLevel(GroupId gid, unsigned int level) -{ - AdminGroup *pGroup = (AdminGroup *)m_pMemory->GetAddress(gid); - if (!pGroup || pGroup->magic != GRP_MAGIC_SET) - { - return 0; - } - - unsigned int old_level = pGroup->immunity_level; - - pGroup->immunity_level = level; - - return old_level; -} - -unsigned int AdminCache::GetGroupImmunityLevel(GroupId gid) -{ - AdminGroup *pGroup = (AdminGroup *)m_pMemory->GetAddress(gid); - if (!pGroup || pGroup->magic != GRP_MAGIC_SET) - { - return 0; - } - - return pGroup->immunity_level; -} - -unsigned int AdminCache::SetAdminImmunityLevel(AdminId id, unsigned int level) -{ - AdminUser *pUser = (AdminUser *)m_pMemory->GetAddress(id); - if (!pUser || pUser->magic != USR_MAGIC_SET) - { - return 0; - } - - unsigned int old_level = pUser->immunity_level; - - pUser->immunity_level = level; - - return old_level; -} - -unsigned int AdminCache::GetAdminImmunityLevel(AdminId id) -{ - AdminUser *pUser = (AdminUser *)m_pMemory->GetAddress(id); - if (!pUser || pUser->magic != USR_MAGIC_SET) - { - return 0; - } - - return pUser->immunity_level; -} - -bool AdminCache::CheckAccess(int client, const char *cmd, FlagBits flags, bool override_only) -{ - if (client == 0) - { - return true; - } - - /* Auto-detect a command if we can */ - FlagBits bits = flags; - bool found_command = false; - if (!override_only) - { - found_command = g_ConCmds.LookForCommandAdminFlags(cmd, &bits); - } - - if (!found_command) - { - GetCommandOverride(cmd, Override_Command, &bits); - } - - return g_ConCmds.CheckCommandAccess(client, cmd, bits) ? 1 : 0; -} diff --git a/core/AdminCache.h b/core/AdminCache.h deleted file mode 100644 index f6cc2db7..00000000 --- a/core/AdminCache.h +++ /dev/null @@ -1,201 +0,0 @@ -/** - * vim: set ts=4 : - * ============================================================================= - * SourceMod - * Copyright (C) 2004-2007 AlliedModders LLC. All rights reserved. - * ============================================================================= - * - * This program is free software; you can redistribute it and/or modify it under - * the terms of the GNU General Public License, version 3.0, as published by the - * Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more - * details. - * - * You should have received a copy of the GNU General Public License along with - * this program. If not, see . - * - * As a special exception, AlliedModders LLC gives you permission to link the - * code of this program (as well as its derivative works) to "Half-Life 2," the - * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software - * by the Valve Corporation. You must obey the GNU General Public License in - * all respects for all other code used. Additionally, AlliedModders LLC grants - * this exception to all derivative works. AlliedModders LLC defines further - * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007), - * or . - * - * Version: $Id$ - */ - -#ifndef _INCLUDE_SOURCEMOD_ADMINCACHE_H_ -#define _INCLUDE_SOURCEMOD_ADMINCACHE_H_ - -#include "sm_memtable.h" -#include -#include -#include -#include -#include "sm_globals.h" -#include - -using namespace SourceHook; - -#define GRP_MAGIC_SET 0xDEADFADE -#define GRP_MAGIC_UNSET 0xFACEFACE -#define USR_MAGIC_SET 0xDEADFACE -#define USR_MAGIC_UNSET 0xFADEDEAD - -struct AdminGroup -{ - uint32_t magic; /* Magic flag, for memory validation (ugh) */ - unsigned int immunity_level; /* Immunity level */ - /* Immune from target table (-1 = nonexistent) - * [0] = number of entries - * [1...N] = immune targets - */ - int immune_table; - Trie *pCmdTable; /* Command override table (can be NULL) */ - Trie *pCmdGrpTable; /* Command group override table (can be NULL) */ - int next_grp; /* Next group in the chain */ - int prev_grp; /* Previous group in the chain */ - int nameidx; /* Name */ - FlagBits addflags; /* Additive flags */ -}; - -struct AuthMethod -{ - String name; - Trie *table; -}; - -struct UserAuth -{ - unsigned int index; /* Index into auth table */ - int identidx; /* Index into the string table */ -}; - -struct AdminUser -{ - uint32_t magic; /* Magic flag, for memory validation */ - FlagBits flags; /* Flags */ - FlagBits eflags; /* Effective flags */ - int nameidx; /* Name index */ - int password; /* Password index */ - unsigned int grp_count; /* Number of groups */ - unsigned int grp_size; /* Size of groups table */ - int grp_table; /* Group table itself */ - int next_user; /* Next user in the list */ - int prev_user; /* Previous user in the list */ - UserAuth auth; /* Auth method for this user */ - unsigned int immunity_level; /* Immunity level */ - unsigned int serialchange; /* Serial # for changes */ -}; - -class AdminCache : - public IAdminSystem, - public SMGlobalClass -{ -public: - AdminCache(); - ~AdminCache(); -public: //SMGlobalClass - void OnSourceModStartup(bool late); - void OnSourceModAllInitialized(); - void OnSourceModLevelChange(const char *mapName); - void OnSourceModShutdown(); - void OnSourceModPluginsLoaded(); -public: //IAdminSystem - /** Command cache stuff */ - void AddCommandOverride(const char *cmd, OverrideType type, FlagBits flags); - bool GetCommandOverride(const char *cmd, OverrideType type, FlagBits *flags); - void UnsetCommandOverride(const char *cmd, OverrideType type); - /** Group cache stuff */ - GroupId AddGroup(const char *group_name); - GroupId FindGroupByName(const char *group_name); - void SetGroupAddFlag(GroupId id, AdminFlag flag, bool enabled); - bool GetGroupAddFlag(GroupId id, AdminFlag flag); - FlagBits GetGroupAddFlags(GroupId id); - void SetGroupGenericImmunity(GroupId id, ImmunityType type, bool enabled); - bool GetGroupGenericImmunity(GroupId id, ImmunityType type); - void InvalidateGroup(GroupId id); - void AddGroupImmunity(GroupId id, GroupId other_id); - unsigned int GetGroupImmunityCount(GroupId id); - GroupId GetGroupImmunity(GroupId id, unsigned int number); - void AddGroupCommandOverride(GroupId id, const char *name, OverrideType type, OverrideRule rule); - bool GetGroupCommandOverride(GroupId id, const char *name, OverrideType type, OverrideRule *pRule); - void DumpAdminCache(AdminCachePart part, bool rebuild); - void AddAdminListener(IAdminListener *pListener); - void RemoveAdminListener(IAdminListener *pListener); - /** User stuff */ - void RegisterAuthIdentType(const char *name); - AdminId CreateAdmin(const char *name); - const char *GetAdminName(AdminId id); - bool BindAdminIdentity(AdminId id, const char *auth, const char *ident); - virtual void SetAdminFlag(AdminId id, AdminFlag flag, bool enabled); - bool GetAdminFlag(AdminId id, AdminFlag flag, AccessMode mode); - FlagBits GetAdminFlags(AdminId id, AccessMode mode); - bool AdminInheritGroup(AdminId id, GroupId gid); - unsigned int GetAdminGroupCount(AdminId id); - GroupId GetAdminGroup(AdminId id, unsigned int index, const char **name); - void SetAdminPassword(AdminId id, const char *password); - const char *GetAdminPassword(AdminId id); - AdminId FindAdminByIdentity(const char *auth, const char *identity); - bool InvalidateAdmin(AdminId id); - unsigned int FlagBitsToBitArray(FlagBits bits, bool array[], unsigned int maxSize); - FlagBits FlagBitArrayToBits(const bool array[], unsigned int maxSize); - FlagBits FlagArrayToBits(const AdminFlag array[], unsigned int numFlags); - unsigned int FlagBitsToArray(FlagBits bits, AdminFlag array[], unsigned int maxSize); - bool CheckAdminFlags(AdminId id, FlagBits bits); - bool CanAdminTarget(AdminId id, AdminId target); - void SetAdminFlags(AdminId id, AccessMode mode, FlagBits bits); - bool FindFlag(const char *str, AdminFlag *pFlag); - bool FindFlag(char c, AdminFlag *pAdmFlag); - FlagBits ReadFlagString(const char *flags, const char **end); - unsigned int GetAdminSerialChange(AdminId id); - bool CanAdminUseCommand(int client, const char *cmd); - const char *GetGroupName(GroupId gid); - unsigned int SetGroupImmunityLevel(GroupId gid, unsigned int level); - unsigned int GetGroupImmunityLevel(GroupId gid); - unsigned int SetAdminImmunityLevel(AdminId id, unsigned int level); - unsigned int GetAdminImmunityLevel(AdminId id); - bool CheckAccess(int client, - const char *cmd, - FlagBits flags, - bool override_only); -public: - bool IsValidAdmin(AdminId id); -private: - void _UnsetCommandOverride(const char *cmd); - void _UnsetCommandGroupOverride(const char *group); - void InvalidateGroupCache(); - void InvalidateAdminCache(bool unlink_admins); - void DumpCommandOverrideCache(OverrideType type); - Trie *GetMethodByIndex(unsigned int index); - bool GetMethodIndex(const char *name, unsigned int *_index); - void NameFlag(const char *str, AdminFlag flag); -public: - BaseStringTable *m_pStrings; - BaseMemTable *m_pMemory; - Trie *m_pCmdOverrides; - Trie *m_pCmdGrpOverrides; - int m_FirstGroup; - int m_LastGroup; - int m_FreeGroupList; - Trie *m_pGroups; - List m_hooks; - List m_AuthMethods; - Trie *m_pAuthTables; - IForward *m_pCacheFwd; - int m_FirstUser; - int m_LastUser; - int m_FreeUserList; - bool m_InvalidatingAdmins; - bool m_destroying; - Trie *m_pLevelNames; -}; - -extern AdminCache g_Admins; - -#endif //_INCLUDE_SOURCEMOD_ADMINCACHE_H_ diff --git a/core/CDataPack.cpp b/core/CDataPack.cpp deleted file mode 100644 index c502f806..00000000 --- a/core/CDataPack.cpp +++ /dev/null @@ -1,259 +0,0 @@ -/** - * vim: set ts=4 : - * ============================================================================= - * SourceMod - * Copyright (C) 2004-2007 AlliedModders LLC. All rights reserved. - * ============================================================================= - * - * This program is free software; you can redistribute it and/or modify it under - * the terms of the GNU General Public License, version 3.0, as published by the - * Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more - * details. - * - * You should have received a copy of the GNU General Public License along with - * this program. If not, see . - * - * As a special exception, AlliedModders LLC gives you permission to link the - * code of this program (as well as its derivative works) to "Half-Life 2," the - * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software - * by the Valve Corporation. You must obey the GNU General Public License in - * all respects for all other code used. Additionally, AlliedModders LLC grants - * this exception to all derivative works. AlliedModders LLC defines further - * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007), - * or . - * - * Version: $Id$ - */ - -#include -#include -#include "CDataPack.h" - -#define DATAPACK_INITIAL_SIZE 512 - -CDataPack::CDataPack() -{ - m_pBase = (char *)malloc(DATAPACK_INITIAL_SIZE); - m_capacity = DATAPACK_INITIAL_SIZE; - Initialize(); -} - -CDataPack::~CDataPack() -{ - free(m_pBase); -} - -void CDataPack::Initialize() -{ - m_curptr = m_pBase; - m_size = 0; -} - -void CDataPack::CheckSize(size_t typesize) -{ - if (m_curptr - m_pBase + typesize <= m_capacity) - { - return; - } - - size_t pos = m_curptr - m_pBase; - do - { - m_capacity *= 2; - m_pBase = (char *)realloc(m_pBase, m_capacity); - m_curptr = m_pBase + pos; - } while (m_curptr - m_pBase + typesize > m_capacity); -} - -void CDataPack::ResetSize() -{ - m_size = 0; -} - -size_t CDataPack::CreateMemory(size_t size, void **addr) -{ - CheckSize(sizeof(size_t) + size); - size_t pos = m_curptr - m_pBase; - - *(size_t *)m_curptr = size; - m_curptr += sizeof(size_t); - - if (addr) - { - *addr = m_curptr; - } - - m_curptr += size; - m_size += sizeof(size_t) + size; - - return pos; -} - -void CDataPack::PackCell(cell_t cell) -{ - CheckSize(sizeof(size_t) + sizeof(cell_t)); - - *(size_t *)m_curptr = sizeof(cell_t); - m_curptr += sizeof(size_t); - - *(cell_t *)m_curptr = cell; - m_curptr += sizeof(cell_t); - - m_size += sizeof(size_t) + sizeof(cell_t); -} - -void CDataPack::PackFloat(float val) -{ - CheckSize(sizeof(size_t) + sizeof(float)); - - *(size_t *)m_curptr = sizeof(float); - m_curptr += sizeof(size_t); - - *(float *)m_curptr = val; - m_curptr += sizeof(float); - - m_size += sizeof(size_t) + sizeof(float); -} - -void CDataPack::PackString(const char *string) -{ - size_t len = strlen(string); - size_t maxsize = sizeof(size_t) + len + 1; - CheckSize(maxsize); - - // Pack the string length first for buffer overrun checking. - *(size_t *)m_curptr = len; - m_curptr += sizeof(size_t); - - // Now pack the string. - memcpy(m_curptr, string, len); - m_curptr[len] = '\0'; - m_curptr += len + 1; - - m_size += maxsize; -} - -void CDataPack::Reset() const -{ - m_curptr = m_pBase; -} - -size_t CDataPack::GetPosition() const -{ - return static_cast(m_curptr - m_pBase); -} - -bool CDataPack::SetPosition(size_t pos) const -{ - if (pos > m_size-1) - { - return false; - } - m_curptr = m_pBase + pos; - - return true; -} - -cell_t CDataPack::ReadCell() const -{ - if (!IsReadable(sizeof(size_t) + sizeof(cell_t))) - { - return 0; - } - if (*reinterpret_cast(m_curptr) != sizeof(cell_t)) - { - return 0; - } - - m_curptr += sizeof(size_t); - - cell_t val = *reinterpret_cast(m_curptr); - m_curptr += sizeof(cell_t); - return val; -} - -float CDataPack::ReadFloat() const -{ - if (!IsReadable(sizeof(size_t) + sizeof(float))) - { - return 0; - } - if (*reinterpret_cast(m_curptr) != sizeof(float)) - { - return 0; - } - - m_curptr += sizeof(size_t); - - float val = *reinterpret_cast(m_curptr); - m_curptr += sizeof(float); - return val; -} - -bool CDataPack::IsReadable(size_t bytes) const -{ - return (bytes + (m_curptr - m_pBase) > m_size) ? false : true; -} - -const char *CDataPack::ReadString(size_t *len) const -{ - if (!IsReadable(sizeof(size_t))) - { - return NULL; - } - - size_t real_len = *(size_t *)m_curptr; - - m_curptr += sizeof(size_t); - char *str = (char *)m_curptr; - - if ((strlen(str) != real_len) || !(IsReadable(real_len+1))) - { - return NULL; - } - - if (len) - { - *len = real_len; - } - - m_curptr += real_len + 1; - - return str; -} - -void *CDataPack::GetMemory() const -{ - return m_curptr; -} - -void *CDataPack::ReadMemory(size_t *size) const -{ - if (!IsReadable(sizeof(size_t))) - { - return NULL; - } - - size_t bytecount = *(size_t *)m_curptr; - m_curptr += sizeof(size_t); - - if (!IsReadable(bytecount)) - { - return NULL; - } - - void *ptr = m_curptr; - - if (size) - { - *size = bytecount; - } - - m_curptr += bytecount; - - return ptr; -} diff --git a/core/CDataPack.h b/core/CDataPack.h deleted file mode 100644 index d04cca51..00000000 --- a/core/CDataPack.h +++ /dev/null @@ -1,71 +0,0 @@ -/** - * vim: set ts=4 : - * ============================================================================= - * SourceMod - * Copyright (C) 2004-2007 AlliedModders LLC. All rights reserved. - * ============================================================================= - * - * This program is free software; you can redistribute it and/or modify it under - * the terms of the GNU General Public License, version 3.0, as published by the - * Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more - * details. - * - * You should have received a copy of the GNU General Public License along with - * this program. If not, see . - * - * As a special exception, AlliedModders LLC gives you permission to link the - * code of this program (as well as its derivative works) to "Half-Life 2," the - * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software - * by the Valve Corporation. You must obey the GNU General Public License in - * all respects for all other code used. Additionally, AlliedModders LLC grants - * this exception to all derivative works. AlliedModders LLC defines further - * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007), - * or . - * - * Version: $Id$ - */ - -#ifndef _INCLUDE_SOURCEMOD_CDATAPACK_H_ -#define _INCLUDE_SOURCEMOD_CDATAPACK_H_ - -#include - -using namespace SourceMod; - -class CDataPack : public IDataPack -{ -public: - CDataPack(); - ~CDataPack(); -public: //IDataReader - void Reset() const; - size_t GetPosition() const; - bool SetPosition(size_t pos) const; - cell_t ReadCell() const; - float ReadFloat() const; - bool IsReadable(size_t bytes) const; - const char *ReadString(size_t *len) const; - void *GetMemory() const; - void *ReadMemory(size_t *size) const; -public: //IDataPack - void ResetSize(); - void PackCell(cell_t cell); - void PackFloat(float val); - void PackString(const char *string); - size_t CreateMemory(size_t size, void **addr); -public: - void Initialize(); -private: - void CheckSize(size_t sizetype); -private: - char *m_pBase; - mutable char *m_curptr; - size_t m_capacity; - size_t m_size; -}; - -#endif //_INCLUDE_SOURCEMOD_CDATAPACK_H_ diff --git a/core/CellArray.h b/core/CellArray.h deleted file mode 100644 index c9ee2831..00000000 --- a/core/CellArray.h +++ /dev/null @@ -1,191 +0,0 @@ -/** - * vim: set ts=4 : - * ============================================================================= - * SourceMod - * Copyright (C) 2004-2007 AlliedModders LLC. All rights reserved. - * ============================================================================= - * - * This program is free software; you can redistribute it and/or modify it under - * the terms of the GNU General Public License, version 3.0, as published by the - * Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more - * details. - * - * You should have received a copy of the GNU General Public License along with - * this program. If not, see . - * - * As a special exception, AlliedModders LLC gives you permission to link the - * code of this program (as well as its derivative works) to "Half-Life 2," the - * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software - * by the Valve Corporation. You must obey the GNU General Public License in - * all respects for all other code used. Additionally, AlliedModders LLC grants - * this exception to all derivative works. AlliedModders LLC defines further - * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007), - * or . - * - * Version: $Id$ - */ - -#include -#include - -extern HandleType_t htCellArray; - -class CellArray -{ -public: - CellArray(size_t blocksize) : m_Data(NULL), m_BlockSize(blocksize), m_AllocSize(0), m_Size(0) - { - } - ~CellArray() - { - free(m_Data); - } - size_t size() const - { - return m_Size; - } - cell_t *push() - { - if (!GrowIfNeeded(1)) - { - return NULL; - } - cell_t *arr = &m_Data[m_Size * m_BlockSize]; - m_Size++; - return arr; - } - cell_t *at(size_t b) const - { - return &m_Data[b * m_BlockSize]; - } - size_t blocksize() const - { - return m_BlockSize; - } - void clear() - { - m_Size = 0; - } - bool swap(size_t item1, size_t item2) - { - /* Make sure there is extra space available */ - if (!GrowIfNeeded(1)) - { - return false; - } - - cell_t *pri = at(item1); - cell_t *alt = at(item2); - - /* Get our temporary array 1 after the limit */ - cell_t *temp = &m_Data[m_Size * m_BlockSize]; - - memcpy(temp, pri, sizeof(cell_t) * m_BlockSize); - memcpy(pri, alt, sizeof(cell_t) * m_BlockSize); - memcpy(alt, temp, sizeof(cell_t) * m_BlockSize); - - return true; - } - void remove(size_t index) - { - /* If we're at the end, take the easy way out */ - if (index == m_Size - 1) - { - m_Size--; - return; - } - - /* Otherwise, it's time to move stuff! */ - size_t remaining_indexes = (m_Size - 1) - index; - cell_t *src = at(index + 1); - cell_t *dest = at(index); - memmove(dest, src, sizeof(cell_t) * m_BlockSize * remaining_indexes); - - m_Size--; - } - cell_t *insert_at(size_t index) - { - /* Make sure it'll fit */ - if (!GrowIfNeeded(1)) - { - return NULL; - } - - /* move everything up */ - cell_t *src = at(index); - cell_t *dst = at(index + 1); - memmove(dst, src, sizeof(cell_t) * m_BlockSize * m_Size); - - m_Size++; - - return src; - } - bool resize(size_t count) - { - if (count <= m_Size) - { - m_Size = count; - return true; - } - - if(!GrowIfNeeded(count - m_Size)) - { - return false; - } - - m_Size = count; - return true; - } - - CellArray *clone() - { - CellArray *array = new CellArray(m_BlockSize); - array->m_AllocSize = m_AllocSize; - array->m_Size = m_Size; - array->m_Data = (cell_t *)malloc(sizeof(cell_t) * m_BlockSize * m_AllocSize); - memcpy(array->m_Data, m_Data, sizeof(cell_t) * m_BlockSize * m_Size); - return array; - } - - cell_t *base() - { - return m_Data; - } - -private: - bool GrowIfNeeded(size_t count) - { - /* Shortcut out if we can store this */ - if (m_Size + count <= m_AllocSize) - { - return true; - } - /* Set a base allocation size of 8 items */ - if (!m_AllocSize) - { - m_AllocSize = 8; - } - /* If it's not enough, keep doubling */ - while (m_Size + count > m_AllocSize) - { - m_AllocSize *= 2; - } - /* finally, allocate the new block */ - if (m_Data) - { - m_Data = (cell_t *)realloc(m_Data, sizeof(cell_t) * m_BlockSize * m_AllocSize); - } else { - m_Data = (cell_t *)malloc(sizeof(cell_t) * m_BlockSize * m_AllocSize); - } - return (m_Data != NULL); - } -private: - cell_t *m_Data; - size_t m_BlockSize; - size_t m_AllocSize; - size_t m_Size; -}; diff --git a/core/CellRecipientFilter.h b/core/CellRecipientFilter.h deleted file mode 100644 index 30070553..00000000 --- a/core/CellRecipientFilter.h +++ /dev/null @@ -1,107 +0,0 @@ -/** - * vim: set ts=4 : - * ============================================================================= - * SourceMod - * Copyright (C) 2004-2007 AlliedModders LLC. All rights reserved. - * ============================================================================= - * - * This program is free software; you can redistribute it and/or modify it under - * the terms of the GNU General Public License, version 3.0, as published by the - * Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more - * details. - * - * You should have received a copy of the GNU General Public License along with - * this program. If not, see . - * - * As a special exception, AlliedModders LLC gives you permission to link the - * code of this program (as well as its derivative works) to "Half-Life 2," the - * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software - * by the Valve Corporation. You must obey the GNU General Public License in - * all respects for all other code used. Additionally, AlliedModders LLC grants - * this exception to all derivative works. AlliedModders LLC defines further - * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007), - * or . - * - * Version: $Id$ - */ - -#ifndef _INCLUDE_SOURCEMOD_CELLRECIPIENTFILTER_H_ -#define _INCLUDE_SOURCEMOD_CELLRECIPIENTFILTER_H_ - -#include -#include - -class CellRecipientFilter : public IRecipientFilter -{ -public: - CellRecipientFilter() : m_IsReliable(false), m_IsInitMessage(false), m_Size(0) {} - ~CellRecipientFilter() {} -public: //IRecipientFilter - bool IsReliable() const; - bool IsInitMessage() const; - int GetRecipientCount() const; - int GetRecipientIndex(int slot) const; -public: - void Initialize(const cell_t *ptr, size_t count); - void SetToReliable(bool isreliable); - void SetToInit(bool isinitmsg); - void Reset(); -private: - cell_t m_Players[255]; - bool m_IsReliable; - bool m_IsInitMessage; - size_t m_Size; -}; - -inline void CellRecipientFilter::Reset() -{ - m_IsReliable = false; - m_IsInitMessage = false; - m_Size = 0; -} - -inline bool CellRecipientFilter::IsReliable() const -{ - return m_IsReliable; -} - -inline bool CellRecipientFilter::IsInitMessage() const -{ - return m_IsInitMessage; -} - -inline int CellRecipientFilter::GetRecipientCount() const -{ - return m_Size; -} - -inline int CellRecipientFilter::GetRecipientIndex(int slot) const -{ - if ((slot < 0) || (slot >= GetRecipientCount())) - { - return -1; - } - return static_cast(m_Players[slot]); -} - -inline void CellRecipientFilter::SetToInit(bool isinitmsg) -{ - m_IsInitMessage = isinitmsg; -} - -inline void CellRecipientFilter::SetToReliable(bool isreliable) -{ - m_IsReliable = isreliable; -} - -inline void CellRecipientFilter::Initialize(const cell_t *ptr, size_t count) -{ - memcpy(m_Players, ptr, count * sizeof(cell_t)); - m_Size = count; -} - -#endif //_INCLUDE_SOURCEMOD_CELLRECIPIENTFILTER_H_ diff --git a/core/ChatTriggers.cpp b/core/ChatTriggers.cpp deleted file mode 100644 index e3841ee1..00000000 --- a/core/ChatTriggers.cpp +++ /dev/null @@ -1,340 +0,0 @@ -/** - * vim: set ts=4 : - * ============================================================================= - * SourceMod - * Copyright (C) 2004-2007 AlliedModders LLC. All rights reserved. - * ============================================================================= - * - * This program is free software; you can redistribute it and/or modify it under - * the terms of the GNU General Public License, version 3.0, as published by the - * Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more - * details. - * - * You should have received a copy of the GNU General Public License along with - * this program. If not, see . - * - * As a special exception, AlliedModders LLC gives you permission to link the - * code of this program (as well as its derivative works) to "Half-Life 2," the - * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software - * by the Valve Corporation. You must obey the GNU General Public License in - * all respects for all other code used. Additionally, AlliedModders LLC grants - * this exception to all derivative works. AlliedModders LLC defines further - * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007), - * or . - * - * Version: $Id$ - */ - -#include -#include "ChatTriggers.h" -#include "sm_stringutil.h" -#include "ConCmdManager.h" -#include - -/* :HACKHACK: We can't SH_DECL here because ConCmdManager.cpp does. - * While the OB build only runs on MM:S 1.6.0+ (SH 5+), the older one - * can technically be compiled against any MM:S version after 1.4.2. - */ -#if defined ORANGEBOX_BUILD -extern bool __SourceHook_FHRemoveConCommandDispatch(void *, bool, class fastdelegate::FastDelegate1); -extern int __SourceHook_FHAddConCommandDispatch(void *, ISourceHook::AddHookMode, bool, class fastdelegate::FastDelegate1); -#else -extern bool __SourceHook_FHRemoveConCommandDispatch(void *, bool, class fastdelegate::FastDelegate0); -#if SH_IMPL_VERSION >= 5 -extern int __SourceHook_FHAddConCommandDispatch(void *, ISourceHook::AddHookMode, bool, class fastdelegate::FastDelegate0); -#elif SH_IMPL_VERSION == 4 -extern int __SourceHook_FHAddConCommandDispatch(void *, bool, class fastdelegate::FastDelegate0); -#elif SH_IMPL_VERSION == 3 -extern bool __SourceHook_FHAddConCommandDispatch(void *, bool, class fastdelegate::FastDelegate0); -#endif //SH_IMPL_VERSION -#endif //ORANGEBOX_BUILD - -ChatTriggers g_ChatTriggers; - -ChatTriggers::ChatTriggers() : m_pSayCmd(NULL), m_bWillProcessInPost(false), - m_bTriggerWasSilent(false), m_ReplyTo(SM_REPLY_CONSOLE) -{ - m_PubTrigger = sm_strdup("!"); - m_PrivTrigger = sm_strdup("/"); - m_PubTriggerSize = 1; - m_PrivTriggerSize = 1; - m_bIsChatTrigger = false; -} - -ChatTriggers::~ChatTriggers() -{ - delete [] m_PubTrigger; - m_PubTrigger = NULL; - delete [] m_PrivTrigger; - m_PrivTrigger = NULL; -} - -ConfigResult ChatTriggers::OnSourceModConfigChanged(const char *key, - const char *value, - ConfigSource source, - char *error, - size_t maxlength) -{ - if (strcmp(key, "PublicChatTrigger") == 0) - { - delete [] m_PubTrigger; - m_PubTrigger = sm_strdup(value); - m_PubTriggerSize = strlen(m_PubTrigger); - return ConfigResult_Accept; - } else if (strcmp(key, "SilentChatTrigger") == 0) { - delete [] m_PrivTrigger; - m_PrivTrigger = sm_strdup(value); - m_PrivTriggerSize = strlen(m_PrivTrigger); - return ConfigResult_Accept; - } - - return ConfigResult_Ignore; -} - -void ChatTriggers::OnSourceModGameInitialized() -{ - unsigned int total = 2; - ConCommandBase *pCmd = icvar->GetCommands(); - const char *name; - while (pCmd) - { - if (pCmd->IsCommand()) - { - name = pCmd->GetName(); - if (!m_pSayCmd && strcmp(name, "say") == 0) - { - m_pSayCmd = (ConCommand *)pCmd; - if (--total == 0) - { - break; - } - } else if (!m_pSayTeamCmd && strcmp(name, "say_team") == 0) { - m_pSayTeamCmd = (ConCommand *)pCmd; - if (--total == 0) - { - break; - } - } - } - pCmd = const_cast(pCmd->GetNext()); - } - - if (m_pSayCmd) - { - SH_ADD_HOOK_MEMFUNC(ConCommand, Dispatch, m_pSayCmd, this, &ChatTriggers::OnSayCommand_Pre, false); - SH_ADD_HOOK_MEMFUNC(ConCommand, Dispatch, m_pSayCmd, this, &ChatTriggers::OnSayCommand_Post, true); - } - if (m_pSayTeamCmd) - { - SH_ADD_HOOK_MEMFUNC(ConCommand, Dispatch, m_pSayTeamCmd, this, &ChatTriggers::OnSayCommand_Pre, false); - SH_ADD_HOOK_MEMFUNC(ConCommand, Dispatch, m_pSayTeamCmd, this, &ChatTriggers::OnSayCommand_Post, true); - } -} - -void ChatTriggers::OnSourceModShutdown() -{ - if (m_pSayTeamCmd) - { - SH_REMOVE_HOOK_MEMFUNC(ConCommand, Dispatch, m_pSayTeamCmd, this, &ChatTriggers::OnSayCommand_Post, true); - SH_REMOVE_HOOK_MEMFUNC(ConCommand, Dispatch, m_pSayTeamCmd, this, &ChatTriggers::OnSayCommand_Pre, false); - } - if (m_pSayCmd) - { - SH_REMOVE_HOOK_MEMFUNC(ConCommand, Dispatch, m_pSayCmd, this, &ChatTriggers::OnSayCommand_Post, true); - SH_REMOVE_HOOK_MEMFUNC(ConCommand, Dispatch, m_pSayCmd, this, &ChatTriggers::OnSayCommand_Pre, false); - } -} - -#if defined ORANGEBOX_BUILD -void ChatTriggers::OnSayCommand_Pre(const CCommand &command) -{ -#else -void ChatTriggers::OnSayCommand_Pre() -{ - CCommand command; -#endif - int client = g_ConCmds.GetCommandClient(); - m_bIsChatTrigger = false; - - /* The server console cannot do this */ - if (client == 0) - { - RETURN_META(MRES_IGNORED); - } - - const char *args = command.ArgS(); - - if (!args) - { - RETURN_META(MRES_IGNORED); - } - - /* Handle quoted string sets */ - bool is_quoted = false; - if (args[0] == '"') - { - args++; - is_quoted = true; - } - - bool is_trigger = false; - bool is_silent = false; - - /* Check for either trigger */ - if (m_PubTriggerSize && strncmp(args, m_PubTrigger, m_PubTriggerSize) == 0) - { - is_trigger = true; - args = &args[m_PubTriggerSize]; - } else if (m_PrivTriggerSize && strncmp(args, m_PrivTrigger, m_PrivTriggerSize) == 0) { - is_trigger = true; - is_silent = true; - args = &args[m_PrivTriggerSize]; - } - - if (!is_trigger) - { - RETURN_META(MRES_IGNORED); - } - - /** - * Test if this is actually a command! - */ - if (!PreProcessTrigger(engine->PEntityOfEntIndex(client), args, is_quoted)) - { - RETURN_META(MRES_IGNORED); - } - - m_bIsChatTrigger = true; - - /** - * We'll execute it in post. - */ - m_bWillProcessInPost = true; - m_bTriggerWasSilent = is_silent; - - /* If we're silent, block */ - if (is_silent) - { - RETURN_META(MRES_SUPERCEDE); - } - - /* Otherwise, let the command continue */ - RETURN_META(MRES_IGNORED); -} - -#if defined ORANGEBOX_BUILD -void ChatTriggers::OnSayCommand_Post(const CCommand &command) -#else -void ChatTriggers::OnSayCommand_Post() -#endif -{ - m_bIsChatTrigger = false; - if (m_bWillProcessInPost) - { - /* Reset this for re-entrancy */ - m_bWillProcessInPost = false; - - /* Execute the cached command */ - int client = g_ConCmds.GetCommandClient(); - unsigned int old = SetReplyTo(SM_REPLY_CHAT); - serverpluginhelpers->ClientCommand(engine->PEntityOfEntIndex(client), m_ToExecute); - SetReplyTo(old); - } -} - -bool ChatTriggers::PreProcessTrigger(edict_t *pEdict, const char *args, bool is_quoted) -{ - /* Extract a command. This is kind of sloppy. */ - char cmd_buf[64]; - size_t cmd_len = 0; - const char *inptr = args; - while (*inptr != '\0' - && !textparsers->IsWhitespace(inptr) - && *inptr != '"' - && cmd_len < sizeof(cmd_buf) - 1) - { - cmd_buf[cmd_len++] = *inptr++; - } - cmd_buf[cmd_len] = '\0'; - - if (cmd_len == 0) - { - return false; - } - - /* See if we have this registered */ - bool prepended = false; - if (!g_ConCmds.LookForSourceModCommand(cmd_buf)) - { - /* Check if we had an "sm_" prefix */ - if (strncmp(cmd_buf, "sm_", 3) == 0) - { - return false; - } - - /* Now, prepend. Don't worry about the buffers. This will - * work because the sizes are limited from earlier. - */ - char new_buf[80]; - strcpy(new_buf, "sm_"); - strncopy(&new_buf[3], cmd_buf, sizeof(new_buf)-3); - - /* Recheck */ - if (!g_ConCmds.LookForSourceModCommand(new_buf)) - { - return false; - } - - prepended = true; - } - - /* See if we need to do extra string manipulation */ - if (is_quoted || prepended) - { - size_t len; - - /* Check if we need to prepend sm_ */ - if (prepended) - { - len = UTIL_Format(m_ToExecute, sizeof(m_ToExecute), "sm_%s", args); - } else { - len = strncopy(m_ToExecute, args, sizeof(m_ToExecute)); - } - - /* Check if we need to strip a quote */ - if (is_quoted) - { - if (m_ToExecute[len-1] == '"') - { - m_ToExecute[--len] = '\0'; - } - } - } else { - strncopy(m_ToExecute, args, sizeof(m_ToExecute)); - } - - return true; -} - -unsigned int ChatTriggers::SetReplyTo(unsigned int reply) -{ - unsigned int old = m_ReplyTo; - - m_ReplyTo = reply; - - return old; -} - -unsigned int ChatTriggers::GetReplyTo() -{ - return m_ReplyTo; -} - -bool ChatTriggers::IsChatTrigger() -{ - return m_bIsChatTrigger; -} diff --git a/core/ChatTriggers.h b/core/ChatTriggers.h deleted file mode 100644 index c4adbb4a..00000000 --- a/core/ChatTriggers.h +++ /dev/null @@ -1,83 +0,0 @@ -/** - * vim: set ts=4 : - * ============================================================================= - * SourceMod - * Copyright (C) 2004-2007 AlliedModders LLC. All rights reserved. - * ============================================================================= - * - * This program is free software; you can redistribute it and/or modify it under - * the terms of the GNU General Public License, version 3.0, as published by the - * Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more - * details. - * - * You should have received a copy of the GNU General Public License along with - * this program. If not, see . - * - * As a special exception, AlliedModders LLC gives you permission to link the - * code of this program (as well as its derivative works) to "Half-Life 2," the - * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software - * by the Valve Corporation. You must obey the GNU General Public License in - * all respects for all other code used. Additionally, AlliedModders LLC grants - * this exception to all derivative works. AlliedModders LLC defines further - * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007), - * or . - * - * Version: $Id$ - */ - -#ifndef _INCLUDE_SOURCEMOD_CHAT_TRIGGERS_H_ -#define _INCLUDE_SOURCEMOD_CHAT_TRIGGERS_H_ - -#include "sm_globals.h" -#include "sourcemm_api.h" -#include -#include - -class ChatTriggers : public SMGlobalClass -{ -public: - ChatTriggers(); - ~ChatTriggers(); -public: //SMGlobalClass - void OnSourceModGameInitialized(); - void OnSourceModShutdown(); - ConfigResult OnSourceModConfigChanged(const char *key, - const char *value, - ConfigSource source, - char *error, - size_t maxlength); -private: //ConCommand -#if defined ORANGEBOX_BUILD - void OnSayCommand_Pre(const CCommand &command); - void OnSayCommand_Post(const CCommand &command); -#else - void OnSayCommand_Pre(); - void OnSayCommand_Post(); -#endif -public: - unsigned int GetReplyTo(); - unsigned int SetReplyTo(unsigned int reply); - bool IsChatTrigger(); -private: - bool PreProcessTrigger(edict_t *pEdict, const char *args, bool is_quoted); -private: - ConCommand *m_pSayCmd; - ConCommand *m_pSayTeamCmd; - char *m_PubTrigger; - size_t m_PubTriggerSize; - char *m_PrivTrigger; - size_t m_PrivTriggerSize; - bool m_bWillProcessInPost; - bool m_bTriggerWasSilent; - bool m_bIsChatTrigger; - unsigned int m_ReplyTo; - char m_ToExecute[300]; -}; - -extern ChatTriggers g_ChatTriggers; - -#endif //_INCLUDE_SOURCEMOD_CHAT_TRIGGERS_H_ diff --git a/core/ConCmdManager.cpp b/core/ConCmdManager.cpp deleted file mode 100644 index 28a97069..00000000 --- a/core/ConCmdManager.cpp +++ /dev/null @@ -1,1117 +0,0 @@ -/** - * vim: set ts=4 : - * ============================================================================= - * SourceMod - * Copyright (C) 2004-2007 AlliedModders LLC. All rights reserved. - * ============================================================================= - * - * This program is free software; you can redistribute it and/or modify it under - * the terms of the GNU General Public License, version 3.0, as published by the - * Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more - * details. - * - * You should have received a copy of the GNU General Public License along with - * this program. If not, see . - * - * As a special exception, AlliedModders LLC gives you permission to link the - * code of this program (as well as its derivative works) to "Half-Life 2," the - * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software - * by the Valve Corporation. You must obey the GNU General Public License in - * all respects for all other code used. Additionally, AlliedModders LLC grants - * this exception to all derivative works. AlliedModders LLC defines further - * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007), - * or . - * - * Version: $Id$ - */ - -#include "ConCmdManager.h" -#include "sm_srvcmds.h" -#include "AdminCache.h" -#include "sm_stringutil.h" -#include "PlayerManager.h" -#include "Translator.h" -#include "HalfLife2.h" -#include "ChatTriggers.h" - -ConCmdManager g_ConCmds; - -#if defined ORANGEBOX_BUILD - SH_DECL_HOOK1_void(ConCommand, Dispatch, SH_NOATTRIB, false, const CCommand &); -#else - SH_DECL_HOOK0_void(ConCommand, Dispatch, SH_NOATTRIB, false); -#endif - -SH_DECL_HOOK1_void(IServerGameClients, SetCommandClient, SH_NOATTRIB, false, int); - -struct PlCmdInfo -{ - ConCmdInfo *pInfo; - CmdHook *pHook; - CmdType type; -}; -typedef List CmdList; - -void AddToPlCmdList(CmdList *pList, const PlCmdInfo &info); - -ConCmdManager::ConCmdManager() : m_Strings(1024) -{ - m_pCmds = sm_trie_create(); - m_pCmdGrps = sm_trie_create(); - m_CmdClient = 0; -} - -ConCmdManager::~ConCmdManager() -{ - sm_trie_destroy(m_pCmds); - sm_trie_destroy(m_pCmdGrps); -} - -void ConCmdManager::OnSourceModAllInitialized() -{ - g_PluginSys.AddPluginsListener(this); - g_RootMenu.AddRootConsoleCommand("cmds", "List console commands", this); - SH_ADD_HOOK_MEMFUNC(IServerGameClients, SetCommandClient, serverClients, this, &ConCmdManager::SetCommandClient, false); -} - -void ConCmdManager::OnSourceModShutdown() -{ - /* All commands should already be removed by the time we're done */ - SH_REMOVE_HOOK_MEMFUNC(IServerGameClients, SetCommandClient, serverClients, this, &ConCmdManager::SetCommandClient, false); - g_RootMenu.RemoveRootConsoleCommand("cmds", this); -} - -void ConCmdManager::OnUnlinkConCommandBase(ConCommandBase *pBase, const char *name, bool is_read_safe) -{ - /* Whoa, first get its information struct */ - ConCmdInfo *pInfo; - - if (!sm_trie_retrieve(m_pCmds, name, (void **)&pInfo)) - { - return; - } - - RemoveConCmds(pInfo->srvhooks); - RemoveConCmds(pInfo->conhooks); - - RemoveConCmd(pInfo, name, is_read_safe, false); -} - -void ConCmdManager::RemoveConCmds(List &cmdlist) -{ - List::iterator iter = cmdlist.begin(); - - while (iter != cmdlist.end()) - { - CmdHook *pHook = (*iter); - IPluginContext *pContext = pHook->pf->GetParentContext(); - IPlugin *pPlugin = g_PluginSys.GetPluginByCtx(pContext->GetContext()); - CmdList *pList = NULL; - - //gaben - if (!pPlugin->GetProperty("CommandList", (void **)&pList, false) || !pList) - { - continue; - } - - CmdList::iterator p_iter = pList->begin(); - while (p_iter != pList->end()) - { - PlCmdInfo &cmd = (*p_iter); - if (cmd.pHook == pHook) - { - p_iter = pList->erase(p_iter); - } - else - { - p_iter++; - } - } - - delete pHook->pAdmin; - delete pHook; - - iter = cmdlist.erase(iter); - } -} - -void ConCmdManager::RemoveConCmds(List &cmdlist, IPluginContext *pContext) -{ - List::iterator iter = cmdlist.begin(); - CmdHook *pHook; - - while (iter != cmdlist.end()) - { - pHook = (*iter); - if (pHook->pf->GetParentContext() == pContext) - { - delete pHook->pAdmin; - delete pHook; - iter = cmdlist.erase(iter); - } - else - { - iter++; - } - } -} - -void ConCmdManager::OnPluginDestroyed(IPlugin *plugin) -{ - CmdList *pList; - List removed; - if (plugin->GetProperty("CommandList", (void **)&pList, true)) - { - IPluginContext *pContext = plugin->GetBaseContext(); - CmdList::iterator iter; - /* First pass! - * Only bother if there's an actual command list on this plugin... - */ - for (iter=pList->begin(); - iter!=pList->end(); - iter++) - { - PlCmdInfo &cmd = (*iter); - ConCmdInfo *pInfo = cmd.pInfo; - - /* Has this chain already been fully cleaned/removed? */ - if (removed.find(pInfo) != removed.end()) - { - continue; - } - - /* Remove any hooks from us on this command */ - RemoveConCmds(pInfo->conhooks, pContext); - RemoveConCmds(pInfo->srvhooks, pContext); - - /* See if there are still hooks */ - if (pInfo->srvhooks.size()) - { - continue; - } - if (pInfo->conhooks.size()) - { - continue; - } - - /* Remove the command, it should be safe now */ - RemoveConCmd(pInfo, pInfo->pCmd->GetName(), true, true); - removed.push_back(pInfo); - } - delete pList; - } -} -#if defined ORANGEBOX_BUILD -void CommandCallback(const CCommand &command) -{ -#else -void CommandCallback() -{ - CCommand command; -#endif - - g_HL2.PushCommandStack(&command); - - g_ConCmds.InternalDispatch(command); - - g_HL2.PopCommandStack(); -} - -void ConCmdManager::SetCommandClient(int client) -{ - m_CmdClient = client + 1; -} - -ResultType ConCmdManager::DispatchClientCommand(int client, const char *cmd, int args, ResultType type) -{ - ConCmdInfo *pInfo; - if (sm_trie_retrieve(m_pCmds, cmd, (void **)&pInfo)) - { - cell_t result = type; - cell_t tempres = result; - List::iterator iter; - CmdHook *pHook; - for (iter=pInfo->conhooks.begin(); - iter!=pInfo->conhooks.end(); - iter++) - { - pHook = (*iter); - if (!pHook->pf->IsRunnable()) - { - continue; - } - if (pHook->pAdmin && !CheckAccess(client, cmd, pHook->pAdmin)) - { - if (result < Pl_Handled) - { - result = Pl_Handled; - } - continue; - } - pHook->pf->PushCell(client); - pHook->pf->PushCell(args); - if (pHook->pf->Execute(&tempres) == SP_ERROR_NONE) - { - if (tempres > result) - { - result = tempres; - } - if (result == Pl_Stop) - { - break; - } - } - } - type = (ResultType)result; - } - - return type; -} - -void ConCmdManager::InternalDispatch(const CCommand &command) -{ - int client = m_CmdClient; - - if (client) - { - CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); - if (!pPlayer || !pPlayer->IsConnected()) - { - return; - } - } - - /** - * Note: Console commands will EITHER go through IServerGameDLL::ClientCommand, - * OR this dispatch. They will NEVER go through both. - * -- - * Whether or not it goes through the callback is determined by FCVAR_GAMEDLL - */ - const char *cmd = g_HL2.CurrentCommandName(); - - ConCmdInfo *pInfo; - if (!sm_trie_retrieve(m_pCmds, cmd, (void **)&pInfo)) - { - return; - } - - cell_t result = Pl_Continue; - int args = command.ArgC() - 1; - - List::iterator iter; - CmdHook *pHook; - - /* Execute server-only commands if viable */ - if (client == 0 && pInfo->srvhooks.size()) - { - cell_t tempres = result; - for (iter=pInfo->srvhooks.begin(); - iter!=pInfo->srvhooks.end(); - iter++) - { - pHook = (*iter); - if (!pHook->pf->IsRunnable()) - { - continue; - } - pHook->pf->PushCell(args); - if (pHook->pf->Execute(&tempres) == SP_ERROR_NONE) - { - if (tempres > result) - { - result = tempres; - } - if (result == Pl_Stop) - { - break; - } - } - } - - /* Check if there's an early stop */ - if (result >= Pl_Stop) - { - if (!pInfo->sourceMod) - { - RETURN_META(MRES_SUPERCEDE); - } - return; - } - } - - /* Execute console commands */ - if (pInfo->conhooks.size()) - { - cell_t tempres = result; - for (iter=pInfo->conhooks.begin(); - iter!=pInfo->conhooks.end(); - iter++) - { - pHook = (*iter); - if (!pHook->pf->IsRunnable()) - { - continue; - } - if (client - && pHook->pAdmin - && !CheckAccess(client, cmd, pHook->pAdmin)) - { - if (result < Pl_Handled) - { - result = Pl_Handled; - } - continue; - } - - /* On a listen server, sometimes the server host's client index can be set as 0. - * So index 1 is passed to the command callback to correct this potential problem. - */ - if (client == 0 && !engine->IsDedicatedServer()) - { - pHook->pf->PushCell(1); - } else { - pHook->pf->PushCell(client); - } - - pHook->pf->PushCell(args); - if (pHook->pf->Execute(&tempres) == SP_ERROR_NONE) - { - if (tempres > result) - { - result = tempres; - } - if (result == Pl_Stop) - { - break; - } - } - } - } - - if (result >= Pl_Handled) - { - if (!pInfo->sourceMod) - { - RETURN_META(MRES_SUPERCEDE); - } - return; - } -} - -bool ConCmdManager::CheckCommandAccess(int client, const char *cmd, FlagBits cmdflags) -{ - if (cmdflags == 0 || client == 0) - { - return true; - } - - /* If running listen server, then client 1 is the server host and should have 'root' access */ - if (client == 1 && !engine->IsDedicatedServer()) - { - return true; - } - - CPlayer *player = g_Players.GetPlayerByIndex(client); - if (!player - || player->GetEdict() == NULL - || player->IsFakeClient()) - { - return false; - } - - AdminId adm = player->GetAdminId(); - if (adm != INVALID_ADMIN_ID) - { - FlagBits bits = g_Admins.GetAdminFlags(adm, Access_Effective); - - /* root knows all, WHOA */ - if ((bits & ADMFLAG_ROOT) == ADMFLAG_ROOT) - { - return true; - } - - /* Check for overrides - * :TODO: is it worth optimizing this? - */ - unsigned int groups = g_Admins.GetAdminGroupCount(adm); - GroupId gid; - OverrideRule rule; - bool override = false; - for (unsigned int i=0; ieflags)) - { - return true; - } - - edict_t *pEdict = engine->PEntityOfEntIndex(client); - - /* If we got here, the command failed... */ - char buffer[128]; - if (g_Translator.CoreTrans(client, buffer, sizeof(buffer), "No Access", NULL, NULL) - != Trans_Okay) - { - snprintf(buffer, sizeof(buffer), "You do not have access to this command"); - } - - unsigned int replyto = g_ChatTriggers.GetReplyTo(); - if (replyto == SM_REPLY_CONSOLE) - { - char fullbuffer[192]; - snprintf(fullbuffer, sizeof(fullbuffer), "[SM] %s.\n", buffer); - engine->ClientPrintf(pEdict, fullbuffer); - } else if (replyto == SM_REPLY_CHAT) { - char fullbuffer[192]; - snprintf(fullbuffer, sizeof(fullbuffer), "[SM] %s.", buffer); - g_HL2.TextMsg(client, HUD_PRINTTALK, fullbuffer); - } - - return false; -} - -bool ConCmdManager::AddConsoleCommand(IPluginFunction *pFunction, - const char *name, - const char *description, - int flags) -{ - ConCmdInfo *pInfo = AddOrFindCommand(name, description, flags); - - if (!pInfo) - { - return false; - } - - CmdHook *pHook = new CmdHook(); - - pHook->pf = pFunction; - if (description && description[0]) - { - pHook->helptext.assign(description); - } - pInfo->conhooks.push_back(pHook); - - /* Add to the plugin */ - CmdList *pList; - IPlugin *pPlugin = g_PluginSys.GetPluginByCtx(pFunction->GetParentContext()->GetContext()); - if (!pPlugin->GetProperty("CommandList", (void **)&pList)) - { - pList = new CmdList(); - pPlugin->SetProperty("CommandList", pList); - } - PlCmdInfo info; - info.pInfo = pInfo; - info.type = Cmd_Console; - info.pHook = pHook; - AddToPlCmdList(pList, info); - - return true; -} - -bool ConCmdManager::AddAdminCommand(IPluginFunction *pFunction, - const char *name, - const char *group, - int adminflags, - const char *description, - int flags) -{ - ConCmdInfo *pInfo = AddOrFindCommand(name, description, flags); - - if (!pInfo) - { - return false; - } - - CmdHook *pHook = new CmdHook(); - AdminCmdInfo *pAdmin = new AdminCmdInfo(); - - pHook->pf = pFunction; - if (description && description[0]) - { - pHook->helptext.assign(description); - } - pHook->pAdmin = pAdmin; - - void *object; - int grpid; - if (!sm_trie_retrieve(m_pCmdGrps, group, (void **)&object)) - { - grpid = m_Strings.AddString(group); - sm_trie_insert(m_pCmdGrps, group, (void *)grpid); - } - else - { - grpid = (int)object; - } - - pAdmin->cmdGrpId = grpid; - pAdmin->flags = adminflags; - - /* First get the command group override, if any */ - bool override = g_Admins.GetCommandOverride(group, - Override_CommandGroup, - &(pAdmin->eflags)); - - /* Next get the command override, if any */ - if (g_Admins.GetCommandOverride(name, - Override_Command, - &(pAdmin->eflags))) - { - override = true; - } - - /* Assign normal flags if there were no overrides */ - if (!override) - { - pAdmin->eflags = pAdmin->flags; - } - - /* Finally, add the hook */ - pInfo->conhooks.push_back(pHook); - pInfo->admin = *(pHook->pAdmin); - pInfo->is_admin_set = true; - - /* Now add to the plugin */ - CmdList *pList; - IPlugin *pPlugin = g_PluginSys.GetPluginByCtx(pFunction->GetParentContext()->GetContext()); - if (!pPlugin->GetProperty("CommandList", (void **)&pList)) - { - pList = new CmdList(); - pPlugin->SetProperty("CommandList", pList); - } - PlCmdInfo info; - info.pInfo = pInfo; - info.type = Cmd_Admin; - info.pHook = pHook; - AddToPlCmdList(pList, info); - - return true; -} - -bool ConCmdManager::AddServerCommand(IPluginFunction *pFunction, - const char *name, - const char *description, - int flags) - -{ - ConCmdInfo *pInfo = AddOrFindCommand(name, description, flags); - - if (!pInfo) - { - return false; - } - - CmdHook *pHook = new CmdHook(); - - pHook->pf = pFunction; - if (description && description[0]) - { - pHook->helptext.assign(description); - } - - pInfo->srvhooks.push_back(pHook); - - /* Add to the plugin */ - CmdList *pList; - IPlugin *pPlugin = g_PluginSys.GetPluginByCtx(pFunction->GetParentContext()->GetContext()); - if (!pPlugin->GetProperty("CommandList", (void **)&pList)) - { - pList = new CmdList(); - pPlugin->SetProperty("CommandList", pList); - } - PlCmdInfo info; - info.pInfo = pInfo; - info.type = Cmd_Server; - info.pHook = pHook; - AddToPlCmdList(pList, info); - - return true; -} - -void AddToPlCmdList(CmdList *pList, const PlCmdInfo &info) -{ - CmdList::iterator iter = pList->begin(); - bool inserted = false; - const char *orig = NULL; - - orig = info.pInfo->pCmd->GetName(); - - /* Insert this into the help list, SORTED alphabetically. */ - while (iter != pList->end()) - { - PlCmdInfo &obj = (*iter); - const char *cmd = obj.pInfo->pCmd->GetName(); - if (strcmp(orig, cmd) < 0) - { - pList->insert(iter, info); - inserted = true; - break; - } - iter++; - } - - if (!inserted) - { - pList->push_back(info); - } -} - -void ConCmdManager::AddToCmdList(ConCmdInfo *info) -{ - List::iterator iter = m_CmdList.begin(); - ConCmdInfo *pInfo; - bool inserted = false; - const char *orig = NULL; - - orig = info->pCmd->GetName(); - - /* Insert this into the help list, SORTED alphabetically. */ - while (iter != m_CmdList.end()) - { - const char *cmd = NULL; - pInfo = (*iter); - cmd = pInfo->pCmd->GetName(); - if (strcmp(orig, cmd) < 0) - { - m_CmdList.insert(iter, info); - inserted = true; - break; - } - iter++; - } - - if (!inserted) - { - m_CmdList.push_back(info); - } -} - -void ConCmdManager::UpdateAdminCmdFlags(const char *cmd, OverrideType type, FlagBits bits, bool remove) -{ - ConCmdInfo *pInfo; - - if (type == Override_Command) - { - if (!sm_trie_retrieve(m_pCmds, cmd, (void **)&pInfo)) - { - return; - } - - List::iterator iter; - CmdHook *pHook; - - for (iter=pInfo->conhooks.begin(); iter!=pInfo->conhooks.end(); iter++) - { - pHook = (*iter); - if (pHook->pAdmin) - { - if (!remove) - { - pHook->pAdmin->eflags = bits; - } else { - pHook->pAdmin->eflags = pHook->pAdmin->flags; - } - pInfo->admin = *(pHook->pAdmin); - } - } - pInfo->is_admin_set = true; - } - else if (type == Override_CommandGroup) - { - void *object; - if (!sm_trie_retrieve(m_pCmdGrps, cmd, &object)) - { - return; - } - int grpid = (int)object; - - /* This is bad :( loop through all commands */ - List::iterator iter; - CmdHook *pHook; - for (iter=m_CmdList.begin(); iter!=m_CmdList.end(); iter++) - { - pInfo = (*iter); - for (List::iterator citer=pInfo->conhooks.begin(); - citer!=pInfo->conhooks.end(); - citer++) - { - pHook = (*citer); - if (pHook->pAdmin && pHook->pAdmin->cmdGrpId == grpid) - { - if (remove) - { - pHook->pAdmin->eflags = bits; - } else { - pHook->pAdmin->eflags = pHook->pAdmin->flags; - } - pInfo->admin = *(pHook->pAdmin); - } - } - } - pInfo->is_admin_set = true; - } -} - -void ConCmdManager::RemoveConCmd(ConCmdInfo *info, const char *name, bool is_read_safe, bool untrack) -{ - /* Remove from the trie */ - sm_trie_delete(m_pCmds, name); - - /* Remove console-specific information - * This should always be true as of right now - */ - if (info->pCmd) - { - if (info->sourceMod) - { - /* Unlink from SourceMM */ - g_SMAPI->UnregisterConCommandBase(g_PLAPI, info->pCmd); - /* Delete the command's memory */ - char *new_help = const_cast(info->pCmd->GetHelpText()); - char *new_name = const_cast(info->pCmd->GetName()); - delete [] new_help; - delete [] new_name; - delete info->pCmd; - } - else - { - if (is_read_safe) - { - /* Remove the external hook */ - SH_REMOVE_HOOK_STATICFUNC(ConCommand, Dispatch, info->pCmd, CommandCallback, false); - } - if (untrack) - { - UntrackConCommandBase(info->pCmd, this); - } - } - } - - /* Remove from list */ - m_CmdList.remove(info); - - delete info; -} - -bool ConCmdManager::LookForSourceModCommand(const char *cmd) -{ - ConCmdInfo *pInfo; - - if (!sm_trie_retrieve(m_pCmds, cmd, (void **)&pInfo)) - { - return false; - } - - return pInfo->sourceMod && (pInfo->conhooks.size() > 0); -} - -bool ConCmdManager::LookForCommandAdminFlags(const char *cmd, FlagBits *pFlags) -{ - ConCmdInfo *pInfo; - - if (!sm_trie_retrieve(m_pCmds, cmd, (void **)&pInfo)) - { - return false; - } - - *pFlags = pInfo->admin.eflags; - - return pInfo->is_admin_set; -} - -ConCmdInfo *ConCmdManager::AddOrFindCommand(const char *name, const char *description, int flags) -{ - ConCmdInfo *pInfo; - if (!sm_trie_retrieve(m_pCmds, name, (void **)&pInfo)) - { - pInfo = new ConCmdInfo(); - /* Find the commandopan */ - ConCommandBase *pBase = icvar->GetCommands(); - ConCommand *pCmd = NULL; - while (pBase) - { - if (strcmp(pBase->GetName(), name) == 0) - { - /* Don't want to return convar with same name */ - if (!pBase->IsCommand()) - { - return NULL; - } - - pCmd = (ConCommand *)pBase; - break; - } - pBase = const_cast(pBase->GetNext()); - } - - if (!pCmd) - { - /* Note that we have to duplicate because the source might not be - * a static string, and these expect static memory. - */ - if (!description) - { - description = ""; - } - char *new_name = sm_strdup(name); - char *new_help = sm_strdup(description); - pCmd = new ConCommand(new_name, CommandCallback, new_help, flags); - pInfo->sourceMod = true; - } - else - { - TrackConCommandBase(pCmd, this); - SH_ADD_HOOK_STATICFUNC(ConCommand, Dispatch, pCmd, CommandCallback, false); - } - - pInfo->pCmd = pCmd; - pInfo->is_admin_set = false; - - sm_trie_insert(m_pCmds, name, pInfo); - AddToCmdList(pInfo); - } - - return pInfo; -} - -void ConCmdManager::OnRootConsoleCommand(const char *cmdname, const CCommand &command) -{ - if (command.ArgC() >= 3) - { - const char *text = command.Arg(2); - - int id = atoi(text); - CPlugin *pPlugin = g_PluginSys.GetPluginByOrder(id); - - if (!pPlugin) - { - g_RootMenu.ConsolePrint("[SM] Plugin index %d not found.", id); - return; - } - - const sm_plugininfo_t *plinfo = pPlugin->GetPublicInfo(); - const char *plname = IS_STR_FILLED(plinfo->name) ? plinfo->name : pPlugin->GetFilename(); - - CmdList *pList; - if (!pPlugin->GetProperty("CommandList", (void **)&pList)) - { - g_RootMenu.ConsolePrint("[SM] No commands found for: %s", plname); - return; - } - if (!pList->size()) - { - g_RootMenu.ConsolePrint("[SM] No commands found for: %s", plname); - return; - } - - CmdList::iterator iter; - const char *type = NULL; - const char *name; - const char *help; - g_RootMenu.ConsolePrint("[SM] Listing %d commands for: %s", pList->size(), plname); - g_RootMenu.ConsolePrint(" %-17.16s %-8.7s %s", "[Name]", "[Type]", "[Help]"); - for (iter=pList->begin(); - iter!=pList->end(); - iter++, id++) - { - PlCmdInfo &cmd = (*iter); - if (cmd.type == Cmd_Server) - { - type = "server"; - } - else if (cmd.type == Cmd_Console) - { - type = "console"; - } - else if (cmd.type == Cmd_Admin) - { - type = "admin"; - } - name = cmd.pInfo->pCmd->GetName(); - if (cmd.pHook->helptext.size()) - { - help = cmd.pHook->helptext.c_str(); - } - else - { - help = cmd.pInfo->pCmd->GetHelpText(); - } - g_RootMenu.ConsolePrint(" %-17.16s %-12.11s %s", name, type, help); - } - - return; - } - - g_RootMenu.ConsolePrint("[SM] Usage: sm cmds "); -} - -static int g_yam_state = 0; -void _YamState(int state) -{ - if (state == 0) - { - g_RootMenu.ConsolePrint("Welcome to the SourceMod Text Adventure."); - g_RootMenu.ConsolePrint("Type sm_text to see the last message."); - g_RootMenu.ConsolePrint("Type sm_text to follow a capital word."); - g_RootMenu.ConsolePrint("-------------------------------"); - g_RootMenu.ConsolePrint("You are at VALVE HEADQUARTERS."); - g_RootMenu.ConsolePrint("To your LEFT is BAILOPAN, rearranging the letters to spell"); - g_RootMenu.ConsolePrint("\"A HARD VEAL QUEST\". FORWARD is the entrance to the building."); - g_RootMenu.ConsolePrint("To your RIGHT is your last chance to flee in terror."); - } else if (state == 1) { - g_RootMenu.ConsolePrint("BAILOPAN tells you that his name his pronounced"); - g_RootMenu.ConsolePrint("\"bye low pahn,\" not \"bay low pan.\" Do you "); - g_RootMenu.ConsolePrint("MOCK him, or NOD quietly?"); - } else if (state == 2) { - g_RootMenu.ConsolePrint("You enter the Valve building. You hear screams coming from within."); - g_RootMenu.ConsolePrint("A grotesque figure lumbers up to greet you; it is Gabe Newell."); - g_RootMenu.ConsolePrint("\"Welcome,\" he belches, \"to my lair.\""); - g_RootMenu.ConsolePrint("Do you SHAKE Gaben's hand, WALK past him, or OFFER a donut?"); - } else if (state == 3) { - g_RootMenu.ConsolePrint("You walk into the break room. Alfred \"Alf is from Melmac\" Reynolds and"); - g_RootMenu.ConsolePrint("Yahn \"Yeti\" Bernier are discussing something (you overhear "); - g_RootMenu.ConsolePrint("the phrase \"and next Steam update, here's what we should break\")."); - g_RootMenu.ConsolePrint("Should you DIE in a fire, REPORT a bug, REQUEST a feature, or "); - g_RootMenu.ConsolePrint("SPRAY them with butter?"); - } - g_yam_state = state; -} - -#if defined ORANGEBOX_BUILD -void _IntExt_CallYams(const CCommand &cmd) -{ -#else -void _IntExt_CallYams() -{ - CCommand cmd; -#endif - const char *arg = cmd.Arg(1); - - /* should be impossible */ - if (!arg || arg[0] == '\0') - { - _YamState(g_yam_state); - } - - if (g_yam_state == 1) - { - if (strcasecmp(arg, "mock") == 0) - { - g_RootMenu.ConsolePrint("You mock BAILOPAN's pronunciation. In a fit of rage, "); - g_RootMenu.ConsolePrint("he sticks an INT 3 call into your chest, rendering you broken."); - g_RootMenu.ConsolePrint("YOU HAVE DIED. GAME OVER."); - g_yam_state = 0; - } else if (strcasecmp(arg, "nod") == 0) { - g_RootMenu.ConsolePrint("You nod quietly, and then slowly back away into the Valve headquarters."); - _YamState(2); - } else { - g_RootMenu.ConsolePrint("Commands are MOCK and NOD."); - } - } else if (g_yam_state == 3) { - if (strcasecmp(arg, "report") == 0) - { - g_RootMenu.ConsolePrint("You report a bug to Alfred and Yeti. Immediately, both fall asleep."); - g_RootMenu.ConsolePrint("You decay in the break room for two years while they sleep."); - g_RootMenu.ConsolePrint("YOU HAVE DIED. GAME OVER."); - g_yam_state = 0; - } else if (strcasecmp(arg, "request") == 0) { - g_RootMenu.ConsolePrint("You request a feature to Alfred and Yeti. They both mutter something"); - g_RootMenu.ConsolePrint("about it being implemented \"soon.\" Then, by accident, someone sends"); - g_RootMenu.ConsolePrint("a message over \"Friends.\" The entire building catches fire."); - g_RootMenu.ConsolePrint("YOU HAVE DIED. GAME OVER."); - g_yam_state = 0; - } else if (strcasecmp(arg, "die") == 0) { - g_RootMenu.ConsolePrint("For no reason, you suddenly catch fire. Alfred and Yeti find this"); - g_RootMenu.ConsolePrint("deeply disturbing, and cover your flaming corpse with Episode 2"); - g_RootMenu.ConsolePrint("advertisements. Coming soon, with Team Fortress 2, and Portal!"); - g_RootMenu.ConsolePrint("YOU HAVE DIED. GAME OVER."); - g_yam_state = 0; - } else if (strcasecmp(arg, "spray") == 0) { - g_RootMenu.ConsolePrint("You spray Alfred and Yeti with butter. Like Jack Thompson to an"); - g_RootMenu.ConsolePrint("ambulance, Gabe Newell instantly appears and devours them both."); - g_RootMenu.ConsolePrint("You run away, just in time, as Gabe Newell explodes, registering "); - g_RootMenu.ConsolePrint("a 5.6 earthquake. Outside, world peace is achieved."); - g_RootMenu.ConsolePrint("YOU HAVE WON."); - g_yam_state = 0; - } - } else if (g_yam_state == 2) { - if (strcasecmp(arg, "shake") == 0) - { - g_RootMenu.ConsolePrint("You shake Gaben's hand. It is a terrifying and disgusting experience."); - g_RootMenu.ConsolePrint("However, you survive, and continue on."); - _YamState(3); - } else if (strcasecmp(arg, "offer") == 0) { - g_RootMenu.ConsolePrint("You offer Gabe Newell one (1) donut. With a gleam in his eyes, "); - g_RootMenu.ConsolePrint("he picks you up and devours you whole."); - g_RootMenu.ConsolePrint("YOU HAVE DIED. GAME OVER."); - g_yam_state = 0; - } else if (strcasecmp(arg, "walk") == 0) { - g_RootMenu.ConsolePrint("You walk past Gabe Newell. He can't keep up with your pace!"); - _YamState(3); - } else { - g_RootMenu.ConsolePrint("Commands are SHAKE, OFFER, and WALK."); - } - } else if (g_yam_state == 0) { - if (strcasecmp(arg, "left") == 0) - { - _YamState(1); - } else if (strcasecmp(arg, "right") == 0) { - g_RootMenu.ConsolePrint("You run away from the Valve headquarters in sheer terror."); - g_RootMenu.ConsolePrint("While running, you smash into an unknown person, who turns out to be your soul mate."); - g_RootMenu.ConsolePrint("You marry and raise a family of 3 kids."); - g_RootMenu.ConsolePrint("Many years later, you look back, and realize this was your best choice."); - g_RootMenu.ConsolePrint("YOU HAVE WON."); - g_yam_state = 0; - } else if (strcasecmp(arg, "forward") == 0) { - _YamState(2); - } else if (arg[0] != '\0') { - g_RootMenu.ConsolePrint("Commands are FORWARD, LEFT, and RIGHT."); - } - } -} - -void _IntExt_EnableYams() -{ - static ConCommand *pCmd = NULL; - if (!pCmd) - { - pCmd = new ConCommand("sm_text", _IntExt_CallYams, "Fountain of Yams Adventure Game", FCVAR_GAMEDLL); - g_RootMenu.ConsolePrint("Something is now enabled..."); - } else { - g_RootMenu.ConsolePrint("Something is already enabled..."); - } -} diff --git a/core/ConCmdManager.h b/core/ConCmdManager.h deleted file mode 100644 index 51938cf7..00000000 --- a/core/ConCmdManager.h +++ /dev/null @@ -1,161 +0,0 @@ -/** - * vim: set ts=4 : - * ============================================================================= - * SourceMod - * Copyright (C) 2004-2007 AlliedModders LLC. All rights reserved. - * ============================================================================= - * - * This program is free software; you can redistribute it and/or modify it under - * the terms of the GNU General Public License, version 3.0, as published by the - * Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more - * details. - * - * You should have received a copy of the GNU General Public License along with - * this program. If not, see . - * - * As a special exception, AlliedModders LLC gives you permission to link the - * code of this program (as well as its derivative works) to "Half-Life 2," the - * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software - * by the Valve Corporation. You must obey the GNU General Public License in - * all respects for all other code used. Additionally, AlliedModders LLC grants - * this exception to all derivative works. AlliedModders LLC defines further - * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007), - * or . - * - * Version: $Id$ - */ - -#ifndef _INCLUDE_SOURCEMOD_CONCMDMANAGER_H_ -#define _INCLUDE_SOURCEMOD_CONCMDMANAGER_H_ - -#include "sm_globals.h" -#include "sourcemm_api.h" -#include "ForwardSys.h" -#include "sm_trie.h" -#include "sm_memtable.h" -#include -#include -#include -#include -#include "concmd_cleaner.h" - -using namespace SourceHook; - -enum CmdType -{ - Cmd_Server, - Cmd_Console, - Cmd_Admin, -}; - -struct AdminCmdInfo -{ - AdminCmdInfo() - { - cmdGrpId = -1; - flags = 0; - eflags = 0; - } - int cmdGrpId; /* index into cmdgroup string table */ - FlagBits flags; /* default flags */ - FlagBits eflags; /* effective flags */ -}; - -struct CmdHook -{ - CmdHook() - { - pf = NULL; - pAdmin = NULL; - } - IPluginFunction *pf; /* function hook */ - String helptext; /* help text */ - AdminCmdInfo *pAdmin; /* admin requirements, if any */ -}; - -struct ConCmdInfo -{ - ConCmdInfo() - { - sourceMod = false; - pCmd = NULL; - } - bool sourceMod; /**< Determines whether or not concmd was created by a SourceMod plugin */ - ConCommand *pCmd; /**< Pointer to the command itself */ - List srvhooks; /**< Hooks as a server command */ - List conhooks; /**< Hooks as a console command */ - AdminCmdInfo admin; /**< Admin info, if any */ - bool is_admin_set; /**< Whether or not admin info is set */ -}; - -class ConCmdManager : - public SMGlobalClass, - public IRootConsoleCommand, - public IPluginsListener, - public IConCommandTracker -{ -#if defined ORANGEBOX_BUILD - friend void CommandCallback(const CCommand &command); -#else - friend void CommandCallback(); -#endif -public: - ConCmdManager(); - ~ConCmdManager(); -public: //SMGlobalClass - void OnSourceModAllInitialized(); - void OnSourceModShutdown(); -public: //IPluginsListener - void OnPluginDestroyed(IPlugin *plugin); -public: //IRootConsoleCommand - void OnRootConsoleCommand(const char *cmdname, const CCommand &command); -public: //IConCommandTracker - void OnUnlinkConCommandBase(ConCommandBase *pBase, const char *name, bool is_read_safe); -public: - bool AddServerCommand(IPluginFunction *pFunction, const char *name, const char *description, int flags); - bool AddConsoleCommand(IPluginFunction *pFunction, const char *name, const char *description, int flags); - bool AddAdminCommand(IPluginFunction *pFunction, - const char *name, - const char *group, - int adminflags, - const char *description, - int flags); - ResultType DispatchClientCommand(int client, const char *cmd, int args, ResultType type); - void UpdateAdminCmdFlags(const char *cmd, OverrideType type, FlagBits bits, bool remove); - bool LookForSourceModCommand(const char *cmd); - bool LookForCommandAdminFlags(const char *cmd, FlagBits *pFlags); - bool CheckCommandAccess(int client, const char *cmd, FlagBits flags); -private: - void InternalDispatch(const CCommand &command); - ResultType RunAdminCommand(ConCmdInfo *pInfo, int client, int args); - ConCmdInfo *AddOrFindCommand(const char *name, const char *description, int flags); - void SetCommandClient(int client); - void AddToCmdList(ConCmdInfo *info); - void RemoveConCmd(ConCmdInfo *info, const char *cmd, bool is_read_safe, bool untrack); - void RemoveConCmds(List &cmdlist); - void RemoveConCmds(List &cmdlist, IPluginContext *pContext); - bool CheckAccess(int client, const char *cmd, AdminCmdInfo *pAdmin); -public: - inline int GetCommandClient() - { - return m_CmdClient; - } - inline const List & GetCommandList() - { - return m_CmdList; - } -private: - Trie *m_pCmds; /* command lookup */ - Trie *m_pCmdGrps; /* command group lookup */ - List m_CmdList; /* command list */ - int m_CmdClient; /* current client */ - BaseStringTable m_Strings; /* string table */ -}; - -extern ConCmdManager g_ConCmds; - -#endif // _INCLUDE_SOURCEMOD_CONCMDMANAGER_H_ diff --git a/core/ConVarManager.cpp b/core/ConVarManager.cpp deleted file mode 100644 index 5e9a5ff4..00000000 --- a/core/ConVarManager.cpp +++ /dev/null @@ -1,823 +0,0 @@ -/** - * vim: set ts=4 : - * ============================================================================= - * SourceMod - * Copyright (C) 2004-2007 AlliedModders LLC. All rights reserved. - * ============================================================================= - * - * This program is free software; you can redistribute it and/or modify it under - * the terms of the GNU General Public License, version 3.0, as published by the - * Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more - * details. - * - * You should have received a copy of the GNU General Public License along with - * this program. If not, see . - * - * As a special exception, AlliedModders LLC gives you permission to link the - * code of this program (as well as its derivative works) to "Half-Life 2," the - * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software - * by the Valve Corporation. You must obey the GNU General Public License in - * all respects for all other code used. Additionally, AlliedModders LLC grants - * this exception to all derivative works. AlliedModders LLC defines further - * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007), - * or . - * - * Version: $Id$ - */ - -#include "ConVarManager.h" -#include "HalfLife2.h" -#include "PluginSys.h" -#include "ForwardSys.h" -#include "HandleSys.h" -#include "sm_srvcmds.h" -#include "sm_stringutil.h" -#include -#include - -ConVarManager g_ConVarManager; - -SH_DECL_HOOK5_void(IServerGameDLL, OnQueryCvarValueFinished, SH_NOATTRIB, 0, QueryCvarCookie_t, edict_t *, EQueryCvarValueStatus, const char *, const char *); -SH_DECL_HOOK5_void(IServerPluginCallbacks, OnQueryCvarValueFinished, SH_NOATTRIB, 0, QueryCvarCookie_t, edict_t *, EQueryCvarValueStatus, const char *, const char *); - -const ParamType CONVARCHANGE_PARAMS[] = {Param_Cell, Param_String, Param_String}; -typedef List ConVarList; -KTrie convar_cache; - -ConVarManager::ConVarManager() : m_ConVarType(0), m_bIsDLLQueryHooked(false), m_bIsVSPQueryHooked(false) -{ -} - -ConVarManager::~ConVarManager() -{ -} - -void ConVarManager::OnSourceModAllInitialized() -{ - /** - * Episode 2 has this function by default, but the older versions do not. - */ -#if !defined ORANGEBOX_BUILD - if (g_SMAPI->GetGameDLLVersion() >= 6) -#endif - { - SH_ADD_HOOK_MEMFUNC(IServerGameDLL, OnQueryCvarValueFinished, gamedll, this, &ConVarManager::OnQueryCvarValueFinished, false); - m_bIsDLLQueryHooked = true; - } - - HandleAccess sec; - - /* Set up access rights for the 'ConVar' handle type */ - sec.access[HandleAccess_Read] = 0; - sec.access[HandleAccess_Delete] = HANDLE_RESTRICT_IDENTITY | HANDLE_RESTRICT_OWNER; - sec.access[HandleAccess_Clone] = HANDLE_RESTRICT_IDENTITY | HANDLE_RESTRICT_OWNER; - - /* Create the 'ConVar' handle type */ - m_ConVarType = g_HandleSys.CreateType("ConVar", this, 0, NULL, &sec, g_pCoreIdent, NULL); - - /* Add the 'convars' option to the 'sm' console command */ - g_RootMenu.AddRootConsoleCommand("cvars", "View convars created by a plugin", this); -} - -void ConVarManager::OnSourceModShutdown() -{ - List::iterator iter = m_ConVars.begin(); - HandleSecurity sec(NULL, g_pCoreIdent); - - /* Iterate list of ConVarInfo structures, remove every one of them */ - while (iter != m_ConVars.end()) - { - ConVarInfo *pInfo = (*iter); - - iter = m_ConVars.erase(iter); - - g_HandleSys.FreeHandle(pInfo->handle, &sec); - if (pInfo->pChangeForward != NULL) - { - g_Forwards.ReleaseForward(pInfo->pChangeForward); - } - if (pInfo->sourceMod) - { - /* If we created it, we won't be tracking it, therefore it is - * safe to remove everything in one go. - */ - META_UNREGCVAR(pInfo->pVar); - delete [] pInfo->pVar->GetName(); - delete [] pInfo->pVar->GetHelpText(); - delete [] pInfo->pVar->GetDefault(); - delete pInfo->pVar; - } - else - { - /* If we didn't create it, we might be tracking it. Also, - * it could be unreadable. - */ - UntrackConCommandBase(pInfo->pVar, this); - } - - /* It's not safe to read the name here, so we simply delete the - * the info struct and clear the lookup cache at the end. - */ - delete pInfo; - } - convar_cache.clear(); - - /* Unhook things */ - if (m_bIsDLLQueryHooked) - { - SH_REMOVE_HOOK_MEMFUNC(IServerGameDLL, OnQueryCvarValueFinished, gamedll, this, &ConVarManager::OnQueryCvarValueFinished, false); - m_bIsDLLQueryHooked = false; - } - else if (m_bIsVSPQueryHooked) - { - SH_REMOVE_HOOK_MEMFUNC(IServerPluginCallbacks, OnQueryCvarValueFinished, vsp_interface, this, &ConVarManager::OnQueryCvarValueFinished, false); - m_bIsVSPQueryHooked = false; - } - - /* Remove the 'convars' option from the 'sm' console command */ - g_RootMenu.RemoveRootConsoleCommand("cvars", this); - - /* Remove the 'ConVar' handle type */ - g_HandleSys.RemoveType(m_ConVarType, g_pCoreIdent); -} - -/** - * Orange Box will never use this. - */ -void ConVarManager::OnSourceModVSPReceived() -{ - /** - * Don't bother if the DLL is already hooked. - */ - if (m_bIsDLLQueryHooked) - { - return; - } - - /* For later MM:S versions, use the updated API, since it's cleaner. */ -#if defined METAMOD_PLAPI_VERSION - int engine = g_SMAPI->GetSourceEngineBuild(); - if (engine == SOURCE_ENGINE_ORIGINAL || vsp_version < 2) - { - return; - } -#else - if (g_HL2.IsOriginalEngine() || vsp_version < 2) - { - return; - } -#endif - - SH_ADD_HOOK_MEMFUNC(IServerPluginCallbacks, OnQueryCvarValueFinished, vsp_interface, this, &ConVarManager::OnQueryCvarValueFinished, false); - m_bIsVSPQueryHooked = true; -} - -bool convar_cache_lookup(const char *name, ConVarInfo **pVar) -{ - ConVarInfo **pLookup = convar_cache.retrieve(name); - if (pLookup != NULL) - { - *pVar = *pLookup; - return true; - } - else - { - return false; - } -} - -void ConVarManager::OnUnlinkConCommandBase(ConCommandBase *pBase, const char *name, bool is_read_safe) -{ - /* Only check convars that have not been created by SourceMod's core */ - ConVarInfo *pInfo; - if (!convar_cache_lookup(name, &pInfo)) - { - return; - } - - HandleSecurity sec(NULL, g_pCoreIdent); - - /* Remove it from our cache */ - m_ConVars.remove(pInfo); - convar_cache.remove(name); - - /* Now make sure no plugins are referring to this pointer */ - IPluginIterator *pl_iter = g_PluginSys.GetPluginIterator(); - while (pl_iter->MorePlugins()) - { - IPlugin *pl = pl_iter->GetPlugin(); - - ConVarList *pConVarList; - if (pl->GetProperty("ConVarList", (void **)&pConVarList, true) - && pConVarList != NULL) - { - pConVarList->remove(pInfo->pVar); - } - - pl_iter->NextPlugin(); - } - - /* Free resources */ - g_HandleSys.FreeHandle(pInfo->handle, &sec); - delete pInfo; -} - -void ConVarManager::OnPluginUnloaded(IPlugin *plugin) -{ - ConVarList *pConVarList; - - /* If plugin has a convar list, free its memory */ - if (plugin->GetProperty("ConVarList", (void **)&pConVarList, true)) - { - delete pConVarList; - } -} - -void ConVarManager::OnHandleDestroy(HandleType_t type, void *object) -{ -} - -void ConVarManager::OnRootConsoleCommand(const char *cmdname, const CCommand &command) -{ - int argcount = command.ArgC(); - if (argcount >= 3) - { - /* Get plugin index that was passed */ - int id = atoi(command.Arg(2)); - - /* Get plugin object */ - CPlugin *plugin = g_PluginSys.GetPluginByOrder(id); - - if (!plugin) - { - g_RootMenu.ConsolePrint("[SM] Plugin index %d not found.", id); - return; - } - - /* Get plugin name */ - const sm_plugininfo_t *plinfo = plugin->GetPublicInfo(); - const char *plname = IS_STR_FILLED(plinfo->name) ? plinfo->name : plugin->GetFilename(); - - ConVarList *pConVarList; - ConVarList::iterator iter; - - /* If no convar list... */ - if (!plugin->GetProperty("ConVarList", (void **)&pConVarList)) - { - g_RootMenu.ConsolePrint("[SM] No convars found for: %s", plname); - return; - } - - g_RootMenu.ConsolePrint("[SM] Listing %d convars for: %s", pConVarList->size(), plname); - g_RootMenu.ConsolePrint(" %-32.31s %s", "[Name]", "[Value]"); - - /* Iterate convar list and display each one */ - for (iter = pConVarList->begin(); iter != pConVarList->end(); iter++) - { - const ConVar *pConVar = (*iter); - g_RootMenu.ConsolePrint(" %-32.31s %s", pConVar->GetName(), pConVar->GetString()); - } - - return; - } - - /* Display usage of subcommand */ - g_RootMenu.ConsolePrint("[SM] Usage: sm convars "); -} - -Handle_t ConVarManager::CreateConVar(IPluginContext *pContext, const char *name, const char *defaultVal, const char *description, int flags, bool hasMin, float min, bool hasMax, float max) -{ - ConVar *pConVar = NULL; - ConVarInfo *pInfo = NULL; - Handle_t hndl = 0; - - /* Find out if the convar exists already */ - pConVar = icvar->FindVar(name); - - /* If the convar already exists... */ - if (pConVar) - { - /* Add convar to plugin's list */ - AddConVarToPluginList(pContext, pConVar); - - /* First find out if we already have a handle to it */ - if (convar_cache_lookup(name, &pInfo)) - { - return pInfo->handle; - } - else - { - /* Create and initialize ConVarInfo structure */ - pInfo = new ConVarInfo(); - pInfo->sourceMod = false; - pInfo->pChangeForward = NULL; - pInfo->origCallback = pConVar->GetCallback(); - pInfo->pVar = pConVar; - - /* If we don't, then create a new handle from the convar */ - hndl = g_HandleSys.CreateHandle(m_ConVarType, pInfo, NULL, g_pCoreIdent, NULL); - if (hndl == BAD_HANDLE) - { - delete pInfo; - return BAD_HANDLE; - } - - pInfo->handle = hndl; - - /* Insert struct into caches */ - m_ConVars.push_back(pInfo); - convar_cache.insert(name, pInfo); - TrackConCommandBase(pConVar, this); - - return hndl; - } - } - - /* To prevent creating a convar that has the same name as a console command... ugh */ - ConCommandBase *pBase = icvar->GetCommands(); - - while (pBase) - { - if (pBase->IsCommand() && strcmp(pBase->GetName(), name) == 0) - { - return BAD_HANDLE; - } - - pBase = const_cast(pBase->GetNext()); - } - - /* Create and initialize ConVarInfo structure */ - pInfo = new ConVarInfo(); - pInfo->handle = hndl; - pInfo->sourceMod = true; - pInfo->pChangeForward = NULL; - pInfo->origCallback = NULL; - - /* Create a handle from the new convar */ - hndl = g_HandleSys.CreateHandle(m_ConVarType, pInfo, NULL, g_pCoreIdent, NULL); - if (hndl == BAD_HANDLE) - { - delete pInfo; - return BAD_HANDLE; - } - - pInfo->handle = hndl; - - /* Since an existing convar (or concmd with the same name) was not found , now we can finally create it */ - pConVar = new ConVar(sm_strdup(name), sm_strdup(defaultVal), flags, sm_strdup(description), hasMin, min, hasMax, max); - pInfo->pVar = pConVar; - - /* Add convar to plugin's list */ - AddConVarToPluginList(pContext, pConVar); - - /* Insert struct into caches */ - m_ConVars.push_back(pInfo); - convar_cache.insert(name, pInfo); - - return hndl; -} - -Handle_t ConVarManager::FindConVar(const char *name) -{ - ConVar *pConVar = NULL; - ConVarInfo *pInfo; - Handle_t hndl; - - /* Search for convar */ - pConVar = icvar->FindVar(name); - - /* If it doesn't exist, then return an invalid handle */ - if (!pConVar) - { - return BAD_HANDLE; - } - - /* At this point, the convar exists. So, find out if we already have a handle */ - if (convar_cache_lookup(name, &pInfo)) - { - return pInfo->handle; - } - - /* Create and initialize ConVarInfo structure */ - pInfo = new ConVarInfo(); - pInfo->sourceMod = false; - pInfo->pChangeForward = NULL; - pInfo->origCallback = pConVar->GetCallback(); - pInfo->pVar = pConVar; - - /* If we don't have a handle, then create a new one */ - hndl = g_HandleSys.CreateHandle(m_ConVarType, pInfo, NULL, g_pCoreIdent, NULL); - if (hndl == BAD_HANDLE) - { - delete pInfo; - return BAD_HANDLE; - } - - pInfo->handle = hndl; - - /* Insert struct into our caches */ - m_ConVars.push_back(pInfo); - convar_cache.insert(name, pInfo); - TrackConCommandBase(pConVar, this); - - return hndl; -} - -void ConVarManager::HookConVarChange(ConVar *pConVar, IPluginFunction *pFunction) -{ - ConVarInfo *pInfo; - IChangeableForward *pForward; - - /* Find the convar in the lookup trie */ - if (convar_cache_lookup(pConVar->GetName(), &pInfo)) - { - /* Get the forward */ - pForward = pInfo->pChangeForward; - - /* If forward does not exist, create it */ - if (!pForward) - { - pForward = g_Forwards.CreateForwardEx(NULL, ET_Ignore, 3, CONVARCHANGE_PARAMS); - pInfo->pChangeForward = pForward; - - /* Install our own callback */ - pConVar->InstallChangeCallback(OnConVarChanged); - } - - /* Add function to forward's list */ - pForward->AddFunction(pFunction); - } -} - -void ConVarManager::UnhookConVarChange(ConVar *pConVar, IPluginFunction *pFunction) -{ - ConVarInfo *pInfo; - IChangeableForward *pForward; - IPluginContext *pContext = pFunction->GetParentContext(); - - /* Find the convar in the lookup trie */ - if (convar_cache_lookup(pConVar->GetName(), &pInfo)) - { - /* Get the forward */ - pForward = pInfo->pChangeForward; - - /* If the forward doesn't exist, we can't unhook anything */ - if (!pForward) - { - pContext->ThrowNativeError("Convar \"%s\" has no active hook", pConVar->GetName()); - return; - } - - /* Remove the function from the forward's list */ - if (!pForward->RemoveFunction(pFunction)) - { - pContext->ThrowNativeError("Invalid hook callback specified for convar \"%s\"", pConVar->GetName()); - return; - } - - /* If the forward now has 0 functions in it... */ - if (pForward->GetFunctionCount() == 0) - { - /* Free this forward */ - g_Forwards.ReleaseForward(pForward); - pInfo->pChangeForward = NULL; - - /* Put back the original convar callback */ - pConVar->InstallChangeCallback(pInfo->origCallback); - } - } -} - -QueryCvarCookie_t ConVarManager::QueryClientConVar(edict_t *pPlayer, const char *name, IPluginFunction *pCallback, Handle_t hndl) -{ - QueryCvarCookie_t cookie; - - /* Call StartQueryCvarValue() in either the IVEngineServer or IServerPluginHelpers depending on situation */ - if (m_bIsDLLQueryHooked) - { - cookie = engine->StartQueryCvarValue(pPlayer, name); - } - else if (m_bIsVSPQueryHooked) - { - cookie = serverpluginhelpers->StartQueryCvarValue(pPlayer, name); - } - else - { - return InvalidQueryCvarCookie; - } - - ConVarQuery query = {cookie, pCallback, hndl}; - m_ConVarQueries.push_back(query); - - return cookie; -} - -void ConVarManager::AddConVarToPluginList(IPluginContext *pContext, const ConVar *pConVar) -{ - ConVarList *pConVarList; - ConVarList::iterator iter; - bool inserted = false; - const char *orig = pConVar->GetName(); - - IPlugin *plugin = g_PluginSys.FindPluginByContext(pContext->GetContext()); - - /* Check plugin for an existing convar list */ - if (!plugin->GetProperty("ConVarList", (void **)&pConVarList)) - { - pConVarList = new ConVarList(); - plugin->SetProperty("ConVarList", pConVarList); - } - else if (pConVarList->find(pConVar) != pConVarList->end()) - { - /* If convar is already in list, then don't add it */ - return; - } - - /* Insert convar into list which is sorted alphabetically */ - for (iter = pConVarList->begin(); iter != pConVarList->end(); iter++) - { - if (strcmp(orig, (*iter)->GetName()) < 0) - { - pConVarList->insert(iter, pConVar); - inserted = true; - break; - } - } - - if (!inserted) - { - pConVarList->push_back(pConVar); - } -} - -#if defined ORANGEBOX_BUILD -void ConVarManager::OnConVarChanged(IConVar *pIConVar, const char *oldValue, float flOldValue) -#else -void ConVarManager::OnConVarChanged(ConVar *pConVar, const char *oldValue) -#endif -{ - /* If the values are the same, exit early in order to not trigger callbacks */ -#if defined ORANGEBOX_BUILD - ConVar *pConVar = (ConVar *)pIConVar; -#endif - if (strcmp(pConVar->GetString(), oldValue) == 0) - { - return; - } - - ConVarInfo *pInfo; - - /* Find the convar in the lookup trie */ - if (!convar_cache_lookup(pConVar->GetName(), &pInfo)) - { - return; - } - - FnChangeCallback_t origCallback = pInfo->origCallback; - IChangeableForward *pForward = pInfo->pChangeForward; - - /* If there was a change callback installed previously, call it */ - if (origCallback) - { -#if defined ORANGEBOX_BUILD - origCallback(pConVar, oldValue, flOldValue); -#else - origCallback(pConVar, oldValue); -#endif - } - - /* Now call forwards in plugins that have hooked this */ - pForward->PushCell(pInfo->handle); - pForward->PushString(oldValue); - pForward->PushString(reinterpret_cast(pConVar)->GetString()); - pForward->Execute(NULL); -} - -bool ConVarManager::IsQueryingSupported() -{ - return (m_bIsDLLQueryHooked || m_bIsVSPQueryHooked); -} - -void ConVarManager::OnQueryCvarValueFinished(QueryCvarCookie_t cookie, edict_t *pPlayer, EQueryCvarValueStatus result, const char *cvarName, const char *cvarValue) -{ - IPluginFunction *pCallback = NULL; - cell_t value = 0; - List::iterator iter; - - for (iter = m_ConVarQueries.begin(); iter != m_ConVarQueries.end(); iter++) - { - ConVarQuery &query = (*iter); - if (query.cookie == cookie) - { - pCallback = query.pCallback; - value = query.value; - break; - } - } - - if (pCallback) - { - cell_t ret; - - pCallback->PushCell(cookie); - pCallback->PushCell(engine->IndexOfEdict(pPlayer)); - pCallback->PushCell(result); - pCallback->PushString(cvarName); - - if (result == eQueryCvarValueStatus_ValueIntact) - { - pCallback->PushString(cvarValue); - } - else - { - pCallback->PushString("\0"); - } - - pCallback->PushCell(value); - pCallback->Execute(&ret); - - m_ConVarQueries.erase(iter); - } -} - -HandleError ConVarManager::ReadConVarHandle(Handle_t hndl, ConVar **pVar) -{ - ConVarInfo *pInfo; - HandleError error; - - if ((error = g_HandleSys.ReadHandle(hndl, m_ConVarType, NULL, (void **)&pInfo)) != HandleError_None) - { - return error; - } - - if (pVar) - { - *pVar = pInfo->pVar; - } - - return error; -} - -static int s_YamagramState = 0; - -void _YamagramPrinterTwoPointOhOh(int yamagram) -{ - switch (yamagram) - { - case 0: - g_RootMenu.ConsolePrint("Answer the following questions correctly and Gaben may not eat you after all."); - g_RootMenu.ConsolePrint("You will be given one hint in the form of my patented yamagrams."); - g_RootMenu.ConsolePrint("Type sm_nana to see the last question."); - g_RootMenu.ConsolePrint("Type sm_nana to attempt an answer of the question."); - g_RootMenu.ConsolePrint("-------------------------------"); - _YamagramPrinterTwoPointOhOh(1); - return; - case 1: - g_RootMenu.ConsolePrint("Question Ichi (1)"); - g_RootMenu.ConsolePrint("One can turn into a cow by doing what action?"); - g_RootMenu.ConsolePrint("Hint: AGE SANS GRIT"); - break; - case 2: - g_RootMenu.ConsolePrint("Question Ni (2)"); - g_RootMenu.ConsolePrint("What kind of hat should you wear when using the Internet?"); - g_RootMenu.ConsolePrint("Hint: BRR MOOSE"); - break; - case 3: - g_RootMenu.ConsolePrint("Question San (3)"); - g_RootMenu.ConsolePrint("Who is the lead developer of SourceMod?"); - g_RootMenu.ConsolePrint("Hint: VEAL BANDANA DID RIP SOON"); - break; - case 4: - g_RootMenu.ConsolePrint("Question Yon (4)"); - g_RootMenu.ConsolePrint("A terrible translation of 'SVN Revision' to Japanese romaji might be ..."); - g_RootMenu.ConsolePrint("Hint: I TAKE IN AN AIR OK"); - break; - case 5: - g_RootMenu.ConsolePrint("Question Go (5)"); - g_RootMenu.ConsolePrint("What is a fundamental concept in the game of Go?"); - g_RootMenu.ConsolePrint("Hint: AD LADEN THIEF"); - break; - case 6: - g_RootMenu.ConsolePrint("Question Roku (6)"); - g_RootMenu.ConsolePrint("Why am I asking all these strange questions?"); - g_RootMenu.ConsolePrint("Hint: CHUBBY TITAN EATS EWE WAGE DATA"); - break; - case 7: - g_RootMenu.ConsolePrint("Question Nana (7)"); - g_RootMenu.ConsolePrint("What is my name?"); - g_RootMenu.ConsolePrint("Hint: AD MODE LAG US"); - break; - default: - break; - } - - s_YamagramState = yamagram; -} - -#if defined ORANGEBOX_BUILD -void _IntExt_CallYamagrams(const CCommand &cmd) -{ -#else -void _IntExt_CallYamagrams() -{ - CCommand cmd; -#endif - bool correct = false; - const char *arg = cmd.ArgS(); - - if (!arg || arg[0] == '\0') - { - _YamagramPrinterTwoPointOhOh(s_YamagramState); - return; - } - - switch (s_YamagramState) - { - case 1: - correct = !strcasecmp(arg, "eating grass"); - break; - case 2: - correct = !strcasecmp(arg, "sombrero"); - break; - case 3: - correct = !strcasecmp(arg, "david bailopan anderson"); - break; - case 4: - correct = !strcasecmp(arg, "kaitei no kairan"); - break; - case 5: - correct = !strcasecmp(arg, "life and death"); - break; - case 6: - correct = !strcasecmp(arg, "because gabe wanted it that way"); - if (correct) - { - g_RootMenu.ConsolePrint("Congratulations, you have answered 6 of my questions."); - g_RootMenu.ConsolePrint("However, I have one final question for you. It wouldn't be nana without it."); - g_RootMenu.ConsolePrint("-------------------------------"); - _YamagramPrinterTwoPointOhOh(7); - return; - } - break; - case 7: - correct = !strcasecmp(arg, "damaged soul"); - if (correct) - { - g_RootMenu.ConsolePrint("You don't know how lucky you are to still be alive!"); - g_RootMenu.ConsolePrint("Congratulations. You have answered all 7 questions correctly."); - g_RootMenu.ConsolePrint("The SourceMod Dev Team will be at your door with anti-Gaben grenades"); - g_RootMenu.ConsolePrint("within seconds. You will also be provided with a rocket launcher,"); - g_RootMenu.ConsolePrint("just in case Alfred decides to strike you with a blitzkrieg in retaliation."); - - s_YamagramState = 0; - return; - } - break; - default: - break; - } - - if (s_YamagramState > 0) - { - if (correct) - { - g_RootMenu.ConsolePrint("Correct! You are one step closer to avoiding the deadly jaws of Gaben."); - g_RootMenu.ConsolePrint("-------------------------------"); - s_YamagramState++; - } else { - g_RootMenu.ConsolePrint("Wrong! You better be more careful. Gaben may be at your door at any minute."); - return; - } - } - - _YamagramPrinterTwoPointOhOh(s_YamagramState); -} - -void _IntExt_EnableYamagrams() -{ - static ConCommand *pCmd = NULL; - if (!pCmd) - { - pCmd = new ConCommand("sm_nana", _IntExt_CallYamagrams, "Try these yamagrams!", FCVAR_GAMEDLL); - g_RootMenu.ConsolePrint("[SM] Warning: Gaben has been alerted of your actions. You may be eaten."); - } else { - g_RootMenu.ConsolePrint("[SM] Gaben has already been alerted of your actions..."); - } -} - -#if defined ORANGEBOX_BUILD -void _IntExt_OnHostnameChanged(IConVar *pConVar, const char *oldValue, float flOldValue) -#else -void _IntExt_OnHostnameChanged(ConVar *pConVar, char const *oldValue) -#endif -{ - if (strcmp(oldValue, "Good morning, DS-san.") == 0 - && strcmp(reinterpret_cast(pConVar)->GetString(), "Good night, talking desk lamp.") == 0) - { - _IntExt_EnableYamagrams(); - } -} diff --git a/core/ConVarManager.h b/core/ConVarManager.h deleted file mode 100644 index d9cfea24..00000000 --- a/core/ConVarManager.h +++ /dev/null @@ -1,154 +0,0 @@ -/** - * vim: set ts=4 : - * ============================================================================= - * SourceMod - * Copyright (C) 2004-2007 AlliedModders LLC. All rights reserved. - * ============================================================================= - * - * This program is free software; you can redistribute it and/or modify it under - * the terms of the GNU General Public License, version 3.0, as published by the - * Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more - * details. - * - * You should have received a copy of the GNU General Public License along with - * this program. If not, see . - * - * As a special exception, AlliedModders LLC gives you permission to link the - * code of this program (as well as its derivative works) to "Half-Life 2," the - * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software - * by the Valve Corporation. You must obey the GNU General Public License in - * all respects for all other code used. Additionally, AlliedModders LLC grants - * this exception to all derivative works. AlliedModders LLC defines further - * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007), - * or . - * - * Version: $Id$ - */ - -#ifndef _INCLUDE_SOURCEMOD_CONVARMANAGER_H_ -#define _INCLUDE_SOURCEMOD_CONVARMANAGER_H_ - -#include "sm_globals.h" -#include "sourcemm_api.h" -#include -#include -#include -#include -#include -#include -#include "concmd_cleaner.h" - -using namespace SourceHook; - -/** - * Holds SourceMod-specific information about a convar - */ -struct ConVarInfo -{ - Handle_t handle; /**< Handle to self */ - bool sourceMod; /**< Determines whether or not convar was created by a SourceMod plugin */ - IChangeableForward *pChangeForward; /**< Forward associated with convar */ - FnChangeCallback_t origCallback; /**< The original callback function */ - ConVar *pVar; /**< The actual convar */ -}; - -/** - * Holds information about a client convar query - */ -struct ConVarQuery -{ - QueryCvarCookie_t cookie; /**< Cookie that identifies query */ - IPluginFunction *pCallback; /**< Function that will be called when query is finished */ - cell_t value; /**< Optional value passed to query function */ -}; - -class ConVarManager : - public SMGlobalClass, - public IHandleTypeDispatch, - public IPluginsListener, - public IRootConsoleCommand, - public IConCommandTracker -{ -public: - ConVarManager(); - ~ConVarManager(); -public: // SMGlobalClass - void OnSourceModAllInitialized(); - void OnSourceModShutdown(); - void OnSourceModVSPReceived(); -public: // IHandleTypeDispatch - void OnHandleDestroy(HandleType_t type, void *object); -public: // IPluginsListener - void OnPluginUnloaded(IPlugin *plugin); -public: //IRootConsoleCommand - void OnRootConsoleCommand(const char *cmdname, const CCommand &command); -public: //IConCommandTracker - void OnUnlinkConCommandBase(ConCommandBase *pBase, const char *name, bool is_read_safe); -public: - /** - * Create a convar and return a handle to it. - */ - Handle_t CreateConVar(IPluginContext *pContext, const char *name, const char *defaultVal, - const char *description, int flags, bool hasMin, float min, bool hasMax, float max); - - /** - * Searches for a convar and returns a handle to it - */ - Handle_t FindConVar(const char* name); - - /** - * Add a function to call when the specified convar changes. - */ - void HookConVarChange(ConVar *pConVar, IPluginFunction *pFunction); - - /** - * Remove a function from the forward that will be called when the specified convar changes. - */ - void UnhookConVarChange(ConVar *pConVar, IPluginFunction *pFunction); - - /** - * Starts a query to find the value of a client convar. - */ - QueryCvarCookie_t QueryClientConVar(edict_t *pPlayer, const char *name, IPluginFunction *pCallback, - Handle_t hndl); - - bool IsQueryingSupported(); - - HandleError ReadConVarHandle(Handle_t hndl, ConVar **pVar); - -private: - /** - * Adds a convar to a plugin's list. - */ - static void AddConVarToPluginList(IPluginContext *pContext, const ConVar *pConVar); - - /** - * Static callback that Valve's ConVar object executes when the convar's value changes. - */ -#if defined ORANGEBOX_BUILD - static void OnConVarChanged(IConVar *pConVar, const char *oldValue, float flOldValue); -#else - static void OnConVarChanged(ConVar *pConVar, const char *oldValue); -#endif - - /** - * Callback for when StartQueryCvarValue() has finished. - */ - void OnQueryCvarValueFinished(QueryCvarCookie_t cookie, edict_t *pPlayer, EQueryCvarValueStatus result, - const char *cvarName, const char *cvarValue); -private: - HandleType_t m_ConVarType; - List m_ConVars; - List m_ConVarQueries; - bool m_bIsDLLQueryHooked; - bool m_bIsVSPQueryHooked; -}; - -extern ConVarManager g_ConVarManager; - -#endif // _INCLUDE_SOURCEMOD_CONVARMANAGER_H_ - diff --git a/core/CoreConfig.cpp b/core/CoreConfig.cpp deleted file mode 100644 index dab545bb..00000000 --- a/core/CoreConfig.cpp +++ /dev/null @@ -1,420 +0,0 @@ -/** - * vim: set ts=4 : - * ============================================================================= - * SourceMod - * Copyright (C) 2004-2007 AlliedModders LLC. All rights reserved. - * ============================================================================= - * - * This program is free software; you can redistribute it and/or modify it under - * the terms of the GNU General Public License, version 3.0, as published by the - * Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more - * details. - * - * You should have received a copy of the GNU General Public License along with - * this program. If not, see . - * - * As a special exception, AlliedModders LLC gives you permission to link the - * code of this program (as well as its derivative works) to "Half-Life 2," the - * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software - * by the Valve Corporation. You must obey the GNU General Public License in - * all respects for all other code used. Additionally, AlliedModders LLC grants - * this exception to all derivative works. AlliedModders LLC defines further - * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007), - * or . - * - * Version: $Id$ - */ - -#include -#include "CoreConfig.h" -#include "sourcemod.h" -#include "sourcemm_api.h" -#include "sm_srvcmds.h" -#include "sm_version.h" -#include "sm_stringutil.h" -#include "LibrarySys.h" -#include "Logger.h" -#include "PluginSys.h" -#include "ForwardSys.h" - -#ifdef PLATFORM_WINDOWS -ConVar sm_corecfgfile("sm_corecfgfile", "addons\\sourcemod\\configs\\core.cfg", 0, "SourceMod core configuration file"); -#elif defined PLATFORM_LINUX -ConVar sm_corecfgfile("sm_corecfgfile", "addons/sourcemod/configs/core.cfg", 0, "SourceMod core configuration file"); -#endif - -IForward *g_pOnServerCfg = NULL; -IForward *g_pOnConfigsExecuted = NULL; -CoreConfig g_CoreConfig; -bool g_bConfigsExecd = false; - -void CoreConfig::OnSourceModAllInitialized() -{ - g_RootMenu.AddRootConsoleCommand("config", "Set core configuration options", this); - g_pOnServerCfg = g_Forwards.CreateForward("OnServerCfg", ET_Ignore, 0, NULL); - g_pOnConfigsExecuted = g_Forwards.CreateForward("OnConfigsExecuted", ET_Ignore, 0, NULL); -} - -void CoreConfig::OnSourceModShutdown() -{ - g_RootMenu.RemoveRootConsoleCommand("config", this); - g_Forwards.ReleaseForward(g_pOnServerCfg); - g_Forwards.ReleaseForward(g_pOnConfigsExecuted); -} - -void CoreConfig::OnSourceModLevelChange(const char *mapName) -{ - g_bConfigsExecd = false; -} - -void CoreConfig::OnRootConsoleCommand(const char *cmdname, const CCommand &command) -{ - int argcount = command.ArgC(); - if (argcount >= 4) - { - const char *option = command.Arg(2); - const char *value = command.Arg(3); - - char error[255]; - - ConfigResult res = SetConfigOption(option, value, ConfigSource_Console, error, sizeof(error)); - - if (res == ConfigResult_Reject) - { - g_RootMenu.ConsolePrint("[SM] Could not set config option \"%s\" to \"%s\" (%s)", option, value, error); - } else if (res == ConfigResult_Ignore) { - g_RootMenu.ConsolePrint("[SM] No such config option \"%s\" exists.", option); - } else { - g_RootMenu.ConsolePrint("Config option \"%s\" successfully set to \"%s.\"", option, value); - } - - return; - } - - g_RootMenu.ConsolePrint("[SM] Usage: sm config