Skip to content

Instantly share code, notes, and snippets.

@w1lla
Created June 28, 2013 12:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save w1lla/5884328 to your computer and use it in GitHub Desktop.
Save w1lla/5884328 to your computer and use it in GitHub Desktop.
Xaseco Mumble Plugin
<?php
/**
Name: Willem 'W1lla' van den Munckhof
Date: 2013-06-28
Project Name: Mumble Widget / Info
**/
/**
* ---------------------------------------------------------------------
* 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.
* ---------------------------------------------------------------------
*/
Aseco::registerEvent('onSync', 'mum_onSync');
Aseco::registerEvent('onPlayerConnect', 'mum_onPlayerConnect');
Aseco::registerEvent('onPlayerManialinkPageAnswer', 'mum_onPlayerManialinkPageAnswer');
Aseco::registerEvent('onEverySecond', 'mum_onEverySecond');
Aseco::registerEvent('onBeginMap', 'mum_onBeginMap');
Aseco::registerEvent('onEndMap1', 'mum_onEndMap1');
function mum_onSync ($aseco) {
}
function mum_onPlayerConnect ($aseco, $player) {
// Send InfoWidget to this Player
mum_buildInfoWidget($player->login);
}
function mum_MumbleWidget($login = false){
global $aseco;
$icon_mumble = "http://tmrankings.com/manialink/mv/icons/mumble.png";
$xml = '<?xml version="1.0" encoding="utf-8"?>';
$xml .= '<manialink id="MumbleLogo">';
$xml .= '<frame posn="-60 -20 0">';
$xml .= '<quad sizen="4 4" posn="0 0 0" action="5555555555555" image="'. $icon_mumble .'"/>';
$xml .= '</frame>';
$xml .= '</manialink>';
if ($login != false) {
// Send to given Player
$aseco->client->query('SendDisplayManialinkPageToLogin', $login, $xml, 0, false);
}
else {
// Send to all connected Players
$aseco->client->query('SendDisplayManialinkPage', $xml, 0, false);
}
}
function mum_onBeginMap ($aseco, $race) {
// Show InfoWidget at all Players at Race
mum_MumbleWidget(false, true);
}
// $answer = [0]=PlayerUid, [1]=Login, [2]=Answer
function mum_onPlayerManialinkPageAnswer ($aseco, $answer) {
global $aseco;
// If id = 0, bail out immediately
if ($answer[2] == 0) {
$xml = '<?xml version="1.0" encoding="UTF-8"?><manialinks><manialink id="1234567891012"></manialink></manialinks>';
if ($answer[1] != false) {
// Send to given Player
$aseco->client->query('SendDisplayManialinkPageToLogin', $answer[1], $xml, 0, false);
}
else {
// Send to all connected Players
$aseco->client->query('SendDisplayManialinkPage', $answer[1], 0, false);
}
}
if ($answer[2] == "5555555555555") {
mum_buildInfoWidget($answer[1]); // Build InfoWindow
}
}
function mum_buildInfoWidget($login) {
echo $login;
global $aseco;
$xml = '<?xml version="1.0" encoding="UTF-8"?>';
$xml .= '<manialink id="1234567891012">';
$file = "http://lynx.tmfserver.com/mumble-django/mumble/1.json";
$icon_mumble = "http://tmrankings.com/manialink/mv/icons/mumble.png";
$icon_channel = "http://tmrankings.com/manialink/mv/icons/channel.png";
$icon_user_on = "http://tmrankings.com/manialink/mv/icons/user_on.png";
$icon_user_off = "http://tmrankings.com/manialink/mv/icons/user_off.png";
$icon_authenticated = "http://tmrankings.com/manialink/mv/icons/authenticated.png";
$icon_muted_server = "http://tmrankings.com/manialink/mv/icons/muted_server.png";
$icon_deaf_self = "http://tmrankings.com/manialink/mv/icons/deafened_self.png";
$icon_deaf_server = "http://tmrankings.com/manialink/mv/icons/deafened_server.png";
$icon_selfmute = "http://tmrankings.com/manialink/mv/icons/muted_self.png";
$icon_active = "http://tmrankings.com/manialink/mv/icons/talking_alt.png";
$mumble_feed = json_decode(file_get_contents($file), true);
$xml .= '<frame posn="-50 20 0">
<format textsize="1" textcolor="$0f0"/>
<quad posn="0 0 0" sizen="100 50" style="BgsPlayerCard" substyle="BgRacePlayerName"/>
<quad posn="0 0 0.04" sizen="100 2.5" style="BgsPlayerCard" substyle="ProgressBar"/>
<quad posn="0.6 0 0.05" sizen="2.5 2.5" style="Icons128x128_1" substyle="Multiplayer"/>
<quad posn="-49 78 1" sizen="1 1" scale="5" image="'.$icon_mumble.'"/>
<label posn="3.2 -0.65 0.05" sizen="17.3 0" textsize="1" text="'.$mumble_feed['name'].'"/>';
$channels = $mumble_feed['root']['channels'];
global $icon_channel, $icon_active, $icon_mumble, $icon_user_on, $icon_user_off, $icon_authenticated, $icon_deaf_self, $icon_deaf_server, $icon_mute_server, $icon_selfmute;
$line = 1;
$offset = 0;
$entries = 0;
foreach ($channels as $channel)
{
if ($line > 15) {
$offset += 55.5;
$line = 1;
}
$pid_offset = 0;
if ($channel['name'] > 0){
$pid_offset = 1;
}
$xml .= '<quad posn="'. ($offset + 15.7) .' -'. (2.8 * $line) .' 0.05" sizen="1.8 1.8" style="Icons128x128_1" substyle="Lan"/>';
$xml .= '<label posn="'. ($offset + $pid_offset + 0.9) .' -'. (2.8 * $line) .' 0.05" sizen="'. (16.2 - $pid_offset) .' 1.85" scale="0.9" style="TextTitle3" textcolor="fff" text="'. $channel['name'] .'" url="'.$channel['x_connecturl'].'"/>';
$line++;
$entries++;
$subchannels = $channel['channels'];
if (sizeof($subchannels) > 0)
{
foreach ($subchannels as $subchannel){
if ($line > 25) {
$offset += 55.5;
$line = 1;
}
$xml .= '<quad posn="'. ($offset + 15.7) .' -'. (2.75 * $line) .' 0.05" sizen="1.8 1.8" style="Icons128x128_1" substyle="Lan"/>';
$xml .= '<label posn="'. ($offset + $pid_offset + 0.9) .' -'. (2.75 * $line) .' 0.05" style="TextTitle3" textcolor="fff" text="'. $subchannel['name'] .'" url="'.$subchannel['x_connecturl'].'"/>';
$line++;
$entries++;
$users = $subchannel['users'];
foreach($users as $user)
{
if ($line > 6) {
$offset += 55.5;
$line = 1;
}
$icon_user = ($user['bytespersec'] == 0 ? $icon_user_off : $icon_user_on);
$auth = ($user['userid'] > 0);
$selfmute = ($user['selfMute']);
$deaf = ($user['selfDeaf']);
if ($deaf){
$icon_deaf = $icon_deaf_self;
}
else{
$icon_deaf = $icon_active;
}
if ($selfmute){
$icon_selfmuted = $icon_selfmute;
}
else{
$icon_selfmuted = $icon_active;
}
if ($auth){
$icon_auth = $icon_authenticated;
}
else
{
$icon_auth = $icon_mumble;
}
$xml .= '<quad posn="'. ($offset + 15.7) .' -'. (2.75 * $line) .' 0.05" sizen="1.8 1.8" image="'.$icon_user.'"/>';
$xml .= '<quad posn="'. ($offset + 18.7) .' -'. (2.75 * $line) .' 0.05" sizen="1.8 1.8" image="'.$icon_auth.'"/>';
$xml .= '<quad posn="'. ($offset + 21.7) .' -'. (2.75 * $line) .' 0.05" sizen="1.8 1.8" image="'.$icon_selfmuted.'"/>';
$xml .= '<quad posn="'. ($offset + 24.7) .' -'. (2.75 * $line) .' 0.05" sizen="1.8 1.8" image="'.$icon_deaf.'"/>';
$xml .= '<label posn="'. ($offset + 2.9) .' -'. (2.75 * $line) .' 0.05" sizen="'. (16.2 - $pid_offset) .' 1.85" scale="0.6" textcolor="fff" style="TextTitle2Blink" text="'.$user['name'].'"/>';
$line++;
$entries++;
}
}
foreach ($subchannel['channels'] as $sub_subchannel){
if ($line > 25) {
$offset += 55.5;
$line = 1;
}
$xml .= '<quad posn="'. ($offset + 15.7) .' -'. (2.75 * $line) .' 0.05" sizen="1.8 1.8" style="Icons128x128_1" substyle="Lan"/>';
$xml .= '<label posn="'. ($offset + $pid_offset + 0.9) .' -'. (2.75 * $line) .' 0.05" style="TextTitle3" textcolor="fff" text="'. $sub_subchannel['name'] .'" url="'.$sub_subchannel['x_connecturl'].'"/>';
$line++;
$entries++;
$users = $sub_subchannel['users'];
foreach($users as $user)
{
if ($line > 6) {
$offset += 55.5;
$line = 1;
}
$icon_user = ($user['bytespersec'] == 0 ? $icon_user_off : $icon_user_on);
$auth = ($user['userid'] > 0);
$selfmute = ($user['selfMute']);
$deaf = ($user['selfDeaf']);
if ($deaf){
$icon_deaf = $icon_deaf_self;
}
else{
$icon_deaf = $icon_active;
}
if ($selfmute){
$icon_selfmuted = $icon_selfmute;
}
else{
$icon_selfmuted = $icon_active;
}
if ($auth){
$icon_auth = $icon_authenticated;
}
else
{
$icon_auth = $icon_mumble;
}
$xml .= '<quad posn="'. ($offset + 15.7) .' -'. (2.75 * $line) .' 0.05" sizen="1.8 1.8" image="'.$icon_user.'"/>';
$xml .= '<quad posn="'. ($offset + 18.7) .' -'. (2.75 * $line) .' 0.05" sizen="1.8 1.8" image="'.$icon_auth.'"/>';
$xml .= '<quad posn="'. ($offset + 21.7) .' -'. (2.75 * $line) .' 0.05" sizen="1.8 1.8" image="'.$icon_selfmuted.'"/>';
$xml .= '<quad posn="'. ($offset + 24.7) .' -'. (2.75 * $line) .' 0.05" sizen="1.8 1.8" image="'.$icon_deaf.'"/>';
$xml .= '<label posn="'. ($offset + 2.9) .' -'. (2.75 * $line) .' 0.05" sizen="'. (16.2 - $pid_offset) .' 1.85" scale="0.6" textcolor="fff" style="TextTitle2Blink" text="'.$user['name'].'"/>';
$line++;
$entries++;
}
}
}
$users = $channel['users'];
foreach($users as $user)
{
if ($line > 6) {
$offset += 55.5;
$line = 1;
}
$icon_user = ($user['bytespersec'] == 0 ? $icon_user_off : $icon_user_on);
$auth = ($user['userid'] > 0);
$selfmute = ($user['selfMute']);
$deaf = ($user['selfDeaf']);
if ($deaf){
$icon_deaf = $icon_deaf_self;
}
else{
$icon_deaf = $icon_active;
}
if ($selfmute){
$icon_selfmuted = $icon_selfmute;
}
else{
$icon_selfmuted = $icon_active;
}
if ($auth){
$icon_auth = $icon_authenticated;
}
else
{
$icon_auth = $icon_mumble;
}
$xml .= '<quad posn="'. ($offset + 15.7) .' -'. (2.75 * $line) .' 0.05" sizen="1.8 1.8" image="'.$icon_user.'"/>';
$xml .= '<quad posn="'. ($offset + 18.7) .' -'. (2.75 * $line) .' 0.05" sizen="1.8 1.8" image="'.$icon_auth.'"/>';
$xml .= '<quad posn="'. ($offset + 21.7) .' -'. (2.75 * $line) .' 0.05" sizen="1.8 1.8" image="'.$icon_selfmuted.'"/>';
$xml .= '<quad posn="'. ($offset + 24.7) .' -'. (2.75 * $line) .' 0.05" sizen="1.8 1.8" image="'.$icon_deaf.'"/>';
$xml .= '<label posn="'. ($offset + 2.9) .' -'. (2.75 * $line) .' 0.05" sizen="'. (16.2 - $pid_offset) .' 1.85" scale="0.6" textcolor="fff" style="TextTitle2Blink" text="'.$user['name'].'"/>';
$line++;
$entries++;
}
}
$xml .= '<quad posn="98 -45 1" sizen="4 4" halign="center" imagefocus="http://reaby.kapsi.fi/ml/close_on.png" image="http://reaby.kapsi.fi/ml/close_off.png" action="0"/>';
$xml .= '</frame>';
$xml .= '</manialink>';
if ($login != "") {
// Send to given Player
$aseco->client->query('SendDisplayManialinkPageToLogin', $login, $xml, 0, false);
}
else {
// Send to all connected Players
$aseco->client->query('SendDisplayManialinkPage', $xml, 0, false);
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment