1 | /* |
1 | /* |
2 | * static char *rcsid_login_c = |
2 | * static char *rcsid_login_c = |
3 | * "$Id: login.C,v 1.8 2006/08/30 16:30:37 root Exp $"; |
3 | * "$Id: login.C,v 1.9 2006/08/31 06:23:20 root Exp $"; |
4 | */ |
4 | */ |
5 | |
5 | |
6 | /* |
6 | /* |
7 | CrossFire, A Multiplayer game for X-windows |
7 | CrossFire, A Multiplayer game for X-windows |
8 | |
8 | |
… | |
… | |
223 | * will be saved at the emergency save location. |
223 | * will be saved at the emergency save location. |
224 | * Returns non zero if successful. |
224 | * Returns non zero if successful. |
225 | */ |
225 | */ |
226 | |
226 | |
227 | int save_player(object *op, int flag) { |
227 | int save_player(object *op, int flag) { |
228 | char filename[MAX_BUF]; |
|
|
229 | object *tmp, *container=NULL; |
228 | object *tmp, *container=NULL; |
230 | player *pl = op->contr; |
229 | player *pl = op->contr; |
231 | int i,wiz=QUERY_FLAG(op,FLAG_WIZ); |
230 | int i,wiz=QUERY_FLAG(op,FLAG_WIZ); |
232 | long checksum; |
231 | long checksum; |
233 | #ifdef BACKUP_SAVE_AT_HOME |
232 | #ifdef BACKUP_SAVE_AT_HOME |
… | |
… | |
253 | * mostly exited. |
252 | * mostly exited. |
254 | */ |
253 | */ |
255 | if (pl->state != ST_PLAYING && pl->state != ST_GET_PARTY_PASSWORD) |
254 | if (pl->state != ST_PLAYING && pl->state != ST_GET_PARTY_PASSWORD) |
256 | return 0; |
255 | return 0; |
257 | |
256 | |
258 | INVOKE_PLAYER (SAVE, op->contr, ARG_STRING (filename)); |
257 | INVOKE_PLAYER (SAVE, op->contr); |
259 | |
258 | |
260 | if (flag == 0) |
259 | if (flag == 0) |
261 | terminate_all_pets(op); |
260 | terminate_all_pets(op); |
262 | |
261 | |
263 | sprintf(filename,"%s/%s/%s/%s.pl",settings.localdir,settings.playerdir,op->name,op->name); |
|
|
264 | make_path_to_file(filename); |
|
|
265 | |
|
|
266 | object_freezer fp (filename); |
262 | object_freezer freezer; |
267 | |
263 | |
268 | if (!fp) |
264 | /* Eneq(@csd.uu.se): If we have an open container hide it. */ |
|
|
265 | if (op->container) |
269 | { |
266 | { |
270 | new_draw_info(NDI_UNIQUE, 0,op, "Can't open file for save."); |
|
|
271 | return 0; |
|
|
272 | } |
|
|
273 | |
|
|
274 | /* Eneq(@csd.uu.se): If we have an open container hide it. */ |
|
|
275 | if (op->container) |
|
|
276 | { |
|
|
277 | container = op->container; |
267 | container = op->container; |
278 | op->container = NULL; |
268 | op->container = NULL; |
279 | } |
269 | } |
280 | |
270 | |
281 | fprintf(fp,"password %s\n",pl->password); |
271 | fprintf(freezer,"password %s\n",pl->password); |
282 | |
272 | |
283 | if (settings.set_title == TRUE) |
273 | if (settings.set_title == TRUE) |
284 | if(pl->own_title[0]!='\0') |
274 | if(pl->own_title[0]!='\0') |
285 | fprintf(fp,"title %s\n",pl->own_title); |
275 | fprintf(freezer,"title %s\n",pl->own_title); |
286 | |
276 | |
287 | fprintf(fp,"explore %d\n",pl->explore); |
277 | fprintf(freezer,"explore %d\n",pl->explore); |
288 | fprintf(fp,"gen_hp %d\n",pl->gen_hp); |
278 | fprintf(freezer,"gen_hp %d\n",pl->gen_hp); |
289 | fprintf(fp,"gen_sp %d\n",pl->gen_sp); |
279 | fprintf(freezer,"gen_sp %d\n",pl->gen_sp); |
290 | fprintf(fp,"gen_grace %d\n",pl->gen_grace); |
280 | fprintf(freezer,"gen_grace %d\n",pl->gen_grace); |
291 | fprintf(fp,"listening %d\n",pl->listening); |
281 | fprintf(freezer,"listening %d\n",pl->listening); |
292 | fprintf(fp,"shoottype %d\n",pl->shoottype); |
282 | fprintf(freezer,"shoottype %d\n",pl->shoottype); |
293 | fprintf(fp,"bowtype %d\n",pl->bowtype); |
283 | fprintf(freezer,"bowtype %d\n",pl->bowtype); |
294 | fprintf(fp,"petmode %d\n",pl->petmode); |
284 | fprintf(freezer,"petmode %d\n",pl->petmode); |
295 | fprintf(fp,"peaceful %d\n",pl->peaceful); |
285 | fprintf(freezer,"peaceful %d\n",pl->peaceful); |
296 | fprintf(fp,"no_shout %d\n",pl->no_shout); |
286 | fprintf(freezer,"no_shout %d\n",pl->no_shout); |
297 | fprintf(fp,"digestion %d\n",pl->digestion); |
287 | fprintf(freezer,"digestion %d\n",pl->digestion); |
298 | fprintf(fp,"pickup %d\n", pl->mode); |
288 | fprintf(freezer,"pickup %d\n", pl->mode); |
299 | fprintf(fp,"outputs_sync %d\n", pl->outputs_sync); |
289 | fprintf(freezer,"outputs_sync %d\n", pl->outputs_sync); |
300 | fprintf(fp,"outputs_count %d\n", pl->outputs_count); |
290 | fprintf(freezer,"outputs_count %d\n", pl->outputs_count); |
301 | /* Match the enumerations but in string form */ |
291 | /* Match the enumerations but in string form */ |
302 | fprintf(fp,"usekeys %s\n", pl->usekeys==key_inventory?"key_inventory": |
292 | fprintf(freezer,"usekeys %s\n", pl->usekeys==key_inventory?"key_inventory": |
303 | (pl->usekeys==keyrings?"keyrings":"containers")); |
293 | (pl->usekeys==keyrings?"keyrings":"containers")); |
304 | /* Match the enumerations but in string form */ |
294 | /* Match the enumerations but in string form */ |
305 | fprintf(fp,"unapply %s\n", pl->unapply==unapply_nochoice?"unapply_nochoice": |
295 | fprintf(freezer,"unapply %s\n", pl->unapply==unapply_nochoice?"unapply_nochoice": |
306 | (pl->unapply==unapply_never?"unapply_never":"unapply_always")); |
296 | (pl->unapply==unapply_never?"unapply_never":"unapply_always")); |
307 | |
297 | |
308 | #ifdef BACKUP_SAVE_AT_HOME |
298 | #ifdef BACKUP_SAVE_AT_HOME |
309 | if (op->map!=NULL && flag==0) |
299 | if (op->map!=NULL && flag==0) |
310 | #else |
300 | #else |
311 | if (op->map!=NULL) |
301 | if (op->map!=NULL) |
312 | #endif |
302 | #endif |
313 | fprintf(fp,"map %s\n",op->map->path); |
303 | fprintf(freezer,"map %s\n",op->map->path); |
314 | else |
304 | else |
315 | fprintf(fp,"map %s\n",settings.emergency_mapname); |
305 | fprintf(freezer,"map %s\n",settings.emergency_mapname); |
316 | |
306 | |
317 | fprintf(fp,"savebed_map %s\n", pl->savebed_map); |
307 | fprintf(freezer,"savebed_map %s\n", pl->savebed_map); |
318 | fprintf(fp,"bed_x %d\nbed_y %d\n", pl->bed_x, pl->bed_y); |
308 | fprintf(freezer,"bed_x %d\nbed_y %d\n", pl->bed_x, pl->bed_y); |
319 | fprintf(fp,"weapon_sp %f\n",pl->weapon_sp); |
309 | fprintf(freezer,"weapon_sp %f\n",pl->weapon_sp); |
320 | fprintf(fp,"Str %d\n",pl->orig_stats.Str); |
310 | fprintf(freezer,"Str %d\n",pl->orig_stats.Str); |
321 | fprintf(fp,"Dex %d\n",pl->orig_stats.Dex); |
311 | fprintf(freezer,"Dex %d\n",pl->orig_stats.Dex); |
322 | fprintf(fp,"Con %d\n",pl->orig_stats.Con); |
312 | fprintf(freezer,"Con %d\n",pl->orig_stats.Con); |
323 | fprintf(fp,"Int %d\n",pl->orig_stats.Int); |
313 | fprintf(freezer,"Int %d\n",pl->orig_stats.Int); |
324 | fprintf(fp,"Pow %d\n",pl->orig_stats.Pow); |
314 | fprintf(freezer,"Pow %d\n",pl->orig_stats.Pow); |
325 | fprintf(fp,"Wis %d\n",pl->orig_stats.Wis); |
315 | fprintf(freezer,"Wis %d\n",pl->orig_stats.Wis); |
326 | fprintf(fp,"Cha %d\n",pl->orig_stats.Cha); |
316 | fprintf(freezer,"Cha %d\n",pl->orig_stats.Cha); |
327 | |
317 | |
328 | fprintf(fp,"lev_array %d\n",op->level>10?10:op->level); |
318 | fprintf(freezer,"lev_array %d\n",op->level>10?10:op->level); |
329 | for(i=1;i<=pl->last_level&&i<=10;i++) { |
319 | for(i=1;i<=pl->last_level&&i<=10;i++) { |
330 | fprintf(fp,"%d\n",pl->levhp[i]); |
320 | fprintf(freezer,"%d\n",pl->levhp[i]); |
331 | fprintf(fp,"%d\n",pl->levsp[i]); |
321 | fprintf(freezer,"%d\n",pl->levsp[i]); |
332 | fprintf(fp,"%d\n",pl->levgrace[i]); |
322 | fprintf(freezer,"%d\n",pl->levgrace[i]); |
333 | } |
323 | } |
334 | |
324 | |
335 | fp.put (op->contr); |
325 | freezer.put (op->contr); |
336 | |
326 | |
337 | fprintf(fp,"endplst\n"); |
327 | fprintf(freezer,"endplst\n"); |
338 | |
328 | |
339 | SET_FLAG(op, FLAG_NO_FIX_PLAYER); |
329 | SET_FLAG(op, FLAG_NO_FIX_PLAYER); |
340 | CLEAR_FLAG(op, FLAG_WIZ); |
330 | CLEAR_FLAG(op, FLAG_WIZ); |
341 | #ifdef BACKUP_SAVE_AT_HOME |
331 | #ifdef BACKUP_SAVE_AT_HOME |
342 | if (flag) { |
332 | if (flag) { |
… | |
… | |
346 | op->y = -1; |
336 | op->y = -1; |
347 | } |
337 | } |
348 | /* Save objects, but not unpaid objects. Don't remove objects from |
338 | /* Save objects, but not unpaid objects. Don't remove objects from |
349 | * inventory. |
339 | * inventory. |
350 | */ |
340 | */ |
351 | save_object(fp, op, 2); |
341 | save_object(freezer, op, 2); |
352 | if (flag) { |
342 | if (flag) { |
353 | op->x = backup_x; |
343 | op->x = backup_x; |
354 | op->y = backup_y; |
344 | op->y = backup_y; |
355 | } |
345 | } |
356 | #else |
346 | #else |
357 | save_object(fp, op, 3); /* don't check and don't remove */ |
347 | save_object(freezer, op, 3); /* don't check and don't remove */ |
358 | #endif |
348 | #endif |
|
|
349 | |
|
|
350 | char filename[MAX_BUF]; |
|
|
351 | sprintf(filename,"%s/%s/%s/%s.pl",settings.localdir,settings.playerdir,op->name,op->name); |
|
|
352 | make_path_to_file(filename); |
|
|
353 | freezer.save (filename); |
359 | |
354 | |
360 | CLEAR_FLAG(op, FLAG_NO_FIX_PLAYER); |
355 | CLEAR_FLAG(op, FLAG_NO_FIX_PLAYER); |
361 | |
356 | |
362 | if(!flag) |
357 | if(!flag) |
363 | while ((tmp = op->inv)) |
358 | while ((tmp = op->inv)) |
364 | destroy_object (tmp); |
359 | destroy_object (tmp); |
365 | |
360 | |
366 | /* Eneq(@csd.uu.se): Reveal the container if we have one. */ |
361 | /* Eneq(@csd.uu.se): Reveal the container if we have one. */ |
367 | if (flag&&container!=NULL) |
362 | if (flag && container!=NULL) |
368 | op->container = container; |
363 | op->container = container; |
369 | |
364 | |
370 | if (wiz) SET_FLAG(op,FLAG_WIZ); |
365 | if (wiz) SET_FLAG (op, FLAG_WIZ); |
371 | |
366 | |
372 | if(!flag) |
367 | if(!flag) |
373 | esrv_send_inventory(op, op); |
368 | esrv_send_inventory(op, op); |
374 | |
369 | |
375 | return 1; |
370 | return 1; |