Freelancer Community Network
Reminder: Internet Explorer 6 or below are NOT supported.
HomeHome
ForumForum
WikiWiki
DownloadsDownloads
ForgeForge
Multiplayer Connection Tutorial
Collapse/Expand Random Image
Collapse/Expand Login
Username:

Password:

Remember me



Lost Password?

Register now!
Collapse/Expand Chat
Collapse/Expand Who's Online
77 user(s) are online (47 user(s) are browsing Forum)

Members: 0
Guests: 77

more...
Collapse/Expand Donations
Monthly costs: -30€
Income (ads): +5€
Donations (last month): +0€

Current balance: 55€
(last updated 04/2021)

Please make a donation if you want to help keeping The-Starport online:

Thanks!
Collapse/Expand Links
Collapse/Expand Advertisement
There are currently 40 users playing Freelancer on 44 servers.
July. 6, 2022

Browsing this Thread:   1 Anonymous Users



 Bottom   Previous Topic   Next Topic  Register To Post



Exporting online player list to web via FLHook

Joined:
2009/10/12 15:37
Group:
Registered Users
FLServer Admins
Posts: 46
Offline
I'm interested in having a list of current players on my Freelancer server listed on my web server. I would like it to be relatively real time (maybe polling the server every 5 minutes) versus being a tool like FLStats that scans the account files and provides data about all accounts.

Are there any current tools or routines out there to do this?

I could envision a script that use the remote port for flhook to use "getplayers", and parse that out to an online list of users which could be formatted and then uploaded using something like NcFTP to automatically update the web server.

If anyone aware of any existing tools or scripts that do this, I would appreciate you pointing me towards them.

Thanks!

Posted on: 2010/8/21 21:48
Open in new window
Top
Re: Exporting online player list to web via FLHook
Starport Staff
Joined:
2008/10/7 19:56
From England
Group:
Registered Users
Starport Staff
FLServer Admins
$$$ Supporters $$$
Senior Members
Posts: 639
Offline
Code:
<?php
$ip = "";
$port = 1919;
$pass = "";
$flhookHeader = "Welcome to FLHack, please authenticate";

//Credit goes to Blahb for this class. I've just modified it a bit.
class admin{
    var $loggedIn = false;
    var $con;
    var $timeout = 1000;
    var $errn;
    var $errs;
    var $error;
    var $ok = "OK";
    var $err = "ERR";
    var $cmds = array("getplayers" => array(0,1));
    function connect($ip, $port){
        $this->con = fsockopen($ip,$port,$this->errn,$this->errs,$this->timeout);
    }
    function quit(){
        fclose($this->con);
    }
    function sendCmd($cmd, $param=""){
        fwrite($this->con, $cmd . " " .$param."\r\n");
        while(1){
            $output .= fgetc($this->con);
            //\n and space used incase a player is named OK or ERR
            if((trim(substr($output,-3,3) == "\nOK")) || (trim(substr($output,-4,4) == "ERR "))){
                break;
            }
            else{
                continue;
            }
        }
        return trim($this->cleanOutput($output));
    }
    function processCmd($cmd, $params=""){
        switch($this->cmds[$cmd][0]){
            case 0:
                $params = str_replace(" ","",$params);
                $output = $this->cleanOutput($this->sendCmd($cmd, $params));
            break;
            case 1:
                $params = str_replace(",","",$params);
                $params = preg_replace("/[a-zA-Z]/","",$params);
                $output = $this->cleanOutput($this->sendCmd($cmd, $params));
            break;
            case 2:
                $output = $this->cleanOutput($this->sendCmd($cmd, $params));
            break;
        }
        switch($this->cmds[$cmd][1]){
            //No return needed, other than OK
            case 0:
                if(trim(substr($output,-2,2) == "OK")){
                    return true;
                }
                else{
                    $this->error = trim($output);
                    return false;
                }
            break;
            //Data needs to be returned
            case 1:
                
                if(trim(substr($output,-2,2) == "OK")){
                    return substr($output,0,(strlen($output) - 2));
                }
                else{
                    $this->error = trim($output);
                    return false;
                }
            break;
        }    
    }
    function login($pass){
        $check = $this->sendCmd("pass", $pass);
        if($check == $this->ok){
            $this->loggedIn = true;
        }
        else{
            $this->loggedIn = false;
            $this->error = $check;
        }
    }
    function cleanOutput($output){
            global $flhookHeader;
            //Removes flhook welcome message, so we only have the data returned by the server after sending a command.
            $remove = array("/".$flhookHeader."/");
            $output = preg_replace($remove,"",$output);
            return trim($output);
    }
}

$flhook = new admin();
$flhook->connect($ip, $port);
if($flhook->con){
    $flhook->login($pass);
    if($flhook->loggedIn){
        $players = explode("\n",$flhook->processCmd("getplayers"));
        foreach($players as $playerline){
            if(preg_match("/charname=(.+?) /",$playerline,$matches)){
                echo $matches[1]."<br>\r\n";
            }
        }
    }
    else{
        echo "Error: " . $flhook->error;
    }
}
?>

Posted on: 2010/8/21 22:11
Top
Re: Exporting online player list to web via FLHook
Just can't stay away
Joined:
2008/6/20 0:27
From Russia, GMT+4
Group:
Registered Users
FLServer Admins
Trusted Speciality Developers
Senior Members
Posts: 278
Offline
Yeah, i use this class too, it was initially posted on HHC forums i think.

Then parse the output and store it in DB or something.

edit: regarding the end of previous script, i'm not too familiar with regexps but i think strpos() would be better resource-wise there.

Posted on: 2010/8/22 1:10
Top
Re: Exporting online player list to web via FLHook

Joined:
2009/10/12 15:37
Group:
Registered Users
FLServer Admins
Posts: 46
Offline
Perfect. Thanks Alex!

I'm extremely new to php, but I would like to simply sort the output alphabetically. Would you happen to already have code to do that?

In the mean time, I'm going to try to figure it out on my own as well. I assume I would load the output into an array, then sort it, then echo out the array.

If I get it figured out, I'll post my results back up for comment.


Edit: Ok.. wow.. duh. The data is already in the array $players. Found the sort command and added

sort($players);

right before I echo them out.




Posted on: 2010/8/22 15:49
Open in new window
Top