Stránka 1 z 1

Propojení herního serveru s webem

Napsal: 27 pro 2015 01:47
od MrFiliper
Již dlouho dobu pracuji na kompletním propojení herních serverů s webem. Vše mi jde jedna báseň, přesto jsem se ale zasekl u jedné věcičky, která je vcelku důležitá a na internetu jsem nic podobného nenašel.

Jelikož mám web jak pro hráče minecraftu, tak zde mám i administraci. Chci tam nacpat opravdu vše, co bude potřeba. Konzole patří k těm potřebným věcem. Moje otázka tedy zní jak na výpis a zápis do konzole? Jak navázat komunikaci se serverem přes php a vypisovat data, aniž bych musel javascriptem pře načítat stránku. RCON tu je, ale to není to, co já potřebuji. Slyšel jsem že to lze udělat nějak přes sockety, i když jsem koukal do php dokumentace, jsem trošičku mimo. Byl by tu nějaký dobrák, který by mi ukázal jak na to? Propojení serveru, výpis dat, zápis dat? To vše v reálném čase.

Děkuji za pomoc.

Re: Propojení herního serveru s webem

Napsal: 27 pro 2015 13:47
od lamin_cz

Re: Propojení herního serveru s webem

Napsal: 27 pro 2015 20:17
od MrFiliper
Ano, přesně toto. na to jsme i koukal, ale nefungovalo. Tudíž nějaké jiné řešení?

Re: Propojení herního serveru s webem

Napsal: 27 pro 2015 21:46
od lamin_cz
Nefungovalo ... to je široký pojem ... copak Ti to psalo?

Re: Propojení herního serveru s webem

Napsal: 27 pro 2015 23:23
od MrFiliper
Hlásí to chybu: Warning: socket_connect() [function.socket-connect.html]: in C:\Complex-Web-Server-2\www\mcterm\mc_interface.php on line 90
Nemohlo b�vo�����en�proto�e c�v�ta�e aktivn�dm�.

Kód

Kód: Vybrat vše

<?php
include( "mcterm_cfg.php" );

@session_start();

//get password
if( isset( $_SESSION['mineremote_password'] ) ) {
	$password = $_SESSION['mineremote_password'];
} else {
	$password = "";
}

//checks to see if the password is valid
function check_pwd() {
	global $server, $port, $password;
	$rval = FALSE;
	
	$socket = socket_create( AF_INET, SOCK_STREAM, SOL_TCP );
	if( socket_connect( $socket, $server, $port ) === FALSE ) {
		exit( socket_strerror( socket_last_error( $socket ) ) );
	}
	
	//check the prompt line
	$line = socket_read( $socket, 1024 );
	if( preg_match( '/no password/i', $line ) ) {
		//no password set
		$rval = TRUE;
	} else {
		//send the password and check the resposne
		socket_write( $socket, $password );
		$line = socket_read( $socket, 1024 );
		if( substr_compare( '+ Access granted', $line, 0, 16 ) == 0 ) {
			$rval = TRUE;
		}
	}
	
	socket_close( $socket );
	
	return $rval;
}


//runs a cmd and returns the response
function run_cmd( $cmd ) {
	global $server, $port, $password, $response_delay;
	
	$socket = socket_create( AF_INET, SOCK_STREAM, SOL_TCP );
	if( socket_connect( $socket, "localhost", $port ) === FALSE ) {
		exit( socket_strerror( socket_last_error( $socket ) ) );
	}

	//check the prompt
	$line = socket_read( $socket, 1024 );
	if( !preg_match( '/no password/i', $line ) ) {
		//sign in with the password and check to see if it worked
		socket_write( $socket, $password );
		$line = socket_read( $socket, 1024 );
		if( substr_compare( '+ Access granted', $line, 0, 16 ) != 0 ) {
			
			return "<b style='color: red;'>ACCESS DENIED!</b><br/>\n";
		}
	}
	
	//do the command
	socket_write( $socket, $cmd );

	$socket_list = Array( $socket );
	$null = NULL;

	//read the response allowing $response_delay seconds between lines before closing the connection
	$line = "";
	while( socket_select( $socket_list, $null, $null, $response_delay ) != FALSE ) {
		$line .= socket_read( $socket, 1024 )."<br/>";
		$socket_list = Array( $socket );
	}
	
	//close the connection
	socket_close( $socket );
	
	//return the response
	return $line;
}

//This just checks for msgs on the server and returns the first that it finds
//This is following the long-poll model for persistent ajax connections
function poll_server_msgs() {
	global $server, $port, $password, $poll_timer;
	
	$socket = socket_create( AF_INET, SOCK_STREAM, SOL_TCP );
	if( socket_connect( $socket, "localhost", $port ) === FALSE ) {
		exit( socket_strerror( socket_last_error( $socket ) ) );
	}

	//check the prompt
	$line = socket_read( $socket, 1024 );
	if( !preg_match( '/no password/i', $line ) ) {
		//sign in with the password and check to see if it worked
		socket_write( $socket, $password );
		$line = socket_read( $socket, 1024 );
		if( substr_compare( '+ Access granted', $line, 0, 16 ) != 0 ) {
			
			return "<b style='color: red;'>ACCESS DENIED!</b><br/>\n";
		}
	}
	
	$socket_list = Array( $socket );
	$null = NULL;

	//check for any msgs 
	$line = "";
	if( socket_select( $socket_list, $null, $null, $poll_timer ) != FALSE ) {
		$line .= socket_read( $socket, 1024 )."<br/>";
		$socket_list = Array( $socket );
	}
	
	//close the connection
	socket_close( $socket );
	
	//return the response
	return $line;
}
?>
A config

Kód: Vybrat vše

<?php
/***** CONFIG OPTIONS *****/

//number of seconds to allow for a command to respond
$response_delay = 1;
//number of seconds to wait when polling for msgs 
//(Has to be less than your PHP script timeout)
$poll_timer = 1;
//command port for mineremote
$port  = 25565;
//server hosting mineremote
$server = "82.208.17.27";

/***** END CONFIG *****/
?>

Re: Propojení herního serveru s webem

Napsal: 28 pro 2015 00:27
od lamin_cz
Mě to teda žádnou chybu nepíše ... ale nevím ... neznám heslo na server
https://pospisilik.eu/mc/

Re: Propojení herního serveru s webem

Napsal: 28 pro 2015 00:58
od MrFiliper
To mi jde také, ale když zadám heslo (jakékoliv, protože nevím kde to heslo vzít), tak to v konzoli následně píše tuto chybu. Když budu vědět, kde a jaké heslo tam zadat, možná to fungovat bude.

Re: Propojení herního serveru s webem

Napsal: 28 pro 2015 09:55
od lamin_cz
Tak jsem si to pročetl a na MC serveru je potřeba, aby Ti běželo následující:
http://www.minecraftforum.net/forums/su ... aft-server

Re: Propojení herního serveru s webem

Napsal: 28 pro 2015 21:45
od MrFiliper
Tudíž bych musel zvýšit konfiguraci VPS serveru a převést servery z gamehostingu sem. Je ještě nějaká jiná možnost, jak se připojit na vzdálenou konzoli serveru?