mirror of
https://github.com/weechat/weechat.git
synced 2026-07-03 00:03:12 +02:00
relay: add info "relay_client_count" with optional status name as argument
Use in evaluated strings (for example in /eval or triggers):
- "${info:relay_client_count}": total number of relay clients (any status)
With a specific status:
- "${info:relay_client_count,connecting}"
- "${info:relay_client_count,waiting_auth}"
- "${info:relay_client_count,connected}"
- "${info:relay_client_count,auth_failed}"
- "${info:relay_client_count,disconnected}"
This commit is contained in:
@@ -137,6 +137,27 @@ relay_client_search_by_id (int id)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* Searches for a client status.
|
||||
*
|
||||
* Returns index of status in enum t_relay_status, -1 if status is not found.
|
||||
*/
|
||||
|
||||
int
|
||||
relay_client_status_search (const char *name)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < RELAY_NUM_STATUS; i++)
|
||||
{
|
||||
if (strcmp (relay_client_status_name[i], name) == 0)
|
||||
return i;
|
||||
}
|
||||
|
||||
/* status not found */
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Sends a signal with the status of client ("relay_client_xxx").
|
||||
*/
|
||||
|
||||
@@ -113,6 +113,7 @@ extern int relay_client_count;
|
||||
extern int relay_client_valid (struct t_relay_client *client);
|
||||
extern struct t_relay_client *relay_client_search_by_number (int number);
|
||||
extern struct t_relay_client *relay_client_search_by_id (int id);
|
||||
extern int relay_client_status_search (const char *name);
|
||||
extern void relay_client_set_desc (struct t_relay_client *client);
|
||||
extern int relay_client_recv_cb (void *arg_client, int fd);
|
||||
extern int relay_client_send (struct t_relay_client *client, const char *data,
|
||||
|
||||
@@ -27,6 +27,45 @@
|
||||
#include "relay-client.h"
|
||||
|
||||
|
||||
/*
|
||||
* Returns relay info.
|
||||
*/
|
||||
|
||||
const char *
|
||||
relay_info_get_info_cb (void *data, const char *info_name,
|
||||
const char *arguments)
|
||||
{
|
||||
static char str_count[32];
|
||||
int count, status;
|
||||
struct t_relay_client *ptr_client;
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) data;
|
||||
|
||||
if (weechat_strcasecmp (info_name, "relay_client_count") == 0)
|
||||
{
|
||||
str_count[0] = '\0';
|
||||
count = relay_client_count;
|
||||
if (arguments && arguments[0])
|
||||
{
|
||||
status = relay_client_status_search (arguments);
|
||||
if (status < 0)
|
||||
return NULL;
|
||||
count = 0;
|
||||
for (ptr_client = relay_clients; ptr_client;
|
||||
ptr_client = ptr_client->next_client)
|
||||
{
|
||||
if ((int)ptr_client->status == status)
|
||||
count++;
|
||||
}
|
||||
}
|
||||
snprintf (str_count, sizeof (str_count), "%d", count);
|
||||
return str_count;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns infolist with relay info.
|
||||
*/
|
||||
@@ -90,6 +129,15 @@ relay_info_get_infolist_cb (void *data, const char *infolist_name,
|
||||
void
|
||||
relay_info_init ()
|
||||
{
|
||||
/* info hooks */
|
||||
weechat_hook_info ("relay_client_count",
|
||||
N_("number of clients for relay"),
|
||||
/* TRANSLATORS: please do not translate the status names, they must be used in English */
|
||||
N_("status name (optional): connecting, waiting_auth, "
|
||||
"connected, auth_failed, disconnected"),
|
||||
&relay_info_get_info_cb, NULL);
|
||||
|
||||
/* infolist hooks */
|
||||
weechat_hook_infolist ("relay", N_("list of relay clients"),
|
||||
N_("relay pointer (optional)"),
|
||||
NULL,
|
||||
|
||||
Reference in New Issue
Block a user