FPSadmin.com

FPSadmin.com (http://www.fpsadmin.com/forum/index.php)
-   BC2: Remote Admin Tool Support (http://www.fpsadmin.com/forum/forumdisplay.php?f=130)
-   -   BC2Conn - PHP class for communicating with a gameserver (http://www.fpsadmin.com/forum/showthread.php?t=20045)

JLNNN 03-29-2010 09:39 AM

BC2Conn v1.06 - PHP class to communicate with a gameserver
 
This is a PHP class that allows you to administrate / observer your Battlefield Bad Company 2 gameserver just by using a few methods. Visit the project's site for more information!

Download: BC2Conn_v1.06 (updated: 16.01.2011)

There are some XML files for map/squad/playmode/team names, too.

You can find the API here.

Visit the official message board of BC2Conn!

If you experience any problems - let me know http://www.bfbc2admin.com/phpbb/imag...con_e_wink.gif

Changelog:
v1.06
* R28 support
* updated maxNames.xml
* added maps for Battlefield Bad Company 2: Vietnam
Preview of how to use it:

PHP Code:

<?php
/**
 * some examples - how to use the BC2Conn class
 *
 * this file requires BC2Conn >= v1.03-Update1
 *
 * project page: http://bc2conn.sf.net/
 * board       : http://bc2conn.sf.net/board/
 * API         : http://bc2conn.sf.net/API/
 *
 * live demo of this script: http://bc2conn.sf.net/demo/
 *
 * contact     : JLN@hush.ai
 *
 * $Id: example.php 15 2010-06-10 16:05:40Z jlnnn $
 */

// include the class file
include ("BC2Conn.php");

// opens a connection to gameserver
$BC2Conn = new BC2Conn("127.0.0.1"48888);

if (!
$BC2Conn->isConnected()) {
    echo 
"Connection could not be established. " .
    
"To debug, set '-d' as 3rd parameter to new connection.<br />" .
    
"<br />" .
    
"Example: \$BC2Conn = new BC2Conn(\"127.0.0.1\", 48888, \"-d\");";

    return 
0// stop executing this script
}

// secure login
$BC2Conn->loginSecure("yourRconPassword");

// unsecure login (not salted)
//$BC2Conn->loginInsecure("yourRconPassword");

// some random serverinformation
echo "Server IP: " $BC2Conn->getServerIP() . "<br />";
echo 
"Servername: " $BC2Conn->getServerName() . "<br />";
echo 
"Players: " $BC2Conn->getCurrentPlayers() . "/" $BC2Conn->getMaxPlayers() . "<br />";
echo 
"Playmode: " $BC2Conn->getCurrentPlaymodeName() . "<br />";
echo 
"Current Map: " $BC2Conn->getCurrentMapName() . "<br /><br /><br /><u>Players:</u><br /><br />";

// playerlist
$playerNames $BC2Conn->getPlayerlistNames();
foreach (
$playerNames as $key => $content) {
    if (
$BC2Conn->getPlayerClantag($content) != "") {
        echo 
"[" $BC2Conn->getPlayerClantag($content) . "]";
    }
    echo 
" " $BC2Conn->getPlayername($content) . " - Kills: ";
    echo 
$BC2Conn->getPlayerKills($content) . " | Deaths: ";
    echo 
$BC2Conn->getPlayerDeaths($content) . " | Score: ";
    echo 
$BC2Conn->getPlayerScore($content) . "<br />";
}

/*
 // change playmode and map and perform nextmap to save settings
 $BC2Conn->adminSetPlaylist("SQDM");
 $BC2Conn->adminMaplistClear();
 $BC2Conn->adminMaplistAppend("Levels/MP_006SDM"); // Arica Harbor
 $BC2Conn->adminMaplistSave();
 $BC2Conn->adminRunNextLevel();
 */

// say something as admin
//$BC2Conn->adminYellMessage("I'm testing BC2Conn PHP class - visit http://bc2conn.sf.net/ for more information!");

// get all available commands
//$BC2Conn->adminGetAllCommands();

// restart current map
//$BC2Conn->adminRestartMap();

// remove map index 3 from maplist and add a new one
//$BC2Conn->adminMaplistRemove(3);
//$BC2Conn->adminMaplistAppend("Levels/MP_003");

// set a new serverdescription
//$BC2Conn->adminVarSetServerDescription("Get the BC2Conn PHP class to administrate your Battlefield Bad Company 2 gameserver - visit http://bc2conn.sf.net/");

// kick a specific player
//$BC2Conn->adminKickPlayer("John Doe");

// ban a specific player permanently and view all bans by playername
//$BC2Conn->adminBanAddPlayername("John Doe");
//print_r($BC2Conn->adminBanlistList());

// turn off killcam
//$BC2Conn->adminVarSetKillCam(false);

// turn off friendly fire
//$BC2Conn->adminVarSetFriendlyFire(false);

// kills the player and moves him to the opponent team
//$BC2Conn->adminMovePlayerSwitchTeam("JLNNN", true);

// logout
$BC2Conn->logout();
?>

- JLNNN

Phogue 03-29-2010 11:29 AM

Love ya work and love your sharing :)

In the spirit of that, if you wanted to add team names to the mix feel free to incorporate this list. I've just ripped it out of my configs but 5 minutes copy+pasting should do the trick =)

global.conquest.us = U.S Army
global.conquest.ru = Russian Army
global.rush.defenders = Defenders
global.rush.attackers = Attackers
global.Squad0 = Alpha
global.Squad1 = Bravo (etc..)
us.png = United States flag
ru.png = Russian flag

While it looks like it follows a fairly steady pattern the US/RU flags are swapped for
port valdez (levels/mp_012gr). Possibly more maps are like that but that's the only one I noticed so far.

[MapFileName] [TeamID] [TeamName] [ImageFlag]
Quote:

procon.protected.teamnames.add "levels/mp_001" 0 "global.conquest.neutral" ""
procon.protected.teamnames.add "levels/mp_001" 1 "global.conquest.us" "us.png"
procon.protected.teamnames.add "levels/mp_001" 2 "global.conquest.ru" "ru.png"
procon.protected.teamnames.add "levels/mp_003" 0 "global.conquest.neutral" ""
procon.protected.teamnames.add "levels/mp_003" 1 "global.conquest.us" "us.png"
procon.protected.teamnames.add "levels/mp_003" 2 "global.conquest.ru" "ru.png"
procon.protected.teamnames.add "levels/mp_005" 0 "global.conquest.neutral" ""
procon.protected.teamnames.add "levels/mp_005" 1 "global.conquest.us" "us.png"
procon.protected.teamnames.add "levels/mp_005" 2 "global.conquest.ru" "ru.png"
procon.protected.teamnames.add "levels/mp_007" 0 "global.conquest.neutral" ""
procon.protected.teamnames.add "levels/mp_007" 1 "global.conquest.us" "us.png"
procon.protected.teamnames.add "levels/mp_007" 2 "global.conquest.ru" "ru.png"
procon.protected.teamnames.add "levels/mp_009cq" 0 "global.conquest.neutral" ""
procon.protected.teamnames.add "levels/mp_009cq" 1 "global.conquest.us" "us.png"
procon.protected.teamnames.add "levels/mp_009cq" 2 "global.conquest.ru" "ru.png"
procon.protected.teamnames.add "levels/mp_002" 0 "global.rush.neutral" ""
procon.protected.teamnames.add "levels/mp_002" 1 "global.rush.attackers" "us.png"
procon.protected.teamnames.add "levels/mp_002" 2 "global.rush.defenders" "ru.png"
procon.protected.teamnames.add "levels/mp_004" 0 "global.rush.neutral" ""
procon.protected.teamnames.add "levels/mp_004" 1 "global.rush.attackers" "us.png"
procon.protected.teamnames.add "levels/mp_004" 2 "global.rush.defenders" "ru.png"
procon.protected.teamnames.add "levels/mp_006" 0 "global.rush.neutral" ""
procon.protected.teamnames.add "levels/mp_006" 1 "global.rush.attackers" "us.png"
procon.protected.teamnames.add "levels/mp_006" 2 "global.rush.defenders" "ru.png"
procon.protected.teamnames.add "levels/mp_008" 0 "global.rush.neutral" ""
procon.protected.teamnames.add "levels/mp_008" 1 "global.rush.defenders" "us.png"
procon.protected.teamnames.add "levels/mp_008" 2 "global.rush.attackers" "ru.png"
procon.protected.teamnames.add "levels/mp_012gr" 0 "global.rush.neutral" ""
procon.protected.teamnames.add "levels/mp_012gr" 1 "global.rush.attackers" "ru.png"
procon.protected.teamnames.add "levels/mp_012gr" 2 "global.rush.defenders" "us.png"
procon.protected.teamnames.add "levels/mp_002sr" 0 "global.rush.neutral" ""
procon.protected.teamnames.add "levels/mp_002sr" 1 "global.conquest.us" "us.png"
procon.protected.teamnames.add "levels/mp_002sr" 2 "global.conquest.ru" "ru.png"
procon.protected.teamnames.add "levels/mp_005sr" 0 "global.rush.neutral" ""
procon.protected.teamnames.add "levels/mp_005sr" 1 "global.conquest.us" "us.png"
procon.protected.teamnames.add "levels/mp_005sr" 2 "global.conquest.ru" "ru.png"
procon.protected.teamnames.add "levels/mp_001sr" 0 "global.rush.neutral" ""
procon.protected.teamnames.add "levels/mp_001sr" 1 "global.conquest.us" "us.png"
procon.protected.teamnames.add "levels/mp_001sr" 2 "global.conquest.ru" "ru.png"
procon.protected.teamnames.add "levels/mp_012sr" 0 "global.rush.neutral" ""
procon.protected.teamnames.add "levels/mp_012sr" 1 "global.conquest.us" "us.png"
procon.protected.teamnames.add "levels/mp_012sr" 2 "global.conquest.ru" "ru.png"
procon.protected.teamnames.add "levels/mp_009sdm" 0 "global.rush.neutral" ""
procon.protected.teamnames.add "levels/mp_009sdm" 1 "global.Squad0" "us.png"
procon.protected.teamnames.add "levels/mp_009sdm" 2 "global.Squad1" "ru.png"
procon.protected.teamnames.add "levels/mp_009sdm" 3 "global.Squad2" "us.png"
procon.protected.teamnames.add "levels/mp_009sdm" 4 "global.Squad3" "ru.png"
procon.protected.teamnames.add "levels/mp_007sdm" 0 "global.rush.neutral" ""
procon.protected.teamnames.add "levels/mp_007sdm" 1 "global.Squad0" "us.png"
procon.protected.teamnames.add "levels/mp_007sdm" 2 "global.Squad1" "ru.png"
procon.protected.teamnames.add "levels/mp_007sdm" 3 "global.Squad2" "us.png"
procon.protected.teamnames.add "levels/mp_007sdm" 4 "global.Squad3" "ru.png"
procon.protected.teamnames.add "levels/mp_006sdm" 0 "global.rush.neutral" ""
procon.protected.teamnames.add "levels/mp_006sdm" 1 "global.Squad0" "us.png"
procon.protected.teamnames.add "levels/mp_006sdm" 2 "global.Squad1" "ru.png"
procon.protected.teamnames.add "levels/mp_006sdm" 3 "global.Squad2" "us.png"
procon.protected.teamnames.add "levels/mp_006sdm" 4 "global.Squad3" "ru.png"
procon.protected.teamnames.add "levels/mp_004sdm" 0 "global.rush.neutral" ""
procon.protected.teamnames.add "levels/mp_004sdm" 1 "global.Squad0" "us.png"
procon.protected.teamnames.add "levels/mp_004sdm" 2 "global.Squad1" "ru.png"
procon.protected.teamnames.add "levels/mp_004sdm" 3 "global.Squad2" "us.png"
procon.protected.teamnames.add "levels/mp_004sdm" 4 "global.Squad3" "ru.png"

JLNNN 03-30-2010 07:30 AM

Updated to v1.2b. (Phogue, I'll take your suggestions into the next version - thanks for that!)

JLNNN 03-31-2010 05:26 PM

Updated to v1.3b.

Xaiin 04-01-2010 09:32 PM

Hi guys,

Very nice work :) Really appreciate that you shared this with the community.

I'd be really interested in seeing if you can include some sort of event handler, something that can capture incoming captures, kills, deaths, chat etc.

I'll keep looking around to see if I can provide any additional information.

Looking forward to your next release :)



-Xaiin

JLNNN 04-02-2010 12:31 PM

Updated to v1.4b.

FireDawg911 04-02-2010 10:30 PM

is there documentation on installing this and use instructions or am i missing something?

JLNNN 04-03-2010 07:46 AM

There are no install instructions yet, but maybe I'll put some on the project's page in the following time..

To use (and understand) the BC2Conn class you need basic PHP skills I think.. Just download the zip archive, extract the included files, edit the example.php (you need to change the example ip and RCON port / password to your gameserver ones) and upload them on your webspace. Then you can call www.example.com/example.php and you'll see some basic data of your gameserver.

To add new functions, just take a look at the API - choose what you want to do and insert the function into your php file with the specific parameters if there are any.

Hope that'll do it.

- JLNNN

Bakes 04-03-2010 11:35 AM

Is this released under any particular license ie the GNU GPL?

JLNNN 04-03-2010 11:48 AM

No, there is no license - use it in the ways you want to (please let the comments in class intact). But if you earn money with it, it would be nice if you donate me some cents :) And please set a link on your page to get it more public.

- JLNNN

DVDFmeanfocker 04-03-2010 05:17 PM

I've been writing my own php script and had success with it being able to list players, ban kick etc etc but couldn't work out what I need to send in the header for white spaces when sending chat? Seeing this I thought I'd bin my script and go with this but it won't work. When running the simple example script (with my gameserver password, port and IP) I get: Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /home/sites/dvdf-clan.co.uk/public_html/rcon/BC2Conn.php on line 18 The webserver is php 5

JLNNN 04-03-2010 05:25 PM

Please show me line 17-19 of your BC2Conn.php file.. I think you edited it - that will be the problem :D

DVDFmeanfocker 04-03-2010 06:48 PM

Here's the first part of the code, I haven't edited anything:

PHP Code:

<?php
/**
 * if you've got any improvements or if you like this class,
 * send me a little message by mail. i can read english / german ;)
 *
 * <b>support:</b><br />
 * http://www.bfbc2admin.com/phpbb/viewtopic.php?f=9&t=220&start=0 <b>(english)</b><br />
 * http://www.fpsadmin.com/forum/showthread.php?t=20045 <b>(english)</b><br />
 * http://www.bf-games.net/forum/index.php?showtopic=45896 <b>(german)</b><br />
 * <br />
 * <b>API:</b><br />
 * http://www.jlnx.de/BC2Conn/API/
 *
 * @author JLNNN <JLN@hush.ai>
 * @version 1.4b
 */
class BC2Conn {
    private 
$_serverIP null;
    private 
$_serverRconQueryPort null;
    private 
$_clientSequenceNr 0;
    private 
$_sock null;
    private 
$_connection false;

    
/**
     * @param String
     * @param Integer
     *
     * @return boolean true = connection successful, false = connection failed
     */
    
function __construct($serverIP$serverRconQueryPort) {
        if (
$this->_serverIP == null) {
            
$this->_serverIP $serverIP;
            
$this->_serverRconQueryPort $serverRconQueryPort;
            
$this->_connection $this->_openConnection();
        }

        return 
$this->_connection;
    }

It seems it doesn't like the private variables???? If I remove them it then doesn't like private functions??? weird?

JLNNN 04-03-2010 06:54 PM

Well okay, that's really strange.. I don't see any problems and the BC2Conn class works fine, trust me.. Maybe you should try another webspace? And what if you just edit the

$BC2Conn = new BC2Conn("127.0.0.1", 48888);

line in the example.php and call it via www.example.com/example.php? Does this work?

JLNNN 04-04-2010 06:23 AM

Updated to v1.41b.


All times are GMT -4. The time now is 09:43 PM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2018, vBulletin Solutions, Inc.
Creative Commons License
This work by www.fpsadmin.com is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License.
About The real Rudedog