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

Comparing deliantra/server/server/login.C (file contents):
Revision 1.21 by root, Tue Dec 12 20:53:03 2006 UTC vs.
Revision 1.35 by root, Mon Dec 25 17:11:17 2006 UTC

20 20
21 The authors can be reached via e-mail at <crossfire@schmorp.de> 21 The authors can be reached via e-mail at <crossfire@schmorp.de>
22*/ 22*/
23 23
24#include <global.h> 24#include <global.h>
25#ifndef __CEXTRACT__
26# include <sproto.h> 25#include <sproto.h>
27#endif
28#include <spells.h> 26#include <spells.h>
29#include <loader.h> 27#include <loader.h>
30#include <define.h> 28#include <define.h>
31 29
32extern void sub_weight (object *, signed long); 30extern void sub_weight (object *, signed long);
37 * keep the game running. Thus, we don't want to free any information. 35 * keep the game running. Thus, we don't want to free any information.
38 */ 36 */
39void 37void
40emergency_save (int flag) 38emergency_save (int flag)
41{ 39{
42 player *pl;
43
44#ifndef NO_EMERGENCY_SAVE
45 trying_emergency_save = 1; 40 trying_emergency_save = 1;
46 if (editor) 41
47 return;
48 LOG (llevError, "Emergency save: "); 42 LOG (llevError, "Emergency save: ");
49 for (pl = first_player; pl != NULL; pl = pl->next) 43 for_all_players (pl)
50 { 44 {
51 if (!pl->ob) 45 if (!pl->ob)
52 { 46 {
53 LOG (llevError, "No name, ignoring this.\n"); 47 LOG (llevError, "No name, ignoring this.\n");
54 continue; 48 continue;
55 } 49 }
50
56 LOG (llevError, "%s ", pl->ob->name); 51 LOG (llevError, "%s ", &pl->ob->name);
57 new_draw_info (NDI_UNIQUE, 0, pl->ob, "Emergency save..."); 52 new_draw_info (NDI_UNIQUE, 0, pl->ob, "Emergency save...");
58 53
59/* If we are not exiting the game (ie, this is sort of a backup save), then 54 /* If we are not exiting the game (ie, this is sort of a backup save), then
60 * don't change the location back to the village. Note that there are other 55 * don't change the location back to the village. Note that there are other
61 * options to have backup saves be done at the starting village 56 * options to have backup saves be done at the starting village
62 */ 57 */
63 if (!flag) 58 if (!flag)
64 { 59 {
65 strcpy (pl->maplevel, first_map_path); 60 strcpy (pl->maplevel, first_map_path);
66 if (pl->ob->map != NULL) 61
67 pl->ob->map = NULL; 62 pl->ob->map = 0;
68 pl->ob->x = -1; 63 pl->ob->x = -1;
69 pl->ob->y = -1; 64 pl->ob->y = -1;
70 } 65 }
71 if (!save_player (pl->ob, flag)) 66
72 { 67 pl->save (1);
73 LOG (llevError, "(failed) ");
74 new_draw_info (NDI_UNIQUE, 0, pl->ob, "Emergency save failed, checking score...");
75 }
76 check_score (pl->ob);
77 } 68 }
69
78 LOG (llevError, "\n"); 70 LOG (llevError, "\n");
79#else
80 LOG (llevInfo, "Emergency saves disabled, no save attempted\n");
81#endif
82 /* If the game is exiting, remove the player locks */
83 if (!flag)
84 {
85 for (pl = first_player; pl != NULL; pl = pl->next)
86 {
87 if (pl->ob)
88 {
89 }
90 }
91 }
92} 71}
93 72
94/* Delete character with name. if new is set, also delete the new 73/* Delete character with name. if new is set, also delete the new
95 * style directory, otherwise, just delete the old style playfile 74 * style directory, otherwise, just delete the old style playfile
96 * (needed for transition) 75 * (needed for transition)
99delete_character (const char *name, int newchar) 78delete_character (const char *name, int newchar)
100{ 79{
101 char buf[MAX_BUF]; 80 char buf[MAX_BUF];
102 81
103 sprintf (buf, "%s/%s/%s.pl", settings.localdir, settings.playerdir, name); 82 sprintf (buf, "%s/%s/%s.pl", settings.localdir, settings.playerdir, name);
83
104 if (unlink (buf) == -1) 84 if (unlink (buf) == -1)
105 LOG (llevDebug, "Cannot delete character file %s: %s\n", buf, strerror (errno)); 85 LOG (llevDebug, "Cannot delete character file %s: %s\n", buf, strerror (errno));
86
106 if (newchar) 87 if (newchar)
107 { 88 {
108 sprintf (buf, "%s/%s/%s", settings.localdir, settings.playerdir, name); 89 sprintf (buf, "%s/%s/%s", settings.localdir, settings.playerdir, name);
109 /* this effectively does an rm -rf on the directory */ 90 /* this effectively does an rm -rf on the directory */
110 remove_directory (buf); 91 remove_directory (buf);
111 } 92 }
112}
113
114/* This verify that a character of name exits, and that it matches
115 * password. It return 0 if there is match, 1 if no such player,
116 * 2 if incorrect password.
117 */
118
119int
120verify_player (const char *name, char *password)
121{
122 char buf[MAX_BUF];
123 int comp;
124 FILE *fp;
125
126 if (strpbrk (name, "/.\\") != NULL)
127 {
128 LOG (llevError, "Username contains illegal characters: %s\n", name);
129 return 1;
130 }
131
132 snprintf (buf, sizeof (buf), "%s/%s/%s/%s.pl", settings.localdir, settings.playerdir, name, name);
133 if (strlen (buf) >= sizeof (buf) - 1)
134 {
135 LOG (llevError, "Username too long: %s\n", name);
136 return 1;
137 }
138
139 if ((fp = open_and_uncompress (buf, 0, &comp)) == NULL)
140 return 1;
141
142 /* Read in the file until we find the password line. Our logic could
143 * be a bit better on cleaning up the password from the file, but since
144 * it is written by the program, I think it is fair to assume that the
145 * syntax should be pretty standard.
146 */
147 while (fgets (buf, MAX_BUF - 1, fp) != NULL)
148 {
149 if (!strncmp (buf, "password ", 9))
150 {
151 buf[strlen (buf) - 1] = 0; /* remove newline */
152 if (check_password (password, buf + 9))
153 {
154 close_and_delete (fp, comp);
155 return 0;
156 }
157 else
158 {
159 close_and_delete (fp, comp);
160 return 2;
161 }
162 }
163 }
164 LOG (llevDebug, "Could not find a password line in player %s\n", name);
165 close_and_delete (fp, comp);
166 return 1;
167}
168
169/* Checks to see if anyone else by 'name' is currently playing.
170 * If we find that file or another character of some name is already in the
171 * game, we don't let this person join (we should really let the new player
172 * enter the password, and if correct, disconnect that socket and attach it to
173 * the players current session.
174 * If no one by that name is currently playing, we then make sure the name
175 * doesn't include any bogus characters.
176 * We return 0 if the name is in use/bad, 1 if it is OK to use this name.
177 */
178
179int
180check_name (player *me, const char *name)
181{
182 player *pl;
183
184 for (pl = first_player; pl != NULL; pl = pl->next)
185 if (pl != me && pl->ob->name != NULL && !strcmp (pl->ob->name, name))
186 {
187 new_draw_info (NDI_UNIQUE, 0, me->ob, "That name is already in use.");
188 return 0;
189 }
190
191 if (*name == '\0')
192 {
193 new_draw_info (NDI_UNIQUE, 0, me->ob, "Null names are not allowed.");
194 return 0;
195 }
196
197 if (!playername_ok (name))
198 {
199 new_draw_info (NDI_UNIQUE, 0, me->ob, "That name contains illegal characters.");
200 return 0;
201 }
202 if (strlen (name) >= MAX_NAME)
203 {
204 new_draw_info (NDI_UNIQUE, 0, me->ob, "That name is too long.");
205 return 0;
206 }
207
208 return 1;
209} 93}
210 94
211int 95int
212create_savedir_if_needed (char *savedir) 96create_savedir_if_needed (char *savedir)
213{ 97{
227 LOG (llevError, "Unable to create player savedir %s: %s\n", savedir, strerror (errno)); 111 LOG (llevError, "Unable to create player savedir %s: %s\n", savedir, strerror (errno));
228 return 0; 112 return 0;
229 } 113 }
230 free (buf); 114 free (buf);
231 } 115 }
116
232 return 1; 117 return 1;
233} 118}
234 119
120/*
121 * If final is set, it a clean/final save, not a backup, ie dont remove objects from inventory
122 */
235void 123void
236destroy_object (object *op) 124player::save (bool final)
237{ 125{
238 object *tmp;
239
240 while ((tmp = op->inv))
241 destroy_object (tmp);
242
243 if (!QUERY_FLAG (op, FLAG_REMOVED))
244 op->remove ();
245 op->destroy (0);
246}
247
248/*
249 * If flag is set, it's only backup, ie dont remove objects from inventory
250 * If BACKUP_SAVE_AT_HOME is set, and the flag is set, then the player
251 * will be saved at the emergency save location.
252 * Returns non zero if successful.
253 */
254
255int
256save_player (object *op, int flag)
257{
258 object *tmp, *container = NULL; 126 object *tmp, *container = 0;
259 player *pl = op->contr;
260 int i, wiz = QUERY_FLAG (op, FLAG_WIZ);
261
262#ifdef BACKUP_SAVE_AT_HOME
263 sint16 backup_x, backup_y;
264#endif
265
266 if (!op->stats.exp)
267 return 0; /* no experience, no save */
268
269 flag &= 1;
270
271 if (!pl->name_changed || (!flag && !op->stats.exp))
272 {
273 if (!flag)
274 {
275 new_draw_info (NDI_UNIQUE, 0, op, "Your game is not valid,");
276 new_draw_info (NDI_UNIQUE, 0, op, "Game not saved.");
277 }
278 return 0;
279 }
280 127
281 /* Sanity check - some stuff changes this when player is exiting */ 128 /* Sanity check - some stuff changes this when player is exiting */
282 if (op->type != PLAYER) 129 if (ob->type != PLAYER || !enable_save || !ns)
283 return 0; 130 return;
284 131
285 /* Prevent accidental saves if connection is reset after player has
286 * mostly exited.
287 */
288 if (pl->state != ST_PLAYING && pl->state != ST_GET_PARTY_PASSWORD)
289 return 0;
290
291 INVOKE_PLAYER (SAVE, op->contr); 132 INVOKE_PLAYER (SAVE, ob->contr);
292
293 if (flag == 0)
294 terminate_all_pets (op);
295 133
296 object_freezer freezer; 134 object_freezer freezer;
297 135
136 int wiz = ob->flag [FLAG_WIZ];
137
298 /* Eneq(@csd.uu.se): If we have an open container hide it. */ 138 /* Eneq(@csd.uu.se): If we have an open container hide it. */
299 if (op->container)
300 {
301 container = op->container; 139 container = ob->container;
302 op->container = NULL; 140 ob->container = 0;
303 }
304 141
305 fprintf (freezer, "password %s\n", pl->password); 142 fprintf (freezer, "password %s\n", password);
306 143
307 if (settings.set_title == TRUE)
308 if (pl->own_title[0] != '\0') 144 if (own_title[0] != '\0')
309 fprintf (freezer, "title %s\n", pl->own_title); 145 fprintf (freezer, "title %s\n", own_title);
310 146
311 fprintf (freezer, "explore %d\n", pl->explore); 147 fprintf (freezer, "explore %d\n", explore);
312 fprintf (freezer, "gen_hp %d\n", pl->gen_hp); 148 fprintf (freezer, "gen_hp %d\n", gen_hp);
313 fprintf (freezer, "gen_sp %d\n", pl->gen_sp); 149 fprintf (freezer, "gen_sp %d\n", gen_sp);
314 fprintf (freezer, "gen_grace %d\n", pl->gen_grace); 150 fprintf (freezer, "gen_grace %d\n", gen_grace);
315 fprintf (freezer, "listening %d\n", pl->listening); 151 fprintf (freezer, "listening %d\n", listening);
316 fprintf (freezer, "shoottype %d\n", pl->shoottype); 152 fprintf (freezer, "shoottype %d\n", shoottype);
317 fprintf (freezer, "bowtype %d\n", pl->bowtype); 153 fprintf (freezer, "bowtype %d\n", bowtype);
318 fprintf (freezer, "petmode %d\n", pl->petmode); 154 fprintf (freezer, "petmode %d\n", petmode);
319 fprintf (freezer, "peaceful %d\n", pl->peaceful); 155 fprintf (freezer, "peaceful %d\n", peaceful);
320 fprintf (freezer, "no_shout %d\n", pl->no_shout);
321 fprintf (freezer, "digestion %d\n", pl->digestion); 156 fprintf (freezer, "digestion %d\n", digestion);
322 fprintf (freezer, "pickup %d\n", pl->mode); 157 fprintf (freezer, "pickup %d\n", mode);
323 fprintf (freezer, "outputs_sync %d\n", pl->outputs_sync); 158 fprintf (freezer, "outputs_sync %d\n", outputs_sync);
324 fprintf (freezer, "outputs_count %d\n", pl->outputs_count); 159 fprintf (freezer, "outputs_count %d\n", outputs_count);
325 /* Match the enumerations but in string form */ 160 /* Match the enumerations but in string form */
326 fprintf (freezer, "usekeys %s\n", pl->usekeys == key_inventory ? "key_inventory" : (pl->usekeys == keyrings ? "keyrings" : "containers")); 161 fprintf (freezer, "usekeys %s\n", usekeys == key_inventory ? "key_inventory" : (usekeys == keyrings ? "keyrings" : "containers"));
327 /* Match the enumerations but in string form */ 162 /* Match the enumerations but in string form */
328 fprintf (freezer, "unapply %s\n", pl->unapply == unapply_nochoice ? "unapply_nochoice" : 163 fprintf (freezer, "unapply %s\n", unapply == unapply_nochoice ? "unapply_nochoice" :
329 (pl->unapply == unapply_never ? "unapply_never" : "unapply_always")); 164 (unapply == unapply_never ? "unapply_never" : "unapply_always"));
330 165
331#ifdef BACKUP_SAVE_AT_HOME 166 if (ob->map)
332 if (op->map != NULL && flag == 0)
333#else
334 if (op->map != NULL)
335#endif
336 fprintf (freezer, "map %s\n", op->map->path); 167 fprintf (freezer, "map %s\n", ob->map->path);
337 else 168 else
338 fprintf (freezer, "map %s\n", settings.emergency_mapname); 169 fprintf (freezer, "map %s\n", settings.emergency_mapname);
339 170
340 fprintf (freezer, "savebed_map %s\n", pl->savebed_map); 171 fprintf (freezer, "savebed_map %s\n", savebed_map);
341 fprintf (freezer, "bed_x %d\nbed_y %d\n", pl->bed_x, pl->bed_y); 172 fprintf (freezer, "bed_x %d\nbed_y %d\n", bed_x, bed_y);
342 fprintf (freezer, "weapon_sp %f\n", pl->weapon_sp); 173 fprintf (freezer, "weapon_sp %f\n", weapon_sp);
343 fprintf (freezer, "Str %d\n", pl->orig_stats.Str); 174 fprintf (freezer, "Str %d\n", orig_stats.Str);
344 fprintf (freezer, "Dex %d\n", pl->orig_stats.Dex); 175 fprintf (freezer, "Dex %d\n", orig_stats.Dex);
345 fprintf (freezer, "Con %d\n", pl->orig_stats.Con); 176 fprintf (freezer, "Con %d\n", orig_stats.Con);
346 fprintf (freezer, "Int %d\n", pl->orig_stats.Int); 177 fprintf (freezer, "Int %d\n", orig_stats.Int);
347 fprintf (freezer, "Pow %d\n", pl->orig_stats.Pow); 178 fprintf (freezer, "Pow %d\n", orig_stats.Pow);
348 fprintf (freezer, "Wis %d\n", pl->orig_stats.Wis); 179 fprintf (freezer, "Wis %d\n", orig_stats.Wis);
349 fprintf (freezer, "Cha %d\n", pl->orig_stats.Cha); 180 fprintf (freezer, "Cha %d\n", orig_stats.Cha);
350 181
351 fprintf (freezer, "lev_array %d\n", op->level > 10 ? 10 : op->level); 182 fprintf (freezer, "lev_array %d\n", ob->level > 10 ? 10 : ob->level);
183
352 for (i = 1; i <= pl->last_level && i <= 10; i++) 184 for (int i = 1; i <= last_level && i <= 10; i++)
353 { 185 {
354 fprintf (freezer, "%d\n", pl->levhp[i]); 186 fprintf (freezer, "%d\n", levhp[i]);
355 fprintf (freezer, "%d\n", pl->levsp[i]); 187 fprintf (freezer, "%d\n", levsp[i]);
356 fprintf (freezer, "%d\n", pl->levgrace[i]); 188 fprintf (freezer, "%d\n", levgrace[i]);
357 } 189 }
358 190
359 freezer.put (op->contr); 191 freezer.put (ob->contr);
360 192
361 fprintf (freezer, "endplst\n"); 193 fprintf (freezer, "endplst\n");
362 194
363 SET_FLAG (op, FLAG_NO_FIX_PLAYER); 195 SET_FLAG (ob, FLAG_NO_FIX_PLAYER);
364 CLEAR_FLAG (op, FLAG_WIZ); 196 CLEAR_FLAG (ob, FLAG_WIZ);
365#ifdef BACKUP_SAVE_AT_HOME
366 if (flag)
367 {
368 backup_x = op->x;
369 backup_y = op->y;
370 op->x = -1;
371 op->y = -1;
372 }
373 /* Save objects, but not unpaid objects. Don't remove objects from
374 * inventory.
375 */
376 save_object (freezer, op, 2);
377 if (flag)
378 {
379 op->x = backup_x;
380 op->y = backup_y;
381 }
382#else
383 save_object (freezer, op, 3); /* don't check and don't remove */ 197 save_object (freezer, ob, 1); /* don't check and don't remove */
384#endif
385 198
386 char filename[MAX_BUF]; 199 char filename[MAX_BUF];
387 200
388 sprintf (filename, "%s/%s/%s/%s.pl", settings.localdir, settings.playerdir, &op->name, &op->name); 201 sprintf (filename, "%s/%s/%s/%s.pl", settings.localdir, settings.playerdir, &ob->name, &ob->name);
389 make_path_to_file (filename); 202 make_path_to_file (filename);
390 freezer.save (filename); 203 freezer.save (filename);
391 204
392 CLEAR_FLAG (op, FLAG_NO_FIX_PLAYER); 205 CLEAR_FLAG (ob, FLAG_NO_FIX_PLAYER);
393
394 if (!flag)
395 while ((tmp = op->inv))
396 destroy_object (tmp);
397 206
398 /* Eneq(@csd.uu.se): Reveal the container if we have one. */ 207 /* Eneq(@csd.uu.se): Reveal the container if we have one. */
399 if (flag && container != NULL)
400 op->container = container; 208 ob->container = container;
401 209
402 if (wiz) 210 ob->flag [FLAG_WIZ] = wiz;
403 SET_FLAG (op, FLAG_WIZ);
404 211
405 if (!flag) 212 enable_save = !final;
406 esrv_send_inventory (op, op);
407
408 return 1;
409} 213}
410 214
411void 215player *
412check_login (object *op) 216player::load (const char *path)
413{ 217{
414 char filename[MAX_BUF];
415 char buf[MAX_BUF], bufall[MAX_BUF];
416 int i, value;
417 player *pl = op->contr;
418 int correct = 0;
419
420 strcpy (pl->maplevel, first_map_path);
421 sprintf (filename, "%s/%s/%s/%s.pl", settings.localdir, settings.playerdir, &op->name, &op->name);
422
423 object_thawer thawer (filename); 218 object_thawer thawer (path);
424 219
425 /* If no file, must be a new player, so lets get confirmation of 220 /* If no file, must be a new player, so lets get confirmation of
426 * the password. Return control to the higher level dispatch, 221 * the password. Return control to the higher level dispatch,
427 * since the rest of this just deals with loading of the file. 222 * since the rest of this just deals with loading of the file.
428 */ 223 */
429 if (!thawer) 224 if (!thawer)
430 {
431 confirm_password (op);
432 return; 225 return 0;
433 }
434 226
435 if (fgets (bufall, MAX_BUF, thawer) != NULL) 227 player *pl = new player;
436 {
437 if (sscanf (bufall, "password %s\n", buf))
438 {
439 /* New password scheme: */
440 correct = check_password (pl->write_buf + 1, buf);
441 }
442 }
443 228
444 if (!correct) 229 char buf[MAX_BUF], bufall[MAX_BUF];
445 {
446 new_draw_info (NDI_UNIQUE, 0, op, " ");
447 new_draw_info (NDI_UNIQUE, 0, op, "Wrong Password!");
448 new_draw_info (NDI_UNIQUE, 0, op, " ");
449 op->name = op->name_pl = "noname";
450 op->contr->socket.password_fails++;
451 if (op->contr->socket.password_fails >= MAX_PASSWORD_FAILURES)
452 {
453 new_draw_info (NDI_UNIQUE, 0, op, "You gave an incorrect password too many times, you will now be dropped from the server.");
454 LOG (llevInfo, "A player connecting from %s has been dropped for password failure\n", op->contr->socket.host);
455 op->contr->socket.status = Ns_Dead; /* the socket loop should handle the rest for us */
456 }
457 else
458 get_name (op);
459 230
460 return; /* Once again, rest of code just loads the char */ 231 pl->set_object (object::create ());
461 }
462
463#ifdef SAVE_INTERVAL
464 pl->last_save_time = time (NULL); 232 pl->last_save_time = time (0);
465#endif /* SAVE_INTERVAL */ 233
466 pl->party = NULL;
467 if (settings.search_items == TRUE)
468 pl->search_str[0] = '\0';
469 pl->name_changed = 1;
470 pl->orig_stats.Str = 0;
471 pl->orig_stats.Dex = 0;
472 pl->orig_stats.Con = 0;
473 pl->orig_stats.Int = 0;
474 pl->orig_stats.Pow = 0;
475 pl->orig_stats.Wis = 0;
476 pl->orig_stats.Cha = 0;
477 strcpy (pl->savebed_map, first_map_path); 234 assign (pl->savebed_map, first_map_path);
478 pl->bed_x = 0, pl->bed_y = 0;
479 pl->spellparam[0] = '\0';
480 235
481 /* Loop through the file, loading the rest of the values */ 236 /* Loop through the file, loading the rest of the values */
482 while (fgets (bufall, MAX_BUF, thawer) != NULL) 237 while (fgets (bufall, MAX_BUF, thawer))
483 { 238 {
239 int value;
484 sscanf (bufall, "%s %d\n", buf, &value); 240 sscanf (bufall, "%s %d\n", buf, &value);
241
485 if (!strcmp (buf, "endplst")) 242 if (!strcmp (buf, "endplst"))
486 break; 243 break;
487 else if (!strcmp (buf, "oid")) 244 else if (!strcmp (buf, "oid"))
488 thawer.get (pl, value); 245 thawer.get (pl, value);
489 else if (!strcmp (buf, "title") && settings.set_title == TRUE) 246 else if (!strcmp (buf, "password"))
247 sscanf (bufall, "password %[^\n]", pl->password);
248 else if (!strcmp (buf, "title"))
490 sscanf (bufall, "title %[^\n]", pl->own_title); 249 sscanf (bufall, "title %[^\n]", pl->own_title);
491 else if (!strcmp (buf, "explore")) 250 else if (!strcmp (buf, "explore"))
492 pl->explore = value; 251 pl->explore = value;
493 else if (!strcmp (buf, "gen_hp")) 252 else if (!strcmp (buf, "gen_hp"))
494 pl->gen_hp = value; 253 pl->gen_hp = value;
504 pl->gen_grace = value; 263 pl->gen_grace = value;
505 else if (!strcmp (buf, "listening")) 264 else if (!strcmp (buf, "listening"))
506 pl->listening = value; 265 pl->listening = value;
507 else if (!strcmp (buf, "peaceful")) 266 else if (!strcmp (buf, "peaceful"))
508 pl->peaceful = value; 267 pl->peaceful = value;
509 else if (!strcmp (buf, "no_shout"))
510 pl->no_shout = value;
511 else if (!strcmp (buf, "digestion")) 268 else if (!strcmp (buf, "digestion"))
512 pl->digestion = value; 269 pl->digestion = value;
513 else if (!strcmp (buf, "pickup")) 270 else if (!strcmp (buf, "pickup"))
514 pl->mode = value; 271 pl->mode = value;
515 else if (!strcmp (buf, "outputs_sync")) 272 else if (!strcmp (buf, "outputs_sync"))
562 else 319 else
563 LOG (llevDebug, "load_player: got unknown unapply type: %s\n", bufall + 8); 320 LOG (llevDebug, "load_player: got unknown unapply type: %s\n", bufall + 8);
564 } 321 }
565 else if (!strcmp (buf, "lev_array")) 322 else if (!strcmp (buf, "lev_array"))
566 { 323 {
567 for (i = 1; i <= value; i++) 324 for (int i = 1; i <= value; i++)
568 { 325 {
569 char line[128]; 326 char line[128];
570 327
571 fgets (line, 128, thawer); 328 fgets (line, 128, thawer);
572 pl->levhp[i] = atoi (line); 329 pl->levhp[i] = atoi (line);
578 /* spell_array code removed - don't know when that was last used. 335 /* spell_array code removed - don't know when that was last used.
579 * Even the load code below will someday be replaced by spells being 336 * Even the load code below will someday be replaced by spells being
580 * objects. 337 * objects.
581 */ 338 */
582 } 339 }
583 else if (!strcmp (buf, "known_spell")) 340 else
584 { 341 LOG (llevDebug, "unparseable line in player file %s: %s\n", path, bufall);
585#if 0 342 }
586 /* Logic is left here in case someone wants to try
587 * and write code to update to spell objects.
588 */
589 char *cp = strchr (bufall, '\n');
590
591 *cp = '\0';
592 cp = strchr (bufall, ' ');
593 cp++;
594 for (i = 0; i < NROFREALSPELLS; i++)
595 if (!strcmp (spells[i].name, cp))
596 {
597 pl->known_spells[pl->nrofknownspells++] = i;
598 break;
599 }
600 if (i == NROFREALSPELLS)
601 LOG (llevDebug, "Error: unknown spell (%s)\n", cp);
602#endif
603 }
604 } /* End of loop loading the character file */
605
606 leave_map (op);
607 op->speed = 0;
608 update_ob_speed (op);
609
610 clear_object (op);
611
612 op->contr = pl;
613 pl->ob = op;
614 343
615 /* this loads the standard objects values. */ 344 /* this loads the standard objects values. */
616 load_object (thawer, op, 0); 345 load_object (thawer, pl->ob, 0);
617
618 CLEAR_FLAG (op, FLAG_NO_FIX_PLAYER);
619
620 assign (pl->title, op->arch->clone.name);
621 346
622 /* If the map where the person was last saved does not exist, 347 /* If the map where the person was last saved does not exist,
623 * restart them on their home-savebed. This is good for when 348 * restart them on their home-savebed. This is good for when
624 * maps change between versions 349 * maps change between versions
625 * First, we check for partial path, then check to see if the full 350 * First, we check for partial path, then check to see if the full
626 * path (for unique player maps) 351 * path (for unique player maps)
627 */ 352 */
353 if (!has_been_loaded (pl->maplevel)
628 if (check_path (pl->maplevel, 1) == -1) 354 && check_path (pl->maplevel, 1) == -1
629 {
630 if (check_path (pl->maplevel, 0) == -1) 355 && check_path (pl->maplevel, 0) == -1)
631 { 356 {
632 strcpy (pl->maplevel, pl->savebed_map); 357 strcpy (pl->maplevel, pl->savebed_map);
633 op->x = pl->bed_x, op->y = pl->bed_y; 358 pl->ob->x = pl->bed_x, pl->ob->y = pl->bed_y;
634 }
635 } 359 }
636 360
637 /* make sure he's a player--needed because of class change. */
638 op->type = PLAYER;
639
640 enter_exit (op, NULL);
641
642 pl->name_changed = 1;
643 pl->state = ST_PLAYING;
644#ifdef AUTOSAVE
645 pl->last_save_tick = pticks; 361 pl->last_save_tick = pticks;
646#endif
647 op->carrying = sum_weight (op);
648 /* Need to call fix_player now - program modified so that it is not
649 * called during the load process (FLAG_NO_FIX_PLAYER set when
650 * saved)
651 * Moved ahead of the esrv functions, so proper weights will be
652 * sent to the client.
653 */
654 link_player_skills (op);
655 362
656 if (!legal_range (op, op->contr->shoottype))
657 op->contr->shoottype = range_none;
658
659 fix_player (op);
660
661 /* if it's a dragon player, set the correct title here */
662 if (is_dragon_pl (op) && op->inv != NULL)
663 {
664 object *tmp, *abil = NULL, *skin = NULL;
665
666 for (tmp = op->inv; tmp != NULL; tmp = tmp->below)
667 {
668 if (tmp->type == FORCE)
669 {
670 if (strcmp (tmp->arch->name, "dragon_ability_force") == 0)
671 abil = tmp;
672 else if (strcmp (tmp->arch->name, "dragon_skin_force") == 0)
673 skin = tmp;
674 }
675 }
676 set_dragon_name (op, abil, skin);
677 }
678
679 new_draw_info (NDI_UNIQUE, 0, op, "Welcome Back!");
680 new_draw_info_format (NDI_UNIQUE | NDI_ALL | NDI_DK_ORANGE, 5, NULL, "%s has entered the game.", &pl->ob->name);
681
682 INVOKE_PLAYER (LOAD, pl, ARG_STRING (filename)); 363 INVOKE_PLAYER (LOAD, pl, ARG_STRING (path));
683 INVOKE_PLAYER (LOGIN, pl);
684 364
685 op->contr->socket.update_look = 1;
686 /* If the player should be dead, call kill_player for them
687 * Only check for hp - if player lacks food, let the normal
688 * logic for that to take place. If player is permanently
689 * dead, and not using permadeath mode, the kill_player will
690 * set the play_again flag, so return.
691 */
692 if (op->stats.hp < 0)
693 {
694 new_draw_info (NDI_UNIQUE, 0, op, "Your character was dead last your played.");
695 kill_player (op);
696 if (pl->state != ST_PLAYING)
697 return;
698 }
699 LOG (llevInfo, "LOGIN: Player named %s from ip %s\n", &op->name, op->contr->socket.host);
700
701 /* Do this after checking for death - no reason sucking up bandwidth if
702 * the data isn't needed.
703 */
704 esrv_new_player (op->contr, op->weight + op->carrying);
705 esrv_send_inventory (op, op);
706 esrv_add_spells (op->contr, NULL);
707
708 CLEAR_FLAG (op, FLAG_FRIENDLY);
709
710 /* can_use_shield is a new flag. However, the can_use.. seems to largely come
711 * from the class, and not race. I don't see any way to get the class information
712 * to then update this. I don't think this will actually break anything - anyone
713 * that can use armour should be able to use a shield. What this may 'break'
714 * are features new characters get, eg, if someone starts up with a Q, they
715 * should be able to use a shield. However, old Q's won't get that advantage.
716 */
717 if (QUERY_FLAG (op, FLAG_USE_ARMOUR))
718 SET_FLAG (op, FLAG_USE_SHIELD);
719
720 return; 365 return pl;
721} 366}
367

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines