admin.cc
musicmud-2.1.6/src/extras/admin.cc · 39.7 KB
From the archive musicmud2.1.6.tar.gz
Download the archive « Back to the archive contents
/*
* MusicMUD - Admin module
* Copyright (C) 1998-2003 Abigail Brady
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <signal.h>
#include <sys/types.h>
#include <dirent.h>
#include <ctype.h>
#include <set>
#include "musicmud.h"
#include "verbs.h"
#include "State.h"
#include "zoneload.h"
#include "magic.h"
#include "msi.h"
#include "misc.h"
#include "Socket.h"
#include "config.h"
#include "startup.h"
#include "trap.h"
#include "flags.h"
#include "pflags.h"
#include "pflagnames.h"
#include "util.h"
#include "levels.h"
#include "actions.h"
#include "nations.h"
#define MODULE "admin"
#define is_room(r) (r->get_flag(FL_ROOM))
static char *str(int what, char *buffer, bool qmark) {
if (qmark) return "???";
sprintf(buffer, "%i", what);
return buffer;
}
extern Socket *primary;
extern Socket *secondary;
/** closeport
*
* This stops the mud from accepting new connections.
*
**/
static bool verb_closeport(MudObject *, int, const char **) {
if (primary || secondary) {
log(PFL_SEEINFO, 0, "admin", "not accepting new connections");
msi::done();
}
return true;
}
/** openport
*
* This starts the acception of new connections on the specified port.
*
**/
static bool verb_openport(MudObject *player, int argc, const char **argv) {
if (primary || secondary) {
msi::done();
}
if (argc > 1) {
int port = atoi(argv[1]);
log(PFL_SEEINFO, 0, "admin", "now accepting connections : port %i", port);
msi::init(port);
} else {
player->printf("which port?\n");
}
return true;
}
/** chstr
*
* Icky internal command. You don't need to know about this.
*
**/
static bool verb_chstr(MudObject *player, int argc, const char *argv[]) {
if (argc < 4) {
player->printf("chstr <object> <property> <value>\n");
return true;
}
MudObject *what = find_object(player, argv[1]);
if (!what) {
player->printf("can't find the %s\n", argv[1]);
return true;
}
if (streq(argv[2], "owner")) {
player->printf("Use \"chown\" instead.\n");
return true;
}
string value = the_rest(argc, argv, 3);
if (strncmp(argv[2], "lua.", 4)==0 ||
strncmp(argv[2], "!lua.", 5)==0) {
string nv = ",";
nv += player->id;
nv += ",1;";
nv += value;
value = nv;
}
what->set(argv[2], value.c_str());
if (!player->ilc) {
log(PFL_SEEINFO, LEV_INTERNAL, "fiddle", "chstr by %s : %s %s %s", player->id, what->id, argv[2], value.c_str());
}
return true;
}
/** chown
*
* Icky internal command. You don't need to know about this.
*
**/
static bool verb_chown(MudObject *player, int argc, const char *argv[]) {
if (argc < 3) {
player->printf("chown <object> <where>\n");
return true;
}
MudObject *what = find_object(player, argv[1]);
if (!what) {
player->printf("Can't find %s. Use exact object ID.\n", argv[1]);
return true;
}
MudObject *where = find_object(player, argv[2]);
if (!where) {
player->printf("Can't find %s. Use exact object ID.\n", argv[2]);
return true;
}
if (is_in(where, what)) {
player->printf("Eep.\n");
} else {
set_owner(what, where);
}
rectify_state(what);
return true;
}
#if 0
/* reparent
*
* Icky internal command. You don't need to know about this.
*
*/
static bool verb_reparent(MudObject *player, int argc, const char *argv[]) {
if (argc < 3) {
player->printf("reparent <object> <parent>\n");
return true;
}
Object *target = planet->get(argv[1]);
if (!target) { player->printf("cannot find %s\n", argv[1]); return true; }
Object *parent = planet->get(argv[2]);
if (!parent) { player->printf("cannot find %s\n", argv[2]); return true; }
target->set("template", parent->id);
player->printf("%s reparented\n", argv[1]);
return true;
}
#endif
/** chint
*
* Icky internal command. You don't need to know about this.
*
**/
static bool verb_chint(MudObject* player, int argc, const char *argv[]) {
if (argc < 4) {
player->printf("chint <object> <property> <value>\n");
return true;
}
MudObject *what = find_object(player, argv[1]);
if (!what) {
player->printf("can't find the %s\n", argv[1]);
return true;
}
char *e = NULL;
strtol(argv[3], &e, 10);
if (e && *e) {
player->printf("Dude, that's not a number.\n");
return true;
}
what->set(argv[2], atoi(argv[3]));
if (!player->ilc) {
log(PFL_SEEINFO, LEV_INTERNAL, "fiddle", "chint by %s : %s %s %s",
player->id, what->id, argv[2], argv[3]);
}
return true;
}
/** delete
*
* Icky internal command. You don't need to know about this.
*
**/
static bool verb_delete(MudObject* player, int argc, const char *argv[]) {
if (argc < 3) {
player->printf("delete <object> <property>\n");
return true;
}
MudObject *what = find_object(player, argv[1]);
if (!what) {
player->printf("can't find the %s\n", argv[1]);
return true;
}
what->unset(argv[2]);
if (!player->ilc) {
log(PFL_SEEINFO, LEV_INTERNAL, "fiddle", "del %s : %s %s",
player->id, what->id, argv[2]);
}
return true;
}
/** setstate
*
* setstate <object> <new-state>
*
* This sets the state of the object to [value]. You can use "open", "closed",
* or "locked", or just a number between 0 and 3.
*
**/
static bool verb_setstate(MudObject* player, int argc, const char *argv[]) {
if (argc < 3) {
player->printf("setstate <object> <value>\n");
return true;
}
MudObject *what = find_object(player, argv[1]);
if (!what) {
player->printf("can't find the %s.\n", argv[1]);
return true;
}
char *e;
int state = strtol(argv[2], &e, 10);
if (*e) {
state = -1;
if (!strcasecmp(argv[2], "open")) state = 0;
if (!strcasecmp(argv[2], "closed")) state = 1;
if (!strcasecmp(argv[2], "locked")) state = 2;
}
if (state < 0) {
player->printf("Bad state. Use a non-negative integer, or 'open'/'closed'/'locked'.\n");
return true;
}
what->set(KEY_STATE, state);
return true;
}
/** announce
*
* announce <text>
*
* This prints the specified message to everyone : your name and
* the fact that this is an announcement are supplied.
*
**/
static bool verb_announce(MudObject *who, int argc, const char *argv[]) {
string what = the_rest(argc, argv, 1);
if (who->get_priv(PFL_CODER) || who->ilc || who==mud) {
broadcast(filter(who), "\a^RANNOUNCEMENT^n (%M) : %s^n\n", who, what.c_str());
return true;
}
if (who->get_int("$blissed")>=now) {
who->printf("\a^RANNOUNCEMENT^n (%M) : %s^n\n", who, what.c_str());
who->oprintf("%#M %[mutters/mutter] to %s.\n", who, himself_or_herself(who));
return true;
}
who->printf("You can't do that : announce\n");
return true;
}
/** verbs
*
* verbs
* verbs <module>
*
* This prints a list of all the verbs. If a module name is specified,
* the list is restricted to the specified module.
*
**/
static bool verb_states(MudObject *who, int argc, const char *argv[]) {
State *s;
int i;
if (argc>1) {
Player *p = (Player *)who;
PersonState *ps = p->get_person_state();
while (ps) {
who->printf("%-10s\n", ps->get("state"));
Object::strit si = ps->strs.begin();
while (si != ps->strs.end()) {
who->printf(" %-10s %s\n", si->first.c_str(), si->second.c_str());
si++;
}
ps = ps->previous;
}
return true;
}
foreach_alpha (states, s, i) {
if (strncmp(s->id, "action.", 7)==0)
continue;
if (strncmp(s->id, "make.", 5)==0)
continue;
who->printf("%20s %s\n", s->id, s->get_prompt());
}
return true;
}
static bool verb_verbs(MudObject *who, int argc, const char *argv[]) {
Verb *v;
int i,count=0;
static bool verbose=0, showall=0;
extern int optind;
optind=0;
char *namematch=NULL, *modmatch=NULL;
int pflmatch=0;
bool optname=false, optmod=false, optpfl=false;
if(argc>1) {
while(1) {
int ch = getopt(argc, (char *const*)argv, ":n:m:p:");
if (ch==EOF) break;
switch(ch) {
case 'n':
optname=true;
namematch=strdup(optarg);
break;
case 'm':
optmod=true;
modmatch=strdup(optarg);
break;
case 'p':
for(int l=0;l<PFL_MAX;l++) {
if(strcasecmp(optarg, priv_names[l])==0) {
optpfl=true;
pflmatch=l;
break;
}
}
break;
}
}
}
if (privs_of(who) >= LEV_CAPTAIN)
{
showall = 1;
verbose = 1;
}
if (who->get_priv(PFL_SEEINFO))
{
verbose = 1;
}
Divert d(who, "verbs");
if(showall)
{
who->printf("List of ^RALL^n verbs");
} else {
who->printf("List of all verbs available to you");
}
if(verbose && optmod)
who->printf(" from module ^Y%s^n",modmatch);
if(optname)
{
who->printf(" whose name matches ^Y*%s*^n",namematch);
if(verbose && optpfl)
who->printf(" and");
}
if(verbose && optpfl)
who->printf(" which require ^Y%s^n",priv_names[pflmatch]);
who->printf(":\n");
if(verbose)
{
who->printf(" ^WVerb^B ^WModule^B ^WLevel^B ^WPFL^n\n");
who->printf("^B^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^+^-^-^-^-^-^-^-^-^-^-^+^-^-^-^-^-^-^+^-^-^-^-^-^-\n");
}
foreach_alpha(verbs,v,i){
const char *module = v->get("module");
int pfv = v->pflag;
if( streq(module,"action")!=0 || !showall && !v->has_privs(who))
continue;
if (verbose && optpfl && pfv != pflmatch)
continue;
if (verbose && optmod && module && strcmp(module,modmatch)!=0)
continue;
if (optname && v->id && strstr(v->id,namematch)==NULL)
continue;
count++;
char foo[100];
strcpy(foo, "^W");
strncat(foo, v->id, v->minlen);
strcat(foo, "^w");
strcat(foo, v->id + v->minlen);
who->printf("%19s", foo);
if(verbose) {
AliasVerb *av = dynamic_cast<AliasVerb*>(v);
if (!av) {
who->printf("^B^|^n%10s^B^|^n%-6i^B^|^n %s",
module,
v->privneeded,
priv_names[pfv]);
} else {
who->printf("^B^|^n alias for %s", av->aliasof->id);
}
}
who->printf("\n");
}
//if(verbose)
//fprintf(f,"^B^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-+^-^-^-^-^-^-^-^-^-^-+^-^-^-^-^-^-+^-^-^-^-^-^-\n");
who->printf("Total: ^Y%i^n verbs\n",count);
if(namematch) free(namematch);
if(modmatch) free(modmatch);
return true;
}
static bool has_help(const char *what) {
char foo[256];
sprintf(foo, DATA_HELP "/%s", what);
struct stat la;
if (stat(foo, &la)==0) {
return 1;
}
return 0;
}
// lists all undocumented verbs - optionally just ones from the module in argv[1]
static bool verb_undocverbs(MudObject *who, int, const char *argv[]) {
Divert d(who, "undocverbs");
Verb *v;
int i;
foreach(verbs, v, i) {
const char *module = v->get("module");
if (!module) module = "";
if (argv[1] && strcmp(argv[1], module) != 0) continue;
if (has_help(v->id))
continue;
AliasVerb *av = dynamic_cast<AliasVerb*>(v);
if (!av && !streq(module, "action"))
who->printf("%-10i : %10s : %s\n",
v->privneeded,
module,
v->id);
}
who->printf("\n");
#if 0
DIR *dir=opendir(DATA_HELP);
if (!dir) return true;
struct dirent *de;
while ((de=readdir(dir))!=NULL) {
if (de->d_name[0]=='.')
continue;
if (strchr(de->d_name, '~'))
continue;
if (strchr(de->d_name, '#'))
continue;
if (verbs->get(de->d_name) && !dynamic_cast<AliasVerb*>(verbs->get(de->d_name)))
continue;
who->printf("%s has unneeded docs.\n", de->d_name);
}
closedir(dir);
who->printf("\n");
#endif
return true;
}
static bool is_zone(Object *o) {
if (!o) return false;
const char *w = strlen(o->id) + o->id - 5;
return streq(w, "_zone");
}
struct {
int objects;
int rooms;
int exits;
int mobiles;
} w_s;
static void calc_totals() {
MudObject *o;
int i;
w_s.objects = 0;
w_s.rooms = 0;
w_s.exits = 0;
w_s.mobiles = 0;
foreach(zones, o, i) {
o->set("objects", 0);
o->set("rooms", 0);
o->set("exits", 0);
o->set("mobiles", 0);
}
foreach(planet, o, i) {
const char *z = o->get("zone");
if (z) {
Object *z2 = zones->get(z);
if (z2) {
if (o->get("link")) {
z2->set("exits", z2->get_int("exits")+1); w_s.exits++;
}
else if (is_mobile(o)) {
z2->set("mobiles", z2->get_int("mobiles")+1);
w_s.mobiles++;
}
else if (is_room(o)) {
z2->set("rooms", z2->get_int("rooms")+1);
w_s.rooms++;
}
else if (!is_zone(o)) {
z2->set("objects", z2->get_int("objects")+1);
w_s.objects++;
}
}
}
}
}
#define zname(i) (zones->get(i)->id)
#define znumloc(i) (zones->get(i)->get_int("rooms"))
#define znumchars(i) (zones->get(i)->get_int("mobiles"))
#define znumobjs(i) (zones->get(i)->get_int("objects"))
#define num_const_zon (zcount)
#define num_const_locs (w_s.rooms)
#define num_const_chars (w_s.mobiles)
#define max_players 0
#define num_const_obs (w_s.objects)
/** locations
*
* This lists the total number of locations in each loaded zone.
*
**/
static bool verb_locations(MudObject *who, int, const char **) {
calc_totals();
who->printf ("^CZone Loc Zone Loc Zone Loc Zone Loc\n");
who->printf ("^c^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^- ^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^- ^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^- ^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-\n");
int zcount = zones->getsize();
int count =1, locs = 0;
char a[10];
for (int zn=zcount-1;zn>=0;zn--,count++) {
bool qmark = !can_affect(who, zname(zn));
who->printf ("^n%-13s ^W%3s", zname (zn), str(znumloc (zn), a, qmark));
if (!qmark) {
locs += znumloc(zn);
}
if ((count % 5 == 4) || (zn==0)) {
count = 0;
who->printf("\n");
} else {
who->printf(" ");
}
}
who->printf ("^c^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^- ^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^- ^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^- ^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-^-\n");
who->printf ("^nA total of ^W%d ^nzones, with ^W%d ^nvisible locations.\n",
num_const_zon, locs);
return true;
}
/** zones
*
* This shows the total number of locations, mobiles and objects,
* in each zone.
*
**/
static MudObject *mudzone(int i)
{
char foo[1024];
sprintf(foo, "%s_zone", zname(i));
return planet->get(foo);
}
static bool verb_zones(MudObject *who, int, const char *[]) {
Divert d(who, "zones");
calc_totals();
int zcount = zones->getsize();
int count = 1, num_locs=0, num_mobs=0, num_objs=0;
char a[10], b[10], c[10];
who->printf ("^CZone Loc Mob Obj Zone Loc Mob Obj Zone Loc Mob Obj\n");
who->printf ("^c^-^-^-^-^-^-^-^-^-^-^-^-^- ^-^-^- ^-^-^- ^-^-^- ^-^-^-^-^-^-^-^-^-^-^-^-^- ^-^-^- ^-^-^- ^-^-^- ^-^-^-^-^-^-^-^-^-^-^-^-^- ^-^-^- ^-^-^- ^-^-^-\n");
for (int zn=zcount-1;zn>=0;zn--,count++) {
bool qmark = !can_affect(who, zname(zn));
who->printf("^n%s%-12s ^D%3s ^P%3s ^c%3s",
(mudzone(zn) && mudzone(zn)->get_flag(FL_PEACEFUL)) ? "*" : " ",
zname(zn),
str(znumloc(zn), a, qmark), str(znumchars(zn), b, qmark), str(znumobjs(zn), c, qmark));
if (!qmark) {
num_locs += znumloc(zn);
num_mobs += znumchars(zn);
num_objs += znumobjs(zn);
}
if ((count % 4 == 3) || (zn==0)) {
count = 0;
who->printf("\n");
} else {
who->printf(" ");
}
}
who->printf ("\n^nA total of ^W%d^n visible zones containing "
"^W%d ^nrooms, ^W%d ^nmobiles, ^W%d ^nobjects.\n",
num_const_zon, num_locs, num_mobs, num_objs);
return true;
}
static string last_chars(const char *what, unsigned int howmany) {
if (strlen(what) < howmany) return what;
string temp = "...";
temp += (what + strlen(what) - (howmany-3));
return temp;
}
#define lastchars(a,b) (last_chars(a,b).c_str())
#define zone_exists(a) (zones->get(a)!=0)
/** mobiles
*
* mobiles
* mobiles <zone>
*
* This command gives you a list of all the mobiles in the game,
* or in the specified zone.
*
**/
static bool verb_mobiles(MudObject *who, int argc, const char **argv) {
if (argc<2) {
who->printf("syntax: mobiles <zone>\n");
return true;
}
bool noclones = argv[1][0]=='|';
if (noclones)
argv[1]++;
if (!zone_exists(argv[1])) {
who->printf("No such zone.\n");
return true;
}
const char *prop = argv[2];
if (!zones->get(argv[1])) {
who->printf("No such zone as %s.\n", argv[1]);
return true;
}
Divert d(who, "mobiles");
MudObject *o;
int i;
MudObject *z = zones->get(argv[1]);
if (can_affect(who, z->id)) {
foreach_alpha(z->children, o, i) {
if (o->get_object("cloneof") && noclones)
continue;
if (!is_mobile(o))
continue;
if (prop && o->get(prop))
continue;
const char *nat = nation(o);
MudObject *at = archetype(o);
if (o->get("wornfrom")) {
at = o->get_object("wornfrom");
}
const char *g = o->get("gender");
who->printf("%-25s %-25s %-15s %1c %2.2s %10s %s\n",
o->id, o->get("name"),
o->owner?(lastchars(bwname(o->owner), 15)):"??",
g?tolower(*g):'?',
nat, o->get("body")?o->get("body"):"human",
at?at->id:"-");
}
}
return true;
}
/* GENERALLY
*
* 1 == root object
* 2 == zone system zone
* 3 == room empty room quest room
* 4 == exit or object or player quests
* 5 == contents inventory
*
* This is not entirely true, of course. Players can actually go INSIDE the
* root room or into zones. From here they can perform management functions,
* like "moving" rooms from one zone to another. Although this makes no
* difference to the file, 'cos all objects have a "zone" attribute. hmm..
*
*/
/** rooms
*
* rooms
* rooms <zone>
*
*
*
*/
static bool verb_rooms(MudObject *who, int argc, const char *argv[]) {
int count=0;
MudObject *o;
int i;
if (argc!=2) {
who->printf("syntax: rooms <zone>\n");
return true;
}
if (!zones->get(argv[1])) {
who->printf("No such zone as %s.\n", argv[1]);
return true;
}
Divert d(who, "rooms");
if (can_affect(who, argv[1])) {
foreach_alpha(zones->get(argv[1])->children, o, i) {
if (!is_exit(o) && is_room(o)) {
who->printf("%s - %s^n\n", o->id, o->get("name"));
count++;
}
}
}
who->printf("Visible rooms : %i\n", count);
return true;
}
/** objects */
static bool verb_objects(MudObject *who, int argc, const char *argv[]) {
int count=0;
MudObject *o;
int i;
if (argc!=2) {
who->printf("syntax: objects <zone>\n");
return true;
}
bool noclones = argv[1][0]=='|';
if (noclones)
argv[1]++;
if (!zones->get(argv[1])) {
who->printf("No such zone as %s.\n", argv[1]);
return true;
}
Divert d(who, "objects");
MudObject *z = zones->get(argv[1]);
if (can_affect(who, z->id)) {
foreach_alpha(z->children, o, i) {
if (noclones && o->get_object("cloneof"))
continue;
if (!is_room(o) && !is_mobile(o) && !is_player(o)
&&!o->get_flag(FL_EXIT)) {
who->printf("%20s - %20s^n - %s\n", o->id, o->get("name"), owhere(o).c_str());
count++;
}
}
}
who->printf("Visible objects : %i\n", count);
return true;
}
static bool verb_loadzone(MudObject *who, int argc, const char **argv) {
if (argc < 2) {
who->printf("syntax : loadzone <zonename>\n");
return false;
}
if (zones->get(argv[1])) {
who->printf("Zone already loaded.\n");
return false;
}
load_newzone(argv[1]);
load_var_data(VARVAR, argv[1]);
log(PFL_SEEINFO, 0, "admin", "zone %s loaded", argv[1]);
doreset(argv[1], false);
return true;
}
static bool verb_discardzone(MudObject *who, int argc, const char **argv) {
if (argc < 2) {
who->printf("syntax : discarcdzone <zonename>\n");
return false;
}
if (!zones->get(argv[1])) {
who->printf("Zone has not been loaded.\n");
return false;
}
save_var_zone(argv[1]);
MudObject *o;
int i;
foreach(zones->get(argv[1])->children, o, i) {
if (streq(o->get("zone"), argv[1])) {
o->nuke_me = 1;
}
}
log(PFL_SEEINFO, 0, "admin", "zone %s discarded", argv[1]);
return true;
}
bool canseeprop(MudObject *who, MudObject *on, const string &p)
{
const char *prop = p.c_str();
if (IS_ADMIRAL(who))
return 1;
if (is_player(on)) {
if (streq(prop, "password"))
return 0;
if (streq(prop, "newpass"))
return 0;
if (streq(prop, "!mail.to"))
return 0;
if (streq(prop, "!mail.subject"))
return 0;
if (streq(prop, "!mail.buffer"))
return 0;
}
return 1;
}
static void stat(MudObject *who, MudObject *o) {
who->printf("mudobject \"%s\"\n", o->id);
if (o->owner) who->printf("\"owner\" = \"%s\"\n", o->owner->id);
{
Object::strit i = o->strs.begin();
while (i != o->strs.end()) {
if (canseeprop(who, o, i->first))
who->printf("\"%s\" = \"%s\"\n", i->first, escape_colour(i->second));
i++;
}
}
{
Object::intit i = o->ints.begin();
while (i != o->ints.end()) {
if (canseeprop(who, o, i->first))
who->printf("\"%s\" = %i\n", i->first, i->second);
i++;
}
}
}
static bool verb_stat(MudObject *player, int argc, const char *argv[]) {
if (argc < 2) {
player->printf("stat <object>\n");
return true;
}
MudObject *src = find_object(player, argv[1]);
if (!src) {
player->printf("%s not found\n", argv[1]);
return true;
}
int invis = src->get_int("invis");
if (privs_of(player) < invis) {
player->printf("%s not found\n", argv[1]);
return true;
}
Divert d(player, "stat");
if (!argv[2]) {
stat(player, src);
return true;
}
if (strchr(argv[2], '*')) {
MudObject::strit i = src->strs.begin();
while (i != src->strs.end()) {
if (canseeprop(player, src, i->first) && wcmatch(argv[2], i->first.c_str())) {
player->printf("\"%s\" = \"%s\"\n", i->first, escape_colour(i->second));
}
i++;
}
MudObject::intit j = src->ints.begin();
while (j != src->ints.end()) {
if (canseeprop(player, src, j->first) && wcmatch(argv[2], j->first.c_str())) {
player->printf("\"%s\" = %i\n", j->first, j->second);
}
j++;
}
return true;
}
if (!canseeprop(player, src, argv[2])) {
player->printf("You can't view that property.\n");
return true;
}
const char *a = src->get(argv[2]);
if (a) {
if (strncmp(argv[2], "lua.", 4)==0) {
string b = a+1;
string u;
const char *user=0;
int rights=0;
if (a[0]==',') {
a = strchr(a, ';');
if (!a) a = "";
else a++;
if (b.find(',')!=string::npos) {
u = b.substr(0, b.find(','));
user = u.c_str();
b = b.substr(b.find(',')+1);
rights = atoi(b.c_str());
}
}
if (user)
player->printf("Object: %M (%s)\nTrap : ^W%s^n\nUser : %s\nRights: %s\n\n%s\n",
src,
src->id,
argv[2],
user,
rights==1?"Unapproved":"Approved",
escape_colour(a).c_str());
else
player->printf("Object: %M (%s)\nTrap: ^W%s^n\n\n%s\n",
src,
src->id,
argv[2],
escape_colour(a).c_str());
}
else
player->printf("%s::%s == \"%s\"\n",
src->id,
argv[2],
escape_colour(a).c_str());
return true;
}
int q = src->get_int(argv[2]);
if (q != -1) {
if (abs(q-now) < 24*60*60*30) {
time_t t = q;
player->printf("%s::%s == (%i) %s\n",
src->id,
argv[2],
q,
ctime_for(player, &t));
}
else {
player->printf("%s::%s == %i\n",
src->id,
argv[2],
q);
}
return true;
}
player->printf("%s::%s not there.\n", src->id, argv[2]);
return true;
}
//! abbreviate a direction name to a 1/2/3 letter code
static const char *abdir(const char *what)
{
if (streq(what, "north")) return "n";
if (streq(what, "south")) return "s";
if (streq(what, "east" )) return "e";
if (streq(what, "west" )) return "w";
if (streq(what, "up" )) return "u";
if (streq(what, "down" )) return "d";
if (streq(what, "port" )) return "pt";
if (streq(what, "starboard")) return "sb";
if (streq(what, "fore")) return "f";
if (streq(what, "aft")) return "a";
if (streq(what, "clockwise")) return "cw";
if (streq(what, "anticlockwise")) return "ac";
if (streq(what, "in")) return "in";
if (streq(what, "out")) return "out";
if (streq(what, "rimwards")) return "r";
if (streq(what, "hubwards")) return "h";
return what;
}
extern Flag find_flag(const char *);
static bool verb_ls(MudObject *player, int argc, const char **argv)
{
MudObject *what;
const char *mp = 0;
Flag fl = FL_NONE;
if (argc < 2) {
what = player->owner;
} else {
what = planet->get(argv[1]);
if (!what && streq(argv[1], "me"))
what = player;
if (!what) {
mp = argv[1];
what = player->owner;
}
if (mp) {
fl = find_flag(mp);
}
}
Divert d(player, "ls");
MudObject *o;
int i;
player->printf("Contents of %s : \n", what->id);
foreach(what->children, o, i) {
int is = o->get_int("initstate");
if (is!=-1)
player->printf("%x(%x) ", state(o),
is);
else
player->printf("%x ", state(o));
if (columns(player)<130) {
player->printf(
"%-10s %-10s %-20s %-25s",
is_player(o) ? "Player" :
is_mobile(o) ? "Mobile" :
o->get_flag(FL_EXIT) ? "Exit" :
o->get_flag(FL_FIXED) ? "Fixed" : "",
o->get("zone") ? o->get("zone") : "",
escape_colour(o->get("name") ? o->get("name") : "").c_str(),
o->id);
} else {
player->printf( "%-10s %-10s %-50s %-25s",
is_player(o) ? "Player" :
is_mobile(o) ? "Mobile" :
o->get_flag(FL_EXIT) ? "Exit" :
o->get_flag(FL_FIXED) ? "Fixed" : "",
o->get("zone") ? o->get("zone") : "",
escape_colour(o->get("name") ? o->get("name") : "").c_str(),
o->id);
}
if (!mp && fl == -1) {
if (o->get("treatas")) {
player->printf(" [%s]", o->get("treatas"));
}
if (o->get_flag(FL_EXIT) && o->get("link")) {
player->printf(" ^W%5s^n -> %s", abdir(o->get("short")),
o->get("link"));
}
if (o->get("other")) {
player->printf(" <-> %s", o->get("other"));
}
if (o->get("door")) {
player->printf(" [%s]", o->get("door"));
}
player-> printf("\n");
} else {
if (fl != FL_NONE && o->get_flag(fl)) {
player->printf("%s\n", mp);
}
else if (mp) {
if (o->get_int(mp)!=-1) {
player->printf("%i\n", o->get_int(mp));
} else if (o->get(mp)) {
player->printf("%s\n", escape_colour(o->get(mp)).c_str());
} else
player->printf("\n");
}
}
}
return true;
}
static bool verb_conn(Player *who, int argc, const char *argv[]) {
Player *p = who;
if (!p->p) {
who->printf("You are linkdead.\n");
return true;
}
p->p->keepalive();
who->printf("<- If this line doesn't start with '<-' then no NOP support.\n");
if (p->p->mxp) {
who->printf("MXP support: yes.\n"); /* lock open mode */
who->printf("\3BOLD\4this should be bold\3/BOLD\4.\n");
who->printf("\033[1z\3SEND\4this should be a link\3/SEND\4.\n");
} else {
who->printf("MXP support: no.\n");
}
#ifndef NOCOMPRESS
if (p->p->will_compress) {
who->printf("MCCP support: yes : %s : %s.\n",
p->p->will_compress?"v2":"v1",
p->p->compress?"on":"off");
} else {
who->printf("MCCP support: no.\n");
}
#endif
if (p->p->do_eor) {
who->printf("EOR support: yes.\n");
} else {
who->printf("EOR support: no.\n");
}
if (p->p->term.length()) {
who->printf("TTYPE support: yes - '%s'.\n", p->p->term.c_str());
} else {
who->printf("TTYPE support: no.\n");
}
if (p->p->row || p->p->col) {
who->printf("NAWS support: yes - window size is %ix%i\n", p->p->col, p->p->row);
} else {
who->printf("NAWS support: no.\n");
}
who->printf("An e with an acute accent 'é'.\n");
who->printf("A no-break space '\xa0'.\n");
who->printf("A y with an umlaut 'ÿ' (IAC IAC).\n");
if (player_knows(who, 0x42f))
who->printf("Backwards R (CYRILLIC YA) '^#x042f;'.\n");
if (player_knows(who, 0x4e2d)||player_knows(who, 0x6587))
who->printf("Some chinese characters '^#x4e2d;^#x6587;'.\n");
who->printf("A shape a bit like an H '\033(0tqu\033(B'.\n");
who->printf("This should not be displayed. \rThis line should have only one sentence on it (CR).\n");
// who->printf("\x0eqqq\x0f <- a line, not qs. (SI and SO)\n");
if (who->get_flag(FL_COLOUR)) {
who->printf("White text on a black background. \033[31mred, \033[39mdefault (39)\033[0m.\n");
who->printf("\033[1;32mBri green, \33[31mbr red, \33[22mn red (22m), \033[2md red (2m). \33[mDef (ESC]m).\2\n");
who->printf("\2330;1;34mBright blue (uses CSI).\2330m\n");
who->printf("^cCyan text on a black background.\v");
who->printf("and ^CBright cyan text on a black background.^n\n");
who->printf("&=lwBlack text on a white background.^n\n");
who->printf("&=rgRed text on a green background.^n\n");
who->printf("&_Underlined^n, &/italics^n and \033[5mblinking\033[m\2\n");
who->printf("\033[7mInverse\033[0m, \033[8mhidden\033[0m and \033[9mstrikethrough\033[0m\2.\n");
who->printf("\033[21mDouble underline\033[0m, \033[20mfraktur\033[0m and \033[53moverline\033[0m\2.\n");
who->printf("^nDefault colour should be darker than ^Wbright white.^n\n");
#if 0
int cols[8] = {0, 4, 5, 1, 2, 6, 3, 7};
for (int i=0;i<8;i++) {
who->printf("\033[3%i;2md\033[22mn\033[1mb\033[0m\n", cols[i]);
}
#endif
}
// p->p->do_eor = 1;
return true;
}
extern int sc_wait;
static bool verb_spell(MudObject *who, int argc, const char **argv)
{
MudObject *where = 0;
const char *prop = "desc";
if (argc>1) {
where = planet->get(argv[1]);
if (streq(argv[1], "here")) where = who->owner;
if (streq(argv[1], "me")) where = who;
if (argc>2)
prop = argv[2];
} else
where = who->owner;
if (!where) {
who->printf("Spellcheck where?\n");
return true;
}
const char *p = where->get(prop);
if (!p)
who->printf("Cat't find any %s:%s.\n", where->id, prop);
string s = lose_colour(p);
char fn[100];
sprintf(fn, "spell-%s", who->id);
FILE *f = xopen("tmp", fn, "w+");
if (!f)
return true;
fprintf(f, "%s\n", s.c_str());
xclose(f);
char cmdline[1000];
#define ASPELL_BIN "/home/cryosphere/bin/myspell"
sprintf(cmdline, ASPELL_BIN" -l < tmp/spell-%s > tmp/spellbuf-%s",
who->id, who->id);
sc_wait = 0;
system(cmdline);
sc_wait = 1;
sprintf(cmdline, "spellbuf-%s", who->id);
who->spewfile("tmp", cmdline);
return true;
}
static bool verb_addtele(MudObject *who, int argc, const char **argv)
{
if (argc < 2) {
who->printf("Addtele <what>.\n");
return true;
}
MudObject *what = planet->get(argv[1]);
MudObject *where = who->owner;
if (!what) {
who->printf("Can't find %s.\n", argv[1]);
return true;
}
if (!cantouch_zone(who, where->get("zone"))) {
who->printf("You can't edit this zone.\n");
return true;
}
int tc = where->array_size("tele");
for (int i = 0; i < tc; i++) {
if (where->array_get_object("tele", i)==what) {
where->array_set("tele", i, "count", where->array_get_int("tele", i, "count", 1)+1);
return true;
}
}
where->array_set("tele", tc, what->id);
where->set("tele.count", tc+1);
return true;
}
static bool verb_addstock(MudObject *who, int argc, const char **argv)
{
if (argc < 2) {
who->printf("Addstock <what>.\n");
return true;
}
MudObject *what = planet->get(argv[1]);
MudObject *where = who->owner;
if (!what) {
who->printf("Can't find %s.\n", argv[1]);
return true;
}
if (!cantouch_zone(who, where->get("zone"))) {
who->printf("You can't edit this zone.\n");
return true;
}
int tc = where->array_size("shop");
for (int i = 0; i < tc; i++) {
if (where->array_get_object("shop", i)==what) {
// where->array_set("shop", i, "count", where->array_get_int("shop", i, "count", 1)+1);
return true;
}
}
where->array_set("shop", tc, what->id);
where->set("shop.count", tc+1);
return true;
}
static bool verb_addauto(MudObject *who, int argc, const char **argv)
{
if (argc < 2) {
who->printf("Addauto <what>.\n");
return true;
}
MudObject *what = planet->get(argv[1]);
MudObject *where = who->owner;
if (!what) {
who->printf("Can't find %s.\n", argv[1]);
return true;
}
if (!cantouch_zone(who, where->get("zone"))) {
who->printf("You can't edit this zone.\n");
return true;
}
int tc = where->array_size("auto");
for (int i = 0; i < tc; i++) {
if (where->array_get_object("auto", i)==what) {
if (where->array_get_int("auto", i, "worn", 0) ||
where->array_get_int("auto", i, "wield", 0)) {
who->printf("It is used as equipment. Not adding more.\n");
return true;
} else {
int n;
where->array_set("auto", i, "count", n=(where->array_get_int("auto", i, "count", 1)+1));
who->printf("There are now %i.\n", n);
return true;
}
}
}
where->array_set("auto", tc, what->id);
if (what->get("wornon") && is_person(where)) {
where->array_set("auto", tc, "worn", 1);
who->printf("Added as worn.\n");
} else if (what->get_int("damage")>=1 && is_person(where)) {
where->array_set("auto", tc, "wield", 1);
who->printf("Added as weapon.\n");
} else {
who->printf("Added as contents.\n");
}
where->set("auto.count", tc+1);
return true;
}
static bool verb_remstock(MudObject *who, int argc, const char **argv)
{
if (argc < 2) {
who->printf("Remstock <what>.\n");
return true;
}
MudObject *what = planet->get(argv[1]);
MudObject *where = who->owner;
if (!what) {
who->printf("Can't find %s.\n", argv[1]);
return true;
}
int tc = where->array_size("shop");
if (!cantouch_zone(who, where->get("zone"))) {
who->printf("You can't edit this zone.\n");
return true;
}
for (int i = 0; i < tc; i++) {
if (where->array_get_object("shop", i)==what) {
// who->printf("%i must go.\n", i);
where->array_unset("shop", i);
where->array_unset("shop", i, "istock");
where->array_unset("$stock", i);
for (int j=i+1;j<tc;j++) {
where->array_set("shop", j-1, where->array_get("shop", j));
int st = where->array_get_int("$stock", j);
if (st==-1) {
where->array_unset("$stock", j-1);
} else {
where->array_set("$stock", j-1, st);
}
st = where->array_get_int("shop", j, "istock");
if (st==-1) {
where->array_unset("shop", j-1, "istock");
} else {
where->array_set("shop", j-1, "istock", st);
}
st = where->array_get_int("shop", j, "atonce");
if (st==-1) {
where->array_unset("shop", j-1, "atonce");
} else {
where->array_set("shop", j-1, "atonce", st);
}
}
where->set("shop.count", where->array_size("shop")-1);
return true;
}
}
who->printf("No match.\n");
return true;
}
#define LOGS 20
extern struct logmsg_t {
int time;
PFlag priv;
int level;
string sys;
string msg;
string who;
} log_circle[LOGS];
extern int log_n;
static bool verb_log(MudObject *who, int argc, const char **argv)
{
for (int x=0;x<LOGS;x++) {
int i = (log_n + x)%LOGS;
if (log_circle[i].time) {
PFlag priv = log_circle[i].priv;
if (priv!=PFL_NONE && !who->get_priv(priv))
continue;
if (log_circle[i].level > privs_of(who))
continue;
time_t then = log_circle[i].time;
struct tm*t=localtime(&then);
char when[20];
strftime(when, 10, "%H%M", t);
when[10] = 0;
string whos = log_circle[i].who;
if (MudObject *q=planet->get(whos.c_str())) {
if (visible_to(who, q)) {
const char *n = q->get("name");
if (!n) n = q->id;
whos = n;
}
}
who->printf("%s ^| %-10s ^| %-12s ^| ^Z%s\n", when,
log_circle[i].sys.c_str(),
whos.c_str(),
log_circle[i].msg.c_str());
}
}
return true;
}
struct ZI {
string planet;
string colplanet;
MudObject *zone;
string seconds;
int zs;
bool operator <(const ZI&z) const {
if (planet < z.planet)
return 1;
if (zs < z.zs)
return 1;
return seconds < z.seconds;
}
};
static bool verb_planets(MudObject *who, int argc, const char **argv)
{
MudObject *z;
int i;
Divert d(who, "planets");
NewWorld non;
foreach(zones, z, i) {
MudObject *o = getzone(z->id);
if (!o)
continue;
if (!o->get("planet"))
non.add(*o);
}
NewWorld unk;
who->spec_printf("%-15s %14s %14s %14s %s\n",
"Planet",
"Cop room",
"Hospital",
"Saves",
"Zones");
set<ZI> zi;
foreach_alpha(zones, z, i) {
MudObject *o = getzone(z->id);
if (!o)
continue;
string s;
MudObject *p;
int j;
int y = 0;
s += z->id;
int zs = 1;
foreach_alpha((&non), p, j) {
if (p->get_object("fwd")==o) {
s += ", ";
s += p->get("zone");
if (const char *cr = p->get("coproom")) {
s += ssprintf(" (cops: %s)", cr);
}
if (const char *cr = p->get("hospital")) {
s += ssprintf(" (hospital: %s)", cr);
}
y = 1;
zs++;
}
}
if (o->get("planet")) {
ZI z;
z.zone = o;
z.seconds = s;
z.planet = o->get("planet");
if (const char *cp=o->get("colplanet"))
z.colplanet = cp;
else
z.colplanet = "^Y" + z.planet + "^n";
z.zs = 1;
zi.insert(z);
} else if (!o->get_object("fwd")) {
unk.add(z);
}
}
const char *lastp = 0;
for(set<ZI>::iterator zit = zi.begin();zit!=zi.end();zit++) {
MudObject *hosp = get_zonepropobj(zit->zone, "hospital");
MudObject *copr = get_zonepropobj(zit->zone, "coproom");
who->printf("%-15s %14s %14s %14s ^Z%s\n",
!streq(lastp, zit->planet.c_str())?zit->colplanet.c_str():" \"",
zit->zone->get("coproom")?:copr?((string)"("+copr->id+")").c_str():"",
zit->zone->get("hospital")?:hosp?((string)"("+hosp->id+")").c_str():"",
zit->zone->get_flag(FL_STICKYROOM)?"sticky":zit->zone->get("home")?:"",
zit->seconds.c_str());
lastp=zit->planet.c_str();
}
if (unk.getsize()) {
who->printf("%-15s %14s %14s %14s ^Z%W\n", "Unknown", "", "", "", &unk);
}
return 0;
}
#include "verbmodule.h"
void startup() {
AUTO_VERB(states, 6, 0, PFL_GOD);
AUTO_VERB(verbs, 2, 0, PFL_NONE);
AUTO_VERB(undocverbs, 5, 0, PFL_NONE);
AUTO_VERB(ls, 2, 0, PFL_DETAIL);
AUTO_VERB(rooms, 2, 0, PFL_ROOM);
AUTO_VERB(objects, 3, 0, PFL_ROOM);
AUTO_VERB(zones, 2, 0, PFL_ROOM);
AUTO_VERB(locations, 6, 0, PFL_ROOM);
AUTO_VERB(mobiles, 3, 0, PFL_ROOM);
AUTO_VERB(planets, 2, 0, PFL_ROOM);
AUTO_VERB(setstate, 7, 0, PFL_MAKE);
AUTO_VERB(announce, 3, 0, PFL_NONE, VFL_OKNOOWNER);
AUTO_VERB(chstr, 3, 0, PFL_CODER);
AUTO_VERB(chint, 3, 0, PFL_CODER);
AUTO_VERB(chown, 3, 0, PFL_CODER);
AUTO_VERB(delete, 3, 0, PFL_CODER);
AUTO_VERB(stat, 4, 0, PFL_DETAIL);
AUTO_VERB(conn, 4, 0, PFL_NONE);
AUTO_VERB(openport, 5, 0, PFL_CODER);
AUTO_VERB(closeport, 6, 0, PFL_CODER);
AUTO_VERB(loadzone, 5, 0, PFL_ZONES);
AUTO_VERB(discardzone, 8, 0, PFL_ZONES);
AUTO_VERB(spell, 5, 0, PFL_NONE);
AUTO_VERB(addstock, 5, 0, PFL_MAKE);
AUTO_VERB(remstock, 5, 0, PFL_MAKE);
AUTO_VERB(addtele, 5, 0, PFL_MAKE);
AUTO_VERB(addauto, 5, 0, PFL_MAKE);
ADD_ALIAS(addworn, 5, addauto);
AUTO_VERB(log, 3, 0, PFL_NONE);
}