Created
January 9, 2017 20:41
-
-
Save Bueddl/1bb367c09cf933155f6a7822cb705971 to your computer and use it in GitHub Desktop.
XAseco Plugin to Sync Blacklist files across multiple gameservers
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 | |
/* vim: set noexpandtab tabstop=2 softtabstop=2 shiftwidth=2: */ | |
/** | |
* Sync servers plugin. | |
* Synchronizes black lists accross servers upon each round. | |
* Created by Bueddl | |
* | |
* Dependencies: none | |
*/ | |
Aseco::registerEvent('onPlayerConnect', 'ss_handle_player_connect'); | |
class ss_plugin_status | |
{ | |
private static $_instance = null; | |
private $_aseco; | |
private $_checksum = null; | |
private $_filename = 'blacklist.txt'; | |
public function __construct($aseco) | |
{ | |
$this->_aseco = $aseco; | |
} | |
public function hasChecksum() | |
{ | |
return !is_null($this->_checksum); | |
} | |
public function getChecksum() | |
{ | |
return $this->_checksum; | |
} | |
public function setChecksum($checksum) | |
{ | |
$this->_checksum = $checksum; | |
} | |
public function reloadBlacklist() | |
{ | |
$filepath = '/var/gameserver/data/app/TrackmaniaForever/GameData/Config/' . $this->_filename; | |
$checksum = md5_file($filepath); | |
if ($this->hasChecksum() && $checksum == $this->getChecksum()) | |
return false; | |
$this->log('Blacklist outdated, reloading (md5=' . $checksum . ')'); | |
$this->_aseco->client->query('LoadBlackList', $this->_filename); | |
$this->setChecksum($checksum); | |
return true; | |
} | |
public function isPlayerBlacklisted($player) | |
{ | |
for ($idx = 0; ; $idx += 300) | |
{ | |
$this->_aseco->client->query('GetBlackList', 300, $idx); | |
$players = $this->_aseco->client->getResponse(); | |
foreach ($players as $entry) | |
{ | |
if ($entry['Login'] == $player->login) | |
return true; | |
} | |
if (count($players) < 300) | |
break; | |
} | |
return false; | |
} | |
private function log($message) | |
{ | |
$this->_aseco->console($message); | |
} | |
public static function getInstance($aseco) | |
{ | |
if (is_null(self::$_instance)) | |
self::$_instance = new ss_plugin_status($aseco); | |
return self::$_instance; | |
} | |
} | |
function ss_handle_player_connect($aseco, $player) | |
{ | |
$plugin = ss_plugin_status::getInstance($aseco); | |
if ($plugin->reloadBlacklist()) | |
{ | |
if ($plugin->isPlayerBlacklisted($player)) | |
{ | |
$aseco->console('[!!!] Player is blacklisted!'); | |
$aseco->client->query('Kick', $player->login, 'You are blacklisted. Bye bye!'); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment