Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Readme!!!
- 1. Make a mc database
- 2. Import the database.sql
- 3. (might need to do) Make a virturalhost for www.minecraft.net
- For Apache:
- <VirtualHost *:80>
- DocumentRoot /path/to/folder
- ServerName www.minecraft.net
- </VirtualHost>
- 4. Restart Apache
- 5. Make a folder named "game" in the root of the vitrual host's folder.
- 6. Copy the below code into the folder above using the names above them.
- 7. Edit your host file so that www.minecraft.net is pointing to the webserver's IP.
- 8. Enjoy.
- (make sure to make a .htaccess file with the following)
- <files *>
- ForceType application/x-httpd-php
- </files>
- getversion.jsp
- <?php
- include_once("mcproxy.php");
- if (isset($_POST['user']) && isset($_POST['password']) && isset($_POST['version'])) {
- $host = "localhost"; // Host name
- $username = "root"; // Mysql username
- $password = ""; // Mysql password
- $db_name = "mc"; // Database name
- $tbl_name = "login"; // Table name
- $cliver = $_POST['version'];
- $version = "1291385898000"; // Current Minecraft version
- // Connect to server and select databse.
- mysql_connect("$host", "$username", "$password") or die("cannot connect");
- mysql_select_db("$db_name") or die("cannot select DB");
- $username = $_POST['user'];
- $password = $_POST['password'];
- // To protect MySQL injection
- $username = stripslashes($username);
- $password = stripslashes($password);
- $username = mysql_real_escape_string($username);
- $password = mysql_real_escape_string($password);
- $sql = "SELECT * FROM $tbl_name WHERE username='$username' and password='$password'";
- $result = mysql_query($sql);
- $count = mysql_num_rows($result);
- if ($count == 1) {
- $sql = "SELECT sessionid FROM $tbl_name WHERE username='$username' LIMIT 1";
- $result = mysql_query($sql);
- $row = mysql_fetch_array($result);
- $id = $row['sessionid'];
- // Register $myusername, $mypassword and redirect to file "login_success.php"
- echo $version . ":" . md5($username) . ":" . $username . ":" . $id . ":";
- } else {
- echo getData("getversion.jsp?user=$username&password=$password&version=$cliver");
- //echo "Bad login"; // Can be used if you don't want to connect to minecraft.net
- }
- }
- ?>
- mcproxy.php
- <?php
- function getData($where)
- {
- $ip = '194.28.157.42'; // Minecraft IP
- $host = 'www.minecraft.net'; // Minecraft Host
- $req = "/game/" . $where; // Base location to send the request
- $fp = fsockopen($ip, 80, $errno, $errstr, 5);
- $result = "";
- if (!$fp) {
- echo "Error";
- } else {
- // HTTP headers
- $out = "GET $req HTTP/1.1\r\n";
- $out .= "Host: $host\r\n";
- $out .= 'User-Agent: Java/1.6.0_22';
- $out .= "Connection: Close\r\n\r\n";
- fwrite($fp, $out);
- while (!feof($fp)) {
- $result .= fgets($fp, 128);
- }
- fclose($fp);
- $array = explode("\r", $result);
- if (sizeof($array) > 7) { // Check if array is larger then a 404 reply.
- $array[sizeof($array)-1] = str_replace("\n", "", $array[sizeof($array)-1]);
- return $array[sizeof($array)-1]; // Where the "key" is at
- } else {
- return "Bad login";
- }
- }
- }
- ?>
- register.php
- <?php
- $host = "localhost"; // Host name
- $username = "root"; // Mysql username
- $password = ""; // Mysql password
- $db_name = "mc"; // Database name
- $tbl_name = "login"; // Table name
- $id = mt_rand(9999999,9999999999999999);
- if (isset($_POST['username'])) {
- // Make a MySQL Connection
- mysql_connect($host, $username, $password) or die(mysql_error());
- mysql_select_db($db_name) or die(mysql_error());
- // Username
- $tmpu = $_POST['username'];
- $tmpu = stripslashes($tmpu);
- $tmpu = mysql_real_escape_string($tmpu);
- $tmpu = trim($tmpu);
- // Password
- $tmpp = $_POST['password'];
- $tmpp = stripslashes($tmpp);
- $tmpp = mysql_real_escape_string($tmpp);
- $tmpp = trim($tmpp);
- if (strlen($tmpu) != 0 && strlen($tmpp) != 0) { // Check if username is already used
- $sql = "SELECT * from $tbl_name WHERE username = '$tmpu'";
- $result = mysql_query($sql);
- $count = mysql_num_rows($result);
- if ($count == true) {
- echo "<br>Username already registerd. Try again";
- } else { // Add new username to database
- mysql_query("INSERT INTO $tbl_name(username, password, sessionid) VALUES('$tmpu', '$tmpp', '$id') ") or
- die(mysql_error());
- echo "Registered with " . $_POST['username'] . " - " . $_POST['password'];
- }
- }
- }
- ?>
- <html>
- <body>
- <FORM ACTION="register.php" METHOD=POST>
- Username: <input type="text" name="username"><br>
- Password: <input type="text" name="password"><br>
- <input type="submit" value="Register">
- </FORM>
- </body>
- </html>
- checkserver.jsp
- <?php
- include_once("mcproxy.php");
- if (isset($_GET['user']) && isset($_GET['serverId'])) {
- $srvid = $_GET['sessionId'];
- $host = "localhost"; // Host name
- $username = "root"; // Mysql username
- $password = ""; // Mysql password
- $db_name = "mc"; // Database name
- $tbl_name = "login"; // Table name
- $srvid = $_GET['serverId'];
- $tmpname = $_GET['user'];
- mysql_connect("$host", "$username", "$password") or die("cannot connect");
- mysql_select_db("$db_name") or die("cannot select DB");
- $result = mysql_query("SELECT * FROM $tbl_name WHERE username = '$tmpname' ") or // Select username from databse
- die(mysql_error());
- $row = mysql_fetch_array($result);
- if ($row['username'] == $_GET['user'] && $row['serverid'] == $_GET['serverId']) { // Check to see if the username is registerd to the server
- echo "YES";
- die;
- } else {
- echo getData("checkserver.jsp?user=$tmpname&serverId=$srvid"); // Send request to minecraft.net to see if the user is valid
- die;
- }
- }
- ?>
- database.sql
- -- phpMyAdmin SQL Dump
- -- version 3.2.4
- -- http://www.phpmyadmin.net
- --
- -- Host: localhost
- -- Generation Time: Nov 26, 2010 at 02:52 AM
- -- Server version: 5.1.41
- -- PHP Version: 5.3.1
- SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
- /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
- /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
- /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
- /*!40101 SET NAMES utf8 */;
- --
- -- Database: `mc`
- --
- -- --------------------------------------------------------
- --
- -- Table structure for table `login`
- --
- CREATE TABLE IF NOT EXISTS `login` (
- `id` int(11) NOT NULL AUTO_INCREMENT,
- `username` text NOT NULL,
- `password` text NOT NULL,
- `sessionid` text NOT NULL,
- `serverid` text NOT NULL,
- PRIMARY KEY (`id`),
- UNIQUE KEY `id` (`id`)
- ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=12 ;
- /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
- /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
- /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
- joinserver.jsp
- <?php
- include_once("mcproxy.php");
- if (isset($_GET['sessionId']) && isset($_GET['user']) && isset($_GET['serverId'])) {
- $sessid = $_GET['sessionId'];
- $host = "localhost"; // Host name
- $username = "root"; // Mysql username
- $password = ""; // Mysql password
- $db_name = "mc"; // Database name
- $tbl_name = "login"; // Table name
- $srvid = $_GET['serverId'];
- $tmpname = $_GET['user'];
- // Connect to server and select databse.
- mysql_connect("$host", "$username", "$password") or die("cannot connect");
- mysql_select_db("$db_name") or die("cannot select DB");
- $result = mysql_query("SELECT * FROM $tbl_name WHERE username = '$tmpname' ") or // Select username from the database.
- die(mysql_error());
- $row = mysql_fetch_array($result);
- if ($row['username'] == $_GET['user'] && $row['sessionid'] == $_GET['sessionId']) { // See if the username and password are in the database
- echo "OK";
- mysql_query("UPDATE login SET serverid = '$srvid' WHERE username= '$tmpname'") or
- die(mysql_error());
- } else {
- echo getData("joinserver.jsp?user=$tmpname&sessionId=$sessid&serverId=$srvid"); // Send request to minecraft.net to see if the user is valid
- die;
- }
- }
- ?>
Add Comment
Please, Sign In to add comment