Dragonfly CMS v9 ⇒ Gamers Modules & Blocks :: Archives ⇒ How to create a Block for DF with this PHP code :: Archived ⇒ Community Forums ⇒ CPG Dragonfly™ CMS
Forum Index Modules & Blocks Gamers Modules & Blocks ⇒ Archives

Archived ⇒ How to create a Block for DF with this PHP code


Hi all

I have this Server Indication Code (to display, how many players are on a Game-Server) and would like to use it as a block on my DF Site.

Can anybody give me a hand how to do this?

It just displays a single Link to the Server Stats and a green indication light plus the number of players and works fine in just executing the php code.

Would be great if someone knows how to make it a Block.

Heres the Code
<?php // Script shows, wether server is online/offline //----------------------------- declaration block ------------------------------ $filename_failed = "red.gif"; // if serverf offline $filename_ok = "green.gif"; // if server online $filename_pict = $filename_failed; $link_for_server = "http://www.free-birds.org/il2sc/"; $link_for_stat = "http://www.free-birds.org/il2sc/index.php?navigation=online/index.html"; // $server_name = "Free-Birds.org"; // server name $server_ip = "86.3.55.156"; // server ip $server_port = "21001"; // server port $amount_of_red = 0; $amount_of_blue = 0; //----------------------------- end declaration block -------------------------- $fp = @fsockopen ("udp://" . $server_ip . "", $server_port, $errno, $errstr, 2); if (!$fp) { echo<<<OUTPUT <b> <a href = "$link_for_server"> $server_name </a> <img src="$filename_pict"> <a href = "$link_for_stat"> $amount_of_red/$amount_of_blue</a> </b> OUTPUT; die(); // } @stream_set_timeout($fp,1); if (@fwrite($fp,"\\status\\") === false){ // die(); } $str = @fread($fp, 65000); $str = $str . @fread($fp, 65000); @fclose($fp); $items = explode("\\",$str); if (count($items) > 1){ // if the server replied $filename_pict = $filename_ok; for($i = 1; $i <= count($items); $i++){ $is_player = strncmp($items[$i],"player_",7); if($is_player == 0){ $players[$i] = array('name' => $items[$i+1], 'score' => $items[$i+3], 'ping' => $items[$i+5], 'side' => $items[$i+7]); if ($items[$i+7] == "2"){ // blue $amount_of_blue++; } else if($items[$i+7] == "1"){ // red $amount_of_red++; } } } } echo<<<OUTPUT <b> <a href = "$link_for_server"> $server_name </a> <img src="$filename_pict"> <a href = "$link_for_stat"> $amount_of_red/$amount_of_blue</a> </b> OUTPUT; ?>

Server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS):
Linux 1.3.27 4.0.23 4.4.1 CMS 9.1.1


<?php if (!defined('CPG_NUKE')) { exit; } // Script shows, wether server is online/offline $content = ''; $content .= freebirds(); function freebirds() { //----------------------------- declaration block ------------------------------ $filename_failed = "red.gif"; // if serverf offline $filename_ok = "green.gif"; // if server online $filename_pict = $filename_failed; $link_for_server = "http://www.free-birds.org/il2sc/"; $link_for_stat = "http://www.free-birds.org/il2sc/index.php?navigation=online/index.html"; // $server_name = "Free-Birds.org"; // server name $server_ip = "86.3.55.156"; // server ip $server_port = "21001"; // server port $amount_of_red = 0; $amount_of_blue = 0; //----------------------------- end declaration block -------------------------- $fp = @fsockopen ("udp://" . $server_ip . "", $server_port, $errno, $errstr, 2); if (!$fp) { return '<b><a href="'.$link_for_server.'">'.$server_name.'</a> <img src="'.$filename_pict.'"> <a href = "'.$link_for_stat.'"> '.$amount_of_red.'/'.$amount_of_blue.'</a></b>'; } @stream_set_timeout($fp,1); if (@fwrite($fp,"\\status\") === false){ return 'cannot write'; } $str = @fread($fp, 65000); $str = $str . @fread($fp, 65000); @fclose($fp); $items = explode("\",$str); if (count($items) > 1){ // if the server replied $filename_pict = $filename_ok; for($i = 1; $i < count($items); $i++){ $is_player = strncmp($items[$i],"player_",7); if($is_player == 0){ $players[$i] = array('name' => $items[$i+1], 'score' => $items[$i+3], 'ping' => $items[$i+5], 'side' => $items[$i+7]); if ($items[$i+7] == "2"){ // blue $amount_of_blue++; } else if($items[$i+7] == "1"){ // red $amount_of_red++; } } } } $data = '<b><a href = "'.$link_for_server.'"> '.$server_name.' </a> <img src="'.$filename_pict.'"> <a href = "'.$link_for_stat.'"> '.$amount_of_red.'/'.$amount_of_blue.'</a></b><br />'; //$data .= 'add more link other infos'; //$data .= 'add more and more of them'; return $data; } ?>

.:: I met php the 03 December 2003 :: Unforgettable day! ::.

Server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS):
CloudLinux / Apache 2.4 LSAPI / MySQLi 5.6 / PHP 5.6 / DCVS


Wohooo..that works..


thx alot not worthy

Now i only have to adjust design

thx
CeeGee

Server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS):
Linux 1.3.27 4.0.23 4.4.1 CMS 9.1.1


Me again Smile

how is it possible to implement that code maybe into header Data so that the Info appears in the header, or Top Nav Bar...is that possible?

Thx
CeeGee

Server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS):
Linux 1.3.27 4.0.23 4.4.1 CMS 9.1.1


get the "function freebirds() { ... }" move it wherever you want and then just

echo freebirds();

OR

move the function inside
themes/yourtheme/theme.php

add inside the $cpgtpl variables
"S_FREEBIRDS" => freebirds(),

then add in themes/yourtheme/templates/header.html
{S_FREEBIRDS}

.:: I met php the 03 December 2003 :: Unforgettable day! ::.

Server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS):
CloudLinux / Apache 2.4 LSAPI / MySQLi 5.6 / PHP 5.6 / DCVS


Thx

hope i get it together

i added it to the header.php and to header.html but it only shows the word "freebirds" in the Top Nav Bar (the location where i put the variable)

Server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS):
Linux 1.3.27 4.0.23 4.4.1 CMS 9.1.1


Never mind...

i will use it as a Block

Thx for all your help

Brilliant support Smile

Server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS):
Linux 1.3.27 4.0.23 4.4.1 CMS 9.1.1

All times are UTC