Thread: Server Status page like no other!

Page 1 of 3 123 LastLast
Results 1 to 10 of 26
  1. #1 Server Status page like no other! 
    Respected Member

    Join Date
    Jan 2009
    Posts
    5,682
    Thanks given
    1,093
    Thanks received
    3,494
    Discord
    View profile
    Rep Power
    5000
    Purpose: To create a Server Status page like no other! See picture: [Only registered and activated users can see links. ]
    Difficulty: 5?
    Assumed Knowledge: Java, If you do not how MySQL works please do not go any futher.
    Classes Modified: Process? Server? What ever your main loop thread is in...

    Ok so first of all you will need the PHP file on your server and also connecting to your MySQL Database.

    Code:
    <?php
    
    /**
     * @author Stuart
     * @copyright 2010
     */
     
    $status = new status();
    
    $status->getStatus();
    
    
    ?>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html>
    <head>
    	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    	<title>Server Status Page</title>
    	<link rel="stylesheet" href="style.css" media="screen" />
    </head>
    <body>
    	<div id="wrapper">
    		<table width="100%" border="0" cellspacing="1" cellpadding="3" class="stats_table">
    			<tr class="stats_head">
    				<th class="stats_th" colspan="4">Server Status for SERVERNAME HERE</th>
    			</tr>
     			<tr>
    				<th class="stats_th">Server Status:</th> 
    				<td class="stats_td"><?php echo $status->status; ?></td>
    				<th class="stats_th">Server Uptime:</th> 
    				<td class="stats_td"><?php echo $status->uptime; ?></td>
    			</tr>
     			<tr>
    				<th class="stats_th">Online Players:</th> 
    				<td class="stats_td"><?php echo $status->players; ?></td>
    				<th class="stats_th">Online Peak:</th> 
    				<td class="stats_td"><?php echo $status->peek; ?></td>
    		</table>
    		
    		<?php if($status->status != "offline" && $status->players != 0) { ?>
    		
    		<table width="100%" border="0" cellspacing="1" cellpadding="2" class="stats_table">
    			<tr class="stats_head">
    				<th class="stats_th" colspan="6">Online Players</th> 
    			</tr>
    			<tr>
    				<th class="stats_th">Name</th> 
    				<th class="stats_th">Combat Level</th>
    				<th class="stats_th">Total Level</th>
    				<th class="stats_th">Total EXP</th>
    				<th class="stats_th">Rank</th>
    				<th class="stats_th">Highscores</th>
    			</tr>
    				
    <?php echo $status->getOnline(); ?>
    				
    		</table>
    		
    		<?php } ?>
    	</div>
    </body>
    </html>
    
    <?php
    
    class status
    {
    
        var $connected;
        var $time;
        var $status;
    	var $uptime;
    	var $players;
    	var $peek;
    
        function status()
        {
            $this->connected = false;
            $this->time = time();
        }
    
        function getStatus()
        {
            $query = $this->query("SELECT * FROM `status`");
            $row = mysql_fetch_array($query);
            $status = $row['status'];
            $timerequested = $row['time'];
            if ($this->time - $timerequested > 600) {
                $this->updateStatus();
                $query = $this->query("SELECT * FROM `status`");
                $row = mysql_fetch_array($query);
                $status = $row['status'];
            }
    		$this->peek = $row['peek'];
            if ($status == 0) {
    			$this->status = "offline";
    			$this->uptime = "N/A";
    			$this->players = "N/A";
            } else {
    			$this->status = "online";
    			$this->uptime = $row['servertime'];
    			$this->players = $row['online'];
            }
        }
    
        function updateStatus()
        {
            $checkport = @fsockopen("127.0.0.1", 3424, $errnum, $errstr, 2);
            if ($checkport) {
                $this->query("UPDATE status SET status = '1', time = '" . $this->time . "'");
            } else {
                $this->query("UPDATE status SET status = '0', time = '" . $this->time . "'");
            }
        }
    
    	function getOnline() 
    	{
    		$content = "";
    		
    		$result = $this->query("SELECT * FROM playersonline");
    			
    		while($players = mysql_fetch_assoc($result)) {
    			$content .= "\t\t\t<tr>\r";
    			$content .= "\t\t\t\t<td class=\"stats_td\">".$players['name']."</td>\r"; 
    			$content .= "\t\t\t\t<td class=\"stats_td\">".$players['combat']."</td>\r";
    			$content .= "\t\t\t\t<td class=\"stats_td\">".$players['total']."</td>\r"; 
    			$content .= "\t\t\t\t<td class=\"stats_td\">".$players['exp']."</td>\r"; 
    			if($players['level'] == 0) {
    				$content .= "\t\t\t\t<td class=\"stats_td\">Player</td>\r"; 
    			} elseif($players['level'] == 1) {
    				$content .= "\t\t\t\t<td class=\"stats_td\">Moderator</td>\r"; 
    			} elseif($players['level'] == 2) {
    				$content .= "\t\t\t\t<td class=\"stats_td\">Admin</td>\r"; 
    			} else {
    				$content .= "\t\t\t\t<td class=\"stats_td\">Owner</td>\r"; 
    			}
    			$content .= "\t\t\t\t<td class=\"stats_td\"><a href=\"http://domain.com/highscores/index.php?name=".$players['name']."\">Highscores ".$players['name']."</a></td>\r";
    			$content .= "\t\t\t</tr>\r"; 
    		}
    		return $content;
    	}
    
        function connect()
        {
            if ([email protected]_connect("127.0.0.1", "username", "password")) {
                $this->error("Error connecting to database!");
            }
            if ([email protected]_select_db("databasename")) {
                $this->error("Could not select database!");
            }
            $this->connected = true;
        }
    
        function query($query)
        {
            if (!$this->connected)
                $this->connect();
            $qd = mysql_query($query);
            if (!$qd)
                $this->error("Could not run query: " . $query);
            return $qd;
        }
    
        function error($err)
        {
            die($err);
        }
    }
    
    ?>
    You will need to edit the function:

    Code:
        function connect()
        {
            if ([email protected]_connect("127.0.0.1", "username", "password")) {
                $this->error("Error connecting to database!");
            }
            if ([email protected]_select_db("databasename")) {
                $this->error("Could not select database!");
            }
            $this->connected = true;
        }
    Replace username, password, databasename with your MySQL login details

    Once you have that on your server you are going to require the tables in which the script and server work with to store information, I suggest using phpmyadmin, mysql console or something which will enable you to run querys.

    Code:
    CREATE TABLE `playersonline` (
      `name` varchar(12) NOT NULL,
      `total` int(20) NOT NULL,
      `exp` int(20) NOT NULL,
      `level` mediumint(1) NOT NULL,
      `combat` int(3) NOT NULL
    )
    
    INSERT INTO `playersonline` (`name`, `total`, `exp`, `level`, `combat`) VALUES
    ('noob', 0, 0, 0, 0);
    
    CREATE TABLE `status` (
      `status` int(1) default NULL,
      `time` int(15) default NULL,
      `servertime` varchar(255) NOT NULL,
      `online` int(10) NOT NULL,
      `peek` int(10) NOT NULL
    ) 
    
    INSERT INTO `status` (`status`, `time`, `servertime`, `online`, `peek`) VALUES
    (1, 1268827223, '0 Minutes', 0, 0);
    Once you have done that the script you have uploaded to your server should work.

    Code:
    body {
    	padding: 0px;
    	margin: 0 auto;
    }
    #wrapper {
    	margin: 0 auto;
    	width: 700px;
    }
    
    
    
    table.stats_table {
    	background: #CCCCCC;
    	margin-bottom:20px;
    }
    
    td.stats_td {
    	background-color:#FFFFFF;
    	font-size:9pt;
    	border-top-style: none;
    	border-right-style: none;
    	border-bottom-style: none;
    	border-left-style: none;
    }
    
    th.stats_th {
    	background: #999999;
    	font-size:9pt;
    	text-align: left;
    	color:#FFFFFF;
    }
    
    
    
    tr.stats_head th {
    	text-align:center;
    	font-size:10pt;
    	color:#FFFFFF;
    	padding:5px;
    	background-color: #080b13;
    }
    Put this style.css in the same directory as the script change the colors / look to what you want...


    Now to actually update these stats server sided...

    In server define:

    Code:
    public static MySQL sql = new MySql();
    This creates a basic refrance to the class we are going to use.

    Next the class itself

    Code:
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Statement;
    
    public class MySQL {
    
    	public static Connection con = null;
    	public static Statement stm;
    
    	public static void destroyCon() {
    		try {
    			stm.close();
    			con.close();
    		} catch (Exception e) {
    			e.printStackTrace();
    		}
    	}
    
    	public static ResultSet query(String s) throws SQLException {
    		try {
    			if (s.toLowerCase().startsWith("select")) {
    				ResultSet rs = stm.executeQuery(s);
    				return rs;
    			} else {
    				stm.executeUpdate(s);
    			}
    			return null;
    		} catch (Exception e) {
    			Misc.println("MySQL Error:" + s);
    			e.printStackTrace();
    		}
    		return null;
    	}
    
    	public MySQL() {
    		try {
    			Class.forName("com.mysql.jdbc.Driver").newInstance();
    			con = DriverManager.getConnection(
    					"jdbc:mysql://127.0.0.1/databasename", "username", "password");
    			stm = con.createStatement();
    			updateStats();
    		} catch (Exception e) {
    			e.printStackTrace();
    		}
    	}
    
    	public void updateStats() {
    		try {
    			query("UPDATE status SET servertime = '"
    					+ Misc.getUptime(Settings.START_TIME) + "', online = '"
    					+ PlayerHandler.getPlayerCount() + "'");
    			Statement statement = con.createStatement();
    			String query = "SELECT * FROM status";
    			ResultSet results = statement.executeQuery(query);
    			while (results.next()) {
    				int amount = results.getInt("peek");
    				if (amount < PlayerHandler.getPlayerCount())
    					query("UPDATE status SET peek = '"
    							+ PlayerHandler.getPlayerCount() + "'");
    			}
    			query("DELETE FROM playersonline");
    			for (Player p : PlayerHandler.players) {
    				if (p == null || !p.isActive)
    					continue;
    				Client temp = (Client) p;
    				if ((temp != null) && !temp.disconnected && p.isActive) {
    					query("INSERT INTO playersonline values('"
    							+ temp.playerName + "', '" + temp.getTotalLevel()
    							+ "', '" + temp.getTotalXP() + "', '"
    							+ temp.playerRights + "', '" + temp.combatLevel
    							+ "')");
    					// HIGH SCORES IF YOU HAVE THEM ?saveHighScore(temp);
    				}
    			}
    		} catch (SQLException e) {
    			e.printStackTrace();
    		}
    	}
    }
    You will need to edit:

    Code:
    con = DriverManager.getConnection(
    					"jdbc:mysql://127.0.0.1/databasename", "username", "password");
    Place your mysql details.

    That's about it now this alters on how you want to do it, to update the stats I simply have used grahams event manager...

    Code:
    // in server  .java then run it when the server starts...
    	public static void serverTimer() {
    		EventManager.getSingleton().addEvent(new Event() {
    			public void execute(EventContainer c) {
    				//System.gc();
    				Server.sql.updateStats();
    				//ConnectionHandler.clearConnections();
    			}
    		}, 600000);
    	}
    Or you could add it your tick timer...

    Code:
    //declare 
    private long fiveMins = System.currentTimeMillis();
    
    				if(System.currentTimeMillis() - fiveMins > 300) {
    					fiveMins = System.currentTimeMillis();
    					Server.sql.updateStats();
    				}
    That all really depends on you to be honest...

    You may need to declare these / change the current functions to these

    Code:
    public int getTotalLevel() {
    	int level = 0;
    	for (int i = 0; i < 21; i++) {
    		level += getLevelForXP(playerXP[i]);
    	}
    	sendQuest("Total Lvl: " + total + "", 3984);
    	return level;
    }
    
    public int getTotalXP() {
    	int exp = 0;
    	for (int i = 0; i < 21; i++) {
    		exp += getXPForLevel(playerXP[i]);
    	}
    	return exp;
    }
    MySQL driver: [Only registered and activated users can see links. ]

    No other RuneScape server has anything close to this, I entirely coded this myself, feel free to leech or change to how you want, but if you repost this then please do leave the full url to this post and my name "Stuart" / "RogueX" in the post.

    Need any help post and ill try to assist you.

    NOTE: YOU MAY WANT TO REJECT YOUR WEBSERVER URL ON YOUR SERVER AS IT MAY CAUSE NULLING ON CRAPPY SERVERS! if(connection.contains(hostname)) socket.close();
    Reply With Quote  
     

  2. Thankful users:


  3. #2  
    Donator

    Ecstasy's Avatar
    Join Date
    Sep 2008
    Age
    26
    Posts
    5,032
    Thanks given
    324
    Thanks received
    596
    Rep Power
    843
    Meh, the page looks rather ugly no offense.

    Reply With Quote  
     

  4. #3  
    Registered Member

    Join Date
    Feb 2010
    Posts
    3,187
    Thanks given
    1,124
    Thanks received
    834
    Discord
    View profile
    Rep Power
    1514
    Haha looks fucking epic
    Reply With Quote  
     

  5. #4  
    Respected Member

    Join Date
    Jan 2009
    Posts
    5,682
    Thanks given
    1,093
    Thanks received
    3,494
    Discord
    View profile
    Rep Power
    5000
    I personally do not feel the need to make this look attractive to users of the community it is there for simply viewing and as a demo illustration of what the script achives. Like I said change to how you like it the back end is there for you all to use...
    Reply With Quote  
     

  6. #5  
    Super Donator

    Join Date
    Oct 2008
    Posts
    328
    Thanks given
    34
    Thanks received
    20
    Rep Power
    66
    He did the PHP part, lol. If you want something like this with looks, use PhotoShop.

    Good job. ++
    Reply With Quote  
     

  7. #6  
    Registered Member

    Join Date
    Jun 2008
    Posts
    734
    Thanks given
    8
    Thanks received
    14
    Rep Power
    148
    Amg loops are so cool!
    Code:
    for (int i = 0; i < 21; i++) {
        getLevelForXP(playerXP[i]);
    }
    S Quare Quxx: Raul > paladin end of the story
    Reply With Quote  
     

  8. #7  
    Respected Member

    Join Date
    Jan 2009
    Posts
    5,682
    Thanks given
    1,093
    Thanks received
    3,494
    Discord
    View profile
    Rep Power
    5000
    Quote Originally Posted by iMagico View Post
    Amg loops are so cool!
    Code:
    for (int i = 0; i < 21; i++) {
        getLevelForXP(playerXP[i]);
    }
    Does not add them up

    Code:
    int exp = 0;
    for (int i = 0; i < 21; i++) {
    	int a;
    	int b = exp;
    	a = getLevelForXP(playerXP[i]);
    	exp = a+b;
    }
    return exp;
    Will work though if you wanna be funny about things.
    Reply With Quote  
     

  9. #8  
    Banned

    Join Date
    Jun 2008
    Age
    24
    Posts
    2,313
    Thanks given
    485
    Thanks received
    231
    Rep Power
    0
    Quote Originally Posted by RogueX View Post
    Does not add them up

    Code:
    int exp = 0;
    for (int i = 0; i < 21; i++) {
    	int a;
    	int b = exp;
    	a = getLevelForXP(playerXP[i]);
    	exp = a+b;
    }
    return exp;
    Will work though if you wanna be funny about things.
    lolwut, a doesnt need to be there

    int totalExp = 0;
    for (int i = 0; i < playerLevels.length; i++) {
    totalExp += getLevelForXP(playerXP[i]);
    }


    Looks good btw.
    Reply With Quote  
     

  10. #9  
    Registered Member
    Xynth's Avatar
    Join Date
    May 2009
    Posts
    2,222
    Thanks given
    226
    Thanks received
    259
    Rep Power
    1155
    Nice.
    Reply With Quote  
     

  11. #10  
    Respected Member

    Join Date
    Jan 2009
    Posts
    5,682
    Thanks given
    1,093
    Thanks received
    3,494
    Discord
    View profile
    Rep Power
    5000
    Quote Originally Posted by Jinrake View Post
    lolwut, a doesnt need to be there

    int totalExp = 0;
    for (int i = 0; i < playerLevels.length; i++) {
    totalExp += getLevelForXP(playerXP[i]);
    }


    Looks good btw.
    Thank you, updated.

    int Leechers[] = {Sinzscapeowns, Atrix676, Markian, ShadowBarrage, XParadiseX, Division};

    if(Leechers.length){
    sendMessage("GTFO R-S and learn Java.");
    launchURL([Only registered and activated users can see links. ], true);
    }
    You do know that is completely wrong right?
    Reply With Quote  
     

Page 1 of 3 123 LastLast

Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •