… | |
… | |
24 | |
24 | |
25 | #include <global.h> |
25 | #include <global.h> |
26 | #include <loader.h> |
26 | #include <loader.h> |
27 | #include <sproto.h> |
27 | #include <sproto.h> |
28 | |
28 | |
29 | #include <dirent.h> |
|
|
30 | |
|
|
31 | /* Handles misc. input request - things like hash table, malloc, maps, |
29 | /* Handles misc. input request - things like hash table, malloc, maps, |
32 | * who, etc. |
30 | * who, etc. |
33 | */ |
31 | */ |
34 | |
32 | |
35 | /* This command dumps the body information for object *op. |
33 | /* This command dumps the body information for object *op. |
… | |
… | |
100 | * a description of it. It is there merely for flavour text. |
98 | * a description of it. It is there merely for flavour text. |
101 | */ |
99 | */ |
102 | void |
100 | void |
103 | current_region_info (object *op) |
101 | current_region_info (object *op) |
104 | { |
102 | { |
105 | /* |
103 | if (region *reg = op->region ()) |
106 | * Ok I /suppose/ I should write a seperate function for this, but it isn't |
|
|
107 | * going to be /that/ slow, and won't get called much |
|
|
108 | */ |
|
|
109 | region *r = get_region_by_name (get_name_of_region_for_map (op->map)); |
|
|
110 | |
|
|
111 | if (!r) |
|
|
112 | return; |
|
|
113 | /* This should only be possible if regions are not operating on this server. */ |
|
|
114 | |
|
|
115 | new_draw_info_format (NDI_UNIQUE, 0, op, "You are in %s. \n %s", get_region_longname (r), get_region_msg (r)); |
104 | new_draw_info_format (NDI_UNIQUE, 0, op, "You are in %s.\n%s", reg->longname, reg->msg); |
116 | } |
105 | } |
117 | |
106 | |
118 | void |
107 | void |
119 | current_map_info (object *op) |
108 | current_map_info (object *op) |
120 | { |
109 | { |
121 | maptile *m = op->map; |
110 | maptile *m = op->map; |
122 | |
111 | |
123 | if (!m) |
112 | if (!m) |
124 | return; |
113 | return; |
125 | |
114 | |
126 | new_draw_info_format (NDI_UNIQUE, 0, op, "%s (%s) in %s", &m->name, &m->path, get_name_of_region_for_map (m)); |
115 | new_draw_info_format (NDI_UNIQUE, 0, op, "%s (%s) in %s", &m->name, &m->path, op->region ()->name); |
127 | |
116 | |
128 | if (QUERY_FLAG (op, FLAG_WIZ)) |
117 | if (QUERY_FLAG (op, FLAG_WIZ)) |
129 | { |
|
|
130 | new_draw_info_format (NDI_UNIQUE, 0, op, |
118 | new_draw_info_format (NDI_UNIQUE, 0, op, |
131 | "players:%d difficulty:%d size:%dx%d start:%dx%d timeout %ld", |
119 | "players:%d difficulty:%d size:%dx%d start:%dx%d timeout %ld", |
132 | m->players, m->difficulty, m->width, m->height, m->enter_x, m->enter_y, m->timeout); |
120 | m->players, m->difficulty, m->width, m->height, m->enter_x, m->enter_y, m->timeout); |
133 | |
121 | |
134 | } |
|
|
135 | if (m->msg) |
122 | if (m->msg) |
136 | new_draw_info (NDI_UNIQUE, NDI_NAVY, op, m->msg); |
123 | new_draw_info (NDI_UNIQUE, NDI_NAVY, op, m->msg); |
137 | } |
124 | } |
138 | |
125 | |
139 | #ifdef DEBUG_MALLOC_LEVEL |
126 | #ifdef DEBUG_MALLOC_LEVEL |
… | |
… | |
151 | #endif |
138 | #endif |
152 | |
139 | |
153 | int |
140 | int |
154 | command_whereabouts (object *op, char *params) |
141 | command_whereabouts (object *op, char *params) |
155 | { |
142 | { |
156 | |
143 | //TODO: should obviously not waste space in struct region for this. |
157 | region *reg; |
|
|
158 | player *pl; |
|
|
159 | |
|
|
160 | /* |
144 | /* |
161 | * reset the counter on the region, then use it to store the number of |
145 | * reset the counter on the region, then use it to store the number of |
162 | * players there. |
146 | * players there. |
163 | * I don't know how thread-safe this would be, I suspect not very.... |
147 | * I don't know how thread-safe this would be, I suspect not very.... |
164 | */ |
148 | */ |
165 | for (reg = first_region; reg != NULL; reg = reg->next) |
149 | for (region *reg = first_region; reg; reg = reg->next) |
166 | { |
|
|
167 | reg->counter = 0; |
150 | reg->counter = 0; |
168 | } |
151 | |
169 | for_all_players (pl) |
152 | for_all_players (pl) |
170 | if (pl->ob->map != NULL) |
153 | if (pl->ob->map) |
171 | get_region_by_map (pl->ob->map)->counter++; |
154 | ++pl->ob->region ()->counter; |
172 | |
155 | |
173 | /* we only want to print out by places with a 'longname' field... */ |
156 | /* we only want to print out by places with a 'longname' field... */ |
174 | for (reg = first_region; reg != NULL; reg = reg->next) |
157 | for (region *reg = first_region; reg; reg = reg->next) |
175 | { |
158 | { |
176 | if (reg->longname == NULL && reg->counter > 0) |
159 | if (reg->longname == NULL && reg->counter > 0) |
177 | { |
160 | { |
178 | if (reg->parent != NULL) |
161 | if (reg->parent) |
179 | { |
162 | { |
180 | reg->parent->counter += reg->counter; |
163 | reg->parent->counter += reg->counter; |
181 | reg->counter = 0; |
164 | reg->counter = 0; |
182 | } |
165 | } |
183 | else /*uh oh, we shouldn't be here. */ |
166 | else /*uh oh, we shouldn't be here. */ |
184 | LOG (llevError, "command_whereabouts() Region %s with no longname has no parent", reg->name); |
167 | LOG (llevError, "command_whereabouts() Region %s with no longname has no parent", reg->name); |
185 | } |
168 | } |
186 | } |
169 | } |
|
|
170 | |
187 | new_draw_info_format (NDI_UNIQUE, 0, op, "In the world currently there are:"); |
171 | new_draw_info_format (NDI_UNIQUE, 0, op, "In the world currently there are:"); |
|
|
172 | |
188 | for (reg = first_region; reg != NULL; reg = reg->next) |
173 | for (region *reg = first_region; reg; reg = reg->next) |
189 | if (reg->counter > 0) |
174 | if (reg->counter) |
190 | new_draw_info_format (NDI_UNIQUE, 0, op, "%u players in %s", reg->counter, get_region_longname (reg)); |
175 | new_draw_info_format (NDI_UNIQUE, 0, op, "%u players in %s", reg->counter, get_region_longname (reg)); |
|
|
176 | |
191 | return 1; |
177 | return 1; |
192 | } |
178 | } |
193 | |
179 | |
194 | typedef struct |
180 | typedef struct |
195 | { |
181 | { |
… | |
… | |
560 | op->update_stats (); |
546 | op->update_stats (); |
561 | return 1; |
547 | return 1; |
562 | } |
548 | } |
563 | |
549 | |
564 | int |
550 | int |
565 | command_players (object *op, char *paramss) |
|
|
566 | { |
|
|
567 | char buf[MAX_BUF]; |
|
|
568 | char *t; |
|
|
569 | DIR *Dir; |
|
|
570 | |
|
|
571 | sprintf (buf, "%s/%s/", settings.localdir, settings.playerdir); |
|
|
572 | t = buf + strlen (buf); |
|
|
573 | if ((Dir = opendir (buf)) != NULL) |
|
|
574 | { |
|
|
575 | const struct dirent *Entry; |
|
|
576 | |
|
|
577 | while ((Entry = readdir (Dir))) |
|
|
578 | { |
|
|
579 | /* skip '.' , '..' */ |
|
|
580 | if (!((Entry->d_name[0] == '.' && Entry->d_name[1] == '\0') || |
|
|
581 | (Entry->d_name[0] == '.' && Entry->d_name[1] == '.' && Entry->d_name[2] == '\0'))) |
|
|
582 | { |
|
|
583 | struct stat Stat; |
|
|
584 | |
|
|
585 | strcpy (t, Entry->d_name); |
|
|
586 | if (stat (buf, &Stat) == 0) |
|
|
587 | { |
|
|
588 | /* This was not posix compatible |
|
|
589 | * if ((Stat.st_mode & S_IFMT)==S_IFDIR) { |
|
|
590 | */ |
|
|
591 | if (S_ISDIR (Stat.st_mode)) |
|
|
592 | { |
|
|
593 | char buf2[MAX_BUF]; |
|
|
594 | struct tm *tm = localtime (&Stat.st_mtime); |
|
|
595 | |
|
|
596 | sprintf (buf2, "%s\t%04d %02d %02d %02d %02d %02d", |
|
|
597 | Entry->d_name, 1900 + tm->tm_year, 1 + tm->tm_mon, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec); |
|
|
598 | new_draw_info (NDI_UNIQUE, 0, op, buf2); |
|
|
599 | } |
|
|
600 | } |
|
|
601 | } |
|
|
602 | } |
|
|
603 | } |
|
|
604 | closedir (Dir); |
|
|
605 | return 0; |
|
|
606 | } |
|
|
607 | |
|
|
608 | |
|
|
609 | |
|
|
610 | int |
|
|
611 | command_logs (object *op, char *params) |
551 | command_logs (object *op, char *params) |
612 | { |
552 | { |
613 | new_draw_info (NDI_UNIQUE, 0, op, "Nobody is currently logging kills."); |
553 | new_draw_info (NDI_UNIQUE, 0, op, "Nobody is currently logging kills."); |
614 | |
554 | |
615 | return 1; |
555 | return 1; |
… | |
… | |
636 | else |
576 | else |
637 | { |
577 | { |
638 | new_draw_info_format (NDI_UNIQUE, 0, op, "applymode: Unknown options %s, valid options are nochoice, never, always", params); |
578 | new_draw_info_format (NDI_UNIQUE, 0, op, "applymode: Unknown options %s, valid options are nochoice, never, always", params); |
639 | return 0; |
579 | return 0; |
640 | } |
580 | } |
|
|
581 | |
641 | new_draw_info_format (NDI_UNIQUE, 0, op, "Applymode %s set to %s", |
582 | new_draw_info_format (NDI_UNIQUE, 0, op, "Applymode %s set to %s", |
642 | (unapply == op->contr->unapply ? "" : " now"), types[op->contr->unapply]); |
583 | (unapply == op->contr->unapply ? "" : " now"), types[op->contr->unapply]); |
643 | return 1; |
584 | return 1; |
644 | } |
585 | } |
645 | |
586 | |
… | |
… | |
667 | found++; |
608 | found++; |
668 | op->contr->bowtype = (bowtype_t) i; |
609 | op->contr->bowtype = (bowtype_t) i; |
669 | break; |
610 | break; |
670 | } |
611 | } |
671 | } |
612 | } |
|
|
613 | |
672 | if (!found) |
614 | if (!found) |
673 | { |
615 | { |
674 | sprintf (buf, "bowmode: Unknown options %s, valid options are:", params); |
616 | sprintf (buf, "bowmode: Unknown options %s, valid options are:", params); |
675 | for (i = 0; i <= bow_bestarrow; i++) |
617 | for (i = 0; i <= bow_bestarrow; i++) |
676 | { |
618 | { |
… | |
… | |
682 | strcat (buf, "."); |
624 | strcat (buf, "."); |
683 | } |
625 | } |
684 | new_draw_info_format (NDI_UNIQUE, 0, op, buf); |
626 | new_draw_info_format (NDI_UNIQUE, 0, op, buf); |
685 | return 0; |
627 | return 0; |
686 | } |
628 | } |
|
|
629 | |
687 | new_draw_info_format (NDI_UNIQUE, 0, op, "bowmode %s set to %s", (oldtype == op->contr->bowtype ? "" : "now"), types[op->contr->bowtype]); |
630 | new_draw_info_format (NDI_UNIQUE, 0, op, "bowmode %s set to %s", (oldtype == op->contr->bowtype ? "" : "now"), types[op->contr->bowtype]); |
688 | return 1; |
631 | return 1; |
689 | } |
632 | } |
690 | |
633 | |
691 | int |
634 | int |