venin all,

   Appologies in advance for the lengthy email. I have been
working on an ANSI to HTML converter for over 3 months now.
I am trying to get a socket to open up, read in the buffer,
and if any ANSI color codes are found, convert them to their
proper FONT tags. The socket callin is working fine. ( Though
I can't seem to get it to close properly after the login
screen of a game is completed ) This script is made to call
MUD's ( multi user dungeon ) games. Some of these muds have
color capable logins, and I'd like to convert those login
screens to HTML FONT.

   The purpose of this email is to request any help at
all in the completion of this small script. My string
function handling in any language is rusty at best. If
any on this list can give me some pointers, helpfull hints,
or debugging statements, it would be most appreciated.



The below script calls a host and a specific port ( I
hard coded in my game as an example ). If you save
this script, and run it, you will see what I am referring
to. It calls the game, and retrieves the login screen.


-------------------script begins below------------------

  
<HTML>
<BODY BGCOLOR="BLACK" TEXT="WHITE">
<big><TT>
<?
/* Function to convert each ANSI color to its appropriate
 * HTML FONT color. When an entry is sent, it is sent as
 * a single number
 */
function convert( $entry )
{
        switch ($entry)
        {
                 case '0':  return "</FONT>"; break;
                 case '1':  return "<strong>"; break;
                 case '2':  return "Dim"; break;
                 case '4':  return "<u>"; break;  
                 case '5':  return ""; break;
                 case '7':  return "Reverse"; break;
                 case '8':  return "Hidden"; break;
                 case '30':  return "<FONT COLOR=\"BLACK\">"; break;
                 case '31':  return "<FONT COLOR=#ff0019>"; break;
                 case '32':  return "<FONT COLOR=\"GREEN\">"; break;
                 case '33':  return "<FONT COLOR=\"YELLOW\">"; break;
                 case '34':  return "<FONT COLOR=#2626c1>"; break;
                 case '35':  return "<FONT COLOR=\"PURPLE\">"; break;
                 case '36':  return "<FONT COLOR=\"99FFFF\">"; break;
                 case '37':  return "<FONT COLOR=\"WHITE\">"; break;
                 case '40':  return "Black"; break;
                 case '41':  return "Red"; break;
                 case '42':  return "Green"; break;
                 case '43':  return "Yellow"; break;
                 case '44':  return "Blue"; break;
                 case '45':  return "Magenta"; break;
                 case '46':  return "Cyan"; break;
                 case '47':  return "White"; break;
                 default: return "UKNOWN"; break;
        }
}        

$query_str= "Memory";

 
$fp = fsockopen("kyndig.com", 9000, &$errno, &$errstr);
if (!$fp) 
{
        echo "ERROR: $errno - $errstr<br>\n";
        exit;
} 
else 
{
        fputs($fp, "\n");
        while(!feof($fp)) 
        {
                $buf = fgets($fp,4096);

                /* Lets store what it really looks like in another
variable */
                $actual .= $buf;

                /* We are looking for the most standard ANSI color
                 * codes here: example: [1;33;4m
                 */
                if (preg_match("/\[\d+(;\d+)+m/",$buf))
                {
                        /* we don't want to reset the 'buf' we are
reading in */

                        $buffer = $buf;
                        /* first we pull out the matches and stick them
in an array   
                         * we also get rid of the [ at this point
                         */
                        preg_match_all("/\d+(;\d+)+m/",$buffer,
$matches);

                        for ($i=0; $i< count($matches[0]); $i++)
                        {
                                /* TEST is just a reference */
                                /* $TEST .= "matched:
".$matches[0][$i]."\n<br>";*/

                                /* We have isolated all color in a
single line in its own array now
                                 * It looks like:  [1;33;4m   or
[1;33m    For those that are [#m ANSI
                                 * code, the next ifcheck takes care of
them. Now lets go through each
                                 * code we have, split it up, and
convert it to HTML
                                 */
                                $code = $matches[0][$i];
                                list( $color1 , $color2, $color3 ) =
split( ";", $code);
                                $two = intval($color2);
                                $three = intval($color3);

                                $setting = convert($color1);
                                $foreground = convert($two);
                                if( $three != 0 )
                                {
                                        $background = convert($three);
                                }
                                if( $three == 0 )
                                {
                                        $background = "";
                                }

                                /* We now have the colors converter to
proper HTML format
                                 * Now we have to bring our buffer back,
and place all
                                 * the text around the ANSI code,
example: [1;33mt would
                                 * be <FONT COLOR="RED">t
                                 */             
                                if (preg_match("/\[\d+(;\d+)+m/",$buf) )
                                {
                                           $test =
preg_replace("/\[\d+(;\d+)+m/","", $buf);
                                }

                         
                                $final .=
"$setting$foreground$background$test<br>";
                                /*$final .= "<br>Color1: $color1 ====
Color2: $two ==== Color3: $three<br>"; */
                        }
                }     /* End ifcheck for common ANSI */
        }             /* End WHILE loop */


        /* Next We check against other not so common combinations
         * of ANSI colors, example: [1;33m and [0m;
         */
        if (preg_match("/\[\d+m/",$buffer))
        {
                       
                preg_match_all("/\[\d+m/",$buf, $matches);
                for ($i=0; $i< count($matches[0]); $i++)
                {
                     /*            $final .= "matched:
".$matches[0][$i]."\n<br>"; */
                }        
        }

        echo "$final";
        echo "<hr>";
        $proper = ereg_replace( "\n", "<br>", $actual);
        echo "\n</FONT><FONT COLOR=\"WHITE\">The actual image looks
like: $proper";
        fclose($fp);
}
?>
</BODY>
</HTML>

-----------------------------script
stops--------------------------------------------

Thankyou for any assistance in getting this script to work.
 
Kind Regards,
---
Kyndig
Online Text Game Resource Site:  http://www.kyndig.com
ICQ#    10451240

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to