Plugin Directory

Changeset 457348


Ignore:
Timestamp:
10/30/2011 11:48:42 AM (14 years ago)
Author:
Sinopa
Message:

Now supports supports multiple instances and displays current map thumbnail.

Location:
game-server-tracker/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • game-server-tracker/trunk/index.php

    r452732 r457348  
    22/*
    33Plugin Name: Game Server Tracker
    4 Plugin URI: http://hannawerner.com/wordpress/game-server-tracker/
    5 Description: Gets current stats of a Game Server from GameTracker.com and displays them in the sidebar. Some of the games this tracker works on are: Battlefield 3 [BETA], Battlefield Bad Company 2, Call of Duty 2, Call of Duty 4, Call of Duty : Black Ops, Counter Strike 1.6, Counter Strike Source, Day of Defeat Source, Left 4 Dead 2, Medal of Honor, Minecraft, Team Fortress 2 and Wolfenstein Enemy Territory.
    6 Version: 1.0
     4Plugin URI: http://hannawerner.com/wordpress/game-server-tracker-version-1-1/
     5Description: Gets current stats of a Game Server from GameTracker.com and displays them in the sidebar. The Game Server Tracker supports all games supported by GameTracker.com.
     6Version: 1.1
    77License: GPLv2
    88Author: Hanna Camille Werner
     
    1010*/
    1111
    12 class hcw_gameserver_tracker extends WP_Widget {
    13  
    14  
    15     /** constructor -- name this the same as the class above */
    16     function hcw_gameserver_tracker() {
    17         parent::WP_Widget(false, $name = 'Game Server Tracker');
    18     }
    19  
    20     /** @see WP_Widget::widget -- do not rename this */
     12// Inspired by the built-in WP_Widget_Text class
    2113
    22     function widget($args, $instance) {
    23         extract( $args );
    24         $title      = apply_filters('widget_title', $instance['title']);
    25         $serverip   = $instance['message'];
    26    /**  $clanname   = $instance['messagetwo']; **/
    27         ?>
    28               <?php echo $before_widget; ?>
    29                   <?php if ( $title )
    30                         echo $before_title . $title . $after_title; ?>
     14class HCW_Gameserver_Tracker extends WP_Widget {
    3115
     16    function HCW_Gameserver_Tracker() {
     17        $widget_ops = array('classname' => 'widget_hcw_gst', 'description' => __('Displays Game  Server Information'));
     18        $control_ops = array();
     19        $this->WP_Widget('hcwgst', __('Game Server Tracker'), $widget_ops, $control_ops);
     20    }
    3221
    33 <!------------------------------------->
     22    function widget( $args, $instance ) {
     23        extract($args);
     24        $serverip = $instance['serverip'];
     25       
     26    echo $before_widget;
     27
     28    ?>
     29
     30<script type="text/javascript" language="JavaScript">
     31<!--
     32    function HideMoreContent(d) {
     33        document.getElementById(d).style.display = "none";
     34    }
     35    function ShowMoreContent(d) {
     36        document.getElementById(d).style.display = "block";
     37    }
     38    function ReverseDisplay(d) {
     39        if(document.getElementById(d).style.display == "none") { document.getElementById(d).style.display = "block"; }
     40        else { document.getElementById(d).style.display = "none"; }
     41    }
     42//-->
     43</script>
    3444
    3545<?php
     46$content = file_get_contents("http://www.gametracker.com/server_info/$serverip/");
     47preg_match("/<span class=\"item_color_success\"(.*?)>(.+?)<\/span>/s", $content, $matchesalive);
     48preg_match("/<span id=\"HTML_num_players\"(.*?)>(.+?)<\/span>/s", $content, $matchesnumplayers);
     49preg_match("/<span id=\"HTML_max_players\"(.*?)>(.+?)<\/span>/s", $content, $matchestotalplayers);
     50preg_match("/<span id=\"HTML_num_bots\"(.*?)>(.+?)<\/span>/s", $content, $matchesbots);
     51preg_match("/<div class=\"si_map_header\" id=\"HTML_curr_map\"(.*?)>(.+?)<\/div>/s", $content, $matchesmap);
     52preg_match("/<span class=\"item_color_title\"(.*?)>Game:<\/span>(.+?)&nbsp;/s", $content, $matchesgame);
     53preg_match("/<span class=\"item_color_title\"(.*?)>Name:<\/span>(.+?)<br\/\>/s", $content, $matchesclan);
     54preg_match("/<div class=\"si_map_image\" id=\"HTML_map_ss_img\"(.*?)>(.+?)<\/div>/s", $content, $matchesimgmap);
    3655
    37 function textbetweenarray($s1,$s2,$s){
    38   $myarray=array();
    39   $s1=strtolower($s1);
    40   $s2=strtolower($s2);
    41   $L1=strlen($s1);
    42   $L2=strlen($s2);
    43   $scheck=strtolower($s);
     56    echo '<ul>';
     57    echo '<li><strong>';
     58    echo $instance['alttitle'];
     59    echo '</strong><br /><strong>Game: </strong>';
     60    echo $matchesgame[2];
     61    echo '<br /><strong>Server Status: </strong>';
     62    echo $matchesalive[2];
     63    echo '<br /><strong>Players: </strong>';
     64    echo $matchesnumplayers[2];
     65    echo '/';
     66    echo $matchestotalplayers[2];
     67    echo '<br /><strong>Bots: </strong>';
     68    echo $matchesbots[2];
     69    echo '<br /><strong>Map: </strong>';
     70    echo $matchesmap[2];
     71?>
     72<a class="moreserverinfo" href="javascript:ReverseDisplay('<?php echo $serverip; ?>')"><strong>&darr;</strong></a>
     73<div class="content-sidebar" id="<?php echo $serverip; ?>" style="display:none;">
     74    <?php echo $matchesimgmap[2]; ?>
     75</div>
     76    <?php
     77        echo '</li>';
     78        echo '</ul>';
     79    ?>
     80    <?php echo $after_widget;
     81    }
    4482
    45   do{
    46   $pos1 = strpos($scheck,$s1);
    47   if($pos1!==false){
    48     $pos2 = strpos(substr($scheck,$pos1+$L1),$s2);
    49     if($pos2!==false){
    50       $myarray[]=substr($s,$pos1+$L1,$pos2);
    51       $s=substr($s,$pos1+$L1+$pos2+$L2);
    52       $scheck=strtolower($s);
    53       }
    54         }
    55   } while (($pos1!==false)and($pos2!==false));
    56 return $myarray;
     83    function update( $new_instance, $old_instance ) {
     84        $instance = $old_instance;
     85        $instance['serverip'] = strip_tags($new_instance['serverip']);
     86        $instance['alttitle'] = strip_tags($new_instance['alttitle']);
     87        return $instance;
     88    }
     89
     90    function form( $instance ) {
     91        $instance = wp_parse_args( (array) $instance, array( 'title' => '', 'serverip' => '', 'alttitle' => false ) );
     92
     93        if ($instance['serverip'])
     94        $title = preg_replace('/\?.*/', "", basename($instance['serverip']));
     95
     96?>
     97    <?php ?>
     98    <input id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="hidden" value="<?php echo $title; ?>" />
     99
     100        <p>
     101            <label for="<?php echo $this->get_field_id('alttitle'); ?>">
     102                &nbsp;<?php _e('Server Name:'); ?>
     103                <input class="widefat" id="<?php echo $this->get_field_id('alttitle'); ?>" name="<?php echo $this->get_field_name('alttitle'); ?>" type="text" value="<?php echo $instance['alttitle']; ?>" />
     104               
     105            </label>
     106        </p>
     107
     108        <p>
     109            <label for="<?php echo $this->get_field_id('serverip'); ?>">
     110                 &nbsp;<?php _e('Server IP and Port:'); ?>
     111                <input class="widefat" id="<?php echo $this->get_field_id('serverip'); ?>" name="<?php echo $this->get_field_name('serverip'); ?>" type="text" value="<?php echo $instance['serverip']; ?>" /><br />&nbsp;<small>e.g. 127.0.0.1:27960</small><br />
     112            </label>
     113        </p>
     114
     115<?php
     116    }
    57117}
    58118
    59 $content = file_get_contents("http://www.gametracker.com/server_info/$serverip");
     119function widget_hcw_gst_init() {
     120  register_widget('HCW_Gameserver_Tracker');
     121}
     122add_action('init', 'widget_hcw_gst_init', 1);
    60123
    61 $servergame     = "<strong>Game:</strong> ";
    62 $playerstats    = "<strong>Players Online:</strong> ";
    63 $serverstatus   = "<strong>Status:</strong> ";
    64 $currentmap     = "<strong>Current Map:</strong> ";
    65 $serverclan     = "<strong>Clan:</strong> ";
    66 /** $members        = "<strong>Members:</strong> "; **/
    67 
    68 $nextline       = "<br />";
    69 
    70 $trServerName = textbetweenarray("<span class=\"item_color_title\">Name:</span>", "<br/>", $content);
    71 $trServerGame = textbetweenarray("<span class=\"item_color_title\">Game:</span>", "&nbsp;", $content);
    72 $trCurrent    = textbetweenarray("<span id=\"HTML_num_players\">", "</span>", $content);
    73 $trTotal      = textbetweenarray("<span id=\"HTML_max_players\">", "</span>", $content);
    74 $trStatus     = textbetweenarray("<span class=\"item_color_success\">", "</span>", $content);
    75 $trCurrMap    = textbetweenarray("<div class=\"si_map_header\" id=\"HTML_curr_map\">", "</div>", $content);
    76 /** $trMembers    = textbetweenarray("<span class=\"item_color_title\">Members:</span>", "&nbsp;", $content);  **/
    77 
    78 /** SERVER NAME **/
    79 
    80 foreach($trServerName as $tr) {
    81  echo $tr;
    82 }
    83 
    84 echo $nextline. "\n";
    85 
    86 /** CLAN
    87 
    88 echo $serverclan;
    89 echo $clanname;
    90 echo $nextline. "\n";
    91 
    92 **/
    93 /** MEMBERS
    94 
    95 echo $members ;
    96 foreach($trMembers as $tr) {
    97  echo $tr;
    98 }
    99 echo $nextline. "\n";
    100  **/
    101 /** GAME **/
    102 
    103 echo $servergame;
    104 foreach($trServerGame as $tr) {
    105  echo $tr;
    106 }
    107 echo $nextline. "\n";
    108 
    109 /** STATUS **/
    110 
    111 echo $serverstatus;
    112 foreach($trStatus  as $tr) {
    113  echo $tr;
    114 }
    115 echo $nextline. "\n";
    116 
    117 /** CURRENT and TOTAL **/
    118 
    119 echo $playerstats;
    120 foreach($trCurrent as $tr) {
    121  echo $tr;
    122 }
    123 ?>/<?php
    124 foreach($trTotal as $tr) {
    125  echo $tr;
    126 }
    127 echo $nextline. "\n";
    128124?>
    129 <?php
    130 /** CURRENTMAP **/
    131 
    132 echo $currentmap;
    133 foreach($trCurrMap   as $tr) {
    134  echo $tr;
    135 }
    136 echo $nextline. "\n";
    137 
    138 
    139 /*****************************/
    140 ?>
    141 
    142 
    143               <?php echo $after_widget; ?>
    144         <?php
    145     }
    146  
    147     /** @see WP_Widget::update -- do not rename this */
    148     function update($new_instance, $old_instance) {
    149         $instance = $old_instance;
    150         $instance['title'] = strip_tags($new_instance['title']);
    151         $instance['message'] = strip_tags($new_instance['message']);
    152     /** $instance['messagetwo'] = strip_tags($new_instance['messagetwo']); **/
    153         return $instance;
    154     }
    155  
    156     /** @see WP_Widget::form -- do not rename this */
    157     function form($instance) {
    158  
    159         $title      = esc_attr($instance['title']);
    160         $serverip   = esc_attr($instance['message']);
    161   /**   $clanname   = esc_attr($instance['messagetwo']);   **/
    162         ?>
    163          <p>
    164           <label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label>
    165           <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title; ?>" />
    166         </p>
    167         <p>
    168           <label for="<?php echo $this->get_field_id('message'); ?>"><?php _e('Server and port. eg: 127.0.0.1:27960'); ?></label>
    169           <input class="widefat" id="<?php echo $this->get_field_id('message'); ?>" name="<?php echo $this->get_field_name('message'); ?>" type="text" value="<?php echo $serverip; ?>" />
    170         </p>
    171 
    172 
    173         <?php
    174     }
    175  
    176  
    177 } // end class hcw_gameserver_tracker
    178 add_action('widgets_init', create_function('', 'return register_widget("hcw_gameserver_tracker");'));
    179 ?>
  • game-server-tracker/trunk/readme.txt

    r452732 r457348  
    11=== Plugin Name ===
    22Contributors: Sinopa
    3 Tags: games, servers, tracker, clan
     3Tags: games, servers, details, tracker
    44Requires at least: 3.0
    55Tested up to: 3.2.1
    6 Stable tag: 1.0
     6Stable tag: 1.1
    77
    8  Gets current stats of a Game Server from GameTracker.com and displays them in the sidebar.
     8Gets current stats of a Game Server from GameTracker.com and displays them in the sidebar.
    99
    1010== Description ==
    1111
    12 Gets current stats for a Game Server from GameTracker.com and displays them in the sidebar. Some of the games this tracker works on are: Battlefield 3 [BETA], Battlefield Bad Company 2, Call of Duty 2, Call of Duty 4, Call of Duty : Black Ops, Counter Strike 1.6, Counter Strike Source, Day of Defeat Source, Left 4 Dead 2, Medal of Honor, Minecraft, Team Fortress 2 and Wolfenstein Enemy Territory.
    13 
    14 Everything that GameTracker.com supports, this widget supports.
     12Gets current stats of a Game Server from GameTracker.com and displays them in the sidebar. The Game Server Tracker supports all games supported by GameTracker.com.
    1513
    1614== Installation ==
    1715
    18 This section describes how to install the plugin and get it working.
    19 
    20 e.g.
    21 
    22 1. Upload `plugin-name.php` to the `/wp-content/plugins/` directory
    23 1. Activate the plugin through the 'Plugins' menu in WordPress
    24 1. Drag the widget to sidebar menu
     161. Download the plugin.
     172. Install it to your /wp-content/plugins/ directory
     183. Activate the plugin in your Wordpress Admin UI.
     194. Drag the widget to sidebar menu
     205. Write Server Name in widget.
     216. Write IP address and Port. eg. 127.0.0.1:27960
    2522
    2623== Frequently Asked Questions ==
    2724
    28 = No questions yet =
     25= Does Game Server Tracker support multiple instances? =
    2926
    30 So no answers have been given.
    31 
     27Yes. Now it supports multiple instances.
    3228
    3329== Changelog ==
    3430
    35 = 1.0 =
    36 * No Changes yet
     31Added support for multiple instances and current map thumbnail.
    3732
    3833== Upgrade Notice ==
    3934
     35= 1.1 =
     36* October 30, 2011 - 1.1 release.
     37* Added support for multiple instances and current map thumbnail.
     38
    4039= 1.0 =
    41 * No upgrades has been done
     40* October 19, 2011 - 1.0 release.
    4241
    4342== Screenshots ==
    4443
    45 Screenshots can be found at http://hannawerner.com/wordpress/game-server-tracker/
     44Screenshots can be found at http://hannawerner.com/wordpress/game-server-tracker-version-1-1/
    4645
    4746== Donate ==
    4847
    49 If you feel you want to donate something. Send me a postcard or something :)
     48If you feel you want to donate something. Then donate a small area in your blog with a linke to my site http://www.hannawerner.com :)
    5049
    51 
Note: See TracChangeset for help on using the changeset viewer.