hirc

IRC client
Log | Files | Refs

commit a70bdf802ce19aaf0f9442e0a005cef3c6d55d4a
parent df2a82675b5f76fbaa88f502104cbc95d0e97446
Author: hhvn <dev@hhvn.uk>
Date:   Fri, 12 Nov 2021 22:11:31 +0000

commands.c hirc.h: /server command

Diffstat:
Mcommands.c | 35+++++++++++++++++++++++++++++++++++
Mhirc.h | 1+
2 files changed, 36 insertions(+), 0 deletions(-)

diff --git a/commands.c b/commands.c @@ -33,6 +33,9 @@ static struct Command commands[] = { " /set <variable> string....", "Set a configuration variable.", "Passing only the name prints content.", NULL}}, + {"server", command_server, { + "usage: /server <server> cmd....", + "Run (non-raw) command with server as target.", NULL}}, {"help", command_help, { "usage: /help [command or variable]", "Print help information.", @@ -236,6 +239,38 @@ command_set(struct Server *server, char *str) { } void +command_server(struct Server *server, char *str) { + struct Server *nserver; + char *tserver, *cmd, *arg; + int i; + + tserver = strtok_r(str, " ", &arg); + cmd = strtok_r(NULL, " ", &arg); + + if (!tserver || !cmd) { + ui_error("/server requires 2 arguments", NULL); + return; + } + + if ((nserver = serv_get(&servers, tserver)) == NULL) { + ui_error("no such server: '%s'", tserver); + return; + } + + if (*cmd == '/') + cmd++; + + for (i=0; commands[i].name && commands[i].func; i++) { + if (strcmp(commands[i].name, cmd) == 0) { + commands[i].func(nserver, arg); + return; + } + } + + ui_error("no such commands: '%s'", cmd); +} + +void command_help(struct Server *server, char *str) { int cmdonly = 0; int i, j; diff --git a/hirc.h b/hirc.h @@ -131,6 +131,7 @@ void command_quote(struct Server *server, char *str); void command_connect(struct Server *server, char *str); void command_select(struct Server *server, char *str); void command_set(struct Server *server, char *str); +void command_server(struct Server *server, char *str); void command_help(struct Server *server, char *str); /* config.c */