1

I run Unturned(game) server from console by tiping "C:\Program Files (x86)\Steam\steamapps\common\Unturned\Unturned.exe" -nographics -batchmode +secureserver/MyServer and then i can type there commands like

Give 1254235/125/3       or
Kick 131245654/cheats    or
Night

I want to allow users to do things like this from web site. For example, user press button 'Day' on web site and its send query to PHP file thats connects to the server and type this command. Any idea how to implement it?

JohnnyDinner
  • 67
  • 1
  • 9
  • Is server controlled by running **new** process with params or by giving command to **already running** process? – Im0rtality Aug 11 '15 at 08:17
  • So basically you run other process with params and these params (commands) are passed to your running server. Is this correct? – Im0rtality Aug 11 '15 at 08:36
  • No, that's same process. I run process **Unturned.exe** with params **-nographics** and **-batchmode** and it run server as console application, wrere i can type 'DAY' and it will turn day in the game. I need to allow users do it from website. – JohnnyDinner Aug 11 '15 at 08:50

1 Answers1

3

Simple way - exec()'ing command which sends your commands (i.e. Give 1254235/125/3) to game server itself) on user click asynchronously (See this answer for async execute).

Generalized example: Should open Notepad (yes, in awkward way, to show how to pass text into already open console window) from PHP:

script.php:

public function runScript() {
    exec("AutoIt3.exe script.au3 > NUL 2>NUL");
}

script.au3:

WinActivate("Command Prompt")
WinWaitActivate("Command Prompt")
Send("nodepad.exe")

Why another script?

AutoIt allows easier interactions with 3rd party applications than PHP. I'm not even sure it is possible with PHP.

Community
  • 1
  • 1
Im0rtality
  • 3,463
  • 3
  • 31
  • 41
  • Im not sure that I understand you. Can You, please, write full example? exec() will run many instances, or send command to exists? – JohnnyDinner Aug 11 '15 at 10:10
  • @JohnnyDinner Changed AutoHotKey to AutoIt - mixed up tool names in first place. Added example - you should be able to adapt to your case by changing what AutoIt script does. – Im0rtality Aug 11 '15 at 10:37