--- deliantra/server/socket/request.c 2006/04/16 02:56:46 1.3 +++ deliantra/server/socket/request.c 2006/06/11 15:02:17 1.9 @@ -125,13 +125,13 @@ { int flags = 0; - if (ob->map->tile_map [0]) flags |= 1; - if (ob->map->tile_map [1]) flags |= 2; - if (ob->map->tile_map [2]) flags |= 4; - if (ob->map->tile_map [3]) flags |= 8; + 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 current %d %d %d %d %d %s", - flags, ob->x, ob->y, + 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 @@ -141,6 +141,87 @@ } } +void ExtCmd (char *buf, int len, player *pl) +{ + execute_global_event (EVENT_EXTCMD, pl, buf, len); +} + +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) { @@ -210,7 +291,10 @@ // safe_strcat(cmdback, param, &slen, HUGE_BUF); } else if (!strcmp(cmd,"mapinfocmd")) { ns->mapinfocmd = atoi(param); - safe_strcat(cmdback, param, &slen, HUGE_BUF); + safe_strcat(cmdback, "1", &slen, HUGE_BUF); + } else if (!strcmp(cmd,"extcmd")) { + ns->extcmd = atoi(param); + safe_strcat(cmdback, "1", &slen, HUGE_BUF); } else if (!strcmp(cmd,"facecache")) { ns->facecache = atoi(param); safe_strcat(cmdback, param, &slen, HUGE_BUF); @@ -512,7 +596,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; } @@ -713,7 +797,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; } @@ -1479,8 +1563,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 "); @@ -1770,6 +1852,8 @@ pl->contr->socket.sent_scroll = 0; } free(sl.buf); + + check_map_change (pl->contr); } /** @@ -1892,6 +1976,8 @@ } } esrv_map_doneredraw(&pl->contr->socket, &newmap); + + check_map_change (pl->contr); } @@ -1976,7 +2062,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); } @@ -1997,7 +2083,7 @@ for(i=0; i MAXSOCKBUF) { + if (sl.len >= MAXSOCKBUF) { LOG(llevError,"Buffer overflow in send_spell_paths!\n"); fatal(0); } @@ -2141,7 +2227,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 "); @@ -2155,7 +2241,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); }