Forum

> > Off Topic > [PHP]Message to Server
ForenübersichtOff Topic-ÜbersichtEinloggen, um zu antworten

Englisch [PHP]Message to Server

6 Antworten
Zum Anfang Vorherige 1 Nächste Zum Anfang

alt [PHP]Message to Server

Marcell
Super User Off Offline

Zitieren
I would like to send custom text by web to my game server throught this script, but i dunno how to define the text inside input

Any tip or suggestion or fix?

the script is:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<?php


function send_command($ip,$port,$rcon,$command) {
 $fp = @fsockopen("udp://".$ip, $port, $errno, $errstr);
 if ($fp){
      $request = chr(1).chr(0).chr(242).chr(strlen($rcon)).$rcon.pack("S",strlen($command)).$command;
      fwrite($fp, $request);
 }
}


$name = "Owner";
echo "<input type='text' name='$msg'";


if (isset($_REQUEST['send'])) {
send_command("192.168.1.69",36963,"asdasd","say ©255255255".$name.": ".$msg);
}



?>

alt Re: [PHP]Message to Server

Yates
Reviewer Off Offline

Zitieren
@user Gaios: You don't need it if you execute the script like he is doing now.

Sadly, the dedicated server does not (to my knowledge) support command input from outside.

alt Re: [PHP]Message to Server

Starkkz
Moderator Off Offline

Zitieren
@user Yates: unless he wasn't talking about CS2D's dedicated server.

But if he was, he could just go and use file us [Lua 5.1] LuaSocket 3.0 x86 Windows/Linux/MacOS .

Edit: Ignore what I just said, I realized it actually is the dedicated server's IP. It can handle regular RCon commands.

Edit2:
I'm not sure how you'd do it in PHP, but this is how I'd do it in Lua.
1
2
3
4
5
6
7
8
9
10
local RCon = "Some rcon"
local Command = "Some command"

local CommandLength = string.len(Command)
local Short1 = CommandLength - math.floor(CommandLength/256)*256
local Short2 = (CommandLength - Short1)/256

Request = string.char(1) .. string.char(2) .. string.char(242)
Request = Request .. string.char(string.len(RCon)) .. RCon
Request = Request .. string.char(Short1) .. string.char(Short2) .. Command
3× editiert, zuletzt 27.02.16 21:49:19
Zum Anfang Vorherige 1 Nächste Zum Anfang
Einloggen, um zu antwortenOff Topic-ÜbersichtForenübersicht