… | |
… | |
20 | * <http://www.gnu.org/licenses/>. |
20 | * <http://www.gnu.org/licenses/>. |
21 | * |
21 | * |
22 | * The authors can be reached via e-mail to <support@deliantra.net> |
22 | * The authors can be reached via e-mail to <support@deliantra.net> |
23 | */ |
23 | */ |
24 | |
24 | |
|
|
25 | //+GPL |
|
|
26 | |
25 | /** |
27 | /** |
26 | * \file |
28 | * \file |
27 | * Client handling. |
29 | * Client handling. |
28 | * |
30 | * |
29 | * \date 2003-12-02 |
31 | * \date 2003-12-02 |
… | |
… | |
64 | * This table translates the attack numbers as used within the |
66 | * This table translates the attack numbers as used within the |
65 | * program to the value we use when sending STATS command to the |
67 | * program to the value we use when sending STATS command to the |
66 | * client. If a value is -1, then we don't send that to the |
68 | * client. If a value is -1, then we don't send that to the |
67 | * client. |
69 | * client. |
68 | */ |
70 | */ |
69 | short atnr_cs_stat[NROFATTACKS] = { CS_STAT_RES_PHYS, |
71 | static short atnr_cs_stat[NROFATTACKS] = { CS_STAT_RES_PHYS, |
70 | CS_STAT_RES_MAG, CS_STAT_RES_FIRE, CS_STAT_RES_ELEC, |
72 | CS_STAT_RES_MAG, CS_STAT_RES_FIRE, CS_STAT_RES_ELEC, |
71 | CS_STAT_RES_COLD, CS_STAT_RES_CONF, CS_STAT_RES_ACID, |
73 | CS_STAT_RES_COLD, CS_STAT_RES_CONF, CS_STAT_RES_ACID, |
72 | CS_STAT_RES_DRAIN, -1 /* weaponmagic */ , |
74 | CS_STAT_RES_DRAIN, -1 /* weaponmagic */ , |
73 | CS_STAT_RES_GHOSTHIT, CS_STAT_RES_POISON, |
75 | CS_STAT_RES_GHOSTHIT, CS_STAT_RES_POISON, |
74 | CS_STAT_RES_SLOW, CS_STAT_RES_PARA, CS_STAT_TURN_UNDEAD, |
76 | CS_STAT_RES_SLOW, CS_STAT_RES_PARA, CS_STAT_TURN_UNDEAD, |
… | |
… | |
218 | socket.current_x = ob->x; |
220 | socket.current_x = ob->x; |
219 | socket.current_y = ob->y; |
221 | socket.current_y = ob->y; |
220 | } |
222 | } |
221 | |
223 | |
222 | /** |
224 | /** |
|
|
225 | * This sends the skill number to name mapping. We ignore |
|
|
226 | * the params - we always send the same info no matter what. |
|
|
227 | */ |
|
|
228 | static void |
|
|
229 | send_skill_info (client *ns, char *params) |
|
|
230 | { |
|
|
231 | packet sl; |
|
|
232 | sl << "replyinfo skill_info\n"; |
|
|
233 | |
|
|
234 | for (int i = 1; i < NUM_SKILLS; i++) |
|
|
235 | sl.printf ("%d:%s\n", i + CS_STAT_SKILLINFO, &skill_names [i]); |
|
|
236 | |
|
|
237 | if (sl.length () > MAXSOCKBUF) |
|
|
238 | { |
|
|
239 | LOG (llevError, "Buffer overflow in send_skill_info!\n"); |
|
|
240 | fatal (0); |
|
|
241 | } |
|
|
242 | |
|
|
243 | ns->send_packet (sl); |
|
|
244 | } |
|
|
245 | |
|
|
246 | /** |
|
|
247 | * This sends the spell path to name mapping. We ignore |
|
|
248 | * the params - we always send the same info no matter what. |
|
|
249 | */ |
|
|
250 | static void |
|
|
251 | send_spell_paths (client * ns, char *params) |
|
|
252 | { |
|
|
253 | packet sl; |
|
|
254 | |
|
|
255 | sl << "replyinfo spell_paths\n"; |
|
|
256 | |
|
|
257 | for (int i = 0; i < NRSPELLPATHS; i++) |
|
|
258 | sl.printf ("%d:%s\n", 1 << i, spellpathnames[i]); |
|
|
259 | |
|
|
260 | if (sl.length () > MAXSOCKBUF) |
|
|
261 | { |
|
|
262 | LOG (llevError, "Buffer overflow in send_spell_paths!\n"); |
|
|
263 | fatal (0); |
|
|
264 | } |
|
|
265 | |
|
|
266 | ns->send_packet (sl); |
|
|
267 | } |
|
|
268 | |
|
|
269 | /** |
223 | * RequestInfo is sort of a meta command. There is some specific |
270 | * RequestInfo is sort of a meta command. There is some specific |
224 | * request of information, but we call other functions to provide |
271 | * request of information, but we call other functions to provide |
225 | * that information. |
272 | * that information. |
226 | */ |
273 | */ |
227 | void |
274 | void |
… | |
… | |
263 | ExtiCmd (char *buf, int len, client *ns) |
310 | ExtiCmd (char *buf, int len, client *ns) |
264 | { |
311 | { |
265 | INVOKE_CLIENT (EXTICMD, ns, ARG_DATA (buf, len)); |
312 | INVOKE_CLIENT (EXTICMD, ns, ARG_DATA (buf, len)); |
266 | } |
313 | } |
267 | |
314 | |
|
|
315 | //-GPL |
|
|
316 | |
268 | void |
317 | void |
269 | client::mapinfo_queue_clear () |
318 | client::mapinfo_queue_clear () |
270 | { |
319 | { |
271 | for (auto (i, mapinfo_queue.begin ()); i != mapinfo_queue.end (); ++i) |
320 | for (auto (i, mapinfo_queue.begin ()); i != mapinfo_queue.end (); ++i) |
272 | free (*i); |
321 | free (*i); |
… | |
… | |
396 | AddMeCmd (char *buf, int len, client *ns) |
445 | AddMeCmd (char *buf, int len, client *ns) |
397 | { |
446 | { |
398 | INVOKE_CLIENT (ADDME, ns, ARG_DATA (buf, len)); |
447 | INVOKE_CLIENT (ADDME, ns, ARG_DATA (buf, len)); |
399 | } |
448 | } |
400 | |
449 | |
|
|
450 | //+GPL |
|
|
451 | |
401 | /* |
452 | /* |
402 | #define MSG_TYPE_BOOK 1 |
453 | #define MSG_TYPE_BOOK 1 |
403 | #define MSG_TYPE_CARD 2 |
454 | #define MSG_TYPE_CARD 2 |
404 | #define MSG_TYPE_PAPER 3 |
455 | #define MSG_TYPE_PAPER 3 |
405 | #define MSG_TYPE_SIGN 4 |
456 | #define MSG_TYPE_SIGN 4 |
… | |
… | |
525 | * commands. |
576 | * commands. |
526 | */ |
577 | */ |
527 | pl->count = 0; |
578 | pl->count = 0; |
528 | |
579 | |
529 | //TODO: schmorp thinks whatever this calculates, it makes no sense at all |
580 | //TODO: schmorp thinks whatever this calculates, it makes no sense at all |
530 | int time = fabs (pl->ob->speed) < 0.001 |
581 | int time = pl->ob->has_active_speed () |
531 | ? time = MAX_TIME * 100 |
|
|
532 | : time = (int) (MAX_TIME / fabs (pl->ob->speed)); |
582 | ? (int) (MAX_TIME / pl->ob->speed) |
|
|
583 | : MAX_TIME * 100; |
533 | |
584 | |
534 | /* Send confirmation of command execution now */ |
585 | /* Send confirmation of command execution now */ |
535 | packet sl ("comc"); |
586 | packet sl ("comc"); |
536 | sl << uint16 (cmdid) << uint32 (time); |
587 | sl << uint16 (cmdid) << uint32 (time); |
537 | pl->ns->send_packet (sl); |
588 | pl->ns->send_packet (sl); |
… | |
… | |
787 | AddIfInt64 (ns->last_stats.exp, ob->stats.exp, CS_STAT_EXP64); |
838 | AddIfInt64 (ns->last_stats.exp, ob->stats.exp, CS_STAT_EXP64); |
788 | AddIfShort (ns->last_level, ob->level, CS_STAT_LEVEL); |
839 | AddIfShort (ns->last_level, ob->level, CS_STAT_LEVEL); |
789 | AddIfShort (ns->last_stats.wc, ob->stats.wc, CS_STAT_WC); |
840 | AddIfShort (ns->last_stats.wc, ob->stats.wc, CS_STAT_WC); |
790 | AddIfShort (ns->last_stats.ac, ob->stats.ac, CS_STAT_AC); |
841 | AddIfShort (ns->last_stats.ac, ob->stats.ac, CS_STAT_AC); |
791 | AddIfShort (ns->last_stats.dam, ob->stats.dam, CS_STAT_DAM); |
842 | AddIfShort (ns->last_stats.dam, ob->stats.dam, CS_STAT_DAM); |
792 | AddIfFloat (ns->last_speed, ob->speed, CS_STAT_SPEED, 1.f/TICK); |
843 | AddIfFloat (ns->last_speed, ob->speed, CS_STAT_SPEED, 1.f / TICK); |
793 | AddIfShort (ns->last_stats.food, ob->stats.food, CS_STAT_FOOD); |
844 | AddIfShort (ns->last_stats.food, ob->stats.food, CS_STAT_FOOD); |
794 | AddIfFloat (ns->last_weapon_sp, pl->weapon_sp, CS_STAT_WEAP_SP, 1.f/TICK); |
845 | AddIfFloat (ns->last_weapon_sp, pl->weapon_sp, CS_STAT_WEAP_SP, 1.f / TICK); |
795 | AddIfInt (ns->last_weight_limit, weight_limit[ob->stats.Str], CS_STAT_WEIGHT_LIM); |
846 | AddIfInt (ns->last_weight_limit, weight_limit[ob->stats.Str], CS_STAT_WEIGHT_LIM); |
796 | |
847 | |
797 | flags = 0; |
848 | flags = 0; |
798 | |
849 | |
799 | if (opl->fire_on) |
850 | if (opl->fire_on) |
… | |
… | |
802 | if (opl->run_on) |
853 | if (opl->run_on) |
803 | flags |= SF_RUNON; |
854 | flags |= SF_RUNON; |
804 | |
855 | |
805 | AddIfShort (ns->last_flags, flags, CS_STAT_FLAGS); |
856 | AddIfShort (ns->last_flags, flags, CS_STAT_FLAGS); |
806 | |
857 | |
807 | if (ns->sc_version < 1025) |
|
|
808 | { AddIfShort (ns->last_resist[ATNR_PHYSICAL], ob->resist[ATNR_PHYSICAL], CS_STAT_ARMOUR) } |
|
|
809 | else |
|
|
810 | for (int i = 0; i < NROFATTACKS; i++) |
858 | for (int i = 0; i < NROFATTACKS; i++) |
811 | { |
859 | { |
812 | /* Skip ones we won't send */ |
860 | /* Skip ones we won't send */ |
813 | if (atnr_cs_stat[i] == -1) |
861 | if (atnr_cs_stat[i] == -1) |
814 | continue; |
862 | continue; |
815 | |
863 | |
816 | AddIfShort (ns->last_resist[i], ob->resist[i], atnr_cs_stat[i]); |
864 | AddIfShort (ns->last_resist[i], ob->resist[i], atnr_cs_stat[i]); |
817 | } |
865 | } |
818 | |
866 | |
819 | if (pl->ns->monitor_spells) |
867 | if (pl->ns->monitor_spells) |
820 | { |
868 | { |
821 | AddIfInt (ns->last_path_attuned, ob->path_attuned, CS_STAT_SPELL_ATTUNE); |
869 | AddIfInt (ns->last_path_attuned, ob->path_attuned, CS_STAT_SPELL_ATTUNE); |
822 | AddIfInt (ns->last_path_repelled, ob->path_repelled, CS_STAT_SPELL_REPEL); |
870 | AddIfInt (ns->last_path_repelled, ob->path_repelled, CS_STAT_SPELL_REPEL); |
… | |
… | |
924 | |
972 | |
925 | /* Nothing changed */ |
973 | /* Nothing changed */ |
926 | return 0; |
974 | return 0; |
927 | } |
975 | } |
928 | |
976 | |
|
|
977 | //-GPL |
|
|
978 | |
929 | // prefetch (and touch) all maps within a specific distancd |
979 | // prefetch (and touch) all maps within a specific distancd |
930 | static void |
980 | static void |
931 | prefetch_surrounding_maps (maptile *map, int distance) |
981 | prefetch_surrounding_maps (maptile *map, int distance) |
932 | { |
982 | { |
933 | map->touch (); |
983 | map->touch (); |
… | |
… | |
945 | static void |
995 | static void |
946 | prefetch_surrounding_maps (object *op) |
996 | prefetch_surrounding_maps (object *op) |
947 | { |
997 | { |
948 | prefetch_surrounding_maps (op->map, 3); |
998 | prefetch_surrounding_maps (op->map, 3); |
949 | } |
999 | } |
|
|
1000 | |
|
|
1001 | //+GPL |
950 | |
1002 | |
951 | /** |
1003 | /** |
952 | * Draws client map. |
1004 | * Draws client map. |
953 | */ |
1005 | */ |
954 | void |
1006 | void |
… | |
… | |
1211 | socket.send_packet (sl); |
1263 | socket.send_packet (sl); |
1212 | socket.sent_scroll = 0; |
1264 | socket.sent_scroll = 0; |
1213 | } |
1265 | } |
1214 | } |
1266 | } |
1215 | |
1267 | |
1216 | /*****************************************************************************/ |
|
|
1217 | /* GROS: The following one is used to allow a plugin to send a generic cmd to*/ |
|
|
1218 | /* a player. Of course, the client need to know the command to be able to */ |
|
|
1219 | /* manage it ! */ |
|
|
1220 | /*****************************************************************************/ |
|
|
1221 | void |
|
|
1222 | send_plugin_custom_message (object *pl, char *buf) |
|
|
1223 | { |
|
|
1224 | pl->contr->ns->send_packet (buf); |
|
|
1225 | } |
|
|
1226 | |
|
|
1227 | /** |
|
|
1228 | * This sends the skill number to name mapping. We ignore |
|
|
1229 | * the params - we always send the same info no matter what. |
|
|
1230 | */ |
|
|
1231 | void |
|
|
1232 | send_skill_info (client *ns, char *params) |
|
|
1233 | { |
|
|
1234 | packet sl; |
|
|
1235 | sl << "replyinfo skill_info\n"; |
|
|
1236 | |
|
|
1237 | for (int i = 1; i < NUM_SKILLS; i++) |
|
|
1238 | sl.printf ("%d:%s\n", i + CS_STAT_SKILLINFO, &skill_names [i]); |
|
|
1239 | |
|
|
1240 | if (sl.length () > MAXSOCKBUF) |
|
|
1241 | { |
|
|
1242 | LOG (llevError, "Buffer overflow in send_skill_info!\n"); |
|
|
1243 | fatal (0); |
|
|
1244 | } |
|
|
1245 | |
|
|
1246 | ns->send_packet (sl); |
|
|
1247 | } |
|
|
1248 | |
|
|
1249 | /** |
|
|
1250 | * This sends the spell path to name mapping. We ignore |
|
|
1251 | * the params - we always send the same info no matter what. |
|
|
1252 | */ |
|
|
1253 | void |
|
|
1254 | send_spell_paths (client * ns, char *params) |
|
|
1255 | { |
|
|
1256 | packet sl; |
|
|
1257 | |
|
|
1258 | sl << "replyinfo spell_paths\n"; |
|
|
1259 | |
|
|
1260 | for (int i = 0; i < NRSPELLPATHS; i++) |
|
|
1261 | sl.printf ("%d:%s\n", 1 << i, spellpathnames[i]); |
|
|
1262 | |
|
|
1263 | if (sl.length () > MAXSOCKBUF) |
|
|
1264 | { |
|
|
1265 | LOG (llevError, "Buffer overflow in send_spell_paths!\n"); |
|
|
1266 | fatal (0); |
|
|
1267 | } |
|
|
1268 | |
|
|
1269 | ns->send_packet (sl); |
|
|
1270 | } |
|
|
1271 | |
|
|
1272 | /** |
1268 | /** |
1273 | * This looks for any spells the player may have that have changed their stats. |
1269 | * This looks for any spells the player may have that have changed their stats. |
1274 | * it then sends an updspell packet for each spell that has changed in this way |
1270 | * it then sends an updspell packet for each spell that has changed in this way |
1275 | */ |
1271 | */ |
1276 | void |
1272 | void |
1277 | esrv_update_spells (player *pl) |
1273 | esrv_update_spells (player *pl) |
1278 | { |
1274 | { |
1279 | if (!pl->ns) |
1275 | if (!pl->ns) |
1280 | return; |
1276 | return; |
|
|
1277 | |
|
|
1278 | pl->ns->update_spells = false; |
1281 | |
1279 | |
1282 | if (!pl->ns->monitor_spells) |
1280 | if (!pl->ns->monitor_spells) |
1283 | return; |
1281 | return; |
1284 | |
1282 | |
1285 | for (object *spell = pl->ob->inv; spell; spell = spell->below) |
1283 | for (object *spell = pl->ob->inv; spell; spell = spell->below) |
… | |
… | |
1456 | /* finally, we can send the packet */ |
1454 | /* finally, we can send the packet */ |
1457 | pl->ns->flush_fx (); |
1455 | pl->ns->flush_fx (); |
1458 | pl->ns->send_packet (sl); |
1456 | pl->ns->send_packet (sl); |
1459 | } |
1457 | } |
1460 | |
1458 | |
|
|
1459 | //-GPL |
|
|
1460 | |