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.51 by root, Thu Dec 21 06:12:37 2006 UTC vs.
Revision 1.53 by root, Fri Dec 22 16:03:21 2006 UTC

37player * 37player *
38find_player (const char *plname) 38find_player (const char *plname)
39{ 39{
40 player *pl; 40 player *pl;
41 41
42 for (pl = first_player; pl != NULL; pl = pl->next) 42 for (pl = first_player; pl; pl = pl->next)
43 { 43 {
44 if (pl->ob != NULL && !strcmp (query_name (pl->ob), plname)) 44 if (pl->obL && !strcmp (query_name (pl->ob), plname))
45 return pl; 45 return pl;
46 }; 46 };
47
47 return NULL; 48 return 0;
48} 49}
49 50
50player * 51player *
51find_player_partial_name (const char *plname) 52find_player_partial_name (const char *plname)
52{ 53{
53 player *pl; 54 player *pl;
54 player *found = NULL; 55 player *found = NULL;
55 size_t namelen = strlen (plname); 56 size_t namelen = strlen (plname);
56 57
57 for (pl = first_player; pl != NULL; pl = pl->next) 58 for (pl = first_player; pl; pl = pl->next)
58 { 59 {
59 if ((size_t) strlen (pl->ob->name) < namelen) 60 if ((size_t) strlen (pl->ob->name) < namelen)
60 continue; 61 continue;
61 62
62 if (!strcmp (pl->ob->name, plname)) 63 if (!strcmp (pl->ob->name, plname))
63 return pl; 64 return pl;
64 65
65 if (!strncasecmp (pl->ob->name, plname, namelen)) 66 if (!strncasecmp (pl->ob->name, plname, namelen))
66 { 67 {
67 if (found) 68 if (found)
68 return NULL; 69 return 0;
69 70
70 found = pl; 71 found = pl;
71 } 72 }
72 } 73 }
74
73 return found; 75 return found;
74} 76}
75 77
76void 78void
77display_motd (const object *op) 79display_motd (const object *op)
87 return; 89 return;
88 90
89 motd[0] = '\0'; 91 motd[0] = '\0';
90 size = 0; 92 size = 0;
91 93
92 while (fgets (buf, MAX_BUF, fp) != NULL) 94 while (fgets (buf, MAX_BUF, fp))
93 { 95 {
94 if (*buf == '#') 96 if (*buf == '#')
95 continue; 97 continue;
96 98
97 strncat (motd + size, buf, HUGE_BUF - size); 99 strncat (motd + size, buf, HUGE_BUF - size);
116 return; 118 return;
117 119
118 rules[0] = '\0'; 120 rules[0] = '\0';
119 size = 0; 121 size = 0;
120 122
121 while (fgets (buf, MAX_BUF, fp) != NULL) 123 while (fgets (buf, MAX_BUF, fp))
122 { 124 {
123 if (*buf == '#') 125 if (*buf == '#')
124 continue; 126 continue;
125 127
126 if (size + strlen (buf) >= HUGE_BUF) 128 if (size + strlen (buf) >= HUGE_BUF)
244 op->direction = 5; /* So player faces south */ 246 op->direction = 5; /* So player faces south */
245 op->stats.wc = 2; 247 op->stats.wc = 2;
246 op->run_away = 25; /* Then we panick... */ 248 op->run_away = 25; /* Then we panick... */
247 249
248 { 250 {
249 int oldmon = p->socket->monitor_spells; // what a hack 251 int oldmon = p->ns->monitor_spells; // what a hack
250 p->socket->monitor_spells = 0; /* Needed because esrv_update_spells( ) gets called by roll_stats */ 252 p->ns->monitor_spells = 0; /* Needed because esrv_update_spells( ) gets called by roll_stats */
251 roll_stats (op); 253 roll_stats (op);
252 p->socket->monitor_spells = oldmon; 254 p->ns->monitor_spells = oldmon;
253 } 255 }
254 p->state = ST_ROLL_STAT; 256 p->ns->state = ST_ROLL_STAT;
255 clear_los (op); 257 clear_los (op);
256 258
257 p->gen_sp_armour = 10; 259 p->gen_sp_armour = 10;
258 p->last_speed = -1; 260 p->last_speed = -1;
259 p->shoottype = range_none; 261 p->shoottype = range_none;
286 p->last_resist[i] = -1; 288 p->last_resist[i] = -1;
287 289
288 p->last_stats.exp = -1; 290 p->last_stats.exp = -1;
289 p->last_weight = (uint32) - 1; 291 p->last_weight = (uint32) - 1;
290 292
291 p->socket->update_look = 0; 293 p->ns->update_look = 0;
292 p->socket->look_position = 0; 294 p->ns->look_position = 0;
293 295
294 return p; 296 return p;
295} 297}
296 298
297/* This loads the first map an puts the player on it. */ 299/* This loads the first map an puts the player on it. */
312int 314int
313add_player (client *ns) 315add_player (client *ns)
314{ 316{
315 player *p = new player; 317 player *p = new player;
316 318
317 p->socket = ns; 319 p->ns = ns;
318 ns->pl = p; 320 ns->pl = p;
319 321
320 p->next = first_player; 322 p->next = first_player;
321 first_player = p; 323 first_player = p;
322 324
698 700
699void 701void
700get_name (object *op) 702get_name (object *op)
701{ 703{
702 op->contr->write_buf[0] = '\0'; 704 op->contr->write_buf[0] = '\0';
703 op->contr->state = ST_GET_NAME; 705 op->contr->ns->state = ST_GET_NAME;
704 send_query (op->contr->socket, 0, "What is your name?\n:"); 706 send_query (op->contr->ns, 0, "What is your name?\n:");
705} 707}
706 708
707void 709void
708get_password (object *op) 710get_password (object *op)
709{ 711{
710 op->contr->write_buf[0] = '\0'; 712 op->contr->write_buf[0] = '\0';
711 op->contr->state = ST_GET_PASSWORD; 713 op->contr->ns->state = ST_GET_PASSWORD;
712 send_query (op->contr->socket, CS_QUERY_HIDEINPUT, "What is your password?\n:"); 714 send_query (op->contr->ns, CS_QUERY_HIDEINPUT, "What is your password?\n:");
713} 715}
714 716
715void 717void
716play_again (object *op) 718play_again (object *op)
717{ 719{
718 op->contr->state = ST_PLAY_AGAIN; 720 op->contr->ns->state = ST_PLAY_AGAIN;
719 op->chosen_skill = NULL; 721 op->chosen_skill = NULL;
720 send_query (op->contr->socket, CS_QUERY_SINGLECHAR, "Do you want to play again (a/q)?"); 722 send_query (op->contr->ns, CS_QUERY_SINGLECHAR, "Do you want to play again (a/q)?");
721 /* a bit of a hack, but there are various places early in th 723 /* a bit of a hack, but there are various places early in th
722 * player creation process that a user can quit (eg, roll 724 * player creation process that a user can quit (eg, roll
723 * stats) that isn't removing the player. Taking a quick 725 * stats) that isn't removing the player. Taking a quick
724 * look, there are many places that call play_again without 726 * look, there are many places that call play_again without
725 * removing the player - it probably makes more sense 727 * removing the player - it probably makes more sense
774void 776void
775confirm_password (object *op) 777confirm_password (object *op)
776{ 778{
777 779
778 op->contr->write_buf[0] = '\0'; 780 op->contr->write_buf[0] = '\0';
779 op->contr->state = ST_CONFIRM_PASSWORD; 781 op->contr->ns->state = ST_CONFIRM_PASSWORD;
780 send_query (op->contr->socket, CS_QUERY_HIDEINPUT, "Please type your password again.\n:"); 782 send_query (op->contr->ns, CS_QUERY_HIDEINPUT, "Please type your password again.\n:");
781} 783}
782 784
783void 785void
784get_party_password (object *op, partylist *party) 786get_party_password (object *op, partylist *party)
785{ 787{
787 { 789 {
788 LOG (llevError, "get_party_password(): tried to make player %s join a NULL party", &op->name); 790 LOG (llevError, "get_party_password(): tried to make player %s join a NULL party", &op->name);
789 return; 791 return;
790 } 792 }
791 op->contr->write_buf[0] = '\0'; 793 op->contr->write_buf[0] = '\0';
792 op->contr->state = ST_GET_PARTY_PASSWORD; 794 op->contr->ns->state = ST_GET_PARTY_PASSWORD;
793 op->contr->party_to_join = party; 795 op->contr->party_to_join = party;
794 send_query (op->contr->socket, CS_QUERY_HIDEINPUT, "What is the password?\n:"); 796 send_query (op->contr->ns, CS_QUERY_HIDEINPUT, "What is the password?\n:");
795} 797}
796 798
797 799
798/* This rolls four 1-6 rolls and sums the best 3 of the 4. */ 800/* This rolls four 1-6 rolls and sums the best 3 of the 4. */
799int 801int
896 898
897void 899void
898Roll_Again (object *op) 900Roll_Again (object *op)
899{ 901{
900 esrv_new_player (op->contr, 0); 902 esrv_new_player (op->contr, 0);
901 send_query (op->contr->socket, CS_QUERY_SINGLECHAR, 903 send_query (op->contr->ns, CS_QUERY_SINGLECHAR,
902 "[y] to roll new stats [n] to use stats\n[1-7] [1-7] to swap stats.\nRoll again (y/n/1-7)? "); 904 "[y] to roll new stats [n] to use stats\n[1-7] [1-7] to swap stats.\nRoll again (y/n/1-7)? ");
903} 905}
904 906
905void 907void
906Swap_Stat (object *op, int Swap_Second) 908Swap_Stat (object *op, int Swap_Second)
973 new_draw_info (NDI_UNIQUE, 0, op, buf); 975 new_draw_info (NDI_UNIQUE, 0, op, buf);
974 } 976 }
975 else 977 else
976 Swap_Stat (op, stat_trans[keynum]); 978 Swap_Stat (op, stat_trans[keynum]);
977 979
978 send_query (op->contr->socket, CS_QUERY_SINGLECHAR, ""); 980 send_query (op->contr->ns, CS_QUERY_SINGLECHAR, "");
979 return 1; 981 return 1;
980 } 982 }
981 switch (key) 983 switch (key)
982 { 984 {
983 case 'n': 985 case 'n':
997 enter_exit (op, NULL); 999 enter_exit (op, NULL);
998#endif 1000#endif
999 SET_ANIMATION (op, 2); /* So player faces south */ 1001 SET_ANIMATION (op, 2); /* So player faces south */
1000 /* Enter exit adds a player otherwise */ 1002 /* Enter exit adds a player otherwise */
1001 add_statbonus (op); 1003 add_statbonus (op);
1002 send_query (op->contr->socket, CS_QUERY_SINGLECHAR, 1004 send_query (op->contr->ns, CS_QUERY_SINGLECHAR,
1003 "Now choose a character.\nPress any key to change outlook.\nPress `d' when you're pleased.\n"); 1005 "Now choose a character.\nPress any key to change outlook.\nPress `d' when you're pleased.\n");
1004 op->contr->state = ST_CHANGE_CLASS; 1006 op->contr->ns->state = ST_CHANGE_CLASS;
1005 if (op->msg) 1007 if (op->msg)
1006 new_draw_info (NDI_BLUE, 0, op, op->msg); 1008 new_draw_info (NDI_BLUE, 0, op, op->msg);
1007 return 0; 1009 return 0;
1008 } 1010 }
1009 case 'y': 1011 case 'y':
1010 case 'Y': 1012 case 'Y':
1011 roll_stats (op); 1013 roll_stats (op);
1012 send_query (op->contr->socket, CS_QUERY_SINGLECHAR, ""); 1014 send_query (op->contr->ns, CS_QUERY_SINGLECHAR, "");
1013 return 1; 1015 return 1;
1014 1016
1015 case 'q': 1017 case 'q':
1016 case 'Q': 1018 case 'Q':
1017 play_again (op); 1019 play_again (op);
1018 return 1; 1020 return 1;
1019 1021
1020 default: 1022 default:
1021 send_query (op->contr->socket, CS_QUERY_SINGLECHAR, "Yes, No, Quit or 1-6. Roll again?"); 1023 send_query (op->contr->ns, CS_QUERY_SINGLECHAR, "Yes, No, Quit or 1-6. Roll again?");
1022 return 0; 1024 return 0;
1023 } 1025 }
1024 return 0; 1026 return 0;
1025} 1027}
1026 1028
1054 create_treasure (tl, op, 0, 0, 0); 1056 create_treasure (tl, op, 0, 0, 0);
1055 1057
1056 INVOKE_PLAYER (BIRTH, op->contr); 1058 INVOKE_PLAYER (BIRTH, op->contr);
1057 INVOKE_PLAYER (LOGIN, op->contr); 1059 INVOKE_PLAYER (LOGIN, op->contr);
1058 1060
1059 op->contr->state = ST_PLAYING; 1061 op->contr->ns->state = ST_PLAYING;
1060 1062
1061 if (op->msg) 1063 if (op->msg)
1062 op->msg = NULL; 1064 op->msg = NULL;
1063 1065
1064 /* We create this now because some of the unique maps will need it 1066 /* We create this now because some of the unique maps will need it
1135 op->stats.grace = 0; 1137 op->stats.grace = 0;
1136 1138
1137 if (op->msg) 1139 if (op->msg)
1138 new_draw_info (NDI_BLUE, 0, op, op->msg); 1140 new_draw_info (NDI_BLUE, 0, op, op->msg);
1139 1141
1140 send_query (op->contr->socket, CS_QUERY_SINGLECHAR, "Press any key for the next race.\nPress `d' to play this race.\n"); 1142 send_query (op->contr->ns, CS_QUERY_SINGLECHAR, "Press any key for the next race.\nPress `d' to play this race.\n");
1141 return 0; 1143 return 0;
1142} 1144}
1143 1145
1144int 1146int
1145key_confirm_quit (object *op, char key) 1147key_confirm_quit (object *op, char key)
1146{ 1148{
1147 char buf[MAX_BUF]; 1149 char buf[MAX_BUF];
1148 1150
1149 if (key != 'y' && key != 'Y' && key != 'q' && key != 'Q') 1151 if (key != 'y' && key != 'Y' && key != 'q' && key != 'Q')
1150 { 1152 {
1151 op->contr->state = ST_PLAYING; 1153 op->contr->ns->state = ST_PLAYING;
1152 new_draw_info (NDI_UNIQUE, 0, op, "OK, continuing to play."); 1154 new_draw_info (NDI_UNIQUE, 0, op, "OK, continuing to play.");
1153 return 1; 1155 return 1;
1154 } 1156 }
1155 1157
1156 INVOKE_PLAYER (LOGOUT, op->contr); 1158 INVOKE_PLAYER (LOGOUT, op->contr);
2554 /* call this here - we also will call this in do_ericserver, but 2556 /* call this here - we also will call this in do_ericserver, but
2555 * the players time has been increased when doericserver has been 2557 * the players time has been increased when doericserver has been
2556 * called, so we recheck it here. 2558 * called, so we recheck it here.
2557 */ 2559 */
2558 //TODO: better than handling 8 commands, use some more intelligent rate-limiting 2560 //TODO: better than handling 8 commands, use some more intelligent rate-limiting
2559 for (int rep = 8; --rep && op->contr->socket->handle_command (); ) 2561 for (int rep = 8; --rep && op->contr->ns->handle_command (); )
2560 ; 2562 ;
2561 2563
2562 if (op->speed_left < 0) 2564 if (op->speed_left < 0)
2563 return 0; 2565 return 0;
2564 2566
2711 for (i = 0; i < NUM_OUTPUT_BUFS; i++) 2713 for (i = 0; i < NUM_OUTPUT_BUFS; i++)
2712 if (op->contr->outputs[i].buf != NULL && (op->contr->outputs[i].first_update + op->contr->outputs_sync) < (uint16) pticks) 2714 if (op->contr->outputs[i].buf != NULL && (op->contr->outputs[i].first_update + op->contr->outputs_sync) < (uint16) pticks)
2713 flush_output_element (op, &op->contr->outputs[i]); 2715 flush_output_element (op, &op->contr->outputs[i]);
2714 } 2716 }
2715 2717
2716 if (op->contr->state == ST_PLAYING) 2718 if (op->contr->ns->state == ST_PLAYING)
2717 { 2719 {
2718 2720
2719 /* these next three if clauses make it possible to SLOW DOWN 2721 /* these next three if clauses make it possible to SLOW DOWN
2720 hp/grace/spellpoint regeneration. */ 2722 hp/grace/spellpoint regeneration. */
2721 if (op->contr->gen_hp >= 0) 2723 if (op->contr->gen_hp >= 0)
2863 if (!QUERY_FLAG (op, FLAG_WIZ)) 2865 if (!QUERY_FLAG (op, FLAG_WIZ))
2864 op->stats.food--; 2866 op->stats.food--;
2865 } 2867 }
2866 } 2868 }
2867 2869
2868 if (op->contr->state == ST_PLAYING && op->stats.food < 0 && op->stats.hp >= 0) 2870 if (op->contr->ns->state == ST_PLAYING && op->stats.food < 0 && op->stats.hp >= 0)
2869 { 2871 {
2870 object *tmp, *flesh = NULL; 2872 object *tmp, *flesh = NULL;
2871 2873
2872 for (tmp = op->inv; tmp != NULL; tmp = tmp->below) 2874 for (tmp = op->inv; tmp != NULL; tmp = tmp->below)
2873 { 2875 {
2895 } /* end if player is starving */ 2897 } /* end if player is starving */
2896 2898
2897 while (op->stats.food < 0 && op->stats.hp > 0) 2899 while (op->stats.food < 0 && op->stats.hp > 0)
2898 op->stats.food++, op->stats.hp--; 2900 op->stats.food++, op->stats.hp--;
2899 2901
2900 if (!op->contr->state && !QUERY_FLAG (op, FLAG_WIZ) && (op->stats.hp < 0 || op->stats.food < 0)) 2902 if (!op->contr->ns->state && !QUERY_FLAG (op, FLAG_WIZ) && (op->stats.hp < 0 || op->stats.food < 0))
2901 kill_player (op); 2903 kill_player (op);
2902} 2904}
2903 2905
2904 2906
2905 2907
3384fix_luck (void) 3386fix_luck (void)
3385{ 3387{
3386 player *pl; 3388 player *pl;
3387 3389
3388 for (pl = first_player; pl != NULL; pl = pl->next) 3390 for (pl = first_player; pl != NULL; pl = pl->next)
3389 if (!pl->ob->contr->state) 3391 if (!pl->ob->contr->ns->state)
3390 change_luck (pl->ob, 0); 3392 change_luck (pl->ob, 0);
3391} 3393}
3392 3394
3393 3395
3394/* cast_dust() - handles op throwing objects of type 'DUST'. 3396/* cast_dust() - handles op throwing objects of type 'DUST'.
3636 3638
3637 /* only the viewable area the player sees is updated by LOS 3639 /* only the viewable area the player sees is updated by LOS
3638 * code, so we need to restrict ourselves to that range of values 3640 * code, so we need to restrict ourselves to that range of values
3639 * for any meaningful values. 3641 * for any meaningful values.
3640 */ 3642 */
3641 if (FABS (dx) <= (pl->contr->socket->mapx / 2) && 3643 if (FABS (dx) <= (pl->contr->ns->mapx / 2) &&
3642 FABS (dy) <= (pl->contr->socket->mapy / 2) && 3644 FABS (dy) <= (pl->contr->ns->mapy / 2) &&
3643 !pl->contr->blocked_los[dx + (pl->contr->socket->mapx / 2)][dy + (pl->contr->socket->mapy / 2)]) 3645 !pl->contr->blocked_los[dx + (pl->contr->ns->mapx / 2)][dy + (pl->contr->ns->mapy / 2)])
3644 return 1; 3646 return 1;
3645 op = op->more; 3647 op = op->more;
3646 } 3648 }
3647 return 0; 3649 return 0;
3648} 3650}
3834 { 3836 {
3835 /* forces in the treasurelist can alter the player's stats */ 3837 /* forces in the treasurelist can alter the player's stats */
3836 object *skin; 3838 object *skin;
3837 3839
3838 /* first get the dragon skin force */ 3840 /* first get the dragon skin force */
3841 shstr_cmp dragon_skin_force ("dragon_skin_force");
3839 for (skin = who->inv; skin != NULL && strcmp (skin->arch->name, "dragon_skin_force") != 0; skin = skin->below); 3842 for (skin = who->inv; skin && !(skin->arch->name == dragon_skin_force); skin = skin->below)
3843 ;
3844
3840 if (skin == NULL) 3845 if (!skin)
3841 return; 3846 return;
3842 3847
3843 /* adding new spellpath attunements */ 3848 /* adding new spellpath attunements */
3844 if (item->path_attuned > 0 && !(skin->path_attuned & item->path_attuned)) 3849 if (item->path_attuned > 0 && !(skin->path_attuned & item->path_attuned))
3845 { 3850 {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines