--- deliantra/server/socket/info.C 2006/09/19 09:38:32 1.8 +++ deliantra/server/socket/info.C 2006/12/14 02:37:37 1.16 @@ -45,21 +45,16 @@ * 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_socket * ns, int color, const char *str) { - char buf[HUGE_BUF]; + packet sl; 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); } /** @@ -72,15 +67,12 @@ * 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_socket * 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));*/ + packet sl; + sl.printf ("drawextinfo %d %hhu %hhu %s", color, type, subtype, message); + ns->send_packet (sl); } /** @@ -98,10 +90,8 @@ print_message (int colr, const object *pl, const char *tmp) { - if (tmp == (char *) NULL) - { - tmp = "[NULL]"; - } + if (!tmp) + tmp = "[NULL]"; if (!pl || (pl->type == PLAYER && pl->contr == NULL)) return; @@ -113,7 +103,6 @@ } } - /** * Prints out the contents of specified buffer structures, * and clears the string. @@ -219,43 +208,31 @@ if (flags & NDI_ALL) { player *tmppl; - int i; for (tmppl = first_player; tmppl != NULL; tmppl = tmppl->next) new_draw_info ((flags & ~NDI_ALL), pri, tmppl->ob, buf); - for (i = 1; i < socket_info.allocated_sockets; i++) - { - if (init_sockets[i].status == Ns_Old && init_sockets[i].old_mode != Old_Listen && pri < 10) - { - cs_write_string (&init_sockets[i], buf, strlen (buf)); - /* Most messages don't have a newline, so add one */ - cs_write_string (&init_sockets[i], "\n", 1); - } - } - return; } + if (!pl || (pl->type == PLAYER && pl->contr == NULL)) { /* Write to the socket? */ print_message (0, NULL, buf); return; } + if (pl->type != PLAYER) return; + if (pri >= pl->contr->listening) return; if ((flags & NDI_COLOR_MASK) == NDI_BLACK && !(flags & NDI_UNIQUE)) - { - /* following prints stuff out, as appropriate */ - check_output_buffers (pl, buf); - } + /* following prints stuff out, as appropriate */ + check_output_buffers (pl, buf); else - { - print_message (flags & NDI_COLOR_MASK, pl, buf); - } + print_message (flags & NDI_COLOR_MASK, pl, buf); } /** @@ -425,6 +402,7 @@ for (op = pl->inv; op; op = op->below) if (op->type == BOW && QUERY_FLAG (op, FLAG_APPLIED)) break; + if (op == NULL) break; @@ -438,9 +416,9 @@ if (pl->casting_time > -1) { if (pl->casting_time == 0) - sprintf (obuf, "Range: Holding spell (%s)", (const char *) pl->spell->name); + sprintf (obuf, "Range: Holding spell (%s)", &pl->spell->name); else - sprintf (obuf, "Range: Casting spell (%s)", (const char *) pl->spell->name); + sprintf (obuf, "Range: Casting spell (%s)", &pl->spell->name); } else sprintf (obuf, "Range: spell (%s)", &pl->contr->ranges[range_magic]->name); @@ -621,10 +599,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) { @@ -644,35 +620,28 @@ ymin = MAGIC_MAP_SIZE; xmax = 0; ymax = 0; - for (x = 0; x < MAGIC_MAP_SIZE; x++) - { - for (y = 0; y < MAGIC_MAP_SIZE; y++) - { - 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; - } - } - } - 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 (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) + { + xmin = x < xmin ? x : xmin; + xmax = x > xmax ? x : xmax; + ymin = y < ymin ? y : ymin; + ymax = y > ymax ? y : ymax; + } - 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 */ + 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); Send_With_Handling (&pl->contr->socket, &sl); - free (sl.buf); + + free (map_mark); } @@ -684,24 +653,13 @@ void Log_Kill (const char *Who, const char *What, int WhatType, const char *With, int WithType) { - int i; size_t len; char buf[MAX_BUF]; if (With != NULL) - { - snprintf (buf, MAX_BUF, "%s\t%s\t%d\t%s\t%d\n", Who, What, WhatType, With, WithType); - } + snprintf (buf, MAX_BUF, "%s\t%s\t%d\t%s\t%d\n", Who, What, WhatType, With, WithType); else - { - snprintf (buf, MAX_BUF, "%s\t%s\t%d\n", Who, What, WhatType); - } + snprintf (buf, MAX_BUF, "%s\t%s\t%d\n", Who, What, WhatType); + len = strlen (buf); - for (i = 1; i < socket_info.allocated_sockets; i++) - { - if (init_sockets[i].old_mode == Old_Listen) - { - cs_write_string (&init_sockets[i], buf, len); - } - } }