View Single Post
  #1  
Old 12-02-2008, 03:36 PM
StilleVande StilleVande is offline
 
Join Date: Nov 2006
Posts: 3
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Trying to add another section Below "Who's Online"

I run a gameserver, and I have some php code that checks the server status. Here is the code if youd like to see it:

Code:
<?php

# function: nwserver_status
# Returns the server status in an array
# If the server does not respond with the expected hex string, 
# it returns an error message (which is not an array).


function nwserver_status($serveraddr, $port="5121", $timeout=5) {
	$connect = fsockopen( "udp://" . $serveraddr, $port, $errno, $errstr, $timeout );
	$error = NULL;
	if ( ! $connect )    {
	    $error = "server down";
	    return $error;
	} else {
	    socket_set_timeout( $connect, $timeout );
	    $send = "\xFE\xFD\x00\xE0\xEB\x2D\x0E\x14\x01\x0B\x01\x05\x08\x0A\x33\x34\x35\x13\x04\x36\x37\x38\x39\x14\x3A\x3B\x3C\x3D\x00\x00";
	    fwrite( $connect, $send );
	    $output = fread( $connect, 5000 );
	    if ( ! $output ) {
            $error = "no reply";
	    } else {
            $statusarray = explode( "\x00", $output );
            if (count($statusarray) < 6) { // if the array has < 6 elements, we're referencing a non-existing element
                $error = "bad reply";
            }
	    }
	}
	fclose( $connect );
	if ($error == NULL) {
		return $statusarray;
	} else {
		return $error;
	}
}

# php script to get the server status and player list

// gets server status directly from the gameserver

$serveraddr = "xxx.xxx.xxx.xxx";
// $server_down is displayed if the script can't connect 
// or if it receives no data from the server
$server_down = "<p class=\"highlight\">The server is down - now what are you gonna do?</p>\n";


$status = nwserver_status($serveraddr);
if (!is_array($status)) { // if an error message was returned
	print ($status);
} else {
    // format serverstatus array
	// $status[11] is the port used, $status[5] the number of players online
	// $status[6] the maximum number of players allowed
    print( "Server Address: <strong>$serveraddr:$status[11]</strong><br />\n" );
    print( "Server Status: <strong>Online</strong><br />\n" );
    print( "Players: <strong>$status[5]</strong> / <strong>$status[6]</strong><br />\n" );
}

?>
Id like to add it between "Who's Online" and the "Statistics" section on the bottom of the forums, but I cant figure it out.

I know it deals with making a plugin, but I dont know what to hook it off of for it to be there.

In the end, Id like to have it fire off and give the feedback, essentially looking like this:
Quote:
Server Address: xxx.xxx.xxx.xxx:5121
Server Status: Online
Players: 0 / 12
Any help would be highly appreciated.
Reply With Quote
 
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01330 seconds
  • Memory Usage 1,770KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD_SHOWPOST
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_code
  • (1)bbcode_quote
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_box
  • (1)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit_info
  • (1)postbit
  • (1)postbit_onlinestatus
  • (1)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • reputationlevel
  • showthread
Included Files:
  • ./showpost.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showpost_start
  • bbcode_fetch_tags
  • bbcode_create
  • postbit_factory
  • showpost_post
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • showpost_complete