· 8 years ago · Apr 22, 2018, 04:20 AM
1Readme!!!
2
31. Make a mc database
42. Import the database.sql
53. (might need to do) Make a virturalhost for www.minecraft.net
6
7 For Apache:
8 <VirtualHost *:80>
9 DocumentRoot /path/to/folder
10 ServerName www.minecraft.net
11 </VirtualHost>
12
134. Restart Apache
145. Make a folder named "game" in the root of the vitrual host's folder.
156. Copy the below code into the folder above using the names above them.
167. Edit your host file so that www.minecraft.net is pointing to the webserver's IP.
178. Enjoy.
18
19
20(make sure to make a .htaccess file with the following)
21<files *>
22ForceType application/x-httpd-php
23</files>
24
25
26getversion.jsp
27
28<?php
29include_once("mcproxy.php");
30
31if (isset($_POST['user']) && isset($_POST['password']) && isset($_POST['version'])) {
32
33 $host = "localhost"; // Host name
34 $username = "root"; // Mysql username
35 $password = ""; // Mysql password
36 $db_name = "mc"; // Database name
37 $tbl_name = "login"; // Table name
38 $cliver = $_POST['version'];
39 $version = "1291385898000"; // Current Minecraft version
40
41
42 // Connect to server and select databse.
43 mysql_connect("$host", "$username", "$password") or die("cannot connect");
44 mysql_select_db("$db_name") or die("cannot select DB");
45
46 $username = $_POST['user'];
47 $password = $_POST['password'];
48
49 // To protect MySQL injection
50 $username = stripslashes($username);
51 $password = stripslashes($password);
52 $username = mysql_real_escape_string($username);
53 $password = mysql_real_escape_string($password);
54
55 $sql = "SELECT * FROM $tbl_name WHERE username='$username' and password='$password'";
56 $result = mysql_query($sql);
57
58 $count = mysql_num_rows($result);
59
60 if ($count == 1) {
61 $sql = "SELECT sessionid FROM $tbl_name WHERE username='$username' LIMIT 1";
62 $result = mysql_query($sql);
63 $row = mysql_fetch_array($result);
64 $id = $row['sessionid'];
65
66 // Register $myusername, $mypassword and redirect to file "login_success.php"
67 echo $version . ":" . md5($username) . ":" . $username . ":" . $id . ":";
68 } else {
69 echo getData("getversion.jsp?user=$username&password=$password&version=$cliver");
70 //echo "Bad login"; // Can be used if you don't want to connect to minecraft.net
71 }
72}
73?>
74
75mcproxy.php
76
77<?php
78function getData($where)
79{
80 $ip = '194.28.157.42'; // Minecraft IP
81 $host = 'www.minecraft.net'; // Minecraft Host
82 $req = "/game/" . $where; // Base location to send the request
83 $fp = fsockopen($ip, 80, $errno, $errstr, 5);
84 $result = "";
85 if (!$fp) {
86 echo "Error";
87 } else {
88 // HTTP headers
89 $out = "GET $req HTTP/1.1\r\n";
90 $out .= "Host: $host\r\n";
91 $out .= 'User-Agent: Java/1.6.0_22';
92 $out .= "Connection: Close\r\n\r\n";
93
94 fwrite($fp, $out);
95 while (!feof($fp)) {
96 $result .= fgets($fp, 128);
97 }
98 fclose($fp);
99 $array = explode("\r", $result);
100 if (sizeof($array) > 7) { // Check if array is larger then a 404 reply.
101 $array[sizeof($array)-1] = str_replace("\n", "", $array[sizeof($array)-1]);
102 return $array[sizeof($array)-1]; // Where the "key" is at
103 } else {
104 return "Bad login";
105 }
106 }
107}
108?>
109
110
111register.php
112
113<?php
114$host = "localhost"; // Host name
115$username = "root"; // Mysql username
116$password = ""; // Mysql password
117$db_name = "mc"; // Database name
118$tbl_name = "login"; // Table name
119$id = mt_rand(9999999,9999999999999999);
120
121if (isset($_POST['username'])) {
122 // Make a MySQL Connection
123 mysql_connect($host, $username, $password) or die(mysql_error());
124 mysql_select_db($db_name) or die(mysql_error());
125
126 // Username
127 $tmpu = $_POST['username'];
128 $tmpu = stripslashes($tmpu);
129 $tmpu = mysql_real_escape_string($tmpu);
130 $tmpu = trim($tmpu);
131
132 // Password
133 $tmpp = $_POST['password'];
134 $tmpp = stripslashes($tmpp);
135 $tmpp = mysql_real_escape_string($tmpp);
136 $tmpp = trim($tmpp);
137
138 if (strlen($tmpu) != 0 && strlen($tmpp) != 0) { // Check if username is already used
139 $sql = "SELECT * from $tbl_name WHERE username = '$tmpu'";
140 $result = mysql_query($sql);
141 $count = mysql_num_rows($result);
142 if ($count == true) {
143 echo "<br>Username already registerd. Try again";
144
145 } else { // Add new username to database
146 mysql_query("INSERT INTO $tbl_name(username, password, sessionid) VALUES('$tmpu', '$tmpp', '$id') ") or
147 die(mysql_error());
148 echo "Registered with " . $_POST['username'] . " - " . $_POST['password'];
149 }
150 }
151
152
153}
154?>
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171<html>
172<body>
173<FORM ACTION="register.php" METHOD=POST>
174Username: <input type="text" name="username"><br>
175Password: <input type="text" name="password"><br>
176<input type="submit" value="Register">
177</FORM>
178</body>
179</html>
180
181checkserver.jsp
182
183<?php
184include_once("mcproxy.php");
185
186if (isset($_GET['user']) && isset($_GET['serverId'])) {
187 $srvid = $_GET['sessionId'];
188 $host = "localhost"; // Host name
189 $username = "root"; // Mysql username
190 $password = ""; // Mysql password
191 $db_name = "mc"; // Database name
192 $tbl_name = "login"; // Table name
193
194 $srvid = $_GET['serverId'];
195 $tmpname = $_GET['user'];
196
197 mysql_connect("$host", "$username", "$password") or die("cannot connect");
198 mysql_select_db("$db_name") or die("cannot select DB");
199 $result = mysql_query("SELECT * FROM $tbl_name WHERE username = '$tmpname' ") or // Select username from databse
200 die(mysql_error());
201 $row = mysql_fetch_array($result);
202
203 if ($row['username'] == $_GET['user'] && $row['serverid'] == $_GET['serverId']) { // Check to see if the username is registerd to the server
204 echo "YES";
205 die;
206 } else {
207 echo getData("checkserver.jsp?user=$tmpname&serverId=$srvid"); // Send request to minecraft.net to see if the user is valid
208 die;
209 }
210}
211?>
212
213database.sql
214
215-- phpMyAdmin SQL Dump
216-- version 3.2.4
217-- http://www.phpmyadmin.net
218--
219-- Host: localhost
220-- Generation Time: Nov 26, 2010 at 02:52 AM
221-- Server version: 5.1.41
222-- PHP Version: 5.3.1
223
224SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
225
226
227/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
228/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
229/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
230/*!40101 SET NAMES utf8 */;
231
232--
233-- Database: `mc`
234--
235
236-- --------------------------------------------------------
237
238--
239-- Table structure for table `login`
240--
241
242CREATE TABLE IF NOT EXISTS `login` (
243 `id` int(11) NOT NULL AUTO_INCREMENT,
244 `username` text NOT NULL,
245 `password` text NOT NULL,
246 `sessionid` text NOT NULL,
247 `serverid` text NOT NULL,
248 PRIMARY KEY (`id`),
249 UNIQUE KEY `id` (`id`)
250) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=12 ;
251
252/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
253/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
254/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
255
256
257joinserver.jsp
258
259<?php
260include_once("mcproxy.php");
261
262if (isset($_GET['sessionId']) && isset($_GET['user']) && isset($_GET['serverId'])) {
263 $sessid = $_GET['sessionId'];
264 $host = "localhost"; // Host name
265 $username = "root"; // Mysql username
266 $password = ""; // Mysql password
267 $db_name = "mc"; // Database name
268 $tbl_name = "login"; // Table name
269
270 $srvid = $_GET['serverId'];
271 $tmpname = $_GET['user'];
272
273 // Connect to server and select databse.
274 mysql_connect("$host", "$username", "$password") or die("cannot connect");
275 mysql_select_db("$db_name") or die("cannot select DB");
276
277 $result = mysql_query("SELECT * FROM $tbl_name WHERE username = '$tmpname' ") or // Select username from the database.
278 die(mysql_error());
279 $row = mysql_fetch_array($result);
280
281 if ($row['username'] == $_GET['user'] && $row['sessionid'] == $_GET['sessionId']) { // See if the username and password are in the database
282 echo "OK";
283 mysql_query("UPDATE login SET serverid = '$srvid' WHERE username= '$tmpname'") or
284 die(mysql_error());
285 } else {
286 echo getData("joinserver.jsp?user=$tmpname&sessionId=$sessid&serverId=$srvid"); // Send request to minecraft.net to see if the user is valid
287 die;
288 }
289}
290
291?>