Author Topic: Prompted nuke command  (Read 5242 times)

Offline daelaskai

  • BFF
  • ***
  • Posts: 174
    • View Profile
Prompted nuke command
« on: October 09, 2006, 10:52:59 pm »
Below is the nuke command that I set up on my mud.  I hope everyone likes it and wanted to share it with the world!



Comments/suggestions/improvements are welcome. :)



code:

/*    /secure/cmds/adm/rid.c
 *    from the Dead Soulsr2 Object Library
 *    command to get rid of players
 *    created by Descartes of Borg 951015
 */

/*    Modified the rid command to do pictures
 *    on a nuke and can do silent nukes or
 *    publicly broadcast nukes. Pictures are
 *    saved in /secure/save/nukes directory
 *    created for just this command.
 *    Currently, the pictures are set up
 *    without an extension.  If you would
 *    like to add the extension, you may
 *    modify this code as you wish.
 *
 *    Added option to banish the name being
 *    nuked.
 *
 *    Instructions:
 *    Type: nuke and hit enter
 *    follow the prompts :)
 *
 *    Hope you all enjoy this command.  Feel
 *    free to give suggestions :)
 *
 *    Thanks go to Cratylus for the original
 *    rid command that was modified to make
 *    what you see here!
 */

#include <lib.h>
#include <dirs.h>
#include <daemons.h>
#include <privs.h>
#include <flags.h>

inherit LIB_DAEMON;
#define NUKES    "/secure/save/nukes/"
int get_nuked(string ags);
int get_picture(string pic, string who);
int get_silent(string args, string who, string pic);
int get_ban(string ban, string who, string pic, int silent);

object ob;
string str, file, who, pic, tmp;
mixed array dir;
int silent, i, ban;

static void EndRid(string str);

int cmd() {

    if(!archp(previous_object())) return 0;
    tmp = "\t%^MAGENTA%^" + mud_name() + " Ascii%^RESET%^ %^RED%^Nuke%^RESET%^ %^MAGENTA%^Tool%^RESET%^\n";
    tmp += "\t===========================\n\n";
    write( tmp + "%^RED%^Whom would you like to nuke?%^RESET%^" );
    input_to( (: get_nuked :), I_NOECHO );
    return 1;
}

int get_nuked(string str){
 
  if(!str || str == "" ) {
     write("No person entered.  Aborting.");
     return 0;
    }
    who = capitalize(str);
    str = convert_name(who);
    if( member_group(str, PRIV_SECURE) || member_group(str, PRIV_ASSIST) ){
   write("You must first remove this person from a secure group.");
   return 0;
    }
  if( !user_exists(who) ) {
   write("No such person: " + who + ".");
   return 0;
    }

  write( "Okay.  Nuking " + who + "." );
 
  //  This is where I display the files in the nukes/ directory that can
  //  be chosen during the nuking process.  To use this command as is,
  //  do not save the pictures with any extension (such as .c or .txt).
 
   dir = get_dir("/secure/save/nukes/");
        for(i=0; i<sizeof(dir); i++) dir = replace_string(dir, "_", " ");
        message("info", "\n" + replace_string(format_page(dir, 3), "\n", " ") + "\n",
          this_player());
  write( "%^RED%^What picture would you like to nuke " + who + " with?%^RESET%^ (Default: nuke)" );
  input_to( (: get_picture :), I_NOECHO, who );
  return 1;
}

int get_picture(string pic, string who) {

  if( !pic || pic == "" ) pic = "nuke";
   if( !file_exists("/secure/save/nukes/" + pic) ) {
    write( "Picture " + pic + " not found." );
    return 0;
  }
  write( "Okay.  Using the " + pic + " picture." );
  write( "%^RED%^Would you like the nuke to be broadcast publicly?%^RESET%^ (Default: Yes)" );
  input_to( (: get_silent :), I_NOECHO, who, pic );
  return 1;
}

int get_silent(string args, string who, string pic) {

    switch(args){
  case "yes" : silent = 0; break;
  case "no" : silent = 1; break;
  default : silent = 0; break;
  }

  write( "Okay.  Proceeding." );
  write( "%^RED%^Would you like to banish this name from being used again?%^RESET%^ (Default: No)" );
  input_to( (: get_ban :), I_NOECHO, who, pic, silent );
  return 1;
}


int get_ban(string banish, string who, string pic, int silent) {

    switch(banish){
  case "yes" : ban = 1; break;
  case "no" : ban = 0; break;
  default : ban = 0; break;
  }

  if( ob = find_player(convert_name(who)) ) {
     who = (string)ob->GetCapName();
     message("system", "You are being ridded from " + mud_name() + ".",
       ob);
     if( !((int)ob->eventDestruct()) ) destruct(ob);
    }
    if( !silent){
      message( "system", "\n" + read_file(NUKES+pic) + "\n", users() );
      message( "system", "%^BOLD%^RED%^" + who + " has been wiped from existence!%^RESET%^", users() );
      }
  else
    write(who + " has been ridded from " + mud_name() + ".");
  file = save_file(who) + __SAVE_EXTENSION__;
  if( rename(file, DIR_RID + "/" + lower_case(who) + __SAVE_EXTENSION__) ) {
     write("Rename failed, security violation logged.");
     log_file("security", "\n*****\nRid violation attempted\n"
       "Target: " + who + "\nCall stack:\n" +
       sprintf("%O\n", previous_object(-1)));
     return 1;
    }
  write("Enter reason for ridding " + who + ".");
  file = DIR_TMP + "/" + (string)this_player()->GetKeyName();
  rm(file);
  this_player()->eventEdit(file, (: EndRid, who :));
  return 1;
}

static void EndRid(string who) {

    file = DIR_TMP + "/" + (string)this_player()->GetKeyName();
    if( !(str = read_file(file)) ) str = "No comment.\n";
    log_file("rid", "\n" + who + " by " + (string)this_player()->GetCapName() +
      "\n" + str + "\n");
    PLAYERS_D->RemoveUser(lower_case(who));
    if( ban ){
      write( "The name " + who + " has been banished!" );
      catch(call_other(BANISH_D, "banish_name", who));
    }
}

void help() {
    write( @EndText
Syntax: rid <name>
Effect: Deletes, nukes, wipes out and annhilates unwanted player <name>
See also: demote, promote, sponsor
EndText
    );
}




Daelas/Amun-Ra

Offline irmo

  • Acquaintance
  • *
  • Posts: 36
    • View Profile
Re: Prompted nuke command
« Reply #1 on: March 13, 2008, 05:22:01 pm »
Trying to get this to work on DS 2.6 fails, resulting in the following errors:

2008.03.13-23.09
*Error in loading object '/secure/cmds/admins/rid'
Object: /secure/sefun/sefun at /secure/sefun/load_object.c:14

'<fake>' at /secure/save/creators/i/irmo (/<driver>) at line 0
'cmdAll' at /secure/save/creators/i/irmo (/lib/command.c) at line 162
'cmd' at /secure/cmds/creators/update at line 110
'eventUpdate' at /secure/cmds/creators/update at line 138
'load_object' at /secure/sefun/sefun at /secure/sefun/load_object.c:14
'CATCH' at /secure/sefun/sefun at /secure/sefun/load_object.c:14
Trace written to /log/catch
/secure/cmds/admins/rid.c line 86: Bad assignment ( array vs string ).

*Error in loading object '/secure/cmds/admins/rid'
Object: /secure/cmds/creators/update at line 151

'<fake>' at /secure/save/creators/i/irmo (/<driver>) at line 0
'cmdAll' at /secure/save/creators/i/irmo (/lib/command.c) at line 162
'cmd' at /secure/cmds/creators/update at line 110
'eventUpdate' at /secure/cmds/creators/update at line 151
'CATCH' at /secure/cmds/creators/update at line 151
Trace written to /log/catch
/secure/cmds/admins/rid: Error in update
*Error in loading object '/secure/cmds/admins/rid'


I took a look at rid.c, line 86 but I can't make out what's wrong.

Code: [Select]
for(i=0; i<sizeof(dir); i++) dir = replace_string(dir, "_", " ");
Anyone have any suggestions?
I'm not as think as you drunk I am.

Offline daelaskai

  • BFF
  • ***
  • Posts: 174
    • View Profile
Re: Prompted nuke command
« Reply #2 on: March 13, 2008, 08:13:58 pm »
Wow, I haven't looked at this in a long time and this was one of the first things I coded.  I'll look into it.  Thanks.

Daelas

Offline cratylus

  • Your favorite and best
  • Administrator
  • ***
  • Posts: 1022
  • Cratylus@Dead Souls <ds> np
    • View Profile
    • About Cratylus
Re: Prompted nuke command
« Reply #3 on: March 13, 2008, 08:24:25 pm »
Quote
Wow, I haven't looked at this in a long time and this was one of the first things I coded.  I'll look into it.

Boy, do I know that feeling!

-Crat

Offline Nulvect

  • BFF
  • ***
  • Posts: 127
    • View Profile
Re: Prompted nuke command
« Reply #4 on: March 13, 2008, 08:27:03 pm »
Code: [Select]
for(i=0; i<sizeof(dir); i++) dir = replace_string(dir, "_", " ");

dir is a mixed array, so you want this:

Code: [Select]
for(i=0; i<sizeof(dir); i++) dir[i] = replace_string(dir[i], "_", " ");

or, slightly faster:

Code: [Select]
dir = map(dir, (: replace_string($1, "_", " ") :) );

Offline daelaskai

  • BFF
  • ***
  • Posts: 174
    • View Profile
Re: Prompted nuke command
« Reply #5 on: March 13, 2008, 08:27:49 pm »
The only thing I can think of is a coding error on my part.  Try the following code:

Code: [Select]
/*    /secure/cmds/adm/rid.c
 *    from the Dead Soulsr2 Object Library
 *    command to get rid of players
 *    created by Descartes of Borg 951015
 */

#include <lib.h>
#include <dirs.h>
#include <daemons.h>
#include <privs.h>
#include <flags.h>

inherit LIB_DAEMON;
#define NUKES    "/secure/save/nukes/"
int get_nuked(string ags);
int get_picture(string pic, string who);
int get_silent(string args, string who, string pic);
int get_ban(string ban, string who, string pic, int silent);

object ob;
string str, file, who, pic, tmp;
mixed array dir;
int silent, i, ban;

static void EndRid(string str);

int cmd() {

    if(!archp(previous_object())) return 0;
    tmp = "\t%^MAGENTA%^" + mud_name() + " Ascii%^RESET%^ %^RED%^Nuke%^RESET%^ %^MAGENTA%^Tool%^RESET%^\n";
    tmp += "\t===========================\n\n";
    write( tmp + "%^RED%^Whom would you like to nuke?%^RESET%^" );
    input_to( (: get_nuked :), I_NOECHO );
    return 1;
}

int get_nuked(string str){
 
  if(!str || str == "" ) {
  write("No person entered.  Aborting.");
  return 0;
    }
    who = capitalize(str);
    str = convert_name(who);
    if( member_group(str, PRIV_SECURE) || member_group(str, PRIV_ASSIST) ){
write("You must first remove this person from a secure group.");
return 0;
    }
  if( !user_exists(lower_case(who)) ) {
write("No such person: " + who + ".");
return 0;
    }

  write( "Okay.  Nuking " + who + "." );
dir = get_dir("/secure/save/nukes/");
        for(i=0; i<sizeof(dir); i++) dir[i] = replace_string(dir[i], "_", " ");
        message("info", "\n" + replace_string(format_page(dir, 3), "\n", " ") + "\n",
          this_player());
  write( "%^RED%^What picture would you like to nuke " + who + " with?%^RESET%^ (Default: nuke)" );
  input_to( (: get_picture :), I_NOECHO, who );
  return 1;
}

int get_picture(string pic, string who) {

  if( !pic || pic == "" ) pic = "nuke";
if( !file_exists("/secure/save/nukes/" + pic) ) {
    write( "Picture " + pic + " not found." );
    return 0;
  }
  write( "Okay.  Using the " + pic + " picture." );
  write( "%^RED%^Would you like the nuke to be broadcast publicly?%^RESET%^ (Default: Yes)" );
  input_to( (: get_silent :), I_NOECHO, who, pic );
  return 1;
}

int get_silent(string args, string who, string pic) {

    switch(args){
  case "yes" : silent = 0; break;
  case "no" : silent = 1; break;
  default : silent = 0; break;
  }

  write( "Okay.  Proceeding." );
  write( "%^RED%^Would you like to banish this name from being used again?%^RESET%^ (Default: No)" );
  input_to( (: get_ban :), I_NOECHO, who, pic, silent );
  return 1;
}


int get_ban(string banish, string who, string pic, int silent) {

    switch(banish){
  case "yes" : ban = 1; break;
  case "no" : ban = 0; break;
  default : ban = 0; break;
  }

  if( ob = find_player(convert_name(who)) ) {
  who = (string)ob->GetCapName();
  message("system", "You are being ridded from " + mud_name() + ".",
    ob);
  if( !((int)ob->eventDestruct()) ) destruct(ob);
    }
  if( !silent){
    message( "system", "\n" + read_file(NUKES+pic) + "\n", users() );
    message( "system", "%^BOLD%^RED%^" + who + " has been wiped from existence!%^RESET%^", users() );
    }
  else
    write(who + " has been ridded from " + mud_name() + ".");
  file = save_file(who) + __SAVE_EXTENSION__;
  if( rename(file, DIR_RID + "/" + lower_case(who) + __SAVE_EXTENSION__) ) {
  write("Rename failed, security violation logged.");
  log_file("security", "\n*****\nRid violation attempted\n"
    "Target: " + who + "\nCall stack:\n" +
    sprintf("%O\n", previous_object(-1)));
  return 1;
    }
  write("Enter reason for ridding " + who + ".");
  file = DIR_TMP + "/" + (string)this_player()->GetKeyName();
  rm(file);
  this_player()->eventEdit(file, (: EndRid, who :));
  return 1;
}

static void EndRid(string who) {

    file = DIR_TMP + "/" + (string)this_player()->GetKeyName();
    if( !(str = read_file(file)) ) str = "No comment.\n";
    log_file("rid", "\n" + who + " by " + (string)this_player()->GetCapName() +
      "\n" + str + "\n");
    PLAYERS_D->RemoveUser(lower_case(who));
    if( ban ){
      write( "The name " + who + " has been banished!" );
      catch(call_other(BANISH_D, "banish_name", who));
    }
}

void help() {
    write( @EndText
Syntax: rid <name>
Effect: Deletes, nukes, wipes out and annhilates unwanted player <name>
See also: demote, promote, sponsor
EndText
    );
}

I tested it on a stock DS 2.6.2 and it worked as long as I had a folder called /secure/save/nukes and had some picture files in there to test with.

Daelas

Offline daelaskai

  • BFF
  • ***
  • Posts: 174
    • View Profile
Re: Prompted nuke command
« Reply #6 on: March 13, 2008, 08:28:37 pm »
P.S.

Nulvect is correct.  Using the map() function will be slightly faster.

Daelas

Offline irmo

  • Acquaintance
  • *
  • Posts: 36
    • View Profile
Re: Prompted nuke command
« Reply #7 on: March 13, 2008, 08:52:06 pm »
I'd say you guys saved me from having another sleepless night, but I think I'll stay up for a while anyway. :)

Thanks! Your help was very much appreciated.
I'm not as think as you drunk I am.

Offline daelaskai

  • BFF
  • ***
  • Posts: 174
    • View Profile
Re: Prompted nuke command
« Reply #8 on: March 14, 2008, 12:36:00 am »
No problem, Irmo!  That's why I posted this in the first place so people could use it in its entirety or benefit from it as an example.
Granted, there may be better ways to do some of the stuff, (such as the map() function) but all in all, it was a good start for a newbie like me.  Lpmuds.net is a great community space for people of all levels of experience so we hope you continue to use it and spread the word :).

Daelas

Offline Raudhrskal

  • BFF
  • ***
  • Posts: 214
  • The MUD community needs YOUR help!
    • View Profile
Re: Prompted nuke command
« Reply #9 on: March 14, 2008, 03:50:37 am »
The only thing I can think of is a coding error on my part.  Try the following code:

Nope, it just wasn't previously posted between [ code ] tags, and array indexes [ i ] has been interpreted as italic text directive ;)

Look, parts of the code at the first post are slanted.
I think, therefore i may be wrong.
Please note that if you met a Raudhrskal in a place that's not related to muds, it wasn't me. *sigh*... back when I started there was zero hits on google for that name...

Offline cratylus

  • Your favorite and best
  • Administrator
  • ***
  • Posts: 1022
  • Cratylus@Dead Souls <ds> np
    • View Profile
    • About Cratylus
Re: Prompted nuke command
« Reply #10 on: March 14, 2008, 10:44:47 am »
Quote
The only thing I can think of is a coding error on my part.

I'm pretty sure I'm partly, if not entirely, to blame for the code problem.

The original post was made in October 2006, when this forum used
Beehive software.

A few months later we migrated to Simple Machines software, and
the migration, though mostly successful, was not perfect. For example,
polls did not survive the transition, and member post counts and total
post counts are not quite right.

It looks like one of the imperfections may have been that code posted from
back then is now being treated as regular text and being emoticonized and
bbcified. :(

On the plus side, at least the old content were preserved, however
imperfectly. I'd rather have a little confusion than the loss of contributions.

Having said all that, mea culpa, my apologies.

-Crat

Offline Raudhrskal

  • BFF
  • ***
  • Posts: 214
  • The MUD community needs YOUR help!
    • View Profile
Re: Prompted nuke command
« Reply #11 on: March 17, 2008, 01:47:56 am »
Not your fault. Database conversion is always a royal pain in the a**. And because there is no way
of reliable automatic detection of LPC snippets in old posts, the only way to [ code ] them would be manual vgrep.
Personally, I think Beehive was awful. SMF is the second most popular (next to phpBB)
and best-looking forum software. Administration is easy, and convenient. BTW, what do you think
about some custom visual theme for the forum?
I think, therefore i may be wrong.
Please note that if you met a Raudhrskal in a place that's not related to muds, it wasn't me. *sigh*... back when I started there was zero hits on google for that name...