1 | /* |
1 | /* |
2 | * static char *rcsid_init_c = |
2 | * static char *rcsid_init_c = |
3 | * "$Id: request.C,v 1.5 2006/08/19 02:57:05 root Exp $"; |
3 | * "$Id: request.C,v 1.13 2006/09/03 00:18:43 root Exp $"; |
4 | */ |
4 | */ |
5 | |
5 | |
6 | /* |
6 | /* |
7 | CrossFire, A Multiplayer game for X-windows |
7 | CrossFire, A Multiplayer game for X-windows |
8 | |
8 | |
… | |
… | |
128 | */ |
128 | */ |
129 | mx = ns->mapx; |
129 | mx = ns->mapx; |
130 | my = ns->mapy; |
130 | my = ns->mapy; |
131 | |
131 | |
132 | if (ns->mapmode == Map1aCmd) { |
132 | if (ns->mapmode == Map1aCmd) { |
133 | mx += MAX_HEAD_OFFSET; |
133 | mx += MAX_HEAD_OFFSET; |
134 | my += MAX_HEAD_OFFSET; |
134 | my += MAX_HEAD_OFFSET; |
135 | } |
135 | } |
136 | |
136 | |
137 | /* the x and y here are coordinates for the new map, i.e. if we moved |
137 | /* the x and y here are coordinates for the new map, i.e. if we moved |
138 | * (dx,dy), newmap[x][y] = oldmap[x-dx][y-dy]. For this reason, |
138 | * (dx,dy), newmap[x][y] = oldmap[x-dx][y-dy]. For this reason, |
139 | * if the destination x or y coordinate is outside the viewable |
139 | * if the destination x or y coordinate is outside the viewable |
140 | * area, we clear the values - otherwise, the old values |
140 | * area, we clear the values - otherwise, the old values |
141 | * are preserved, and the check_head thinks it needs to clear them. |
141 | * are preserved, and the check_head thinks it needs to clear them. |
142 | */ |
142 | */ |
143 | for(x=0; x<mx; x++) { |
143 | for(x=0; x<mx; x++) { |
144 | for(y=0; y<my; y++) { |
144 | for(y=0; y<my; y++) { |
145 | if(x >= ns->mapx || y >= ns->mapy) { |
145 | if(x >= ns->mapx || y >= ns->mapy) { |
146 | /* clear cells outside the viewable area */ |
146 | /* clear cells outside the viewable area */ |
147 | memset(&newmap.cells[x][y], 0, sizeof(struct MapCell)); |
147 | memset(&newmap.cells[x][y], 0, sizeof(struct MapCell)); |
148 | } |
148 | } |
149 | else if ((x+dx) < 0 || (x+dx) >= ns->mapx || (y+dy) < 0 || (y + dy) >= ns->mapy) { |
149 | else if ((x+dx) < 0 || (x+dx) >= ns->mapx || (y+dy) < 0 || (y + dy) >= ns->mapy) { |
150 | /* clear newly visible tiles within the viewable area */ |
150 | /* clear newly visible tiles within the viewable area */ |
151 | memset(&(newmap.cells[x][y]), 0, sizeof(struct MapCell)); |
151 | memset(&(newmap.cells[x][y]), 0, sizeof(struct MapCell)); |
152 | } |
152 | } |
153 | else { |
153 | else { |
154 | memcpy(&(newmap.cells[x][y]), |
154 | memcpy(&(newmap.cells[x][y]), |
155 | &(ns->lastmap.cells[x+dx][y+dy]),sizeof(struct MapCell)); |
155 | &(ns->lastmap.cells[x+dx][y+dy]),sizeof(struct MapCell)); |
156 | } |
156 | } |
157 | } |
157 | } |
158 | } |
158 | } |
159 | |
159 | |
160 | memcpy(&(ns->lastmap), &newmap,sizeof(struct Map)); |
160 | memcpy(&(ns->lastmap), &newmap,sizeof(struct Map)); |
161 | |
161 | |
162 | /* Make sure that the next "map1" command will be sent (even if it is |
162 | /* Make sure that the next "map1" command will be sent (even if it is |
163 | * empty). |
163 | * empty). |
164 | */ |
164 | */ |
165 | ns->sent_scroll = 1; |
165 | ns->sent_scroll = 1; |
|
|
166 | } |
|
|
167 | |
|
|
168 | static void |
|
|
169 | clear_map (player *pl) |
|
|
170 | { |
|
|
171 | NewSocket &socket = pl->socket; |
|
|
172 | |
|
|
173 | memset (&socket.lastmap, 0, sizeof (socket.lastmap)); |
|
|
174 | |
|
|
175 | if (socket.newmapcmd == 1) |
|
|
176 | Write_String_To_Socket (&socket, "newmap", 6); |
|
|
177 | |
|
|
178 | socket.update_look = 1; |
|
|
179 | socket.look_position = 0; |
166 | } |
180 | } |
167 | |
181 | |
168 | /** check for map change and send new map data */ |
182 | /** check for map change and send new map data */ |
169 | static void |
183 | static void |
170 | check_map_change (player *pl) |
184 | check_map_change (player *pl) |
… | |
… | |
174 | char buf[MAX_BUF]; /* eauugggh */ |
188 | char buf[MAX_BUF]; /* eauugggh */ |
175 | |
189 | |
176 | if (socket.current_map != ob->map) |
190 | if (socket.current_map != ob->map) |
177 | { |
191 | { |
178 | socket.current_map = ob->map; |
192 | socket.current_map = ob->map; |
179 | memset (&socket.lastmap, 0, sizeof(socket.lastmap)); |
|
|
180 | |
193 | |
181 | if (socket.newmapcmd == 1) |
194 | clear_map (pl); |
182 | Write_String_To_Socket (&socket, "newmap", 6); |
|
|
183 | |
|
|
184 | socket.update_look = 1; |
|
|
185 | socket.look_position =0; |
|
|
186 | |
195 | |
187 | if (socket.mapinfocmd) |
196 | if (socket.mapinfocmd) |
188 | { |
197 | { |
189 | if (ob->map && ob->map->path [0]) |
198 | if (ob->map && ob->map->path [0]) |
190 | { |
199 | { |
… | |
… | |
205 | Write_String_To_Socket (&socket, buf, strlen (buf)); |
214 | Write_String_To_Socket (&socket, buf, strlen (buf)); |
206 | } |
215 | } |
207 | } |
216 | } |
208 | else if (socket.current_x != ob->x || socket.current_y != ob->y) |
217 | else if (socket.current_x != ob->x || socket.current_y != ob->y) |
209 | { |
218 | { |
|
|
219 | int dx = ob->x - socket.current_x; |
|
|
220 | int dy = ob->y - socket.current_y; |
|
|
221 | |
|
|
222 | if (socket.buggy_mapscroll && (abs (dx) > 8 || abs (dy) > 8)) |
|
|
223 | clear_map (pl); // current (<= 1.9.1) clients have unchecked buffer overflows |
|
|
224 | else |
|
|
225 | { |
210 | socket_map_scroll (&socket, ob->x - socket.current_x, ob->y - socket.current_y); |
226 | socket_map_scroll (&socket, ob->x - socket.current_x, ob->y - socket.current_y); |
211 | socket.update_look = 1; |
227 | socket.update_look = 1; |
212 | socket.look_position = 0; |
228 | socket.look_position = 0; |
|
|
229 | } |
213 | } |
230 | } |
214 | |
231 | |
215 | socket.current_x = ob->x; |
232 | socket.current_x = ob->x; |
216 | socket.current_y = ob->y; |
233 | socket.current_y = ob->y; |
217 | } |
234 | } |
218 | |
235 | |
219 | void ExtCmd (char *buf, int len, player *pl) |
236 | void ExtCmd (char *buf, int len, player *pl) |
220 | { |
237 | { |
221 | execute_global_event (EVENT_EXTCMD, pl, buf, len); |
238 | INVOKE_PLAYER (EXTCMD, pl, ARG_DATA (buf, len)); |
222 | } |
239 | } |
223 | |
240 | |
224 | void MapInfoCmd (char *buf, int len, player *pl) |
241 | void MapInfoCmd (char *buf, int len, player *pl) |
225 | { |
242 | { |
226 | // <mapinfo tag spatial tile-path |
243 | // <mapinfo tag spatial tile-path |
… | |
… | |
312 | |
329 | |
313 | LOG(llevInfo,"Get SetupCmd:: %s\n", buf); |
330 | LOG(llevInfo,"Get SetupCmd:: %s\n", buf); |
314 | strcpy(cmdback,"setup"); |
331 | strcpy(cmdback,"setup"); |
315 | for(s=0;s<len; ) { |
332 | for(s=0;s<len; ) { |
316 | |
333 | |
317 | cmd = &buf[s]; |
334 | cmd = &buf[s]; |
318 | |
335 | |
319 | /* find the next space, and put a null there */ |
336 | /* find the next space, and put a null there */ |
320 | for(;buf[s] && buf[s] != ' ';s++) ; |
337 | for(;buf[s] && buf[s] != ' ';s++) ; |
321 | buf[s++]=0; |
338 | buf[s++]=0; |
322 | while (buf[s] == ' ') s++; |
339 | while (buf[s] == ' ') s++; |
323 | |
340 | |
324 | if(s>=len) |
341 | if(s>=len) |
325 | break; |
342 | break; |
326 | |
343 | |
327 | param = &buf[s]; |
344 | param = &buf[s]; |
328 | |
345 | |
329 | for(;buf[s] && buf[s] != ' ';s++) ; |
346 | for(;buf[s] && buf[s] != ' ';s++) ; |
330 | buf[s++]=0; |
347 | buf[s++]=0; |
331 | while (buf[s] == ' ') s++; |
348 | while (buf[s] == ' ') s++; |
332 | |
349 | |
333 | slen = strlen(cmdback); |
350 | slen = strlen(cmdback); |
334 | safe_strcat(cmdback, " ", &slen, HUGE_BUF); |
351 | safe_strcat(cmdback, " ", &slen, HUGE_BUF); |
335 | safe_strcat(cmdback, cmd, &slen, HUGE_BUF); |
352 | safe_strcat(cmdback, cmd, &slen, HUGE_BUF); |
336 | safe_strcat(cmdback, " ", &slen, HUGE_BUF); |
353 | safe_strcat(cmdback, " ", &slen, HUGE_BUF); |
337 | |
354 | |
338 | if (!strcmp(cmd,"sound")) { |
355 | if (!strcmp(cmd,"sound")) { |
339 | ns->sound = atoi(param); |
356 | ns->sound = atoi(param); |
340 | safe_strcat(cmdback, param, &slen, HUGE_BUF); |
357 | safe_strcat(cmdback, param, &slen, HUGE_BUF); |
341 | } |
358 | } |
342 | else if (!strcmp(cmd,"exp64")) { |
359 | else if (!strcmp(cmd,"exp64")) { |
343 | ns->exp64 = atoi(param); |
360 | ns->exp64 = atoi(param); |
344 | safe_strcat(cmdback, param, &slen, HUGE_BUF); |
361 | safe_strcat(cmdback, param, &slen, HUGE_BUF); |
345 | } else if (!strcmp(cmd, "spellmon")) { |
362 | } else if (!strcmp(cmd, "spellmon")) { |
346 | ns->monitor_spells = atoi(param); |
363 | ns->monitor_spells = atoi(param); |
347 | safe_strcat(cmdback, param, &slen, HUGE_BUF); |
364 | safe_strcat(cmdback, param, &slen, HUGE_BUF); |
348 | } else if (!strcmp(cmd,"darkness")) { |
365 | } else if (!strcmp(cmd,"darkness")) { |
349 | ns->darkness = atoi(param); |
366 | ns->darkness = atoi(param); |
350 | safe_strcat(cmdback, param, &slen, HUGE_BUF); |
367 | safe_strcat(cmdback, param, &slen, HUGE_BUF); |
351 | } else if (!strcmp(cmd,"map1cmd")) { |
368 | } else if (!strcmp(cmd,"map1cmd")) { |
352 | if (atoi(param)) ns->mapmode = Map1Cmd; |
369 | if (atoi(param)) ns->mapmode = Map1Cmd; |
353 | /* if beyond this size, need to use map1cmd no matter what */ |
370 | /* if beyond this size, need to use map1cmd no matter what */ |
354 | if (ns->mapx>11 || ns->mapy>11) ns->mapmode = Map1Cmd; |
371 | if (ns->mapx>11 || ns->mapy>11) ns->mapmode = Map1Cmd; |
355 | safe_strcat(cmdback, ns->mapmode == Map1Cmd?"1":"0", &slen, HUGE_BUF); |
372 | safe_strcat(cmdback, ns->mapmode == Map1Cmd?"1":"0", &slen, HUGE_BUF); |
356 | } else if (!strcmp(cmd,"map1acmd")) { |
373 | } else if (!strcmp(cmd,"map1acmd")) { |
357 | if (atoi(param)) ns->mapmode = Map1aCmd; |
374 | if (atoi(param)) ns->mapmode = Map1aCmd; |
358 | /* if beyond this size, need to use map1acmd no matter what */ |
375 | /* if beyond this size, need to use map1acmd no matter what */ |
359 | if (ns->mapx>11 || ns->mapy>11) ns->mapmode = Map1aCmd; |
376 | if (ns->mapx>11 || ns->mapy>11) ns->mapmode = Map1aCmd; |
360 | safe_strcat(cmdback, ns->mapmode == Map1aCmd?"1":"0", &slen, HUGE_BUF); |
377 | safe_strcat(cmdback, ns->mapmode == Map1aCmd?"1":"0", &slen, HUGE_BUF); |
361 | } else if (!strcmp(cmd,"newmapcmd")) { |
378 | } else if (!strcmp(cmd,"newmapcmd")) { |
362 | ns->newmapcmd= atoi(param); |
379 | ns->newmapcmd= atoi(param); |
363 | safe_strcat(cmdback, param, &slen, HUGE_BUF); |
380 | safe_strcat(cmdback, param, &slen, HUGE_BUF); |
364 | // } else if (!strcmp(cmd,"plugincmd")) { |
381 | // } else if (!strcmp(cmd,"plugincmd")) { |
365 | // ns->plugincmd = atoi(param); |
382 | // ns->plugincmd = atoi(param); |
366 | // safe_strcat(cmdback, param, &slen, HUGE_BUF); |
383 | // safe_strcat(cmdback, param, &slen, HUGE_BUF); |
367 | } else if (!strcmp(cmd,"mapinfocmd")) { |
384 | } else if (!strcmp(cmd,"mapinfocmd")) { |
368 | ns->mapinfocmd = atoi(param); |
385 | ns->mapinfocmd = atoi(param); |
369 | safe_strcat(cmdback, "1", &slen, HUGE_BUF); |
386 | safe_strcat(cmdback, "1", &slen, HUGE_BUF); |
370 | } else if (!strcmp(cmd,"extcmd")) { |
387 | } else if (!strcmp(cmd,"extcmd")) { |
371 | ns->extcmd = atoi(param); |
388 | ns->extcmd = atoi(param); |
372 | safe_strcat(cmdback, "1", &slen, HUGE_BUF); |
389 | safe_strcat(cmdback, "1", &slen, HUGE_BUF); |
373 | } else if (!strcmp(cmd,"extmap")) { |
390 | } else if (!strcmp(cmd,"extmap")) { |
374 | ns->extmap = atoi(param); |
391 | ns->extmap = atoi(param); |
375 | safe_strcat(cmdback, "1", &slen, HUGE_BUF); |
392 | safe_strcat(cmdback, "1", &slen, HUGE_BUF); |
376 | } else if (!strcmp(cmd,"facecache")) { |
393 | } else if (!strcmp(cmd,"facecache")) { |
377 | ns->facecache = atoi(param); |
394 | ns->facecache = atoi(param); |
378 | safe_strcat(cmdback, param, &slen, HUGE_BUF); |
395 | safe_strcat(cmdback, param, &slen, HUGE_BUF); |
379 | } else if (!strcmp(cmd,"faceset")) { |
396 | } else if (!strcmp(cmd,"faceset")) { |
380 | char tmpbuf[20]; |
397 | char tmpbuf[20]; |
381 | int q = atoi(param); |
398 | int q = atoi(param); |
382 | |
399 | |
383 | if (is_valid_faceset(q)) |
400 | if (is_valid_faceset(q)) |
384 | ns->faceset=q; |
401 | ns->faceset=q; |
385 | sprintf(tmpbuf,"%d", ns->faceset); |
402 | sprintf(tmpbuf,"%d", ns->faceset); |
386 | safe_strcat(cmdback, tmpbuf, &slen, HUGE_BUF); |
403 | safe_strcat(cmdback, tmpbuf, &slen, HUGE_BUF); |
387 | /* if the client is using faceset, it knows about image2 command */ |
404 | /* if the client is using faceset, it knows about image2 command */ |
388 | ns->image2=1; |
405 | ns->image2=1; |
389 | } else if (!strcmp(cmd,"itemcmd")) { |
406 | } else if (!strcmp(cmd,"itemcmd")) { |
390 | /* Version of the item protocol command to use. Currently, |
407 | /* Version of the item protocol command to use. Currently, |
391 | * only supported versions are 1 and 2. Using a numeric |
408 | * only supported versions are 1 and 2. Using a numeric |
392 | * value will make it very easy to extend this in the future. |
409 | * value will make it very easy to extend this in the future. |
393 | */ |
410 | */ |
394 | char tmpbuf[20]; |
411 | char tmpbuf[20]; |
395 | int q = atoi(param); |
412 | int q = atoi(param); |
396 | if (q<1 || q>2) { |
413 | if (q<1 || q>2) { |
397 | strcpy(tmpbuf,"FALSE"); |
414 | strcpy(tmpbuf,"FALSE"); |
398 | } else { |
415 | } else { |
399 | ns->itemcmd = q; |
416 | ns->itemcmd = q; |
400 | sprintf(tmpbuf,"%d", ns->itemcmd); |
417 | sprintf(tmpbuf,"%d", ns->itemcmd); |
401 | } |
418 | } |
402 | safe_strcat(cmdback, tmpbuf, &slen, HUGE_BUF); |
419 | safe_strcat(cmdback, tmpbuf, &slen, HUGE_BUF); |
403 | } else if (!strcmp(cmd,"mapsize")) { |
420 | } else if (!strcmp(cmd,"mapsize")) { |
404 | int x, y=0; |
421 | int x, y=0; |
405 | char tmpbuf[MAX_BUF], *cp; |
422 | char tmpbuf[MAX_BUF], *cp; |
406 | |
423 | |
407 | x = atoi(param); |
424 | x = atoi(param); |
408 | for (cp = param; *cp!=0; cp++) |
425 | for (cp = param; *cp!=0; cp++) |
409 | if (*cp == 'x' || *cp == 'X') { |
426 | if (*cp == 'x' || *cp == 'X') { |
410 | y = atoi(cp+1); |
427 | y = atoi(cp+1); |
411 | break; |
428 | break; |
412 | } |
429 | } |
413 | if (x < 9 || y < 9 || x>MAP_CLIENT_X || y > MAP_CLIENT_Y) { |
430 | if (x < 9 || y < 9 || x>MAP_CLIENT_X || y > MAP_CLIENT_Y) { |
414 | sprintf(tmpbuf," %dx%d", MAP_CLIENT_X, MAP_CLIENT_Y); |
431 | sprintf(tmpbuf," %dx%d", MAP_CLIENT_X, MAP_CLIENT_Y); |
415 | safe_strcat(cmdback, tmpbuf, &slen, HUGE_BUF); |
432 | safe_strcat(cmdback, tmpbuf, &slen, HUGE_BUF); |
416 | } else { |
433 | } else { |
417 | ns->mapx = x; |
434 | ns->mapx = x; |
418 | ns->mapy = y; |
435 | ns->mapy = y; |
419 | /* better to send back what we are really using and not the |
436 | /* better to send back what we are really using and not the |
420 | * param as given to us in case it gets parsed differently. |
437 | * param as given to us in case it gets parsed differently. |
421 | */ |
438 | */ |
422 | sprintf(tmpbuf,"%dx%d", x,y); |
439 | sprintf(tmpbuf,"%dx%d", x,y); |
423 | safe_strcat(cmdback, tmpbuf, &slen, HUGE_BUF); |
440 | safe_strcat(cmdback, tmpbuf, &slen, HUGE_BUF); |
424 | /* If beyond this size and still using orig map command, need to |
441 | /* If beyond this size and still using orig map command, need to |
425 | * go to map1cmd. |
442 | * go to map1cmd. |
426 | */ |
443 | */ |
427 | if ((x>11 || y>11) && ns->mapmode == Map0Cmd) ns->mapmode = Map1Cmd; |
444 | if ((x>11 || y>11) && ns->mapmode == Map0Cmd) ns->mapmode = Map1Cmd; |
428 | } |
445 | } |
429 | } else if (!strcmp(cmd,"extendedMapInfos")) { |
446 | } else if (!strcmp(cmd,"extendedMapInfos")) { |
430 | /* Added by tchize |
447 | /* Added by tchize |
431 | * prepare to use the mapextended command |
448 | * prepare to use the mapextended command |
432 | */ |
449 | */ |
433 | char tmpbuf[20]; |
450 | char tmpbuf[20]; |
434 | ns->ext_mapinfos = (atoi(param)); |
451 | ns->ext_mapinfos = (atoi(param)); |
435 | sprintf(tmpbuf,"%d", ns->ext_mapinfos); |
452 | sprintf(tmpbuf,"%d", ns->ext_mapinfos); |
436 | safe_strcat(cmdback, tmpbuf, &slen, HUGE_BUF); |
453 | safe_strcat(cmdback, tmpbuf, &slen, HUGE_BUF); |
437 | } else if (!strcmp(cmd,"extendedTextInfos")) { |
454 | } else if (!strcmp(cmd,"extendedTextInfos")) { |
438 | /* Added by tchize |
455 | /* Added by tchize |
439 | * prepare to use the extended text commands |
456 | * prepare to use the extended text commands |
440 | * Client toggle this to non zero to get exttext |
457 | * Client toggle this to non zero to get exttext |
441 | */ |
458 | */ |
442 | char tmpbuf[20]; |
459 | char tmpbuf[20]; |
443 | |
460 | |
444 | ns->has_readable_type = (atoi(param)); |
461 | ns->has_readable_type = (atoi(param)); |
445 | sprintf(tmpbuf,"%d", ns->has_readable_type); |
462 | sprintf(tmpbuf,"%d", ns->has_readable_type); |
446 | safe_strcat(cmdback, tmpbuf, &slen, HUGE_BUF); |
463 | safe_strcat(cmdback, tmpbuf, &slen, HUGE_BUF); |
447 | } else { |
464 | } else { |
448 | /* Didn't get a setup command we understood - |
465 | /* Didn't get a setup command we understood - |
449 | * report a failure to the client. |
466 | * report a failure to the client. |
450 | */ |
467 | */ |
451 | safe_strcat(cmdback, "FALSE", &slen, HUGE_BUF); |
468 | safe_strcat(cmdback, "FALSE", &slen, HUGE_BUF); |
452 | } |
469 | } |
453 | } /* for processing all the setup commands */ |
470 | } /* for processing all the setup commands */ |
454 | LOG(llevInfo,"SendBack SetupCmd:: %s\n", cmdback); |
471 | LOG(llevInfo,"SendBack SetupCmd:: %s\n", cmdback); |
455 | Write_String_To_Socket(ns, cmdback, strlen(cmdback)); |
472 | Write_String_To_Socket(ns, cmdback, strlen(cmdback)); |
456 | } |
473 | } |
457 | |
474 | |
… | |
… | |
464 | void AddMeCmd(char *buf, int len, NewSocket *ns) |
481 | void AddMeCmd(char *buf, int len, NewSocket *ns) |
465 | { |
482 | { |
466 | Settings oldsettings; |
483 | Settings oldsettings; |
467 | oldsettings=settings; |
484 | oldsettings=settings; |
468 | if (ns->status != Ns_Add || add_player(ns)) { |
485 | if (ns->status != Ns_Add || add_player(ns)) { |
469 | Write_String_To_Socket(ns, "addme_failed",12); |
486 | Write_String_To_Socket(ns, "addme_failed",12); |
470 | } else { |
487 | } else { |
471 | /* Basically, the add_player copies the socket structure into |
488 | /* Basically, the add_player copies the socket structure into |
472 | * the player structure, so this one (which is from init_sockets) |
489 | * the player structure, so this one (which is from init_sockets) |
473 | * is not needed anymore. The write below should still work, as the |
490 | * is not needed anymore. The write below should still work, as the |
474 | * stuff in ns is still relevant. |
491 | * stuff in ns is still relevant. |
475 | */ |
492 | */ |
476 | Write_String_To_Socket(ns, "addme_success",13); |
493 | Write_String_To_Socket(ns, "addme_success",13); |
477 | socket_info.nconns--; |
494 | socket_info.nconns--; |
478 | ns->status = Ns_Avail; |
495 | ns->status = Ns_Avail; |
479 | } |
496 | } |
480 | settings=oldsettings; |
497 | settings=oldsettings; |
481 | } |
498 | } |
482 | |
499 | |
483 | /** Reply to ExtendedInfos command */ |
500 | /** Reply to ExtendedInfos command */ |
… | |
… | |
577 | * again. |
594 | * again. |
578 | */ |
595 | */ |
579 | if ((!FindSmooth (face, &smoothface)) && |
596 | if ((!FindSmooth (face, &smoothface)) && |
580 | (!FindSmooth ( smooth_face->number, &smoothface))) { |
597 | (!FindSmooth ( smooth_face->number, &smoothface))) { |
581 | |
598 | |
582 | LOG(llevError,"could not findsmooth for %d. Neither default (%s)\n",face,smooth_face->name); |
599 | LOG(llevError,"could not findsmooth for %d. Neither default (%s)\n", face, &smooth_face->name); |
583 | ns->faces_sent[face] |= NS_FACESENT_SMOOTH; |
600 | ns->faces_sent[face] |= NS_FACESENT_SMOOTH; |
584 | return; |
601 | return; |
585 | } |
602 | } |
586 | |
603 | |
587 | if (!(ns->faces_sent[smoothface] & NS_FACESENT_FACE)) |
604 | if (!(ns->faces_sent[smoothface] & NS_FACESENT_FACE)) |
588 | esrv_send_face(ns, smoothface, 0); |
605 | esrv_send_face(ns, smoothface, 0); |
589 | |
606 | |
590 | ns->faces_sent[face] |= NS_FACESENT_SMOOTH; |
607 | ns->faces_sent[face] |= NS_FACESENT_SMOOTH; |
591 | |
608 | |
592 | sl.buf=reply; |
609 | sl.buf=reply; |
593 | strcpy((char*)sl.buf,"smooth "); |
610 | strcpy((char*)sl.buf,"smooth "); |
… | |
… | |
623 | * Therefore, the error message doesn't have to be too clear - if |
640 | * Therefore, the error message doesn't have to be too clear - if |
624 | * someone is playing with a hacked/non working client, this gives them |
641 | * someone is playing with a hacked/non working client, this gives them |
625 | * an idea of the problem, but they deserve what they get |
642 | * an idea of the problem, but they deserve what they get |
626 | */ |
643 | */ |
627 | if (pl->state!=ST_PLAYING) { |
644 | if (pl->state!=ST_PLAYING) { |
628 | new_draw_info_format(NDI_UNIQUE, 0,pl->ob, |
645 | new_draw_info_format(NDI_UNIQUE, 0,pl->ob, |
629 | "You can not issue commands - state is not ST_PLAYING (%s)", buf); |
646 | "You can not issue commands - state is not ST_PLAYING (%s)", buf); |
630 | return; |
647 | return; |
631 | } |
648 | } |
632 | /* Check if there is a count. In theory, a zero count could also be |
649 | /* Check if there is a count. In theory, a zero count could also be |
633 | * sent, so check for that also. |
650 | * sent, so check for that also. |
634 | */ |
651 | */ |
635 | if (atoi(buf) || buf[0]=='0') { |
652 | if (atoi(buf) || buf[0]=='0') { |
636 | pl->count=atoi((char*)buf); |
653 | pl->count=atoi((char*)buf); |
637 | buf=strchr(buf,' '); /* advance beyond the numbers */ |
654 | buf=strchr(buf,' '); /* advance beyond the numbers */ |
638 | if (!buf) { |
655 | if (!buf) { |
639 | #ifdef ESRV_DEBUG |
656 | #ifdef ESRV_DEBUG |
640 | LOG(llevDebug,"PlayerCmd: Got count but no command.\n"); |
657 | LOG(llevDebug,"PlayerCmd: Got count but no command.\n"); |
641 | #endif |
658 | #endif |
642 | return; |
659 | return; |
643 | } |
660 | } |
644 | buf++; |
661 | buf++; |
645 | } |
662 | } |
646 | /* This should not happen anymore. */ |
663 | /* This should not happen anymore. */ |
647 | if (pl->ob->speed_left<-1.0) { |
664 | if (pl->ob->speed_left<-1.0) { |
648 | LOG(llevError,"Player has negative time - shouldn't do command.\n"); |
665 | LOG(llevError,"Player has negative time - shouldn't do command.\n"); |
649 | } |
666 | } |
650 | /* In c_new.c */ |
667 | /* In c_new.c */ |
651 | execute_newserver_command(pl->ob, (char*)buf); |
668 | execute_newserver_command(pl->ob, (char*)buf); |
652 | /* Perhaps something better should be done with a left over count. |
669 | /* Perhaps something better should be done with a left over count. |
653 | * Cleaning up the input should probably be done first - all actions |
670 | * Cleaning up the input should probably be done first - all actions |
… | |
… | |
672 | short packet; |
689 | short packet; |
673 | unsigned char command[MAX_BUF]; |
690 | unsigned char command[MAX_BUF]; |
674 | SockList sl; |
691 | SockList sl; |
675 | |
692 | |
676 | if (len < 7) { |
693 | if (len < 7) { |
677 | LOG(llevDebug,"Corrupt ncom command <%s> not long enough - discarding\n", buf); |
694 | LOG(llevDebug,"Corrupt ncom command <%s> not long enough - discarding\n", buf); |
678 | return; |
695 | return; |
679 | } |
696 | } |
680 | |
697 | |
681 | packet = GetShort_String(buf); |
698 | packet = GetShort_String(buf); |
682 | repeat = GetInt_String(buf+2); |
699 | repeat = GetInt_String(buf+2); |
683 | /* -1 is special - no repeat, but don't update */ |
700 | /* -1 is special - no repeat, but don't update */ |
684 | if (repeat!=-1) { |
701 | if (repeat!=-1) { |
685 | pl->count=repeat; |
702 | pl->count=repeat; |
686 | } |
703 | } |
687 | if ((len-4) >= MAX_BUF) len=MAX_BUF-5; |
704 | if ((len-4) >= MAX_BUF) len=MAX_BUF-5; |
688 | |
705 | |
689 | strncpy((char*)command, (char*)buf+6, len-4); |
706 | strncpy((char*)command, (char*)buf+6, len-4); |
690 | command[len-4]='\0'; |
707 | command[len-4]='\0'; |
… | |
… | |
693 | * Therefore, the error message doesn't have to be too clear - if |
710 | * Therefore, the error message doesn't have to be too clear - if |
694 | * someone is playing with a hacked/non working client, this gives them |
711 | * someone is playing with a hacked/non working client, this gives them |
695 | * an idea of the problem, but they deserve what they get |
712 | * an idea of the problem, but they deserve what they get |
696 | */ |
713 | */ |
697 | if (pl->state!=ST_PLAYING) { |
714 | if (pl->state!=ST_PLAYING) { |
698 | new_draw_info_format(NDI_UNIQUE, 0,pl->ob, |
715 | new_draw_info_format(NDI_UNIQUE, 0,pl->ob, |
699 | "You can not issue commands - state is not ST_PLAYING (%s)", buf); |
716 | "You can not issue commands - state is not ST_PLAYING (%s)", buf); |
700 | return; |
717 | return; |
701 | } |
718 | } |
702 | |
719 | |
703 | /* This should not happen anymore. */ |
720 | /* This should not happen anymore. */ |
704 | if (pl->ob->speed_left<-1.0) { |
721 | if (pl->ob->speed_left<-1.0) { |
705 | LOG(llevError,"Player has negative time - shouldn't do command.\n"); |
722 | LOG(llevError,"Player has negative time - shouldn't do command.\n"); |
706 | } |
723 | } |
707 | /* In c_new.c */ |
724 | /* In c_new.c */ |
708 | execute_newserver_command(pl->ob, (char*)command); |
725 | execute_newserver_command(pl->ob, (char*)command); |
709 | /* Perhaps something better should be done with a left over count. |
726 | /* Perhaps something better should be done with a left over count. |
710 | * Cleaning up the input should probably be done first - all actions |
727 | * Cleaning up the input should probably be done first - all actions |
… | |
… | |
718 | strcpy((char*)sl.buf,"comc "); |
735 | strcpy((char*)sl.buf,"comc "); |
719 | sl.len=5; |
736 | sl.len=5; |
720 | SockList_AddShort(&sl,packet); |
737 | SockList_AddShort(&sl,packet); |
721 | if (FABS(pl->ob->speed) < 0.001) time=MAX_TIME * 100; |
738 | if (FABS(pl->ob->speed) < 0.001) time=MAX_TIME * 100; |
722 | else |
739 | else |
723 | time = ( int )( MAX_TIME/ FABS(pl->ob->speed) ); |
740 | time = ( int )( MAX_TIME/ FABS(pl->ob->speed) ); |
724 | SockList_AddInt(&sl,time); |
741 | SockList_AddInt(&sl,time); |
725 | Send_With_Handling(&pl->socket, &sl); |
742 | Send_With_Handling(&pl->socket, &sl); |
726 | } |
743 | } |
727 | |
744 | |
728 | |
745 | |
… | |
… | |
740 | snprintf(pl->write_buf, sizeof(pl->write_buf), ":%s", buf); |
757 | snprintf(pl->write_buf, sizeof(pl->write_buf), ":%s", buf); |
741 | |
758 | |
742 | /* this avoids any hacking here */ |
759 | /* this avoids any hacking here */ |
743 | |
760 | |
744 | switch (pl->state) { |
761 | switch (pl->state) { |
745 | case ST_PLAYING: |
762 | case ST_PLAYING: |
746 | LOG(llevError,"Got reply message with ST_PLAYING input state\n"); |
763 | LOG(llevError,"Got reply message with ST_PLAYING input state\n"); |
747 | break; |
764 | break; |
748 | |
765 | |
749 | case ST_PLAY_AGAIN: |
766 | case ST_PLAY_AGAIN: |
750 | /* We can check this for return value (2==quit). Maybe we |
767 | /* We can check this for return value (2==quit). Maybe we |
751 | * should, and do something appropriate? |
768 | * should, and do something appropriate? |
752 | */ |
769 | */ |
753 | receive_play_again(pl->ob, buf[0]); |
770 | receive_play_again(pl->ob, buf[0]); |
754 | break; |
771 | break; |
755 | |
772 | |
756 | case ST_ROLL_STAT: |
773 | case ST_ROLL_STAT: |
757 | key_roll_stat(pl->ob,buf[0]); |
774 | key_roll_stat(pl->ob,buf[0]); |
758 | break; |
775 | break; |
759 | |
776 | |
760 | case ST_CHANGE_CLASS: |
777 | case ST_CHANGE_CLASS: |
761 | |
778 | |
762 | key_change_class(pl->ob, buf[0]); |
779 | key_change_class(pl->ob, buf[0]); |
763 | break; |
780 | break; |
764 | |
781 | |
765 | case ST_CONFIRM_QUIT: |
782 | case ST_CONFIRM_QUIT: |
766 | key_confirm_quit(pl->ob, buf[0]); |
783 | key_confirm_quit(pl->ob, buf[0]); |
767 | break; |
784 | break; |
768 | |
785 | |
769 | case ST_CONFIGURE: |
786 | case ST_CONFIGURE: |
770 | LOG(llevError,"In client input handling, but into configure state\n"); |
787 | LOG(llevError,"In client input handling, but into configure state\n"); |
771 | pl->state = ST_PLAYING; |
788 | pl->state = ST_PLAYING; |
772 | break; |
789 | break; |
773 | |
790 | |
774 | case ST_GET_NAME: |
791 | case ST_GET_NAME: |
775 | receive_player_name(pl->ob,13); |
792 | receive_player_name(pl->ob,13); |
776 | break; |
793 | break; |
777 | |
794 | |
778 | case ST_GET_PASSWORD: |
795 | case ST_GET_PASSWORD: |
779 | case ST_CONFIRM_PASSWORD: |
796 | case ST_CONFIRM_PASSWORD: |
780 | receive_player_password(pl->ob,13); |
797 | receive_player_password(pl->ob,13); |
781 | break; |
798 | break; |
782 | |
799 | |
783 | case ST_GET_PARTY_PASSWORD: /* Get password for party */ |
800 | case ST_GET_PARTY_PASSWORD: /* Get password for party */ |
784 | receive_party_password(pl->ob,13); |
801 | receive_party_password(pl->ob,13); |
785 | break; |
802 | break; |
786 | |
803 | |
787 | default: |
804 | default: |
788 | LOG(llevError,"Unknown input state: %d\n", pl->state); |
805 | LOG(llevError,"Unknown input state: %d\n", pl->state); |
789 | } |
806 | } |
790 | } |
807 | } |
791 | |
808 | |
792 | /** |
809 | /** |
793 | * Client tells its version. If there is a mismatch, we close the |
810 | * Client tells its version. If there is a mismatch, we close the |
… | |
… | |
798 | */ |
815 | */ |
799 | void VersionCmd(char *buf, int len,NewSocket *ns) |
816 | void VersionCmd(char *buf, int len,NewSocket *ns) |
800 | { |
817 | { |
801 | char *cp; |
818 | char *cp; |
802 | char version_warning[256]; |
819 | char version_warning[256]; |
803 | |
820 | |
804 | if (!buf) { |
821 | if (!buf) { |
805 | LOG(llevError, "CS: received corrupted version command\n"); |
822 | LOG(llevError, "CS: received corrupted version command\n"); |
806 | return; |
823 | return; |
807 | } |
824 | } |
808 | |
825 | |
809 | ns->cs_version = atoi(buf); |
826 | ns->cs_version = atoi(buf); |
810 | ns->sc_version = ns->cs_version; |
827 | ns->sc_version = ns->cs_version; |
811 | if (VERSION_CS != ns->cs_version) { |
828 | if (VERSION_CS != ns->cs_version) { |
812 | #ifdef ESRV_DEBUG |
829 | #ifdef ESRV_DEBUG |
813 | LOG(llevDebug, "CS: csversion mismatch (%d,%d)\n", VERSION_CS,ns->cs_version); |
830 | LOG(llevDebug, "CS: csversion mismatch (%d,%d)\n", VERSION_CS,ns->cs_version); |
814 | #endif |
831 | #endif |
815 | } |
832 | } |
816 | cp = strchr(buf+1,' '); |
833 | cp = strchr(buf+1,' '); |
817 | if (!cp) return; |
834 | if (!cp) return; |
818 | ns->sc_version = atoi(cp); |
835 | ns->sc_version = atoi(cp); |
819 | if (VERSION_SC != ns->sc_version) { |
836 | if (VERSION_SC != ns->sc_version) { |
820 | #ifdef ESRV_DEBUG |
837 | #ifdef ESRV_DEBUG |
821 | LOG(llevDebug, "CS: scversion mismatch (%d,%d)\n",VERSION_SC,ns->sc_version); |
838 | LOG(llevDebug, "CS: scversion mismatch (%d,%d)\n",VERSION_SC,ns->sc_version); |
822 | #endif |
839 | #endif |
823 | } |
840 | } |
824 | cp = strchr(cp+1, ' '); |
841 | cp = strchr(cp+1, ' '); |
825 | if (cp) { |
842 | if (cp) { |
826 | LOG(llevDebug,"CS: connection from client of type <%s>, ip %s\n", cp, ns->host); |
843 | LOG(llevDebug,"CS: connection from client of type <%s>, ip %s\n", cp, ns->host); |
827 | |
844 | |
|
|
845 | snprintf (ns->client, sizeof (ns->client), "%s", cp + 1); |
|
|
846 | |
828 | /* This is first implementation - i skip all beta DX clients with it |
847 | /* This is first implementation - i skip all beta DX clients with it |
829 | * Add later stuff here for other clients |
848 | * Add later stuff here for other clients |
830 | */ |
849 | */ |
831 | |
850 | |
832 | /* these are old dxclients */ |
851 | /* these are old dxclients */ |
833 | /* Version 1024 added support for singular + plural name values - |
852 | /* Version 1024 added support for singular + plural name values - |
834 | * requiing this minimal value reduces complexity of that code, and it |
853 | * requiing this minimal value reduces complexity of that code, and it |
835 | * has been around for a long time. |
854 | * has been around for a long time. |
836 | */ |
855 | */ |
837 | if(!strcmp(" CF DX CLIENT", cp) || ns->sc_version < 1024 ) |
856 | if(!strcmp(" CF DX CLIENT", cp) || ns->sc_version < 1024 ) |
838 | { |
857 | { |
839 | sprintf(version_warning,"drawinfo %d %s", NDI_RED, "**** VERSION WARNING ****\n**** CLIENT IS TOO OLD!! UPDATE THE CLIENT!! ****"); |
858 | sprintf(version_warning,"drawinfo %d %s", NDI_RED, "**** VERSION WARNING ****\n**** CLIENT IS TOO OLD!! UPDATE THE CLIENT!! ****"); |
840 | Write_String_To_Socket(ns, version_warning, strlen(version_warning)); |
859 | Write_String_To_Socket(ns, version_warning, strlen(version_warning)); |
841 | } |
860 | } |
842 | |
861 | |
843 | } |
862 | } |
844 | } |
863 | } |
845 | |
864 | |
846 | /** sound related functions. */ |
865 | /** sound related functions. */ |
… | |
… | |
880 | * we obviously am not going to find a space after the third |
899 | * we obviously am not going to find a space after the third |
881 | * record. Perhaps we should just replace this with a |
900 | * record. Perhaps we should just replace this with a |
882 | * sscanf? |
901 | * sscanf? |
883 | */ |
902 | */ |
884 | for (i=0; i<2; i++) { |
903 | for (i=0; i<2; i++) { |
885 | vals[i]=atoi(buf); |
904 | vals[i]=atoi(buf); |
886 | if (!(buf = strchr(buf, ' '))) { |
905 | if (!(buf = strchr(buf, ' '))) { |
887 | LOG(llevError,"Incomplete move command: %s\n", buf); |
906 | LOG(llevError,"Incomplete move command: %s\n", buf); |
888 | return; |
907 | return; |
889 | } |
908 | } |
890 | buf++; |
909 | buf++; |
891 | } |
910 | } |
892 | vals[2]=atoi(buf); |
911 | vals[2]=atoi(buf); |
893 | |
912 | |
894 | /* LOG(llevDebug,"Move item %d (nrof=%d) to %d.\n", vals[1], vals[2], vals[0]);*/ |
913 | /* LOG(llevDebug,"Move item %d (nrof=%d) to %d.\n", vals[1], vals[2], vals[0]);*/ |
895 | esrv_move_object(pl->ob,vals[0], vals[1], vals[2]); |
914 | esrv_move_object(pl->ob,vals[0], vals[1], vals[2]); |
… | |
… | |
914 | sprintf(buf,"query %d %s", flags, text?text:""); |
933 | sprintf(buf,"query %d %s", flags, text?text:""); |
915 | Write_String_To_Socket(ns, buf, strlen(buf)); |
934 | Write_String_To_Socket(ns, buf, strlen(buf)); |
916 | } |
935 | } |
917 | |
936 | |
918 | #define AddIfInt64(Old,New,Type) if (Old != New) {\ |
937 | #define AddIfInt64(Old,New,Type) if (Old != New) {\ |
919 | Old = New; \ |
938 | Old = New; \ |
920 | SockList_AddChar(&sl, Type); \ |
939 | SockList_AddChar(&sl, Type); \ |
921 | SockList_AddInt64(&sl, New); \ |
940 | SockList_AddInt64(&sl, New); \ |
922 | } |
941 | } |
923 | |
942 | |
924 | #define AddIfInt(Old,New,Type) if (Old != New) {\ |
943 | #define AddIfInt(Old,New,Type) if (Old != New) {\ |
925 | Old = New; \ |
944 | Old = New; \ |
926 | SockList_AddChar(&sl, Type); \ |
945 | SockList_AddChar(&sl, Type); \ |
927 | SockList_AddInt(&sl, New); \ |
946 | SockList_AddInt(&sl, New); \ |
928 | } |
947 | } |
929 | |
948 | |
930 | #define AddIfShort(Old,New,Type) if (Old != New) {\ |
949 | #define AddIfShort(Old,New,Type) if (Old != New) {\ |
931 | Old = New; \ |
950 | Old = New; \ |
932 | SockList_AddChar(&sl, Type); \ |
951 | SockList_AddChar(&sl, Type); \ |
933 | SockList_AddShort(&sl, New); \ |
952 | SockList_AddShort(&sl, New); \ |
934 | } |
953 | } |
935 | |
954 | |
936 | #define AddIfFloat(Old,New,Type) if (Old != New) {\ |
955 | #define AddIfFloat(Old,New,Type) if (Old != New) {\ |
937 | Old = New; \ |
956 | Old = New; \ |
938 | SockList_AddChar(&sl, Type); \ |
957 | SockList_AddChar(&sl, Type); \ |
939 | SockList_AddInt(&sl,(long)(New*FLOAT_MULTI));\ |
958 | SockList_AddInt(&sl,(long)(New*FLOAT_MULTI));\ |
940 | } |
959 | } |
941 | |
960 | |
942 | #define AddIfString(Old,New,Type) if (Old == NULL || strcmp(Old,New)) {\ |
961 | #define AddIfString(Old,New,Type) if (Old == NULL || strcmp(Old,New)) {\ |
943 | if (Old) free(Old);\ |
962 | if (Old) free(Old);\ |
944 | Old = strdup_local(New);\ |
963 | Old = strdup_local(New);\ |
945 | SockList_AddChar(&sl, Type); \ |
964 | SockList_AddChar(&sl, Type); \ |
946 | SockList_AddChar(&sl, ( char )strlen(New)); \ |
965 | SockList_AddChar(&sl, ( char )strlen(New)); \ |
947 | strcpy((char*)sl.buf + sl.len, New); \ |
966 | strcpy((char*)sl.buf + sl.len, New); \ |
948 | sl.len += strlen(New); \ |
967 | sl.len += strlen(New); \ |
949 | } |
968 | } |
950 | |
969 | |
951 | /** |
970 | /** |
952 | * Sends a statistics update. We look at the old values, |
971 | * Sends a statistics update. We look at the old values, |
953 | * and only send what has changed. Stat mapping values are in newclient.h |
972 | * and only send what has changed. Stat mapping values are in newclient.h |
954 | * Since this gets sent a lot, this is actually one of the few binary |
973 | * Since this gets sent a lot, this is actually one of the few binary |
… | |
… | |
979 | AddIfShort(pl->last_stats.Dex, pl->ob->stats.Dex, CS_STAT_DEX); |
998 | AddIfShort(pl->last_stats.Dex, pl->ob->stats.Dex, CS_STAT_DEX); |
980 | AddIfShort(pl->last_stats.Con, pl->ob->stats.Con, CS_STAT_CON); |
999 | AddIfShort(pl->last_stats.Con, pl->ob->stats.Con, CS_STAT_CON); |
981 | AddIfShort(pl->last_stats.Cha, pl->ob->stats.Cha, CS_STAT_CHA); |
1000 | AddIfShort(pl->last_stats.Cha, pl->ob->stats.Cha, CS_STAT_CHA); |
982 | } |
1001 | } |
983 | if(pl->socket.exp64) { |
1002 | if(pl->socket.exp64) { |
984 | uint8 s; |
1003 | uint8 s; |
985 | for(s=0;s<NUM_SKILLS;s++) { |
1004 | for(s=0;s<NUM_SKILLS;s++) { |
986 | if (pl->last_skill_ob[s] && |
1005 | if (pl->last_skill_ob[s] && |
987 | pl->last_skill_exp[s] != pl->last_skill_ob[s]->stats.exp) { |
1006 | pl->last_skill_exp[s] != pl->last_skill_ob[s]->stats.exp) { |
988 | |
1007 | |
989 | /* Always send along the level if exp changes. This is only |
1008 | /* Always send along the level if exp changes. This is only |
990 | * 1 extra byte, but keeps processing simpler. |
1009 | * 1 extra byte, but keeps processing simpler. |
991 | */ |
1010 | */ |
992 | SockList_AddChar(&sl, ( char )( s + CS_STAT_SKILLINFO )); |
1011 | SockList_AddChar(&sl, ( char )( s + CS_STAT_SKILLINFO )); |
993 | SockList_AddChar(&sl, ( char )pl->last_skill_ob[s]->level); |
1012 | SockList_AddChar(&sl, ( char )pl->last_skill_ob[s]->level); |
994 | SockList_AddInt64(&sl, pl->last_skill_ob[s]->stats.exp); |
1013 | SockList_AddInt64(&sl, pl->last_skill_ob[s]->stats.exp); |
995 | pl->last_skill_exp[s] = pl->last_skill_ob[s]->stats.exp; |
1014 | pl->last_skill_exp[s] = pl->last_skill_ob[s]->stats.exp; |
996 | } |
1015 | } |
997 | } |
1016 | } |
998 | } |
1017 | } |
999 | if (pl->socket.exp64) { |
1018 | if (pl->socket.exp64) { |
1000 | AddIfInt64(pl->last_stats.exp, pl->ob->stats.exp, CS_STAT_EXP64); |
1019 | AddIfInt64(pl->last_stats.exp, pl->ob->stats.exp, CS_STAT_EXP64); |
1001 | } else { |
1020 | } else { |
1002 | AddIfInt(pl->last_stats.exp, ( int )pl->ob->stats.exp, CS_STAT_EXP); |
1021 | AddIfInt(pl->last_stats.exp, ( int )pl->ob->stats.exp, CS_STAT_EXP); |
1003 | } |
1022 | } |
1004 | AddIfShort(pl->last_level, ( char )pl->ob->level, CS_STAT_LEVEL); |
1023 | AddIfShort(pl->last_level, ( char )pl->ob->level, CS_STAT_LEVEL); |
1005 | AddIfShort(pl->last_stats.wc, pl->ob->stats.wc, CS_STAT_WC); |
1024 | AddIfShort(pl->last_stats.wc, pl->ob->stats.wc, CS_STAT_WC); |
1006 | AddIfShort(pl->last_stats.ac, pl->ob->stats.ac, CS_STAT_AC); |
1025 | AddIfShort(pl->last_stats.ac, pl->ob->stats.ac, CS_STAT_AC); |
1007 | AddIfShort(pl->last_stats.dam, pl->ob->stats.dam, CS_STAT_DAM); |
1026 | AddIfShort(pl->last_stats.dam, pl->ob->stats.dam, CS_STAT_DAM); |
… | |
… | |
1013 | if (pl->fire_on) flags |=SF_FIREON; |
1032 | if (pl->fire_on) flags |=SF_FIREON; |
1014 | if (pl->run_on) flags |= SF_RUNON; |
1033 | if (pl->run_on) flags |= SF_RUNON; |
1015 | |
1034 | |
1016 | AddIfShort(pl->last_flags, flags, CS_STAT_FLAGS); |
1035 | AddIfShort(pl->last_flags, flags, CS_STAT_FLAGS); |
1017 | if (pl->socket.sc_version<1025) { |
1036 | if (pl->socket.sc_version<1025) { |
1018 | AddIfShort(pl->last_resist[ATNR_PHYSICAL], pl->ob->resist[ATNR_PHYSICAL], CS_STAT_ARMOUR); |
1037 | AddIfShort(pl->last_resist[ATNR_PHYSICAL], pl->ob->resist[ATNR_PHYSICAL], CS_STAT_ARMOUR); |
1019 | } else { |
1038 | } else { |
1020 | int i; |
1039 | int i; |
1021 | |
1040 | |
1022 | for (i=0; i<NROFATTACKS; i++) { |
1041 | for (i=0; i<NROFATTACKS; i++) { |
1023 | /* Skip ones we won't send */ |
1042 | /* Skip ones we won't send */ |
1024 | if (atnr_cs_stat[i]==-1) continue; |
1043 | if (atnr_cs_stat[i]==-1) continue; |
1025 | AddIfShort(pl->last_resist[i], pl->ob->resist[i], ( char )atnr_cs_stat[i]); |
1044 | AddIfShort(pl->last_resist[i], pl->ob->resist[i], ( char )atnr_cs_stat[i]); |
1026 | } |
1045 | } |
1027 | } |
1046 | } |
1028 | if (pl->socket.monitor_spells) { |
1047 | if (pl->socket.monitor_spells) { |
1029 | AddIfInt(pl->last_path_attuned, pl->ob->path_attuned, CS_STAT_SPELL_ATTUNE); |
1048 | AddIfInt(pl->last_path_attuned, pl->ob->path_attuned, CS_STAT_SPELL_ATTUNE); |
1030 | AddIfInt(pl->last_path_repelled, pl->ob->path_repelled, CS_STAT_SPELL_REPEL); |
1049 | AddIfInt(pl->last_path_repelled, pl->ob->path_repelled, CS_STAT_SPELL_REPEL); |
1031 | AddIfInt(pl->last_path_denied, pl->ob->path_denied, CS_STAT_SPELL_DENY); |
1050 | AddIfInt(pl->last_path_denied, pl->ob->path_denied, CS_STAT_SPELL_DENY); |
1032 | } |
1051 | } |
1033 | rangetostring(pl->ob, buf); /* we want use the new fire & run system in new client */ |
1052 | rangetostring(pl->ob, buf); /* we want use the new fire & run system in new client */ |
1034 | AddIfString(pl->socket.stats.range, buf, CS_STAT_RANGE); |
1053 | AddIfString(pl->socket.stats.range, buf, CS_STAT_RANGE); |
1035 | set_title(pl->ob, buf); |
1054 | set_title(pl->ob, buf); |
1036 | AddIfString(pl->socket.stats.title, buf, CS_STAT_TITLE); |
1055 | AddIfString(pl->socket.stats.title, buf, CS_STAT_TITLE); |
1037 | |
1056 | |
1038 | /* Only send it away if we have some actual data */ |
1057 | /* Only send it away if we have some actual data */ |
1039 | if (sl.len>6) { |
1058 | if (sl.len>6) { |
1040 | #ifdef ESRV_DEBUG |
1059 | #ifdef ESRV_DEBUG |
1041 | LOG(llevDebug,"Sending stats command, %d bytes long.\n", sl.len); |
1060 | LOG(llevDebug,"Sending stats command, %d bytes long.\n", sl.len); |
1042 | #endif |
1061 | #endif |
1043 | Send_With_Handling(&pl->socket, &sl); |
1062 | Send_With_Handling(&pl->socket, &sl); |
1044 | } |
1063 | } |
1045 | free(sl.buf); |
1064 | free(sl.buf); |
1046 | } |
1065 | } |
1047 | |
1066 | |
1048 | |
1067 | |
… | |
… | |
1088 | /* Do some checking on the anim_num we got. Note that the animations |
1107 | /* Do some checking on the anim_num we got. Note that the animations |
1089 | * are added in contigous order, so if the number is in the valid |
1108 | * are added in contigous order, so if the number is in the valid |
1090 | * range, it must be a valid animation. |
1109 | * range, it must be a valid animation. |
1091 | */ |
1110 | */ |
1092 | if (anim_num < 0 || anim_num > num_animations) { |
1111 | if (anim_num < 0 || anim_num > num_animations) { |
1093 | LOG(llevError,"esrv_send_anim (%d) out of bounds??\n",anim_num); |
1112 | LOG(llevError,"esrv_send_anim (%d) out of bounds??\n",anim_num); |
1094 | return; |
1113 | return; |
1095 | } |
1114 | } |
1096 | |
1115 | |
1097 | sl.buf = (unsigned char*) malloc(MAXSOCKBUF); |
1116 | sl.buf = (unsigned char*) malloc(MAXSOCKBUF); |
1098 | strcpy((char*)sl.buf, "anim "); |
1117 | strcpy((char*)sl.buf, "anim "); |
1099 | sl.len=5; |
1118 | sl.len=5; |
… | |
… | |
1101 | SockList_AddShort(&sl, 0); /* flags - not used right now */ |
1120 | SockList_AddShort(&sl, 0); /* flags - not used right now */ |
1102 | /* Build up the list of faces. Also, send any information (ie, the |
1121 | /* Build up the list of faces. Also, send any information (ie, the |
1103 | * the face itself) down to the client. |
1122 | * the face itself) down to the client. |
1104 | */ |
1123 | */ |
1105 | for (i=0; i<animations[anim_num].num_animations; i++) { |
1124 | for (i=0; i<animations[anim_num].num_animations; i++) { |
1106 | if (!(ns->faces_sent[animations[anim_num].faces[i]] & NS_FACESENT_FACE)) |
1125 | if (!(ns->faces_sent[animations[anim_num].faces[i]] & NS_FACESENT_FACE)) |
1107 | esrv_send_face(ns,animations[anim_num].faces[i],0); |
1126 | esrv_send_face(ns,animations[anim_num].faces[i],0); |
1108 | SockList_AddShort(&sl, animations[anim_num].faces[i]); /* flags - not used right now */ |
1127 | SockList_AddShort(&sl, animations[anim_num].faces[i]); /* flags - not used right now */ |
1109 | } |
1128 | } |
1110 | Send_With_Handling(ns, &sl); |
1129 | Send_With_Handling(ns, &sl); |
1111 | free(sl.buf); |
1130 | free(sl.buf); |
1112 | ns->anims_sent[anim_num] = 1; |
1131 | ns->anims_sent[anim_num] = 1; |
1113 | } |
1132 | } |
… | |
… | |
1122 | /** |
1141 | /** |
1123 | * This adds face_num to a map cell at x,y. If the client doesn't have |
1142 | * This adds face_num to a map cell at x,y. If the client doesn't have |
1124 | * the face yet, we will also send it. |
1143 | * the face yet, we will also send it. |
1125 | */ |
1144 | */ |
1126 | static void esrv_map_setbelow(NewSocket *ns, int x,int y, |
1145 | static void esrv_map_setbelow(NewSocket *ns, int x,int y, |
1127 | short face_num, struct Map *newmap) |
1146 | short face_num, struct Map *newmap) |
1128 | { |
1147 | { |
1129 | if(newmap->cells[x][y].count >= MAP_LAYERS) { |
1148 | if(newmap->cells[x][y].count >= MAP_LAYERS) { |
1130 | LOG(llevError,"Too many faces in map cell %d %d\n",x,y); |
1149 | LOG(llevError,"Too many faces in map cell %d %d\n",x,y); |
1131 | return; |
1150 | return; |
1132 | abort(); |
1151 | abort(); |
1133 | } |
1152 | } |
1134 | newmap->cells[x][y].faces[newmap->cells[x][y].count] = face_num; |
1153 | newmap->cells[x][y].faces[newmap->cells[x][y].count] = face_num; |
1135 | newmap->cells[x][y].count ++; |
1154 | newmap->cells[x][y].count ++; |
1136 | if (!(ns->faces_sent[face_num] & NS_FACESENT_FACE)) |
1155 | if (!(ns->faces_sent[face_num] & NS_FACESENT_FACE)) |
1137 | esrv_send_face(ns,face_num,0); |
1156 | esrv_send_face(ns,face_num,0); |
1138 | } |
1157 | } |
1139 | |
1158 | |
1140 | struct LayerCell { |
1159 | struct LayerCell { |
1141 | uint16 xy; |
1160 | uint16 xy; |
1142 | short face; |
1161 | short face; |
… | |
… | |
1154 | |
1173 | |
1155 | if (ns->lastmap.cells[i][j].count != newmap->cells[i][j].count) |
1174 | if (ns->lastmap.cells[i][j].count != newmap->cells[i][j].count) |
1156 | return 1; |
1175 | return 1; |
1157 | for(k=0;k<newmap->cells[i][j].count;k++) { |
1176 | for(k=0;k<newmap->cells[i][j].count;k++) { |
1158 | if (ns->lastmap.cells[i][j].faces[k] != |
1177 | if (ns->lastmap.cells[i][j].faces[k] != |
1159 | newmap->cells[i][j].faces[k]) { |
1178 | newmap->cells[i][j].faces[k]) { |
1160 | return 1; |
1179 | return 1; |
1161 | } |
1180 | } |
1162 | } |
1181 | } |
1163 | return 0; |
1182 | return 0; |
1164 | } |
1183 | } |
… | |
… | |
1168 | * cnum is the client number, cur is the the buffer we put all of |
1187 | * cnum is the client number, cur is the the buffer we put all of |
1169 | * this data into. we return the end of the data. layers is |
1188 | * this data into. we return the end of the data. layers is |
1170 | * how many layers of data we should back. |
1189 | * how many layers of data we should back. |
1171 | */ |
1190 | */ |
1172 | static uint8 *compactlayer(NewSocket *ns, unsigned char *cur, int numlayers, |
1191 | static uint8 *compactlayer(NewSocket *ns, unsigned char *cur, int numlayers, |
1173 | struct Map *newmap) |
1192 | struct Map *newmap) |
1174 | { |
1193 | { |
1175 | int x,y,k; |
1194 | int x,y,k; |
1176 | int face; |
1195 | int face; |
1177 | unsigned char *fcur; |
1196 | unsigned char *fcur; |
1178 | struct MapLayer layers[MAP_LAYERS]; |
1197 | struct MapLayer layers[MAP_LAYERS]; |
1179 | |
1198 | |
1180 | for(k = 0;k<MAP_LAYERS;k++) |
1199 | for(k = 0;k<MAP_LAYERS;k++) |
1181 | layers[k].count = 0; |
1200 | layers[k].count = 0; |
1182 | fcur = cur; |
1201 | fcur = cur; |
1183 | for(x=0;x<ns->mapx;x++) { |
1202 | for(x=0;x<ns->mapx;x++) { |
1184 | for(y=0;y<ns->mapy;y++) { |
1203 | for(y=0;y<ns->mapy;y++) { |
1185 | if (!mapcellchanged(ns,x,y,newmap)) |
1204 | if (!mapcellchanged(ns,x,y,newmap)) |
1186 | continue; |
1205 | continue; |
1187 | if (newmap->cells[x][y].count == 0) { |
1206 | if (newmap->cells[x][y].count == 0) { |
1188 | *cur = x*ns->mapy+y; /* mark empty space */ |
1207 | *cur = x*ns->mapy+y; /* mark empty space */ |
1189 | cur++; |
1208 | cur++; |
1190 | continue; |
1209 | continue; |
1191 | } |
1210 | } |
1192 | for(k=0;k<newmap->cells[x][y].count;k++) { |
1211 | for(k=0;k<newmap->cells[x][y].count;k++) { |
1193 | layers[k].lcells[layers[k].count].xy = x*ns->mapy+y; |
1212 | layers[k].lcells[layers[k].count].xy = x*ns->mapy+y; |
1194 | layers[k].lcells[layers[k].count].face = |
1213 | layers[k].lcells[layers[k].count].face = |
1195 | newmap->cells[x][y].faces[k]; |
1214 | newmap->cells[x][y].faces[k]; |
1196 | layers[k].count++; |
1215 | layers[k].count++; |
1197 | } |
1216 | } |
1198 | } |
1217 | } |
1199 | } |
1218 | } |
1200 | /* If no data, return now. */ |
1219 | /* If no data, return now. */ |
1201 | if (fcur == cur && layers[0].count == 0) |
1220 | if (fcur == cur && layers[0].count == 0) |
1202 | return cur; |
1221 | return cur; |
1203 | *cur = 255; /* mark end of explicitly cleared cells */ |
1222 | *cur = 255; /* mark end of explicitly cleared cells */ |
1204 | cur++; |
1223 | cur++; |
1205 | /* First pack by layers. */ |
1224 | /* First pack by layers. */ |
1206 | for(k=0;k<numlayers;k++) { |
1225 | for(k=0;k<numlayers;k++) { |
1207 | if (layers[k].count == 0) |
1226 | if (layers[k].count == 0) |
1208 | break; /* once a layer is entirely empty, no layer below it can |
1227 | break; /* once a layer is entirely empty, no layer below it can |
1209 | have anything in it either */ |
1228 | have anything in it either */ |
1210 | /* Pack by entries in thie layer */ |
1229 | /* Pack by entries in thie layer */ |
1211 | for(x=0;x<layers[k].count;) { |
1230 | for(x=0;x<layers[k].count;) { |
1212 | fcur = cur; |
1231 | fcur = cur; |
1213 | *cur = layers[k].lcells[x].face >> 8; |
1232 | *cur = layers[k].lcells[x].face >> 8; |
1214 | cur++; |
1233 | cur++; |
1215 | *cur = layers[k].lcells[x].face & 0xFF; |
1234 | *cur = layers[k].lcells[x].face & 0xFF; |
1216 | cur++; |
1235 | cur++; |
1217 | face = layers[k].lcells[x].face; |
1236 | face = layers[k].lcells[x].face; |
1218 | /* Now, we back the redundant data into 1 byte xy pairings */ |
1237 | /* Now, we back the redundant data into 1 byte xy pairings */ |
1219 | for(y=x;y<layers[k].count;y++) { |
1238 | for(y=x;y<layers[k].count;y++) { |
1220 | if (layers[k].lcells[y].face == face) { |
1239 | if (layers[k].lcells[y].face == face) { |
1221 | *cur = ( uint8 )layers[k].lcells[y].xy; |
1240 | *cur = ( uint8 )layers[k].lcells[y].xy; |
1222 | cur++; |
1241 | cur++; |
1223 | layers[k].lcells[y].face = -1; |
1242 | layers[k].lcells[y].face = -1; |
1224 | } |
1243 | } |
1225 | } |
1244 | } |
1226 | *(cur-1) = *(cur-1) | 128; /* mark for end of xy's; 11*11 < 128 */ |
1245 | *(cur-1) = *(cur-1) | 128; /* mark for end of xy's; 11*11 < 128 */ |
1227 | /* forward over the now redundant data */ |
1246 | /* forward over the now redundant data */ |
1228 | while(x < layers[k].count && |
1247 | while(x < layers[k].count && |
1229 | layers[k].lcells[x].face == -1) |
1248 | layers[k].lcells[x].face == -1) |
1230 | x++; |
1249 | x++; |
1231 | } |
1250 | } |
1232 | *fcur = *fcur | 128; /* mark for end of faces at this layer */ |
1251 | *fcur = *fcur | 128; /* mark for end of faces at this layer */ |
1233 | } |
1252 | } |
1234 | return cur; |
1253 | return cur; |
1235 | } |
1254 | } |
1236 | |
1255 | |
1237 | static void esrv_map_doneredraw(NewSocket *ns, struct Map *newmap) |
1256 | static void esrv_map_doneredraw(NewSocket *ns, struct Map *newmap) |
… | |
… | |
1249 | sl.len=cur-(char*)sl.buf; |
1268 | sl.len=cur-(char*)sl.buf; |
1250 | |
1269 | |
1251 | /* LOG(llevDebug, "Sending map command.\n");*/ |
1270 | /* LOG(llevDebug, "Sending map command.\n");*/ |
1252 | |
1271 | |
1253 | if (sl.len>( int )strlen("map ") || ns->sent_scroll) { |
1272 | if (sl.len>( int )strlen("map ") || ns->sent_scroll) { |
1254 | /* All of this is just accounting stuff */ |
1273 | /* All of this is just accounting stuff */ |
1255 | if (tframes>100) { |
1274 | if (tframes>100) { |
1256 | tframes = tbytes = 0; |
1275 | tframes = tbytes = 0; |
1257 | } |
1276 | } |
1258 | tframes++; |
1277 | tframes++; |
1259 | frames++; |
1278 | frames++; |
1260 | tbytes += sl.len; |
1279 | tbytes += sl.len; |
1261 | bytes += sl.len; |
1280 | bytes += sl.len; |
1262 | memcpy(&ns->lastmap,newmap,sizeof(struct Map)); |
1281 | memcpy(&ns->lastmap,newmap,sizeof(struct Map)); |
1263 | Send_With_Handling(ns, &sl); |
1282 | Send_With_Handling(ns, &sl); |
1264 | ns->sent_scroll = 0; |
1283 | ns->sent_scroll = 0; |
1265 | } |
1284 | } |
1266 | free(sl.buf); |
1285 | free(sl.buf); |
1267 | } |
1286 | } |
1268 | |
1287 | |
1269 | |
1288 | |
… | |
… | |
1273 | cell->faces[0] = face0; |
1292 | cell->faces[0] = face0; |
1274 | cell->faces[1] = face1; |
1293 | cell->faces[1] = face1; |
1275 | cell->faces[2] = face2; |
1294 | cell->faces[2] = face2; |
1276 | cell->count = count; |
1295 | cell->count = count; |
1277 | cell->stat_hp = 0; |
1296 | cell->stat_hp = 0; |
|
|
1297 | cell->player = 0; |
1278 | } |
1298 | } |
1279 | |
1299 | |
1280 | #define MAX_HEAD_POS MAX(MAX_CLIENT_X, MAX_CLIENT_Y) |
1300 | #define MAX_HEAD_POS MAX(MAX_CLIENT_X, MAX_CLIENT_Y) |
1281 | #define MAX_LAYERS 3 |
1301 | #define MAX_LAYERS 3 |
1282 | |
1302 | |
… | |
… | |
1295 | * for empty space checking. |
1315 | * for empty space checking. |
1296 | */ |
1316 | */ |
1297 | static inline int have_head(int ax, int ay) { |
1317 | static inline int have_head(int ax, int ay) { |
1298 | |
1318 | |
1299 | if (heads[(ay * MAX_HEAD_POS + ax) * MAX_LAYERS] || |
1319 | if (heads[(ay * MAX_HEAD_POS + ax) * MAX_LAYERS] || |
1300 | heads[(ay * MAX_HEAD_POS + ax) * MAX_LAYERS + 1] || |
1320 | heads[(ay * MAX_HEAD_POS + ax) * MAX_LAYERS + 1] || |
1301 | heads[(ay * MAX_HEAD_POS + ax) * MAX_LAYERS + 2]) return 1; |
1321 | heads[(ay * MAX_HEAD_POS + ax) * MAX_LAYERS + 2]) return 1; |
1302 | return 0; |
1322 | return 0; |
1303 | } |
1323 | } |
1304 | |
1324 | |
1305 | /** |
1325 | /** |
1306 | * check_head is a bit simplistic version of update_space below. |
1326 | * check_head is a bit simplistic version of update_space below. |
… | |
… | |
1312 | static int check_head (SockList &sl, NewSocket &ns, int ax, int ay, int layer) |
1332 | static int check_head (SockList &sl, NewSocket &ns, int ax, int ay, int layer) |
1313 | { |
1333 | { |
1314 | short face_num; |
1334 | short face_num; |
1315 | |
1335 | |
1316 | if (heads[(ay * MAX_HEAD_POS + ax) * MAX_LAYERS + layer]) |
1336 | if (heads[(ay * MAX_HEAD_POS + ax) * MAX_LAYERS + layer]) |
1317 | face_num = heads[(ay * MAX_HEAD_POS + ax) * MAX_LAYERS + layer]->face->number; |
1337 | face_num = heads[(ay * MAX_HEAD_POS + ax) * MAX_LAYERS + layer]->face->number; |
1318 | else |
1338 | else |
1319 | face_num = 0; |
1339 | face_num = 0; |
1320 | |
1340 | |
1321 | if (face_num != ns.lastmap.cells[ax][ay].faces[layer]) { |
1341 | if (face_num != ns.lastmap.cells[ax][ay].faces[layer]) { |
1322 | SockList_AddShort (&sl, face_num); |
1342 | SockList_AddShort (&sl, face_num); |
1323 | if (face_num && !(ns.faces_sent[face_num] & NS_FACESENT_FACE)) |
1343 | if (face_num && !(ns.faces_sent[face_num] & NS_FACESENT_FACE)) |
1324 | esrv_send_face (&ns, face_num, 0); |
1344 | esrv_send_face (&ns, face_num, 0); |
1325 | heads[(ay * MAX_HEAD_POS + ax) * MAX_LAYERS + layer] = NULL; |
1345 | heads[(ay * MAX_HEAD_POS + ax) * MAX_LAYERS + layer] = NULL; |
1326 | ns.lastmap.cells[ax][ay].faces[layer] = face_num; |
1346 | ns.lastmap.cells[ax][ay].faces[layer] = face_num; |
1327 | return 1; |
1347 | return 1; |
1328 | } |
1348 | } |
1329 | |
1349 | |
1330 | return 0; /* No change */ |
1350 | return 0; /* No change */ |
1331 | } |
1351 | } |
1332 | |
1352 | |
… | |
… | |
1372 | * 3) We need to do some extra checking to make sure that we will |
1392 | * 3) We need to do some extra checking to make sure that we will |
1373 | * otherwise send the image as this layer, eg, either it matches |
1393 | * otherwise send the image as this layer, eg, either it matches |
1374 | * the head value, or is not multipart. |
1394 | * the head value, or is not multipart. |
1375 | */ |
1395 | */ |
1376 | if (head && !head->more) { |
1396 | if (head && !head->more) { |
1377 | for (i=0; i<MAP_LAYERS; i++) { |
1397 | for (i=0; i<MAP_LAYERS; i++) { |
1378 | ob = GET_MAP_FACE_OBJ(mp, mx, my, i); |
1398 | ob = GET_MAP_FACE_OBJ(mp, mx, my, i); |
1379 | if (!ob) continue; |
1399 | if (!ob) continue; |
1380 | |
1400 | |
1381 | if (ob->head) ob=ob->head; |
1401 | if (ob->head) ob=ob->head; |
1382 | |
1402 | |
1383 | if (ob == head) { |
1403 | if (ob == head) { |
1384 | heads[(sy * MAX_HEAD_POS + sx) * MAX_LAYERS + layer] = NULL; |
1404 | heads[(sy * MAX_HEAD_POS + sx) * MAX_LAYERS + layer] = NULL; |
1385 | head = NULL; |
1405 | head = NULL; |
1386 | break; |
1406 | break; |
1387 | } |
1407 | } |
1388 | } |
1408 | } |
1389 | } |
1409 | } |
1390 | |
1410 | |
1391 | ob = head; |
1411 | ob = head; |
1392 | if (!ob) ob = GET_MAP_FACE_OBJ(mp, mx, my, layer); |
1412 | if (!ob) ob = GET_MAP_FACE_OBJ(mp, mx, my, layer); |
1393 | |
1413 | |
… | |
… | |
1397 | * precedence over the other object for this space. |
1417 | * precedence over the other object for this space. |
1398 | * otherwise, we do special head processing |
1418 | * otherwise, we do special head processing |
1399 | */ |
1419 | */ |
1400 | if (!ob || ob->face == blank_face) face_num=0; |
1420 | if (!ob || ob->face == blank_face) face_num=0; |
1401 | else if (head){ |
1421 | else if (head){ |
1402 | /* if this is a head that had previously been stored */ |
1422 | /* if this is a head that had previously been stored */ |
1403 | face_num = ob->face->number; |
1423 | face_num = ob->face->number; |
1404 | } else { |
1424 | } else { |
1405 | /* if the faces for the different parts of a multipart object |
1425 | /* if the faces for the different parts of a multipart object |
1406 | * are the same, we only want to send the bottom right most |
1426 | * are the same, we only want to send the bottom right most |
1407 | * portion of the object. That info is in the tail_.. values |
1427 | * portion of the object. That info is in the tail_.. values |
1408 | * of the head. Note that for the head itself, ob->head will |
1428 | * of the head. Note that for the head itself, ob->head will |
1409 | * be null, so we only do this block if we are working on |
1429 | * be null, so we only do this block if we are working on |
1410 | * a tail piece. |
1430 | * a tail piece. |
1411 | */ |
1431 | */ |
1412 | |
1432 | |
1413 | /* tail_x and tail_y will only be set in the head object. If |
1433 | /* tail_x and tail_y will only be set in the head object. If |
1414 | * this is the head object and these are set, we proceed |
1434 | * this is the head object and these are set, we proceed |
1415 | * with logic to only send bottom right. Similarly, if |
1435 | * with logic to only send bottom right. Similarly, if |
1416 | * this is one of the more parts but the head has those values |
1436 | * this is one of the more parts but the head has those values |
1417 | * set, we want to do the processing. There can be cases where |
1437 | * set, we want to do the processing. There can be cases where |
1418 | * the head is not visible but one of its parts is, so we just |
1438 | * the head is not visible but one of its parts is, so we just |
1419 | * can always expect that ob->arch->tail_x will be true for all |
1439 | * can always expect that ob->arch->tail_x will be true for all |
1420 | * object we may want to display. |
1440 | * object we may want to display. |
1421 | */ |
1441 | */ |
1422 | if ((ob->arch->tail_x || ob->arch->tail_y) || |
1442 | if ((ob->arch->tail_x || ob->arch->tail_y) || |
1423 | (ob->head && (ob->head->arch->tail_x || ob->head->arch->tail_y))) { |
1443 | (ob->head && (ob->head->arch->tail_x || ob->head->arch->tail_y))) { |
1424 | |
1444 | |
1425 | if (ob->head) head = ob->head; |
1445 | if (ob->head) head = ob->head; |
1426 | else head = ob; |
1446 | else head = ob; |
1427 | |
1447 | |
1428 | /* Basically figure out where the offset is from where we are right |
1448 | /* Basically figure out where the offset is from where we are right |
1429 | * now. the ob->arch->clone.{x,y} values hold the offset that this current |
1449 | * now. the ob->arch->clone.{x,y} values hold the offset that this current |
1430 | * piece is from the head, and the tail is where the tail is from the |
1450 | * piece is from the head, and the tail is where the tail is from the |
1431 | * head. Note that bx and by will equal sx and sy if we are already working |
1451 | * head. Note that bx and by will equal sx and sy if we are already working |
1432 | * on the bottom right corner. If ob is the head, the clone values |
1452 | * on the bottom right corner. If ob is the head, the clone values |
1433 | * will be zero, so the right thing will still happen. |
1453 | * will be zero, so the right thing will still happen. |
1434 | */ |
1454 | */ |
1435 | bx = sx + head->arch->tail_x - ob->arch->clone.x; |
1455 | bx = sx + head->arch->tail_x - ob->arch->clone.x; |
1436 | by = sy + head->arch->tail_y - ob->arch->clone.y; |
1456 | by = sy + head->arch->tail_y - ob->arch->clone.y; |
1437 | |
1457 | |
1438 | /* I don't think this can ever happen, but better to check for it just |
1458 | /* I don't think this can ever happen, but better to check for it just |
1439 | * in case. |
1459 | * in case. |
1440 | */ |
1460 | */ |
1441 | if (bx < sx || by < sy) { |
1461 | if (bx < sx || by < sy) { |
1442 | LOG(llevError,"update_space: bx (%d) or by (%d) is less than sx (%d) or sy (%d)\n", |
1462 | LOG(llevError,"update_space: bx (%d) or by (%d) is less than sx (%d) or sy (%d)\n", |
1443 | bx, by, sx, sy); |
1463 | bx, by, sx, sy); |
1444 | face_num = 0; |
1464 | face_num = 0; |
1445 | } |
1465 | } |
1446 | /* single part object, multipart object with non merged faces, |
1466 | /* single part object, multipart object with non merged faces, |
1447 | * of multipart object already at lower right. |
1467 | * of multipart object already at lower right. |
1448 | */ |
1468 | */ |
1449 | else if (bx == sx && by == sy) { |
1469 | else if (bx == sx && by == sy) { |
1450 | face_num = ob->face->number; |
1470 | face_num = ob->face->number; |
1451 | |
1471 | |
1452 | /* if this face matches one stored away, clear that one away. |
1472 | /* if this face matches one stored away, clear that one away. |
1453 | * this code relies on the fact that the map1 commands |
1473 | * this code relies on the fact that the map1 commands |
1454 | * goes from 2 down to 0. |
1474 | * goes from 2 down to 0. |
1455 | */ |
1475 | */ |
1456 | for (i=0; i<MAP_LAYERS; i++) |
1476 | for (i=0; i<MAP_LAYERS; i++) |
1457 | if (heads[(sy * MAX_HEAD_POS + sx) * MAX_LAYERS + i] && |
1477 | if (heads[(sy * MAX_HEAD_POS + sx) * MAX_LAYERS + i] && |
1458 | heads[(sy * MAX_HEAD_POS + sx) * MAX_LAYERS + i]->face->number == face_num) |
1478 | heads[(sy * MAX_HEAD_POS + sx) * MAX_LAYERS + i]->face->number == face_num) |
1459 | heads[(sy * MAX_HEAD_POS + sx) * MAX_LAYERS + i] = NULL; |
1479 | heads[(sy * MAX_HEAD_POS + sx) * MAX_LAYERS + i] = NULL; |
1460 | } |
1480 | } |
1461 | else { |
1481 | else { |
1462 | /* If this head is stored away, clear it - otherwise, |
1482 | /* If this head is stored away, clear it - otherwise, |
1463 | * there can be cases where a object is on multiple layers - |
1483 | * there can be cases where a object is on multiple layers - |
1464 | * we only want to send it once. |
1484 | * we only want to send it once. |
1465 | */ |
1485 | */ |
1466 | face_num = head->face->number; |
1486 | face_num = head->face->number; |
1467 | for (i=0; i<MAP_LAYERS; i++) |
1487 | for (i=0; i<MAP_LAYERS; i++) |
1468 | if (heads[(by * MAX_HEAD_POS + bx) * MAX_LAYERS + i] && |
1488 | if (heads[(by * MAX_HEAD_POS + bx) * MAX_LAYERS + i] && |
1469 | heads[(by * MAX_HEAD_POS + bx) * MAX_LAYERS + i]->face->number == face_num) |
1489 | heads[(by * MAX_HEAD_POS + bx) * MAX_LAYERS + i]->face->number == face_num) |
1470 | heads[(by * MAX_HEAD_POS + bx) * MAX_LAYERS + i] = NULL; |
1490 | heads[(by * MAX_HEAD_POS + bx) * MAX_LAYERS + i] = NULL; |
1471 | |
1491 | |
1472 | /* First, try to put the new head on the same layer. If that is used up, |
1492 | /* First, try to put the new head on the same layer. If that is used up, |
1473 | * then find another layer. |
1493 | * then find another layer. |
1474 | */ |
1494 | */ |
1475 | if (heads[(by * MAX_HEAD_POS + bx) * MAX_LAYERS + layer] == NULL) { |
1495 | if (heads[(by * MAX_HEAD_POS + bx) * MAX_LAYERS + layer] == NULL) { |
1476 | heads[(by * MAX_HEAD_POS + bx) * MAX_LAYERS + layer] = head; |
1496 | heads[(by * MAX_HEAD_POS + bx) * MAX_LAYERS + layer] = head; |
1477 | } else for (i=0; i<MAX_LAYERS; i++) { |
1497 | } else for (i=0; i<MAX_LAYERS; i++) { |
1478 | if (heads[(by * MAX_HEAD_POS + bx) * MAX_LAYERS + i] == NULL || |
1498 | if (heads[(by * MAX_HEAD_POS + bx) * MAX_LAYERS + i] == NULL || |
1479 | heads[(by * MAX_HEAD_POS + bx) * MAX_LAYERS + i] == head) { |
1499 | heads[(by * MAX_HEAD_POS + bx) * MAX_LAYERS + i] == head) { |
1480 | heads[(by * MAX_HEAD_POS + bx) * MAX_LAYERS + i] = head; |
1500 | heads[(by * MAX_HEAD_POS + bx) * MAX_LAYERS + i] = head; |
1481 | } |
1501 | } |
1482 | } |
1502 | } |
1483 | face_num = 0; /* Don't send this object - we'll send the head later */ |
1503 | face_num = 0; /* Don't send this object - we'll send the head later */ |
1484 | } |
1504 | } |
1485 | } else { |
1505 | } else { |
1486 | /* In this case, we are already at the lower right or single part object, |
1506 | /* In this case, we are already at the lower right or single part object, |
1487 | * so nothing special |
1507 | * so nothing special |
1488 | */ |
1508 | */ |
1489 | face_num = ob->face->number; |
1509 | face_num = ob->face->number; |
1490 | |
1510 | |
1491 | /* clear out any head entries that have the same face as this one */ |
1511 | /* clear out any head entries that have the same face as this one */ |
1492 | for (bx=0; bx<layer; bx++) |
1512 | for (bx=0; bx<layer; bx++) |
1493 | if (heads[(sy * MAX_HEAD_POS + sx) * MAX_LAYERS + bx] && |
1513 | if (heads[(sy * MAX_HEAD_POS + sx) * MAX_LAYERS + bx] && |
1494 | heads[(sy * MAX_HEAD_POS + sx) * MAX_LAYERS + bx]->face->number == face_num) |
1514 | heads[(sy * MAX_HEAD_POS + sx) * MAX_LAYERS + bx]->face->number == face_num) |
1495 | heads[(sy * MAX_HEAD_POS + sx) * MAX_LAYERS + bx] = NULL; |
1515 | heads[(sy * MAX_HEAD_POS + sx) * MAX_LAYERS + bx] = NULL; |
1496 | } |
1516 | } |
1497 | } /* else not already head object or blank face */ |
1517 | } /* else not already head object or blank face */ |
1498 | |
1518 | |
1499 | /* This is a real hack. Basically, if we have nothing to send for this layer, |
1519 | /* This is a real hack. Basically, if we have nothing to send for this layer, |
1500 | * but there is a head on the next layer, send that instead. |
1520 | * but there is a head on the next layer, send that instead. |
1501 | * Without this, what happens is you can get the case where the player stands |
1521 | * Without this, what happens is you can get the case where the player stands |
1502 | * on the same space as the head. However, if you have overlapping big objects |
1522 | * on the same space as the head. However, if you have overlapping big objects |
1503 | * of the same type, what happens then is it doesn't think it needs to send |
1523 | * of the same type, what happens then is it doesn't think it needs to send |
1504 | * This tends to make stacking also work/look better. |
1524 | * This tends to make stacking also work/look better. |
1505 | */ |
1525 | */ |
1506 | if (!face_num && layer > 0 && heads[(sy * MAX_HEAD_POS + sx) * MAX_LAYERS + layer -1]) { |
1526 | if (!face_num && layer > 0 && heads[(sy * MAX_HEAD_POS + sx) * MAX_LAYERS + layer -1]) { |
1507 | face_num = heads[(sy * MAX_HEAD_POS + sx) * MAX_LAYERS + layer -1]->face->number; |
1527 | face_num = heads[(sy * MAX_HEAD_POS + sx) * MAX_LAYERS + layer -1]->face->number; |
1508 | heads[(sy * MAX_HEAD_POS + sx) * MAX_LAYERS + layer -1] = NULL; |
1528 | heads[(sy * MAX_HEAD_POS + sx) * MAX_LAYERS + layer -1] = NULL; |
1509 | } |
1529 | } |
1510 | |
1530 | |
1511 | /* Another hack - because of heads and whatnot, this face may match one |
1531 | /* Another hack - because of heads and whatnot, this face may match one |
1512 | * we already sent for a lower layer. In that case, don't send |
1532 | * we already sent for a lower layer. In that case, don't send |
1513 | * this one. |
1533 | * this one. |
1514 | */ |
1534 | */ |
1515 | if (face_num && layer+1<MAP_LAYERS && ns->lastmap.cells[sx][sy].faces[layer+1] == face_num) { |
1535 | if (face_num && layer+1<MAP_LAYERS && ns->lastmap.cells[sx][sy].faces[layer+1] == face_num) { |
1516 | face_num = 0; |
1536 | face_num = 0; |
1517 | } |
1537 | } |
1518 | |
1538 | |
1519 | /* We've gotten what face we want to use for the object. Now see if |
1539 | /* We've gotten what face we want to use for the object. Now see if |
1520 | * if it has changed since we last sent it to the client. |
1540 | * if it has changed since we last sent it to the client. |
1521 | */ |
1541 | */ |
1522 | if (ns->lastmap.cells[sx][sy].faces[layer] != face_num) { |
1542 | if (ns->lastmap.cells[sx][sy].faces[layer] != face_num) { |
1523 | ns->lastmap.cells[sx][sy].faces[layer] = face_num; |
1543 | ns->lastmap.cells[sx][sy].faces[layer] = face_num; |
1524 | if (!(ns->faces_sent[face_num] & NS_FACESENT_FACE)) |
1544 | if (!(ns->faces_sent[face_num] & NS_FACESENT_FACE)) |
1525 | esrv_send_face(ns, face_num, 0); |
1545 | esrv_send_face(ns, face_num, 0); |
1526 | SockList_AddShort(sl, face_num); |
1546 | SockList_AddShort(sl, face_num); |
1527 | return 1; |
1547 | return 1; |
1528 | } |
1548 | } |
1529 | /* Nothing changed */ |
1549 | /* Nothing changed */ |
1530 | return 0; |
1550 | return 0; |
1531 | } |
1551 | } |
1532 | |
1552 | |
… | |
… | |
1559 | /* If there is no object for this space, or if the face for the object |
1579 | /* If there is no object for this space, or if the face for the object |
1560 | * is the blank face, set the smoothlevel to zero. |
1580 | * is the blank face, set the smoothlevel to zero. |
1561 | */ |
1581 | */ |
1562 | if (!ob || ob->face == blank_face || MAP_NOSMOOTH(mp)) smoothlevel=0; |
1582 | if (!ob || ob->face == blank_face || MAP_NOSMOOTH(mp)) smoothlevel=0; |
1563 | else { |
1583 | else { |
1564 | smoothlevel = ob->smoothlevel; |
1584 | smoothlevel = ob->smoothlevel; |
1565 | if (smoothlevel && !(ns->faces_sent[ob->face->number] & NS_FACESENT_SMOOTH)) |
1585 | if (smoothlevel && !(ns->faces_sent[ob->face->number] & NS_FACESENT_SMOOTH)) |
1566 | SendSmooth(ns, ob->face->number); |
1586 | SendSmooth(ns, ob->face->number); |
1567 | } /* else not already head object or blank face */ |
1587 | } /* else not already head object or blank face */ |
1568 | |
1588 | |
1569 | /* We've gotten what face we want to use for the object. Now see if |
1589 | /* We've gotten what face we want to use for the object. Now see if |
1570 | * if it has changed since we last sent it to the client. |
1590 | * if it has changed since we last sent it to the client. |
1571 | */ |
1591 | */ |
1572 | if (smoothlevel>255) |
1592 | if (smoothlevel>255) |
1573 | smoothlevel=255; |
1593 | smoothlevel=255; |
1574 | else if (smoothlevel<0) |
1594 | else if (smoothlevel<0) |
1575 | smoothlevel=0; |
1595 | smoothlevel=0; |
1576 | if (ns->lastmap.cells[sx][sy].smooth[layer] != smoothlevel) { |
1596 | if (ns->lastmap.cells[sx][sy].smooth[layer] != smoothlevel) { |
1577 | ns->lastmap.cells[sx][sy].smooth[layer] = smoothlevel; |
1597 | ns->lastmap.cells[sx][sy].smooth[layer] = smoothlevel; |
1578 | SockList_AddChar(sl, (uint8) (smoothlevel&0xFF)); |
1598 | SockList_AddChar(sl, (uint8) (smoothlevel&0xFF)); |
1579 | return 1; |
1599 | return 1; |
1580 | } |
1600 | } |
1581 | /* Nothing changed */ |
1601 | /* Nothing changed */ |
1582 | return 0; |
1602 | return 0; |
1583 | } |
1603 | } |
1584 | |
1604 | |
… | |
… | |
1633 | |
1653 | |
1634 | check_map_change (pl->contr); |
1654 | check_map_change (pl->contr); |
1635 | |
1655 | |
1636 | sl.buf=(unsigned char*)malloc(MAXSOCKBUF); |
1656 | sl.buf=(unsigned char*)malloc(MAXSOCKBUF); |
1637 | if (socket.mapmode == Map1Cmd) |
1657 | if (socket.mapmode == Map1Cmd) |
1638 | strcpy((char*)sl.buf,"map1 "); |
1658 | strcpy((char*)sl.buf,"map1 "); |
1639 | else |
1659 | else |
1640 | strcpy((char*)sl.buf,"map1a "); |
1660 | strcpy((char*)sl.buf,"map1a "); |
1641 | sl.len=strlen((char*)sl.buf); |
1661 | sl.len=strlen((char*)sl.buf); |
1642 | startlen = sl.len; |
1662 | startlen = sl.len; |
1643 | /*Extendedmapinfo structure initialisation*/ |
1663 | /*Extendedmapinfo structure initialisation*/ |
1644 | if (socket.ext_mapinfos){ |
1664 | if (socket.ext_mapinfos){ |
1645 | esl.buf=(unsigned char*)malloc(MAXSOCKBUF); |
1665 | esl.buf=(unsigned char*)malloc(MAXSOCKBUF); |
… | |
… | |
1673 | * but that started to get a bit messy to look at. |
1693 | * but that started to get a bit messy to look at. |
1674 | */ |
1694 | */ |
1675 | max_x = pl->x+(socket.mapx+1)/2; |
1695 | max_x = pl->x+(socket.mapx+1)/2; |
1676 | max_y = pl->y+(socket.mapy+1)/2; |
1696 | max_y = pl->y+(socket.mapy+1)/2; |
1677 | if (socket.mapmode == Map1aCmd) { |
1697 | if (socket.mapmode == Map1aCmd) { |
1678 | max_x += MAX_HEAD_OFFSET; |
1698 | max_x += MAX_HEAD_OFFSET; |
1679 | max_y += MAX_HEAD_OFFSET; |
1699 | max_y += MAX_HEAD_OFFSET; |
1680 | } |
1700 | } |
1681 | |
1701 | |
1682 | for(y=pl->y-socket.mapy/2; y<max_y; y++,ay++) { |
1702 | for(y=pl->y-socket.mapy/2; y<max_y; y++,ay++) { |
1683 | ax=0; |
1703 | ax=0; |
1684 | for(x=pl->x-socket.mapx/2;x<max_x;x++,ax++) { |
1704 | for(x=pl->x-socket.mapx/2;x<max_x;x++,ax++) { |
1685 | |
1705 | |
1686 | emask = mask = (ax & 0x3f) << 10 | (ay & 0x3f) << 4; |
1706 | emask = mask = (ax & 0x3f) << 10 | (ay & 0x3f) << 4; |
1687 | |
1707 | |
1688 | /* If this space is out of the normal viewable area, we only check |
1708 | /* If this space is out of the normal viewable area, we only check |
1689 | * the heads value ax or ay will only be greater than what |
1709 | * the heads value ax or ay will only be greater than what |
1690 | * the client wants if using the map1a command - this is because |
1710 | * the client wants if using the map1a command - this is because |
1691 | * if the map1a command is not used, max_x and max_y will be |
1711 | * if the map1a command is not used, max_x and max_y will be |
1692 | * set to lower values. |
1712 | * set to lower values. |
1693 | */ |
1713 | */ |
1694 | if (ax >= socket.mapx || ay >= socket.mapy) { |
1714 | if (ax >= socket.mapx || ay >= socket.mapy) { |
1695 | int i, got_one; |
1715 | int i, got_one; |
1696 | |
1716 | |
1697 | oldlen = sl.len; |
1717 | oldlen = sl.len; |
1698 | |
1718 | |
1699 | SockList_AddShort(&sl, mask); |
1719 | SockList_AddShort(&sl, mask); |
1700 | |
1720 | |
1701 | if (check_head (sl, socket, ax, ay, 2)) |
1721 | if (check_head (sl, socket, ax, ay, 2)) |
1702 | mask |= 0x4; |
1722 | mask |= 0x4; |
1703 | if (check_head (sl, socket, ax, ay, 1)) |
1723 | if (check_head (sl, socket, ax, ay, 1)) |
1704 | mask |= 0x2; |
1724 | mask |= 0x2; |
1705 | if (check_head (sl, socket, ax, ay, 0)) |
1725 | if (check_head (sl, socket, ax, ay, 0)) |
1706 | mask |= 0x1; |
1726 | mask |= 0x1; |
1707 | |
1727 | |
1708 | /* If all we are doing is sending 0 (blank) faces, we don't |
1728 | /* If all we are doing is sending 0 (blank) faces, we don't |
1709 | * actually need to send that - just the coordinates |
1729 | * actually need to send that - just the coordinates |
1710 | * with no faces tells the client to blank out the |
1730 | * with no faces tells the client to blank out the |
1711 | * space. |
1731 | * space. |
1712 | */ |
1732 | */ |
1713 | got_one=0; |
1733 | got_one=0; |
1714 | for (i=oldlen+2; i<sl.len; i++) { |
1734 | for (i=oldlen+2; i<sl.len; i++) { |
1715 | if (sl.buf[i]) got_one=1; |
1735 | if (sl.buf[i]) got_one=1; |
1716 | } |
1736 | } |
1717 | |
1737 | |
1718 | if (got_one && (mask & 0xf)) { |
1738 | if (got_one && (mask & 0xf)) { |
1719 | sl.buf[oldlen+1] = mask & 0xff; |
1739 | sl.buf[oldlen+1] = mask & 0xff; |
1720 | } else { /*either all faces blank, either no face at all*/ |
1740 | } else { /*either all faces blank, either no face at all*/ |
1721 | if (mask & 0xf) /*at least 1 face, we know it's blank, only send coordinates*/ |
1741 | if (mask & 0xf) /*at least 1 face, we know it's blank, only send coordinates*/ |
1722 | sl.len = oldlen + 2; |
1742 | sl.len = oldlen + 2; |
1723 | else |
1743 | else |
1724 | sl.len = oldlen; |
1744 | sl.len = oldlen; |
1725 | } |
1745 | } |
1726 | /*What concerns extendinfos, nothing to be done for now |
1746 | /*What concerns extendinfos, nothing to be done for now |
1727 | * (perhaps effects layer later) |
1747 | * (perhaps effects layer later) |
1728 | */ |
1748 | */ |
1729 | continue; /* don't do processing below */ |
1749 | continue; /* don't do processing below */ |
1730 | } |
1750 | } |
1731 | |
1751 | |
1732 | MapCell &lastcell = socket.lastmap.cells[ax][ay]; |
1752 | MapCell &lastcell = socket.lastmap.cells[ax][ay]; |
1733 | |
1753 | |
1734 | d = pl->contr->blocked_los[ax][ay]; |
1754 | d = pl->contr->blocked_los[ax][ay]; |
1735 | |
1755 | |
1736 | /* If the coordinates are not valid, or it is too dark to see, |
1756 | /* If the coordinates are not valid, or it is too dark to see, |
1737 | * we tell the client as such |
1757 | * we tell the client as such |
1738 | */ |
1758 | */ |
1739 | nx=x; |
1759 | nx=x; |
1740 | ny=y; |
1760 | ny=y; |
1741 | m = get_map_from_coord(pl->map, &nx, &ny); |
1761 | m = get_map_from_coord(pl->map, &nx, &ny); |
1742 | if (!m) { |
1762 | if (!m) { |
1743 | /* space is out of map. Update space and clear values |
1763 | /* space is out of map. Update space and clear values |
1744 | * if this hasn't already been done. If the space is out |
1764 | * if this hasn't already been done. If the space is out |
1745 | * of the map, it shouldn't have a head |
1765 | * of the map, it shouldn't have a head |
1746 | */ |
1766 | */ |
1747 | if (lastcell.count != -1) { |
1767 | if (lastcell.count != -1) { |
1748 | SockList_AddShort(&sl, mask); |
1768 | SockList_AddShort(&sl, mask); |
1749 | map_clearcell(&lastcell,0,0,0,-1); |
1769 | map_clearcell(&lastcell,0,0,0,-1); |
1750 | } |
1770 | } |
1751 | } else if (d>3) { |
1771 | } else if (d>3) { |
1752 | int need_send=0, count; |
1772 | int need_send=0, count; |
1753 | /* This block deals with spaces that are not visible for whatever |
1773 | /* This block deals with spaces that are not visible for whatever |
1754 | * reason. Still may need to send the head for this space. |
1774 | * reason. Still may need to send the head for this space. |
1755 | */ |
1775 | */ |
1756 | |
1776 | |
1757 | oldlen = sl.len; |
1777 | oldlen = sl.len; |
1758 | |
1778 | |
1759 | SockList_AddShort(&sl, mask); |
1779 | SockList_AddShort(&sl, mask); |
1760 | if (lastcell.count != -1) need_send=1; |
1780 | if (lastcell.count != -1) need_send=1; |
1761 | count = -1; |
1781 | count = -1; |
1762 | |
1782 | |
1763 | if (socket.mapmode == Map1aCmd && have_head(ax, ay)) { |
1783 | if (socket.mapmode == Map1aCmd && have_head(ax, ay)) { |
1764 | /* Now check to see if any heads need to be sent */ |
1784 | /* Now check to see if any heads need to be sent */ |
1765 | |
1785 | |
1766 | if (check_head (sl, socket, ax, ay, 2)) |
1786 | if (check_head (sl, socket, ax, ay, 2)) |
1767 | mask |= 0x4; |
1787 | mask |= 0x4; |
1768 | if (check_head (sl, socket, ax, ay, 1)) |
1788 | if (check_head (sl, socket, ax, ay, 1)) |
1769 | mask |= 0x2; |
1789 | mask |= 0x2; |
1770 | if (check_head (sl, socket, ax, ay, 0)) |
1790 | if (check_head (sl, socket, ax, ay, 0)) |
1771 | mask |= 0x1; |
1791 | mask |= 0x1; |
1772 | |
1792 | |
1773 | lastcell.count = count; |
1793 | lastcell.count = count; |
1774 | |
1794 | |
1775 | } else { |
1795 | } else { |
1776 | struct MapCell *cell = &lastcell; |
1796 | struct MapCell *cell = &lastcell; |
1777 | /* properly clear a previously sent big face */ |
1797 | /* properly clear a previously sent big face */ |
1778 | if(cell->faces[0] != 0 |
1798 | if(cell->faces[0] != 0 |
1779 | || cell->faces[1] != 0 |
1799 | || cell->faces[1] != 0 |
1780 | || cell->faces[2] != 0) |
1800 | || cell->faces[2] != 0) |
1781 | need_send = 1; |
1801 | need_send = 1; |
1782 | map_clearcell(&lastcell, 0, 0, 0, count); |
1802 | map_clearcell(&lastcell, 0, 0, 0, count); |
1783 | } |
1803 | } |
1784 | |
1804 | |
1785 | if ((mask & 0xf) || need_send) { |
1805 | if ((mask & 0xf) || need_send) { |
1786 | sl.buf[oldlen+1] = mask & 0xff; |
1806 | sl.buf[oldlen+1] = mask & 0xff; |
1787 | } else { |
1807 | } else { |
1788 | sl.len = oldlen; |
1808 | sl.len = oldlen; |
1789 | } |
1809 | } |
1790 | } else { |
1810 | } else { |
1791 | /* In this block, the space is visible or there are head objects |
1811 | /* In this block, the space is visible or there are head objects |
1792 | * we need to send. |
1812 | * we need to send. |
1793 | */ |
1813 | */ |
1794 | |
1814 | |
1795 | /* Rather than try to figure out what everything that we might |
1815 | /* Rather than try to figure out what everything that we might |
1796 | * need to send is, then form the packet after that, |
1816 | * need to send is, then form the packet after that, |
1797 | * we presume that we will in fact form a packet, and update |
1817 | * we presume that we will in fact form a packet, and update |
1798 | * the bits by what we do actually send. If we send nothing, |
1818 | * the bits by what we do actually send. If we send nothing, |
1799 | * we just back out sl.len to the old value, and no harm |
1819 | * we just back out sl.len to the old value, and no harm |
1800 | * is done. |
1820 | * is done. |
1801 | * I think this is simpler than doing a bunch of checks to see |
1821 | * I think this is simpler than doing a bunch of checks to see |
1802 | * what if anything we need to send, setting the bits, then |
1822 | * what if anything we need to send, setting the bits, then |
1803 | * doing those checks again to add the real data. |
1823 | * doing those checks again to add the real data. |
1804 | */ |
1824 | */ |
1805 | oldlen = sl.len; |
1825 | oldlen = sl.len; |
1806 | mask = (ax & 0x3f) << 10 | (ay & 0x3f) << 4; |
1826 | mask = (ax & 0x3f) << 10 | (ay & 0x3f) << 4; |
1807 | eoldlen = esl.len; |
1827 | eoldlen = esl.len; |
1808 | emask = (ax & 0x3f) << 10 | (ay & 0x3f) << 4; |
1828 | emask = (ax & 0x3f) << 10 | (ay & 0x3f) << 4; |
1809 | SockList_AddShort(&sl, mask); |
|
|
1810 | |
|
|
1811 | if (socket.ext_mapinfos) |
|
|
1812 | SockList_AddShort(&esl, emask); |
1829 | SockList_AddShort(&sl, mask); |
|
|
1830 | |
|
|
1831 | if (socket.ext_mapinfos) |
|
|
1832 | SockList_AddShort(&esl, emask); |
1813 | |
1833 | |
1814 | unsigned char dummy; |
1834 | unsigned char dummy; |
1815 | unsigned char *last_ext = &dummy; |
1835 | unsigned char *last_ext = &dummy; |
1816 | |
1836 | |
1817 | /* Darkness changed */ |
1837 | /* Darkness changed */ |
1818 | if (lastcell.count != d && socket.darkness) { |
1838 | if (lastcell.count != d && socket.darkness) { |
1819 | mask |= 0x8; |
1839 | mask |= 0x8; |
1820 | |
1840 | |
1821 | if (socket.extmap) |
1841 | if (socket.extmap) |
1822 | { |
1842 | { |
1823 | *last_ext |= 0x80; last_ext = sl.buf + sl.len; SockList_AddChar (&sl, d); |
1843 | *last_ext |= 0x80; last_ext = sl.buf + sl.len; SockList_AddChar (&sl, d); |
1824 | } |
1844 | } |
1825 | else |
1845 | else |
1826 | SockList_AddChar (&sl, 255 - 64 * d); |
1846 | SockList_AddChar (&sl, 255 - 64 * d); |
1827 | } |
1847 | } |
1828 | |
1848 | |
1829 | lastcell.count = d; |
1849 | lastcell.count = d; |
1830 | |
1850 | |
1831 | if (socket.extmap) |
1851 | if (socket.extmap) |
1832 | { |
1852 | { |
1833 | uint8 stat_hp = 0; |
1853 | uint8 stat_hp = 0; |
|
|
1854 | uint8 stat_width = 0; |
|
|
1855 | tag_t player = 0; |
1834 | |
1856 | |
1835 | // send hp information, if applicable |
1857 | // send hp information, if applicable |
1836 | if (object *op = GET_MAP_FACE_OBJ (m, nx, ny, 0)) |
1858 | if (object *op = GET_MAP_FACE_OBJ (m, nx, ny, 0)) |
|
|
1859 | { |
|
|
1860 | if (op->head || op->invisible) |
|
|
1861 | ; // do not show |
|
|
1862 | else if (op->type == PLAYER |
|
|
1863 | || QUERY_FLAG (op, FLAG_MONSTER) |
|
|
1864 | || QUERY_FLAG (op, FLAG_ALIVE) |
|
|
1865 | || QUERY_FLAG (op, FLAG_GENERATOR)) |
|
|
1866 | { |
1837 | if (op->stats.maxhp > 0 |
1867 | if (op->stats.maxhp > 0 |
1838 | && (unsigned)op->stats.maxhp > (unsigned)op->stats.hp |
1868 | && (unsigned)op->stats.maxhp > (unsigned)op->stats.hp) |
1839 | && IS_LIVE (op)) |
1869 | { |
1840 | stat_hp = 255 - (op->stats.hp * 255 + 254) / op->stats.maxhp; |
1870 | stat_hp = 255 - (op->stats.hp * 255 + 254) / op->stats.maxhp; |
|
|
1871 | stat_width = op->arch->tail_x; |
|
|
1872 | } |
|
|
1873 | } |
1841 | |
1874 | |
|
|
1875 | if (op->type == PLAYER && op != pl) |
|
|
1876 | player = op->count; |
|
|
1877 | } |
|
|
1878 | |
1842 | if (lastcell.stat_hp != stat_hp) |
1879 | if (lastcell.stat_hp != stat_hp && 0) |
1843 | { |
1880 | { |
1844 | lastcell.stat_hp = stat_hp; |
1881 | lastcell.stat_hp = stat_hp; |
1845 | |
1882 | |
1846 | mask |= 0x8; |
1883 | mask |= 0x8; |
1847 | *last_ext |= 0x80; last_ext = sl.buf + sl.len; SockList_AddChar (&sl, 5); |
1884 | *last_ext |= 0x80; last_ext = sl.buf + sl.len; SockList_AddChar (&sl, 5); |
1848 | SockList_AddChar (&sl, stat_hp); |
1885 | SockList_AddChar (&sl, stat_hp); |
|
|
1886 | |
|
|
1887 | if (stat_width > 1) |
|
|
1888 | { |
|
|
1889 | *last_ext |= 0x80; last_ext = sl.buf + sl.len; SockList_AddChar (&sl, 6); |
|
|
1890 | SockList_AddChar (&sl, stat_width); |
|
|
1891 | } |
|
|
1892 | } |
|
|
1893 | |
|
|
1894 | if (lastcell.player != player && 0) |
|
|
1895 | { |
|
|
1896 | lastcell.player = player; |
|
|
1897 | mask |= 0x8; |
|
|
1898 | *last_ext |= 0x80; last_ext = sl.buf + sl.len; SockList_AddChar (&sl, 0x47); |
|
|
1899 | SockList_AddChar (&sl, 4); |
|
|
1900 | SockList_AddInt (&sl, player); |
1849 | } |
1901 | } |
1850 | } |
1902 | } |
1851 | |
1903 | |
1852 | /* Floor face */ |
1904 | /* Floor face */ |
1853 | if (update_space(&sl, &socket, m, nx, ny, ax, ay, 2)) |
1905 | if (update_space(&sl, &socket, m, nx, ny, ax, ay, 2)) |
1854 | mask |= 0x4; |
1906 | mask |= 0x4; |
1855 | |
1907 | |
1856 | if (socket.EMI_smooth) |
1908 | if (socket.EMI_smooth) |
1857 | if (update_smooth(&esl, &socket, m, nx, ny, ax, ay, 2)) |
1909 | if (update_smooth(&esl, &socket, m, nx, ny, ax, ay, 2)) |
1858 | emask |= 0x4; |
1910 | emask |= 0x4; |
1859 | |
1911 | |
1860 | /* Middle face */ |
1912 | /* Middle face */ |
1861 | if (update_space(&sl, &socket, m, nx, ny, ax, ay, 1)) |
1913 | if (update_space(&sl, &socket, m, nx, ny, ax, ay, 1)) |
1862 | mask |= 0x2; |
1914 | mask |= 0x2; |
1863 | |
1915 | |
1864 | if (socket.EMI_smooth) |
1916 | if (socket.EMI_smooth) |
1865 | if (update_smooth(&esl, &socket, m, nx, ny, ax, ay, 1)) |
1917 | if (update_smooth(&esl, &socket, m, nx, ny, ax, ay, 1)) |
1866 | emask |= 0x2; |
1918 | emask |= 0x2; |
1867 | |
1919 | |
1868 | if(nx == pl->x && ny == pl->y && pl->invisible & (pl->invisible < 50 ? 4 : 1)) { |
1920 | if(nx == pl->x && ny == pl->y && pl->invisible & (pl->invisible < 50 ? 4 : 1)) { |
1869 | if (lastcell.faces[0] != pl->face->number) { |
1921 | if (lastcell.faces[0] != pl->face->number) { |
1870 | lastcell.faces[0] = pl->face->number; |
1922 | lastcell.faces[0] = pl->face->number; |
1871 | mask |= 0x1; |
1923 | mask |= 0x1; |
1872 | if (!(socket.faces_sent[pl->face->number] &NS_FACESENT_FACE)) |
1924 | if (!(socket.faces_sent[pl->face->number] &NS_FACESENT_FACE)) |
1873 | esrv_send_face(&socket, pl->face->number, 0); |
1925 | esrv_send_face(&socket, pl->face->number, 0); |
1874 | SockList_AddShort(&sl, pl->face->number); |
1926 | SockList_AddShort(&sl, pl->face->number); |
1875 | } |
1927 | } |
1876 | } |
1928 | } |
1877 | /* Top face */ |
1929 | /* Top face */ |
1878 | else { |
1930 | else { |
1879 | if (update_space(&sl, &socket, m, nx, ny, ax, ay, 0)) |
1931 | if (update_space(&sl, &socket, m, nx, ny, ax, ay, 0)) |
1880 | mask |= 0x1; |
1932 | mask |= 0x1; |
1881 | if (socket.EMI_smooth) |
1933 | if (socket.EMI_smooth) |
1882 | if (update_smooth(&esl, &socket, m, nx, ny, ax, ay, 0)){ |
1934 | if (update_smooth(&esl, &socket, m, nx, ny, ax, ay, 0)){ |
1883 | emask |= 0x1; |
1935 | emask |= 0x1; |
1884 | } |
1936 | } |
1885 | } |
1937 | } |
1886 | /* Check to see if we are in fact sending anything for this |
1938 | /* Check to see if we are in fact sending anything for this |
1887 | * space by checking the mask. If so, update the mask. |
1939 | * space by checking the mask. If so, update the mask. |
1888 | * if not, reset the len to that from before adding the mask |
1940 | * if not, reset the len to that from before adding the mask |
1889 | * value, so we don't send those bits. |
1941 | * value, so we don't send those bits. |
1890 | */ |
1942 | */ |
1891 | if (mask & 0xf) { |
1943 | if (mask & 0xf) { |
1892 | sl.buf[oldlen+1] = mask & 0xff; |
1944 | sl.buf[oldlen+1] = mask & 0xff; |
1893 | } else { |
1945 | } else { |
1894 | sl.len = oldlen; |
1946 | sl.len = oldlen; |
1895 | } |
1947 | } |
1896 | if (emask & 0xf) { |
1948 | if (emask & 0xf) { |
1897 | esl.buf[eoldlen+1] = emask & 0xff; |
1949 | esl.buf[eoldlen+1] = emask & 0xff; |
1898 | } else { |
1950 | } else { |
1899 | esl.len = eoldlen; |
1951 | esl.len = eoldlen; |
1900 | } |
1952 | } |
1901 | } /* else this is a viewable space */ |
1953 | } /* else this is a viewable space */ |
1902 | } /* for x loop */ |
1954 | } /* for x loop */ |
1903 | } /* for y loop */ |
1955 | } /* for y loop */ |
1904 | |
1956 | |
1905 | /* Verify that we in fact do need to send this */ |
1957 | /* Verify that we in fact do need to send this */ |
1906 | if (socket.ext_mapinfos){ |
1958 | if (socket.ext_mapinfos){ |
1907 | if (!(sl.len>startlen || socket.sent_scroll)){ |
1959 | if (!(sl.len>startlen || socket.sent_scroll)){ |
… | |
… | |
1915 | Send_With_Handling(&socket, &esl); |
1967 | Send_With_Handling(&socket, &esl); |
1916 | } |
1968 | } |
1917 | free(esl.buf); |
1969 | free(esl.buf); |
1918 | } |
1970 | } |
1919 | if (sl.len>startlen || socket.sent_scroll) { |
1971 | if (sl.len>startlen || socket.sent_scroll) { |
1920 | Send_With_Handling(&socket, &sl); |
1972 | Send_With_Handling(&socket, &sl); |
1921 | socket.sent_scroll = 0; |
1973 | socket.sent_scroll = 0; |
1922 | } |
1974 | } |
1923 | free(sl.buf); |
1975 | free(sl.buf); |
1924 | } |
1976 | } |
1925 | |
1977 | |
1926 | /** |
1978 | /** |
… | |
… | |
1935 | int d, mflags; |
1987 | int d, mflags; |
1936 | struct Map newmap; |
1988 | struct Map newmap; |
1937 | mapstruct *m, *pm; |
1989 | mapstruct *m, *pm; |
1938 | |
1990 | |
1939 | if (pl->type != PLAYER) { |
1991 | if (pl->type != PLAYER) { |
1940 | LOG(llevError,"draw_client_map called with non player/non eric-server\n"); |
1992 | LOG(llevError,"draw_client_map called with non player/non eric-server\n"); |
1941 | return; |
1993 | return; |
1942 | } |
1994 | } |
1943 | |
1995 | |
1944 | if (pl->contr->transport) { |
|
|
1945 | pm = pl->contr->transport->map; |
|
|
1946 | } |
|
|
1947 | else |
|
|
1948 | pm = pl->map; |
1996 | pm = pl->map; |
1949 | |
1997 | |
1950 | /* If player is just joining the game, he isn't here yet, so the map |
1998 | /* If player is just joining the game, he isn't here yet, so the map |
1951 | * can get swapped out. If so, don't try to send them a map. All will |
1999 | * can get swapped out. If so, don't try to send them a map. All will |
1952 | * be OK once they really log in. |
2000 | * be OK once they really log in. |
1953 | */ |
2001 | */ |
… | |
… | |
1955 | |
2003 | |
1956 | memset(&newmap, 0, sizeof(struct Map)); |
2004 | memset(&newmap, 0, sizeof(struct Map)); |
1957 | |
2005 | |
1958 | for(j = (pl->y - pl->contr->socket.mapy/2) ; j < (pl->y + (pl->contr->socket.mapy+1)/2); j++) { |
2006 | for(j = (pl->y - pl->contr->socket.mapy/2) ; j < (pl->y + (pl->contr->socket.mapy+1)/2); j++) { |
1959 | for(i = (pl->x - pl->contr->socket.mapx/2) ; i < (pl->x + (pl->contr->socket.mapx+1)/2); i++) { |
2007 | for(i = (pl->x - pl->contr->socket.mapx/2) ; i < (pl->x + (pl->contr->socket.mapx+1)/2); i++) { |
1960 | ax=i; |
2008 | ax=i; |
1961 | ay=j; |
2009 | ay=j; |
1962 | m = pm; |
2010 | m = pm; |
1963 | mflags = get_map_flags(m, &m, ax, ay, &ax, &ay); |
2011 | mflags = get_map_flags(m, &m, ax, ay, &ax, &ay); |
1964 | if (mflags & P_OUT_OF_MAP) |
2012 | if (mflags & P_OUT_OF_MAP) |
1965 | continue; |
2013 | continue; |
1966 | if (mflags & P_NEED_UPDATE) |
2014 | if (mflags & P_NEED_UPDATE) |
1967 | update_position(m, ax, ay); |
2015 | update_position(m, ax, ay); |
1968 | /* If a map is visible to the player, we don't want to swap it out |
2016 | /* If a map is visible to the player, we don't want to swap it out |
1969 | * just to reload it. This should really call something like |
2017 | * just to reload it. This should really call something like |
1970 | * swap_map, but this is much more efficient and 'good enough' |
2018 | * swap_map, but this is much more efficient and 'good enough' |
1971 | */ |
2019 | */ |
1972 | if (mflags & P_NEW_MAP) |
2020 | if (mflags & P_NEW_MAP) |
1973 | m->timeout = 50; |
2021 | m->timeout = 50; |
1974 | } |
2022 | } |
1975 | } |
2023 | } |
1976 | /* do LOS after calls to update_position */ |
2024 | /* do LOS after calls to update_position */ |
1977 | if(pl->contr->do_los) { |
2025 | if(pl->contr->do_los) { |
1978 | update_los(pl); |
2026 | update_los(pl); |
1979 | pl->contr->do_los = 0; |
2027 | pl->contr->do_los = 0; |
… | |
… | |
1984 | draw_client_map1(pl); |
2032 | draw_client_map1(pl); |
1985 | return; |
2033 | return; |
1986 | } |
2034 | } |
1987 | |
2035 | |
1988 | if(pl->invisible & (pl->invisible < 50 ? 4 : 1)) { |
2036 | if(pl->invisible & (pl->invisible < 50 ? 4 : 1)) { |
1989 | esrv_map_setbelow(&pl->contr->socket,pl->contr->socket.mapx/2, |
2037 | esrv_map_setbelow(&pl->contr->socket,pl->contr->socket.mapx/2, |
1990 | pl->contr->socket.mapy/2,pl->face->number,&newmap); |
2038 | pl->contr->socket.mapy/2,pl->face->number,&newmap); |
1991 | } |
2039 | } |
1992 | |
2040 | |
1993 | /* j and i are the y and x coordinates of the real map (which is |
2041 | /* j and i are the y and x coordinates of the real map (which is |
1994 | * basically some number of spaces around the player) |
2042 | * basically some number of spaces around the player) |
1995 | * ax and ay are values from within the viewport (ie, 0, 0 is upper |
2043 | * ax and ay are values from within the viewport (ie, 0, 0 is upper |
… | |
… | |
2000 | * 11 spaces. Now, we would send from -5 to 4, which is properly. If mapx is |
2048 | * 11 spaces. Now, we would send from -5 to 4, which is properly. If mapx is |
2001 | * odd, this still works fine. |
2049 | * odd, this still works fine. |
2002 | */ |
2050 | */ |
2003 | ay=0; |
2051 | ay=0; |
2004 | for(j=pl->y-pl->contr->socket.mapy/2; j<=pl->y+(pl->contr->socket.mapy-1)/2;j++, ay++) { |
2052 | for(j=pl->y-pl->contr->socket.mapy/2; j<=pl->y+(pl->contr->socket.mapy-1)/2;j++, ay++) { |
2005 | ax=0; |
2053 | ax=0; |
2006 | for(i=pl->x-pl->contr->socket.mapx/2;i<=pl->x+(pl->contr->socket.mapx-1)/2;i++, ax++) { |
2054 | for(i=pl->x-pl->contr->socket.mapx/2;i<=pl->x+(pl->contr->socket.mapx-1)/2;i++, ax++) { |
2007 | |
2055 | |
2008 | d = pl->contr->blocked_los[ax][ay]; |
2056 | d = pl->contr->blocked_los[ax][ay]; |
2009 | /* note the out_of_map and d>3 checks are both within the same |
2057 | /* note the out_of_map and d>3 checks are both within the same |
2010 | * negation check. |
2058 | * negation check. |
2011 | */ |
2059 | */ |
2012 | nx = i; |
2060 | nx = i; |
2013 | ny = j; |
2061 | ny = j; |
2014 | m = get_map_from_coord(pm, &nx, &ny); |
2062 | m = get_map_from_coord(pm, &nx, &ny); |
2015 | if (m && d<4) { |
2063 | if (m && d<4) { |
2016 | face = GET_MAP_FACE(m, nx, ny,0); |
2064 | face = GET_MAP_FACE(m, nx, ny,0); |
2017 | floor2 = GET_MAP_FACE(m, nx, ny,1); |
2065 | floor2 = GET_MAP_FACE(m, nx, ny,1); |
2018 | floor = GET_MAP_FACE(m, nx, ny,2); |
2066 | floor = GET_MAP_FACE(m, nx, ny,2); |
2019 | |
2067 | |
2020 | /* If all is blank, send a blank face. */ |
2068 | /* If all is blank, send a blank face. */ |
2021 | if ((!face || face == blank_face) && |
2069 | if ((!face || face == blank_face) && |
2022 | (!floor2 || floor2 == blank_face) && |
2070 | (!floor2 || floor2 == blank_face) && |
2023 | (!floor || floor == blank_face)) { |
2071 | (!floor || floor == blank_face)) { |
2024 | esrv_map_setbelow(&pl->contr->socket,ax,ay, |
2072 | esrv_map_setbelow(&pl->contr->socket,ax,ay, |
2025 | blank_face->number,&newmap); |
2073 | blank_face->number,&newmap); |
2026 | } else { /* actually have something interesting */ |
2074 | } else { /* actually have something interesting */ |
2027 | /* send the darkness mask, if any. */ |
2075 | /* send the darkness mask, if any. */ |
2028 | if (d && pl->contr->socket.darkness) |
2076 | if (d && pl->contr->socket.darkness) |
2029 | esrv_map_setbelow(&pl->contr->socket,ax,ay, |
2077 | esrv_map_setbelow(&pl->contr->socket,ax,ay, |
2030 | dark_faces[d-1]->number,&newmap); |
2078 | dark_faces[d-1]->number,&newmap); |
2031 | |
2079 | |
2032 | if (face && face != blank_face) |
2080 | if (face && face != blank_face) |
2033 | esrv_map_setbelow(&pl->contr->socket,ax,ay, |
2081 | esrv_map_setbelow(&pl->contr->socket,ax,ay, |
2034 | face->number,&newmap); |
2082 | face->number,&newmap); |
2035 | if (floor2 && floor2 != blank_face) |
2083 | if (floor2 && floor2 != blank_face) |
2036 | esrv_map_setbelow(&pl->contr->socket,ax,ay, |
2084 | esrv_map_setbelow(&pl->contr->socket,ax,ay, |
2037 | floor2->number,&newmap); |
2085 | floor2->number,&newmap); |
2038 | if (floor && floor != blank_face) |
2086 | if (floor && floor != blank_face) |
2039 | esrv_map_setbelow(&pl->contr->socket,ax,ay, |
2087 | esrv_map_setbelow(&pl->contr->socket,ax,ay, |
2040 | floor->number,&newmap); |
2088 | floor->number,&newmap); |
2041 | } |
2089 | } |
2042 | } /* Is a valid space */ |
2090 | } /* Is a valid space */ |
2043 | } |
2091 | } |
2044 | } |
2092 | } |
2045 | esrv_map_doneredraw(&pl->contr->socket, &newmap); |
2093 | esrv_map_doneredraw(&pl->contr->socket, &newmap); |
2046 | |
2094 | |
2047 | check_map_change (pl->contr); |
2095 | check_map_change (pl->contr); |
2048 | } |
2096 | } |
… | |
… | |
2068 | int i; |
2116 | int i; |
2069 | |
2117 | |
2070 | sl.buf = (unsigned char*) malloc(MAXSOCKBUF); |
2118 | sl.buf = (unsigned char*) malloc(MAXSOCKBUF); |
2071 | strcpy((char*)sl.buf,"replyinfo skill_info\n"); |
2119 | strcpy((char*)sl.buf,"replyinfo skill_info\n"); |
2072 | for (i=1; i< NUM_SKILLS; i++) { |
2120 | for (i=1; i< NUM_SKILLS; i++) { |
2073 | sprintf((char*)sl.buf + strlen((char*)sl.buf), "%d:%s\n", i + CS_STAT_SKILLINFO, |
2121 | sprintf((char*)sl.buf + strlen((char*)sl.buf), "%d:%s\n", i + CS_STAT_SKILLINFO, |
2074 | skill_names[i]); |
2122 | &skill_names[i]); |
2075 | } |
2123 | } |
2076 | sl.len = strlen((char*)sl.buf); |
2124 | sl.len = strlen((char*)sl.buf); |
2077 | if (sl.len >= MAXSOCKBUF) { |
2125 | if (sl.len >= MAXSOCKBUF) { |
2078 | LOG(llevError,"Buffer overflow in send_skill_info!\n"); |
2126 | LOG(llevError,"Buffer overflow in send_skill_info!\n"); |
2079 | fatal(0); |
2127 | fatal(0); |
2080 | } |
2128 | } |
2081 | Send_With_Handling(ns, &sl); |
2129 | Send_With_Handling(ns, &sl); |
2082 | free(sl.buf); |
2130 | free(sl.buf); |
2083 | } |
2131 | } |
2084 | |
2132 | |
… | |
… | |
2091 | int i; |
2139 | int i; |
2092 | |
2140 | |
2093 | sl.buf = (unsigned char*) malloc(MAXSOCKBUF); |
2141 | sl.buf = (unsigned char*) malloc(MAXSOCKBUF); |
2094 | strcpy((char*)sl.buf,"replyinfo spell_paths\n"); |
2142 | strcpy((char*)sl.buf,"replyinfo spell_paths\n"); |
2095 | for(i=0; i<NRSPELLPATHS; i++) |
2143 | for(i=0; i<NRSPELLPATHS; i++) |
2096 | sprintf((char*)sl.buf + strlen((char*)sl.buf), "%d:%s\n", 1<<i, spellpathnames[i]); |
2144 | sprintf((char*)sl.buf + strlen((char*)sl.buf), "%d:%s\n", 1<<i, spellpathnames[i]); |
2097 | sl.len = strlen((char*)sl.buf); |
2145 | sl.len = strlen((char*)sl.buf); |
2098 | if (sl.len >= MAXSOCKBUF) { |
2146 | if (sl.len >= MAXSOCKBUF) { |
2099 | LOG(llevError,"Buffer overflow in send_spell_paths!\n"); |
2147 | LOG(llevError,"Buffer overflow in send_spell_paths!\n"); |
2100 | fatal(0); |
2148 | fatal(0); |
2101 | } |
2149 | } |
2102 | Send_With_Handling(ns, &sl); |
2150 | Send_With_Handling(ns, &sl); |
2103 | free(sl.buf); |
2151 | free(sl.buf); |
2104 | } |
2152 | } |
2105 | |
2153 | |
… | |
… | |
2111 | SockList sl; |
2159 | SockList sl; |
2112 | int flags=0; |
2160 | int flags=0; |
2113 | object *spell; |
2161 | object *spell; |
2114 | if (!pl->socket.monitor_spells) return; |
2162 | if (!pl->socket.monitor_spells) return; |
2115 | for (spell=pl->ob->inv; spell!=NULL; spell=spell->below) { |
2163 | for (spell=pl->ob->inv; spell!=NULL; spell=spell->below) { |
2116 | if (spell->type == SPELL) { |
2164 | if (spell->type == SPELL) { |
2117 | /* check if we need to update it*/ |
2165 | /* check if we need to update it*/ |
2118 | if (spell->last_sp != SP_level_spellpoint_cost(pl->ob, spell, SPELL_MANA)) { |
2166 | if (spell->last_sp != SP_level_spellpoint_cost(pl->ob, spell, SPELL_MANA)) { |
2119 | spell->last_sp = SP_level_spellpoint_cost(pl->ob, spell, SPELL_MANA); |
2167 | spell->last_sp = SP_level_spellpoint_cost(pl->ob, spell, SPELL_MANA); |
2120 | flags |= UPD_SP_MANA; |
2168 | flags |= UPD_SP_MANA; |
2121 | } |
2169 | } |
2122 | if (spell->last_grace != SP_level_spellpoint_cost(pl->ob, spell, SPELL_GRACE)) { |
2170 | if (spell->last_grace != SP_level_spellpoint_cost(pl->ob, spell, SPELL_GRACE)) { |
2123 | spell->last_grace = SP_level_spellpoint_cost(pl->ob, spell, SPELL_GRACE); |
2171 | spell->last_grace = SP_level_spellpoint_cost(pl->ob, spell, SPELL_GRACE); |
2124 | flags |= UPD_SP_GRACE; |
2172 | flags |= UPD_SP_GRACE; |
2125 | } |
2173 | } |
2126 | if (spell->last_eat != spell->stats.dam+SP_level_dam_adjust(pl->ob, spell)) { |
2174 | if (spell->last_eat != spell->stats.dam+SP_level_dam_adjust(pl->ob, spell)) { |
2127 | spell->last_eat = spell->stats.dam+SP_level_dam_adjust(pl->ob, spell); |
2175 | spell->last_eat = spell->stats.dam+SP_level_dam_adjust(pl->ob, spell); |
2128 | flags |= UPD_SP_DAMAGE; |
2176 | flags |= UPD_SP_DAMAGE; |
2129 | } |
2177 | } |
2130 | if (flags !=0) { |
2178 | if (flags !=0) { |
2131 | sl.buf =(unsigned char*) malloc(MAXSOCKBUF); |
2179 | sl.buf =(unsigned char*) malloc(MAXSOCKBUF); |
2132 | strcpy((char*)sl.buf,"updspell "); |
2180 | strcpy((char*)sl.buf,"updspell "); |
2133 | sl.len=strlen((char*)sl.buf); |
2181 | sl.len=strlen((char*)sl.buf); |
2134 | SockList_AddChar(&sl, flags); |
2182 | SockList_AddChar(&sl, flags); |
2135 | SockList_AddInt(&sl, spell->count); |
2183 | SockList_AddInt(&sl, spell->count); |
2136 | if (flags & UPD_SP_MANA) SockList_AddShort(&sl, spell->last_sp); |
2184 | if (flags & UPD_SP_MANA) SockList_AddShort(&sl, spell->last_sp); |
2137 | if (flags & UPD_SP_GRACE) SockList_AddShort(&sl, spell->last_grace); |
2185 | if (flags & UPD_SP_GRACE) SockList_AddShort(&sl, spell->last_grace); |
2138 | if (flags & UPD_SP_DAMAGE) SockList_AddShort(&sl, spell->last_eat); |
2186 | if (flags & UPD_SP_DAMAGE) SockList_AddShort(&sl, spell->last_eat); |
2139 | flags = 0; |
2187 | flags = 0; |
2140 | Send_With_Handling(&pl->socket, &sl); |
2188 | Send_With_Handling(&pl->socket, &sl); |
2141 | free(sl.buf); |
2189 | free(sl.buf); |
2142 | } |
2190 | } |
2143 | } |
2191 | } |
2144 | } |
2192 | } |
2145 | } |
2193 | } |
2146 | |
2194 | |
2147 | void esrv_remove_spell(player *pl, object *spell) { |
2195 | void esrv_remove_spell(player *pl, object *spell) { |
2148 | SockList sl; |
2196 | SockList sl; |
2149 | |
2197 | |
2150 | if (!pl->socket.monitor_spells) return; |
2198 | if (!pl->socket.monitor_spells) return; |
2151 | if (!pl || !spell || spell->env != pl->ob) { |
2199 | if (!pl || !spell || spell->env != pl->ob) { |
2152 | LOG(llevError, "Invalid call to esrv_remove_spell"); |
2200 | LOG(llevError, "Invalid call to esrv_remove_spell"); |
2153 | return; |
2201 | return; |
2154 | } |
2202 | } |
2155 | sl.buf = (unsigned char*) malloc(MAXSOCKBUF); |
2203 | sl.buf = (unsigned char*) malloc(MAXSOCKBUF); |
2156 | strcpy((char*)sl.buf,"delspell "); |
2204 | strcpy((char*)sl.buf,"delspell "); |
2157 | sl.len=strlen((char*)sl.buf); |
2205 | sl.len=strlen((char*)sl.buf); |
2158 | SockList_AddInt(&sl, spell->count); |
2206 | SockList_AddInt(&sl, spell->count); |
… | |
… | |
2180 | SockList_AddShort(sl, spell->last_grace); |
2228 | SockList_AddShort(sl, spell->last_grace); |
2181 | SockList_AddShort(sl, spell->last_eat); |
2229 | SockList_AddShort(sl, spell->last_eat); |
2182 | |
2230 | |
2183 | /* figure out which skill it uses, if it uses one */ |
2231 | /* figure out which skill it uses, if it uses one */ |
2184 | if (spell->skill) { |
2232 | if (spell->skill) { |
2185 | for (i=1; i< NUM_SKILLS; i++) |
2233 | for (i=1; i< NUM_SKILLS; i++) |
2186 | if (!strcmp(spell->skill, skill_names[i])) { |
2234 | if (!strcmp(spell->skill, skill_names[i])) { |
2187 | skill = i+CS_STAT_SKILLINFO; |
2235 | skill = i+CS_STAT_SKILLINFO; |
2188 | break; |
2236 | break; |
2189 | } |
2237 | } |
2190 | } |
2238 | } |
2191 | SockList_AddChar(sl, skill); |
2239 | SockList_AddChar(sl, skill); |
2192 | |
2240 | |
2193 | SockList_AddInt(sl, spell->path_attuned); |
2241 | SockList_AddInt(sl, spell->path_attuned); |
2194 | SockList_AddInt(sl, (spell->face)?spell->face->number:0); |
2242 | SockList_AddInt(sl, (spell->face)?spell->face->number:0); |
… | |
… | |
2197 | SockList_AddChar(sl, (char)len); |
2245 | SockList_AddChar(sl, (char)len); |
2198 | memcpy(sl->buf+sl->len, spell->name, len); |
2246 | memcpy(sl->buf+sl->len, spell->name, len); |
2199 | sl->len+=len; |
2247 | sl->len+=len; |
2200 | |
2248 | |
2201 | if (!spell->msg) { |
2249 | if (!spell->msg) { |
2202 | SockList_AddShort(sl, 0); |
2250 | SockList_AddShort(sl, 0); |
2203 | } |
2251 | } |
2204 | else { |
2252 | else { |
2205 | len = strlen(spell->msg); |
2253 | len = strlen(spell->msg); |
2206 | SockList_AddShort(sl, len); |
2254 | SockList_AddShort(sl, len); |
2207 | memcpy(sl->buf+sl->len, spell->msg, len); |
2255 | memcpy(sl->buf+sl->len, spell->msg, len); |
2208 | sl->len+=len; |
2256 | sl->len+=len; |
2209 | } |
2257 | } |
2210 | } |
2258 | } |
2211 | |
2259 | |
2212 | /** |
2260 | /** |
2213 | * This tells the client to add the spell *ob, if *ob is NULL, then add |
2261 | * This tells the client to add the spell *ob, if *ob is NULL, then add |
2214 | * all spells in the player's inventory. |
2262 | * all spells in the player's inventory. |
2215 | */ |
2263 | */ |
2216 | void esrv_add_spells(player *pl, object *spell) { |
2264 | void esrv_add_spells(player *pl, object *spell) { |
2217 | SockList sl; |
2265 | SockList sl; |
2218 | if (!pl) { |
2266 | if (!pl) { |
2219 | LOG(llevError, "esrv_add_spells, tried to add a spell to a NULL player"); |
2267 | LOG(llevError, "esrv_add_spells, tried to add a spell to a NULL player"); |
2220 | return; |
2268 | return; |
2221 | } |
2269 | } |
2222 | if (!pl->socket.monitor_spells) return; |
2270 | if (!pl->socket.monitor_spells) return; |
2223 | sl.buf = (unsigned char*) malloc(MAXSOCKBUF); |
2271 | sl.buf = (unsigned char*) malloc(MAXSOCKBUF); |
2224 | strcpy((char*)sl.buf,"addspell "); |
2272 | strcpy((char*)sl.buf,"addspell "); |
2225 | sl.len=strlen((char*)sl.buf); |
2273 | sl.len=strlen((char*)sl.buf); |
2226 | if (!spell) { |
2274 | if (!spell) { |
2227 | for (spell=pl->ob->inv; spell!=NULL; spell=spell->below) { |
2275 | for (spell=pl->ob->inv; spell!=NULL; spell=spell->below) { |
2228 | /* were we to simply keep appending data here, we could exceed |
2276 | /* were we to simply keep appending data here, we could exceed |
2229 | * MAXSOCKBUF if the player has enough spells to add, we know that |
2277 | * MAXSOCKBUF if the player has enough spells to add, we know that |
2230 | * append_spells will always append 19 data bytes, plus 4 length |
2278 | * append_spells will always append 19 data bytes, plus 4 length |
2231 | * bytes and 3 strings (because that is the spec) so we need to |
2279 | * bytes and 3 strings (because that is the spec) so we need to |
2232 | * check that the length of those 3 strings, plus the 23 bytes, |
2280 | * check that the length of those 3 strings, plus the 23 bytes, |
2233 | * won't take us over the length limit for the socket, if it does, |
2281 | * won't take us over the length limit for the socket, if it does, |
2234 | * we need to send what we already have, and restart packet formation |
2282 | * we need to send what we already have, and restart packet formation |
2235 | */ |
2283 | */ |
2236 | /* Seeing crashes by overflowed buffers. Quick arithemetic seems |
2284 | /* Seeing crashes by overflowed buffers. Quick arithemetic seems |
2237 | * to show add_spell is 26 bytes + 2 strings. However, the overun |
2285 | * to show add_spell is 26 bytes + 2 strings. However, the overun |
2238 | * is hundreds of bytes off, so correcting 22 vs 26 doesn't seem |
2286 | * is hundreds of bytes off, so correcting 22 vs 26 doesn't seem |
2239 | * like it will fix this |
2287 | * like it will fix this |
2240 | */ |
2288 | */ |
2241 | if (spell->type != SPELL) continue; |
2289 | if (spell->type != SPELL) continue; |
2242 | if (sl.len >= (MAXSOCKBUF - (26 + strlen(spell->name) + |
2290 | if (sl.len >= (MAXSOCKBUF - (26 + strlen(spell->name) + |
2243 | (spell->msg?strlen(spell->msg):0)))) { |
2291 | (spell->msg?strlen(spell->msg):0)))) { |
2244 | Send_With_Handling(&pl->socket, &sl); |
2292 | Send_With_Handling(&pl->socket, &sl); |
2245 | strcpy((char*)sl.buf,"addspell "); |
2293 | strcpy((char*)sl.buf,"addspell "); |
2246 | sl.len=strlen((char*)sl.buf); |
2294 | sl.len=strlen((char*)sl.buf); |
2247 | } |
2295 | } |
2248 | append_spell(pl, &sl, spell); |
2296 | append_spell(pl, &sl, spell); |
2249 | } |
2297 | } |
2250 | } |
2298 | } |
2251 | else if (spell->type != SPELL) { |
2299 | else if (spell->type != SPELL) { |
2252 | LOG(llevError, "Asked to send a non-spell object as a spell"); |
2300 | LOG(llevError, "Asked to send a non-spell object as a spell"); |
2253 | return; |
2301 | return; |
2254 | } |
2302 | } |
2255 | else append_spell(pl, &sl, spell); |
2303 | else append_spell(pl, &sl, spell); |
2256 | if (sl.len >= MAXSOCKBUF) { |
2304 | if (sl.len >= MAXSOCKBUF) { |
2257 | LOG(llevError,"Buffer overflow in esrv_add_spells!\n"); |
2305 | LOG(llevError,"Buffer overflow in esrv_add_spells!\n"); |
2258 | fatal(0); |
2306 | fatal(0); |
2259 | } |
2307 | } |
2260 | /* finally, we can send the packet */ |
2308 | /* finally, we can send the packet */ |
2261 | Send_With_Handling(&pl->socket, &sl); |
2309 | Send_With_Handling(&pl->socket, &sl); |
2262 | free(sl.buf); |
2310 | free(sl.buf); |
2263 | } |
2311 | } |