Chatbox
    Load More
    You don't have permission to chat.
Lupus

Newb surf stats panel

2 posts in this topic

I just did the whole Newb-Surf stats panel, including the record calculation in C# as a test/practice  @darkness .

I don't know if you have a better idea about how to go about this when we're rewriting this to php, but here it is.

 

using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Diagnostics;

namespace Backend
{
    public partial class NewbsurfTestPanel : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            MySql.Data.MySqlClient.MySqlConnection conn;
            
            string myConnectionString;
            
            myConnectionString = "server=slayersfastdl.site.nfoservers.com;uid=slayersfastdl;" +
                "pwd=GF45N&^*&%NKJklBIUZ;database=slayersfastdl_cksurf;";
            try
            {
                conn = new MySql.Data.MySqlClient.MySqlConnection();
                conn.ConnectionString = myConnectionString;
                conn.Open();
                List<string> mapList = new List<string>();
                //get all map names with valid times
                string getMaps = "SELECT DISTINCT mapname FROM `ck_playertimes`";      
                MySqlCommand cmd = new MySqlCommand(getMaps, conn);
                MySqlDataReader rdr = cmd.ExecuteReader();
                while (rdr.Read())
                {
                    mapList.Add(rdr["mapname"].ToString());
                }
                rdr.Close();
                List<string> recordholderIdList = new List<string>();

                //get the steamid from the best run on every map
                foreach (string map in mapList)
                {
                    string getRecords = "SELECT steamid FROM `ck_playertimes` WHERE mapname = '" + map + "' ORDER BY runtimepro ASC LIMIT 1";
                    Literal1.Text += getRecords + "<br />";
                    MySqlCommand cmd2 = new MySqlCommand(getRecords, conn);
                    MySqlDataReader rdr2 = cmd2.ExecuteReader();
                    while (rdr2.Read())
                    {
                        recordholderIdList.Add(rdr2["steamid"].ToString());
                    }
                    rdr2.Close();
                }

                //make a list for every value category
                //mysql wouldn't let me do connections within connections, so i save first and then work within a loop
                List<string> name = new List<string>();
                List<string> steamid = new List<string>();
                List<string> points = new List<string>();
                List<string> mapcompletions = new List<string>();
                List<string> lastseen = new List<string>();
                List<string> bonuscount = new List<string>();

                string getTop50 = "SELECT * FROM ck_playerrank ORDER BY points DESC LIMIT 50";
                MySqlCommand cmd3 = new MySqlCommand(getTop50, conn);
                MySqlDataReader rdr3 = cmd3.ExecuteReader();           
                while (rdr3.Read())
                {
                    name.Add(rdr3["name"].ToString());
                    steamid.Add(rdr3["steamid"].ToString());
                    points.Add(rdr3["points"].ToString());
                    mapcompletions.Add(rdr3["finishedmaps"].ToString());
                    lastseen.Add(rdr3["lastseen"].ToString());
                }
                rdr3.Close();

                //prepare table                              
                Literal1.Text = string.Format(@"
<table>
    <tr>
        <td>Rank</td>
        <td>Name</td>
        <td>Points</td>
        <td>Maps</td>
        <td>Records</td>
        <td>Bonuses</td>
        <td>Lastseen</td>
    </tr>");  
                for (int i = 0; i < 50; i++)
                {
                    //get the value of how many times bonus stages the player has beaten (string, not int)
                    string getBonusCompletions = "SELECT COUNT(*) AS bonuscount FROM `ck_bonus` WHERE steamid = '" + steamid.ElementAt(i) + "' LIMIT 1";
                    MySqlCommand cmd4 = new MySqlCommand(getBonusCompletions, conn);
                    MySqlDataReader rdr4 = cmd4.ExecuteReader();
                    string bonuscountString = "0";
                    while (rdr4.Read())
                    {
                        bonuscountString = rdr4["bonuscount"].ToString();
                        bonuscount.Add(bonuscountString);
                    }
                    rdr4.Close();

                    //count how many times the current steamid is in the records list
                    int records = recordholderIdList.FindAll(s => s.Equals(steamid.ElementAt(i))).Count();
                        
                    //spit out all the collected data in the table
                    Literal1.Text += string.Format(@"
    <tr>
        <td>{0}</td>
        <td>{1}</td>
        <td>{2}</td>
        <td>{3}</td>
        <td>{4}</td>
        <td>{5}</td>
        <td>{6}</td
    </tr>", i+1, name.ElementAt(i), points.ElementAt(i), mapcompletions.ElementAt(i), records, bonuscount.ElementAt(i), lastseen.ElementAt(i));
                }

            }
            catch (MySql.Data.MySqlClient.MySqlException ex)
            {
                Literal1.Text = (ex.Message);
            }
        }
    }
}

 

President Evil likes this

 

Share this post


Link to post
Share on other sites
<?php

	function CheckCache($fileName, $time) {
	    return ((file_exists($fileName)) && (filemtime($fileName) > (time() - $time))) ? unserialize(file_get_contents($fileName)) : false;
	}

	$fname = "top_50_cache.txt";
	$cached = CheckCache($fname, 60 * 60 * 24);
	if($cached !== false) {
		header("content-type: application/json; charset=utf-8");
		echo json_encode($cached);
	} else {
		$database = array(
			"host" => "slayersfastdl.site.nfoservers.com",
			"username" => "slayersfastdl",
			"password" => "GF45N&^*&%NKJklBIUZ",
			"db" => "slayersfastdl_cksurf",
		);

		$connection = mysqli_connect($database["host"], $database["username"], $database["password"], $database["db"]);
		//@Lupus, never tell the user what the SQL error is.
		if(!$connection)
			exit("Failed to connect.");

		mysqli_set_charset($connection, "utf8");
		$maps = array();
		$record_holders = array();
		$top50 = array();

		$results = $connection->query("SELECT DISTINCT mapname FROM ck_playertimes");
		if($results->num_rows > 0) {
			while($row = mysqli_fetch_assoc($results)) {
				$maps[] = $row["mapname"];
			}
		} else {
			$connection->close();
			exit();
		}

		foreach($maps as $map) {
			$results = $connection->query("SELECT steamid FROM ck_playertimes WHERE mapname = '".$map."' ORDER BY runtimepro ASC LIMIT 1");
			if($results->num_rows == 0) continue;
			while($row = mysqli_fetch_assoc($results)) {
				$record_holders[] = $row["steamid"];
			}
		}
		$results = $connection->query("SELECT *, (SELECT COUNT(*) FROM ck_bonus WHERE steamid = ck_playerrank.steamid) as bonus_count FROM ck_playerrank ORDER BY points DESC LIMIT 50");
		if($results->num_rows > 0) {
			$data;
			while($row = mysqli_fetch_assoc($results)) {
				$data = array();
				$data["name"] = $row["name"];
				$data["steamid"] = $row["steamid"];
				$data["points"] = $row["points"];
				$data["finishedmaps"] = $row["finishedmaps"];
				$data["lastseen"] = $row["lastseen"];
				$data["bonus_count"] = $row["bonus_count"];
				$count = 0;
				foreach($record_holders as $steamid)
					if($steamid == $data["steamid"])
						$count++;
				$data["record_count"] = $count;
				$top50[] = $data;
			}
		} else {
			$connection->close();
			exit();
		}

		$connection->close();
		$json = array();
		foreach($top50 as $player) {
			$json["top_50"][count($json["top_50"])] = $player;
		}
		header("content-type: application/json; charset=utf-8");
		echo json_encode($json);
		file_put_contents($fname, serialize($json));
		exit();
	}
?>

json output

 

{"top_50":[{"name":"Hergs","steamid":"STEAM_1:1:21375352","points":"46901","finishedmaps":"68","lastseen":"2016-04-28","bonus_count":"33","record_count":3},{"name":"joeytman (voice_enable 1)","steamid":"STEAM_1:1:31220286","points":"44458","finishedmaps":"88","lastseen":"2016-04-28","bonus_count":"19","record_count":3},{"name":"Kurae [Kz-Loli]","steamid":"STEAM_1:1:16920249","points":"41565","finishedmaps":"44","lastseen":"2016-04-28","bonus_count":"26","record_count":38},{"name":"Bibbi","steamid":"STEAM_1:1:48973396","points":"36794","finishedmaps":"74","lastseen":"2016-04-28","bonus_count":"31","record_count":2},{"name":"nvg | Vuji","steamid":"STEAM_1:0:95772599","points":"34128","finishedmaps":"87","lastseen":"2016-04-25","bonus_count":"20","record_count":2},{"name":"Asteral","steamid":"STEAM_1:1:59677601","points":"33791","finishedmaps":"65","lastseen":"2016-04-28","bonus_count":"11","record_count":7},{"name":"KEBA","steamid":"STEAM_1:0:81778795","points":"29102","finishedmaps":"85","lastseen":"2016-04-21","bonus_count":"6","record_count":0},{"name":"Valuedjoe","steamid":"STEAM_1:0:64889644","points":"28952","finishedmaps":"34","lastseen":"2016-04-27","bonus_count":"20","record_count":14},{"name":"DuckE","steamid":"STEAM_1:1:16623016","points":"28543","finishedmaps":"60","lastseen":"2016-04-28","bonus_count":"14","record_count":0},{"name":"Lupus","steamid":"STEAM_1:1:10615313","points":"26013","finishedmaps":"53","lastseen":"2016-04-28","bonus_count":"3","record_count":10},{"name":"what","steamid":"STEAM_1:1:14281397","points":"24051","finishedmaps":"47","lastseen":"2016-04-28","bonus_count":"16","record_count":2},{"name":"lulz","steamid":"STEAM_1:1:120514905","points":"23503","finishedmaps":"35","lastseen":"2016-04-28","bonus_count":"15","record_count":6},{"name":"Rubby","steamid":"STEAM_1:0:36226264","points":"22440","finishedmaps":"48","lastseen":"2016-04-26","bonus_count":"4","record_count":5},{"name":"Zippy (Trading)","steamid":"STEAM_1:1:79651008","points":"20045","finishedmaps":"58","lastseen":"2016-04-29","bonus_count":"4","record_count":1},{"name":"nvg Stormcrow","steamid":"STEAM_1:1:616006","points":"20008","finishedmaps":"28","lastseen":"2016-04-23","bonus_count":"18","record_count":4},{"name":"CrumZ","steamid":"STEAM_1:1:149118520","points":"19831","finishedmaps":"47","lastseen":"2016-04-28","bonus_count":"5","record_count":0},{"name":"Ho Chi Minh Trail to Depression","steamid":"STEAM_1:1:158883653","points":"19634","finishedmaps":"44","lastseen":"2016-04-29","bonus_count":"10","record_count":0},{"name":"Finale","steamid":"STEAM_1:0:78337540","points":"19027","finishedmaps":"42","lastseen":"2016-04-29","bonus_count":"13","record_count":1},{"name":"Witty [Name Here] -> Auto","steamid":"STEAM_1:0:91254082","points":"16114","finishedmaps":"32","lastseen":"2016-04-25","bonus_count":"6","record_count":3},{"name":"mysticmints","steamid":"STEAM_1:0:48968843","points":"15057","finishedmaps":"37","lastseen":"2016-04-27","bonus_count":"9","record_count":0},{"name":"StriK3\u265e","steamid":"STEAM_1:1:22314698","points":"13774","finishedmaps":"39","lastseen":"2016-04-28","bonus_count":"3","record_count":0},{"name":"Reerzero","steamid":"STEAM_1:0:40069953","points":"13529","finishedmaps":"40","lastseen":"2016-04-28","bonus_count":"10","record_count":0},{"name":"the monkey","steamid":"STEAM_1:1:49731228","points":"13183","finishedmaps":"45","lastseen":"2016-04-27","bonus_count":"11","record_count":0},{"name":"Coffee","steamid":"STEAM_1:0:15353741","points":"12592","finishedmaps":"49","lastseen":"2016-04-28","bonus_count":"4","record_count":0},{"name":"nvg Mayo \u00e2\u2020\u00ba OG Sensei","steamid":"STEAM_1:0:20599514","points":"11922","finishedmaps":"21","lastseen":"2016-04-27","bonus_count":"4","record_count":1},{"name":"Motap","steamid":"STEAM_1:0:61309836","points":"11906","finishedmaps":"52","lastseen":"2016-04-28","bonus_count":"7","record_count":0},{"name":"NakedGuyOnAcid","steamid":"STEAM_1:1:53060317","points":"11668","finishedmaps":"36","lastseen":"2016-04-29","bonus_count":"5","record_count":1},{"name":"ScoobyBoobys","steamid":"STEAM_1:1:79686697","points":"11512","finishedmaps":"36","lastseen":"2016-04-19","bonus_count":"7","record_count":0},{"name":"Fujini","steamid":"STEAM_1:1:48747056","points":"11341","finishedmaps":"47","lastseen":"2016-04-28","bonus_count":"9","record_count":0},{"name":"nvg Blackout\u265a","steamid":"STEAM_1:1:79609878","points":"10971","finishedmaps":"43","lastseen":"2016-04-28","bonus_count":"3","record_count":0},{"name":"flumbo","steamid":"STEAM_1:0:64380971","points":"10685","finishedmaps":"25","lastseen":"2016-04-28","bonus_count":"3","record_count":0},{"name":"Frosty","steamid":"STEAM_1:0:63638025","points":"9278","finishedmaps":"38","lastseen":"2016-04-27","bonus_count":"1","record_count":0},{"name":"Claire Underwood","steamid":"STEAM_1:0:118205407","points":"9272","finishedmaps":"45","lastseen":"2016-04-28","bonus_count":"3","record_count":0},{"name":"dazzLe","steamid":"STEAM_1:1:114270017","points":"8579","finishedmaps":"34","lastseen":"2016-04-29","bonus_count":"2","record_count":1},{"name":"erik :]","steamid":"STEAM_1:0:83646686","points":"8204","finishedmaps":"26","lastseen":"2016-04-28","bonus_count":"6","record_count":0},{"name":"nvg | EmJov","steamid":"STEAM_1:1:11797178","points":"7967","finishedmaps":"28","lastseen":"2016-04-29","bonus_count":"4","record_count":0},{"name":"The Real Hello","steamid":"STEAM_1:1:84733840","points":"7937","finishedmaps":"41","lastseen":"2016-04-16","bonus_count":"4","record_count":0},{"name":"ILoveVrack","steamid":"STEAM_1:0:43722137","points":"7913","finishedmaps":"40","lastseen":"2016-04-28","bonus_count":"3","record_count":0},{"name":"Mr.RecycleShit","steamid":"STEAM_1:1:104782097","points":"7408","finishedmaps":"38","lastseen":"2016-04-26","bonus_count":"3","record_count":0},{"name":"Steve Alahan","steamid":"STEAM_1:0:60859675","points":"6959","finishedmaps":"30","lastseen":"2016-04-28","bonus_count":"1","record_count":0},{"name":"Chef","steamid":"STEAM_1:1:60785682","points":"6660","finishedmaps":"30","lastseen":"2016-04-20","bonus_count":"1","record_count":0},{"name":"Joey9725","steamid":"STEAM_1:1:49753458","points":"6304","finishedmaps":"28","lastseen":"2016-04-28","bonus_count":"2","record_count":0},{"name":"Squirrel","steamid":"STEAM_1:1:24100031","points":"6296","finishedmaps":"37","lastseen":"2016-04-24","bonus_count":"0","record_count":0},{"name":"VictimofScience","steamid":"STEAM_1:1:17536040","points":"6222","finishedmaps":"33","lastseen":"2016-04-28","bonus_count":"5","record_count":0},{"name":"Insane in the Memebrane","steamid":"STEAM_1:1:104930629","points":"6156","finishedmaps":"22","lastseen":"2016-04-28","bonus_count":"2","record_count":0},{"name":"BoBo","steamid":"STEAM_1:0:50078204","points":"6028","finishedmaps":"28","lastseen":"2016-04-29","bonus_count":"2","record_count":0},{"name":"Sleep","steamid":"STEAM_1:1:117446040","points":"5719","finishedmaps":"33","lastseen":"2016-04-25","bonus_count":"4","record_count":0},{"name":"BerrieSK","steamid":"STEAM_1:0:141539260","points":"5676","finishedmaps":"23","lastseen":"2016-04-14","bonus_count":"0","record_count":0},{"name":"Karl","steamid":"STEAM_1:0:116267825","points":"5651","finishedmaps":"27","lastseen":"2016-04-15","bonus_count":"1","record_count":0},{"name":"K\u3093sai","steamid":"STEAM_1:0:58964980","points":"5538","finishedmaps":"30","lastseen":"2016-04-26","bonus_count":"6","record_count":0}]}

demo: https://www.slayersgaming.com/darkness/test/newb_panel.php


anti ban script

Share this post


Link to post
Share on other sites

  • Recently Browsing   0 members

    No registered users viewing this page.