Need help with PHP script

For all the help you need with Armagetron!
Post Reply
User avatar
ConVicT
Shutout Match Winner
Posts: 1001
Joined: Fri Feb 17, 2012 2:33 am

Need help with PHP script

Post by ConVicT »

So I have 3 scripts.

This one brings up a scoreboard of matches won at the beginning of ever match.

Code: Select all

#!/usr/bin/php
<?php
	$dir = "http://95.154.207.220/maps/McWellob/logs/"; //the directory location of the file
    $file = "won_matches.txt";         //the file you will rotate
	
     // Your border colors. Add/remove lines as you please.
    // Add a color multiple times to make it appear more often, or only once to make it rare.
   // Example: 1/16 (6.25%); 3/16 (18.75%); 8/16 (50%)
          $color_border = array("0xooff44", // 1.blue
                               "0xooff44", // 2.blue again
                              "0xooff44", // 3.blue once more
                             "0xooff44", // 4.gray
                            "0xooff44", // 5.gray again
                           "0xooff44", // 6.gray once more
                          "0xooff44", // 7.red
                         "0xooff44", // 8.red again
                        "0xooff44", // 9.green
                       "0xooff44", // 10.green again
                      "0xooff44", // 11.cyan border+purple text
                     "0xooff44", // 12.yellow
                    "0xooff44", // 13.gray (inverted)
                   "0xooff44", // 14.blue (inverted)
                  "0xooff44", // 15.red (inverted)
                "0xooff44"); // 16.green (inverted)
                                             
          // Your text colors - same amount and order as the border colors, otherwise wtf broken.
            $color_text = array("0xffff00", // 1.blue
                               "0xffff00", // 2.blue again
                              "0xffff00", // 3.blue once more
                             "0xffff00", // 4.gray
                            "0xffff00", // 5.gray again
                           "0xffff00", // 6.gray once more
                          "0xffff00", // 7.red
                         "0xffff00", // 8.red again
                        "0xffff00", // 9.green
                       "0xffff00", // 10.green again
                      "0xffff00", // 11.cyan border+purple text
                     "0xffff00", // 12.yellow
                    "0xffff00", // 13.gray (inverted)
                   "0xffff00", // 14.blue (inverted)
                  "0xffff00", // 15.red (inverted)
                "0xffff00"); // 16.green (inverted)         
         
            
    $trigger = "NEW_MATCH";
   
    $file = $dir.$file;
    while (1)
    {
            $line = rtrim( fgets(STDIN) );
           
            if (feof(STDIN))
                    break;
           
            $part = explode(" ", $line);
           
            if ($part[0] == $trigger)
            {
                    $fp = fopen($file, 'r');
                   
                    $colornumber = mt_rand(0, count($color_border)-1);  // randomizer by Titanoboa,
                    $color_1 = $color_border[$colornumber];            // anyone may use or modify
                    $color_2 = $color_text[$colornumber];             // as they please.  \(¤_¤)/
         
                    $board  = "{$color_1}***********************************************************" . '\\n';   
                    $board .= "{$color_1}***************    {$color_2}Top 10 Craziest Inmates   {$color_1}*****************" . '\\n';
                    $board .= "{$color_1}***********************************************************" . '\\n';
                    $board .= "{$color_1}**   {$color_2}RANK   {$color_1}***          {$color_2}PLAYER           {$color_1}***    {$color_2}WINS    {$color_1}**" . '\\n';
                    $board .= "{$color_1}***********************************************************" . '\\n';
                   
                     for ($i = 0; $i < 10; $i++)
                    {
                            $log = fgets($fp);
                           
                            if (feof($fp))
                                    break;
                           
                            list($wins, $player) = preg_split('/\s+/', $log);
                           
                            $rank = $i + 1;
                            $space_rank = 6 - strlen($rank);
                            $space_wins = 7 - strlen($wins);
                            $space_player = 23 - strlen( stripcslashes($player) );
                           
                            $board .= "{$color_1}**    {$color_2}{$rank}" . str_repeat(" ", $space_rank) . "{$color_1}***    {$color_2}" . stripslashes($player) . str_repeat(" ", $space_player) . "{$color_1}***     {$color_2}{$wins}" . str_repeat(" ", $space_wins) . "{$color_1}**" . '\\n';
                    }
                   
                    $board .= "{$color_1}***********************************************************";
                   
                    fclose($fp);
                   
                    console_message($board);
            }
    }
     
    function console_message($message)
    {
            echo "CONSOLE_MESSAGE {$message}" . "\n";
    }
     
?>
This one allows you type /rounds for a rounds won scoreboard to be shown.

Code: Select all

#!/usr/bin/php
<?php
  $dir = "/home/duke/aa/servers/McWellob/var/"; //the directory location of the file
  $file = "rounds_won.txt";         //the file you will rotate
  
     // Your border colors. Add/remove lines as you please.
    // Add a color multiple times to make it appear more often, or only once to make it rare.
   // Example: 1/16 (6.25%); 3/16 (18.75%); 8/16 (50%)
          $color_border = array("0x444488", // 1.blue
                               "0x444488", // 2.blue again
                              "0x444488", // 3.blue once more
                             "0x888888", // 4.gray
                            "0x888888", // 5.gray again
                           "0x888888", // 6.gray once more
                          "0x884444", // 7.red
                         "0x884444", // 8.red again
                        "0x448844", // 9.green
                       "0x448844", // 10.green again
                      "0x448888", // 11.cyan border+purple text
                     "0x888844", // 12.yellow
                    "0xaaaaaa", // 13.gray (inverted)
                   "0x8888bb", // 14.blue (inverted)
                  "0xbb8888", // 15.red (inverted)
                "0x88bb88"); // 16.green (inverted)
                                             
          // Your text colors - same amount and order as the border colors, otherwise wtf broken.
            $color_text = array("0x8888bb", // 1.blue
                               "0x8888bb", // 2.blue again
                              "0x8888bb", // 3.blue once more
                             "0xdddddd", // 4.gray
                            "0xdddddd", // 5.gray again
                           "0xdddddd", // 6.gray once more
                          "0xbb8888", // 7.red
                         "0xbb8888", // 8.red again
                        "0x88bb88", // 9.green
                       "0x88bb88", // 10.green again
                      "0x8888bb", // 11.cyan border+purple text
                     "0xbbbb88", // 12.yellow
                    "0x888888", // 13.gray (inverted)
                   "0x444488", // 14.blue (inverted)
                  "0x884444", // 15.red (inverted)
                "0x448844"); // 16.green (inverted)         
         
            
    $trigger = "/rounds";
   
    $file = $dir.$file;
    while (1)
    {
            $line = rtrim( fgets(STDIN) );
           
            if (feof(STDIN))
                    break;
           
            $part = explode(" ", $line);
           
            if ($part[1] == $trigger)
            {
                    $fp = fopen($file, 'r');
                   
                    $colornumber = mt_rand(0, count($color_border)-1);  // randomizer by Titanoboa,
                    $color_1 = $color_border[$colornumber];            // anyone may use or modify
                    $color_2 = $color_text[$colornumber];             // as they please.  \(¤_¤)/
         
                    $board  = "{$color_1}***********************************************************" . '\\n';   
                    $board .= "{$color_1}***************    {$color_2}Top 10 Match Winners   {$color_1}*****************" . '\\n';
                    $board .= "{$color_1}***********************************************************" . '\\n';
                    $board .= "{$color_1}**   {$color_2}RANK   {$color_1}***          {$color_2}PLAYER           {$color_1}***    {$color_2}WINS    {$color_1}**" . '\\n';
                    $board .= "{$color_1}***********************************************************" . '\\n';
                   
                    for ($i = 0; $i < 10; $i++)
                    {
                            $log = fgets($fp);
                           
                            if (feof($fp))
                                    break;
                           
                            list($wins, $player) = preg_split('/\s+/', $log);
                           
                            $rank = $i + 1;
                            $space_rank = 6 - strlen($rank);
                            $space_wins = 7 - strlen($wins);
                            $space_player = 23 - strlen( stripcslashes($player) );
                           
                            $board .= "{$color_1}**    {$color_2}{$rank}" . str_repeat(" ", $space_rank) . "{$color_1}***    {$color_2}" . stripslashes($player) . str_repeat(" ", $space_player) . "{$color_1}***     {$color_2}{$wins}" . str_repeat(" ", $space_wins) . "{$color_1}**" . '\\n';
                    }
                   
                    $board .= "{$color_1}***********************************************************";
                   
                    fclose($fp);
                   
                    console_message($board);
            }
    }
     
    function console_message($message)
    {
            echo "CONSOLE_MESSAGE {$message}" . "\n";
    }
     
?>
This one allows you type /ladder for a ladder scoreboard to be shown.

Code: Select all

#!/usr/bin/php
<?php
  $dir = "/home/duke/aa/servers/McWellob/var/"; //the directory location of the file
  $file = "ladder.txt";         //the file you will rotate
  
     // Your border colors. Add/remove lines as you please.
    // Add a color multiple times to make it appear more often, or only once to make it rare.
   // Example: 1/16 (6.25%); 3/16 (18.75%); 8/16 (50%)
          $color_border = array("0x444488", // 1.blue
                               "0x444488", // 2.blue again
                              "0x444488", // 3.blue once more
                             "0x888888", // 4.gray
                            "0x888888", // 5.gray again
                           "0x888888", // 6.gray once more
                          "0x884444", // 7.red
                         "0x884444", // 8.red again
                        "0x448844", // 9.green
                       "0x448844", // 10.green again
                      "0x448888", // 11.cyan border+purple text
                     "0x888844", // 12.yellow
                    "0xaaaaaa", // 13.gray (inverted)
                   "0x8888bb", // 14.blue (inverted)
                  "0xbb8888", // 15.red (inverted)
                "0x88bb88"); // 16.green (inverted)
                                             
          // Your text colors - same amount and order as the border colors, otherwise wtf broken.
            $color_text = array("0x8888bb", // 1.blue
                               "0x8888bb", // 2.blue again
                              "0x8888bb", // 3.blue once more
                             "0xdddddd", // 4.gray
                            "0xdddddd", // 5.gray again
                           "0xdddddd", // 6.gray once more
                          "0xbb8888", // 7.red
                         "0xbb8888", // 8.red again
                        "0x88bb88", // 9.green
                       "0x88bb88", // 10.green again
                      "0x8888bb", // 11.cyan border+purple text
                     "0xbbbb88", // 12.yellow
                    "0x888888", // 13.gray (inverted)
                   "0x444488", // 14.blue (inverted)
                  "0x884444", // 15.red (inverted)
                "0x448844"); // 16.green (inverted)         
         
            
    $trigger = "/ladder";
   
    $file = $dir.$file;
    while (1)
    {
            $line = rtrim( fgets(STDIN) );
           
            if (feof(STDIN))
                    break;
           
            $part = explode(" ", $line);
           
            if ($part[1] == $trigger)
            {
                    $fp = fopen($file, 'r');
                   
                    $colornumber = mt_rand(0, count($color_border)-1);  // randomizer by Titanoboa,
                    $color_1 = $color_border[$colornumber];            // anyone may use or modify
                    $color_2 = $color_text[$colornumber];             // as they please.  \(¤_¤)/
         
                    $board  = "{$color_1}***********************************************************" . '\\n';   
                    $board .= "{$color_1}***************    {$color_2}Top 10 Match Winners   {$color_1}*****************" . '\\n';
                    $board .= "{$color_1}***********************************************************" . '\\n';
                    $board .= "{$color_1}**   {$color_2}RANK   {$color_1}***          {$color_2}PLAYER           {$color_1}***    {$color_2}WINS    {$color_1}**" . '\\n';
                    $board .= "{$color_1}***********************************************************" . '\\n';
                   
                    for ($i = 0; $i < 10; $i++)
                    {
                            $log = fgets($fp);
                           
                            if (feof($fp))
                                    break;
                           
                            list($wins, $player) = preg_split('/\s+/', $log);
                           
                            $rank = $i + 1;
                            $space_rank = 6 - strlen($rank);
                            $space_wins = 7 - strlen($wins);
                            $space_player = 23 - strlen( stripcslashes($player) );
                           
                            $board .= "{$color_1}**    {$color_2}{$rank}" . str_repeat(" ", $space_rank) . "{$color_1}***    {$color_2}" . stripslashes($player) . str_repeat(" ", $space_player) . "{$color_1}***     {$color_2}{$wins}" . str_repeat(" ", $space_wins) . "{$color_1}**" . '\\n';
                    }
                   
                    $board .= "{$color_1}***********************************************************";
                   
                    fclose($fp);
                   
                    console_message($board);
            }
    }
     
    function console_message($message)
    {
            echo "CONSOLE_MESSAGE {$message}" . "\n";
    }
     
?>
What I want is for these 3 scripts to be merged into one, and when I type /rounds, or /ladder, I want it to only show the board to the player that typed it and not everyone else, which is what it's doing just now.

Any help would be greatly appreciated.
User avatar
Light
Reverse Outside Corner Grinder
Posts: 1667
Joined: Thu Oct 20, 2011 2:11 pm

Re: Need help with PHP script

Post by Light »

You can just put them into functions and call them when it triggers. Also, use PLAYER_MESSAGE instead of CONSOLE_MESSAGE to send it privately.
User avatar
ConVicT
Shutout Match Winner
Posts: 1001
Joined: Fri Feb 17, 2012 2:33 am

Re: Need help with PHP script

Post by ConVicT »

I'm still not too good at this, do you mean like this:

Code: Select all

{
    $line = rtrim(fgets(STDIN, 1024));
	
	if(preg_match( "/^INVALID_COMMAND/", $line))
	{
		$part = explode(" ", $line);
		if($part[1] == "/rounds")
		{
			echo "PLAYER_MESSAGE $board\n";
		}
		if($part[1] == "/ladder")
		{
			echo "PLAYER_MEESAGE $board\n";
			
?
And then have:

Code: Select all

$dir = "http://95.154.207.220/maps/McWellob/logs/";
$dir1 = "/home/duke/aa/servers/McWellob/var/";
$file1 = "rounds_won.txt";
$file2 = "ladder.txt";
I get the feeling I'm making it harder for my self.
Big noob, if I'm honest.
User avatar
ConVicT
Shutout Match Winner
Posts: 1001
Joined: Fri Feb 17, 2012 2:33 am

Re: Need help with PHP script

Post by ConVicT »

Thanks for trying, Light.

In the end I had Durf have a look at it and he sent me exactly what I needed, with a few added extras.
Cheers, Durf. :D
Word
Reverse Adjust Outside Corner Grinder
Posts: 4258
Joined: Wed Jan 07, 2009 6:13 pm

Re: Need help with PHP script

Post by Word »

BTW, how likely is it that durf will get a job here?
User avatar
ConVicT
Shutout Match Winner
Posts: 1001
Joined: Fri Feb 17, 2012 2:33 am

Re: Need help with PHP script

Post by ConVicT »

Why do you always feel the need to sully his name like this?

This thread isn't even about Durf, and you're just going off topic for reasons that, I, personally thought were over and done with.

I was only thanking Light for trying to help me, and letting him know how I got it sorted out.

And Durf isn't being charitable, if that's what you mean.
As far as my thoughts go, he did a favour for a friend/someone who appreciates the contributions he's made (Not to mention that it helps the whole community with new servers).

He helped me out, and I'm sure if he weren't banned, he'd have did it right here.

Stop making topics all about the past. This thread was never about Durf, or yourself. :roll:
Word
Reverse Adjust Outside Corner Grinder
Posts: 4258
Joined: Wed Jan 07, 2009 6:13 pm

Re: Need help with PHP script

Post by Word »

Why do you always feel the need to sully his name like this?[...]This thread was never about Durf, or yourself
ALWAYS? Well, now it is, for once. Man, do you ever think twice before you do something? Of course here I'm guilty of that as well and should have known better than to tease you, but the remark only made fun of his way of posting. So please, chill. I'm not sure what else you read into it, but if you're that aggravated everytime someone mentions his name in that context (I know you can claim all day that he's not responsible for his actions and the ban wasn't fully deserved, so let's leave it at that), you make it difficult to ignore your thinking's ridiculousness in that respect.

Aside from that, if you continue to promote his services despite knowing what he did (well, posts like the one above reveal that you still think there was some kind of conspiracy and that his contributions outweigh everything else he did - or worse, that he's innocent and the ban was unfair), don't be surprised if you get negative feedback (at least from me).

Not that I don't already try to ignore you, in case you haven't noticed, but it's really difficult sometimes; and I'd nominate myself for a tronny to reward the effort. Please stop posting stupid crap without thought, that'll make it much easier -- not so much the "Oh no, somebody's wrong on the internet"-stuff (I'm already used to those...), but the "OUR SPECIES IS DOOMED AND THIS GUY SEEMS GLAD TO BE RESPONSIBLE"-stuff (yes, that's what your posts tend to evoke in others). Thank you in advance.
User avatar
ConVicT
Shutout Match Winner
Posts: 1001
Joined: Fri Feb 17, 2012 2:33 am

Re: Need help with PHP script

Post by ConVicT »

The point of my last post was to point out that your post served no purpose other than to make fun of Durf.
Which you freely admit:
Word wrote: Of course here I'm guilty of that as well and should have known better than to tease you, but the remark only made fun of his way of posting.
Just to be clear, the main subject of my post was "my problem is solved" not "Durf".
Your main subject is "Durf".
This topic was finished, my problem was solved, then you go ahead and start a whole new topic, starting with "BTW".

And to top it all off, you go ahead and threaten with negative feedback because of a name drop (not promotion of services, just a name drop). Why?

This post will be my last reply to you because it's pretty obvious you like to try and set me up.
I'm not falling for it this time.
Word
Reverse Adjust Outside Corner Grinder
Posts: 4258
Joined: Wed Jan 07, 2009 6:13 pm

Re: Need help with PHP script

Post by Word »

Which you freely admit
Yes. And you react in an over-sensitive way.
...and start a whole new topic, starting with "BTW".
As I thought I made clear, it was a joke that wasn't supposed to make you defend Durf (was it a real attack in the first place? what, do you think, are the odds that he actually goes to university there? would it be a terrible thing if he went there? how did I sully his name?) or derail the topic, get over it.
...because it's pretty obvious you like to try and set me up.
Even you aren't that important.
Why?
Word wrote:posts like the [second] one above [which was a little more than a name drop]
Convict wrote:And Durf isn't being charitable [*proceeds to point out how charitable Durf is*]
User avatar
kyle
Reverse Outside Corner Grinder
Posts: 1876
Joined: Thu Jun 08, 2006 3:33 pm
Location: Indiana, USA, Earth, Milky Way Galaxy, Universe, Multiverse
Contact:

Re: Need help with PHP script

Post by kyle »

If you guys care to discuss this further, just use PM's

Thanks
Image
User avatar
Z-Man
God & Project Admin
Posts: 11587
Joined: Sun Jan 23, 2005 6:01 pm
Location: Cologne
Contact:

Re: Need help with PHP script

Post by Z-Man »

kyle wrote:If you guys care to discuss this further, just use PM's

Thanks
That, or better, drop it entirely.
User avatar
ConVicT
Shutout Match Winner
Posts: 1001
Joined: Fri Feb 17, 2012 2:33 am

Re: Need help with PHP script

Post by ConVicT »

Weird how both of us are being told to "drop it", "BTW"...

Tell me where I said something I shouldn't. :?
User avatar
sinewav
Graphic Artist
Posts: 6413
Joined: Wed Jan 23, 2008 3:37 am
Contact:

Re: Need help with PHP script

Post by sinewav »

ConVicT wrote:Tell me where I said something I shouldn't. :?
Right now, by being a victim instead of just dropping it. Can you stop yourself from replying to me? Can you? If not, then you are just as guilty as Word, sorry to say. It's time to move on and forget about this thread.
User avatar
/dev/null
Shutout Match Winner
Posts: 819
Joined: Sat Sep 04, 2004 6:28 pm
Location: Chicago-ish

Re: Need help with PHP script

Post by /dev/null »

I want to help you, but php is terrible, and damn near impossible to debug. Might as well use perl.
All the issues of C, without reliable typing.

Haha, you guys got serious about it, ******* noobs.

Stop being fucktards and grow a sack.
Post Reply