--- deliantra/server/socket/request.c 2006/02/22 18:03:29 1.1.1.2 +++ deliantra/server/socket/request.c 2006/04/17 07:31:54 1.6 @@ -106,10 +106,121 @@ -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 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) { - int s; + int s, slen; char *cmd, *param, cmdback[HUGE_BUF]; /* run through the cmds of setup @@ -139,40 +250,46 @@ buf[s++]=0; while (buf[s] == ' ') s++; - strcat(cmdback, " "); - strcat(cmdback, cmd); - strcat(cmdback, " "); - + slen = strlen(cmdback); + safe_strcat(cmdback, " ", &slen, HUGE_BUF); + safe_strcat(cmdback, cmd, &slen, HUGE_BUF); + safe_strcat(cmdback, " ", &slen, HUGE_BUF); if (!strcmp(cmd,"sound")) { ns->sound = atoi(param); - strcat(cmdback, param); + safe_strcat(cmdback, param, &slen, HUGE_BUF); } else if (!strcmp(cmd,"exp64")) { ns->exp64 = atoi(param); - strcat(cmdback, param); + safe_strcat(cmdback, param, &slen, HUGE_BUF); } else if (!strcmp(cmd, "spellmon")) { ns->monitor_spells = atoi(param); - strcat(cmdback, param); + safe_strcat(cmdback, param, &slen, HUGE_BUF); } else if (!strcmp(cmd,"darkness")) { ns->darkness = atoi(param); - strcat(cmdback, param); + safe_strcat(cmdback, param, &slen, HUGE_BUF); } else if (!strcmp(cmd,"map1cmd")) { if (atoi(param)) ns->mapmode = Map1Cmd; /* if beyond this size, need to use map1cmd no matter what */ if (ns->mapx>11 || ns->mapy>11) ns->mapmode = Map1Cmd; - strcat(cmdback, ns->mapmode == Map1Cmd?"1":"0"); + safe_strcat(cmdback, ns->mapmode == Map1Cmd?"1":"0", &slen, HUGE_BUF); } else if (!strcmp(cmd,"map1acmd")) { if (atoi(param)) ns->mapmode = Map1aCmd; /* if beyond this size, need to use map1acmd no matter what */ if (ns->mapx>11 || ns->mapy>11) ns->mapmode = Map1aCmd; - strcat(cmdback, ns->mapmode == Map1aCmd?"1":"0"); + safe_strcat(cmdback, ns->mapmode == Map1aCmd?"1":"0", &slen, HUGE_BUF); } else if (!strcmp(cmd,"newmapcmd")) { ns->newmapcmd= atoi(param); - strcat(cmdback, 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, param, &slen, HUGE_BUF); } else if (!strcmp(cmd,"facecache")) { ns->facecache = atoi(param); - strcat(cmdback, param); + safe_strcat(cmdback, param, &slen, HUGE_BUF); } else if (!strcmp(cmd,"faceset")) { char tmpbuf[20]; int q = atoi(param); @@ -180,7 +297,7 @@ if (is_valid_faceset(q)) ns->faceset=q; sprintf(tmpbuf,"%d", ns->faceset); - strcat(cmdback, tmpbuf); + safe_strcat(cmdback, tmpbuf, &slen, HUGE_BUF); /* if the client is using faceset, it knows about image2 command */ ns->image2=1; } else if (!strcmp(cmd,"itemcmd")) { @@ -196,7 +313,7 @@ ns->itemcmd = q; sprintf(tmpbuf,"%d", ns->itemcmd); } - strcat(cmdback, tmpbuf); + safe_strcat(cmdback, tmpbuf, &slen, HUGE_BUF); } else if (!strcmp(cmd,"mapsize")) { int x, y=0; char tmpbuf[MAX_BUF], *cp; @@ -209,7 +326,7 @@ } if (x < 9 || y < 9 || x>MAP_CLIENT_X || y > MAP_CLIENT_Y) { sprintf(tmpbuf," %dx%d", MAP_CLIENT_X, MAP_CLIENT_Y); - strcat(cmdback, tmpbuf); + safe_strcat(cmdback, tmpbuf, &slen, HUGE_BUF); } else { ns->mapx = x; ns->mapy = y; @@ -217,34 +334,35 @@ * param as given to us in case it gets parsed differently. */ sprintf(tmpbuf,"%dx%d", x,y); - strcat(cmdback, tmpbuf); + safe_strcat(cmdback, tmpbuf, &slen, HUGE_BUF); /* If beyond this size and still using orig map command, need to * go to map1cmd. */ if ((x>11 || y>11) && ns->mapmode == Map0Cmd) ns->mapmode = Map1Cmd; } } else if (!strcmp(cmd,"extendedMapInfos")) { - /* Added by tchize - * prepare to use the mapextended command - */ + /* Added by tchize + * prepare to use the mapextended command + */ char tmpbuf[20]; - ns->ext_mapinfos = (atoi(param)); + ns->ext_mapinfos = (atoi(param)); sprintf(tmpbuf,"%d", ns->ext_mapinfos); - strcat(cmdback, tmpbuf); + safe_strcat(cmdback, tmpbuf, &slen, HUGE_BUF); } else if (!strcmp(cmd,"extendedTextInfos")) { - /* Added by tchize - * prepare to use the extended text commands - * Client toggle this to non zero to get exttext - */ + /* Added by tchize + * prepare to use the extended text commands + * Client toggle this to non zero to get exttext + */ char tmpbuf[20]; - ns->has_readable_type = (atoi(param)); + + ns->has_readable_type = (atoi(param)); sprintf(tmpbuf,"%d", ns->has_readable_type); - strcat(cmdback, tmpbuf); + safe_strcat(cmdback, tmpbuf, &slen, HUGE_BUF); } else { /* Didn't get a setup command we understood - * report a failure to the client. */ - strcat(cmdback, "FALSE"); + safe_strcat(cmdback, "FALSE", &slen, HUGE_BUF); } } /* for processing all the setup commands */ LOG(llevInfo,"SendBack SetupCmd:: %s\n", cmdback); @@ -619,7 +737,7 @@ } cp = strchr(cp+1, ' '); if (cp) { - LOG(llevDebug,"CS: connection from client of type <%s>\n", cp); + LOG(llevDebug,"CS: connection from client of type <%s>, ip %s\n", cp, ns->host); /* This is first implementation - i skip all beta DX clients with it * Add later stuff here for other clients @@ -671,6 +789,7 @@ memset(&pl->socket.lastmap, 0, sizeof(pl->socket.lastmap)); Write_String_To_Socket( &pl->socket, "newmap", 6); } + pl->socket.current_map = 0; } @@ -1725,6 +1844,8 @@ pl->contr->socket.sent_scroll = 0; } free(sl.buf); + + check_map_change (pl->contr); } /** @@ -1847,6 +1968,8 @@ } } esrv_map_doneredraw(&pl->contr->socket, &newmap); + + check_map_change (pl->contr); } @@ -1925,12 +2048,12 @@ int i; sl.buf = malloc(MAXSOCKBUF); - strcpy(sl.buf,"replyinfo skill_info\n"); + strcpy((char*)sl.buf,"replyinfo skill_info\n"); for (i=1; i< NUM_SKILLS; i++) { - sprintf(sl.buf + strlen(sl.buf), "%d:%s\n", i + CS_STAT_SKILLINFO, + sprintf((char*)sl.buf + strlen((char*)sl.buf), "%d:%s\n", i + CS_STAT_SKILLINFO, skill_names[i]); } - sl.len = strlen(sl.buf); + sl.len = strlen((char*)sl.buf); if (sl.len > MAXSOCKBUF) { LOG(llevError,"Buffer overflow in send_skill_info!\n"); fatal(0); @@ -1948,10 +2071,10 @@ int i; sl.buf = malloc(MAXSOCKBUF); - strcpy(sl.buf,"replyinfo spell_paths\n"); + strcpy((char*)sl.buf,"replyinfo spell_paths\n"); for(i=0; i MAXSOCKBUF) { LOG(llevError,"Buffer overflow in send_spell_paths!\n"); fatal(0); @@ -1986,7 +2109,7 @@ } if (flags !=0) { sl.buf = malloc(MAXSOCKBUF); - strcpy(sl.buf,"updspell "); + strcpy((char*)sl.buf,"updspell "); sl.len=strlen((char*)sl.buf); SockList_AddChar(&sl, flags); SockList_AddInt(&sl, spell->count); @@ -2010,7 +2133,7 @@ return; } sl.buf = malloc(MAXSOCKBUF); - strcpy(sl.buf,"delspell "); + strcpy((char*)sl.buf,"delspell "); sl.len=strlen((char*)sl.buf); SockList_AddInt(&sl, spell->count); Send_With_Handling(&pl->socket, &sl); @@ -2078,7 +2201,7 @@ } if (!pl->socket.monitor_spells) return; sl.buf = malloc(MAXSOCKBUF); - strcpy(sl.buf,"addspell "); + strcpy((char*)sl.buf,"addspell "); sl.len=strlen((char*)sl.buf); if (!spell) { for (spell=pl->ob->inv; spell!=NULL; spell=spell->below) { @@ -2099,7 +2222,7 @@ if (sl.len > (MAXSOCKBUF - (26 + strlen(spell->name) + (spell->msg?strlen(spell->msg):0)))) { Send_With_Handling(&pl->socket, &sl); - strcpy(sl.buf,"addspell "); + strcpy((char*)sl.buf,"addspell "); sl.len=strlen((char*)sl.buf); } append_spell(pl, &sl, spell);