diff --git a/docs/protected/data/guide/2.0/api.txt b/docs/protected/data/guide/2.0/api.txt deleted file mode 100644 index 12a4618..0000000 --- a/docs/protected/data/guide/2.0/api.txt +++ /dev/null @@ -1,38 +0,0 @@ -# API - -To access SourceBans functionality in an external PHP script, simply include `api.php`. -~~~ -[php] -include '/path/to/sourcebans/api.php'; - -// Add web group -$group = new SBGroup; -$group->name = 'Owner'; -$group->permissions = array('OWNER'); -if(!$group->save()) -{ - echo CHtml::errorSummary($group); -} - -// Add server group -$server_group = new SBServerGroup; -$server_group->name = 'Root'; -$server_group->flags = SM_ROOT; -$server_group->immunity = 100; -if(!$server_group->save()) -{ - echo CHtml::errorSummary($server_group); -} - -if(!$group->hasErrors() && !$server_group->hasErrors()) -{ - // Add admin - $admin = new SBAdmin; - $admin->name = 'Demo'; - $admin->auth = SBAdmin::STEAM_AUTH; - $admin->identity = 'STEAM_0:1:2'; - $admin->group = $group; - $admin->server_groups = array($server_group); - $admin->save(); -} -~~~ \ No newline at end of file diff --git a/docs/protected/data/guide/2.0/game-plugins.txt b/docs/protected/data/guide/2.0/game-plugins.txt deleted file mode 100644 index 56f6ad8..0000000 --- a/docs/protected/data/guide/2.0/game-plugins.txt +++ /dev/null @@ -1,84 +0,0 @@ -~~~ -[sourcepawn] -/** - * When connected to SourceBans database - * - * @param database The database handle - * @noreturn - */ -forward SB_OnConnect(Handle:database); - -/** - * When SourceBans config is reloaded - * - * @noreturn - */ -forward SB_OnReload(); - - -/** - * Connect to SourceBans database - * - * @noreturn - */ -native SB_Connect(); - -/** - * Escapes a database string for literal insertion - * - * @param string String to quote. - * @param buffer Buffer to store quoted string in. - * @param maxlength Maximum length of the buffer. - * @param written Optionally returns the number of bytes written. - * @return True on success, false if buffer is not big enough. - * The buffer must be at least 2*strlen(string)+1. - * @error Invalid database or statement Handle. - */ -native bool:SB_Escape(const String:string[], String:buffer[], maxlength, &written = 0); - -/** - * Execute query on SourceBans database and ignore result set - * - * @noreturn - */ -native SB_Execute(const String:query[], DBPriority:prio = DBPrio_Normal); - -/** - * Get string value from SourceBans config - * - * @param key The key of the value to retrieve - * @param buffer The string buffer to store the value in - * @param maxlength The max length of the string buffer - * @noreturn - */ -native SB_GetConfigString(const String:key[], String:buffer[], maxlength); - -/** - * Get value from SourceBans config - * - * @param key The key of the value to retrieve - * @return value The value - */ -native SB_GetConfigValue(const String:key[]); - -/** - * Initialize third party SourceBans plugin in case it was late loaded - * - * @noreturn - */ -native SB_Init(); - -/** - * Query SourceBans database - * - * @noreturn - */ -native SB_Query(SQLTCallback:callback, const String:query[], any:data = 0, DBPriority:prio = DBPrio_Normal); - -/** - * Reload SourceBans config - * - * @noreturn - */ -native SB_Reload(); -~~~ \ No newline at end of file diff --git a/docs/protected/data/guide/2.0/keyvalues.txt b/docs/protected/data/guide/2.0/keyvalues.txt deleted file mode 100644 index 1173fbd..0000000 --- a/docs/protected/data/guide/2.0/keyvalues.txt +++ /dev/null @@ -1,66 +0,0 @@ -# KeyValues - -KeyValues or VDF (Valve Data Format) files consist of a root node and any number of sub-keys or sub-sections. -For example, a file might look like this: -~~~ -"MyFile" -{ - "STEAM_0:0:7" - { - "name" "crab" - } -} -~~~ -We can use the [KeyValues] and [SMCParser] classes to handle these files. - -## KeyValues - -Let's take our MyFile example from above. How could we retrieve the name "crab" given the Steam ID? -~~~ -[php] -$kv = new KeyValues('MyFile'); -$kv->load('myfile.txt'); - -echo $kv['STEAM_0:0:7']['name']; // will output "crab" -~~~ -The [load()|KeyValues::load] method also accepts a KeyValues string. - -To create the MyFile example from a PHP array, pass the array to the constructor: -~~~ -[php] -$kv = new KeyValues('MyFile', array( - 'STEAM_0:0:7' => array( - 'name' => 'crab', - ), -)); -$kv->save('myfile.txt'); -~~~ - -## SMC Parser - -The SMC (SourceMod Config) parser differs from KeyValues in that it's event-based. -Instead of loading the entire structure into memory, it calls listener methods for each section and key/value pair. -Return `false` in any of the methods to stop the rest of the file from being parsed. -Examples of SMC files are *admins.cfg* and *admin_groups.cfg*. - -The following example will output the name of each section, followed by each key and their value: -~~~ -[php] -class AdminsListener implements ISMCListener -{ - public function NewSection($name) - { - echo $name, "\n"; - } - - public function KeyValue($key, $value) - { - echo $key, ': ', $value, "\n"; - } - - public function EndSection() {} -} - -$listener = new AdminsListener; -SMCParser::parse('admins.cfg', $listener); -~~~ \ No newline at end of file diff --git a/docs/protected/data/guide/2.0/servers.txt b/docs/protected/data/guide/2.0/servers.txt deleted file mode 100644 index 90e0ad5..0000000 --- a/docs/protected/data/guide/2.0/servers.txt +++ /dev/null @@ -1,34 +0,0 @@ -# Servers - -## Server queries - -To retrieve info such as the hostname of the server and the map currently playing, -as well as players and rules (public console variables and their values), -we can use the [ServerQuery] class: -~~~ -[php] -$server = SBServer::model()->findByPk(1); -$query = new ServerQuery($server->ip, $server->port); - -print_r($query->getInfo()); -print_r($query->getPlayers()); -print_r($query->getRules()); -~~~ - -## RCON - -Additionally, we can use the [ServerRcon] class to execute RCON commands: -~~~ -[php] -// Find all Team Fortress 2 servers -$servers = SBServer::model()->with('game')->findAll('game.folder = "tf"'); - -foreach($servers as $server) -{ - $rcon = new ServerRcon($server->ip, $server->port, $server->rcon); - if(!$rcon->auth()) - continue; - - echo $rcon->execute('sm plugins list'), "\n"; -} -~~~ \ No newline at end of file diff --git a/docs/protected/data/guide/2.0/steam.txt b/docs/protected/data/guide/2.0/steam.txt deleted file mode 100644 index 7d0f708..0000000 --- a/docs/protected/data/guide/2.0/steam.txt +++ /dev/null @@ -1,80 +0,0 @@ -# Steam API - -> Note: The Steam API is fairly slow. Please consider caching the data for at least a minute. - -To access the Steam Community Data and Web API, we can use the [SteamProfile], [SteamGroup] and [SteamGame] classes. - -> Note: Some of the functionality provided in these classes requires a Steam Web API Key. Since each user must register -> their own API key, make sure to warn the user that your code requires an API key, or make that functionality optional. - -When working with Steam Community IDs, note that not all versions of PHP support these large numbers. -To be safe, pass them as strings, as shown in the first example. - -## Steam Profile - -To retrieve a player's Steam profile, pass their Steam Community ID or custom URL to the constructor: -~~~ -[php] -$profile = new SteamProfile('76561197990304788'); - -echo $profile->steamID; // will output "Tsunami" - -foreach($profile->getFriends() as $friend) -{ - echo $friend['steamid'], "\n"; -} -~~~ -This information is accessible for admins and bans through [SBAdmin::community] and [SBBan::community]. - -## Steam Group - -The same method as above applies to Steam groups: -~~~ -[php] -$group = new SteamGroup('GameConnect'); - -echo $group->headline; // will output "GameConnect - Serious Gaming" - -foreach($group->members as $steamid) -{ - echo $steamid, "\n"; -} -~~~ - -## Steam Game - -Lastly, to retrieve information about a game and its news on Steam: -~~~ -[php] -$game = new SteamGame(440); -$schema = $game->getSchema(); - -echo $schema['gameName']; // will output "Team Fortress 2" - -foreach($game->getNews(5, 500) as $news) -{ - echo $news['title'], "\n"; -} -~~~ - -**This snippet doesn't belong here, but I didn't feel like throwing it away.** -It retrieves the Steam Community name of all the members of the GameConnect group. -~~~ -[php] -$group = new SteamGroup('GameConnect'); -$members = $group->members; - -do -{ - // SteamProfile::getSummaries is limited to 100 Steam IDs, - // so repeatedly remove the first 100 until the array is empty. - $steamids = array_splice($members, 0, 100); - $profiles = SteamProfile::getSummaries($steamids); - - foreach($profiles as $profile) - { - echo $profile['personaname'], "\n"; - } -} -while(!empty($members)); -~~~ \ No newline at end of file diff --git a/docs/protected/data/guide/2.0/web-plugins.txt b/docs/protected/data/guide/2.0/web-plugins.txt deleted file mode 100644 index 90c9c67..0000000 --- a/docs/protected/data/guide/2.0/web-plugins.txt +++ /dev/null @@ -1,197 +0,0 @@ -~~~ -[php] -class DemoPlugin extends SBPlugin -{ - /** - * @var boolean whether the plugin can be disabled. - * You may set this to false when the plugin does not provide any web functionality, - * for example if it simply provides a page to configure a game plugins' settings. - * This property will be ignored if the plugin does not have an installation procedure. - * @see canDisable() - */ - public $allowDisable = true; - - - /** - * Returns the name of this SourceBans plugin - * - * @return string the name of this SourceBans plugin - */ - public function getName() - { - return 'your_plugin_name'; - } - - /** - * Returns the description of this SourceBans plugin - * - * @return string the description of this SourceBans plugin - */ - public function getDescription() - { - return 'your_plugin_description'; - } - - /** - * Returns the author of this SourceBans plugin - * - * @return string the author of this SourceBans plugin - */ - public function getAuthor() - { - return 'your_name'; - } - - /** - * Returns the version of this SourceBans plugin - * - * @return string the version of this SourceBans plugin - */ - public function getVersion() - { - return '1.0'; - } - - /** - * Returns the URL of this SourceBans plugin - * - * @return string the URL of this SourceBans plugin - */ - public function getUrl() - { - return 'your_url'; - } - - /** - * This method is invoked when installing the plugin. - * - * @return boolean Whether the installation was successful - */ - public function runInstall() - { - $transaction = Yii::app()->db->beginTransaction(); - - try - { - Yii::app()->db->createCommand()->createTable('your_table', array( - 'id' => 'pk', - 'name' => 'string', - ), 'ENGINE=InnoDB DEFAULT CHARSET=utf8'); - - $transaction->commit(); - return true; - } - catch(Exception $e) - { - $transaction->rollback(); - return false; - } - } - - /** - * This method is invoked right before the settings action is to be executed (after all possible filters.) - * You may override this method to do last-minute preparation for the action. - */ - public function runSettings() - { - Yii::import($this->getPathAlias('models.*')); - - $assetsUrl = Yii::app()->assetManager->publish($this->getPath('assets')); - Yii::app()->clientScript->registerCssFile($assetsUrl . '/css/your_style.css'); - Yii::app()->clientScript->registerScriptFile($assetsUrl . '/js/your_script.js'); - - $admins = SBAdmin::model()->findAll(array('order' => 'name')); - - return array( - 'admins' => $admins, - ); - } - - /** - * This method is invoked when uninstalling the plugin. - * - * @return boolean Whether the uninstallation was successful - */ - public function runUninstall() - { - $transaction = Yii::app()->db->beginTransaction(); - - try - { - Yii::app()->db->createCommand()->dropTable('your_table'); - - $transaction->commit(); - return true; - } - catch(Exception $e) - { - $transaction->rollback(); - return false; - } - } - - /** - * Raised right BEFORE the application processes the request. - * @param CEvent $event the event parameter - */ - public function onBeginRequest($event) {} - - /** - * Raised right AFTER the application processes the request. - * @param CEvent $event the event parameter - */ - public function onEndRequest($event) {} - - /** - * This method is invoked right before an action is to be executed (after all possible filters.) - * You may override this method to do last-minute preparation for the action. - * @param CAction $action the action to be executed. - */ - public function onBeforeAction($action) {} - - /** - * This method is invoked at the beginning of {@link CController::render()}. - * You may override this method to do some preprocessing when rendering a view. - * @param string $view the view to be rendered - */ - public function onBeforeRender($view) {} - - /** - * This method is invoked right after an action is executed. - * You may override this method to do some postprocessing for the action. - * @param CAction $action the action just executed. - */ - public function onAfterAction($action) {} - - /** - * This method is invoked after the specified is rendered by calling {@link CController::render()}. - * Note that this method is invoked BEFORE {@link CController::processOutput()}. - * You may override this method to do some postprocessing for the view rendering. - * @param string $view the view that has been rendered - * @param string $output the rendering result of the view. Note that this parameter is passed - * as a reference. That means you can modify it within this method. - */ - public function onAfterRender($view, &$output) {} - - public function onAddAdmin(SBAdmin $admin) {} - public function onAddBan(SBBan $ban) {} - public function onAddGame(SBGame $game) {} - public function onAddServer(SBServer $server) {} - public function onAddServerGroup(SBServerGroup $group) {} - public function onAddWebGroup(SBGroup $group) {} - - public function onDeleteAdmin(SBAdmin $admin) {} - public function onDeleteBan(SBBan $ban) {} - public function onDeleteGame(SBGame $game) {} - public function onDeleteServer(SBServer $server) {} - public function onDeleteServerGroup(SBServerGroup $group) {} - public function onDeleteWebGroup(SBGroup $group) {} - - public function onEditAdmin(SBAdmin $admin) {} - public function onEditBan(SBBan $ban) {} - public function onEditGame(SBGame $game) {} - public function onEditServer(SBServer $server) {} - public function onEditServerGroup(SBServerGroup $group) {} - public function onEditWebGroup(SBGroup $group) {} -} -~~~ \ No newline at end of file diff --git a/game/addons/sourcemod/plugins/sb_admins.smx b/game/addons/sourcemod/plugins/sb_admins.smx index b322d36..e875827 100644 Binary files a/game/addons/sourcemod/plugins/sb_admins.smx and b/game/addons/sourcemod/plugins/sb_admins.smx differ diff --git a/game/addons/sourcemod/scripting/sb_admins.sp b/game/addons/sourcemod/scripting/sb_admins.sp index 1456a96..4106f1e 100644 --- a/game/addons/sourcemod/scripting/sb_admins.sp +++ b/game/addons/sourcemod/scripting/sb_admins.sp @@ -1191,7 +1191,7 @@ stock SB_FetchAdmin(iClient) // Construct the query using the information the client gave us. decl String:sCondition[1024] = "", String:sEscapedName[MAX_NAME_LENGTH * 2 + 1], String:sQuery[1024]; if(g_bRequireSiteLogin) - StrCat(sCondition, sizeof(sCondition), " AND ad.lastvisit IS NOT NULL"); + StrCat(sCondition, sizeof(sCondition), " AND ad.login_time IS NOT NULL"); SB_Escape(sName, sEscapedName, sizeof(sEscapedName)); Format(sQuery, sizeof(sQuery), "SELECT ad.id, ad.name, ad.auth, ad.identity, ad.server_password, COUNT(ag.group_id) \ diff --git a/web/application/controllers/PluginsController.php b/web/application/controllers/PluginsController.php index e10bcff..3ed6e5b 100644 --- a/web/application/controllers/PluginsController.php +++ b/web/application/controllers/PluginsController.php @@ -59,7 +59,7 @@ public function actionEnable($id) public function actionInstall($id) { $plugin=$this->loadModel($id); - $result=$plugin->runInstall(); + $result=$plugin->runInstall()!==false; if($result) { @@ -98,7 +98,7 @@ public function actionSettings($id) public function actionUninstall($id) { $plugin=$this->loadModel($id); - $result=$plugin->runUninstall(); + $result=$plugin->runUninstall()!==false; if($result) { diff --git a/web/application/models/SBPlugin.php b/web/application/models/SBPlugin.php index 3cb13c0..77f72d8 100644 --- a/web/application/models/SBPlugin.php +++ b/web/application/models/SBPlugin.php @@ -162,7 +162,13 @@ public function canDisable() return !$this->hasInstall(); } - + + /** + * Finds a single plugin with the specified unique identifier. + * + * @param string $id the unique identifier + * @return SBPlugin the plugin found. Null if none is found. + */ public function findById($id) { static $_plugins; @@ -171,7 +177,10 @@ public function findById($id) $_plugins = SBPlugin::model()->findAll(array('index' => 'id')); } - return $_plugins[$id]; + if(isset($_plugins[$id])) + return $_plugins[$id]; + + return null; } public function getAction() @@ -185,6 +194,11 @@ public function getAction() return $this->hasInstall() ? 'Install' : 'Enable'; } + /** + * Returns the unique identifier for the plugin. + * + * @return string the unique identifier for the application. + */ public function getId() { return strtok($this->class, '.');