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

Comparing deliantra/server/server/player.C (file contents):
Revision 1.88 by pippijn, Sat Jan 6 14:42:31 2007 UTC vs.
Revision 1.91 by root, Sun Jan 7 23:10:43 2007 UTC

1/* 1/*
2 CrossFire, A Multiplayer game for X-windows 2 * CrossFire, A Multiplayer game
3 3 *
4 Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team 4 * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team
5 Copyright (C) 2002 Mark Wedel & Crossfire Development Team 5 * Copyright (C) 2002 Mark Wedel & Crossfire Development Team
6 Copyright (C) 1992 Frank Tore Johansen 6 * Copyright (C) 1992 Frank Tore Johansen
7 7 *
8 This program is free software; you can redistribute it and/or modify 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 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 10 * the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version. 11 * (at your option) any later version.
12 12 *
13 This program is distributed in the hope that it will be useful, 13 * This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details. 16 * GNU General Public License for more details.
17 17 *
18 You should have received a copy of the GNU General Public License 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 19 * along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 21 *
22 The author can be reached via e-mail to <crossfire@schmorp.de> 22 * The author can be reached via e-mail to <crossfire@schmorp.de>
23*/ 23 */
24 24
25#include <global.h> 25#include <global.h>
26#include <pwd.h> 26#include <pwd.h>
27#include <sproto.h> 27#include <sproto.h>
28#include <sounds.h> 28#include <sounds.h>
32#include <skills.h> 32#include <skills.h>
33 33
34#include <algorithm> 34#include <algorithm>
35#include <functional> 35#include <functional>
36 36
37player * 37playervec players;
38find_player (const char *plname)
39{
40 for_all_players (pl)
41 if (pl->ob && !strcmp (query_name (pl->ob), plname))
42 return pl;
43
44 return 0;
45}
46 38
47void 39void
48display_motd (const object *op) 40display_motd (const object *op)
49{ 41{
50 char buf[MAX_BUF]; 42 char buf[MAX_BUF];
133 125
134 if (*buf == '%') 126 if (*buf == '%')
135 { /* send one news */ 127 { /* send one news */
136 if (size > 0) 128 if (size > 0)
137 draw_ext_info_format (NDI_UNIQUE | NDI_GREEN, 0, op, MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_NEWS, "INFORMATION: %s\n%s", "%s\n%s", subject, news); /*send previously read news */ 129 draw_ext_info_format (NDI_UNIQUE | NDI_GREEN, 0, op, MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_NEWS, "INFORMATION: %s\n%s", "%s\n%s", subject, news); /*send previously read news */
130
138 strcpy (subject, buf + 1); 131 strcpy (subject, buf + 1);
139 strip_endline (subject); 132 strip_endline (subject);
140 size = 0; 133 size = 0;
141 news[0] = '\0'; 134 news[0] = '\0';
142 } 135 }
177 ob->enter_exit (tmp); 170 ob->enter_exit (tmp);
178 171
179 tmp->destroy (); 172 tmp->destroy ();
180} 173}
181 174
175void
176player::activate ()
177{
178 if (active)
179 return;
180
181 players.insert (this);
182 ob->remove ();
183 ob->map = 0;
184 ob->activate_recursive ();
185 enter_map ();
186}
187
188void
189player::deactivate ()
190{
191 if (!active)
192 return;
193
194 terminate_all_pets (ob);
195 ob->deactivate_recursive ();
196 ob->remove ();
197 ob->map = 0;
198
199 players.erase (this);
200}
201
182// connect the player with a specific client 202// connect the player with a specific client
183// also changed, rationalises, and fixes some incorrect settings 203// also changed, rationalises, and fixes some incorrect settings
184void 204void
185player::connect (client *ns) 205player::connect (client *ns)
186{ 206{
187 this->ns = ns; 207 this->ns = ns;
188 ns->pl = this; 208 ns->pl = this;
189
190 next = first_player;
191 first_player = this;
192 209
193 ns->update_look = 0; 210 ns->update_look = 0;
194 ns->look_position = 0; 211 ns->look_position = 0;
195 212
196 clear_los (ob); 213 clear_los (ob);
238 } 255 }
239 256
240 CLEAR_FLAG (ob, FLAG_FRIENDLY); 257 CLEAR_FLAG (ob, FLAG_FRIENDLY);
241 add_friendly_object (ob); 258 add_friendly_object (ob);
242 259
243 LOG (llevInfo, "LOGIN: Player named %s from ip %s\n", &ob->name, ns->host);
244
245 new_draw_info (NDI_UNIQUE, 0, ob, "Welcome Back!"); 260 new_draw_info (NDI_UNIQUE, 0, ob, "Welcome Back!");
246 261
247 esrv_new_player (this, ob->weight + ob->carrying); 262 esrv_new_player (this, ob->weight + ob->carrying);
248 263
249 ob->update_stats (); 264 ob->update_stats ();
250 ns->floorbox_update (); 265 ns->floorbox_update ();
251 266
252 esrv_send_inventory (ob, ob); 267 esrv_send_inventory (ob, ob);
253 esrv_add_spells (this, 0); 268 esrv_add_spells (this, 0);
254 269
255 ob->activate_recursive (); 270 activate ();
256 enter_map ();
257 271
258 send_rules (ob); 272 send_rules (ob);
259 send_news (ob); 273 send_news (ob);
260 display_motd (ob); 274 display_motd (ob);
261 275
264} 278}
265 279
266void 280void
267player::disconnect () 281player::disconnect ()
268{ 282{
269 if (ob)
270 ob->deactivate_recursive ();
271
272 //TODO: don't be so harsh and destroy :)
273 if (ns) 283 if (ns)
274 { 284 {
275 if (enable_save) 285 if (active)
276 {
277 INVOKE_PLAYER (LOGOUT, this, ARG_INT (0)); 286 INVOKE_PLAYER (LOGOUT, this, ARG_INT (0));
278 save (true);
279 }
280 287
281 INVOKE_PLAYER (DISCONNECT, this); 288 INVOKE_PLAYER (DISCONNECT, this);
282 289
283 client *ns = this->ns;
284 ns->send_packet ("goodbye");
285 ns->flush ();
286 ns->pl = 0; 290 ns->pl = 0;
287 this->ns = 0; 291 this->ns = 0;
288
289 ns->destroy ();
290 destroy ();
291 } 292 }
293
294 deactivate ();
292} 295}
293 296
294// the need for this function can be explained 297// the need for this function can be explained
295// by load_object not returning the object 298// by load_object not returning the object
296void 299void
348void 351void
349player::do_destroy () 352player::do_destroy ()
350{ 353{
351 disconnect (); 354 disconnect ();
352 355
353 save (false);
354 enable_save = false;
355
356 attachable::do_destroy (); 356 attachable::do_destroy ();
357
358 terminate_all_pets (ob);
359
360 if (first_player != this)
361 {
362 player *prev = first_player;
363
364 while (prev && prev->next && prev->next != this)
365 prev = prev->next;
366
367 if (prev->next != this)
368 {
369 LOG (llevError, "Free_player: Can't find previous player.\n");
370 abort ();
371 }
372
373 prev->next = next;
374 }
375 else
376 first_player = next;
377 357
378 if (ob) 358 if (ob)
379 { 359 {
380 ob->destroy_inv (false); 360 ob->destroy_inv (false);
381 ob->destroy (); 361 ob->destroy ();
993 973
994 send_query (op->contr->ns, CS_QUERY_SINGLECHAR, "Press any key for the next race.\nPress `d' to play this race.\n"); 974 send_query (op->contr->ns, CS_QUERY_SINGLECHAR, "Press any key for the next race.\nPress `d' to play this race.\n");
995 return 0; 975 return 0;
996} 976}
997 977
998int
999key_confirm_quit (object *op, char key)
1000{
1001 if (key != 'y' && key != 'Y' && key != 'q' && key != 'Q')
1002 {
1003 op->contr->ns->state = ST_PLAYING;
1004 new_draw_info (NDI_UNIQUE, 0, op, "OK, continuing to play.");
1005 return 1;
1006 }
1007
1008 INVOKE_PLAYER (LOGOUT, op->contr);
1009 INVOKE_PLAYER (QUIT, op->contr);
1010
1011 op->contr->enable_save = false;
1012 delete_character (op->name);
1013
1014 terminate_all_pets (op);
1015 op->remove ();
1016 op->direction = 0;
1017 new_draw_info_format (NDI_UNIQUE | NDI_ALL, 5, NULL, "%s quits the game.", &op->name);
1018
1019 strcpy (op->contr->killer, "quit");
1020 check_score (op);
1021 op->contr->party = 0;
1022 op->contr->own_title[0] = '\0';
1023 op->contr->destroy ();
1024
1025 return 1;
1026}
1027
1028void 978void
1029flee_player (object *op) 979flee_player (object *op)
1030{ 980{
1031 int dir, diff; 981 int dir, diff;
1032 rv_vector rv; 982 rv_vector rv;
2775 2725
2776 command_kill_pets (op, 0); 2726 command_kill_pets (op, 0);
2777 2727
2778 if (op->stats.food < 0) 2728 if (op->stats.food < 0)
2779 { 2729 {
2780 if (op->contr->explore)
2781 {
2782 new_draw_info (NDI_UNIQUE, 0, op, "You would have starved, but you are");
2783 new_draw_info (NDI_UNIQUE, 0, op, "in explore mode, so...");
2784 op->stats.food = 999;
2785 return;
2786 }
2787 sprintf (buf, "%s starved to death.", &op->name); 2730 sprintf (buf, "%s starved to death.", &op->name);
2788 strcpy (op->contr->killer, "starvation"); 2731 strcpy (op->contr->killer, "starvation");
2789 } 2732 }
2790 else 2733 else
2791 {
2792 if (op->contr->explore)
2793 {
2794 new_draw_info (NDI_UNIQUE, 0, op, "You would have died, but you are");
2795 new_draw_info (NDI_UNIQUE, 0, op, "in explore mode, so...");
2796 op->stats.hp = op->stats.maxhp;
2797 return;
2798 }
2799 sprintf (buf, "%s died.", &op->name); 2734 sprintf (buf, "%s died.", &op->name);
2800 }
2801 2735
2802 play_sound_player_only (op->contr, SOUND_PLAYER_DIES, 0, 0); 2736 play_sound_player_only (op->contr, SOUND_PLAYER_DIES, 0, 0);
2803 2737
2804 /* save the map location for corpse, gravestone */ 2738 /* save the map location for corpse, gravestone */
2805 x = op->x; 2739 x = op->x;
2998 /* */ 2932 /* */
2999 /****************************************/ 2933 /****************************************/
3000 2934
3001 enter_player_savebed (op); 2935 enter_player_savebed (op);
3002 2936
3003 /* Save the player before inserting the force to reduce
3004 * chance of abuse.
3005 */
3006 op->contr->braced = 0; 2937 op->contr->braced = 0;
3007 op->contr->save ();
3008 2938
3009 /* it is possible that the player has blown something up 2939 /* it is possible that the player has blown something up
3010 * at his savebed location, and that can have long lasting 2940 * at his savebed location, and that can have long lasting
3011 * spell effects. So first see if there is a spell effect 2941 * spell effects. So first see if there is a spell effect
3012 * on the space that might harm the player. 2942 * on the space that might harm the player.

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines