| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242 |
- /*
- * Copyright (C) 1997 Robey Pointer
- * Copyright (C) 1999 - 2002 Eggheads Development Team
- * Copyright (C) 2002 - 2010 Bryan Drewery
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- */
- /*
- * cmdsserv.c -- part of server.mod
- * handles commands from a user via dcc that cause server interaction
- *
- */
- static void cmd_servers(int idx, char *par)
- {
- struct server_list *x = serverlist;
- int i;
- char s[1024] = "";
- putlog(LOG_CMDS, "*", "#%s# servers", dcc[idx].nick);
- if (!x) {
- dprintf(idx, "There are no servers in the server list.\n");
- } else {
- dprintf(idx, "Server list:\n");
- i = 0;
- for (; x; x = x->next) {
- simple_snprintf(s, sizeof s, " %s:%d %s", x->name,
- x->port ? x->port : (ssl_use ? default_port_ssl : default_port),
- (i == curserv) ? "<- I am here" : "");
- dprintf(idx, "%s\n", s);
- i++;
- }
- dprintf(idx, "End of server list.\n");
- }
- }
- static void cmd_dump(int idx, char *par)
- {
- putlog(LOG_CMDS, "*", "#%s# dump %s", dcc[idx].nick, par);
- if (!isowner(dcc[idx].nick)) {
- putlog(LOG_WARN, "*", "%s attempted 'dump' %s", dcc[idx].nick, par);
- dprintf(idx, "dump is only available to permanent owners.\n");
- return;
- }
- if (!par[0]) {
- dprintf(idx, "Usage: dump <server stuff>\n");
- return;
- }
- dprintf(DP_DUMP, "%s\n", replace_vars(par));
- }
- static void cmd_umode(int idx, char *par)
- {
- putlog(LOG_CMDS, "*", "#%s# umode %s", dcc[idx].nick, par);
- if (!par[0]) {
- dprintf(idx, "Usage: umode <+flags>\n");
- return;
- }
- dprintf(DP_SERVER, "MODE %s %s\n", botname, par);
- }
- static void cmd_jump(int idx, char *par)
- {
- char *other = NULL, *p = NULL;
- int port;
- if (par[0]) {
- other = newsplit(&par);
- port = atoi(newsplit(&par));
- if ((p = strchr(other, ':'))) {
- *p = 0;
- p++;
- if (!port)
- port = atoi(p);
- }
- if (!port)
- port = (ssl_use ? default_port_ssl : default_port);
- putlog(LOG_CMDS, "*", "#%s# jump %s %d %s", dcc[idx].nick, other, port, par);
- strlcpy(newserver, other, sizeof newserver);
- newserverport = port;
- strlcpy(newserverpass, par, sizeof newserverpass);
- } else
- putlog(LOG_CMDS, "*", "#%s# jump", dcc[idx].nick);
- dprintf(idx, "Jumping servers...\n");
- nuke_server("changing servers");
- cycle_time = 0;
- }
- static void cmd_keyx(int idx, char *par) {
- putlog(LOG_CMDS, "*", "#%s# keyx %s", dcc[idx].nick, par);
- if (!par[0]) {
- dprintf(idx, "Usage: keyx <nick>\n");
- return;
- }
- if (strchr(CHANMETA, par[0])) {
- dprintf(idx, "Error: Cannot key-exchange with a channel.\n");
- return;
- }
- if (!server_online) {
- dprintf(idx, "Error: Not online.\n");
- return;
- }
- char *nick = newsplit(&par);
- bd::String myPublicKeyB64, myPrivateKey, sharedKey;
- DH1080_gen(myPrivateKey, myPublicKeyB64);
- putlog(LOG_MSGS, "*", "[FiSH] Initiating DH1080 key-exchange with %s - sending my public key", nick);
- notice(nick, "DH1080_INIT " + myPublicKeyB64, DP_HELP);
- fish_data_t* fishData = new fish_data_t;
- fishData->myPublicKeyB64 = myPublicKeyB64;
- fishData->myPrivateKey = myPrivateKey;
- fishData->timestamp = now;
- FishKeys[nick] = fishData;
- return;
- }
- static void cmd_setkey(int idx, char *par) {
- putlog(LOG_CMDS, "*", "#%s# setkey %s", dcc[idx].nick, par);
- if (!par[0]) {
- dprintf(idx, "Usage: setkey <nick|channel> [key]\n");
- return;
- }
- char *target = newsplit(&par);
- char *key = newsplit(&par);
- bool have_key = FishKeys.contains(target);
- fish_data_t* fishData = NULL;
- if (!key[0]) {
- // Clear the key
- if (have_key) {
- fishData = FishKeys[target];
- FishKeys.remove(target);
- delete fishData;
- dprintf(idx, "Key cleared for '%s'\n", target);
- } else {
- dprintf(idx, "No key found for '%s'\n", target);
- }
- } else {
- // Set the key
- fishData = new fish_data_t;
- fishData->sharedKey = key;
- fishData->timestamp = now;
- dprintf(idx, "Set key for '%s' to: %s", target, key);
- }
- return;
- }
- static void cmd_clearqueue(int idx, char *par)
- {
- int msgs;
- putlog(LOG_CMDS, "*", "#%s# clearqueue %s", dcc[idx].nick, par);
- if (!par[0]) {
- dprintf(idx, "Usage: clearqueue <mode|server|help|all>\n");
- return;
- }
- if (!strcasecmp(par, "all")) {
- msgs = modeq.tot + mq.tot + hq.tot + aq.tot;
- msgq_clear(&modeq);
- msgq_clear(&mq);
- msgq_clear(&hq);
- msgq_clear(&aq);
- burst = 0;
- double_warned = 0;
- dprintf(idx, "Removed %d message%s from all queues.\n", msgs,
- (msgs != 1) ? "s" : "");
- } else if (!strcasecmp(par, "mode")) {
- msgs = modeq.tot;
- msgq_clear(&modeq);
- if (mq.tot == 0)
- burst = 0;
- double_warned = 0;
- dprintf(idx, "Removed %d message%s from the mode queue.\n", msgs,
- (msgs != 1) ? "s" : "");
- } else if (!strcasecmp(par, "help")) {
- msgs = hq.tot;
- msgq_clear(&hq);
- double_warned = 0;
- dprintf(idx, "Removed %d message%s from the help queue.\n", msgs,
- (msgs != 1) ? "s" : "");
- } else if (!strcasecmp(par, "play")) {
- msgs = aq.tot;
- msgq_clear(&aq);
- double_warned = 0;
- dprintf(idx, "Removed %d message%s from the play queue.\n", msgs,
- (msgs != 1) ? "s" : "");
- } else if (!strcasecmp(par, "server")) {
- msgs = mq.tot;
- msgq_clear(&mq);
- if (modeq.tot == 0)
- burst = 0;
- double_warned = 0;
- dprintf(idx, "Removed %d message%s from the server queue.\n", msgs,
- (msgs != 1) ? "s" : "");
- } else {
- dprintf(idx, "Usage: clearqueue <mode|server|help|all>\n");
- return;
- }
- }
- /* Function call should be:
- * int cmd_whatever(idx,"parameters");
- *
- * As with msg commands, function is responsible for any logging.
- */
- static cmd_t C_dcc_serv[] =
- {
- {"clearqueue", "m", (Function) cmd_clearqueue, NULL, LEAF|AUTH},
- {"dump", "a", (Function) cmd_dump, NULL, LEAF},
- {"jump", "m", (Function) cmd_jump, NULL, LEAF},
- {"keyx", "o", (Function) cmd_keyx, NULL, LEAF},
- {"servers", "m", (Function) cmd_servers, NULL, LEAF},
- {"setkey", "m", (Function) cmd_setkey, NULL, LEAF},
- {"umode", "m", (Function) cmd_umode, NULL, LEAF},
- {NULL, NULL, NULL, NULL, 0}
- };
|