Matches
";
# parse the message
$opponent; $time; $server; $type; $scoreshome; $scoresopponent; $recording; $screenshots;
preg_match ('@^opponent: ([^\r\n\f]+)@m', $postmessage, $opponent);
preg_match ("@^time: ([0-9]+)@m", $postmessage, $time);
preg_match ('@^server: ([^\r\n\f]+)@m', $postmessage, $server);
preg_match ('@^type: ([^\r\n\f]+)@m', $postmessage, $type);
preg_match ("@^scoreshome: ([0-9 ]+)@m", $postmessage, $scoreshome);
preg_match ("@^scoresopponent: ([0-9 ]+)@m", $postmessage, $scoresopponent);
preg_match ("@^recording: $regexp_url@m", $postmessage, $recording);
preg_match_all ("@^screenshot: $regexp_url@m", $postmessage, $screenshots);
$match;
$match['id'] = $id;
$match['opponent'] = $opponent[1];
$match['time'] = $time[1];
$match['server'] = $server[1];
$match['type'] = $type[1];
$match['scoreshome'] = explode(" ", $scoreshome[1]);
$match['matchescount'] = count($match['scoreshome']);
$match['scoresopponent'] = explode(" ", $scoresopponent[1]);
$match['recording'] = $recording[1];
$match['screenshots'] = $screenshots[1];
$match['scorehome'] = 0;
$match['scoreopponent'] = 0;
#determines won matches
for ($i = 0;$i < $match['matchescount']; $i++)
{
if($match['scoreshome'][$i] < $match['scoresopponent'][$i])
$match['scoreopponent']++;
else
$match['scorehome']++;
}
$match['winner'] = ($match['scorehome'] > $match['scoreopponent'])? "Tronic Donkeys" : $match['opponent'];
/* echo ""; */
# var_export($opponent); var_export($time); var_export($server); var_export($type); var_export($scorehome); var_export($scoreopponent); var_export($recording); var_export($screenshots);
return $match;
}
function order_match(&$match, &$past, &$present, &$future)
{
if ($match['scoreshome'][0] !== "")
$past[]=$match;
else if ($match['time'] < time())
$present[]=$match;
else
$future[]=$match;
}
function compare_match_times($a, $b)
{
if ($a['time'] == $b['time']) return 0;
return ($a['time'] > $b['time'])? 1 : -1;
}
function print_matches($past, $present, $future)
{
?>
| Opponent |
Time |
Server |
Type |
Score |
Winner |
Current running matches | ";
foreach($present as $match)
{
echo "| {$match['opponent']} | ".date("Y/m/d H:i", $match['time'])." GMT | {$match['server']} | {$match['type']} | No results yet |
";
}
}
if (isset($future[0]))
{
echo "| Next upcoming matches |
";
foreach($future as $match)
{
echo "| {$match['opponent']} | ".date("Y/m/d H:i", $match['time'])." GMT | {$match['server']} | {$match['type']} | No results yet |
";
}
}
if (isset($past[0]))
{
echo "| Past matches |
";
foreach($past as $match)
{
echo "| {$match['opponent']} | ".date("Y/m/d H:i", $match['time'])." GMT | {$match['server']} | {$match['type']} | " . $match['scorehome'] . " - " . $match['scoreopponent'] . " | {$match['winner']} |
";
}
} ?>
";
echo "| Tronic Donkeys VS {$matchdata['opponent']}, the ". date("j \of F", $matchdata['time']) ." |
";
echo "| Date | The ". date("jS \of F, Y", $matchdata['time']) ." |
";
echo "| Time | " . date("H:i", $matchdata['time']) . " GMT |
";
echo "| Server | {$matchdata['server']} |
";
echo "| Type | {$matchdata['type']} |
";
if ($matchdata['scoreshome'][0] != '')
{
echo "| Results |
";
for($i = 0; $i < $matchdata['matchescount']; $i++)
{
echo "| Match ". ($i + 1) ." | {$matchdata['scoreshome'][$i]}-{$matchdata['scoresopponent'][$i]} |
";
}
echo "| Final scores | {$matchdata['scorehome']}-{$matchdata['scoreopponent']} |
";
echo "| Winner | {$matchdata['winner']} |
";
echo "| Recording | Click here |
";
}
echo "";
}
function list_all()
{
$pastmatches;
$currentmatches;
$upcomingmatches;
$matches = get_matches();
foreach ($matches as $match_id => $match)
{
$matchdata = parse_post($match, $match_id);
order_match($matchdata, $pastmatches, $currentmatches, $upcomingmatches);
}
@usort($pastmatches, "compare_match_times");
@usort($currentmatches, "compare_match_times");
@usort($upcomingmatches, "compare_match_times");
print_matches($pastmatches, $currentmatches, $upcomingmatches);
}
function match_info ($id)
{
$match = get_match($id);
if ($match == 0)
{
echo "There is no such match. Return
";
return;
}
$matchdata = parse_post($match[$id], $id);
print_match($matchdata);
echo "Return
";
}
?>