Last active
December 28, 2015 02:59
-
-
Save w1lla/7431671 to your computer and use it in GitHub Desktop.
Spectator Plugin pre alpha stuff
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
Name: Willem 'W1lla' van den Munckhof | |
Date: 11/11/2013 | |
Project Name: ESWC Elite Statistics | |
What to do: | |
/** | |
* --------------------------------------------------------------------- | |
* This program is free software: you can redistribute it and/or modify | |
* it under the terms of the GNU General Public License as published by | |
* the Free Software Foundation, either version 3 of the License, or | |
* (at your option) any later version. | |
* | |
* 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 <http://www.gnu.org/licenses/>. | |
* --------------------------------------------------------------------- | |
* You are allowed to change things or use this in other projects, as | |
* long as you leave the information at the top (name, date, version, | |
* website, package, author, copyright) and publish the code under | |
* the GNU General Public License version 3. | |
* --------------------------------------------------------------------- | |
*/ | |
namespace ManiaLivePlugins\Shootmania\Spectator; | |
/** @var integer */ | |
protected $MatchNumber = false; | |
/** @var integer */ | |
protected $TurnNumber; | |
protected $Mapscore_blue; | |
protected $Mapscore_red; | |
protected $WarmUpAllReady; | |
protected $MapNumber; | |
protected $BlueScoreMatch; | |
protected $RedScoreMatch; | |
protected $BlueMapScore; | |
protected $RedMapScore; | |
/** @var Log */ | |
private $logger; | |
/** @var $playerIDs[$login] = number */ | |
private $playerIDs = array(); | |
function onInit() { | |
$this->setVersion('0.4.0'); | |
$this->logger = new Log($this->storage->serverLogin); | |
} | |
function onLoad() { | |
$this->enableDedicatedEvents(); | |
} | |
function onReady() { | |
foreach ($this->storage->spectators as $player) { | |
Console::println('[' . date('H:i:s') . '] [Shootmania] Spectator Elite Core v' . $this->getVersion()); | |
$this->connection->chatSendServerMessage('$fff» $fa0Welcome, this server uses $fff [Shootmania] Elite Spectator Stats$fa0!', $player->login); | |
} | |
public function onModeScriptCallback($event, $json) { | |
$this->logger->Callbacks($event); | |
$this->logger->Callbacks($json); | |
switch ($event) { | |
case 'BeginTurn': | |
$this->onXmlRpcEliteSpectatorBeginTurn(new JsonCallbacks\BeginTurn($json)); | |
break; | |
} | |
} | |
function onXmlRpcEliteBeginTurn(JsonCallbacks\BeginTurn $content) { | |
// Players and stuff | |
if ($content->attackingPlayer == NULL){ | |
} | |
else | |
{ | |
$AtkPlayer = $this->getPlayerId($content->attackingPlayer->login); | |
$queryCurrentMatchAtkPlayerStats = "SELECT SUM( player_maps.atkrounds ) AS atkrounds, SUM( player_maps.atkSucces ) AS atkSucces, ( | |
SUM( player_maps.atkSucces ) / SUM( player_maps.atkrounds ) *100 | |
) AS AtkRatio | |
FROM player_maps | |
JOIN matches ON player_maps.match_id = matches.id | |
WHERE player_maps.player_id = " . $this->db->quote($AtkPlayer) . " | |
AND player_maps.match_id = " . $this->db->quote($this->MatchNumber) . ""; | |
$this->logger->Debug($queryCurrentMatchAtkPlayerStats); | |
$this->db->execute($queryCurrentMatchAtkPlayerStats); | |
$AtkRatio = $this->db->execute($queryCurrentMatchAtkPlayerStats)->fetchObject()->AtkRatio; | |
$AtkRounds = $this->db->execute($queryCurrentMatchAtkPlayerStats)->fetchObject()->atkrounds; | |
$AtkSucces = $this->db->execute($queryCurrentMatchAtkPlayerStats)->fetchObject()->atkSucces; | |
} | |
/** get cached value of database player id */ | |
function getPlayerId($login) { | |
if (isset($this->playerIDs[$login])) { | |
return $this->playerIDs[$login]; | |
} else { | |
$q = "SELECT id FROM `players` WHERE `login` = " . $this->db->quote($login) . ""; | |
$this->logger->Debug($q); | |
return $this->db->execute($q)->fetchObject()->id; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment