bloor

chat.php

May 9th, 2012
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 14.83 KB | None | 0 0
  1. <script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script>
  2. <?php
  3.  
  4.         // RGC Login
  5.         $p = preg_replace(':/{2,}:', '/', $_SERVER['REQUEST_URI']);
  6.         $c = substr_count( $p, '/');
  7.         $__inc_base = ''; for($i=1;$i<$c;$i++) $__inc_base .= '../';
  8.         include_once $__inc_base.'login/login.php';
  9.  
  10. //ACCESS CHECKS
  11. check_access_channeladmin(); //no normal users
  12.  
  13. //dotacolors
  14. /*$dotacolor[0] = '#0000FF';
  15. $dotacolor[1] = '#66FFFF';
  16. $dotacolor[2] = '#660099';
  17. $dotacolor[3] = '#FFFF00';
  18. $dotacolor[4] = '#FF6600';
  19. $dotacolor[5] = '#FF66FF';
  20. $dotacolor[6] = '#999999';
  21. $dotacolor[7] = '#99CCFF';
  22. $dotacolor[8] = '#003300';
  23. $dotacolor[9] = '#330000';*/
  24.  
  25. $dotacolor[0] = '#4b72f0';
  26. $dotacolor[1] = '#5dbfd7';
  27. $dotacolor[2] = '#7353d9';
  28. $dotacolor[3] = '#d9d154';
  29. $dotacolor[4] = '#d8943c';
  30. $dotacolor[5] = '#cf8bde';
  31. $dotacolor[6] = '#94a2ab';
  32. $dotacolor[7] = '#81a1d1';
  33. $dotacolor[8] = '#49734f';
  34. //$dotacolor[9] = '#5d4c42';
  35. $dotacolor[9] = '#663300';
  36.  
  37. $___debug = 0;
  38. if($___debug) takeTime();
  39.  
  40. if(!$_GET['gid']) { echo "<center><h2>Invalid GameID</h2></center>"; exit; }  
  41.  
  42. DisplayStats($_GET['gid']);
  43.  
  44. function DisplayStats($gameid)
  45. {
  46.         global $___debug, $dotacolor;
  47.  
  48.         $gameid = (int)$gameid;
  49.  
  50.         // Get GameInfo
  51.         $sql = "SELECT g.gamename, g.channel_id, g.hosted, g.length, g.started, m.name, g.winner FROM game1_info g, client_maps m WHERE g.ID = '$gameid' AND m.ID = g.MapID";
  52.         $inforesult = ValueToArray(mysql_query($sql));
  53.         if($___debug) { echo "<b>[SQL] Select Game Info</b><br>"; takeTime(); }
  54.         if($inforesult['Total'] == 0) return;//die(echo("<b>There exists no game for the <font color='red'>GID $gameid</font></b>"));
  55.  
  56.         // Get GamePlayers
  57.         $sql = "SELECT a.name, p.player_id, p.status, p.Time, p.LeftReason, p.Kills, p.Deaths, p.Assists FROM game1_players p, client_accounts a WHERE a.ID = p.acc_id AND p.game_id = '$gameid'"; // ORDER BY Time ASC
  58.         $presult = ValueToArray(mysql_query($sql));
  59.  
  60.         // Get ChannelName
  61.         /*$sql = "SELECT name FROM client_channels WHERE channel_id = '".$inforesult[1]['channel_id']."'";
  62.         $cresult=ValueToArray(mysql_query($sql));
  63.         if($cresult['Total'] == 0) $cresult[1]*/
  64.         $cname = GetSingleResult(mysql_query("SELECT name FROM client_channels WHERE channel_id = '".$inforesult[1]['channel_id']."'"));
  65.         if(!isset($cname)) $cname = "<font color='gray'><i><b>Deleted Room</b></i></font>"; else $cname = BDecode($cname);
  66.         if($___debug) { echo "<b>[SQL] Select Channel Info</b><br>"; takeTime(); }
  67.  
  68.         //Check for global staff access
  69.         $headadmin = ($_SESSION['access'] == 2); // || $_SESSION['access'] == 13);
  70.        
  71.         //If not, check for channel the game was hosted on access!
  72.         if(!$headadmin) {
  73.                 $sql = "SELECT 1 FROM client_channelaccess WHERE channel_id = ".$inforesult[1]['channel_id']." AND access = 13 AND acc_id = '".$_SESSION['uid']."'";
  74.                 $vResult = ValueToArray(mysql_query($sql));
  75.                 $headadmin = ($vResult['Total'] != 0);
  76.         }
  77.  
  78.         //Special for Tiago, cancel games
  79.         //check if he has head admin in this channel
  80.         /*if($headadmin && ($_SESSION['uid']== 37830 || $_SESSION['uid']== 6)) {
  81.                 $cancel = true;
  82.         } else */ $cancel = false;
  83.  
  84.  
  85.         // NEW GAMENAME
  86.         if($gameid > 2598248) $inforesult[1]['gamename'] = BDecode($inforesult[1]['gamename']);
  87.  
  88.         if($headadmin) echo "<form action='change.php' method='get'>";
  89.         echo "<b>Game: </b> Warcraft III : The Frozen Throne<br>";
  90.         echo "<b>Map: </b> ".BDecode($inforesult[1]['name'])."<br>";
  91.         //echo "<b>Room: </b> ".BDecode($cresult[1]['name'])."<br>";
  92.         echo "<b>Room: </b> $cname<br>";
  93.         echo "<b>Name: </b> ".$inforesult[1]['gamename']."<br>";
  94.         echo "<b>Time: </b> ".date("d/m/Y - H:i", $inforesult[1]['hosted'])."<br>";
  95.  
  96.         if($inforesult[1]['length'] != -1) echo "<b>Length: </b> ".TimeToStr($inforesult[1]['length'])."<br>";
  97.         else if($inforesult[1]['started']) echo "<b>Length: </b> ".TimeToStr(time() - $inforesult[1]['started'])." <font color='red'>(ongoing)</font><br>";
  98.         else echo "<b>Status: </b><font color='blue'>(Lobby)</font><br>";
  99.         echo "<br>";
  100.  
  101.         $winner = $inforesult[1]['winner'];
  102.         echo "<b>Stats</b>";
  103.         echo "<b> (Winner: </b>";       if($inforesult[1]['winner'] == 0) { echo "<i>None</i>"; }
  104.                                         if($inforesult[1]['winner'] == 1) { echo "<font color='green'>Sentinel</font>"; }
  105.                                         if($inforesult[1]['winner'] == 2) { echo "<font color='red'>Scourge</font>"; }
  106.                                         if($inforesult[1]['winner'] == 4) { echo "<i>None - Nulled Sentinel</i>"; }
  107.                                         if($inforesult[1]['winner'] == 5) { echo "<i>None - Nulled Scourge</i>"; }
  108.         echo "<b>)</b>";
  109.         echo "<hr>";
  110.  
  111.         //SELECT player_id, name, status, Time, Kills, Deaths, Assissts FROM game1_players p
  112.         if($headadmin) echo "<input type='hidden' name='gid' value='$gameid'>";
  113.  
  114.         // Sort presult by pid (this should not be needed, but you never know
  115.         for($i=1;$i<=$presult['Total'];$i++) {
  116.                 $up[$presult[$i]['player_id']] = $presult[$i];
  117.         } $up['Total'] = $presult['Total'];
  118.  
  119.        
  120.         echo "<table border=0><tr>";
  121.         if($headadmin) echo "<td></td>";
  122.         echo "<td><center>Player</td><td><center>K</td><td><center>D</td><td><center>A</td></tr>";
  123.  
  124.         // Process sorted presult, up=unprocessed players
  125.         for($i=1;$i<=10;$i++) {
  126.                 //if($i == 6) echo "<br>";
  127.                 if($i == 6) {
  128.                         echo "<tr>";
  129.                         if($headadmin) echo "<td></td>";
  130.                         echo "<td><center><font color='red'>VS</font></center></td><td></td><td></td><td></td>";
  131.                         echo "</tr>";
  132.                 }
  133.                 echo "<tr><td>";
  134.  
  135.                 if(!isset($up[$i])) {
  136.                         //echo "<font color='".$dotacolor[$i-1]."'>&lt;empty&gt;</font><br>";
  137.                         echo "<font color='".$dotacolor[$i-1]."'>&lt;Player $i&gt;</font><br>";
  138.                 } else {
  139.                         $up[$i]['cleanname'] = CleanString(BDecode($up[$i]['name']));
  140.  
  141.                         if($headadmin) echo "<input type='checkbox' name='$i' value='";
  142.                         $font = "<font color='"; if($up[$i]['status'] == 0) {
  143.                                 if($headadmin) echo "2";
  144.                                 $font .= "black";
  145.                         } else {
  146.                                 if($headadmin) echo "1";
  147.                                 $p = $up[$i]['player_id'] - 1;
  148.                                 if($p >= 5 * ($winner - 1) && $p < 5 * $winner) $font .= "orange";
  149.                                 else $font .= "red";
  150.                         } $font .= "'>";
  151.                         if($headadmin) echo "' /></td><td>";
  152.  
  153.                         echo $font."[".TimeToStr($up[$i]['Time'])."]</font> ";
  154.  
  155.                         echo "<a href='search.php?m=0&var=".BDecode($up[$i]['name'])."'><font color='".$dotacolor[$i-1]."'>".$up[$i]['cleanname']."</font></a>";
  156.                         //echo " ---".$up[$i]['Kills']." - ".$up[$i]['Deaths']." - ".$up[$i]['Assists']."<br>";
  157.                         //echo " ".$up[$i]['Kills']." / ".$up[$i]['Deaths']." / ".$up[$i]['Assists']."<br>";
  158.                         $ex = "</td><td><center><font color='".$dotacolor[$i-1]."'>";
  159.                         echo $ex.$up[$i]['Kills'].$ex.$up[$i]['Deaths'].$ex.$up[$i]['Assists'];
  160.                 }
  161.  
  162.                 echo "</td></tr>";
  163.         }
  164.         echo "</table>";
  165.  
  166.         if($___debug) { echo "<b>[SQL] Set Players</b><br>"; takeTime(); }
  167.  
  168.         echo "<br>";
  169.         if($up['Total'] != 0 && $headadmin) echo "<input type='submit' value='Change'></form>";
  170.  
  171.         if($up['Total'] != 0 && $cancel && $up[1]['winner']) { //No winner, no cancel
  172.                 if($up[1]['winner'] < 3) $actionName = "Cancel Game";
  173.                 else $actionName = "Rescore Game";
  174.  
  175.                 echo "<form action='cancel.php' action='get'>";
  176.                 echo "<input type='hidden' name='gid' value='$gameid'>";
  177.                 echo "<input type='submit' value='$actionName'></form>";
  178.         }
  179.  
  180.         echo "<br>";
  181.         echo DisplayLobbyChat($gameid);
  182.  
  183.         // Add Fakeplayers (for ongoing games)
  184.         if($up['Total'] == 0) for($i=1;$i<11;$i++) {
  185.                 $up[$i]['cleanname'] = "Player ".$i;
  186.                 $up[$i]['LeftReason'] = 'game ongoing';
  187.                 $up[$i]['Time'] = 0;
  188.         }
  189.  
  190.         echo "<br><br>";
  191.         echo DisplayGameChat($gameid, $up);
  192. }
  193.  
  194. function DisplayLobbyChat($gameid)
  195. {
  196.         global $___debug;
  197.  
  198.         echo "<b>Lobby</b><hr>";
  199.         $sql="SELECT * FROM game1_chat_lobby WHERE game_id = '$gameid'";
  200.         $result=ValueToArray(mysql_query($sql));
  201. if($___debug) { echo "<b>[SQL] Select Lobby Chat</b><br>"; takeTime(); }
  202.  
  203.         for($i=0; $i<$result['Total']; $i++)
  204.         {
  205.                 echo "[".TimeToStr($result[$i+1]['time'])."] ";
  206.  
  207.                 //OLD LOGS
  208.                 if($gameid < 60552) echo $result[$i+1]['nickname'].": ".CleanString($result[$i+1]['message'])."<br>";
  209.                 else
  210.                 {
  211.                         $nick = CleanString(BDecode($result[$i+1]['nickname']));
  212.                         $msg = CleanString(BDecode($result[$i+1]['message']));
  213.                         if(!$nick) {
  214.                                 echo "<font color='gray'>".substr($msg, 1)." ";
  215.                                 if($msg[0] == "1") echo "has joined the game lobby.";
  216.                                 else if($msg[0] == "2") echo "has left the game lobby.";
  217.                                 echo "</font>";
  218.                         } else echo $nick.": ".$msg; //add to cleanstring maybe? //urldecode(utf8_decode(pack('H*', $result[$i+1]['nickname'])))
  219.                         echo '<br>';
  220.                 }      
  221.         }
  222.  
  223. if($___debug) { echo "<b>[Arrange] Lobby Chat</b><br>"; takeTime(); }
  224. }
  225.  
  226. function DisplayGameChat($gameid, $players)
  227. {
  228.         global $___debug, $dotacolor;
  229.  
  230.         //$sql="SELECT * FROM game1_chat_ingame WHERE game_id=".$gameid." ORDER BY time ASC";
  231.         $sql="SELECT time, message, player_id, status FROM game1_chat_ingame WHERE game_id = '$gameid' ORDER BY time ASC";
  232.         $result=ValueToArray(mysql_query($sql));
  233. if($___debug) { echo "<b>[SQL] Select Ingame Chat</b><br>"; takeTime(); }
  234.        
  235.         echo "<b>Ingame</b><hr>";
  236.  
  237.         echo "<div style='position: relative; height: 50px; width: 100%;'>";        
  238.         //Add leaving as an event
  239.         $eCC = 0;
  240.         for($i=1;$i<=10;$i++) {
  241.                 echo "<input type='button' value='".$players[$i]['cleanname']."' class='playerChat' id='".$i."' style='float: left; margin: 5px 5px 0px 0px; width: 150px; height: 30px; color: ".$dotacolor[$i-1]."'>";
  242.  
  243.                 if(isset($players[$i])) {
  244.                         $event[$eCC]['time'] = $players[$i]['Time'];
  245.                         $event[$eCC]['desc'] = "<font color='".$dotacolor[$i-1]."'>".$players[$i]['cleanname']." ".$players[$i]['LeftReason']."</font>";
  246.                         $eCC++;
  247.                 }
  248.         }
  249.  
  250.         </div>
  251. if($___debug) { echo "<b>[Arrange] Add Leaver Event</b><br>"; takeTime(); }
  252.  
  253.         // Bubble Sort - for Left Times, SORT ASC
  254.         for($x = 0; $x < count($event); $x++) {
  255.                 for($y = 0; $y < count($event); $y++) {
  256.                         if($event[$x]['time'] < $event[$y]['time']) {
  257.                                 $hold = $event[$x];
  258.                                 $event[$x] = $event[$y];
  259.                                 $event[$y] = $hold;
  260.                         }
  261.                 }
  262.         }
  263. if($___debug) { echo "<b>[Arrange] Bubble Sort</b><br>"; takeTime(); }
  264.         //////// ingame chat div.
  265.         echo "<div style='height: auto; width: 100%; float: left; position: relative;'>"
  266.         $eCC = 0;
  267.         for($i=0; $i<$result['Total']; $i++)
  268.         {
  269.                 $pid = $result[$i+1]['player_id']
  270.                
  271.                 if(isset($event[$eCC]) && ($event[$eCC]['time'] <= $result[$i+1]['time']))
  272.                 {
  273.                         $time = $event[$eCC]['time'];
  274.                         $desc = $event[$eCC]['desc'];
  275.                         $eCC++;
  276.                         $i--;
  277.                 }
  278.                 else
  279.                 {
  280.                         $time = $result[$i+1]['time'];
  281.  
  282.                         if($pid > 10) $desc = "<font color='darkred'>[Referee] ";
  283.                         else {
  284.                                 $desc = "<font color='".$dotacolor[$pid-1]."'>".$players[$pid]['cleanname']."</font>";//": ";
  285.  
  286.                                 if($result[$i+1]['status'] == 0) $desc .= ": ";
  287.                                 else if($result[$i+1]['status'] == 1) {
  288.                                         if($pid >= 1 && $pid <= 5)
  289.                                                 $desc .= "<font color='green'> (Sentinel): ";
  290.                                         else
  291.                                                 $desc .= "<font color='red'> (Scourge): ";
  292.                                 }
  293.                                 else $desc .= " (Private): ";
  294.                         }
  295.                        
  296.                         if($gameid < 60552) $desc .= CleanString($result[$i+1]['message']);
  297.                         else $desc .= CleanString(BDecode($result[$i+1]['message']));
  298.  
  299.                         $desc .= "</font>";
  300.                 }
  301.  
  302.                 echo "<div class='player-".$pid."' style='float: left; clear: left;'>[".TimeToStr($time)."]".$desc."</div>";
  303.         }
  304.  
  305.         // Show remaining events at the end of the chatlog
  306.         while (isset($event[$eCC])) {
  307.                 echo "<div style='float: left; clear: left;'> [".TimeToStr($event[$eCC]['time'])."]".$event[$eCC]['desc'];
  308.                 $eCC++;
  309.         }
  310.        echo "</div>";
  311.  
  312. if($___debug) { echo "<b>[Arrange] Ingame Chat</b><br>"; takeTime(); }
  313. }
  314.  
  315. function CleanString($string) { return htmlspecialchars($string, ENT_QUOTES); }
  316. function TimeToStr($time)
  317. {
  318.         $min = floor($time / 60);
  319.         $sec = $time % 60;
  320.  
  321.         if(strlen($min) == 1) { $min = "0".$min; }
  322.         if(strlen($sec) == 1) { $sec = "0".$sec; }
  323.        
  324.         return $min.":".$sec;
  325. }
  326.  
  327. //Show how long it took to load the page
  328. if($___debug) totalTimeTaken();
  329.  
  330. ?>
  331.  
  332.  
  333. <script>
  334.        
  335.         $('.playerChat').click(function(){
  336.                 id = $(this).attr('id');
  337.                 $('.player-'+id).fadeToggle(100);
  338.         });
  339.  
  340. </script>
Advertisement
Add Comment
Please, Sign In to add comment