From: APTX Date: Mon, 10 Jan 2011 21:40:32 +0000 (+0100) Subject: Add high score web page. X-Git-Url: https://gitweb.aptx.org/?a=commitdiff_plain;h=refs%2Fheads%2Fmaster;p=tim-server.git Add high score web page. --- diff --git a/chatserver.php b/chatserver.php index 5999c4f..f1d863e 100644 --- a/chatserver.php +++ b/chatserver.php @@ -61,6 +61,23 @@ function genkey() $client_names = array(); + +function sendAllButOne($message, array $clients, $socket) +{ + global $sock; + // send this to all the clients in the $clients array (except the first one, which is a listening socket) + foreach ($clients as $send_sock) { + + // if its the listening sock or the client that we got the message from, go to the next one in the list + if ($send_sock == $sock || $send_sock == $socket) + continue; + + // write the message to the client -- add a newline character to the end of the message + socket_write($send_sock, $message); + + } // end of broadcast foreach +} + while (true) { // create a copy, so $clients doesn't get modified by socket_select() $read = $clients; @@ -78,7 +95,7 @@ while (true) { $client_names[$newkey] = ''; // send the client a welcome message - socket_write($newsock, ">> Connected. There are ".(count($clients) - 1)." client(s) connected to the server\n>> Type /quit to closse chat view.\n"); + socket_write($newsock, ">> Connected. There are ".(count($clients) - 1)." client(s) connected to the server\n"); socket_getpeername($newsock, $ip); echo "New client connected: {$ip}\n"; @@ -98,45 +115,36 @@ while (true) { // check if the client is disconnected if ($data === false) { + sendAllButOne("<- " . $client_names[$key] . " disconnected.\n", $clients, $read_sock); // remove client for $clients array unset($clients[$key]); unset($client_names[$key]); echo "client disconnected.\n"; - // continue to the next client to read from, if any continue; } - + // trim off the trailing/beginning white spaces $data = trim($data); // check if there is any data after trimming off the spaces if (!empty($data)) { + // Auth if (empty($client_names[$key])) { $result = auth($data); - if ($result !== false) + if ($result === false) { - $client_names[$key] = $result; + socket_write($read_sock, ">> AUTH ERROR\n"); continue; } - socket_write($read_sock, ">> AUTH ERROR\n"); + $client_names[$key] = $result; + sendAllButOne("-> " . $result . " connected.\n", $clients, $read_sock); continue; } - $sender_name = $client_names[$key]; - // send this to all the clients in the $clients array (except the first one, which is a listening socket) - foreach ($clients as $send_sock) { - - // if its the listening sock or the client that we got the message from, go to the next one in the list - if ($send_sock == $sock || $send_sock == $read_sock) - continue; - - // write the message to the client -- add a newline character to the end of the message - socket_write($send_sock, $sender_name . ": " . $data."\n"); - - } // end of broadcast foreach - + // If authed, send the message to others + sendAllButOne($client_names[$key] . ": " . $data."\n", $clients, $read_sock); } } // end of reading foreach diff --git a/index.php b/index.php index d0e29e8..ee4d07c 100644 --- a/index.php +++ b/index.php @@ -12,9 +12,9 @@ switch($_GET['a']) case 'setscore': return set_score(); case 'score': - default: return score(); - die(); + default: + return score(true); } function login() { @@ -90,7 +90,7 @@ function success($message) '; } -function score() +function score($html = false) { global $entityManager; @@ -100,20 +100,40 @@ function score() ->setMaxResults(20) ->getResult(); - print "\n\n\t\n"; - $position = 0; - foreach ($myScores AS $score) + + if ($html) { - print "\t\t\n" - . "\t\t\t" . ++$position . "\n" - . "\t\t\t" . $score->getUser()->id() . "\n" - . "\t\t\t" . $score->getUser()->getName() . "\n" - . "\t\t\t" . $score->getGscore() . "\n" - . "\t\t\n"; + print "\n" + . "\n\t\n" + . "\t\t" . '' + . "\n\t\t" . '' + . "\n\t\tTIM Game High Scores\n" + . "\t\n\t\n\t\t

TIM Game High Scores

\n"; + foreach ($myScores AS $score) + { + print "\t\t
\n\t\t\t
\n" + . "\t\t\t\t
" . ++$position . "
\n" + . "\t\t\t\t" . $score->getUser()->getName() . "\n" + . "\t\t\t\t" . $score->getGscore() . "\n" + . "\t\t\t
\n\t\t
\n"; + } + print "\t\n\n"; + } + else + { + print "\n\n\t\n"; + foreach ($myScores AS $score) + { + print "\t\t\n" + . "\t\t\t" . ++$position . "\n" + . "\t\t\t" . $score->getUser()->id() . "\n" + . "\t\t\t" . $score->getUser()->getName() . "\n" + . "\t\t\t" . $score->getGscore() . "\n" + . "\t\t\n"; + } + print "\t\n\n"; } - print "\t
\n
\n"; - } function set_score() diff --git a/stripes.png b/stripes.png new file mode 100644 index 0000000..9f36727 Binary files /dev/null and b/stripes.png differ diff --git a/style.css b/style.css new file mode 100644 index 0000000..da9834a --- /dev/null +++ b/style.css @@ -0,0 +1,69 @@ +html { + height: 100%; + background-color: #343434; + background-image:url('stripes.png'); + background-attachment:fixed; +} + +body { + min-width: 600px; + max-width: 1000px; + margin: 0 auto; /* center */ padding: 0 20px; + color: white; + font-size 2em; +} + +h1 { + text-align: center +} + +.entrywrap { + width: 100%; + height: 40px; + margin-top: 3px; + margin-bottom: 3px; + background: rgba(192,192,192, 0.2); + border-radius: 10px; + -moz-border-radius: 10px; + -webkit-border-radius: 10px; + padding: 5px 5px 5px 5px; + display: table; +} + +.entry { + display: table-cell; vertical-align: middle; +} + +div.entrywrap:nth-child(2) { + color: gold; + font-size: 5em; +} + +div.entrywrap:nth-child(3) { + color: silver; + font-size: 4em; +} + +div.entrywrap:nth-child(4) { + color: brown; + font-size: 3em; +} + +.position { + float: left; + width: 33%; +} + +.user { + float: right; + clear: right; + text-align: right; + width: 33%; +} + +.score { + float: left; + text-align: center; + margin: auto; + width: 33%; +} \ No newline at end of file