Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ SMAUG ➜ SMAUG coding ➜ Adding Commands to SWR

Adding Commands to SWR

It is now over 60 days since the last post. This thread is closed.     Refresh page


Pages: 1 2  

Posted by Celestine   (29 posts)  Bio
Date Tue 03 Jun 2003 03:25 AM (UTC)
Message
I'm running SWR v1.0, and I added the command pinfo (stands for player information). I added the necessary lines in tables.c under the correct case things

case 'p':
if ( !str_cmp( name, "do_pager" )) return do_pager;
if ( !str_cmp( name, "do_pardon" )) return do_pardon;
if ( !str_cmp( name, "do_password" )) return do_password;
if ( !str_cmp( name, "do_peace" )) return do_peace;
if ( !str_cmp( name, "do_pick" )) return do_pick;
if ( !str_cmp( name, "do_pickshiplock" )) return do_pickshiplock;
if ( !str_cmp( name, "do_pinfo" )) return do_pinfo;

and

if ( skill == do_owhere ) return "do_owhere";
if ( skill == do_pager ) return "do_pager";
if ( skill == do_pardon ) return "do_pardon";
if ( skill == do_password ) return "do_password";
if ( skill == do_peace ) return "do_peace";
if ( skill == do_pick ) return "do_pick";
if ( skill == do_pinfo ) return "do_pinfo";

I added the thing to command.dat

#COMMAND
Name pinfo~
Code do_pinfo
Position 0
Level 0
Log 0
End

and mud.h

DECLARE_DO_FUN( do_owhere );
DECLARE_DO_FUN( do_pager );
DECLARE_DO_FUN( do_pardon );
DECLARE_DO_FUN( do_password );
DECLARE_DO_FUN( do_peace );
DECLARE_DO_FUN( do_pick );
DECLARE_DO_FUN( do_pinfo );

I wrote a small bit of test code which looks like:

void do_pinfo( CHAR_DATA *ch, char *argument)
{
set_char_color( AT_SCORE, ch);
ch_printf(ch, "\n\rTESTING\n\r", ch->pcdata->title);
}

in act_info.c

Right now, it shows up if I type 'commands', it shows up. If I type 'pinfo', however, it says 'Huh?'. If I type cmdtable, it shows up and it counts the number of times I have typed 'pinfo'. Any help/suggestions?
Top

Posted by Nick Gammon   Australia  (23,140 posts)  Bio   Forum Administrator
Date Reply #1 on Tue 03 Jun 2003 04:48 AM (UTC)
Message
What you have described works with normal SMAUG - I just tried it. You have a minor bug that I don't think would cause your problem, you should really have a %s in the line:

ch_printf(ch, "\n\rTESTING %s \n\r", ch->pcdata->title);

If you add the command to commands.dat it should be before the final #END line, however if it shows up in pinfo that should be correct.

Unless the SWR command parser is different from the normal one it doesn't seem possible for it to count the command without going past the part that says "Huh".

However having said that there seem to be around 113 places where it sends the string "Huh?" - a brute-force approach would be to edit each of those and change them slightly (eg. Huh (1)) in case it is failing some other test that isn't obvious.

A fairly neat way of doing that would be to simply replace each call which does:


send_to_char ("Huh?\n\r", ch);


with a macro (HUH) that expands out to:


#define HUH \
     ch_printf (ch, "Huh? At line %i of file %s\n\r", \
           __LINE__, __FILE__)


Then when you have it debugged just change the macro back to remove the debugging stuff.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Celestine   (29 posts)  Bio
Date Reply #2 on Tue 03 Jun 2003 05:45 AM (UTC)
Message
Where would I put the Macro? Or would I just go through all the files and find/replace the Huh's?
Top

Posted by Nick Gammon   Australia  (23,140 posts)  Bio   Forum Administrator
Date Reply #3 on Tue 03 Jun 2003 06:31 AM (UTC)
Message
Put the 3 lines starting with #define in mud.h (near the bottom, say) and then replace all the lines with Huh? in them. This did the trick for me...

First, look for them ...

grep Huh? *.c

You should see about 113 of them.

Then if you have perl working, do this (be careful, on Cygwin you might lose the lot). Make a BACKUP first.

perl -pi -e 's/send_to_char\( ?\"Huh\?\\n\\r\", ch ?\)/HUH/g' *.c

If this doesn't work, use a program like UltraEdit that has a "replace in multiple files" function.

There are a couple of variants of the Huh? line (extra space here and there). The perl line above should catch all of them, except about four, which look different:

bash-2.05a$ grep Huh *.c
act_comm.c: ch_printf(ch, "Huh?\n\r");
act_wiz.c: ch_printf(ch, "Huh?\n\r");
boards.c: send_to_char( "Huh? Type 'help note' for usage.\n\r", ch );
boards.c: send_to_char( "Huh? Type 'help note' for usage.\n\r", ch );
comments.c: send_to_char( "Huh? Type 'help comment' for usage (i hope!).\n\r", ch );

Fix those up manually (you can ignore the last two because they look different anyway).

Once you have done that, do a make and it should work. Try connecting and typing some nonsense ...

ladedah
Huh? At line 685 of file interp.c



- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Nick Cash   USA  (626 posts)  Bio
Date Reply #4 on Tue 03 Jun 2003 08:37 AM (UTC)
Message
I've done a lot of editing with SWR 1.0 and you did everything right. The only thing I saw that wasn't done is the function needs the return on it. Make it look like this:

void do_pinfo( CHAR_DATA *ch, char *argument)
{
set_char_color( AT_SCORE, ch);
ch_printf(ch, "\n\rTESTING\n\r", ch->pcdata->title);
return;
}

I'm not completely sure this would influence anything, but all commands return, to note when the do loop/function has ended. Anyways, if thats whats holding it up then yay. Otherwise, make sure your did a make(complied) and reboot the mud. Not sure what else to say.

~Nick Cash
http://www.nick-cash.com
Top

Posted by Celestine   (29 posts)  Bio
Date Reply #5 on Tue 03 Jun 2003 04:08 PM (UTC)
Message
Well it turns out I did everything right except for one thing. I'm too used to smaug's exe compiling into the correct folder. However, the version of SWR I have outputs the make file to the src directory, but it needs to be in the src directory to function properly. That said, I was wondering if there was something I could change in order to have it create the executable in the area folder automatically. Makefile is below.

CC = gcc
PROF =
NOCRYPT = -DNOCRYPT
#Uncomment the next line if you want request support
#DBUGFLG = -DREQUESTS
C_FLAGS = -g3 -Wall $(PROF) $(NOCRYPT) $(DBUGFLG)
L_FLAGS = $(PROF)

#delete?
NEED_CRYPT = -lcrypt
NEED_REG = -lgnuregex

O_FILES = act_comm.o act_info.o act_move.o act_obj.o act_wiz.o boards.o \
build.o clans.o comm.o comments.o const.o db.o fight.o \
handler.o hashstr.o id.o interp.o magic.o makeobjs.o \
misc.o mud_comm.o mud_prog.o player.o requests.o \
reset.o save.o shops.o skills.o special.o tables.o track.o update.o \
space.o bounty.o swskills.o

C_FILES = act_comm.c act_info.c act_move.c act_obj.c act_wiz.c boards.c \
build.c clans.c comm.c comments.c const.c db.c fight.c \
handler.c hashstr.c id.c interp.c magic.c makeobjs.c \
misc.c mud_comm.c mud_prog.c player.c requests.c \
reset.c save.c shops.c skills.c special.c tables.c track.c update.c \
space.c bounty.c swskills.c

H_FILES = mud.h bet.h

all:
# co $(H_FILES)
make swr
# rm -f $(H_FILES)

swr: $(O_FILES)
rm -f swr
$(CC) $(L_FLAGS) -o swr $(O_FILES) -lm -lcrypt
chmod g+w swr.exe
chmod g+w $(O_FILES)

.c.o: mud.h
$(CC) -c $(C_FLAGS) $<

clean:
rm -f $(O_FILES)
Top

Posted by Nick Gammon   Australia  (23,140 posts)  Bio   Forum Administrator
Date Reply #6 on Tue 03 Jun 2003 09:40 PM (UTC)
Message
Change these lines:


rm -f swr
$(CC) $(L_FLAGS) -o swr $(O_FILES) -lm -lcrypt
chmod g+w swr.exe


to


rm -f ../area/swr.exe
$(CC) $(L_FLAGS) -o ../area/swr.exe $(O_FILES) -lm -lcrypt
chmod g+w ../area/swr.exe

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Celestine   (29 posts)  Bio
Date Reply #7 on Wed 04 Jun 2003 12:26 AM (UTC)
Message
Thanks to Nick Gammon (or how should I refer to you?), I got the executable to output into the area folder. Now, I have yet another question, but this time it concerns the actual pinfo function. Right now, I have:

//Command for getting player info
void do_pinfo(CHAR_DATA * ch, char *argument)
{
CHAR_DATA *victim;

if (IS_NPC(ch))
{
ch_printf(ch, "\n\r NPC's don't have Player Infos\n\r");
return;
}

set_char_color(AT_SCORE, ch);
send_to_char("+--------------------------------------------------------------------------+\n\r", ch);
ch_printf(ch,"|Name: %s |\n\r", victim->name );
/*ch_printf(ch,"|Gender: %s |\n\r", victim->sex );
ch_printf(ch,"|Age: %s |\n\r", get_age(victim) );
ch_printf(ch,"|Align: %s |\n\r", victim->alignment );
send_to_char("+--------------------------------------------------------------------------+\n\r", ch);
*/// ch_printf(ch,"|Personality: %s |\n\r", victim->personality );
// send_to_char("+--------------------------------------------------------------------------+\n\r", ch);
/* ch_printf(ch,"|History: %s |\n\r", victim->history );
send_to_char("+--------------------------------------------------------------------------+\n\r", ch);
ch_printf(ch,"|Position: ");
switch (ch->position)
{
case POS_DEAD:
ch_printf(ch, "%s is slowly decomposing. |", victim->name );
break;
case POS_MORTAL:
ch_printf(ch,"%s is mortally wounded. |", victim->name );
break;
case POS_INCAP:
ch_printf(ch,"%s is incapacitated. |", victim->name );
break;
case POS_STUNNED:
ch_printf(ch,"%s is stunned. |", victim->name );
break;
case POS_SLEEPING:
ch_printf(ch,"%s is sleeping. |", victim->name );
break;
case POS_RESTING:
ch_printf(ch,"%s is resting. |", victim->name );
break;
case POS_STANDING:
ch_printf(ch,"%s is standing. |", victim->name );
break;
case POS_FIGHTING:
ch_printf(ch,"%s is fighting. |", victim->name );
break;
case POS_MOUNTED:
ch_printf(ch,"%s is fighting. |", victim->name );
break;
case POS_SITTING:
ch_printf(ch,"%s is sitting. |", victim->name );
break;
}*/
send_to_char("+--------------------------------------------------------------------------+\n\r", ch);
send_to_char("\n\r", ch);
return;
}

If you notice, there's quite a bit commented out. I was trying to find what was wrong with it, and apparently the flaw is when the function first makes a reference to the "victim"'s name variable. If I run the swr file and type in "pinfo," the MUD crashes and says something about transferring data to swr.exe.stackdump. That file's contents after the crash are as follows:

Exception: STATUS_ACCESS_VIOLATION at eip=004D4AC4
eax=00000000 ebx=00000000 ecx=0A10C1C8 edx=0A10C1C8 esi=00000000 edi=00552C20
ebp=0022EC88 esp=0022EC70 program=C:\Cygwin\home\Hailey\swrmin\dist\area\swr.exe
cs=001B ds=0023 es=0023 fs=003B gs=0000 ss=0023
Stack trace:
Frame Function Args
0022EC88 004D4AC4 (0A10D7C0, 0022F955, 0A10DCF0, 0022F0F0)
0022F8F8 004A6934 (0A10D7C0, 0022F955, 0022F7F4, 0022F7F4)
0022FD68 00470D86 (0056C1B0, 00000000, 00000066, 77E7A730)
0022FDA0 0046FF26 (00000001, 0A041E68, 0A040328, 00000005)
0022FF40 61007408 (610D1F58, FFFFFFFE, 0000001C, 610D1E7C)
0022FF90 610076ED (00000000, 00000000, 00000001, 00000000)
0022FFB0 00552572 (0046FB88, 037F0009, 0022FFF0, 77E814C7)
0022FFC0 0040103C (70A71A29, 80000002, 7FFDF000, EEB86CF0)
0022FFF0 77E814C7 (00401000, 00000000, 78746341, 00000020)
End of stack trace
Top

Posted by Boborak   USA  (228 posts)  Bio
Date Reply #8 on Wed 04 Jun 2003 12:55 AM (UTC)

Amended on Wed 04 Jun 2003 12:59 AM (UTC) by Boborak

Message
Here's the problem. You have CHAR_DATA *victim; declared, but you're not setting 'victim' to anything before using it. So, when the mud makes an attempt to access that variable, there's nothing to access, which is a bad thing and the mud crashes. As good as computers are, they're not very skilled at reading your mind or making assumptions, and are quite picky.

I would assume that you want 'pinfo' to display info on the char that is typing the command. If that's the case, everywhere you have 'victim' replace it with 'char', and recompile. You should be good to go.

Another faster fix, would be to change:

'CHAR_DATA *victim;' to 'CHAR_DATA *victim = ch;'

I would reccommend the first however, as then you're just wasting memory.
Top

Posted by Celestine   (29 posts)  Bio
Date Reply #9 on Wed 04 Jun 2003 01:01 AM (UTC)
Message
Actually, I want it to be a command where the victim is another player. Meaning you type say... 'pinfo bob' (without quotes) where bob is the name of the player you want the info about.
Top

Posted by Boborak   USA  (228 posts)  Bio
Date Reply #10 on Wed 04 Jun 2003 01:29 AM (UTC)
Message
If that's the case, then you need to set the 'victim' to *something*. A decent function to use would be get_char_world() or get_char_room() This returns a CHAR_DATA variable based on the argument you give it. It'll return NULL if a char wasn't found.

Adding this somewhere BEFORE you use victim should do teh trick.


if( (victim = get_char_world(ch, argument)) == NULL)
{
   send_to_char("No such player online.\n\r", ch);
   return;
}
Top

Posted by Celestine   (29 posts)  Bio
Date Reply #11 on Wed 04 Jun 2003 03:04 AM (UTC)

Amended on Wed 04 Jun 2003 04:26 AM (UTC) by Celestine

Message
Thanks Boborak, your addition made the command work. I have another question for this command regarding formatting, however. If you notice, the print has something like:

|Name: %s [a certain number of spaces] |

However, the location of the last | varies depending on how long the name (or whatever variable) is. Is there a way to fix this? And while I'm on that topic, I have the history data which is basically like a description. It's entered in the same way too. Is there a way to make a box which expands according to the length of that data (like the number of lines and such)?

Another question. I finished adding the history by itself, and that worked. Now I added yet another char field called 'personality'. I uncommented/commented each addition in and out, and I found that the problem was located at clear_char function in db.c

void clear_char( CHAR_DATA *ch )
{
ch->editor = NULL;
ch->hunting = NULL;
ch->fearing = NULL;
ch->hating = NULL;
ch->name = NULL;
ch->short_descr = NULL;
ch->long_descr = NULL;
ch->description = NULL;
ch->personality = NULL;
...
}

I basically took the history char field (which works if I take out the personality field), and copied each line and put it in the correct spot. On save.c, I did make sure to put it under the case 'P': as well. If I include this, the compilation is clean, but upon booting up the server, I receive another dumping stack trace like the access violation error posted above.
Top

Posted by Nick Gammon   Australia  (23,140 posts)  Bio   Forum Administrator
Date Reply #12 on Wed 04 Jun 2003 06:22 AM (UTC)
Message
Quote:

Thanks to Nick Gammon (or how should I refer to you?),


You can call me Nick. :)

As for the crash, try rebuilding everything, as it sounds like you have changed the layout in mud.h?

In other words, remove all object files:

rm *.o

(not the .c files).

Then do a "make".

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Nick Gammon   Australia  (23,140 posts)  Bio   Forum Administrator
Date Reply #13 on Wed 04 Jun 2003 06:40 AM (UTC)
Message
Quote:

I'm not completely sure this would influence anything, but all commands return, to note when the do loop/function has ended.


"void" functions don't need a return statement, they will return anyway (what else can they do?).

Functions that are not declared void need a return, otherwise you have said you will return something but don't. eg.


int add (int a, int b)
  {
  return a + b;
  }



- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Celestine   (29 posts)  Bio
Date Reply #14 on Thu 05 Jun 2003 12:51 AM (UTC)
Message
The deleting/remaking of the files seemed to dispose of the crash. However, I'm still faced with the problem of the formatting. Basically, It'd work if I could find out how many lines there were in the history (which is created the same way a desc is. Any help?
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


75,827 views.

This is page 1, subject is 2 pages long: 1 2  [Next page]

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.