Code: Select all
<?php
/* Xaseco Plugin Showinfo v1.0 by kevlarsoft
* Inlcudes code from Flo and AssemblerManiac (Aseco/Rasp 2) , from Basti 504 (Plugin Collectin)
* and from FuFi (FuFi Widgets)
* Display next track info, local records, local ranks and karma vote, during intermission
*
*
* Currently used ManiaLink id's and action's:
* id= "201": Local records
* "202": Next track info
* "203": Local ranks
* "204": Karma Vote
* action= "11111": Karma vote good
* "22222": Karma vote bad
* "33333": Karma vote undiceded
*/
//dummy plugin class for XAseco
if (!class_exists('PluginShowInfo')){
class PluginShowInfo{
var $author, $version, $description, $Aseco, $dependencies;
function setAuthor($auth){
$this->author = $auth;
}
function setVersion($version){
$this->version = $version;
}
function setDescription($description){
$this->description = $description;
}
}
}
class ShowInfo extends PluginShowInfo {
function onEndRace(){
$challenge = $this->Aseco->server->challenge->name;
foreach($this->Aseco->server->players->player_list as $player) {
$query = 'SELECT Id FROM players WHERE Login=' . quotedString($player->login);
$res = mysql_query($query);
if (mysql_num_rows($res) > 0){
$row = mysql_fetch_row($res);
$pid = $row[0];
}
else{
$this->Aseco->console_text('no player!');
return;
}
mysql_free_result($res);
$popwin = true;
$query2 = 'SELECT Id, Score FROM rs_karma WHERE PlayerId=' . $pid . ' AND ChallengeId=' . $this->Aseco->server->challenge->id;
$res2 = mysql_query($query2);
if (mysql_num_rows($res2) > 0){
$popwin = false;
}
mysql_free_result($res2);
if ( $popwin ){
$xmlheader = "<?xml version='1.0' encoding='utf-8' ?>
<manialinks><custom_ui>
<notice visible='true'/>
<challenge_info visible='false'/>
<net_infos visible='true'/>
<chat visible='true'/>
<checkpoint_list visible='true'/>
<round_scores visible='true'/>
<scoretable visible='true'/>
<global visible='true'/>
</custom_ui>
<manialink posx='0.9' posy='-0.39' id='204'>
<type>default</type>
<format textsize='2' textcolor='000f' />
<background bgcolor='999F' bgborderx='0.01' bgbordery='0.01'/>";
$xmlfooter = "</manialink></manialinks>";
$content = $xmlheader;
$content .= "<line><cell><text textcolor='ee0'>How did you like \$i'" . htmlspecialchars($this->stripFormatting($challenge)). "'\$i ?</text></cell>";
$content .= "<cell><text textcolor='0e0' halign='center' action='11111'> Good</text></cell>
<cell><text textcolor='e00' halign='center' action='22222'> Bad</text></cell>
<cell><text textcolor='333' halign='center' action='33333'> Undecided</text></cell></line>";
$content.= $xmlfooter;
//$this->Aseco->console_text($content);
$this->sendMLtoLogin($player->login, $content);
}
}
} // onEndRace
function showRecords(){ //show server ranking
//Number of records displayed
$NumberRecords = 25;
$xmlheader = "<?xml version='1.0' encoding='utf-8' ?>
<manialinks><custom_ui>
<notice visible='true'/>
<challenge_info visible='false'/>
<net_infos visible='true'/>
<chat visible='true'/>
<checkpoint_list visible='true'/>
<round_scores visible='true'/>
<scoretable visible='true'/>
<global visible='true'/>
</custom_ui>
<manialink posx='-0.63' posy='0.27' id='201'>
<type>default</type>
<format textsize='1' textcolor='000f' />
<background bgcolor='000F' bgborderx='0' bgbordery='0'/>";
$xmlfooter = "</manialink></manialinks>";
$content = $xmlheader;
$leftcell = "<cell width='.03' bgcolor='000F'><text textcolor='ddd' halign='center'>";
$timecell = "<cell width='.1' bgcolor='000F'><text textcolor='8af' halign='center'>";
$rightcell = "<cell width='0.28' bgcolor='000F'><text textcolor='8af' halign='left'>";
$content .= "<line><cell bgcolor='888F' width='.37'><text textcolor='FF0' halign='center'>Current Track top$NumberRecords records</text></cell></line>";
for ($i = 0; $i < $NumberRecords; $i++)
{
$cur_record = $this->Aseco->server->records->getRecord($i);
// as long as score is not 0 ...
if ($cur_record->score == 0) break;
// format record score for displaying ...
if ($this->Aseco->server->gameinfo->getMode() == 'Stunts') {
$record_score = $cur_record->score;
}
else{
$record_score = formatTime($cur_record->score);
}
$content .= "<line height='.03'>". $leftcell . ($i + 1) . '.</text></cell>';
$content .= $timecell . $record_score . '</text></cell>';
$nickname = str_replace("\$w", '', $cur_record->player->nickname);
// original $content .= $rightcell . htmlspecialchars($nickname) . '</text></cell></line>' . CRLF;
$content .= $rightcell . htmlspecialchars($this->getValidUTF8String($nickname)) . '</text></cell></line>' . CRLF;
}
$content.= $xmlfooter;
foreach($this->Aseco->server->players->player_list as $pl){
$this->sendMLtoLogin($pl->login, $content);
}
} // showRecords
function showTrackInfo(){ //show next track info
// get next server mode
$this->Aseco->client->query('GetNextGameInfo');
$GameInfo = $this->Aseco->client->getResponse();
$GameMode = $GameInfo['GameMode'];
$failpoint = '';
$failed = false;
$this->Aseco->client->query("GetNextChallengeIndex");
$next_index = $this->Aseco->client->getResponse();
// do GetChallengeList and send it the next index, this way you avoid looping through data to find the right one later
$this->Aseco->client->query("GetChallengeList", 1, $next_index);
$challenge = $this->Aseco->client->getResponse();
if ( $challenge['faultString'] == 'Start index out of bound.' ){ // tried to get track xx, but only xx-1 tracks exist, get track 0 instead - using getnextchallengeindex this should NEVER occur
$this->Aseco->client->query("GetChallengeList", 1, 0);
$challenge = $this->Aseco->client->getResponse();
$this->Aseco->client->error->code = 0;
$this->Aseco->client->error->message = '';
}
else{
$filename = $challenge[0]['FileName'];
}
if ( !$failed ){
$this->Aseco->client->query("GetChallengeInfo", $filename);
$result = $this->Aseco->client->getResponse();
if ( isset($result['faultCode'] ) ){
$this->Aseco->console_text('[RaspShowNext] - \'' . $filename . '\' - unable to get track info');
$this->Aseco->console_text('[RaspShowNext] - GetChallengeInfo failed - [' . $result['faultCode'] . '] - ' . $result['faultString']);
$failed = true;
$failpoint = 'GetChallengeInfo';
}
}
if ( $failed ){
$automsg = $failpoint . ' failed, no data shown';
$trackinfo = array(); // clear it out so it doesn't crash
}
else{
$trackinfo = $result;
}
/*
Datablock in $result[0][0]
Array
(
[UId] => nIGJHQkY_Wy5mt11GnWtcLo_zaf
[Name] => $s$f80new mix on the block$ffc$sz
[FileName] => new mix on the blockz.Challenge.gbx
[Author] => z3383z
[Environnement] => Stadium
[Mood] => Sunset
[BronzeTime] => 74000
[SilverTime] => 59000
[GoldTime] => 52000
[AuthorTime] => 48790
[CopperPrice] => 3779
[LapRace] =>
)
*/
$this->Aseco->client->query("GetTimeAttackLimit", $newtime);
$result = $this->Aseco->client->getResponse();
if (!$result){
trigger_error('[' . $this->Aseco->client->getErrorCode() . '] ' . $this->Aseco->client->getErrorMessage());
}
else
{
$nexttime = $result['NextValue'];
// xml content
$xmlheader = "<?xml version='1.0' encoding='utf-8' ?>
<manialinks><custom_ui>
<notice visible='true'/>
<challenge_info visible='false'/>
<net_infos visible='true'/>
<chat visible='true'/>
<checkpoint_list visible='true'/>
<round_scores visible='true'/>
<scoretable visible='true'/>
<global visible='true'/>
</custom_ui>
<manialink posx='-0.5' posy='0.745' id='202'>
<type>default</type>
<format textsize='1' textcolor='000f' />
<background bgcolor='000F' bgborderx='0' bgbordery='0'/>";
$xmlfooter = "</manialink></manialinks>";
$content = $xmlheader;
$leftcell = "<cell width='0.125' bgcolor='000F'><text textcolor='8af' halign='right'>";
$rightcell = "<cell width='0.275' bgcolor='000F'><text textcolor='ddd' halign='left'>";
$content .= "<line><cell bgcolor='888F' width='.4'><text textcolor='0E0' halign='center'>Next Track Info</text></cell></line>
<line height='.03'>
" . $leftcell . "Name: </text></cell>"
. $rightcell . htmlspecialchars($this->stripFormatting($trackinfo['Name'])) . "</text></cell>
</line>
<line height='.03'>
" . $leftcell . "Env: </text></cell>"
. $rightcell . $trackinfo['Environnement'] . "</text></cell>
</line>
<line height='.03'>
" . $leftcell . "Mood: </text></cell>"
. $rightcell . $trackinfo['Mood'] . "</text></cell>
</line>
<line height='.03'>
" . $leftcell . "Author: </text></cell>"
. $rightcell . $trackinfo['Author'] . "</text></cell>
</line>";
switch ($GameMode)
{
case 0: // Rounds
$c1l = 'Mode:';
$c1r = 'Rounds';
$c2l = 'Points:';
$c2r = $GameInfo['RoundsPointsLimit'];
break;
case 1: // TimeAttack
$c1l = 'Author Time:';
$c1r = formatTime($trackinfo['AuthorTime']);
$c2l = 'Time Limit:';
$c2r = formatTime($nexttime);
break;
case 2: // Teams
$c1l = 'Mode:';
$c1r = 'Teams';
$c2l = 'Points:';
$c2r = 'Limit ' . $GameInfo['TeamsPointsLimit'] . ' / Max ' . $GameInfo['TeamMaxPoints'];
break;
case 3: // Laps
$c1l = 'Laps:';
$c1r = $GameInfo['LapsNbLaps'];
$c2l = 'Time Limit:';
$c2r = formatTime($GameInfo['LapsTimeLimit']);
break;
case 4: // Stunts
$c1l = 'Mode:';
$c1r = 'Stunts';
$c2l = '';
$c2r = '';
break;
}
$content .= "<line height='.03'>
" . $leftcell . $c1l . " </text></cell>"
. $rightcell . $c1r . "</text></cell>
</line>
<line height='.03'>
" . $leftcell . $c2l . " </text></cell>"
. $rightcell . $c2r . "</text></cell>
</line>";
$content .= $xmlfooter;
foreach($this->Aseco->server->players->player_list as $pl){
$this->sendMLtoLogin($pl->login, $content);
}
}
} // showTrackInfo
function showRanks(){
$xmlheader = "<?xml version='1.0' encoding='utf-8' ?>
<manialinks><custom_ui>
<notice visible='true'/>
<challenge_info visible='false'/>
<net_infos visible='true'/>
<chat visible='true'/>
<checkpoint_list visible='true'/>
<round_scores visible='true'/>
<scoretable visible='true'/>
<global visible='true'/>
</custom_ui>
<manialink posx='1' posy='0.27' id='203'>
<type>default</type>
<format textsize='1' textcolor='000f' />
<background bgcolor='000F' bgborderx='0' bgbordery='0'/>";
$xmlfooter = "</manialink></manialinks>";
$content = $xmlheader;
$leftcell = "<cell width='0.033' bgcolor='000F'><text textcolor='ddd' halign='center'>";
$rightcell = "<cell width='0.28' bgcolor='000F'><text textcolor='8af' halign='left'>";
$avgcell = "<cell width='0.06' bgcolor='000F'><text textcolor='8af' halign='left'>";
$content .= "<line><cell bgcolor='888F' width='.37'><text textcolor='FF0' halign='center'>Current top20 Ranking</text></cell></line>";
$query = 'SELECT p.NickName, r.avg, ROUND(r.avg/10000, 2) as rank FROM players p LEFT JOIN rs_rank r ON (p.Id=r.PlayerId) WHERE r.avg!=0 ORDER BY r.avg ASC LIMIT 20';
$res = mysql_query($query);
$i = 1;
$top = 20;
while ($row = mysql_fetch_object($res)) {
$content .= "<line height='.03'>" . $leftcell . $i . ". </text></cell>";
$nickname = str_replace("\$w", '', $row->NickName);
// original $content .= $rightcell . htmlspecialchars($nickname) . "</text></cell>";
$content .= $rightcell . htmlspecialchars($this->getValidUTF8String($nickname)) . "</text></cell>";
$content .= $avgcell . $row->rank . "</text></cell></line>";
$i++;
}
$content .= $xmlfooter;
foreach($this->Aseco->server->players->player_list as $pl) {
$this->sendMLtoLogin($pl->login, $content);
}
} //showRanks
function onStatusChange3() { // Hide everything
$content = "<?xml version='1.0' encoding='UTF-8'?>
<manialinks>
<manialink id='201'></manialink>
<manialink id='203'></manialink>
</manialinks>";
// <manialink id='202'></manialink> <manialink id='204'></manialink>
foreach($this->Aseco->server->players->player_list as $pl)
{
$this->sendMLtoLogin($pl->login, $content);
}
} // onStatusChange3
function start($aseco_ext) {
$this->Aseco = $aseco_ext;
}
function sendMLtoLogin($login, $xml){
//$this->Aseco->console_text($xml);
$this->Aseco->client->addCall("SendDisplayManialinkPageToLogin", array($login, $xml, 0, false));
}
/**
* Handles mouse click on Karma questions
*
* @param mixed $command
*/
function doHandleClick($aseco, $command){
if (($command[2] == 11111) || ($command[2] == 22222) || ($command[2] == 33333)) {
$action = substr($command[2], 0, 1);
$this->executeKarma($command[1], $action);
$content = "<?xml version='1.0' encoding='UTF-8'?>
<manialinks>
<manialink id='204'></manialink>
</manialinks>";
$this->sendMLtoLogin($command[1], $content);
}
}
/**
* Executes Karma votes
*
* @param String $login
* @param String $action
*/
function executeKarma($login, $action){
$cmd=array();
$cmd['author'] = $this->Aseco->server->players->getPlayer($login);
if ($action==1){
$vote = 1;
} else if ($action==2){
$vote = -1;
} else return;
KarmaVote($this->Aseco, $cmd, $vote);
}
// added by FoxShadow *********************************************************************
/**
* Returns a valid UTF String and replaces faulty byte values with a given string
* Thanks a lot to Slig for his original tm_substring function.
*
* @param String $str
* @param String $replaceInvalidWith
* @return String
*/
function getValidUTF8String($str, $replaceInvalidWith = ''){
$s = strlen($str); // byte string length
$pos = 0; // current byte pos in string
$newStr = '';
while($pos < $s){
$c = $str[$pos];
$co = ord($c);
if($co >= 240 && $co <248){ // 4 bytes utf8 => 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
if(($pos+3 < $s ) &&
(ord($str[$pos+1]) >= 128) && (ord($str[$pos+1]) < 192) &&
(ord($str[$pos+2]) >= 128) && (ord($str[$pos+2]) < 192) &&
(ord($str[$pos+3]) >= 128) && (ord($str[$pos+3]) < 192)){
// ok, it was 1 character, increase counters
$newStr.=substr($str, $pos, 4);
$pos += 4;
}else{
// bad multibyte char
$newStr.= $replaceInvalidWith;
$pos++;
}
}elseif($co >= 224){ // 3 bytes utf8 => 1110xxxx 10xxxxxx 10xxxxxx
if(($pos+2 < $s ) &&
(ord($str[$pos+1]) >= 128) && (ord($str[$pos+1]) < 192) &&
(ord($str[$pos+2]) >= 128) && (ord($str[$pos+2]) < 192)){
// ok, it was 1 character, increase counters
$newStr.=substr($str, $pos, 3);
$pos += 3;
}else{
// bad multibyte char
$newStr.= $replaceInvalidWith;
$pos++;
}
}elseif($co >= 192){ // 2 bytes utf8 => 110xxxxx 10xxxxxx
if(($pos+1 < $s ) &&
(ord($str[$pos+1]) >= 128) && (ord($str[$pos+1]) < 192)){
$newStr.=substr($str, $pos, 2);
$pos += 2;
}else{
// bad multibyte char
$newStr.=$replaceInvalidWith;
$pos++;
}
}else{
// ascii char or erroneus middle multibyte char
if($co >=128)
$newStr.=$replaceInvalidWith;
else
$newStr.=$str[$pos];
$pos++;
}
}
return $newStr;
}
// end of added *********************************************************************
function stripFormatting($input) {
return
//Replace all occurances of a null character back with a pair of dollar
//signs again
str_replace("\0", '$$',
//Replace links (introduced with the advent of TMU)
preg_replace(
'/
#Strip TMU H, L and P links by stripping everything between each
#square bracket pair until another $H, $L or $P sequence is found.
#This allows a $H to close a $L and vice versa, as does the game
\\$[hlp](.*?)(?:\\[.*?\\](.*?))*(?:\\$[hlp]|$)
/ix',
//Keep the second and third capturing groups if present
'$1$2',
//Replace various patterns beginning with an unescaped dollar
preg_replace(
'/
#Match a single dollar sign and any of the following:
\\$
(?:
#Strip colour codes by matching any hexadecimal character
#and any other two characters following it
[0-9a-f]..
#Strip any single character that does not match the above rule
#and is not an H, L or P link
|[^hlp]
#Strip the dollar sign if it is at the end of the string
|$
)
#Ignore alphabet case, ignore whitespace in pattern & use UTF-8 mode
/ixu',
//Replace any matches with nothing (i.e. strip matches)
'',
//Replace all occurances of dollar sign pairs with a null character
str_replace('$$', "\0", $input)
)
)
)
;
} //stripformatting
}
Aseco::registerEvent('onStartup', 'showranks_startUp');
function showranks_startUp($aseco) {
global $ShowInfo;
$ShowInfo = new ShowInfo();
$ShowInfo->setAuthor('Assembler Maniac');
$ShowInfo->setVersion(1.0);
$ShowInfo->setDescription('Show Ranks Info During Intermission');
$ShowInfo->start($aseco);
}
Aseco::registerEvent('onEndRace', 'showranks_endRace');
function showranks_endRace(){
global $ShowInfo;
$ShowInfo->showRecords();
// $ShowInfo->showTrackInfo();
$ShowInfo->showRanks();
// $ShowInfo->onEndRace();
}
Aseco::registerEvent('onStatusChangeTo3', 'showranks_statusChange');
function showranks_statusChange(){
global $ShowInfo;
$ShowInfo->onStatusChange3();
}
Aseco::registerEvent('onPlayerManialinkPageAnswer', 'handleClick');
function handleClick($aseco, $command){
global $ShowInfo;
$ShowInfo->doHandleClick($aseco, $command);
}