Jump to content
Defent

[PHP] Live kill feed

Recommended Posts

So I created a script that checks your .RPT and reports back the latest kill that happened. 
I am not that good at PHP scripting so excuse any stupid placements of blocks or whatnot.
 

<?php
//CONFIG
$search = 'PKILL:';
$input = array_reverse(file("C:\Server\Steam\SteamApps\common\panthera\Configs\instance_16_panthera\arma2oaserver.RPT"),1); // the ,1) needs to be there.. for some reason.
//CONFIG END

$found = false;
foreach ($input as $line)
{
if(strpos($line, $search) !== false)
	{
	$found = true;
		echo "<h7>[".$line."]</h7><br/>";
	break;	
	}
}	
if(!$found)
{
  echo "<h5>I see no dead, yet.</h5>";
}

?>

The result ends up like this: 
 
http://numenadayz.com/stats.php

What do you think? Any feedback on how to make it better or should I keep it away because it affects performance and yada yada?

Share this post


Link to post
Share on other sites

I like it.

Maybe make something like (Im not a PHP boss either a SQF boss nor C++ etc so..^^):

If (weapon == "DMR_DZ") then {Image DMR};

 

Otherwise, I really, really like it, good job mate.

xBowBii

 

That would be possible, you can add another search word in the script and just make a if case and then add images based on that boolean etc :) - I guess atleast. And thanks!

 

:unsure: :wacko: :blink:

 

Warning: array_reverse() expects parameter 1 to be array, boolean given in *snip on line 4

Warning: Invalid argument supplied for foreach() in *snip on line 8

 

Try this instead:

$input = array_reverse file("path\to\my.rpt");

I don't actually know what the 2nd error means. did you change any of my arrays and what not?

Share this post


Link to post
Share on other sites

icons\dmr.png  <---- currently

 

icons/dmr.png  <--- should be

 

 

looks good man , neat idea!  ;)

Yea noticed that.. amongst other things.

I've been trying to get the picture to show up but it just won't respond to the arrays.

I guess the break; ruins the for loop and therefore the script only returns the first array.

I have no idea how to make the loop only return one line though.. I kinda made a cheap move to break the loop after the first value had been returned :)

 

Here's what I've done so far:

<?php
//CONFIG
$search = 'PKILL:';
$search_array = array("DMR", "m8_carbine", "AK_74", "m8_compact");
$input = array_reverse(file("C:\Server\Steam\SteamApps\common\panthera\Configs\instance_16_panthera\arma2oaserver.RPT"),1);
//CONFIG END

$found = false;
foreach ($input as $line )
{

if(strpos($line, $search) !== false)
	{

	/*	
			if (array_search("DMR", $search_array)) {
			$found = true;
			echo "<h7><img src='fuck/dmr.png'></img>&nbsp;".$line."</h7><br/>";
			break;
			}
			else
			if (array_search("AK_74", $search_array))
			{
				$found = true;
				echo "<h7><img src='fuck/ak_74.png'></img>&nbsp;".$line."</h7><br/>";	
				break;
			}
			else
			
			if (array_search("m8_compact", $search_array))
			{
				$found = true;
				echo "<h7><img src='fuck/m8_carbine.png'></img>&nbsp;".$line."</h7><br/>";	
				break;
			}
			$found = true;
			echo "<h7><img src='fuck/shitisfucked.png'></img>&nbsp;".$line."</h7><br/>";	
			break;
			
		*/
			
	}
/*
					else //bob the builder, if shit is not working well then its fucked.
					{
					$found = true;
					echo "<h7><img src='fuck\shitisfucked.png'  heigh='30' width='30'></img>&nbsp;".$line."</h7><br/>";
					break;	
					}
*/

}


if(!$found)
{
  echo "<h5>I see no dead, yet.</h5>";
}
?>

Share this post


Link to post
Share on other sites

This only shows the last kill? Can it be a list of all kills in that .RPT?

 

..and only way it worked for me is like this:

$input = file('path\to\my.rpt');
$rev_input = array_reverse($input);

EDIT: Never mind. I just removed "break;" and it shows all kills.

Share this post


Link to post
Share on other sites

My code, all kills.

<?php
$file = 'C:\dayz\server\instance_11_Chernarus\arma2oaserver.RPT';
$searchfor = 'PKILL:';

    header('Content-Type: text/plain');
    $contents = file_get_contents($file);

    $pattern = preg_quote($searchfor, '/');

    $pattern = "/^.*$pattern.*$/m";

  if(preg_match_all($pattern, $contents, $matches)){
     echo "Kill list: 
 ";
     echo implode(" ", $matches[0]);
     }
  else {
     echo "Not Kills!";
       }

 ?>

Share this post


Link to post
Share on other sites

I modified the code for easier insertion into html page.

<pre>
<?php
$file = 'C:\dayz\server\instance_11_Chernarus\arma2oaserver.RPT';
$searchfor = 'PKILL:';
    $contents = file_get_contents($file);
    $pattern = preg_quote($searchfor, '/');
    $pattern = "/^.*$pattern.*$/m";
if(preg_match_all($pattern, $contents, $matches)){
    echo "Список убийств: <br> ";
    $result = implode(" ", $matches[0]);
	$patterns = array();
	$patterns[0] = '/"PKILL:/';
	$patterns[1] = '/was killed by/';
	$patterns[2] = '/with weapon/';
	$patterns[3] = '/from/';
	$patterns[4] = '/m"/';
	$replacements = array();
	$replacements[4] = 'Игрок<b>';
	$replacements[3] = '</b>был убит игроком<b>';
	$replacements[2] = '</b>из оружия<b>';
	$replacements[1] = '</b>с расстояния';
	$replacements[0] = '</b> метров.';
	echo preg_replace($patterns, $replacements, $result);
    }
else {
    echo "Пока что убийств нету!";
      }
 ?>
</pre>

</pre></pre> - required to correct lines

line looks like this: "12:40:30 Игрок puhru был убит игроком Yilk из оружия AKS_74_U с расстояния 3.30967 метров."

I used replacement, translated into Russian, and added html codes.

result of the work here: http://kill.ggbb.ws/

Share this post


Link to post
Share on other sites

If you want images of weapons. Edit the replacement code. And use images of weapons PrivateHiveTools 

	$patterns = array();
	$patterns[0] = '/"PKILL:/';
	$patterns[1] = '/was killed by/';
	$patterns[2] = '/with weapon /';
	$patterns[3] = '/ from/';
	$patterns[4] = '/m"/';
	$replacements = array();
	$replacements[4] = 'Игрок<b>';
	$replacements[3] = '</b>был убит игроком<b>';
	$replacements[2] = '</b>из оружия<b><img src=/images/';
	$replacements[1] = '.png width=120 height=30></b>с расстояния';
	$replacements[0] = '</b> метров.';

Specify your image sizes and a folder of images taken from PrivateHiveTools

Note that in 4 and 5 string added spaces.

 

Defent, thanks for the idea of this code!

Share this post


Link to post
Share on other sites

this is how mine is done it dont show the gun image but its not needed

 

i created an .dll that writes to a text file and then made a php script to read everything on that file

 

i added this line into my server files/compile/serverPlayerDied.sqf

 

under

diag_log _loc_message;

 

i added
"Deathsz" callExtension (_loc_message)

 

Deathsz being my .dll name

 

php code

<?php

$file1 = "C:\Users\DayZ\Desktop\DayZ Servers\Epoch\Deathsz.txt";

$lines = file($file1);

foreach($lines as $line_num => $line)

{
echo "<font color='red'>$line</font>";
echo "<br>";
}

?>

and the output would look like this ( you would just have the kills not the menus )

 

HIbxp3j.png

Share this post


Link to post
Share on other sites

I'd love to add this to my site, but im really confused.

 

Running a couple of servers on a dedi, with the site hosted separately.

 

 

 

Guessing this only works if the server and site are hosted off the same machine?

 

 

Share this post


Link to post
Share on other sites

Setup a shared drive on the webserver where you would like the file to stay.

 

Create a new limited access user account that can be used to login to that share.  Make sure the account is not having any access to the game server.

 

Mount the shared drive on you game server (using the restricted access account). 

 

Setup a batchfile to run robocopy to sync the gameserver rpt with the remote share location (push from game server to webserver for security reasons).

 

Use Windows task schedular to run the batch file automatically every XXX minutes.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Advertisement
  • Advertisement
  • Supporters
  • Advertisement
  • Discord

×