--- deliantra/server/socket/info.C 2006/12/09 17:28:37 1.12 +++ deliantra/server/socket/info.C 2006/12/14 01:12:35 1.14 @@ -47,19 +47,15 @@ static void esrv_print_msg (NewSocket * ns, int color, const char *str) { - char buf[HUGE_BUF]; + SockList sl (MAXSOCKBUF); if (ns->status == Ns_Old) - { - snprintf (buf, HUGE_BUF, "%s\n", str); - } + sl.printf ("%s\n", str); else - { - snprintf (buf, HUGE_BUF, "drawinfo %d %s", color, str); - } + sl.printf ("drawinfo %d %s", color, str); -/* LOG(llevDebug,"sending %s to socket, len=%d\n", buf, strlen(buf));*/ - Write_String_To_Socket (ns, buf, strlen (buf)); + ns->send_packet (sl); + sl.free (); } /** @@ -74,13 +70,11 @@ static void esrv_print_ext_msg (NewSocket * ns, int color, uint8 type, uint8 subtype, const char *message) { - char buf[HUGE_BUF]; - - snprintf (buf, HUGE_BUF, "drawextinfo %d %hhu %hhu %s", color, type, subtype, message); - Write_String_To_Socket (ns, buf, strlen (buf)); - -/* LOG(llevDebug,"sending %s to socket, len=%d", buf, strlen(buf));*/ + SockList sl (MAXSOCKBUF); + sl.printf ("drawextinfo %d %hhu %hhu %s", color, type, subtype, message); + ns->send_packet (sl); + sl.free (); } /** @@ -607,10 +601,8 @@ void draw_magic_map (object *pl) { - int x, y; - char *map_mark = (char *) calloc (MAGIC_MAP_SIZE * MAGIC_MAP_SIZE, 1); + char *map_mark = (char *)calloc (MAGIC_MAP_SIZE * MAGIC_MAP_SIZE, 1); int xmin, xmax, ymin, ymax; - SockList sl; if (pl->type != PLAYER) { @@ -630,35 +622,29 @@ ymin = MAGIC_MAP_SIZE; xmax = 0; ymax = 0; - for (x = 0; x < MAGIC_MAP_SIZE; x++) - { - for (y = 0; y < MAGIC_MAP_SIZE; y++) + + for (int x = 0; x < MAGIC_MAP_SIZE; x++) + for (int y = 0; y < MAGIC_MAP_SIZE; y++) + if (map_mark[x + MAP_WIDTH (pl->map) * y] | FACE_FLOOR) { - if (map_mark[x + MAP_WIDTH (pl->map) * y] | FACE_FLOOR) - { - xmin = x < xmin ? x : xmin; - xmax = x > xmax ? x : xmax; - ymin = y < ymin ? y : ymin; - ymax = y > ymax ? y : ymax; - } + xmin = x < xmin ? x : xmin; + xmax = x > xmax ? x : xmax; + ymin = y < ymin ? y : ymin; + ymax = y > ymax ? y : ymax; } - } - sl.buf = (unsigned char *) malloc (MAXSOCKBUF); - snprintf ((char *) sl.buf, MAXSOCKBUF, "magicmap %d %d %d %d ", (xmax - xmin + 1), (ymax - ymin + 1), - MAGIC_MAP_HALF - xmin, MAGIC_MAP_HALF - ymin); - sl.len = strlen ((char *) sl.buf); - - for (y = ymin; y <= ymax; y++) - { - for (x = xmin; x <= xmax; x++) - { - sl.buf[sl.len++] = map_mark[x + MAGIC_MAP_SIZE * y] & ~FACE_FLOOR; - } /* x loop */ - } /* y loop */ + SockList sl (MAXSOCKBUF); + sl.printf ("magicmap %d %d %d %d ", (xmax - xmin + 1), (ymax - ymin + 1), + MAGIC_MAP_HALF - xmin, MAGIC_MAP_HALF - ymin); + + for (int y = ymin; y <= ymax; y++) + for (int x = xmin; x <= xmax; x++) + sl << uint8 (map_mark[x + MAGIC_MAP_SIZE * y] & ~FACE_FLOOR); Send_With_Handling (&pl->contr->socket, &sl); - free (sl.buf); + + sl.free (); + free (map_mark); }