/* cmds.c */ #include "copyright.h" #include "config.h" #include <stdio.h> #ifdef STRING_H #include <string.h> #else #include <strings.h> #endif /* STRING_H */ #include <sys/types.h> #include <sys/param.h> #include <sys/stat.h> #include <ctype.h> #include "teeny.h" #include "match.h" #include "case.h" extern char cmdwork[]; voidfunc do_enter(player, arg) int player; char *arg; { int here, obj; char *name; if (!arg || !*arg) { notify_player(player, "Enter what?\r\n"); return; } if (get_int_elt(player, LOC, &here) == -1) goto enterbomb; if ((obj = match_here(player, here, arg, MAT_THINGS)) == -1) { if ((obj = match_here(player, here, arg, MAT_PLAYERS)) == -1) { notify_player(player, "I don't see that here.\r\n"); return; } } if (obj == -2) { notify_player(player, "I can't tell which one you mean.\r\n"); return; } if ((!controls(player, obj) && !isenterok(obj)) || islocked(player, obj, ELOCK)) { act_object(player, obj, EFAIL, OEFAIL, -1, "You don't quite fit.", (char *) 0); return; } name = getname(player); act_object(player, obj, ENTER, OENTER, -1, (char *) 0, (char *) 0); act_object(player, obj, -1, OXENTER, obj, (char *) 0, (char *) 0); if (!isdark(player) && !isdark(here)) { sprintf(cmdwork, "%s has left.\r\n", name); notify_oall(player, cmdwork); } list_drop(player, here, CONTENTS_LIST); list_add(player, obj, CONTENTS_LIST); if (set_int_elt(player, LOC, obj) == -1) goto enterbomb; if (!isdark(player) && !isdark(obj)) { sprintf(cmdwork, "%s has arrived.\r\n", name); notify_oall(player, cmdwork); } stamp(here); do_look(player, (char *) 0); return; enterbomb: notify_bad(player); return; } voidfunc do_leave(player) int player; { int here, hereloc; char *name; if (get_int_elt(player, LOC, &here) == -1) goto leavebomb; if (isroom(here)) { notify_player(player, "You're not inside of anything to leave!\r\n"); return; } if (get_int_elt(here, LOC, &hereloc) == -1) goto leavebomb; name = getname(player); act_object(player, here, LEAVE, OLEAVE, -1, (char *) 0, (char *) 0); act_object(player, here, -1, OXLEAVE, hereloc, (char *) 0, (char *) 0); if (!isdark(player) && !isdark(here)) { sprintf(cmdwork, "%s has left.\r\n", name); notify_oall(player, cmdwork); } list_drop(player, here, CONTENTS_LIST); list_add(player, hereloc, CONTENTS_LIST); if (set_int_elt(player, LOC, hereloc) == -1) goto leavebomb; if (!isdark(player) && !isdark(hereloc)) { sprintf(cmdwork, "%s has arrived.\r\n", name); notify_oall(player, cmdwork); } stamp(here); do_look(player, (char *) 0); return; leavebomb: notify_bad(player); return; } voidfunc do_fixrooms(player) int player; { register int i; if (player != PLAYER_GOD) { notify_player(player, "Buzz off.\r\n"); return; } for (i = 0; i < db_top(); i++) { if (!exists_object(i) || !isroom(i)) continue; if (set_int_elt(i, NEXT, -1) == -1) continue; } for (i = 0; i < db_top(); i++) { if (!exists_object(i) || !isroom(i)) continue; if (set_int_elt(i, LOC, ROOT_PARENT) == -1) continue; if (i != ROOT_PARENT) list_add(i, ROOT_PARENT, ROOMS_LIST); } notify_player(player, "Done.\r\n"); } voidfunc do_attach(player, argone, argtwo) int player; char *argone; char *argtwo; { int dest, action, loc; if (!argone || !*argone || !argtwo || !*argtwo) { notify_player(player, "Attach what to what?\r\n"); return; } if ((action = resolve_exit(player, argone)) == -1) { notify_player(player, "I can't find that action.\r\n"); return; } if (action == -2) { notify_player(player, "I can't tell which action you mean.\r\n"); return; } if ((dest = resolve_object(player, argtwo)) == -1) { if ((dest = resolve_player(player, argone, iswiz(player))) == -1) { notify_player(player, "I can't find that source.\r\n"); return; } } if (dest == -2) { notify_player(player, "I can't tell which source you mean.\r\n"); return; } if (!controls(player, action)) { notify_player(player, "Permission denied.\r\n"); return; } if (!controls(player, dest) || isexit(dest)) { notify_player(player, "You can't attach anything to that!\r\n"); return; } if (get_int_elt(action, LOC, &loc) == -1) goto bomb; list_drop(action, loc, EXITS_LIST); list_add(action, dest, EXITS_LIST); if (set_int_elt(action, LOC, dest) == -1) goto bomb; stamp(action); notify_player(player, "Action reattached.\r\n"); return; bomb: notify_bad(player); } /* * Basic player commands pertaining to communication. */ voidfunc do_pose(player, arg) int player; char *arg; { char *name; if (get_str_elt(player, NAME, &name) == -1) goto posebomb; while (arg && *arg && isspace(*arg)) arg++; if (arg && *arg) sprintf(cmdwork, "%s%s%s\r\n", name, (arg[0] == '\'' || arg[0] == ',') ? "" : " ", (arg && *arg) ? arg : ""); else sprintf(cmdwork, "%s\r\n", name); notify_all(player, cmdwork); return; posebomb: notify_bad(player); return; } voidfunc do_page(player, argone, argtwo) int player; char *argone, *argtwo; { int pagee; char *name; int location; if (argone == NULL) { notify_player(player, "Page whom?\r\n"); return; } if (issticky(player)) { notify_player(player, "You can't send pages while ignoring them.\r\n"); return; } if ((pagee = match_active_player(argone)) == -1 || pagee == -2) { if ((pagee = match_who(argone)) == -1) { if ((pagee = match_player(argone)) == -1) { notify_player(player, "No such player.\r\n"); return; } } } if (!isalive(pagee)) { notify_player(player, "That player is not connected.\r\n"); return; } if (issticky(pagee)) { notify_player(player, "That player can't be disturbed at the moment.\r\n"); return; } /* OK. Send the message. */ if (argtwo == NULL) { if (get_str_elt(player, NAME, &name) == -1) goto pagebomb; if (get_int_elt(player, LOC, &location) == -1) goto pagebomb; sprintf(cmdwork, "You sense that %s is looking for you in %s", name, getname(location)); if (controls(pagee, location) || isjumpok(location)) sprintf(cmdwork + strlen(cmdwork), "(#%d)\r\n", location); else strcat(cmdwork, "\r\n"); notify_player(pagee, cmdwork); } else { /* message page */ if (get_str_elt(player, NAME, &name) == -1) goto pagebomb; if (argtwo && *argtwo && *argtwo == ':' && argtwo[1]) { argtwo++; sprintf(cmdwork, "From afar, %s%s%s\r\n", name, (argtwo[0] != '\'' && argtwo[0] != ',') ? " " : "", argtwo); } else sprintf(cmdwork, "%s pages: %s\r\n", name, (argtwo && *argtwo) ? argtwo : ""); notify_player(pagee, cmdwork); } notify_player(player, "Your message has been sent.\r\n"); return; pagebomb: notify_bad(player); return; } voidfunc do_say(player, arg) int player; char *arg; { char *name; if (get_str_elt(player, NAME, &name) == -1) goto saybomb; while (arg && *arg && isspace(*arg)) arg++; sprintf(cmdwork, "%s says, \"%s\"\r\n", name, (arg && *arg) ? arg : ""); notify_oall(player, cmdwork); sprintf(cmdwork, "You say, \"%s\"\r\n", (arg && *arg) ? arg : ""); notify_player(player, cmdwork); return; saybomb: notify_bad(player); return; } voidfunc do_whisper(player, argone, argtwo) int player; char *argone, *argtwo; { int whisperee, here; char *name; if (get_int_elt(player, LOC, &here) == -1) goto whisperbomb; if (argone == NULL || (!iswiz(player) && (whisperee = match_here(player, here, argone, MAT_PLAYERS)) == -1)) { notify_player(player, "Whisper to whom?\r\n"); return; } if (iswiz(player)) { /* wizard whisper */ if (argone == NULL || (whisperee = resolve_player(player, argone, 1)) == -1) { notify_player(player, "Whisper to whom?\r\n"); return; } } if (whisperee == -2) { notify_player(player, "I don't know which player you mean.\r\n"); return; } /* OK. Tell the players */ while (argtwo && *argtwo && isspace(*argtwo)) argtwo++; if (argtwo && *argtwo && argtwo[0] == ':' && argtwo[1]) { argtwo++; if (get_str_elt(player, NAME, &name) == -1) goto whisperbomb; notify_player(player, "Your message has been sent.\r\n"); sprintf(cmdwork, "You sense that %s%s%s\r\n", name, (argtwo[0] == '\'' || argtwo[0] == ',') ? "" : " ", argtwo); notify_player(whisperee, cmdwork); } else { if (get_str_elt(whisperee, NAME, &name) == -1) goto whisperbomb; sprintf(cmdwork, "You whisper, \"%s\" to %s.\r\n", (argtwo && *argtwo) ? argtwo : "", name); notify_player(player, cmdwork); if (get_str_elt(player, NAME, &name) == -1) goto whisperbomb; sprintf(cmdwork, "%s whispers, \"%s\"\r\n", name, (argtwo && *argtwo) ? argtwo : ""); notify_player(whisperee, cmdwork); } return; whisperbomb: notify_bad(player); return; }