--- deliantra/server/socket/request.c 2006/03/15 14:05:40 1.1.1.3 +++ deliantra/server/socket/request.c 2006/06/19 10:15:44 1.10 @@ -106,6 +106,122 @@ -1 /* Disease - not fully done yet */ }; +/** check for map change and send new map data */ +static void +check_map_change (player *pl) +{ + char buf[MAX_BUF]; /* eauugggh */ + + object *ob = pl->ob; + + if (!pl->socket.mapinfocmd) + return; + + if (pl->socket.current_map != ob->map) + { + pl->socket.current_map = ob->map; + + if (ob->map && ob->map->path [0]) + { + 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"); + + Write_String_To_Socket (&pl->socket, buf, strlen (buf)); + } +} + +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) { @@ -170,6 +286,15 @@ } else if (!strcmp(cmd,"newmapcmd")) { ns->newmapcmd= atoi(param); safe_strcat(cmdback, param, &slen, HUGE_BUF); +// } else if (!strcmp(cmd,"plugincmd")) { +// ns->plugincmd = atoi(param); +// safe_strcat(cmdback, param, &slen, HUGE_BUF); + } else if (!strcmp(cmd,"mapinfocmd")) { + ns->mapinfocmd = atoi(param); + 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); @@ -471,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; } @@ -672,6 +797,7 @@ memset(&pl->socket.lastmap, 0, sizeof(pl->socket.lastmap)); Write_String_To_Socket( &pl->socket, "newmap", 6); } + pl->socket.current_map = 0; } @@ -1487,8 +1613,7 @@ ax=0; for(x=pl->x-pl->contr->socket.mapx/2;xcontr->socket.sent_scroll = 0; } free(sl.buf); + + check_map_change (pl->contr); } /** @@ -1848,6 +1975,8 @@ } } esrv_map_doneredraw(&pl->contr->socket, &newmap); + + check_map_change (pl->contr); } @@ -1932,7 +2061,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); } @@ -1953,7 +2082,7 @@ for(i=0; i MAXSOCKBUF) { + if (sl.len >= MAXSOCKBUF) { LOG(llevError,"Buffer overflow in send_spell_paths!\n"); fatal(0); } @@ -2097,7 +2226,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 "); @@ -2111,7 +2240,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); }