dedimania update

This commit is contained in:
kremsy 2014-02-23 15:28:53 +01:00 committed by Steffen Schröder
parent bcd8a9de67
commit dc248a69ed
4 changed files with 121 additions and 32 deletions

View File

@ -5,10 +5,6 @@ namespace ManiaControl\Server;
use ManiaControl\Callbacks\CallbackListener;
use ManiaControl\Callbacks\CallbackManager;
use ManiaControl\ManiaControl;
use ManiaControl\Players\Player;
use Maniaplanet\DedicatedServer\Structures\ServerOptions;
use Maniaplanet\DedicatedServer\Structures\SystemInfos;
use Maniaplanet\DedicatedServer\Structures\Version;
use Maniaplanet\DedicatedServer\Xmlrpc\Exception;
/**
@ -21,7 +17,7 @@ class Server implements CallbackListener {
/**
* Constants
*/
const TABLE_SERVERS = 'mc_servers';
const TABLE_SERVERS = 'mc_servers';
const CB_TEAM_MODE_CHANGED = 'ServerCallback.TeamModeChanged';
/**
@ -124,6 +120,29 @@ class Server implements CallbackListener {
return true;
}
/**
* Gets all Servers from the Database
*
* @return array
*/
public function getAllServers() {
$mysqli = $this->maniaControl->database->mysqli;
$query = "SELECT * FROM `" . self::TABLE_SERVERS . "`";
$result = $mysqli->query($query);
if (!$result) {
trigger_error($mysqli->error);
return array();
}
$servers = array();
while($row = $result->fetch_object()) {
array_push($servers, $row);
}
$result->close();
return $servers;
}
/**
* Handle OnInit Callback
*/

View File

@ -39,8 +39,7 @@ class Dedimania implements CallbackListener, TimerListener, Plugin {
const SETTING_WIDGET_WIDTH = 'Widget Width';
const SETTING_WIDGET_LINESCOUNT = 'Widget Displayed Lines Count';
const SETTING_WIDGET_LINEHEIGHT = 'Widget Line Height';
const SETTING_SERVER_LOGINS = 'Serverlogins, splitted by ;';
const SETTING_DEDIMANIA_CODES = 'Dedimania Codes, splitted by ;';
const SETTING_DEDIMANIA_CODE = 'Dedimania Code for ';
/**
* Private Properties
@ -60,8 +59,10 @@ class Dedimania implements CallbackListener, TimerListener, Plugin {
* @return mixed
*/
public static function prepare(ManiaControl $maniaControl) {
$maniaControl->settingManager->initSetting(get_class(), self::SETTING_SERVER_LOGINS, '');
$maniaControl->settingManager->initSetting(get_class(), self::SETTING_DEDIMANIA_CODES, '');
$servers = $maniaControl->server->getAllServers();
foreach($servers as $server) {
$maniaControl->settingManager->initSetting(get_class(), self::SETTING_DEDIMANIA_CODE . $server->login, '');
}
}
/**
@ -100,28 +101,9 @@ class Dedimania implements CallbackListener, TimerListener, Plugin {
$serverVersion = $this->maniaControl->client->getVersion();
$packMask = substr($this->maniaControl->server->titleId, 2);
$logins = $this->maniaControl->settingManager->getSetting($this, self::SETTING_SERVER_LOGINS);
$codes = $this->maniaControl->settingManager->getSetting($this, self::SETTING_DEDIMANIA_CODES);
if ($logins == '' || $codes == '') {
throw new \Exception("No Dedimania Data Specified, check the settings!");
}
$logins = explode(";", $logins);
$codes = explode(";", $codes);
$dedimaniaCode = "";
foreach($logins as $key => $login) {
if ($login == $serverInfo->login) {
if (!isset($codes[$key])) {
throw new \Exception("No Dedimania Code Specified, check the settings!");
}
$dedimaniaCode = $codes[$key];
}
}
$dedimaniaCode = $this->maniaControl->settingManager->getSetting($this, self::SETTING_DEDIMANIA_CODE . $serverInfo->login);
if ($dedimaniaCode == '') {
throw new \Exception("No Valid Serverlogin Specified, check the settings!");
throw new \Exception("No Dedimania Code Specified, check the settings!");
}
$this->dedimaniaData = new DedimaniaData($serverInfo->login, $dedimaniaCode, $serverInfo->path, $packMask, $serverVersion);

View File

@ -0,0 +1,88 @@
<?php
use ManiaControl\ManiaControl;
use ManiaControl\Plugins\Plugin;
/**
* Created by PhpStorm.
* User: Lukas
* Date: 23.02.14
* Time: 14:03
*/
class KarmaTest implements Plugin {
private $maniaControl = null;
/**
* Prepares the Plugin
*
* @param ManiaControl $maniaControl
* @return mixed
*/
public static function prepare(ManiaControl $maniaControl) {
// TODO: Implement prepare() method.
}
/**
* Load the plugin
*
* @param \ManiaControl\ManiaControl $maniaControl
* @return bool
*/
public function load(ManiaControl $maniaControl) {
$this->maniaControl = $maniaControl;
$serverLogin = $this->maniaControl->server->login;
}
/**
* Unload the plugin and its resources
*/
public function unload() {
unset($this->maniaControl);
}
/**
* Get plugin id
*
* @return int
*/
public static function getId() {
// TODO: Implement getId() method.
}
/**
* Get Plugin Name
*
* @return string
*/
public static function getName() {
return "karmatest";
}
/**
* Get Plugin Version
*
* @return float
*/
public static function getVersion() {
// TODO: Implement getVersion() method.
}
/**
* Get Plugin Author
*
* @return string
*/
public static function getAuthor() {
// TODO: Implement getAuthor() method.
}
/**
* Get Plugin Description
*
* @return string
*/
public static function getDescription() {
// TODO: Implement getDescription() method.
}
}