ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/c_wiz.C
(Generate patch)

Comparing deliantra/server/server/c_wiz.C (file contents):
Revision 1.91 by root, Wed Nov 21 12:12:03 2012 UTC vs.
Revision 1.93 by root, Wed Nov 16 23:42:02 2016 UTC

1/* 1/*
2 * This file is part of Deliantra, the Roguelike Realtime MMORPG. 2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 * 3 *
4 * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012 Marc Alexander Lehmann / Robin Redeker / the Deliantra team 4 * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (©) 2002 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2002 Mark Wedel & Crossfire Development Team
6 * Copyright (©) 1992 Frank Tore Johansen 6 * Copyright (©) 1992 Frank Tore Johansen
7 * 7 *
8 * Deliantra is free software: you can redistribute it and/or modify it under 8 * Deliantra is free software: you can redistribute it and/or modify it under
9 * the terms of the Affero GNU General Public License as published by the 9 * the terms of the Affero GNU General Public License as published by the
257 257
258 /* Last case: get stack top */ 258 /* Last case: get stack top */
259 if (from) 259 if (from)
260 *from = STACK_FROM_TOP; 260 *from = STACK_FROM_TOP;
261 return dm_stack_peek (pl); 261 return dm_stack_peek (pl);
262}
263
264/**
265 * Actually hides specified player (obviously a DM).
266 * If 'silent_dm' is non zero, other players are informed of DM entering/leaving,
267 * else they just think someone left/entered.
268 */
269static void
270do_wizard_hide (object *op, int silent_dm)
271{
272 if (op->contr->hidden)
273 {
274 op->contr->hidden = 0;
275 op->invisible = 1;
276 new_draw_info (NDI_UNIQUE, 0, op, "You are no longer hidden from other players");
277 op->map->players++;
278 new_draw_info_format (NDI_UNIQUE | NDI_ALL | NDI_DK_ORANGE, 5, NULL, "%s has entered the game.", &op->name);
279
280 if (!silent_dm)
281 new_draw_info (NDI_UNIQUE | NDI_ALL | NDI_LT_GREEN, 1, NULL, "The Dungeon Master has arrived!");
282 }
283 else
284 {
285 op->contr->hidden = 1;
286 new_draw_info (NDI_UNIQUE, 0, op, "Other players will no longer see you.");
287 op->map->players--;
288
289 if (!silent_dm)
290 new_draw_info (NDI_UNIQUE | NDI_ALL | NDI_LT_GREEN, 1, NULL, "The Dungeon Master is gone..");
291
292 new_draw_info_format (NDI_UNIQUE | NDI_ALL | NDI_DK_ORANGE, 5, NULL, "%s leaves the game.", &op->name);
293 new_draw_info_format (NDI_UNIQUE | NDI_ALL | NDI_DK_ORANGE, 5, NULL, "%s left the game.", &op->name);
294 }
295}
296
297int
298command_hide (object *op, char *params)
299{
300 do_wizard_hide (op, 0);
301 return 1;
302} 262}
303 263
304/** 264/**
305 * This finds and returns the object which matches the name or 265 * This finds and returns the object which matches the name or
306 * object nubmer (specified via num #whatever). 266 * object nubmer (specified via num #whatever).
1117 new_draw_info (NDI_UNIQUE, 0, op, "No such player."); 1077 new_draw_info (NDI_UNIQUE, 0, op, "No such player.");
1118 return 1; 1078 return 1;
1119} 1079}
1120 1080
1121int 1081int
1122command_nowiz (object *op, char *params)
1123{ /* 'nodm' is alias */
1124 op->clr_flag (FLAG_WIZ);
1125 op->clr_flag (FLAG_WIZPASS);
1126 op->clr_flag (FLAG_WIZCAST);
1127 op->clr_flag (FLAG_WIZLOOK);
1128 op->contr->do_los = 1;
1129
1130 if (op->contr->hidden)
1131 {
1132 new_draw_info (NDI_UNIQUE, 0, op, "You are no longer hidden from other players");
1133 op->map->players++;
1134 new_draw_info_format (NDI_UNIQUE | NDI_ALL | NDI_DK_ORANGE, 5, NULL, "%s has entered the game.", &op->name);
1135 op->contr->hidden = 0;
1136 op->invisible = 1;
1137 }
1138 else
1139 new_draw_info (NDI_UNIQUE | NDI_ALL | NDI_LT_GREEN, 1, NULL, "The Dungeon Master is gone..");
1140
1141 return 1;
1142}
1143
1144/**
1145 * object *op is trying to become dm.
1146 * pl_name is name supplied by player. Restrictive DM will make it harder
1147 * for socket users to become DM - in that case, it will check for the players
1148 * character name.
1149 */
1150static int
1151checkdm (object *op, const char *pl_name, const char *pl_passwd, const char *pl_host)
1152{
1153 FILE *dmfile;
1154 char buf[MAX_BUF];
1155 char line_buf[160], name[160], passwd[160], host[160];
1156
1157#ifdef RESTRICTIVE_DM
1158 *pl_name = op->name ? op->name : "*";
1159#endif
1160
1161 sprintf (buf, "%s/%s", settings.confdir, DMFILE);
1162 if ((dmfile = fopen (buf, "r")) == NULL)
1163 {
1164 LOG (llevDebug, "Could not find DM file.\n");
1165 return 0;
1166 }
1167
1168 while (fgets (line_buf, 160, dmfile) != NULL)
1169 {
1170 if (line_buf[0] == '#')
1171 continue;
1172 if (sscanf (line_buf, "%[^:]:%[^:]:%s\n", name, passwd, host) != 3)
1173 {
1174 LOG (llevError, "Warning - malformed dm file entry: %s\n", line_buf);
1175 }
1176 else if ((!strcmp (name, "*") || (pl_name && !strcmp (pl_name, name)))
1177 && (!strcmp (passwd, "*") || !strcmp (passwd, pl_passwd)) && (!strcmp (host, "*") || !strcmp (host, pl_host)))
1178 {
1179 fclose (dmfile);
1180 return (1);
1181 }
1182 }
1183 fclose (dmfile);
1184 return (0);
1185}
1186
1187static int
1188do_wizard_dm (object *op, char *params, int silent)
1189{
1190 if (!op->contr)
1191 return 0;
1192
1193 if (op->flag [FLAG_WIZ])
1194 {
1195 new_draw_info (NDI_UNIQUE, 0, op, "You are already the Dungeon Master!");
1196 return 0;
1197 }
1198
1199 if (checkdm (op, op->name, (params ? params : "*"), op->contr->ns->host))
1200 {
1201 op->set_flag (FLAG_WIZ);
1202 op->set_flag (FLAG_WIZPASS);
1203 op->set_flag (FLAG_WIZCAST);
1204 op->set_flag (FLAG_WIZLOOK);
1205 op->contr->do_los = 1;
1206
1207 new_draw_info (NDI_UNIQUE, 0, op, "Ok, you are the Dungeon Master!");
1208 op->contr->write_buf[0] = '\0';
1209
1210 if (!silent)
1211 new_draw_info (NDI_UNIQUE | NDI_ALL | NDI_LT_GREEN, 1, NULL, "The Dungeon Master has arrived!");
1212
1213 return 1;
1214 }
1215 else
1216 {
1217 new_draw_info (NDI_UNIQUE, 0, op, "Sorry Pal, I don't think so.");
1218 op->contr->write_buf[0] = '\0';
1219 return 0;
1220 }
1221}
1222
1223/*
1224 * Actual command to perhaps become dm. Changed aroun a bit in version 0.92.2
1225 * - allow people on sockets to become dm, and allow better dm file
1226 */
1227int
1228command_dm (object *op, char *params)
1229{
1230 if (!op->contr)
1231 return 0;
1232
1233 do_wizard_dm (op, params, 0);
1234
1235 return 1;
1236}
1237
1238int
1239command_invisible (object *op, char *params) 1082command_invisible (object *op, char *params)
1240{ 1083{
1241 if (op) 1084 if (op)
1242 { 1085 {
1243 op->invisible += 100; 1086 op->invisible += TIME2TICK (60);
1244 update_object (op, UP_OBJ_CHANGE); 1087 update_object (op, UP_OBJ_CHANGE);
1245 new_draw_info (NDI_UNIQUE, 0, op, "You turn invisible."); 1088 new_draw_info (NDI_UNIQUE, 0, op, "You turn invisible.");
1246 } 1089 }
1247 1090
1248 return 0; 1091 return 0;
1353 new_draw_info_format (NDI_UNIQUE, 0, op, "You do not know the spell %s.", params); 1196 new_draw_info_format (NDI_UNIQUE, 0, op, "You do not know the spell %s.", params);
1354 return 0; 1197 return 0;
1355 } 1198 }
1356 1199
1357 do_forget_spell (op, spell->name); 1200 do_forget_spell (op, spell->name);
1358 return 1;
1359}
1360
1361/**
1362 * A players wants to become DM and hide.
1363 * Let's see if that's authorized.
1364 * Make sure to not tell anything to anyone.
1365 */
1366int
1367command_dmhide (object *op, char *params)
1368{
1369 if (!do_wizard_dm (op, params, 1))
1370 return 0;
1371
1372 do_wizard_hide (op, 1);
1373
1374 return 1; 1201 return 1;
1375} 1202}
1376 1203
1377/** 1204/**
1378 * Pop the stack top. 1205 * Pop the stack top.

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines