Current game scores to webpage

Moderator: NADEO

Post Reply
Rephil
Posts: 2
Joined: 31 Oct 2011, 23:17

Current game scores to webpage

Post by Rephil »

Hey all,
Im creating a website where I want to get the scores from races right after they have been completed. I will have a dedicated server with Trackmania Forever on there. Is there there anyway to do that? Im just a regular programmer and not very familiar with Trackmanias sdk or any of their tools... Im currently looking in to it. But If anyone out there knows the ins and outs of this, it would be much appreciated if you could shed a little light on the topic for me.
Thanks a lot in advance. :D
Rephil
User avatar
jonthekiller
Translator
Translator
Posts: 4629
Joined: 15 Jun 2010, 11:07
Location: In Maniaplanet Alpha
Contact:

Re: Current game scores to webpage

Post by jonthekiller »

You can see Adminserv for help you : http://www.zone-kev717.info/adminserv/?p=download
Image
User avatar
w1lla
Posts: 2287
Joined: 15 Jun 2010, 11:09
Location: Netherlands
Contact:

Re: Current game scores to webpage

Post by w1lla »

Made a test code once. It gets data from a server and tells every data back during each gamemode.

Code: Select all

<html>
<head>
<script>
<!--

/*
Auto Refresh Page with Time script
By JavaScript Kit (javascriptkit.com)
Over 200+ free scripts here!
*/

//enter refresh time in "minutes:seconds" Minutes should range from 0 to inifinity. Seconds should range from 0 to 59
var limit="0:03"

if (document.images){
var parselimit=limit.split(":")
parselimit=parselimit[0]*60+parselimit[1]*1
}
function beginrefresh(){
if (!document.images)
return
if (parselimit==1)
window.location.reload()
else{ 
parselimit-=1
curmin=Math.floor(parselimit/60)
cursec=parselimit%60
if (curmin!=0)
curtime=curmin+" minutes and "+cursec+" seconds left until page refresh!"
else
curtime=cursec+" seconds left until page refresh!"
window.status=curtime
setTimeout("beginrefresh()",1000)
}
}

window.onload=beginrefresh
//-->
</script>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type"/>
<title>Intense Mania Stats</title>
<?php

/**
 *  IMS - IntenseManiaStats
 * 
 * -- IMS Webpage --
 * @name IMS Testindex.php
 * @date 13-03-2011
 * @version r001
 * @website ims.tmrankings.com
 * @package IMS
 * 
 * @author Willem "W1lla" van den Munckhof <w1llaopgezwolle@gmail.com> 
 *      
 * @copyright 2010 - 2011
 * 
 * ---------------------------------------------------------------------
 * 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 of 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.
 * ---------------------------------------------------------------------
 */
$version = 0.1;
$ip="localhost";                      //IP address of server

$port=5225;                          //Port for remote access

$user= "SuperAdmin";                  // SuperAdmin Login

$pass= "SuperAdmin";                        // SuperAdmin Password


	require("includes/GbxRemote.inc.php"); // required for connection with server.
	
    require("includes/tmfcolorparser.inc.php"); //colorparser for tracks, nicknames etc.
	
	$client = new IXR_Client_Gbx;
	
    $colors= new TMFColorParser;
	
	 if (!$client->InitWithIp($ip,$port)) {
       echo'An error occurred - '.$client->getErrorCode().":".$client->getErrorMessage();
    }
   if (!$client->query("Authenticate", $user, $pass)) {

       print "login failed !<br/>";
    }	
	if($client->query('GetStatus')) {
       $Status = $client->getResponse();
       }
	   
    if($client->query('GetPlayerList', 300, 0)){ //used to show all player nicknames..
 $players = $client->getResponse();
$CurrentPlayerCount=0;
$playersinput = array();
foreach ($players as $pls) {
$playersinput[$CurrentPlayerCount] = $colors->toHTML($pls['NickName']);
$CurrentPlayerCount++;

}
}

    if($client->query('GetServerOptions')) { //used for the current max state of players.
       $ServerOptions = $client->getResponse();
       $servername=$ServerOptions['Name'];
       $MaxPLayers=$ServerOptions['CurrentMaxPlayers'];
    $pl=0;
    foreach ($players as $player) {
       $pl++;
	   }
	   }
    if($client->query('GetCurrentChallengeInfo')) { //used for current track.
       $CurrentChallengeInfo = $client->getResponse();
       $trackname=$CurrentChallengeInfo['Name'];
       }

    if($client->query('GetCurrentGameInfo')) { // used for current gamemode.
       $GetCurrentGameInfo=$client->getResponse();
       $GameMode=$GetCurrentGameInfo["GameMode"];
	   
    }
if($client->query('GetNextChallengeInfo')) { // used for next track.
	$GetNextChallengeInfo=$client->getResponse();
	$nexttrackname=$GetNextChallengeInfo['Name'];
	
    }
    if ($client->query('GetLadderServerLimits')) { // used for serverlimits.
		$GetLadderServerLimits=$client->getResponse();
		$ladderMin = $GetLadderServerLimits['LadderServerLimitMin'];
		$ladderMax = $GetLadderServerLimits['LadderServerLimitMax'];
        }

    if ($client->query('GetMainServerPlayerInfo')) { // used for serverlogin.
		$GetMainServerPlayerInfo = $client->getResponse();
		$serverlogin = $GetMainServerPlayerInfo['Login'];
        }
		
		
	if ($client->query('GetCurrentGameInfo', 1)) { //used for CurrentGameinfos
	$currentgameinfo = $client->getResponse();
	$RoundsPointsLimit = $currentgameinfo['RoundsPointsLimitNewRules'];
	$CupPointsLimit = $currentgameinfo['CupPointsLimit'];
}
    //Formating Game Mod
    switch($GameMode){
       case 0:
          $GameMode="Rounds";
          Break;
       case 1:
          $GameMode="Time Attack";
          Break;
       case 2:
          $GameMode="Team";
          Break;
       case 3:
          $GameMode="Laps";
          Break;
       case 4:
          $GameMode="Stunts";
          Break;
       case 5:
          $GameMode="Cup";
          Break;
    }
		
	if ($client->query('GetCurrentRanking', 300, 0)) { // used for CurrentRanking tested in Rounds....
		$currentranking = $client->getResponse();
		foreach ($currentranking as $playersplay) {
		$playerlogin = $playersplay['Login'];
		$playernickname = $playersplay['NickName'];
		$score = $playersplay['Score'];
		$Rank = $playersplay['Rank'];
		$playerBest = $playersplay['BestTime'];
		$MWTime = $playerBest;
		$minutes = floor($MWTime/(1000*60));
		$seconds = floor(($MWTime-$minutes*60*1000)/1000);
		$mseconds = substr($MWTime,strlen($MWTime)-3,2);
		$time=sprintf("%02d:%02d.%02d", $minutes, $seconds, $mseconds);
				if ($time=="-1:59.01") {
			$time="No time made";
			$Rank="---";
			}
			}
		}	
	?>
	
	     <tr bgcolor="#000000">
      <td height="25" colspan="5"> <div align="center"><font color="#000000"><?php echo 'Current Gamemode: '.$GameMode.'' ?></font></div></td>
    </tr>
	<br>
		 <tr bgcolor="#000000">
      <td height="25" colspan="5"> <div align="center"><font color="#000000"><?php echo 'Current Track being played: '.$colors->toHTML($trackname).'' ?></font></div></td>
    </tr>
	<br>
		<tr bgcolor="#000000">
      <td height="25" colspan="5"> <div align="center"><font color="#000000"><?php echo 'Next Track being played: '.$colors->toHTML($nexttrackname).'' ?></font></div></td>
    </tr>
	<br>
		<tr bgcolor="#000000">
      <td height="25" colspan="5"> <div align="center"><font color="#000000"><?php echo "Players: $pl/$MaxPLayers" ?></font></div></td>
    </tr>
	<br>
	<?php if ($pl == 1){?>
		<tr bgcolor="#000000">
      <td height="25" colspan="5"> <div align="center"><font color="#000000"><?php echo "Playerlist:<br><br>".implode('<br><br>', $playersinput)."" ?></font></div></td>
    </tr>
	<br>
		<?php } ?>
		<?php if ($GameMode === "Team"){
	?>
	<br>
		<tr bgcolor="#000000">
      <td height="25" colspan="5"> <div align="center"><font color="#000000"><?php echo "Team:".$colors->toHTML($playernickname)."" ?><br></font></div></td>
    </tr>
	<br>
		<tr bgcolor="#000000">
      <td height="25" colspan="5"> <div align="center"><font color="#000000"><?php echo "PlayerBestTime: $time" ?></font></div></td>
    </tr>
	<br>
		<tr bgcolor="#000000">
      <td height="25" colspan="5"> <div align="center"><font color="#000000"><?php echo "Score: $score" ?></font></div></td>
    </tr>
	<br>
<?php
}
?>
	<?php if ($GameMode === "Time Attack"){
	?>
	<br>
		<tr bgcolor="#000000">
      <td height="25" colspan="5"> <div align="center"><font color="#000000"><?php echo "Playernickname:".$colors->toHTML($playernickname)."" ?><br></font></div></td>
    </tr>
	<br>
		<tr bgcolor="#000000">
      <td height="25" colspan="5"> <div align="center"><font color="#000000"><?php echo "Playerlogin:".$playerlogin."" ?><br></font></div></td>
    </tr>
	<br>
		<tr bgcolor="#000000">
      <td height="25" colspan="5"> <div align="center"><font color="#000000"><?php echo "PlayerBestTime: $time" ?></font></div></td>
    </tr>
	<br>
		<tr bgcolor="#000000">
      <td height="25" colspan="5"> <div align="center"><font color="#000000"><?php echo "Score: $score" ?></font></div></td>
    </tr>
	<br>
		<tr bgcolor="#000000">
      <td height="25" colspan="5"> <div align="center"><font color="#000000"><?php echo "Rank: $Rank" ?></font></div></td>
    </tr>
	<br>
<br>
	<?php
	}
	?>
	<br><?php if ($GameMode === "Rounds"){?>
		<tr bgcolor="#000000">
      <td height="25" colspan="5"> <div align="center"><font color="#000000"><?php echo "RoundpointsLimit: $RoundsPointsLimit" ?></font></div></td>
    </tr>
	<br>
	<br>
		<tr bgcolor="#000000">
      <td height="25" colspan="5"> <div align="center"><font color="#000000"><?php echo "Playernickname:".$colors->toHTML($playernickname)."" ?><br></font></div></td>
    </tr>
	<br>
		<tr bgcolor="#000000">
      <td height="25" colspan="5"> <div align="center"><font color="#000000"><?php echo "Playerlogin:".$playerlogin."" ?><br></font></div></td>
    </tr>
	<br>
		<tr bgcolor="#000000">
      <td height="25" colspan="5"> <div align="center"><font color="#000000"><?php echo "PlayerBestTime: $time" ?></font></div></td>
    </tr>
	<br>
		<tr bgcolor="#000000">
      <td height="25" colspan="5"> <div align="center"><font color="#000000"><?php echo "Score: $score" ?></font></div></td>
    </tr>
	<br>
		<tr bgcolor="#000000">
      <td height="25" colspan="5"> <div align="center"><font color="#000000"><?php echo "Rank: $Rank" ?></font></div></td>
    </tr>
	<br>
<br>
	<?php } ?>
	<br><?php if ($GameMode === "Cup"){?>
		<tr bgcolor="#000000">
      <td height="25" colspan="5"> <div align="center"><font color="#000000"><?php echo "CuppointsLimit: $CupPointsLimit" ?></font></div></td>
    </tr>
	<br>
	<br>
		<tr bgcolor="#000000">
      <td height="25" colspan="5"> <div align="center"><font color="#000000"><?php echo "Playernickname:".$colors->toHTML($playernickname)."" ?><br></font></div></td>
    </tr>
	<br>
		<tr bgcolor="#000000">
      <td height="25" colspan="5"> <div align="center"><font color="#000000"><?php echo "Playerlogin:".$playerlogin."" ?><br></font></div></td>
    </tr>
	<br>
		<tr bgcolor="#000000">
      <td height="25" colspan="5"> <div align="center"><font color="#000000"><?php echo "PlayerBestTime: $time" ?></font></div></td>
    </tr>
	<br>
		<tr bgcolor="#000000">
      <td height="25" colspan="5"> <div align="center"><font color="#000000"><?php echo "Score: $score" ?></font></div></td>
    </tr>
	<br>
		<tr bgcolor="#000000">
      <td height="25" colspan="5"> <div align="center"><font color="#000000"><?php echo "Rank: $Rank" ?></font></div></td>
    </tr>
	<br>
<br>
	<?php } ?>
	<?php
echo "<center>Intense Mania Stats  $version. All rights reserved.<br /></center>";
echo '</head>
<body style="background:#BBBBBB; font-family:Arial, sans-serif">';
?>
Copy paste it in a new file and save it as .php extension file.
TM² Info
SM Info
QM Info

OS: Windows 10 x64 Professional
MB: MSI 970A-G46
Processor: AMD FX-6300 3500 mHz
RAM Memory: 16 GB DDR3
Video: SAPPHIRE DUAL-X R9 280X 3GB GDDR5
KB: Logitech G510s
Mouse: Logitech G300s
Mode Creation
ManiaScript Docs
nocturne
Posts: 208
Joined: 23 Jun 2010, 21:31

Re: Current game scores to webpage

Post by nocturne »

It's certainly possible, but the amount of coding necessary really depends on exactly what you want to accomplish.

You'll find that scripting for TM is pretty simple and straightforward -- you use the GbxRemote xmlrpc library (php) to create a connection to the server using login credentials, run the desired methods to gather info, and then terminate the connection (you can find some very basic examples in the dedicated server package).

The only complicating factor is whether you want to show the 'full' rankings of the previous round until the current round finishes (basically, always maintain a full ranking list -- otherwise, 90% of the time there will be little more than a player list shown), or if you want to show the ranking up to that very moment (perhaps with a little javascript auto-refresh action). The former would necessitate an actively running 'daemon' script to store the necessary info into either a db or file to populate the page with (easiest would be a controller (ie. xaseco or ML) plugin, as it's already running anyways. The latter would be much simpler -- get the info by method (GetCurrentRanking), then display.
Post Reply

Return to “Dedicated Server”

Who is online

Users browsing this forum: No registered users and 1 guest