Sfoglia il codice sorgente

* Add cmd_play for playing files to irc. (ASCII art gallery exhibition)

Bryan Drewery 16 anni fa
parent
commit
ed03a43b78
3 ha cambiato i file con 80 aggiunte e 1 eliminazioni
  1. 1 0
      doc/UPDATES
  2. 13 1
      doc/help.txt
  3. 66 0
      src/mod/irc.mod/cmdsirc.c

+ 1 - 0
doc/UPDATES

@@ -2,6 +2,7 @@
 * Add set 'msgrate' to define how often to dequeue to the server. (1 or 2 is good)
 * Add set 'msgburst' to define how many commands to burst to server per msgrate.
 * On hybrid/ratbox servers, burst some commands on connect
+* Add cmd_play for playing files to irc. (ASCII art gallery exhibition)
 
 1.2.17 - http://wraith.botpack.net/milestone/1.2.17
 * Binary / shell / startup changes

+ 13 - 1
doc/help.txt

@@ -691,7 +691,7 @@ See also: chhandle, chpass
 See also: +host, -host
 :leaf:clearqueue
 ###  $bclearqueue$b <queue>
-   Removes all msgs from the specified queue (mode/server/help/all)
+   Removes all msgs from the specified queue (mode/server/help/play/all)
 :hub:cmdpass:
 ###  $bcmdpass$b <command> <pass> [newpassword]
    Places the specified pass on the cmd so that the cmd will need to be 
@@ -1436,6 +1436,18 @@ See also: deop, console
    many pending lines, you may be booted off the bot.
  
 See also: color, console, echo, login, strip
+:leaf:play
+###  $bplay$b [channel] <file>
+   Plays the specified file to the specified channel. If no channel is
+   given then your console channel is used.
+ 
+   The 'play' queue is used for this, which is the lowest priority on
+   the bot. Any IRC related queue needs will immediately trump
+   the 'play' queue and delay the playing of the file.
+ 
+   Only files in the bots directory path may be played. (Symlinked
+   paths are fine). This is to prevent a user from playing /etc/passwd
+   since the cmd is +m.
 ::ps:
 ###  $bps$b [ps-param]
    Will run 'ps' on the bot's shell and display any results. If

+ 66 - 0
src/mod/irc.mod/cmdsirc.c

@@ -24,6 +24,9 @@
  *
  */
 
+#include <bdlib/src/Stream.h>
+#include <bdlib/src/String.h>
+#include "src/misc_file.h"
 
 /* Do we have any flags that will allow us ops on a channel?
  */
@@ -1908,6 +1911,68 @@ static void cmd_reset(int idx, char *par)
   }
 }
 
+static void cmd_play(int idx, char *par)
+{
+  if (!par[0]) {
+    dprintf(idx, "Usage: play [channel] <file>\n");
+    return;
+  }
+
+  char *chname = NULL;
+  struct chanset_t *chan = NULL;
+
+  if (strchr(CHANMETA, par[0]) != NULL)
+    chname = newsplit(&par);
+  else
+    chname = 0;
+  chan = get_channel(idx, chname);
+  if (!chan)
+    return;
+
+  if (!par[0]) {
+    dprintf(idx, "Usage: play [channel] <file>\n");
+    return;
+  }
+
+  memberlist *m = ismember(chan, botname);
+
+  if (!m) {
+    dprintf(idx, "Cannot play to %s: I'm not on that channel.\n", chan->dname);
+    return;
+  }
+
+  get_user_flagrec(dcc[idx].user, &user, chan->dname);
+
+  if (!me_op(chan) && !me_voice(chan)) {
+    dprintf(idx, "Cannot play to %s: I am not voiced or opped.\n", chan->dname);
+    return;
+  }
+  putlog(LOG_CMDS, "*", "#%s# (%s) play %s", dcc[idx].nick, chan->dname, par);
+
+  // Ensure file exists and is within proper path
+  bd::String file(par);
+
+  if (file[0] == '/' || file(0, 2) == "..") {
+    dprintf(idx, "Cannot play '%s': Illegal path.\n", par);
+    return;
+  }
+
+  if (!can_stat(par)) {
+    dprintf(idx, "Cannot play '%s': Cannot access file.\n", par);
+    return;
+  }
+
+  bd::String prefix;
+  bd::Stream stream;
+  stream.loadFile(par);
+  bd::String str;
+  while (stream.tell() < stream.length()) {
+    str = stream.getline().chomp();
+    if (str.length())
+      dprintf(DP_PLAY, "PRIVMSG %s :%s\n", chan->name, str.c_str());
+  }
+}
+
 static cmd_t irc_dcc[] =
 {
   {"act",		"o|o",	 (Function) cmd_act,		NULL, LEAF},
@@ -1930,6 +1995,7 @@ static cmd_t irc_dcc[] =
   {"msg",		"o",	 (Function) cmd_msg,		NULL, LEAF|AUTH},
   {"nick",		"m",	 (Function) cmd_nick,		NULL, LEAF},
   {"op",		"o|o",	 (Function) cmd_op,		NULL, LEAF|AUTH},
+  {"play",		"m|m",	 (Function) cmd_play,		NULL, LEAF|AUTH},
   {"reset",		"m|m",	 (Function) cmd_reset,		NULL, LEAF|AUTH},
   {"resetbans",		"o|o",	 (Function) cmd_resetbans,	NULL, LEAF|AUTH},
   {"resetexempts",	"o|o",	 (Function) cmd_resetexempts,	NULL, LEAF|AUTH},