… | |
… | |
682 | */ |
682 | */ |
683 | static void |
683 | static void |
684 | SendSmooth (NewSocket * ns, uint16 face) |
684 | SendSmooth (NewSocket * ns, uint16 face) |
685 | { |
685 | { |
686 | uint16 smoothface; |
686 | uint16 smoothface; |
687 | unsigned char reply[MAX_BUF]; |
|
|
688 | SockList sl; |
|
|
689 | |
687 | |
690 | /* If we can't find a face, return and set it so we won't try to send this |
688 | /* If we can't find a face, return and set it so we won't try to send this |
691 | * again. |
689 | * again. |
692 | */ |
690 | */ |
693 | if ((!FindSmooth (face, &smoothface)) && (!FindSmooth (smooth_face->number, &smoothface))) |
691 | if ((!FindSmooth (face, &smoothface)) && (!FindSmooth (smooth_face->number, &smoothface))) |
… | |
… | |
701 | if (!(ns->faces_sent[smoothface] & NS_FACESENT_FACE)) |
699 | if (!(ns->faces_sent[smoothface] & NS_FACESENT_FACE)) |
702 | esrv_send_face (ns, smoothface, 0); |
700 | esrv_send_face (ns, smoothface, 0); |
703 | |
701 | |
704 | ns->faces_sent[face] |= NS_FACESENT_SMOOTH; |
702 | ns->faces_sent[face] |= NS_FACESENT_SMOOTH; |
705 | |
703 | |
706 | sl.buf = reply; |
704 | SockList sl (MAXSOCKBUF); |
707 | strcpy ((char *) sl.buf, "smooth "); |
705 | |
708 | sl.len = strlen ((char *) sl.buf); |
706 | sl << "smooth " |
709 | SockList_AddShort (&sl, face); |
707 | << uint16 (face) |
710 | SockList_AddShort (&sl, smoothface); |
708 | << uint16 (smoothface); |
|
|
709 | |
711 | Send_With_Handling (ns, &sl); |
710 | Send_With_Handling (ns, &sl); |
|
|
711 | sl.free (); |
712 | } |
712 | } |
713 | |
713 | |
714 | /** |
714 | /** |
715 | * Tells client the picture it has to use |
715 | * Tells client the picture it has to use |
716 | * to smooth a picture number given as argument. |
716 | * to smooth a picture number given as argument. |
… | |
… | |
722 | |
722 | |
723 | facenbr = atoi (buf); |
723 | facenbr = atoi (buf); |
724 | SendSmooth (ns, facenbr); |
724 | SendSmooth (ns, facenbr); |
725 | } |
725 | } |
726 | |
726 | |
727 | |
|
|
728 | |
|
|
729 | |
|
|
730 | |
|
|
731 | /** |
727 | /** |
732 | * This handles the general commands from the client (ie, north, fire, cast, |
728 | * This handles the general commands from the client (ie, north, fire, cast, |
733 | * etc.) |
729 | * etc.) |
734 | */ |
730 | */ |
735 | void |
731 | void |
… | |
… | |
788 | */ |
784 | */ |
789 | void |
785 | void |
790 | NewPlayerCmd (uint8 * buf, int len, player *pl) |
786 | NewPlayerCmd (uint8 * buf, int len, player *pl) |
791 | { |
787 | { |
792 | int time, repeat; |
788 | int time, repeat; |
|
|
789 | char command[MAX_BUF]; |
793 | short packet; |
790 | short packet; |
794 | unsigned char command[MAX_BUF]; |
|
|
795 | SockList sl; |
|
|
796 | |
791 | |
797 | if (len < 7) |
792 | if (len < 7) |
798 | { |
793 | { |
799 | LOG (llevDebug, "Corrupt ncom command <%s> not long enough - discarding\n", buf); |
794 | LOG (llevDebug, "Corrupt ncom command <%s> not long enough - discarding\n", buf); |
800 | return; |
795 | return; |
801 | } |
796 | } |
802 | |
797 | |
803 | packet = GetShort_String (buf); |
798 | packet = net_uint16 (buf); |
804 | repeat = GetInt_String (buf + 2); |
799 | repeat = net_uint32 (buf + 2); |
|
|
800 | |
805 | /* -1 is special - no repeat, but don't update */ |
801 | /* -1 is special - no repeat, but don't update */ |
806 | if (repeat != -1) |
802 | if (repeat != -1) |
807 | { |
|
|
808 | pl->count = repeat; |
803 | pl->count = repeat; |
809 | } |
804 | |
810 | if ((len - 4) >= MAX_BUF) |
805 | if ((len - 4) >= MAX_BUF) |
811 | len = MAX_BUF - 5; |
806 | len = MAX_BUF - 5; |
812 | |
807 | |
813 | strncpy ((char *) command, (char *) buf + 6, len - 4); |
808 | strncpy ((char *) command, (char *) buf + 6, len - 4); |
814 | command[len - 4] = '\0'; |
809 | command[len - 4] = '\0'; |
… | |
… | |
824 | return; |
819 | return; |
825 | } |
820 | } |
826 | |
821 | |
827 | /* This should not happen anymore. */ |
822 | /* This should not happen anymore. */ |
828 | if (pl->ob->speed_left < -1.0) |
823 | if (pl->ob->speed_left < -1.0) |
829 | { |
|
|
830 | LOG (llevError, "Player has negative time - shouldn't do command.\n"); |
824 | LOG (llevError, "Player has negative time - shouldn't do command.\n"); |
831 | } |
825 | |
832 | /* In c_new.c */ |
826 | /* In c_new.c */ |
833 | execute_newserver_command (pl->ob, (char *) command); |
827 | execute_newserver_command (pl->ob, (char *) command); |
834 | /* Perhaps something better should be done with a left over count. |
828 | /* Perhaps something better should be done with a left over count. |
835 | * Cleaning up the input should probably be done first - all actions |
829 | * Cleaning up the input should probably be done first - all actions |
836 | * for the command that issued the count should be done before any other |
830 | * for the command that issued the count should be done before any other |
837 | * commands. |
831 | * commands. |
838 | */ |
832 | */ |
839 | pl->count = 0; |
833 | pl->count = 0; |
840 | |
834 | |
841 | /* Send confirmation of command execution now */ |
|
|
842 | sl.buf = command; |
|
|
843 | strcpy ((char *) sl.buf, "comc "); |
|
|
844 | sl.len = 5; |
|
|
845 | SockList_AddShort (&sl, packet); |
|
|
846 | if (FABS (pl->ob->speed) < 0.001) |
835 | if (FABS (pl->ob->speed) < 0.001) |
847 | time = MAX_TIME * 100; |
836 | time = MAX_TIME * 100; |
848 | else |
837 | else |
849 | time = (int) (MAX_TIME / FABS (pl->ob->speed)); |
838 | time = (int) (MAX_TIME / FABS (pl->ob->speed)); |
850 | SockList_AddInt (&sl, time); |
839 | |
|
|
840 | /* Send confirmation of command execution now */ |
|
|
841 | |
|
|
842 | SockList sl (MAXSOCKBUF); |
|
|
843 | sl << "comc " << uint16 (packet) << uint32 (time); |
851 | Send_With_Handling (&pl->socket, &sl); |
844 | Send_With_Handling (&pl->socket, &sl); |
|
|
845 | sl.free (); |
852 | } |
846 | } |
853 | |
847 | |
854 | |
848 | |
855 | /** This is a reply to a previous query. */ |
849 | /** This is a reply to a previous query. */ |
856 | void |
850 | void |
… | |
… | |
968 | /* these are old dxclients */ |
962 | /* these are old dxclients */ |
969 | /* Version 1024 added support for singular + plural name values - |
963 | /* Version 1024 added support for singular + plural name values - |
970 | * requiing this minimal value reduces complexity of that code, and it |
964 | * requiing this minimal value reduces complexity of that code, and it |
971 | * has been around for a long time. |
965 | * has been around for a long time. |
972 | */ |
966 | */ |
973 | if (!strcmp (" CF DX CLIENT", cp) || ns->sc_version < 1024) |
967 | if (ns->sc_version < 1026) |
974 | { |
968 | { |
975 | sprintf (version_warning, "drawinfo %d %s", NDI_RED, |
969 | sprintf (version_warning, "drawinfo %d %s", NDI_RED, |
976 | "**** VERSION WARNING ****\n**** CLIENT IS TOO OLD!! UPDATE THE CLIENT!! ****"); |
970 | "**** VERSION WARNING ****\n**** CLIENT IS TOO OLD!! UPDATE THE CLIENT!! ****"); |
977 | Write_String_To_Socket (ns, version_warning, strlen (version_warning)); |
971 | Write_String_To_Socket (ns, version_warning, strlen (version_warning)); |
978 | } |
972 | } |
… | |
… | |
1059 | Write_String_To_Socket (ns, buf, strlen (buf)); |
1053 | Write_String_To_Socket (ns, buf, strlen (buf)); |
1060 | } |
1054 | } |
1061 | |
1055 | |
1062 | #define AddIfInt64(Old,New,Type) if (Old != New) {\ |
1056 | #define AddIfInt64(Old,New,Type) if (Old != New) {\ |
1063 | Old = New; \ |
1057 | Old = New; \ |
1064 | SockList_AddChar(&sl, Type); \ |
1058 | sl << uint8 (Type) << uint64 (New); \ |
1065 | SockList_AddInt64(&sl, New); \ |
|
|
1066 | } |
1059 | } |
1067 | |
1060 | |
1068 | #define AddIfInt(Old,New,Type) if (Old != New) {\ |
1061 | #define AddIfInt(Old,New,Type) if (Old != New) {\ |
1069 | Old = New; \ |
1062 | Old = New; \ |
1070 | SockList_AddChar(&sl, Type); \ |
1063 | sl << uint8 (Type) << uint32 (New); \ |
1071 | SockList_AddInt(&sl, New); \ |
|
|
1072 | } |
1064 | } |
1073 | |
1065 | |
1074 | #define AddIfShort(Old,New,Type) if (Old != New) {\ |
1066 | #define AddIfShort(Old,New,Type) if (Old != New) {\ |
1075 | Old = New; \ |
1067 | Old = New; \ |
1076 | SockList_AddChar(&sl, Type); \ |
1068 | sl << uint8 (Type) << uint16 (New); \ |
1077 | SockList_AddShort(&sl, New); \ |
|
|
1078 | } |
1069 | } |
1079 | |
1070 | |
1080 | #define AddIfFloat(Old,New,Type) if (Old != New) {\ |
1071 | #define AddIfFloat(Old,New,Type) if (Old != New) {\ |
1081 | Old = New; \ |
1072 | Old = New; \ |
1082 | SockList_AddChar(&sl, Type); \ |
1073 | sl << uint8 (Type) << uint32 (New*FLOAT_MULTI); \ |
1083 | SockList_AddInt(&sl,(long)(New*FLOAT_MULTI));\ |
|
|
1084 | } |
1074 | } |
1085 | |
1075 | |
1086 | #define AddIfString(Old,New,Type) if (Old == NULL || strcmp(Old,New)) {\ |
1076 | #define AddIfString(Old,New,Type) if (Old == NULL || strcmp(Old,New)) {\ |
1087 | if (Old) free(Old);\ |
|
|
1088 | Old = strdup_local(New);\ |
1077 | free(Old); Old = strdup (New);\ |
1089 | SockList_AddChar(&sl, Type); \ |
1078 | sl << uint8 (Type) << data8 (New); \ |
1090 | SockList_AddChar(&sl, ( char )strlen(New)); \ |
|
|
1091 | strcpy((char*)sl.buf + sl.len, New); \ |
|
|
1092 | sl.len += strlen(New); \ |
|
|
1093 | } |
1079 | } |
1094 | |
1080 | |
1095 | /** |
1081 | /** |
1096 | * Sends a statistics update. We look at the old values, |
1082 | * Sends a statistics update. We look at the old values, |
1097 | * and only send what has changed. Stat mapping values are in newclient.h |
1083 | * and only send what has changed. Stat mapping values are in newclient.h |
… | |
… | |
1099 | * commands for now. |
1085 | * commands for now. |
1100 | */ |
1086 | */ |
1101 | void |
1087 | void |
1102 | esrv_update_stats (player *pl) |
1088 | esrv_update_stats (player *pl) |
1103 | { |
1089 | { |
1104 | SockList sl; |
|
|
1105 | char buf[MAX_BUF]; |
1090 | char buf[MAX_BUF]; |
1106 | uint16 flags; |
1091 | uint16 flags; |
1107 | |
1092 | |
1108 | sl.buf = (unsigned char *) malloc (MAXSOCKBUF); |
1093 | SockList sl (MAXSOCKBUF); |
1109 | strcpy ((char *) sl.buf, "stats "); |
1094 | sl << "stats "; |
1110 | sl.len = strlen ((char *) sl.buf); |
|
|
1111 | |
1095 | |
1112 | if (pl->ob != NULL) |
1096 | if (pl->ob != NULL) |
1113 | { |
1097 | { |
1114 | AddIfShort (pl->last_stats.hp, pl->ob->stats.hp, CS_STAT_HP); |
1098 | AddIfShort (pl->last_stats.hp, pl->ob->stats.hp, CS_STAT_HP); |
1115 | AddIfShort (pl->last_stats.maxhp, pl->ob->stats.maxhp, CS_STAT_MAXHP); |
1099 | AddIfShort (pl->last_stats.maxhp, pl->ob->stats.maxhp, CS_STAT_MAXHP); |
… | |
… | |
1132 | |
1116 | |
1133 | for (s = 0; s < NUM_SKILLS; s++) |
1117 | for (s = 0; s < NUM_SKILLS; s++) |
1134 | { |
1118 | { |
1135 | if (pl->last_skill_ob[s] && pl->last_skill_exp[s] != pl->last_skill_ob[s]->stats.exp) |
1119 | if (pl->last_skill_ob[s] && pl->last_skill_exp[s] != pl->last_skill_ob[s]->stats.exp) |
1136 | { |
1120 | { |
1137 | |
|
|
1138 | /* Always send along the level if exp changes. This is only |
1121 | /* Always send along the level if exp changes. This is only |
1139 | * 1 extra byte, but keeps processing simpler. |
1122 | * 1 extra byte, but keeps processing simpler. |
1140 | */ |
1123 | */ |
1141 | SockList_AddChar (&sl, (char) (s + CS_STAT_SKILLINFO)); |
1124 | sl << uint8 (s + CS_STAT_SKILLINFO) |
1142 | SockList_AddChar (&sl, (char) pl->last_skill_ob[s]->level); |
1125 | << uint8 (pl->last_skill_ob[s]->level) |
1143 | SockList_AddInt64 (&sl, pl->last_skill_ob[s]->stats.exp); |
1126 | << uint64 (pl->last_skill_ob[s]->stats.exp); |
|
|
1127 | |
1144 | pl->last_skill_exp[s] = pl->last_skill_ob[s]->stats.exp; |
1128 | pl->last_skill_exp[s] = pl->last_skill_ob[s]->stats.exp; |
1145 | } |
1129 | } |
1146 | } |
1130 | } |
1147 | } |
1131 | } |
1148 | |
1132 | |
… | |
… | |
1204 | LOG (llevDebug, "Sending stats command, %d bytes long.\n", sl.len); |
1188 | LOG (llevDebug, "Sending stats command, %d bytes long.\n", sl.len); |
1205 | #endif |
1189 | #endif |
1206 | Send_With_Handling (&pl->socket, &sl); |
1190 | Send_With_Handling (&pl->socket, &sl); |
1207 | } |
1191 | } |
1208 | |
1192 | |
1209 | free (sl.buf); |
1193 | sl.free (); |
1210 | } |
1194 | } |
1211 | |
1195 | |
1212 | /** |
1196 | /** |
1213 | * Tells the client that here is a player it should start using. |
1197 | * Tells the client that here is a player it should start using. |
1214 | */ |
1198 | */ |
1215 | void |
1199 | void |
1216 | esrv_new_player (player *pl, uint32 weight) |
1200 | esrv_new_player (player *pl, uint32 weight) |
1217 | { |
1201 | { |
1218 | SockList sl; |
|
|
1219 | |
|
|
1220 | pl->last_weight = weight; |
1202 | pl->last_weight = weight; |
1221 | |
1203 | |
1222 | sl.buf = (unsigned char *) malloc (MAXSOCKBUF); |
1204 | SockList sl (MAXSOCKBUF); |
|
|
1205 | sl << "player "; |
1223 | |
1206 | |
1224 | strcpy ((char *) sl.buf, "player "); |
1207 | sl << uint32 (pl->ob->count) |
1225 | sl.len = strlen ((char *) sl.buf); |
1208 | << uint32 (weight) |
1226 | SockList_AddInt (&sl, pl->ob->count); |
1209 | << uint32 (pl->ob->face->number) |
1227 | SockList_AddInt (&sl, weight); |
1210 | << data8 (pl->ob->name); |
1228 | SockList_AddInt (&sl, pl->ob->face->number); |
|
|
1229 | |
|
|
1230 | SockList_AddChar (&sl, (char) strlen (pl->ob->name)); |
|
|
1231 | strcpy ((char *) sl.buf + sl.len, pl->ob->name); |
|
|
1232 | sl.len += strlen (pl->ob->name); |
|
|
1233 | |
1211 | |
1234 | Send_With_Handling (&pl->socket, &sl); |
1212 | Send_With_Handling (&pl->socket, &sl); |
1235 | free (sl.buf); |
1213 | sl.free (); |
1236 | SET_FLAG (pl->ob, FLAG_CLIENT_SENT); |
1214 | SET_FLAG (pl->ob, FLAG_CLIENT_SENT); |
1237 | } |
1215 | } |
1238 | |
1216 | |
1239 | /** |
1217 | /** |
1240 | * Need to send an animation sequence to the client. |
1218 | * Need to send an animation sequence to the client. |
… | |
… | |
1244 | * when the player logs in and picks stuff up. |
1222 | * when the player logs in and picks stuff up. |
1245 | */ |
1223 | */ |
1246 | void |
1224 | void |
1247 | esrv_send_animation (NewSocket * ns, short anim_num) |
1225 | esrv_send_animation (NewSocket * ns, short anim_num) |
1248 | { |
1226 | { |
1249 | SockList sl; |
|
|
1250 | int i; |
1227 | int i; |
1251 | |
1228 | |
1252 | /* Do some checking on the anim_num we got. Note that the animations |
1229 | /* Do some checking on the anim_num we got. Note that the animations |
1253 | * are added in contigous order, so if the number is in the valid |
1230 | * are added in contigous order, so if the number is in the valid |
1254 | * range, it must be a valid animation. |
1231 | * range, it must be a valid animation. |
… | |
… | |
1257 | { |
1234 | { |
1258 | LOG (llevError, "esrv_send_anim (%d) out of bounds??\n", anim_num); |
1235 | LOG (llevError, "esrv_send_anim (%d) out of bounds??\n", anim_num); |
1259 | return; |
1236 | return; |
1260 | } |
1237 | } |
1261 | |
1238 | |
1262 | sl.buf = (unsigned char *) malloc (MAXSOCKBUF); |
1239 | SockList sl (MAXSOCKBUF); |
1263 | strcpy ((char *) sl.buf, "anim "); |
1240 | |
1264 | sl.len = 5; |
1241 | sl << "anim " |
1265 | SockList_AddShort (&sl, anim_num); |
1242 | << uint16 (anim_num) |
1266 | SockList_AddShort (&sl, 0); /* flags - not used right now */ |
1243 | << uint16 (0); /* flags - not used right now */ |
|
|
1244 | |
1267 | /* Build up the list of faces. Also, send any information (ie, the |
1245 | /* Build up the list of faces. Also, send any information (ie, the |
1268 | * the face itself) down to the client. |
1246 | * the face itself) down to the client. |
1269 | */ |
1247 | */ |
1270 | for (i = 0; i < animations[anim_num].num_animations; i++) |
1248 | for (i = 0; i < animations[anim_num].num_animations; i++) |
1271 | { |
1249 | { |
1272 | if (!(ns->faces_sent[animations[anim_num].faces[i]] & NS_FACESENT_FACE)) |
1250 | if (!(ns->faces_sent[animations[anim_num].faces[i]] & NS_FACESENT_FACE)) |
1273 | esrv_send_face (ns, animations[anim_num].faces[i], 0); |
1251 | esrv_send_face (ns, animations[anim_num].faces[i], 0); |
1274 | SockList_AddShort (&sl, animations[anim_num].faces[i]); /* flags - not used right now */ |
1252 | sl << uint16 (animations[anim_num].faces[i]); /* flags - not used right now */ |
1275 | } |
1253 | } |
|
|
1254 | |
1276 | Send_With_Handling (ns, &sl); |
1255 | Send_With_Handling (ns, &sl); |
1277 | free (sl.buf); |
1256 | sl.free (); |
|
|
1257 | |
1278 | ns->anims_sent[anim_num] = 1; |
1258 | ns->anims_sent[anim_num] = 1; |
1279 | } |
1259 | } |
1280 | |
1260 | |
1281 | |
1261 | |
1282 | /****************************************************************************** |
1262 | /****************************************************************************** |
… | |
… | |
1296 | { |
1276 | { |
1297 | LOG (llevError, "Too many faces in map cell %d %d\n", x, y); |
1277 | LOG (llevError, "Too many faces in map cell %d %d\n", x, y); |
1298 | return; |
1278 | return; |
1299 | abort (); |
1279 | abort (); |
1300 | } |
1280 | } |
|
|
1281 | |
1301 | newmap->cells[x][y].faces[newmap->cells[x][y].count] = face_num; |
1282 | newmap->cells[x][y].faces[newmap->cells[x][y].count] = face_num; |
1302 | newmap->cells[x][y].count++; |
1283 | newmap->cells[x][y].count++; |
|
|
1284 | |
1303 | if (!(ns->faces_sent[face_num] & NS_FACESENT_FACE)) |
1285 | if (!(ns->faces_sent[face_num] & NS_FACESENT_FACE)) |
1304 | esrv_send_face (ns, face_num, 0); |
1286 | esrv_send_face (ns, face_num, 0); |
1305 | } |
1287 | } |
1306 | |
1288 | |
1307 | struct LayerCell |
1289 | struct LayerCell |
… | |
… | |
1414 | static void |
1396 | static void |
1415 | esrv_map_doneredraw (NewSocket * ns, struct Map *newmap) |
1397 | esrv_map_doneredraw (NewSocket * ns, struct Map *newmap) |
1416 | { |
1398 | { |
1417 | static long frames, bytes, tbytes, tframes; |
1399 | static long frames, bytes, tbytes, tframes; |
1418 | char *cur; |
1400 | char *cur; |
1419 | SockList sl; |
|
|
1420 | |
1401 | |
1421 | |
1402 | SockList sl (MAXSOCKBUF); |
1422 | sl.buf = (unsigned char *) malloc (MAXSOCKBUF); |
1403 | sl << "map "; |
1423 | strcpy ((char *) sl.buf, "map "); |
|
|
1424 | sl.len = strlen ((char *) sl.buf); |
|
|
1425 | |
1404 | |
1426 | cur = (char *) compactlayer (ns, (unsigned char *) sl.buf + sl.len, MAP_LAYERS, newmap); |
1405 | cur = (char *) compactlayer (ns, (unsigned char *) sl.buf + sl.len, MAP_LAYERS, newmap); |
1427 | sl.len = cur - (char *) sl.buf; |
1406 | sl.len = cur - (char *) sl.buf; |
1428 | |
1407 | |
1429 | /* LOG(llevDebug, "Sending map command.\n");*/ |
1408 | /* LOG(llevDebug, "Sending map command.\n");*/ |
… | |
… | |
1441 | memcpy (&ns->lastmap, newmap, sizeof (struct Map)); |
1420 | memcpy (&ns->lastmap, newmap, sizeof (struct Map)); |
1442 | Send_With_Handling (ns, &sl); |
1421 | Send_With_Handling (ns, &sl); |
1443 | ns->sent_scroll = 0; |
1422 | ns->sent_scroll = 0; |
1444 | } |
1423 | } |
1445 | |
1424 | |
1446 | free (sl.buf); |
1425 | sl.free (); |
1447 | } |
1426 | } |
1448 | |
1427 | |
1449 | |
1428 | |
1450 | /** Clears a map cell */ |
1429 | /** Clears a map cell */ |
1451 | static void |
1430 | static void |
… | |
… | |
1493 | * needs to get sent - if so, it adds the data, sending the head |
1472 | * needs to get sent - if so, it adds the data, sending the head |
1494 | * if needed, and returning 1. If this no data needs to get |
1473 | * if needed, and returning 1. If this no data needs to get |
1495 | * sent, it returns zero. |
1474 | * sent, it returns zero. |
1496 | */ |
1475 | */ |
1497 | static int |
1476 | static int |
1498 | check_head (SockList & sl, NewSocket & ns, int ax, int ay, int layer) |
1477 | check_head (SockList &sl, NewSocket &ns, int ax, int ay, int layer) |
1499 | { |
1478 | { |
1500 | short face_num; |
1479 | short face_num; |
1501 | |
1480 | |
1502 | if (heads[(ay * MAX_HEAD_POS + ax) * MAX_LAYERS + layer]) |
1481 | if (heads[(ay * MAX_HEAD_POS + ax) * MAX_LAYERS + layer]) |
1503 | face_num = heads[(ay * MAX_HEAD_POS + ax) * MAX_LAYERS + layer]->face->number; |
1482 | face_num = heads[(ay * MAX_HEAD_POS + ax) * MAX_LAYERS + layer]->face->number; |
1504 | else |
1483 | else |
1505 | face_num = 0; |
1484 | face_num = 0; |
1506 | |
1485 | |
1507 | if (face_num != ns.lastmap.cells[ax][ay].faces[layer]) |
1486 | if (face_num != ns.lastmap.cells[ax][ay].faces[layer]) |
1508 | { |
1487 | { |
1509 | SockList_AddShort (&sl, face_num); |
1488 | sl << uint16 (face_num); |
1510 | if (face_num && !(ns.faces_sent[face_num] & NS_FACESENT_FACE)) |
1489 | if (face_num && !(ns.faces_sent[face_num] & NS_FACESENT_FACE)) |
1511 | esrv_send_face (&ns, face_num, 0); |
1490 | esrv_send_face (&ns, face_num, 0); |
|
|
1491 | |
1512 | heads[(ay * MAX_HEAD_POS + ax) * MAX_LAYERS + layer] = NULL; |
1492 | heads[(ay * MAX_HEAD_POS + ax) * MAX_LAYERS + layer] = NULL; |
1513 | ns.lastmap.cells[ax][ay].faces[layer] = face_num; |
1493 | ns.lastmap.cells[ax][ay].faces[layer] = face_num; |
1514 | return 1; |
1494 | return 1; |
1515 | } |
1495 | } |
1516 | |
1496 | |
… | |
… | |
1536 | * the case, it seems to make more sense to have these layer values |
1516 | * the case, it seems to make more sense to have these layer values |
1537 | * actually match. |
1517 | * actually match. |
1538 | */ |
1518 | */ |
1539 | |
1519 | |
1540 | static int |
1520 | static int |
1541 | update_space (SockList * sl, NewSocket * ns, maptile *mp, int mx, int my, int sx, int sy, int layer) |
1521 | update_space (SockList &sl, NewSocket &ns, maptile *mp, int mx, int my, int sx, int sy, int layer) |
1542 | { |
1522 | { |
1543 | object *ob, *head; |
1523 | object *ob, *head; |
1544 | uint16 face_num; |
1524 | uint16 face_num; |
1545 | int bx, by, i; |
1525 | int bx, by, i; |
1546 | |
1526 | |
1547 | /* If there is a multipart object stored away, treat that as more important. |
1527 | /* If there is a multipart object stored away, treat that as more important. |
1548 | * If not, then do the normal processing. |
1528 | * If not, then do the normal processing. |
1549 | */ |
1529 | */ |
1550 | |
|
|
1551 | head = heads[(sy * MAX_HEAD_POS + sx) * MAX_LAYERS + layer]; |
1530 | head = heads[(sy * MAX_HEAD_POS + sx) * MAX_LAYERS + layer]; |
1552 | |
1531 | |
1553 | /* Check to see if this head is part of the set of objects |
1532 | /* Check to see if this head is part of the set of objects |
1554 | * we would normally send for this space. If so, then |
1533 | * we would normally send for this space. If so, then |
1555 | * don't use the head value. We need to do the check |
1534 | * don't use the head value. We need to do the check |
… | |
… | |
1720 | |
1699 | |
1721 | /* Another hack - because of heads and whatnot, this face may match one |
1700 | /* Another hack - because of heads and whatnot, this face may match one |
1722 | * we already sent for a lower layer. In that case, don't send |
1701 | * we already sent for a lower layer. In that case, don't send |
1723 | * this one. |
1702 | * this one. |
1724 | */ |
1703 | */ |
1725 | if (face_num && layer + 1 < MAP_LAYERS && ns->lastmap.cells[sx][sy].faces[layer + 1] == face_num) |
1704 | if (face_num && layer + 1 < MAP_LAYERS && ns.lastmap.cells[sx][sy].faces[layer + 1] == face_num) |
1726 | { |
|
|
1727 | face_num = 0; |
1705 | face_num = 0; |
1728 | } |
|
|
1729 | |
1706 | |
1730 | /* We've gotten what face we want to use for the object. Now see if |
1707 | /* We've gotten what face we want to use for the object. Now see if |
1731 | * if it has changed since we last sent it to the client. |
1708 | * if it has changed since we last sent it to the client. |
1732 | */ |
1709 | */ |
1733 | if (ns->lastmap.cells[sx][sy].faces[layer] != face_num) |
1710 | if (ns.lastmap.cells[sx][sy].faces[layer] != face_num) |
1734 | { |
1711 | { |
1735 | ns->lastmap.cells[sx][sy].faces[layer] = face_num; |
1712 | ns.lastmap.cells[sx][sy].faces[layer] = face_num; |
1736 | if (!(ns->faces_sent[face_num] & NS_FACESENT_FACE)) |
1713 | if (!(ns.faces_sent[face_num] & NS_FACESENT_FACE)) |
1737 | esrv_send_face (ns, face_num, 0); |
1714 | esrv_send_face (&ns, face_num, 0); |
1738 | SockList_AddShort (sl, face_num); |
1715 | |
|
|
1716 | sl << uint16 (face_num); |
1739 | return 1; |
1717 | return 1; |
1740 | } |
1718 | } |
|
|
1719 | |
1741 | /* Nothing changed */ |
1720 | /* Nothing changed */ |
1742 | return 0; |
1721 | return 0; |
1743 | } |
1722 | } |
1744 | |
1723 | |
1745 | /** |
1724 | /** |
… | |
… | |
1760 | * top layer (this matches what the GET_MAP_FACE and GET_MAP_FACE_OBJ |
1739 | * top layer (this matches what the GET_MAP_FACE and GET_MAP_FACE_OBJ |
1761 | * take. |
1740 | * take. |
1762 | */ |
1741 | */ |
1763 | |
1742 | |
1764 | static inline int |
1743 | static inline int |
1765 | update_smooth (SockList * sl, NewSocket * ns, maptile *mp, int mx, int my, int sx, int sy, int layer) |
1744 | update_smooth (SockList &sl, NewSocket &ns, maptile *mp, int mx, int my, int sx, int sy, int layer) |
1766 | { |
1745 | { |
1767 | object *ob; |
1746 | object *ob; |
1768 | int smoothlevel; /* old face_num; */ |
1747 | int smoothlevel; /* old face_num; */ |
1769 | |
1748 | |
1770 | ob = GET_MAP_FACE_OBJ (mp, mx, my, layer); |
1749 | ob = GET_MAP_FACE_OBJ (mp, mx, my, layer); |
… | |
… | |
1775 | if (!ob || ob->face == blank_face || MAP_NOSMOOTH (mp)) |
1754 | if (!ob || ob->face == blank_face || MAP_NOSMOOTH (mp)) |
1776 | smoothlevel = 0; |
1755 | smoothlevel = 0; |
1777 | else |
1756 | else |
1778 | { |
1757 | { |
1779 | smoothlevel = ob->smoothlevel; |
1758 | smoothlevel = ob->smoothlevel; |
1780 | if (smoothlevel && !(ns->faces_sent[ob->face->number] & NS_FACESENT_SMOOTH)) |
1759 | if (smoothlevel && !(ns.faces_sent[ob->face->number] & NS_FACESENT_SMOOTH)) |
1781 | SendSmooth (ns, ob->face->number); |
1760 | SendSmooth (&ns, ob->face->number); |
1782 | } /* else not already head object or blank face */ |
1761 | } /* else not already head object or blank face */ |
1783 | |
1762 | |
1784 | /* We've gotten what face we want to use for the object. Now see if |
1763 | /* We've gotten what face we want to use for the object. Now see if |
1785 | * if it has changed since we last sent it to the client. |
1764 | * if it has changed since we last sent it to the client. |
1786 | */ |
1765 | */ |
1787 | if (smoothlevel > 255) |
1766 | if (smoothlevel > 255) |
1788 | smoothlevel = 255; |
1767 | smoothlevel = 255; |
1789 | else if (smoothlevel < 0) |
1768 | else if (smoothlevel < 0) |
1790 | smoothlevel = 0; |
1769 | smoothlevel = 0; |
|
|
1770 | |
1791 | if (ns->lastmap.cells[sx][sy].smooth[layer] != smoothlevel) |
1771 | if (ns.lastmap.cells[sx][sy].smooth[layer] != smoothlevel) |
1792 | { |
1772 | { |
1793 | ns->lastmap.cells[sx][sy].smooth[layer] = smoothlevel; |
1773 | ns.lastmap.cells[sx][sy].smooth[layer] = smoothlevel; |
1794 | SockList_AddChar (sl, (uint8) (smoothlevel & 0xFF)); |
1774 | sl << uint8 (smoothlevel); |
1795 | return 1; |
1775 | return 1; |
1796 | } |
1776 | } |
|
|
1777 | |
1797 | /* Nothing changed */ |
1778 | /* Nothing changed */ |
1798 | return 0; |
1779 | return 0; |
1799 | } |
1780 | } |
1800 | |
1781 | |
1801 | /** |
1782 | /** |
… | |
… | |
1842 | draw_client_map1 (object *pl) |
1823 | draw_client_map1 (object *pl) |
1843 | { |
1824 | { |
1844 | int x, y, ax, ay, d, startlen, max_x, max_y, oldlen; |
1825 | int x, y, ax, ay, d, startlen, max_x, max_y, oldlen; |
1845 | sint16 nx, ny; |
1826 | sint16 nx, ny; |
1846 | int estartlen, eoldlen; |
1827 | int estartlen, eoldlen; |
1847 | SockList sl; |
|
|
1848 | SockList esl; /*For extended Map info */ |
|
|
1849 | uint16 mask, emask; |
1828 | uint16 mask, emask; |
1850 | uint8 eentrysize; |
1829 | uint8 eentrysize; |
1851 | uint16 ewhatstart, ewhatflag; |
1830 | uint16 ewhatstart, ewhatflag; |
1852 | uint8 extendedinfos; |
1831 | uint8 extendedinfos; |
1853 | maptile *m; |
1832 | maptile *m; |
1854 | |
1833 | |
1855 | NewSocket & socket = pl->contr->socket; |
1834 | NewSocket &socket = pl->contr->socket; |
1856 | |
1835 | |
1857 | check_map_change (pl->contr); |
1836 | check_map_change (pl->contr); |
1858 | |
1837 | |
1859 | sl.buf = (unsigned char *) malloc (MAXSOCKBUF); |
1838 | SockList sl (MAXSOCKBUF); |
1860 | if (socket.mapmode == Map1Cmd) |
1839 | SockList esl (MAXSOCKBUF); |
1861 | strcpy ((char *) sl.buf, "map1 "); |
1840 | |
1862 | else |
1841 | sl << (socket.mapmode == Map1Cmd ? "map1 " : "map1a "); |
1863 | strcpy ((char *) sl.buf, "map1a "); |
|
|
1864 | sl.len = strlen ((char *) sl.buf); |
|
|
1865 | startlen = sl.len; |
1842 | startlen = sl.len; |
1866 | |
1843 | |
1867 | /*Extendedmapinfo structure initialisation */ |
1844 | /*Extendedmapinfo structure initialisation */ |
1868 | if (socket.ext_mapinfos) |
1845 | if (socket.ext_mapinfos) |
1869 | { |
1846 | { |
1870 | esl.buf = (unsigned char *) malloc (MAXSOCKBUF); |
|
|
1871 | strcpy ((char *) esl.buf, "mapextended "); |
|
|
1872 | esl.len = strlen ((char *) esl.buf); |
|
|
1873 | extendedinfos = EMI_NOREDRAW; |
1847 | extendedinfos = EMI_NOREDRAW; |
1874 | |
1848 | |
1875 | if (socket.EMI_smooth) |
1849 | if (socket.EMI_smooth) |
1876 | extendedinfos |= EMI_SMOOTH; |
1850 | extendedinfos |= EMI_SMOOTH; |
1877 | |
1851 | |
1878 | ewhatstart = esl.len; |
1852 | ewhatstart = esl.len; |
1879 | ewhatflag = extendedinfos; /*The EMI_NOREDRAW bit |
1853 | ewhatflag = extendedinfos; /*The EMI_NOREDRAW bit |
1880 | could need to be taken away */ |
1854 | could need to be taken away */ |
1881 | SockList_AddChar (&esl, extendedinfos); |
|
|
1882 | eentrysize = getExtendedMapInfoSize (&socket); |
1855 | eentrysize = getExtendedMapInfoSize (&socket); |
1883 | SockList_AddChar (&esl, eentrysize); |
1856 | esl << "mapextended " |
|
|
1857 | << uint8 (extendedinfos) |
|
|
1858 | << uint8 (eentrysize); |
1884 | estartlen = esl.len; |
1859 | estartlen = esl.len; |
1885 | } |
1860 | } |
1886 | else |
1861 | else |
1887 | { |
1862 | { |
1888 | /* suppress compiler warnings */ |
1863 | /* suppress compiler warnings */ |
… | |
… | |
1929 | { |
1904 | { |
1930 | int i, got_one; |
1905 | int i, got_one; |
1931 | |
1906 | |
1932 | oldlen = sl.len; |
1907 | oldlen = sl.len; |
1933 | |
1908 | |
1934 | SockList_AddShort (&sl, mask); |
1909 | sl << uint16 (mask); |
1935 | |
1910 | |
1936 | if (check_head (sl, socket, ax, ay, 2)) |
1911 | if (check_head (sl, socket, ax, ay, 2)) mask |= 0x4; |
1937 | mask |= 0x4; |
|
|
1938 | if (check_head (sl, socket, ax, ay, 1)) |
1912 | if (check_head (sl, socket, ax, ay, 1)) mask |= 0x2; |
1939 | mask |= 0x2; |
|
|
1940 | if (check_head (sl, socket, ax, ay, 0)) |
1913 | if (check_head (sl, socket, ax, ay, 0)) mask |= 0x1; |
1941 | mask |= 0x1; |
|
|
1942 | |
1914 | |
1943 | /* If all we are doing is sending 0 (blank) faces, we don't |
1915 | /* If all we are doing is sending 0 (blank) faces, we don't |
1944 | * actually need to send that - just the coordinates |
1916 | * actually need to send that - just the coordinates |
1945 | * with no faces tells the client to blank out the |
1917 | * with no faces tells the client to blank out the |
1946 | * space. |
1918 | * space. |
… | |
… | |
1983 | * if this hasn't already been done. If the space is out |
1955 | * if this hasn't already been done. If the space is out |
1984 | * of the map, it shouldn't have a head |
1956 | * of the map, it shouldn't have a head |
1985 | */ |
1957 | */ |
1986 | if (lastcell.count != -1) |
1958 | if (lastcell.count != -1) |
1987 | { |
1959 | { |
1988 | SockList_AddShort (&sl, mask); |
1960 | sl << uint16 (mask); |
1989 | map_clearcell (&lastcell, 0, 0, 0, -1); |
1961 | map_clearcell (&lastcell, 0, 0, 0, -1); |
1990 | } |
1962 | } |
1991 | } |
1963 | } |
1992 | else if (d > 3) |
1964 | else if (d > 3) |
1993 | { |
1965 | { |
… | |
… | |
1997 | * reason. Still may need to send the head for this space. |
1969 | * reason. Still may need to send the head for this space. |
1998 | */ |
1970 | */ |
1999 | |
1971 | |
2000 | oldlen = sl.len; |
1972 | oldlen = sl.len; |
2001 | |
1973 | |
2002 | SockList_AddShort (&sl, mask); |
1974 | sl << uint16 (mask); |
2003 | |
1975 | |
2004 | if (lastcell.count != -1) |
1976 | if (lastcell.count != -1) |
2005 | need_send = 1; |
1977 | need_send = 1; |
2006 | |
1978 | |
2007 | count = -1; |
1979 | count = -1; |
2008 | |
1980 | |
2009 | if (socket.mapmode == Map1aCmd && have_head (ax, ay)) |
1981 | if (socket.mapmode == Map1aCmd && have_head (ax, ay)) |
2010 | { |
1982 | { |
2011 | /* Now check to see if any heads need to be sent */ |
1983 | /* Now check to see if any heads need to be sent */ |
2012 | |
1984 | |
2013 | if (check_head (sl, socket, ax, ay, 2)) |
1985 | if (check_head (sl, socket, ax, ay, 2)) mask |= 0x4; |
2014 | mask |= 0x4; |
|
|
2015 | if (check_head (sl, socket, ax, ay, 1)) |
1986 | if (check_head (sl, socket, ax, ay, 1)) mask |= 0x2; |
2016 | mask |= 0x2; |
|
|
2017 | if (check_head (sl, socket, ax, ay, 0)) |
1987 | if (check_head (sl, socket, ax, ay, 0)) mask |= 0x1; |
2018 | mask |= 0x1; |
|
|
2019 | |
1988 | |
2020 | lastcell.count = count; |
1989 | lastcell.count = count; |
2021 | } |
1990 | } |
2022 | else |
1991 | else |
2023 | { |
1992 | { |
… | |
… | |
2052 | */ |
2021 | */ |
2053 | oldlen = sl.len; |
2022 | oldlen = sl.len; |
2054 | mask = (ax & 0x3f) << 10 | (ay & 0x3f) << 4; |
2023 | mask = (ax & 0x3f) << 10 | (ay & 0x3f) << 4; |
2055 | eoldlen = esl.len; |
2024 | eoldlen = esl.len; |
2056 | emask = (ax & 0x3f) << 10 | (ay & 0x3f) << 4; |
2025 | emask = (ax & 0x3f) << 10 | (ay & 0x3f) << 4; |
2057 | SockList_AddShort (&sl, mask); |
2026 | sl << uint16 (mask); |
2058 | |
2027 | |
2059 | if (socket.ext_mapinfos) |
2028 | if (socket.ext_mapinfos) |
2060 | SockList_AddShort (&esl, emask); |
2029 | esl << uint16 (emask); |
2061 | |
2030 | |
2062 | unsigned char dummy; |
2031 | unsigned char dummy; |
2063 | unsigned char *last_ext = &dummy; |
2032 | unsigned char *last_ext = &dummy; |
2064 | |
2033 | |
2065 | /* Darkness changed */ |
2034 | /* Darkness changed */ |
… | |
… | |
2069 | |
2038 | |
2070 | if (socket.extmap) |
2039 | if (socket.extmap) |
2071 | { |
2040 | { |
2072 | *last_ext |= 0x80; |
2041 | *last_ext |= 0x80; |
2073 | last_ext = sl.buf + sl.len; |
2042 | last_ext = sl.buf + sl.len; |
2074 | SockList_AddChar (&sl, d); |
2043 | sl << uint8 (d); |
2075 | } |
2044 | } |
2076 | else |
2045 | else |
2077 | SockList_AddChar (&sl, 255 - 64 * d); |
2046 | sl << uint8 (255 - 64 * d); |
2078 | } |
2047 | } |
2079 | |
2048 | |
2080 | lastcell.count = d; |
2049 | lastcell.count = d; |
2081 | |
2050 | |
2082 | if (socket.extmap) |
2051 | if (socket.extmap) |
2083 | { |
2052 | { |
2084 | uint8 stat_hp = 0; |
2053 | uint8 stat_hp = 0; |
2085 | uint8 stat_width = 0; |
2054 | uint8 stat_width = 0; |
2086 | uint8 flags = 0; |
2055 | uint8 flags = 0; |
2087 | tag_t player = 0; |
2056 | UUID player = 0; |
2088 | |
2057 | |
2089 | // send hp information, if applicable |
2058 | // send hp information, if applicable |
2090 | if (object *op = GET_MAP_FACE_OBJ (m, nx, ny, 0)) |
2059 | if (object *op = GET_MAP_FACE_OBJ (m, nx, ny, 0)) |
2091 | { |
2060 | { |
2092 | if (op->head || op->invisible) |
2061 | if (op->head || op->invisible) |
… | |
… | |
2113 | lastcell.stat_hp = stat_hp; |
2082 | lastcell.stat_hp = stat_hp; |
2114 | |
2083 | |
2115 | mask |= 0x8; |
2084 | mask |= 0x8; |
2116 | *last_ext |= 0x80; |
2085 | *last_ext |= 0x80; |
2117 | last_ext = sl.buf + sl.len; |
2086 | last_ext = sl.buf + sl.len; |
2118 | SockList_AddChar (&sl, 5); |
2087 | |
2119 | SockList_AddChar (&sl, stat_hp); |
2088 | sl << uint8 (5) << uint8 (stat_hp); |
2120 | |
2089 | |
2121 | if (stat_width > 1) |
2090 | if (stat_width > 1) |
2122 | { |
2091 | { |
2123 | *last_ext |= 0x80; |
2092 | *last_ext |= 0x80; |
2124 | last_ext = sl.buf + sl.len; |
2093 | last_ext = sl.buf + sl.len; |
2125 | SockList_AddChar (&sl, 6); |
2094 | |
2126 | SockList_AddChar (&sl, stat_width); |
2095 | sl << uint8 (6) << uint8 (stat_width); |
2127 | } |
2096 | } |
2128 | } |
2097 | } |
2129 | |
2098 | |
2130 | if (lastcell.player != player) |
2099 | if (lastcell.player != player) |
2131 | { |
2100 | { |
2132 | lastcell.player = player; |
2101 | lastcell.player = player; |
2133 | |
2102 | |
2134 | mask |= 0x8; |
2103 | mask |= 0x8; |
2135 | *last_ext |= 0x80; |
2104 | *last_ext |= 0x80; |
2136 | last_ext = sl.buf + sl.len; |
2105 | last_ext = sl.buf + sl.len; |
2137 | SockList_AddChar (&sl, 0x47); |
2106 | |
2138 | SockList_AddChar (&sl, 4); |
2107 | sl << uint8 (0x47) << uint8 (8) << (uint64)player; |
2139 | SockList_AddInt (&sl, player); |
|
|
2140 | } |
2108 | } |
2141 | |
2109 | |
2142 | if (lastcell.flags != flags) |
2110 | if (lastcell.flags != flags) |
2143 | { |
2111 | { |
2144 | lastcell.flags = flags; |
2112 | lastcell.flags = flags; |
2145 | |
2113 | |
2146 | mask |= 0x8; |
2114 | mask |= 0x8; |
2147 | *last_ext |= 0x80; |
2115 | *last_ext |= 0x80; |
2148 | last_ext = sl.buf + sl.len; |
2116 | last_ext = sl.buf + sl.len; |
2149 | SockList_AddChar (&sl, 8); |
2117 | |
2150 | SockList_AddChar (&sl, flags); |
2118 | sl << uint8 (8) << uint8 (flags); |
2151 | } |
2119 | } |
2152 | } |
2120 | } |
2153 | |
2121 | |
2154 | /* Floor face */ |
2122 | /* Floor face */ |
2155 | if (update_space (&sl, &socket, m, nx, ny, ax, ay, 2)) |
2123 | if (update_space (sl, socket, m, nx, ny, ax, ay, 2)) |
2156 | mask |= 0x4; |
2124 | mask |= 0x4; |
2157 | |
2125 | |
2158 | if (socket.EMI_smooth) |
2126 | if (socket.EMI_smooth) |
2159 | if (update_smooth (&esl, &socket, m, nx, ny, ax, ay, 2)) |
2127 | if (update_smooth (esl, socket, m, nx, ny, ax, ay, 2)) |
2160 | emask |= 0x4; |
2128 | emask |= 0x4; |
2161 | |
2129 | |
2162 | /* Middle face */ |
2130 | /* Middle face */ |
2163 | if (update_space (&sl, &socket, m, nx, ny, ax, ay, 1)) |
2131 | if (update_space (sl, socket, m, nx, ny, ax, ay, 1)) |
2164 | mask |= 0x2; |
2132 | mask |= 0x2; |
2165 | |
2133 | |
2166 | if (socket.EMI_smooth) |
2134 | if (socket.EMI_smooth) |
2167 | if (update_smooth (&esl, &socket, m, nx, ny, ax, ay, 1)) |
2135 | if (update_smooth (esl, socket, m, nx, ny, ax, ay, 1)) |
2168 | emask |= 0x2; |
2136 | emask |= 0x2; |
2169 | |
2137 | |
2170 | if (nx == pl->x && ny == pl->y && pl->invisible & (pl->invisible < 50 ? 4 : 1)) |
2138 | if (nx == pl->x && ny == pl->y && pl->invisible & (pl->invisible < 50 ? 4 : 1)) |
2171 | { |
2139 | { |
2172 | if (lastcell.faces[0] != pl->face->number) |
2140 | if (lastcell.faces[0] != pl->face->number) |
… | |
… | |
2175 | mask |= 0x1; |
2143 | mask |= 0x1; |
2176 | |
2144 | |
2177 | if (!(socket.faces_sent[pl->face->number] & NS_FACESENT_FACE)) |
2145 | if (!(socket.faces_sent[pl->face->number] & NS_FACESENT_FACE)) |
2178 | esrv_send_face (&socket, pl->face->number, 0); |
2146 | esrv_send_face (&socket, pl->face->number, 0); |
2179 | |
2147 | |
2180 | SockList_AddShort (&sl, pl->face->number); |
2148 | sl << uint16 (pl->face->number); |
2181 | } |
2149 | } |
2182 | } |
2150 | } |
2183 | else |
2151 | else |
2184 | { |
2152 | { |
2185 | /* Top face */ |
2153 | /* Top face */ |
2186 | if (update_space (&sl, &socket, m, nx, ny, ax, ay, 0)) |
2154 | if (update_space (sl, socket, m, nx, ny, ax, ay, 0)) |
2187 | mask |= 0x1; |
2155 | mask |= 0x1; |
2188 | |
2156 | |
2189 | if (socket.EMI_smooth) |
2157 | if (socket.EMI_smooth) |
2190 | if (update_smooth (&esl, &socket, m, nx, ny, ax, ay, 0)) |
2158 | if (update_smooth (esl, socket, m, nx, ny, ax, ay, 0)) |
2191 | emask |= 0x1; |
2159 | emask |= 0x1; |
2192 | } |
2160 | } |
2193 | |
2161 | |
2194 | /* Check to see if we are in fact sending anything for this |
2162 | /* Check to see if we are in fact sending anything for this |
2195 | * space by checking the mask. If so, update the mask. |
2163 | * space by checking the mask. If so, update the mask. |
… | |
… | |
2221 | esl.buf[ewhatstart + 1] = ewhatflag & 0xff; |
2189 | esl.buf[ewhatstart + 1] = ewhatflag & 0xff; |
2222 | } |
2190 | } |
2223 | |
2191 | |
2224 | if (esl.len > estartlen) |
2192 | if (esl.len > estartlen) |
2225 | Send_With_Handling (&socket, &esl); |
2193 | Send_With_Handling (&socket, &esl); |
2226 | |
|
|
2227 | free (esl.buf); |
|
|
2228 | } |
2194 | } |
2229 | |
2195 | |
2230 | if (sl.len > startlen || socket.sent_scroll) |
2196 | if (sl.len > startlen || socket.sent_scroll) |
2231 | { |
2197 | { |
2232 | Send_With_Handling (&socket, &sl); |
2198 | Send_With_Handling (&socket, &sl); |
2233 | socket.sent_scroll = 0; |
2199 | socket.sent_scroll = 0; |
2234 | } |
2200 | } |
2235 | |
2201 | |
2236 | free (sl.buf); |
2202 | sl.free (); |
|
|
2203 | esl.free (); |
2237 | } |
2204 | } |
2238 | |
2205 | |
2239 | /** |
2206 | /** |
2240 | * Draws client map. |
2207 | * Draws client map. |
2241 | */ |
2208 | */ |
… | |
… | |
2355 | esrv_map_setbelow (&pl->contr->socket, ax, ay, floor->number, &newmap); |
2322 | esrv_map_setbelow (&pl->contr->socket, ax, ay, floor->number, &newmap); |
2356 | } |
2323 | } |
2357 | } /* Is a valid space */ |
2324 | } /* Is a valid space */ |
2358 | } |
2325 | } |
2359 | } |
2326 | } |
|
|
2327 | |
2360 | esrv_map_doneredraw (&pl->contr->socket, &newmap); |
2328 | esrv_map_doneredraw (&pl->contr->socket, &newmap); |
2361 | |
2329 | |
2362 | check_map_change (pl->contr); |
2330 | check_map_change (pl->contr); |
2363 | } |
2331 | } |
2364 | |
2332 | |
… | |
… | |
2381 | /** |
2349 | /** |
2382 | * This sends the skill number to name mapping. We ignore |
2350 | * This sends the skill number to name mapping. We ignore |
2383 | * the params - we always send the same info no matter what. |
2351 | * the params - we always send the same info no matter what. |
2384 | */ |
2352 | */ |
2385 | void |
2353 | void |
2386 | send_skill_info (NewSocket * ns, char *params) |
2354 | send_skill_info (NewSocket *ns, char *params) |
2387 | { |
2355 | { |
2388 | SockList sl; |
2356 | SockList sl (MAXSOCKBUF); |
2389 | int i; |
2357 | sl << "replyinfo skill_info\n"; |
2390 | |
2358 | |
2391 | sl.buf = (unsigned char *) malloc (MAXSOCKBUF); |
|
|
2392 | strcpy ((char *) sl.buf, "replyinfo skill_info\n"); |
|
|
2393 | for (i = 1; i < NUM_SKILLS; i++) |
2359 | for (int i = 1; i < NUM_SKILLS; i++) |
2394 | { |
2360 | sl.printf ("%d:%s\n", i + CS_STAT_SKILLINFO, &skill_names[i]); |
2395 | sprintf ((char *) sl.buf + strlen ((char *) sl.buf), "%d:%s\n", i + CS_STAT_SKILLINFO, &skill_names[i]); |
2361 | |
2396 | } |
|
|
2397 | sl.len = strlen ((char *) sl.buf); |
|
|
2398 | if (sl.len >= MAXSOCKBUF) |
2362 | if (sl.len >= MAXSOCKBUF) |
2399 | { |
2363 | { |
2400 | LOG (llevError, "Buffer overflow in send_skill_info!\n"); |
2364 | LOG (llevError, "Buffer overflow in send_skill_info!\n"); |
2401 | fatal (0); |
2365 | fatal (0); |
2402 | } |
2366 | } |
|
|
2367 | |
2403 | Send_With_Handling (ns, &sl); |
2368 | Send_With_Handling (ns, &sl); |
2404 | free (sl.buf); |
2369 | sl.free (); |
2405 | } |
2370 | } |
2406 | |
2371 | |
2407 | /** |
2372 | /** |
2408 | * This sends the spell path to name mapping. We ignore |
2373 | * This sends the spell path to name mapping. We ignore |
2409 | * the params - we always send the same info no matter what. |
2374 | * the params - we always send the same info no matter what. |
2410 | */ |
2375 | */ |
2411 | void |
2376 | void |
2412 | send_spell_paths (NewSocket * ns, char *params) |
2377 | send_spell_paths (NewSocket * ns, char *params) |
2413 | { |
2378 | { |
2414 | SockList sl; |
2379 | SockList sl (MAXSOCKBUF); |
2415 | int i; |
|
|
2416 | |
2380 | |
2417 | sl.buf = (unsigned char *) malloc (MAXSOCKBUF); |
2381 | sl << "replyinfo spell_paths\n"; |
2418 | strcpy ((char *) sl.buf, "replyinfo spell_paths\n"); |
2382 | |
2419 | for (i = 0; i < NRSPELLPATHS; i++) |
2383 | for (int i = 0; i < NRSPELLPATHS; i++) |
2420 | sprintf ((char *) sl.buf + strlen ((char *) sl.buf), "%d:%s\n", 1 << i, spellpathnames[i]); |
2384 | sl.printf ("%d:%s\n", 1 << i, spellpathnames[i]); |
2421 | sl.len = strlen ((char *) sl.buf); |
2385 | |
2422 | if (sl.len >= MAXSOCKBUF) |
2386 | if (sl.len >= MAXSOCKBUF) |
2423 | { |
2387 | { |
2424 | LOG (llevError, "Buffer overflow in send_spell_paths!\n"); |
2388 | LOG (llevError, "Buffer overflow in send_spell_paths!\n"); |
2425 | fatal (0); |
2389 | fatal (0); |
2426 | } |
2390 | } |
|
|
2391 | |
2427 | Send_With_Handling (ns, &sl); |
2392 | Send_With_Handling (ns, &sl); |
2428 | free (sl.buf); |
2393 | sl.free (); |
2429 | } |
2394 | } |
2430 | |
2395 | |
2431 | /** |
2396 | /** |
2432 | * This looks for any spells the player may have that have changed their stats. |
2397 | * This looks for any spells the player may have that have changed their stats. |
2433 | * it then sends an updspell packet for each spell that has changed in this way |
2398 | * it then sends an updspell packet for each spell that has changed in this way |
2434 | */ |
2399 | */ |
2435 | void |
2400 | void |
2436 | esrv_update_spells (player *pl) |
2401 | esrv_update_spells (player *pl) |
2437 | { |
2402 | { |
2438 | SockList sl; |
|
|
2439 | int flags = 0; |
|
|
2440 | object *spell; |
|
|
2441 | |
|
|
2442 | if (!pl->socket.monitor_spells) |
2403 | if (!pl->socket.monitor_spells) |
2443 | return; |
2404 | return; |
|
|
2405 | |
2444 | for (spell = pl->ob->inv; spell != NULL; spell = spell->below) |
2406 | for (object *spell = pl->ob->inv; spell; spell = spell->below) |
2445 | { |
2407 | { |
2446 | if (spell->type == SPELL) |
2408 | if (spell->type == SPELL) |
2447 | { |
2409 | { |
|
|
2410 | int flags = 0; |
|
|
2411 | |
2448 | /* check if we need to update it */ |
2412 | /* check if we need to update it */ |
2449 | if (spell->last_sp != SP_level_spellpoint_cost (pl->ob, spell, SPELL_MANA)) |
2413 | if (spell->last_sp != SP_level_spellpoint_cost (pl->ob, spell, SPELL_MANA)) |
2450 | { |
2414 | { |
2451 | spell->last_sp = SP_level_spellpoint_cost (pl->ob, spell, SPELL_MANA); |
2415 | spell->last_sp = SP_level_spellpoint_cost (pl->ob, spell, SPELL_MANA); |
2452 | flags |= UPD_SP_MANA; |
2416 | flags |= UPD_SP_MANA; |
2453 | } |
2417 | } |
|
|
2418 | |
2454 | if (spell->last_grace != SP_level_spellpoint_cost (pl->ob, spell, SPELL_GRACE)) |
2419 | if (spell->last_grace != SP_level_spellpoint_cost (pl->ob, spell, SPELL_GRACE)) |
2455 | { |
2420 | { |
2456 | spell->last_grace = SP_level_spellpoint_cost (pl->ob, spell, SPELL_GRACE); |
2421 | spell->last_grace = SP_level_spellpoint_cost (pl->ob, spell, SPELL_GRACE); |
2457 | flags |= UPD_SP_GRACE; |
2422 | flags |= UPD_SP_GRACE; |
2458 | } |
2423 | } |
|
|
2424 | |
2459 | if (spell->last_eat != spell->stats.dam + SP_level_dam_adjust (pl->ob, spell)) |
2425 | if (spell->last_eat != spell->stats.dam + SP_level_dam_adjust (pl->ob, spell)) |
2460 | { |
2426 | { |
2461 | spell->last_eat = spell->stats.dam + SP_level_dam_adjust (pl->ob, spell); |
2427 | spell->last_eat = spell->stats.dam + SP_level_dam_adjust (pl->ob, spell); |
2462 | flags |= UPD_SP_DAMAGE; |
2428 | flags |= UPD_SP_DAMAGE; |
2463 | } |
2429 | } |
|
|
2430 | |
2464 | if (flags != 0) |
2431 | if (flags) |
2465 | { |
2432 | { |
2466 | sl.buf = (unsigned char *) malloc (MAXSOCKBUF); |
2433 | SockList sl (MAXSOCKBUF); |
2467 | strcpy ((char *) sl.buf, "updspell "); |
2434 | |
2468 | sl.len = strlen ((char *) sl.buf); |
2435 | sl << "updspell " |
2469 | SockList_AddChar (&sl, flags); |
2436 | << uint8 (flags) |
2470 | SockList_AddInt (&sl, spell->count); |
2437 | << uint32 (spell->count); |
2471 | if (flags & UPD_SP_MANA) |
2438 | |
2472 | SockList_AddShort (&sl, spell->last_sp); |
2439 | if (flags & UPD_SP_MANA ) sl << uint16 (spell->last_sp); |
2473 | if (flags & UPD_SP_GRACE) |
2440 | if (flags & UPD_SP_GRACE ) sl << uint16 (spell->last_grace); |
2474 | SockList_AddShort (&sl, spell->last_grace); |
2441 | if (flags & UPD_SP_DAMAGE) sl << uint16 (spell->last_eat); |
2475 | if (flags & UPD_SP_DAMAGE) |
2442 | |
2476 | SockList_AddShort (&sl, spell->last_eat); |
|
|
2477 | flags = 0; |
|
|
2478 | Send_With_Handling (&pl->socket, &sl); |
2443 | Send_With_Handling (&pl->socket, &sl); |
2479 | free (sl.buf); |
2444 | sl.free (); |
2480 | } |
2445 | } |
2481 | } |
2446 | } |
2482 | } |
2447 | } |
2483 | } |
2448 | } |
2484 | |
2449 | |
2485 | void |
2450 | void |
2486 | esrv_remove_spell (player *pl, object *spell) |
2451 | esrv_remove_spell (player *pl, object *spell) |
2487 | { |
2452 | { |
2488 | SockList sl; |
|
|
2489 | |
|
|
2490 | if (!pl->socket.monitor_spells) |
2453 | if (!pl->socket.monitor_spells) |
2491 | return; |
2454 | return; |
|
|
2455 | |
2492 | if (!pl || !spell || spell->env != pl->ob) |
2456 | if (!pl || !spell || spell->env != pl->ob) |
2493 | { |
2457 | { |
2494 | LOG (llevError, "Invalid call to esrv_remove_spell"); |
2458 | LOG (llevError, "Invalid call to esrv_remove_spell"); |
2495 | return; |
2459 | return; |
2496 | } |
2460 | } |
2497 | sl.buf = (unsigned char *) malloc (MAXSOCKBUF); |
2461 | |
2498 | strcpy ((char *) sl.buf, "delspell "); |
2462 | SockList sl (MAXSOCKBUF); |
2499 | sl.len = strlen ((char *) sl.buf); |
2463 | |
2500 | SockList_AddInt (&sl, spell->count); |
2464 | sl << "delspell " |
|
|
2465 | << uint32 (spell->count); |
|
|
2466 | |
2501 | Send_With_Handling (&pl->socket, &sl); |
2467 | Send_With_Handling (&pl->socket, &sl); |
2502 | free (sl.buf); |
2468 | sl.free (); |
2503 | } |
2469 | } |
2504 | |
2470 | |
2505 | /* appends the spell *spell to the Socklist we will send the data to. */ |
2471 | /* appends the spell *spell to the Socklist we will send the data to. */ |
2506 | static void |
2472 | static void |
2507 | append_spell (player *pl, SockList * sl, object *spell) |
2473 | append_spell (player *pl, SockList &sl, object *spell) |
2508 | { |
2474 | { |
2509 | int len, i, skill = 0; |
2475 | int len, i, skill = 0; |
2510 | |
2476 | |
2511 | if (!(spell->name)) |
2477 | if (!(spell->name)) |
2512 | { |
2478 | { |
2513 | LOG (llevError, "item number %d is a spell with no name.\n", spell->count); |
2479 | LOG (llevError, "item number %d is a spell with no name.\n", spell->count); |
2514 | return; |
2480 | return; |
2515 | } |
2481 | } |
2516 | SockList_AddInt (sl, spell->count); |
2482 | |
2517 | SockList_AddShort (sl, spell->level); |
|
|
2518 | SockList_AddShort (sl, spell->casting_time); |
|
|
2519 | /* store costs and damage in the object struct, to compare to later */ |
2483 | /* store costs and damage in the object struct, to compare to later */ |
2520 | spell->last_sp = SP_level_spellpoint_cost (pl->ob, spell, SPELL_MANA); |
2484 | spell->last_sp = SP_level_spellpoint_cost (pl->ob, spell, SPELL_MANA); |
2521 | spell->last_grace = SP_level_spellpoint_cost (pl->ob, spell, SPELL_GRACE); |
2485 | spell->last_grace = SP_level_spellpoint_cost (pl->ob, spell, SPELL_GRACE); |
2522 | spell->last_eat = spell->stats.dam + SP_level_dam_adjust (pl->ob, spell); |
2486 | spell->last_eat = spell->stats.dam + SP_level_dam_adjust (pl->ob, spell); |
2523 | /* send the current values */ |
|
|
2524 | SockList_AddShort (sl, spell->last_sp); |
|
|
2525 | SockList_AddShort (sl, spell->last_grace); |
|
|
2526 | SockList_AddShort (sl, spell->last_eat); |
|
|
2527 | |
2487 | |
2528 | /* figure out which skill it uses, if it uses one */ |
2488 | /* figure out which skill it uses, if it uses one */ |
2529 | if (spell->skill) |
2489 | if (spell->skill) |
2530 | { |
2490 | { |
2531 | for (i = 1; i < NUM_SKILLS; i++) |
2491 | for (i = 1; i < NUM_SKILLS; i++) |
… | |
… | |
2533 | { |
2493 | { |
2534 | skill = i + CS_STAT_SKILLINFO; |
2494 | skill = i + CS_STAT_SKILLINFO; |
2535 | break; |
2495 | break; |
2536 | } |
2496 | } |
2537 | } |
2497 | } |
2538 | SockList_AddChar (sl, skill); |
|
|
2539 | |
2498 | |
2540 | SockList_AddInt (sl, spell->path_attuned); |
2499 | /* send the current values */ |
|
|
2500 | sl << uint32 (spell->count) |
|
|
2501 | << uint16 (spell->level) |
|
|
2502 | << uint16 (spell->casting_time) |
|
|
2503 | << uint16 (spell->last_sp) |
|
|
2504 | << uint16 (spell->last_grace) |
|
|
2505 | << uint16 (spell->last_eat) |
|
|
2506 | << uint8 (skill) |
|
|
2507 | << uint32 (spell->path_attuned) |
2541 | SockList_AddInt (sl, (spell->face) ? spell->face->number : 0); |
2508 | << uint32 (spell->face ? spell->face->number : 0) |
2542 | |
2509 | << data8 (spell->name) |
2543 | len = strlen (spell->name); |
2510 | << data16 (spell->msg); |
2544 | SockList_AddChar (sl, (char) len); |
|
|
2545 | memcpy (sl->buf + sl->len, spell->name, len); |
|
|
2546 | sl->len += len; |
|
|
2547 | |
|
|
2548 | if (!spell->msg) |
|
|
2549 | { |
|
|
2550 | SockList_AddShort (sl, 0); |
|
|
2551 | } |
|
|
2552 | else |
|
|
2553 | { |
|
|
2554 | len = strlen (spell->msg); |
|
|
2555 | SockList_AddShort (sl, len); |
|
|
2556 | memcpy (sl->buf + sl->len, spell->msg, len); |
|
|
2557 | sl->len += len; |
|
|
2558 | } |
|
|
2559 | } |
2511 | } |
2560 | |
2512 | |
2561 | /** |
2513 | /** |
2562 | * This tells the client to add the spell *ob, if *ob is NULL, then add |
2514 | * This tells the client to add the spell *ob, if *ob is NULL, then add |
2563 | * all spells in the player's inventory. |
2515 | * all spells in the player's inventory. |
2564 | */ |
2516 | */ |
2565 | void |
2517 | void |
2566 | esrv_add_spells (player *pl, object *spell) |
2518 | esrv_add_spells (player *pl, object *spell) |
2567 | { |
2519 | { |
2568 | SockList sl; |
|
|
2569 | |
|
|
2570 | if (!pl) |
2520 | if (!pl) |
2571 | { |
2521 | { |
2572 | LOG (llevError, "esrv_add_spells, tried to add a spell to a NULL player"); |
2522 | LOG (llevError, "esrv_add_spells, tried to add a spell to a NULL player"); |
2573 | return; |
2523 | return; |
2574 | } |
2524 | } |
|
|
2525 | |
2575 | if (!pl->socket.monitor_spells) |
2526 | if (!pl->socket.monitor_spells) |
2576 | return; |
2527 | return; |
2577 | sl.buf = (unsigned char *) malloc (MAXSOCKBUF); |
2528 | |
2578 | strcpy ((char *) sl.buf, "addspell "); |
2529 | SockList sl (MAXSOCKBUF); |
2579 | sl.len = strlen ((char *) sl.buf); |
2530 | |
|
|
2531 | sl << "addspell "; |
|
|
2532 | |
2580 | if (!spell) |
2533 | if (!spell) |
2581 | { |
2534 | { |
2582 | for (spell = pl->ob->inv; spell != NULL; spell = spell->below) |
2535 | for (spell = pl->ob->inv; spell != NULL; spell = spell->below) |
2583 | { |
2536 | { |
2584 | /* were we to simply keep appending data here, we could exceed |
2537 | /* were we to simply keep appending data here, we could exceed |
… | |
… | |
2594 | * is hundreds of bytes off, so correcting 22 vs 26 doesn't seem |
2547 | * is hundreds of bytes off, so correcting 22 vs 26 doesn't seem |
2595 | * like it will fix this |
2548 | * like it will fix this |
2596 | */ |
2549 | */ |
2597 | if (spell->type != SPELL) |
2550 | if (spell->type != SPELL) |
2598 | continue; |
2551 | continue; |
|
|
2552 | |
2599 | if (sl.len >= (MAXSOCKBUF - (26 + strlen (spell->name) + (spell->msg ? strlen (spell->msg) : 0)))) |
2553 | if (sl.len >= (MAXSOCKBUF - (26 + strlen (spell->name) + (spell->msg ? strlen (spell->msg) : 0)))) |
2600 | { |
2554 | { |
2601 | Send_With_Handling (&pl->socket, &sl); |
2555 | Send_With_Handling (&pl->socket, &sl); |
2602 | strcpy ((char *) sl.buf, "addspell "); |
2556 | strcpy ((char *) sl.buf, "addspell "); |
2603 | sl.len = strlen ((char *) sl.buf); |
2557 | sl.len = strlen ((char *) sl.buf); |
2604 | } |
2558 | } |
|
|
2559 | |
2605 | append_spell (pl, &sl, spell); |
2560 | append_spell (pl, sl, spell); |
2606 | } |
2561 | } |
2607 | } |
2562 | } |
2608 | else if (spell->type != SPELL) |
2563 | else if (spell->type != SPELL) |
2609 | { |
2564 | { |
2610 | LOG (llevError, "Asked to send a non-spell object as a spell"); |
2565 | LOG (llevError, "Asked to send a non-spell object as a spell"); |
2611 | return; |
2566 | return; |
2612 | } |
2567 | } |
2613 | else |
2568 | else |
2614 | append_spell (pl, &sl, spell); |
2569 | append_spell (pl, sl, spell); |
|
|
2570 | |
2615 | if (sl.len >= MAXSOCKBUF) |
2571 | if (sl.length () >= MAXSOCKBUF) |
2616 | { |
2572 | { |
2617 | LOG (llevError, "Buffer overflow in esrv_add_spells!\n"); |
2573 | LOG (llevError, "Buffer overflow in esrv_add_spells!\n"); |
2618 | fatal (0); |
2574 | fatal (0); |
2619 | } |
2575 | } |
|
|
2576 | |
2620 | /* finally, we can send the packet */ |
2577 | /* finally, we can send the packet */ |
2621 | Send_With_Handling (&pl->socket, &sl); |
2578 | Send_With_Handling (&pl->socket, &sl); |
2622 | free (sl.buf); |
2579 | |
|
|
2580 | sl.free (); |
2623 | } |
2581 | } |
|
|
2582 | |