Sty+ct+ap server

Post here if you need help setting up your server, etc.
User avatar
Tannermon11
Average Program
Posts: 86
Joined: Tue Sep 18, 2007 1:11 am

Re: Sty+ct+ap server

Post by Tannermon11 »

Hmm if I change the shebang line(first line) to the #!/usr/bin/env php
This is now what shows in the terminal:
[0] Launching external command '/home/tanner/0.2.9-armagetronad-sty+ct+ap/scripts/script.php'...
/usr/bin/env: 'php\r': No such file or directory

This only thing I have in everytime.cfg right now is just: SPAWN_SCRIPT script.php
I can post the script but it will take a while for me to censor the code since it is several hundred lines.
If it makes it easier I could just grab a script off the wiki and test that out in this case and link the script from there on here.
Tested it with a different script and it shows this in terminal:
[0] Launching external command '/home/tanner/0.2.9-armagetronad-sty+ct+ap/scripts/script.php'...
which it is isn't giving an error about no such file or directory

So what's weird is after making a new file and putting a different script in it, I then put in my original script with the #!/usr/bin/env php at the top and it is no longer saying that it can't find the directory/file
Last edited by Tannermon11 on Sat Jul 16, 2016 11:03 am, edited 1 time in total.

User avatar
Lucifer
Project Developer & Local Moonshiner
Posts: 8610
Joined: Sun Aug 15, 2004 3:32 pm
Location: Republic of Texas
Contact:

Re: Sty+ct+ap server

Post by Lucifer »

We only need the first 5-10 lines. We don't need the whole script. We're trying to help you figure out why it's not running, so we only need enough of what you'e writen to see how it's supposed to run. So only post that.

Edit: We'll also need the exact verson of the OS you're running the server on. Also, what tools you're using to edit scripts on the server.
Image

Be the devil's own, Lucifer's my name.
- Iron Maiden

User avatar
Tannermon11
Average Program
Posts: 86
Joined: Tue Sep 18, 2007 1:11 am

Re: Sty+ct+ap server

Post by Tannermon11 »

I had edited my post, apparently making a new file, testing a diff script, then putting the original one in the new file made it so it could find it.
There is still an issue though cause while it is not outputting that error anymore, none of the commands are working which is weird because it worked fine on a server that it was previously running on.
This is Ubuntu 16.04 and I was editing the script with gedit

This is the start of it:

Code: Select all

#!/usr/bin/env php

<?php

while (1) {

$line = rtrim(fgets(STDIN, 1024));

if(preg_match("/^CYCLE_CREATED/", $line))

{

	$split = explode(" ",$line);

	$name = $split[1];

	$players[] = $name;

}

if(preg_match("/^INVALID_COMMAND/", $line))
{
	$split = explode(" ", $line);

	if($split[4] > 1 && $split[1] == "/commandhere")  {

User avatar
Tannermon11
Average Program
Posts: 86
Joined: Tue Sep 18, 2007 1:11 am

Re: Sty+ct+ap server

Post by Tannermon11 »

So this is an example script I found and I put it in my file called script.php and proceeded to launch the server with ./armagetronad-dedicated --userdatadir '/home/tanner/0.2.9-armagetronad-sty+ct+ap'
script.php location is: /home/tanner/0.2.9-armagetronad-sty+ct+ap/scripts
calling spawn_script script.php shows this in the terminal:
[0] Launching external command '/home/tanner/0.2.9-armagetronad-sty+ct+ap/scripts/script.php'...
I test out a command such as /teleport but nothing happens besides unknown chat command "/teleport"

Code: Select all

#!/usr/bin/env php

<?php

while(true)

{

    $line = rtrim(fgets(STDIN, 1024));

	if(preg_match( "/^INVALID_COMMAND/", $line))

	{

		$data = explode(" ", $line);

		if($data[1] == "/zone")

		{

			if(empty($data[6]))

			{

				$data[6] = 10;

				$data[5] = "death";

			}

			echo "console_message $data[2] spawned a zone of size $data[6]!\n";

			if($data[5] == "death")

			{

				echo "spawn_zone death 100 100 $data[6] 0 0 0 false\n";

			}

			else if($data[5] == "win")

			{

				echo "console_message $data[2] is not allowed to spawn a winzone.\n";

			}

			else if($data[5] == "rubber")

			{

				echo "spawn_zone rubber 100 100 $data[6] 0 0 0 1 false\n";

			}

			else if($data[5] == "ball")

			{

				echo "spawn_zone ball 100 100 $data[6] 0 0 0 false\n";

			}

			else

			{

				echo "console_message $data[2] tried to spawn a $data[5] zone but there is no such thing. \n";

			}

		}

		if($data[1] == "/teleport")

		{

			echo "console_message $data[2] teleported!\n";

			echo "teleport_player $data[2] 100 100 1 1\n";

		}

		if($data[1] == "/speed")

		{

			echo "console_message $data[2] changed the speed!\n";

			$random = rand(5, 50);

			echo "cycle_speed $random \n";

		}

	}

}

?>

User avatar
Light
Reverse Outside Corner Grinder
Posts: 1659
Joined: Thu Oct 20, 2011 2:11 pm

Re: Sty+ct+ap server

Post by Light »

Lucifer wrote:#!/usr/bin/env php
Usually /usr/bin/php. You can double check this by using the which command.

Code: Select all

[email protected]:~$ which php
/usr/bin/php

User avatar
Light
Reverse Outside Corner Grinder
Posts: 1659
Joined: Thu Oct 20, 2011 2:11 pm

Re: Sty+ct+ap server

Post by Light »

Just a warning from first glance, it looks like that script is going to continue running with no end. You should have some way to break the while loop or the server may continue spawning more. Something like ...

Code: Select all

while (!feof(STDIN))
.. should work, instead of while (true).

User avatar
Tannermon11
Average Program
Posts: 86
Joined: Tue Sep 18, 2007 1:11 am

Re: Sty+ct+ap server

Post by Tannermon11 »

Ok
So I put some print statements in the while section as well as the if preg_match part to see if it was getting to those but only one printed out.
The print statement in the while loop printed out but the part after the if preg_match invalid_command is not printing.
This would mean the invalid command string is not being sent to $line perhaps?
Why would that not be happening even though unknown chat command is being displayed when a command is typed in?

So I added a print statement after $line = rtrim(fgets(STDIN, 1024));
and nothing was being printed after this.

User avatar
Lucifer
Project Developer & Local Moonshiner
Posts: 8610
Joined: Sun Aug 15, 2004 3:32 pm
Location: Republic of Texas
Contact:

Re: Sty+ct+ap server

Post by Lucifer »

Light wrote:
Lucifer wrote:#!/usr/bin/env php
Usually /usr/bin/php.
Um, familiar with the "which" command. :)

Python uses /usr/bin/env to look for the python version you have chosen to be the default python. I figured php probably did the same thing, because that would be smart. ;)
Image

Be the devil's own, Lucifer's my name.
- Iron Maiden

User avatar
Tannermon11
Average Program
Posts: 86
Joined: Tue Sep 18, 2007 1:11 am

Re: Sty+ct+ap server

Post by Tannermon11 »

So does anyone know why/how $line = rtrim(fgets(STDIN, 1024)); is making nothing work after it? Or how to find out what is going on with this it seems to be the fgets(STDIN,1024) as I put just this into a variable and nothing worked after it...

Is it something with my version of php?

User avatar
Light
Reverse Outside Corner Grinder
Posts: 1659
Joined: Thu Oct 20, 2011 2:11 pm

Re: Sty+ct+ap server

Post by Light »

Maybe this will help you out a bit with getting started.

Code: Select all

#!/usr/bin/php
<?php

/*
 * Demo Script
 * Spam all ladderlog lines to game chat.
 */

while (!feof(STDIN))
{
	// Get the input and strip off the new line on the end.
	$line = rtrim(fgets(STDIN));
	
	// Send command CONSOLE_MESSAGE and end with a new line for submission.
	echo "CONSOLE_MESSAGE {$line}" . "\n";
}

?>

User avatar
Tannermon11
Average Program
Posts: 86
Joined: Tue Sep 18, 2007 1:11 am

Re: Sty+ct+ap server

Post by Tannermon11 »

Nothing prints out, copied that into my script.php and nothing happens

User avatar
Light
Reverse Outside Corner Grinder
Posts: 1659
Joined: Thu Oct 20, 2011 2:11 pm

Re: Sty+ct+ap server

Post by Light »

Tannermon11 wrote:Nothing prints out, copied that into my script.php and nothing happens
What happens when you run this in a settings file? You could also create a file called script.cfg or something so you can include from in-game.

script.cfg

Code: Select all

KILL_SCRIPT script.php
SPAWN_SCRIPT script.php
Then while in game ..

Code: Select all

/admin include script.cfg
Maybe you'll see something obvious in the console log?

User avatar
Tannermon11
Average Program
Posts: 86
Joined: Tue Sep 18, 2007 1:11 am

Re: Sty+ct+ap server

Post by Tannermon11 »

Same thing happens as before. It just does the killing script, then launching external command, but then nothing else happens :/
No idea what is making it get stuck at the fgets stdin either, never heard of that happening. :(
The only difference between when it was working on the previous server and now is that I'm the one hosting the server and it's on a virtual machine but that shouldn't be a reason to make it not work. The only logical explanation is that it just doesn't like me >_<

User avatar
Light
Reverse Outside Corner Grinder
Posts: 1659
Joined: Thu Oct 20, 2011 2:11 pm

Re: Sty+ct+ap server

Post by Light »

Tannermon11 wrote:Same thing happens as before. It just does the killing script, then launching external command, but then nothing else happens :/
No idea what is making it get stuck at the fgets stdin either, never heard of that happening. :(
Try adding this setting to enable your logging. I'm assuming ladderlog.txt is empty?

Code: Select all

LADDERLOG_WRITE_ALL 1|1

User avatar
Tannermon11
Average Program
Posts: 86
Joined: Tue Sep 18, 2007 1:11 am

Re: Sty+ct+ap server

Post by Tannermon11 »

There is no ladderlog.txt at all in the directory ._.

Post Reply