ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/login.C
Revision: 1.3
Committed: Sun Aug 27 16:15:13 2006 UTC (17 years, 9 months ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.2: +14 -4 lines
Log Message:
first, untested persistent objetc storage for players and objects, not yte for maps

File Contents

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