Atrinik Server  4.0
resetmaps.c
Go to the documentation of this file.
1 /*************************************************************************
2  * Atrinik, a Multiplayer Online Role Playing Game *
3  * *
4  * Copyright (C) 2009-2014 Alex Tokar and Atrinik Development Team *
5  * *
6  * Fork from Crossfire (Multiplayer game for X-windows). *
7  * *
8  * This program is free software; you can redistribute it and/or modify *
9  * it under the terms of the GNU General Public License as published by *
10  * the Free Software Foundation; either version 2 of the License, or *
11  * (at your option) any later version. *
12  * *
13  * This program is distributed in the hope that it will be useful, *
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16  * GNU General Public License for more details. *
17  * *
18  * You should have received a copy of the GNU General Public License *
19  * along with this program; if not, write to the Free Software *
20  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
21  * *
22  * The author can be reached at admin@atrinik.org *
23  ************************************************************************/
24 
32 #include <global.h>
33 #include <object.h>
34 
48  mapstruct ***maps, size_t *maps_num)
49 {
50  *maps = erealloc(*maps, sizeof(**maps) * ((*maps_num) + 1));
51  (*maps)[*maps_num] = tiled;
52  (*maps_num)++;
53 
54  return 0;
55 }
56 
58 void command_resetmaps(object *op, const char *command, char *params)
59 {
60  mapstruct *m, **maps;
61  size_t maps_num, i;
62  int failed, success;
63 
64  m = NULL;
65  maps = NULL;
66  maps_num = 0;
67  failed = success = 0;
68 
69  if (params != NULL && strcasecmp(params, "all") == 0) {
70  DL_FOREACH(first_map, m)
71  {
72  command_resetmaps_internal(m, NULL, &maps, &maps_num);
73  }
74  } else {
75  shstr *mappath;
76 
77  mappath = NULL;
78 
79  if (params == NULL) {
80  m = op->map;
81  } else if (!map_path_isabs(params)) {
82  char *path;
83 
84  path = map_get_path(op->map, params, 0, NULL);
85  mappath = add_string(path);
86  efree(path);
87  } else {
88  mappath = add_string(params);
89  }
90 
91  if (mappath != NULL) {
92  m = has_been_loaded_sh(mappath);
93  free_string_shared(mappath);
94  }
95 
96  if (m == NULL) {
97  draw_info(COLOR_WHITE, op, "No such map.");
98  return;
99  }
100 
102  {
103  }
105  }
106 
107  if (maps == NULL) {
108  LOG(BUG, "Failed to find any maps to reset: %s", m->path);
109  draw_info_format(COLOR_RED, op, "Failed to find any maps to reset: %s",
110  m->path);
111  return;
112  }
113 
114  for (i = 0; i < maps_num; i++) {
115  if (map_force_reset(maps[i]) != NULL) {
116  success++;
117  } else {
118  failed++;
119  }
120  }
121 
122  efree(maps);
123 
124  if (success != 0) {
125  draw_info_format(COLOR_WHITE, op, "Successfully reset %d maps.",
126  success);
127  }
128 
129  if (failed != 0) {
130  draw_info_format(COLOR_RED, op, "Failed to reset %d maps.",
131  failed);
132  }
133 }
shstr * path
Definition: map.h:568
#define MAP_TILES_WALK_START(_m, _fnc,...)
Definition: map.h:733
void command_resetmaps(object *op, const char *command, char *params)
Definition: resetmaps.c:58
struct mapdef * map
Definition: object.h:139
static int command_resetmaps_internal(mapstruct *tiled, mapstruct *map, mapstruct ***maps, size_t *maps_num)
Definition: resetmaps.c:47
mapstruct * map_force_reset(mapstruct *m)
Definition: map.c:2691
mapstruct * has_been_loaded_sh(shstr *name)
Definition: map.c:389
#define MAP_TILES_WALK_END
Definition: map.h:766
Definition: map.h:536
mapstruct * first_map
Definition: main.c:59