MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame^] | 1 | /* These are the special commands from the driver that are activated with |
| 2 | * set_is_wizard(). These functions must be added to the player object. |
| 3 | * Also set_is_wizard() must be called in the corresponding player object, |
| 4 | * not as an (simul-)efun. |
| 5 | */ |
| 6 | |
| 7 | #include <commands.h> |
| 8 | #include <driver_info.h> |
| 9 | |
| 10 | /* is_wizard: |
| 11 | * 1: has actions, |
| 12 | * 0: never had actions, |
| 13 | * -1: had actions once. |
| 14 | */ |
| 15 | private nosave int is_wizard; |
| 16 | |
| 17 | private int driver_malloc(string str) |
| 18 | { |
| 19 | if(is_wizard <= 0) |
| 20 | return 0; |
| 21 | |
| 22 | if(!sizeof(str)) |
| 23 | { |
| 24 | write(efun::driver_info(DI_STATUS_TEXT_MALLOC)); |
| 25 | return 1; |
| 26 | } |
| 27 | |
| 28 | if(str == "extstats") |
| 29 | { |
| 30 | write(efun::driver_info(DI_STATUS_TEXT_MALLOC_EXTENDED)); |
| 31 | return 1; |
| 32 | } |
| 33 | |
| 34 | return 0; |
| 35 | } |
| 36 | |
| 37 | private int driver_dumpallobj(string str) |
| 38 | { |
| 39 | if(is_wizard <= 0 || sizeof(str)) |
| 40 | return 0; |
| 41 | |
| 42 | write("Dumping to /OBJ_DUMP ... "); |
| 43 | efun::dump_driver_info(DDI_OBJECTS); |
| 44 | efun::dump_driver_info(DDI_OBJECTS_DESTRUCTED); |
| 45 | write("done\n"); |
| 46 | return 1; |
| 47 | } |
| 48 | |
| 49 | private int driver_opcdump(string str) |
| 50 | { |
| 51 | if(is_wizard <= 0 || sizeof(str)) |
| 52 | return 0; |
| 53 | |
| 54 | efun::dump_driver_info(DDI_OPCODES); |
| 55 | return 1; |
| 56 | } |
| 57 | |
| 58 | private int driver_status(string str) |
| 59 | { |
| 60 | int opt; |
| 61 | if(is_wizard <= 0) |
| 62 | return 0; |
| 63 | |
| 64 | switch(str || "") |
| 65 | { |
| 66 | case "": |
| 67 | opt = DI_STATUS_TEXT_MEMORY; |
| 68 | break; |
| 69 | |
| 70 | case "tables": |
| 71 | case " tables": |
| 72 | opt = DI_STATUS_TEXT_TABLES; |
| 73 | break; |
| 74 | |
| 75 | case "swap": |
| 76 | case " swap": |
| 77 | opt = DI_STATUS_TEXT_SWAP; |
| 78 | break; |
| 79 | |
| 80 | case "malloc": |
| 81 | case " malloc": |
| 82 | opt = DI_STATUS_TEXT_MALLOC; |
| 83 | break; |
| 84 | |
| 85 | case "malloc extstats": |
| 86 | case " malloc extstats": |
| 87 | opt = DI_STATUS_TEXT_MALLOC_EXTENDED; |
| 88 | break; |
| 89 | |
| 90 | default: |
| 91 | return 0; |
| 92 | } |
| 93 | |
| 94 | write(efun::driver_info(opt)); |
| 95 | return 1; |
| 96 | } |
| 97 | |
| 98 | int set_is_wizard(varargs <object|int>* args) |
| 99 | { |
| 100 | int oldval = is_wizard; |
| 101 | |
| 102 | if(!sizeof(args)) |
| 103 | raise_error("Too few arguments to set_is_wizard\n"); |
| 104 | if(sizeof(args) > 2) |
| 105 | raise_error("Too many arguments to set_is_wizard\n"); |
| 106 | if(!objectp(args[0])) |
| 107 | raise_error("Bad arg 1 to set_is_wizard()\n"); |
| 108 | if(args[0] != this_object()) |
| 109 | raise_error("Only set_is_wizard for the current object supported\n"); |
| 110 | if(this_player() != this_object()) |
| 111 | raise_error("The current object must be this_player() for set_is_wizard()\n"); |
| 112 | if(sizeof(args) == 2 && !intp(args[1])) |
| 113 | raise_error("Bad arg 2 to set_is_wizard()\n"); |
| 114 | |
| 115 | if(sizeof(args) == 2 && !args[1]) |
| 116 | { |
| 117 | if(is_wizard > 0) |
| 118 | is_wizard = -1; |
| 119 | } |
| 120 | else if(sizeof(args) == 2 && args[1]<0) |
| 121 | { |
| 122 | // Just return the old value. |
| 123 | } |
| 124 | else |
| 125 | { |
| 126 | if(!is_wizard) |
| 127 | { |
| 128 | add_action(#'driver_malloc, "malloc"); |
| 129 | add_action(#'driver_dumpallobj, "dumpallobj"); |
| 130 | add_action(#'driver_opcdump, "opcdump"); |
| 131 | add_action(#'driver_status, "status", AA_NOSPACE); |
| 132 | } |
| 133 | is_wizard = 1; |
| 134 | } |
| 135 | |
| 136 | return oldval > 0; |
| 137 | } |