Go Back   EQEmulator Home > EQEmulator Forums > Misc > Misc::Off Topic

Misc::Off Topic Want to talk about something that has nothing to do with EverQuest or the emulator? Post here.

Reply
 
Thread Tools Display Modes
  #1  
Old 07-11-2008, 08:00 PM
AndMetal
Developer
 
Join Date: Mar 2007
Location: Ohio
Posts: 648
Default

In general, you're probably going to want to use Regular Expressions, although it's gonna be a little complicated.

When I log into my GM character, this is everything that's returned with the "who" command in the telnet window:
Code:
  * GM-Impossible * [ANON 70 Stone Fist] Xamlagar (Iksar) zone: poknowledge AccID: 13 AccName: AndMetal LSID: 87737 Status: 250
And this is what you get with a regular character (not sure about any leading spaces):
Code:
[59 Master] Yuari (Iksar) zone: sebilis AccID: 298 AccName: Flora LSID: 110561 Status: 0
The first issue is that the string doesn't have the same delimiters every time. You could use explode with a space as the delimiter to start separating it, but because several items can be multiple words (class & race off the top of my head), that doesn't really help. So, back to regular expressions.

First, we'll start by pulling just the character info:
PHP Code:
fConnect($fp,$Server,$Port,$user,$pass);

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

while (!
feof($fp)) {
    
$ret[++$x] = fgets($fp);
    if (
ereg("zone"$ret[$x])) {
        
fclose($fp);
        break;
    };
}; 
So now we can work with $ret.

To separate any GM flag, you should be able to use this:
PHP Code:
preg_match("/\*.*\*/"$ret[1], $matches);
$players[1][GM] = trim($matches[0], "* "); 
This will return:
Code:
GM-Impossible
for the GM character & a blank for a regular character. You could then use the same idea for the rest. This is the script I came up with:
PHP Code:
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);
    };
}; 
Now you have a nice, simple array of all the characters that you can foreach to output to a table. The only thing missing would be anything that has to do with Guilds, but that should be easy enough to add.

I'm sure there's more efficient ways of doing this, especially if you can pull just what you're looking for the with Regular Expression instead of everything around it, but this will at least get the job done.

Hope this helps.
__________________
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
  #2  
Old 07-12-2008, 04:05 PM
spider661
Discordant
 
Join Date: Oct 2005
Location: michigain
Posts: 260
Default

ok i tried doing a print_r($players); and got an error.

Warning: Invalid argument supplied for foreach() in E:\wamp\www\who.php on line 46

for each player online

btw this is after adding to my code so line 46 is the first line there.
foreach ($ret as $key => $value) {


what should i do and am i calling the print_r($players); correctly or should i do something else. im trying to print it so i can see all the values of the array so i can place them in the right tables
Reply With Quote
  #3  
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
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

   

All times are GMT -4. The time now is 07:30 PM.


 

Everquest is a registered trademark of Daybreak Game Company LLC.
EQEmulator is not associated or affiliated in any way with Daybreak Game Company LLC.
Except where otherwise noted, this site is licensed under a Creative Commons License.
       
Powered by vBulletin®, Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Template by Bluepearl Design and vBulletin Templates - Ver3.3