cmdeditsnip.ZIP
snippets · 10.4 KB · 2010-03-30
Command editor snippet (cmdedit.c with install notes): edit commands online.
Download « Back to the snippets list
install.c
/*Backup your code! This is a snippet, written by Davion. This snippet was written to
*Work with Rom24b6, with OLC 1.81 and hasn't been tested with anything
*else. This will remove your command table, and change it to a linked
*list, as well, it comes along with an OLC for them. Disabling the command
*should be easy enough, I may releace a snippet later which allows for
*command disabling. Now remember. Do not skip ahead. This involves file i/o
*and converting to your cmd_list instead of a table. So things have to be
*done in order.*/
/*Ok, make sure to back up all your code, and activate the save functions.
*So first, add cmdedit.c to your Makefile, and add these prototypes to merc.h
*right underneath the prototypes for comm.c */
//cmdedit.c
void save_cmd_table args( ( ) );
void load_cmd_list args( ( ) );
/*Now, you want to save the cmd list, so add the struct to merc.h */
typedef struct command_type CMD_DATA;
struct command_type
{
CMD_DATA * prev;
CMD_DATA * next;
CMD_DATA * char_next;
bool valid;
char * name;
DO_FUN * do_fun;
sh_int position;
sh_int level;
sh_int log;
sh_int show;
sh_int cat;
};
CMD_DATA * cmd_first;
CMD_DATA * cmd_last;
/*Now add this to olc_save.c under the call to asave world. Or any
*Asave function.*/
save_cmd_table();
/*That was easy, huh? :P. Now do a clean make. And copyover!
*Once booted up, execute the command you set save_cmd_table().
*Make sure that you have the directory existant (I would as well, suggest getting
*the fileopen snippet from kyndig.com. Or else, re-write the file i/o in cmdedit.c
*to work with your base. Now, I have alot of commands (450, roughly)
*So you may have to run through the cmdfun_table and set all your do_funs's.
*Best way to do this, take your cmd_table (which is now useless) and hack at it
*so just the name, and the do_fun is left. Then go through the table, make sure
*thier arn't any duplicates, and the name is the same as the do_fun, so if its do_backstab
*make sure the name is "backstab". Tedious, I know. Ok, now you gotta enter cmdedit.c and you'll
*see the prototype at the top of the file for char *dofuname commented out, and one that isn't.
*Delete the one that IS NOT commented out, and uncomment the other one. (Remove the //'s.).
*Keep going through the file. On line 68, you have a save_cmd_table commented out. Take the
*comments out, and delete the save_cmd_table right below it. On line 184 there is a dofuname commented
*out, uncomment it, and delete the one immediately following it. Add a function call to load_cmd_table()
*in boot_db in db.c. Just around where you see things like->*/
fix_mobprogs( );
fix_objprogs( );
fix_roomprogs( );
fBootDb = FALSE;
convert_objects( ); /* ROM OLC */
log_string( "Loading area update." );
area_update( );
load_boards(); /* Load all boards */
save_notes();
load_bans();
load_songs();
/*Make sure that if you have cmd_disabling that loads from a file, or
*anything else that deals with commands on boot, that load_cmd_table()
*is called before them, cause ya can't call functions that havn't been
*loaded yet, make sense? Good. So add*/
load_cmd_table();
/*To that list. Make sure that the cmd_table is removed and you have to change
*void interpet, in interp.c. Add */
CMD_DATA *pCmd;
/*To the variable list at the top of the function. There should be a comment, that reads something like
*"Look for command in command table." Its basicly a for loop that loops through the cmd table. Remove it and add */
for ( pCmd = cmd_first; pCmd ; pCmd = pCmd->next )
{
if ( command[0] == pCmd->name[0]
&& !str_prefix( command, pCmd->name )
&& pCmd->level <= trust )
{
found = TRUE;
break;
}
}
/*Now go through the rest of interpet() and look for things like cmd_table[cmd]. and change
*them to pCmd->. So instead of say, cmd_table[cmd].name you have pCmd->name, ect. As well,
*You might want to go through the whole file looking for loops through the cmd_table and changing
*them accordingly. So instead of for(cmd = 0; cmd_table[cmd].name != NULL ; cmd++ ) you have
* for(pCmd = cmd_first ; pCmd ; pCmd = pCmd->next ). But yeah, you get the idea. Now in olc.h add
* this with the other ED_'s at the top of the file.*/
/***BEGINING OF OLC.H***/
#define ED_COMMAND 12
/*Remember, instead of 12, use the next free one from your list (If you only go up to 4, make it 5).
*Now add this prototype to the rest, near the top of the file.*/
void cmdedit args( ( CHAR_DATA *ch, char *argument ) );
/*Add to the table prototypes */
extern const struct olc_cmd_type cmdedit_table[];
/*To the editor commands*/
DECLARE_DO_FUN( do_cmdedit );
/*Under all the other prototypes that use DECLARE_OLC_FUN */
//Cmdedit functions
DECLARE_OLC_FUN( cmdedit_show );
DECLARE_OLC_FUN( cmdedit_level );
DECLARE_OLC_FUN( cmdedit_dofun );
DECLARE_OLC_FUN( cmdedit_log );
DECLARE_OLC_FUN( cmdedit_showcmd );
DECLARE_OLC_FUN( cmdedit_position );
DECLARE_OLC_FUN( cmdedit_catagory );
DECLARE_OLC_FUN( cmdedit_name );
DECLARE_OLC_FUN( cmdedit_new );
DECLARE_OLC_FUN( cmdedit_move );
/*Add this to the macro's*/
#define EDIT_COMMAND( Ch, Cmd ) ( Cmd = (CMD_DATA *) Ch->desc->pEdit )
/****END OF OLC.H****/
/****BEGINING OF OLC.C****/
/*Add this to the switch statement in run_olc_editor*/
case ED_COMMAND:
cmdedit( d->character, d->incomm);
break;
/*Add this to the switch statement in olc_ed_name*/
case ED_COMMAND:
sprintf(buf, "CmdEdit" );
break;
/*Add this to the switch statement in show_commands*/
case ED_COMMAND:
show_olc_cmds( ch, cmdedit_table );
break;
/*Add this table under the rest */
const struct olc_cmd_type cmdedit_table[] =
{
{ "commands", show_commands },
{ "show", cmdedit_show },
{ "name", cmdedit_name },
{ "catagory", cmdedit_catagory },
{ "dofun", cmdedit_dofun },
{ "level", cmdedit_level },
{ "cmdshow", cmdedit_showcmd },
{ "log", cmdedit_log },
{ "new", cmdedit_new },
{ "move", cmdedit_move },
{ "position", cmdedit_position },
{ NULL, 0 }
};
/*Add this under void medit*/
void cmdedit( CHAR_DATA *ch, char *argument )
{
char command[MAX_INPUT_LENGTH];
char arg[MAX_STRING_LENGTH];
int cmd;
CMD_DATA *pCmd;
arg[0] = '\0';
smash_tilde( argument );
strcpy( arg, argument );
argument = one_argument( argument, command );
EDIT_COMMAND(ch, pCmd);
if ( !str_cmp(command, "done") )
{
edit_done( ch );
return;
}
if ( command[0] == '\0' )
{
cmdedit_show(ch, argument);
return;
}
/* Search Table and Dispatch Command. */
for ( cmd = 0; cmdedit_table[cmd].name != NULL; cmd++ )
{
if ( !str_prefix( command, cmdedit_table[cmd].name ) )
{
cmdedit_table[cmd].olc_fun( ch, argument );
return;
}
}
/* Default to Standard Interpreter. */
interpret( ch, arg );
return;
}
/*Add this to the bottom of the editor_table */
{ "commands", do_cmdedit },
/*Throw this in at the bottom of olc.c */
void do_cmdedit( CHAR_DATA *ch, char *argument )
{
CMD_DATA *cmd;
char arg[MAX_STRING_LENGTH];
arg[0] = '\0';
if ( IS_NPC(ch) )
return;
argument = one_argument(argument, arg);
if(arg[0] == '\0')
{
send_to_char("Syntax: Cmdedit <command>\n\r",ch);
return;
}
if( (cmd = cmd_lookup(arg) ) == NULL )
{
send_to_char("What command is this?\n\r",ch);
return;
}
ch->desc->pEdit = (void *) cmd;
ch->desc->editor = ED_COMMAND;
printf_to_char(ch, "Entering Command Editor for %s.\n\r", cmd->name );
return;
}
/****END OF OLC.C****/
/*And thats it. Run a clean make, and do a copyover. Everything should work
*And you should have cmd_edit! (If you don't, simply add the do_fun to the
*cmdfun_table, and add the entry to the command.dat file. Entry looks like */
Name cmdedit~
Dofun cmdedit~
Position 0
Level 0
Log 1
Show 1
Cat 0
End
/*As well, you might want to look into an autosaving for olc's and what not.
*because as it is, the only way command save is with you executing the command
*you put save_cmd_table() in. Anyawys, and problems/bugs e-mail me at davionkalhen@hotmail.com
*and have fun!
*Davion */Archive contents (2 files)
| File | Size |
|---|---|
| cmdedit.c | 27.6 KB |
| install.c | 8.5 KB |