I need a PHP nexuiz to HTML character/color convertor

Developer discussion of experimental fixes, changes, and improvements.

Moderators: Nexuiz Moderators, Moderators

I need a PHP nexuiz to HTML character/color convertor

Postby [-z-] » Thu Jan 01, 2009 6:57 pm

As those of you who've been paying close attention to the development of the Nexuiz Ninjaz servers know, I've recently created some web (http) scripts to help manage the servers. A nice gui to assist in common server tasks and moderation (such as mute/kick/ban).

I thought I had found a quick and easy way to save myself some time from parsing status to get player numbers by using qstat and going through a loop but this proved to be inaccurate at times and in retrospect an utterly stupid way to do this.

I should be parsing status for the most accurate information... the only problem I have now is qstat graciously converted the dp characters and colors to html for me.

I was wondering if anyone has a php function already written to do this conversion or is willing to write one to save me some time.

this thread gives a hint about what I need to do... but I'm not 100% clear on what needs to be done. A here is div's perl implementation for the IRC gateway

I need this:
RanchDressing{YMCA}|GGG|


to look like this:
<font color="yellow">Ranch</font><font color="green">Dressing</font><font color="blue">{</font><font color="cyan">YMCA</font><font color="blue">}</font><font color="yellow">|</font><font color="white">GGG</font><font color="yellow">|</font><font color="white"></font>


Hex code is preferred over the color name references (i.e #00f to green, #f00 to red) and support for terencehill's new ^xrgb colors would be sweet.


These scripts will be released once I'm finished. There is a still a lot of work to be done (as this show stopping bug has made clear).
[-z-]
Site Admin and Nexuiz Ninja
 
Posts: 1794
Joined: Mon Nov 13, 2006 12:20 am
Location: Florida

Postby divVerent » Thu Jan 01, 2009 9:08 pm

There is new Perl code for this. You may want to base your code on this (written ad hoc):

Code: Select all
our @text_qfont_table = ( # ripped from DP console.c qfont_table
    "\0", '#',  '#',  '#',  '#',  '.',  '#',  '#',
    '#',  9,    10,   '#',  ' ',  13,   '.',  '.',
    '[',  ']',  '0',  '1',  '2',  '3',  '4',  '5',
    '6',  '7',  '8',  '9',  '.',  '<',  '=',  '>',
    ' ',  '!',  '"',  '#',  '$',  '%',  '&',  '\'',
    '(',  ')',  '*',  '+',  ',',  '-',  '.',  '/',
    '0',  '1',  '2',  '3',  '4',  '5',  '6',  '7',
    '8',  '9',  ':',  ';',  '<',  '=',  '>',  '?',
    '@',  'A',  'B',  'C',  'D',  'E',  'F',  'G',
    'H',  'I',  'J',  'K',  'L',  'M',  'N',  'O',
    'P',  'Q',  'R',  'S',  'T',  'U',  'V',  'W',
    'X',  'Y',  'Z',  '[',  '\\', ']',  '^',  '_',
    '`',  'a',  'b',  'c',  'd',  'e',  'f',  'g',
    'h',  'i',  'j',  'k',  'l',  'm',  'n',  'o',
    'p',  'q',  'r',  's',  't',  'u',  'v',  'w',
    'x',  'y',  'z',  '{',  '|',  '}',  '~',  '<',
    '<',  '=',  '>',  '#',  '#',  '.',  '#',  '#',
    '#',  '#',  ' ',  '#',  ' ',  '>',  '.',  '.',
    '[',  ']',  '0',  '1',  '2',  '3',  '4',  '5',
    '6',  '7',  '8',  '9',  '.',  '<',  '=',  '>',
    ' ',  '!',  '"',  '#',  '$',  '%',  '&',  '\'',
    '(',  ')',  '*',  '+',  ',',  '-',  '.',  '/',
    '0',  '1',  '2',  '3',  '4',  '5',  '6',  '7',
    '8',  '9',  ':',  ';',  '<',  '=',  '>',  '?',
    '@',  'A',  'B',  'C',  'D',  'E',  'F',  'G',
    'H',  'I',  'J',  'K',  'L',  'M',  'N',  'O',
    'P',  'Q',  'R',  'S',  'T',  'U',  'V',  'W',
    'X',  'Y',  'Z',  '[',  '\\', ']',  '^',  '_',
    '`',  'a',  'b',  'c',  'd',  'e',  'f',  'g',
    'h',  'i',  'j',  'k',  'l',  'm',  'n',  'o',
    'p',  'q',  'r',  's',  't',  'u',  'v',  'w',
    'x',  'y',  'z',  '{',  '|',  '}',  '~',  '<'
);

sub color_dp_transform(&$)
{
    my ($block, $message) = @_;

    $message =~ s{(?:(\^\^)|\^x([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])|\^([0-9])|(.))(?=([0-9,]?))}{
        defined $1 ? $block->(char => '^', $7) :
        defined $2 ? $block->(rgb => [hex $2, hex $3, hex $4], $7) :
        defined $5 ? $block->(color => $5, $7) :
        defined $6 ? $block->(char => $6, $7) :
            die "Invalid match";
    }esg;

    return $message;
}

my @htmlcolors = qw/000 F00 0F0 FF0 00F 0FF F0F FFF 888 888/;

sub color_dp2html$)
{
    my ($message) = @_;
    my $color = -1;
    return sprintf q{<font color="#fff">%s</font>}, color_dp_transform
    {
        my ($type, $data, $next) = @_;

        $type eq 'rgb' ? qq{</font><font color="#$data ">} :
        $type eq 'char'  ? CGI::escapeHTML($text_qfont_table[ord $data]) :
        $type eq 'color' ? qq{</font><font color="#$htmlcolors[$data]"} :
            die "Invalid type";
    }
    $message;
}
1. Open Notepad
2. Paste: ÿþMSMSMS
3. Save
4. Open the file in Notepad again

You can vary the number of "MS", so you can clearly see it's MS which is causing it.
divVerent
Site admin and keyboard killer
 
Posts: 3809
Joined: Thu Mar 02, 2006 4:46 pm
Location: BRLOGENSHFEGLE

Postby [-z-] » Thu Jan 01, 2009 10:16 pm

whiskas was kind enough to develop a function in php for this. I'm working on dissolving it into my current code. I'll update everyone when I have something more substantial coded.
[-z-]
Site Admin and Nexuiz Ninja
 
Posts: 1794
Joined: Mon Nov 13, 2006 12:20 am
Location: Florida


Return to Nexuiz - Development

Who is online

Users browsing this forum: No registered users and 1 guest

cron