--- deliantra/server/socket/request.c 2006/02/22 18:03:29 1.1.1.2 +++ deliantra/server/socket/request.c 2006/04/16 04:36:34 1.4 @@ -106,10 +106,45 @@ -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_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; + + snprintf (buf, MAX_BUF, "mapinfo current %d %d %d %d %d %s", + flags, ob->x - pl->socket.mapx / 2, ob->y - pl->socket.mapy / 2, + 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)); + } +} + /** 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 +174,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 +221,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 +237,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 +250,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 +258,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 +661,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 @@ -1725,6 +1767,8 @@ pl->contr->socket.sent_scroll = 0; } free(sl.buf); + + check_map_change (pl->contr); } /** @@ -1847,6 +1891,8 @@ } } esrv_map_doneredraw(&pl->contr->socket, &newmap); + + check_map_change (pl->contr); } @@ -1925,12 +1971,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 +1994,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 +2032,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 +2056,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 +2124,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 +2145,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);