--- deliantra/server/socket/info.C 2006/12/09 17:28:37 1.12 +++ deliantra/server/socket/info.C 2006/12/21 23:37:06 1.23 @@ -45,21 +45,9 @@ * replaced with this, just using black as the color. */ static void -esrv_print_msg (NewSocket * ns, int color, const char *str) +esrv_print_msg (client *ns, int color, const char *str) { - char buf[HUGE_BUF]; - - if (ns->status == Ns_Old) - { - snprintf (buf, HUGE_BUF, "%s\n", str); - } - else - { - snprintf (buf, HUGE_BUF, "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_printf ("drawinfo %d %s", color, str); } /** @@ -72,15 +60,9 @@ * message The main message */ static void -esrv_print_ext_msg (NewSocket * ns, int color, uint8 type, uint8 subtype, const char *message) +esrv_print_ext_msg (client *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));*/ - + ns->send_packet_printf ("drawextinfo %d %hhu %hhu %s", color, type, subtype, message); } /** @@ -93,11 +75,9 @@ * * Else sends message to player via esrv_print_msg */ - static void print_message (int colr, const object *pl, const char *tmp) { - if (!tmp) tmp = "[NULL]"; @@ -105,17 +85,13 @@ return; if (pl->type == PLAYER) - { - esrv_print_msg (&pl->contr->socket, colr, (char *) tmp); - return; - } + esrv_print_msg (pl->contr->ns, colr, (char *) tmp); } /** * Prints out the contents of specified buffer structures, * and clears the string. */ - void flush_output_element (const object *pl, Output_Buf * outputs) { @@ -149,7 +125,6 @@ * If message not already in buffers, flushes olders buffer, * and adds message to queue. */ - static void check_output_buffers (const object *pl, const char *buf) { @@ -190,8 +165,6 @@ } } - - /** * Sends message to player(s). * @@ -212,7 +185,6 @@ void new_draw_info (int flags, int pri, const object *pl, const char *buf) { - if (flags & NDI_ALL) { player *tmppl; @@ -251,7 +223,6 @@ * it here. It may also have advantages in the future for reduction of * client/server bandwidth (client could keep track of various strings */ - void new_draw_info_format (int flags, int pri, const object *pl, const char *format, ...) { @@ -268,7 +239,6 @@ new_draw_info (flags, pri, pl, buf); } - void draw_ext_info (int flags, int pri, const object *pl, uint8 type, uint8 subtype, const char *message, const char *oldmessage) { @@ -278,7 +248,8 @@ if (pri >= pl->contr->listening) return; - if (!CLIENT_SUPPORT_READABLES (&pl->contr->socket, type)) + + if (!CLIENT_SUPPORT_READABLES (pl->contr->ns, type)) { char *buf = (char *) malloc (strlen (oldmessage == NULL ? message : oldmessage) + 1); @@ -293,9 +264,7 @@ } } else - { - esrv_print_ext_msg (&pl->contr->socket, flags & NDI_COLOR_MASK, type, subtype, message); - } + esrv_print_ext_msg (pl->contr->ns, flags & NDI_COLOR_MASK, type, subtype, message); } void @@ -309,7 +278,8 @@ if (pri >= pl->contr->listening) return; - if (!CLIENT_SUPPORT_READABLES (&pl->contr->socket, type)) + + if (!CLIENT_SUPPORT_READABLES (pl->contr->ns, type)) { va_list ap; @@ -328,7 +298,7 @@ vsnprintf (buf, HUGE_BUF, new_format, ap); va_end (ap); strip_media_tag (buf); - esrv_print_ext_msg (&pl->contr->socket, flags & NDI_COLOR_MASK, type, subtype, buf); + esrv_print_ext_msg (pl->contr->ns, flags & NDI_COLOR_MASK, type, subtype, buf); } } @@ -594,7 +564,6 @@ } } - /** * Creates and sends magic map to player. * @@ -607,10 +576,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,43 +597,33 @@ 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); + packet sl; + 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); - 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 */ + pl->contr->ns->send_packet (sl); - Send_With_Handling (&pl->contr->socket, &sl); - free (sl.buf); free (map_mark); } - /** * Send a kill log record to sockets */ - void Log_Kill (const char *Who, const char *What, int WhatType, const char *With, int WithType) { @@ -680,3 +637,4 @@ len = strlen (buf); } +