<?php
include('../includes/common.inc.php');
checkReferrer() or die();
$_POST['game'] = str_replace('../', '', $_POST['game']);
$_POST['game'] = str_replace('&', '', $_POST['game']);
$_POST['game'] = str_replace(';', '', $_POST['game']);

/*
data :{
	game       	: game,
	resolution 	: Settings.resolution,
	fps	   		: Settings.fps,
	forcehevc  	: Settings.forcehevc,
	localaudio 	: Settings.localaudio
}
-720                    Use 1280x720 resolution [default]
-1080                   Use 1920x1080 resolution
-width <width>          Horizontal resolution (default 1280)
-height <height>        Vertical resolution (default 720)
-30fps                  Use 30fps
-60fps                  Use 60fps [default]
-bitrate <bitrate>      Specify the bitrate in Kbps
-packetsize <size>      Specify the maximum packetsize in bytes
-forcehevc              Use high efficiency video decoding (HEVC)
-remote                 Enable remote optimizations
-app <app>              Name of app to stream
-nosops                 Don't allow GFE to modify game settings
-localaudio             Play audio locally
-surround               Stream 5.1 surround sound (requires GFE 2.7)
-keydir <directory>     Load encryption keys from directory
*/

$cmd = 'sudo moonlight stream -app "'.$_POST['game'].'"';

if( $_POST['resolution'] == '1920x1080') $cmd .= ' -1080';
if( $_POST['fps'] == '30') $cmd .= ' -30fps';
if( $_POST['forcehevc'] == 'true') $cmd .= ' -forcehevc';
if( $_POST['localaudio'] == 'true') $cmd .= ' -localaudio';
if( $_POST['remote'] == 'true') $cmd .= ' -remote';

exec("$cmd &", $out);
print_r($out);

?>