Thread: php help
View Single Post
  #4  
Old 07-14-2008, 12:16 AM
AndMetal
Developer
 
Join Date: Mar 2007
Location: Ohio
Posts: 648
Default

For some reason, my Telnet code made sense the other day, but after looking at it now, I'm not sure where me head was

Here is the entire script I put together for testing:
PHP Code:
<?php

$ret
[1] = "  * GM-Impossible * [ANON 70 Stone Fist] Xamlagar (Iksar) zone: poknowledge AccID: 13 AccName: AndMetal LSID: 87737 Status: 250";
$ret[2] = "  [59 Master] Yuari (Iksar) zone: sebilis AccID: 298 AccName: Flora LSID: 110561 Status: 0";
$ret[3] = "  [70 Performer] Keasi (Half Elf) zone: poknowledge AccID: 1777 AccName: Keasi LSID: 69583 Status: 0";
$ret[4] = "  [70 Vanquisher] Suddz (Iksar) zone: cabeast AccID: 1780 AccName: OcelotRX LSID: 110949 Status: 0";

echo 
"<pre>\n\$ret = ";
print_r($ret);
echo 
"\n</pre>\n";

foreach (
$ret as $key => $value) {
    
// GM Status
    
if (preg_match("/\*.*\*/"$value$matches)) {
        
$players[$key][GM] = trim($matches[0], "* ");
    };
    
// Role/Anon, Level, & Class
    
if (preg_match("/\[.*\]/"$value$matches)) {
        
$tmp explode(" "trim($matches[0], "[] "));
        if (!
is_numeric($tmp[0])) {
            
$players[$key][Visible] = $tmp[0];
            
$players[$key][Level] = $tmp[1];
            
$players[$key]["Class"] = rtrim($tmp[2] . " " $tmp[3], " ");
        } else {
            
$players[$key][Level] = $tmp[0];
            
$players[$key]["Class"] = rtrim($tmp[1] . " " $tmp[2], " ");
        };
    };
    
// Character's Name
    
if (preg_match("/\].*\(/"$value$matches)) {
        
$players[$key][Name] = trim($matches[0], "] (");
    };
    
// Race
    
if (preg_match("/\(.*\)/"$value$matches)) {
        
$players[$key][Race] = trim($matches[0], "( )");
    };
    
// Zone
    
if (preg_match("/zone:.*AccID:/"$value$matches)) {
        
$players[$key][ZoneLong] = substr($matches[0], 6, -7);
    };
    
// Account ID
    
if (preg_match("/AccID:.*AccName:/"$value$matches)) {
        
$players[$key][AcctID] = substr($matches[0], 7, -9);
    };
    
// Account Name
    
if (preg_match("/AccName:.*LSID:/"$value$matches)) {
        
$players[$key][AcctName] = substr($matches[0], 9, -6);
    };
    
// Login Server ID
    
if (preg_match("/LSID:.*Status:/"$value$matches)) {
        
$players[$key][LSID] = substr($matches[0], 6, -8);
    };
    
// Status
    
if (preg_match("/Status:.*/"$value$matches)) {
        
$players[$key][Status] = substr($matches[0], 83);
    };
};

echo 
"<pre>\n\$players = ";
print_r($players);
echo 
"\n</pre>\n";

?>
And it works fine. However, it doesn't look like the Telnet code I suggested is putting out the array $ret, which is why it's freaking out at the foreach. Try this instead:
PHP Code:
fConnect($fp,$Server,$Port,$user,$pass);

fputs ($fp"who\r"); 
usleep(125000);

while (!
feof($fp)) {
    
$ret_tmp fgets($fp);
    if (
ereg("zone"$ret_tmp)) {$ret[++$x] = $ret_tmp;};
    if (
ereg("online"$ret_tmp)) {break;};
};
fclose($fp); 
That should put just the players into $ret & skip everything else, instead of just stopping the while loop & not outputting anything useful.
__________________
GM-Impossible of 'A work in progress'
A non-legit PEQ DB server
How to create your own non-legit server

My Contributions to the Wiki
Reply With Quote