--- deliantra/server/socket/request.c 2006/04/15 22:38:31 1.2 +++ deliantra/server/socket/request.c 2006/05/01 12:22:03 1.8 @@ -122,9 +122,18 @@ pl->socket.current_map = ob->map; if (ob->map && ob->map->path [0]) - snprintf (buf, MAX_BUF, "mapinfo current %d %d %d %d %s", - ob->x, ob->y, - ob->map->width, ob->map->height, ob->map->path); + { + int flags = 0; + + if (ob->map->tile_path [0]) flags |= 1; + if (ob->map->tile_path [1]) flags |= 2; + if (ob->map->tile_path [2]) flags |= 4; + if (ob->map->tile_path [3]) flags |= 8; + + snprintf (buf, MAX_BUF, "mapinfo - spatial %d %d %d %d %d %s", + flags, pl->socket.mapx / 2 - ob->x, pl->socket.mapy / 2 - ob->y, + ob->map->width, ob->map->height, ob->map->path); + } else snprintf (buf, MAX_BUF, "mapinfo current"); @@ -132,6 +141,82 @@ } } +void MapInfoCmd (char *buf, int len, player *pl) +{ + // mapinfo tag spatial flags x y w h hash + + char bigbuf[MAX_BUF], *cp, *token; + + token = buf; + // copy token + if (!(buf = strchr (buf, ' '))) + return; + + *buf++ = 0; + + if (!strncmp (buf, "spatial ", 8)) + { + buf += 8; + + // initial map and its origin + mapstruct *map = pl->ob->map; + sint16 dx, dy; + int mapx = pl->socket.mapx / 2 - pl->ob->x; + int mapy = pl->socket.mapy / 2 - pl->ob->y; + int max_distance = 8; // limit maximum path length to something generous + + while (*buf && map && max_distance) + { + int dir = *buf++; + + switch (dir) + { + case '1': + dx = 0; dy = -1; map = get_map_from_coord (map, &dx, &dy); + map && (mapy -= map->height); + break; + case '2': + mapx += map->width; + dx = map->width; dy = 0; map = get_map_from_coord (map, &dx, &dy); + break; + case '3': + mapy += map->height; + dx = 0; dy = map->height; map = get_map_from_coord (map, &dx, &dy); + break; + case '4': + dx = -1; dy = 0; map = get_map_from_coord (map, &dx, &dy); + map && (mapx -= map->width); + break; + } + + --max_distance; + } + + if (!max_distance) + snprintf (bigbuf, MAX_BUF, "mapinfo %s error", token); + else if (map && map->path [0]) + { + int flags = 0; + + if (map->tile_path [0]) flags |= 1; + if (map->tile_path [1]) flags |= 2; + if (map->tile_path [2]) flags |= 4; + if (map->tile_path [3]) flags |= 8; + + snprintf (bigbuf, MAX_BUF, "mapinfo %s spatial %d %d %d %d %d %s", + token, flags, mapx, mapy, + map->width, map->height, map->path); + } + else + snprintf (bigbuf, MAX_BUF, "mapinfo %s nomap", token); + } + else + snprintf (bigbuf, MAX_BUF, "mapinfo %s unsupported", token); + + Write_String_To_Socket (&pl->socket, bigbuf, strlen (bigbuf)); +} + /** This is the Setup cmd - easy first implementation */ void SetUp(char *buf, int len, NewSocket *ns) { @@ -503,7 +588,7 @@ SockList sl; if (len < 7) { - LOG(llevDebug,"Corrupt ncom command - not long enough - discarding\n"); + LOG(llevDebug,"Corrupt ncom command <%s> not long enough - discarding\n", buf); return; } @@ -704,7 +789,7 @@ memset(&pl->socket.lastmap, 0, sizeof(pl->socket.lastmap)); Write_String_To_Socket( &pl->socket, "newmap", 6); } - check_map_change (pl); + pl->socket.current_map = 0; } @@ -1470,8 +1555,6 @@ uint8 extendedinfos; mapstruct *m; - check_map_change (pl->contr); - sl.buf=malloc(MAXSOCKBUF); if (pl->contr->socket.mapmode == Map1Cmd) strcpy((char*)sl.buf,"map1 "); @@ -1761,6 +1844,8 @@ pl->contr->socket.sent_scroll = 0; } free(sl.buf); + + check_map_change (pl->contr); } /** @@ -1883,6 +1968,8 @@ } } esrv_map_doneredraw(&pl->contr->socket, &newmap); + + check_map_change (pl->contr); } @@ -1967,7 +2054,7 @@ skill_names[i]); } sl.len = strlen((char*)sl.buf); - if (sl.len > MAXSOCKBUF) { + if (sl.len >= MAXSOCKBUF) { LOG(llevError,"Buffer overflow in send_skill_info!\n"); fatal(0); } @@ -1988,7 +2075,7 @@ for(i=0; i MAXSOCKBUF) { + if (sl.len >= MAXSOCKBUF) { LOG(llevError,"Buffer overflow in send_spell_paths!\n"); fatal(0); } @@ -2132,7 +2219,7 @@ * like it will fix this */ if (spell->type != SPELL) continue; - if (sl.len > (MAXSOCKBUF - (26 + strlen(spell->name) + + if (sl.len >= (MAXSOCKBUF - (26 + strlen(spell->name) + (spell->msg?strlen(spell->msg):0)))) { Send_With_Handling(&pl->socket, &sl); strcpy((char*)sl.buf,"addspell "); @@ -2146,7 +2233,7 @@ return; } else append_spell(pl, &sl, spell); - if (sl.len > MAXSOCKBUF) { + if (sl.len >= MAXSOCKBUF) { LOG(llevError,"Buffer overflow in esrv_add_spells!\n"); fatal(0); }