23 Oct, 2007, goran wrote in the 1st comment:
Votes: 0
Hello again,

First off I would like to say thank you to those whom replied in my
previous thread. I have put that off till later on.

What I am trying to do now is add color to my code and I do not
want to mess around with Lope's Colour snippet.

I downloaded Davion's color snippet here and took out all
of the code that relates to saving colors for players. It
compiles clean but does weird things when trying to use
color codes.

Example:
<20hp 100m 100mv> say {Gtest
You say 'tes
<20hp 100m 100mv> say {Gt{ge{Gs{gterrwerewrwerwerewr
You say 'tester
<20hp 100m 100mv> say {Gt{Re{Ys{Wterrwerewrwerwerewr
You say 'tester
<20hp 100m 100mv> say {Gt{Re{Ys{wterrwerewrwerwerewr
You say 'tester
<20hp 100m 100mv> say {Gt{Re{Ys{wte{grrwerewrwerwerewr
You say 'teste<20hp 100m 100mv> say {Gt{Re{Ys{wte{grrwe{Brewrwerwerewr
You say 'teste<20hp 100m 100mv>

That is the actual output from my game currently. I can't figure out
where to start as I have not messed with this portion of the code before.

I send an email out to Davion not sure if that email address is valid so
I thought I'd see if anyone here could help out.

here is what I modified from the snippet so far
/*
* Append onto an output buffer.
*/
void write_to_buffer( DESCRIPTOR_DATA *d, const char *txt, int length )
{
const char *tmp;
/*
* Find length in case caller didn't.
*/
tmp = colour_string(txt, d->character ? d->character : d->original );
if ( length <= 0 )
length = strlen(tmp);

/*
* Initial \n\r if needed.
*/
if ( d->outtop == 0 && !d->fcommand )
{
d->outbuf[0] = '\n';
d->outbuf[1] = '\r';
d->outtop = 2;
}

/*
* Expand the buffer as needed.
*/
while ( d->outtop + length >= d->outsize )
{
char *outbuf;

if (d->outsize >= 32000)
{
bug("Buffer overflow. Closing.\n\r",0);
close_socket(d);
return;
}
outbuf = alloc_mem( 2 * d->outsize );
strncpy( outbuf, d->outbuf, d->outtop );
free_mem( d->outbuf, d->outsize );
d->outbuf = outbuf;
d->outsize *= 2;
}

/*
* Copy.
*/
strncpy( d->outbuf + d->outtop, tmp, length );
d->outtop += length;
return;
}


at the end of void act_new
*point++ = '\n';
*point++ = '\r';
*point = '\0';

buf[0] = UPPER(buf[0]);
if ( to->desc != NULL )
write_to_buffer( to->desc, buf, point - buf );
else
if ( MOBtrigger )
mp_act_trigger( buf, to, ch, arg1, arg2, TRIG_ACT );
}
return;
}


near the end of bust a prompt
*point = '\0';
write_to_buffer( ch->desc, buf, point - buf );

if (ch->prefix[0] != '\0')
write_to_buffer(ch->desc,ch->prefix,0);
return;
}


and colour.c
const struct colour_type colour_table[] =
{
{ "White", "x", "\e =
{
{ "White", "x", "\e[0m" },
{ "DRed", "r", "\e[0;31m" },
{ "DGreen", "g", "\e[0;32m" },
{ "DYellow", "y", "\e[0;33m" },
{ "DBlue", "b", "\e[0;34m" },
{ "DPurple", "m", "\e[0;35m" },
{ "DCyan", "c", "\e[0;36m" },
{ "Dwhite", "w", "\e[0;37m" },
{ "DGrey", "D", "\e[1;30m" },
{ "BRed", "R", "\e[1;31m" },
{ "BGreen", "G", "\e[1;32m" },
{ "BYellow", "Y", "\e[1;33m" },
{ "BBlue", "B", "\e[1;34m" },
{ "BPink", "M", "\e[1;35m" },
{ "BCyan", "C", "\e[1;36m" },
{ "BWhite", "W", "\e[1;37m" },
{ NULL, NULL, NULL }
};

char *colour_string( const char *txt, CHAR_DATA *ch )
{
const char *string = txt;
static char buf[MSL*4];
char symbol;
char *coloured, *code;
int i;
bool found;

buf[0] = '\0';
coloured = buf;

for(;*string != '\0' ; string++ )
{
found = FALSE;
if(*string == '{' )
{ string++;
symbol = *string;

if( ( i = symbol_lookup(symbol) ) == -1 )
i = 0;

// if( i >= 16 )
//code = get_pc_code(ch, colour_table[i].symbol );
// else
code = colour_table[i].code;

while(*code != '\0' )
{
*coloured++ = *code++;
*coloured = '\0';
}
found = TRUE;
}
if(!found)
{
*coloured++ = *string;
*coloured = '\0';
}
}
*coloured = '\0';

return buf;
}


char * get_colour_name(char *code )
{
int i;
for ( i = 0; colour_table[i].name != NULL ; i++ )
{
if(!str_cmp(code, colour_table[i].code ) )
return colour_table[i].name;
}

return "White";
}

int symbol_lookup( const char symbol )
{
int i;

for ( i = 0; colour_table[i].name != NULL ; i++ )
{
if( symbol == *colour_table[i].symbol )
return i;
}
return -1;
}

char * get_pc_code ( CHAR_DATA *ch, char *symbol )
{

return colour_table[0].code;



}

int get_colour(const char *name )
{
int i;
for( i = 0; i < PC_COL ; i++ )
if(!str_cmp(name, colour_table[i].name ) )
return i;
return -1;
}

int get_field(const char *name )
{
int i;
for( i = PC_COL; colour_table[i].name != NULL ; i++ )
if(!str_cmp(name, colour_table[i].name ) )
return i;
return -1;
}

[/code]

I removed parts where it was trying to compare to a players color settings,,I believe.

Any help would be great

Goran
23 Oct, 2007, Davion wrote in the 2nd comment:
Votes: 0
I should really update the snippets I wrote oh so long ago :).

Not sure exactly what the problem is, but lets see if we can figure it out. Look for
tmp = colour_string(txt, d->character ? d->character : d->original );
if ( length <= 0 )
length = strlen(tmp);


Remove the if statement so it grabs the length everytime.
tmp = colour_string(txt, d->character ? d->character : d->original);
length = strlen(tmp);


In the mean time, I'll try installing this somewhere and see if it works.
23 Oct, 2007, goran wrote in the 3rd comment:
Votes: 0
I removed the if statement and the code seems to
be working proper. Thank you for not making me use
lope's or failing to write my own. :)

I might have been able to fix this on my own..
I am used to programming in java and limited C++.
I had either MS VC or Borland JBuilder where I could set
break points and step through the actual code. Is this
possible with GDB? I guess I am also having trouble with how
this would work with a program such as a MUD. Is there any graphic based
programs in linux that I could do this? Just wondering

Goran
23 Oct, 2007, Davion wrote in the 4th comment:
Votes: 0
You can definitely use gdb, read this article http://www.gammon.com.au/forum/bbshowpos... it'll tell you all about gdb.
24 Oct, 2007, Tyche wrote in the 5th comment:
Votes: 0
There are graphcal UI's for GDB…
DDD and Insight for XWindows
KDbg for KDE
a windowed text UI called GDBTUI.
14 Nov, 2007, BumpInTheNight wrote in the 6th comment:
Votes: 0
Hi, I wanted to chime in that recently I was adding Davion's colour patch (btw, much nicer and smaller then Lope's, even the earlier versions) and ran into the exact same senario. Unfortunately removing that if check only made things worse :P In the end after much debugging I found that once those colour codes were translated into the ansi, Rom2.4b's descriptor output buffer would get grossly corrupted (at least with GCC 4 under Ubuntu Linux). Essentially it wouldn't get accurate string lengths and the pointer always got stuck at the value which was the largest the buffer had been upto that point. As a fun extra I did try Lope's colour translation table as an experiment and it as well behaved the same way.

My final solution was to stick the colour_string function directly into the write_to_descriptor as opposed to write_to_buffer, which pointed further at the output buffer having ansi escape codes in it being the root of the issue. Fortunately I could care less if someone wants colour or not, they're getting it on my mud :P
14 Nov, 2007, kremlin wrote in the 7th comment:
Votes: 0
bumpinthenight said:
Fortunately I could care less if someone wants colour or not, they're getting it on my mud :P

Now that's just mean. Each color tag is about another 7 bytes getting sent to the player, it really adds up! I've seen many a MUD that has so much color it ends up overflowing the buffers and causing disconnections in normal situations. Watch out for that.

Side note, the ability to disable color is a nice advantage for the resourceful pkiller.
14 Nov, 2007, BumpInTheNight wrote in the 8th comment:
Votes: 0
Yah I was thinking about that too and I agree, if people ever bitched enough I could just write a filter to strip out the {x codes in write_to_buffer in the same style as the colour_string function. For now though, sucks to be them ;)
15 Nov, 2007, Hades_Kane wrote in the 9th comment:
Votes: 0
Just out of curiosity, what are people finding 'wrong' with Lope's color?
15 Nov, 2007, BumpInTheNight wrote in the 10th comment:
Votes: 0
I guess it all boils down to coder's taste, while Lope's offers more end-user customizability options its also far more painful to install. I also don't have much care/preference to each player having different coloured channels appearing to themselves. They hopefully have a mud client they can configure if they want it that badly. In pro-Davion's snippet I found his method of using a seperate file for all the grunt work and only needed one call within the mud's output functions infinitely easier to get up and runningl. Copy colour.c to your src, add it to your make and stick colour_string into write_to_buffer: A breeze compared to what happens if the diff for Lope doesn't work.

Oh I also find Davion's function based conversion method much nicer to look at then a huge pile of arrays.
15 Nov, 2007, David Haley wrote in the 11th comment:
Votes: 0
A client can't control color with as much granularity as the server. All the client can do (without going into complex triggers etc) is globally replace one color with another. But what if I want to keep one red thing in red, but change that red thing to blue? It is much, much easier to do that on the server side. And besides, as a matter of principle, shouldn't I be the one to choose what color I get coming from such-and-such channel, instead of having the server dictate color preferences to me?
15 Nov, 2007, BumpInTheNight wrote in the 12th comment:
Votes: 0
DavidHaley said:
A client can't control color with as much granularity as the server. All the client can do (without going into complex triggers etc) is globally replace one color with another. But what if I want to keep one red thing in red, but change that red thing to blue? It is much, much easier to do that on the server side. And besides, as a matter of principle, shouldn't I be the one to choose what color I get coming from such-and-such channel, instead of having the server dictate color preferences to me?


Indeed it does come down to how far you want to go for an individual player's customization desires, Lope's is easier on the end-user hands down. As counter though: When's the last time you went into your web browser's settings and modified the default text's font or colour? ;)
15 Nov, 2007, David Haley wrote in the 13th comment:
Votes: 0
FWIW, I wasn't really trying to compare the snippets in terms of their technical merits, I've never even seen either one. But as for changing web browser settings, well, it's a rather different medium, isn't it? I don't have many kinds of information being sent to me very relatively where I need to categorize them into types to know what I should pay attention to and so forth. But on a MUD, I need to be able to quickly tell one kind of information from another. So I don't think the comparison is the best one. But hey, since you mentioned it, I did actually change my browser's default text font and link colors… :smile:
05 Dec, 2007, Kjwah wrote in the 14th comment:
Votes: 0
Not to go off topic.. but lol..

David, I just realized that your avatar is from baldur's gate. lol

I used that as my characters picture more often than not.
0.0/14