From d2e576a77408c166810db682ca3c2fefa37c7edb Mon Sep 17 00:00:00 2001 From: Kevin Easton Date: Mon, 17 Jul 2017 12:48:28 +1000 Subject: [PATCH] Fix $myservers(1) to only return registered server refnums When $myservers() is called with an argument of 1 it is supposed to only return the refnums of servers that are registered (ie. those which it is legal to send a command to). This is the way EPIC works, and it was always intended to work this way in BX too. Also fix the warning about a NULL itsname - we use our name for the server if it isn't registered yet. Remove the slightly bogus use of strncat() while we're here, by removing the temporary stack buffer and just directly creating the result string with m_s3cat(). --- Changelog | 3 +++ source/functions.c | 2 +- source/server.c | 32 ++++++++++++-------------------- 3 files changed, 16 insertions(+), 21 deletions(-) diff --git a/Changelog b/Changelog index 2696126..cb2277c 100644 --- a/Changelog +++ b/Changelog @@ -1,5 +1,8 @@ [Changes 1.2.2] +* Fix $myservers(1) to only return registered server refnums, so it now + works the way EPIC does which was always the intention. (caf) + * Fix CHANGE_NICK_ON_KILL feature. (caf) * Improve error handling in /READLOG. (caf) diff --git a/source/functions.c b/source/functions.c index 8dc507f..5c60c6c 100644 --- a/source/functions.c +++ b/source/functions.c @@ -1903,7 +1903,7 @@ BUILT_IN_FUNCTION(function_channels, input) BUILT_IN_FUNCTION(function_servers, input) { - return create_server_list(input); /* DONT USE RETURN_STR HERE! */ + RETURN_MSTR(create_server_list(input)); /* DONT USE RETURN_STR HERE! */ } BUILT_IN_FUNCTION(function_pid, input) diff --git a/source/server.c b/source/server.c index e0f5f2f..1d1022b 100644 --- a/source/server.c +++ b/source/server.c @@ -2622,32 +2622,24 @@ extern char *BX_create_server_list (char *input) { int i; int do_read = 0; - char *value = NULL; - char buffer[BIG_BUFFER_SIZE + 1]; - if (input && *input && *input == '1') + char *value = NULL; + + if (input && *input == '1') do_read = 1; - *buffer = '\0'; + for (i = 0; i < number_of_servers; i++) { - if (server_list[i].read != -1) + if (do_read) { - if (do_read) - { - strncat(buffer, ltoa(i), BIG_BUFFER_SIZE); - strncat(buffer, space, BIG_BUFFER_SIZE); - continue; - } - if (server_list[i].itsname) - { - strncat(buffer, server_list[i].itsname, BIG_BUFFER_SIZE); - strncat(buffer, space, BIG_BUFFER_SIZE); - } - else - yell("Warning: server_list[%d].itsname is null and it shouldnt be", i); - + if (is_server_connected(i)) + m_s3cat(&value, " ", ltoa(i)); + } + else + { + if (is_server_open(i)) + m_s3cat(&value, " ", get_server_itsname(i)); } } - malloc_strcpy(&value, buffer); return value; }