Skocz do zawartości
  • 👋 Witaj na MPCForum!

    Przeglądasz forum jako gość, co oznacza, że wiele świetnych funkcji jest jeszcze przed Tobą! 😎

    • Pełny dostęp do działów i ukrytych treści
    • Możliwość pisania i odpowiadania w tematach
    • System prywatnych wiadomości
    • Zbieranie reputacji i rozwijanie swojego profilu
    • Członkostwo w jednej z największych społeczności graczy

    👉 Dołączenie zajmie Ci mniej niż minutę – a zyskasz znacznie więcej!

    Zarejestruj się teraz

[Problem] Łączenie strony z serwerem.


iIvanowski

Rekomendowane odpowiedzi

Opublikowano

Siemka. Mam problem z połączniem servera z stroną, wydaje mi się, że wszystko jest dobrze ustawione. Może ktos pomóc 

 

Server.properties:

 

 

#Minecraft server properties
#Fri Oct 31 15:26:00 CET 2014
spawn-protection=1
query.port=25581
server-name=Nieetyczny
generator-settings=
force-gamemode=false
allow-nether=true
gamemode=0
enable-query=true
player-idle-timeout=0
difficulty=1
spawn-monsters=true
op-permission-level=4
announce-player-achievements=true
pvp=true
snooper-enabled=true
level-type=DEFAULT
hardcore=false
enable-command-block=false
max-players=200
rcon.port=28917
server-port=25581
debug=false
texture-pack=
server-ip=91.193.52.74
spawn-npcs=true
allow-flight=false
level-name=world
view-distance=3
resource-pack=
spawn-animals=true
white-list=false
rcon.password=j8DhSKDM7y
generate-structures=true
online-mode=false
max-build-height=256
level-seed=
motd=Nazwa serwera
enable-rcon=true 

 

 

 

plik łączenia z stroną:

 

 

<?
require_once('rcon.php');

$host = '91.193.52.74'; // Server host name or IP
$port = 28917;                      // Port rcon is listening on
$password = 'j8DhSKDM7y'; // rcon.password setting set in server.properties
$timeout = 3;                       // How long to timeout.

$rcon = new Rcon($host, $port, $password, $timeout);

if ($rcon->connect())
{
  $rcon->send_command("say Hello World!");
}
?> 

 

 

 

skrypt rcon:

 

 

<?
/**
 * See https://developer.valvesoftware.com/wiki/Source_RCON_Protocol for
 * more information about Source RCON Packets
 * 
 * @ 2013 Chris Churchwell
 */
class Rcon {
	
	private $host;
	private $port;
	private $password;
	private $timeout;
	
	private $socket;
	
	private $authorized;
	private $last_response;
	
	const PACKET_AUTHORIZE = 5;
	const PACKET_COMMAND = 6;
	
	const SERVERDATA_AUTH = 3;
	const SERVERDATA_AUTH_RESPONSE = 2;
	const SERVERDATA_EXECCOMMAND = 2;
	const SERVERDATA_RESPONSE_VALUE = 0;
	
	public function __construct($host, $port, $password, $timeout)
	{
		$this->host = $host;
		$this->port = $port;
		$this->password = $password;
		$this->timeout = $timeout;
		
	}
	
	public function get_response() {
		return $this->last_response;
	}
	
	public function connect() {
		
		$this->socket = fsockopen($this->host, $this->port, $errno, $errstr, $this->timeout);
		
		if (!$this->socket)
		{
		  $this->last_response = $errstr;
			return false;
		}
		
		//set timeout
		stream_set_timeout($this->socket, 3, 0);
		
		//authorize
		$auth = $this->authorize();
		
		if ($auth) {
			return true;
		}
		
		return false;
	}
	
	public function disconnect()
	{
		if ($this->socket)
		{
			fclose($this->socket);
		}
	}
	
	public function is_connected() {
		return $this->authorized;
	}
	
	public function send_command($command)
	{
		if (!$this->is_connected()) return false;
		
		// send command packet.
		$this->write_packet(Rcon::PACKET_COMMAND, Rcon::SERVERDATA_EXECCOMMAND, $command);
		
		// get response.
		$response_packet = $this->read_packet();
		if ($response_packet['id'] == Rcon::PACKET_COMMAND)
		{
			if ($response_packet['type'] == Rcon::SERVERDATA_RESPONSE_VALUE)
			{
				$this->last_response = $response_packet['body'];
				return $response_packet['body'];
			}
		}
		
		return false;
	}
	
	private function authorize() {
		$this->write_packet(Rcon::PACKET_AUTHORIZE, Rcon::SERVERDATA_AUTH, $this->password);
		$response_packet = $this->read_packet();
		
		if ($response_packet['type'] == Rcon::SERVERDATA_AUTH_RESPONSE)
		{
			if ($response_packet['id'] == Rcon::PACKET_AUTHORIZE)
			{
				$this->authorized = true;
				return true;
			}
		}
		
		$this->disconnect();
		return false;
	}
	
	/**
	 * Writes a packet to the socket stream..
	 */
	private function write_packet($packet_id, $packet_type, $packet_body)
	{
		/*
		Size			32-bit little-endian Signed Integer	 	Varies, see below.
		ID				32-bit little-endian Signed Integer		Varies, see below.
		Type			32-bit little-endian Signed Integer		Varies, see below.
		Body			Null-terminated ASCII String			Varies, see below.
		Empty String	Null-terminated ASCII String			0x00
		*/
		
		//create packet
		$packet = pack("VV", $packet_id, $packet_type);
		$packet = $packet . $packet_body . "\x00";
		$packet = $packet . "\x00";
		
		// get packet size.
		$packet_size = strlen($packet);
		
		// attach size to packet.
		$packet = pack("V", $packet_size) . $packet;
		
		// write packet.
		fwrite($this->socket, $packet, strlen($packet));
		
	}
	
	private function read_packet()
	{
		//get packet size.
		$size_data = fread($this->socket, 4);
		$size_pack = unpack("V1size", $size_data);
		$size = $size_pack['size'];
		
		// if size is > 4096, the response will be in multiple packets.
		// this needs to be address. get more info about multi-packet responses
		// from the RCON protocol specification at
		// https://developer.valvesoftware.com/wiki/Source_RCON_Protocol
		// currently, this script does not support multi-packet responses.
		
		$packet_data = fread($this->socket, $size);
		$packet_pack = unpack("V1id/V1type/a*body", $packet_data);
		
		return $packet_pack;
	}
}
?> 

 

 

 

Macie może skryt, z którego korzystacie ?

Zarchiwizowany

Ten temat przebywa obecnie w archiwum. Dodawanie nowych odpowiedzi zostało zablokowane.

×
×
  • Dodaj nową pozycję...