Browse files

Merge branch 'mf'

Conflicts:
	.gitignore
	auth.c
	plg.c
  • Loading branch information...
2 parents def6830 + 8515953 commit 23e1761d646bcc4c12469b893b81256947a0983f @pmer committed Apr 7, 2012
Showing with 229 additions and 15 deletions.
  1. +1 −1 auth.c
  2. +1 −1 callback.c
  3. +1 −1 chan.c
  4. +12 −0 ircproto.c
  5. +1 −0 ircproto.h
  6. +1 −1 plg.c
  7. +13 −0 plg/ctcp/Makefile
  8. +76 −0 plg/ctcp/ctcp.c
  9. +11 −0 plg/ctcp/ctcp.h
  10. +13 −0 plg/ctcp_ping/Makefile
  11. +21 −0 plg/ctcp_ping/ctcp_ping.c
  12. +13 −0 plg/ctcp_version/Makefile
  13. +22 −0 plg/ctcp_version/ctcp_version.c
  14. +31 −8 plg/ui/ui.c
  15. +8 −1 plugins.txt.example
  16. +2 −2 usr.c
  17. +2 −0 yak.h
View
2 auth.c
@@ -30,7 +30,7 @@ bool auth_isowner(char *usr)
for (owners = bot_owners; *owners; owners++) {
owner = *owners;
- if (!strncmp(usr, owner, len) && strlen(owner) == len)
+ if (!strncasecmp(usr, owner, len) && strlen(owner) == len)
return true;
}
return false;
View
2 callback.c
@@ -24,7 +24,7 @@ static void handle_privmsg(char *usr, char *cmd, char *src_and_msg)
*spc = '\0';
src = src_and_msg;
msg = spc + 2; /* space, colon */
- if (!strncmp(src, bot_nick, strlen(bot_nick))) {
+ if (!strncasecmp(src, bot_nick, strlen(bot_nick))) {
/* Receiving a private query. Strip the source down to just the
* username. */
if (strchr(usr, '!')) {
View
2 chan.c
@@ -29,7 +29,7 @@ static struct chan *chan_find(char *chan_name)
list_for_each(pos, &chans) {
chan = list_entry(pos, struct chan, link);
- if (!strcmp(chan->name, chan_name))
+ if (!strcasecmp(chan->name, chan_name))
return chan;
}
return NULL;
View
12 ircproto.c
@@ -146,6 +146,18 @@ void ircproto_privmsg(char *recipient, char *format, ...)
sock_sendline("PRIVMSG %s :%s", recipient, message);
}
+void ircproto_notice(char *recipient, char *format, ...)
+{
+ va_list args;
+ char message[512];
+
+ va_start(args, format);
+ vsnprintf(message, sizeof(message), format, args);
+ va_end(args);
+
+ sock_sendline("NOTICE %s :%s", recipient, message);
+}
+
void ircproto_topic(char *chan_name, char *format, ...)
{
va_list args;
View
1 ircproto.h
@@ -41,6 +41,7 @@ void ircproto_oper(char *oper_username, char *password);
void ircproto_join(char *chan_name);
void ircproto_part(char *chan_name);
void ircproto_privmsg(char *recipient, char *format, ...);
+void ircproto_notice(char *recipient, char *format, ...);
void ircproto_topic(char *chan_name, char *format, ...);
void ircproto_kick(char *chan_name, char *nick, char *format, ...);
void ircproto_mode(char *chan_name, char *modes);
View
2 plg.c
@@ -46,7 +46,7 @@ void plg_load_plgs_from(char *filename)
}
while (fgets(line, sizeof(line), f)) {
chomp(line);
- if (*line)
+ if (*line && *line != '#')
plg_load(line);
}
fclose(f);
View
13 plg/ctcp/Makefile
@@ -0,0 +1,13 @@
+SO=ctcp.so
+CFLAGS=-g -fPIC -I../..
+LDFLAGS=-g -fPIC -shared
+OBJS = ctcp.o
+
+all: $(SO)
+
+clean:
+ $(RM) $(OBJS) $(SO)
+
+$(SO): $(OBJS)
+ $(CC) -o $(SO) $(OBJS) $(LDFLAGS)
+
View
76 plg/ctcp/ctcp.c
@@ -0,0 +1,76 @@
+#include <stdlib.h>
+#include "privmsg.h"
+#include "ctcp.h"
+#include "list.h"
+#include "regex.h"
+
+struct re_event {
+ struct list_head link;
+ ctcp_callback call;
+ struct regex match;
+};
+
+
+/**
+ * events - list of regular expression events that we will listen for
+ */
+static LIST_HEAD(events);
+
+
+void ctcp_emit(char *usr, char *src, char *msg)
+{
+ ctcp_callback call;
+ struct list_head *list;
+ struct re_event *rev;
+ int matches, ncap, i;
+
+ static char *caps[REGEX_MAX_CAPTURES];
+ static char caps_buf[512 * REGEX_MAX_CAPTURES];
+ static bool need_init = true;
+
+ if (need_init) {
+ /* setup static memory for regex captures */
+ need_init = false;
+ for (i = 0; i < REGEX_MAX_CAPTURES; i++)
+ caps[i] = &caps_buf[512 * i];
+ }
+
+ /* regex events */
+ list_for_each(list, &events) {
+ rev = list_entry(list, struct re_event, link);
+ matches = regex_match(&rev->match, msg, caps);
+ ncap = matches - 1;
+ if (ncap >= 0)
+ rev->call(usr, src, msg, caps, ncap);
+ }
+}
+
+void ctcp_register(ctcp_callback call, char *pattern)
+{
+ struct re_event *e = malloc(sizeof(struct re_event));
+ e->call = call;
+ e->match.pattern = pattern;
+ e->match.state = RCS_UNINIT;
+ list_add(&e->link, &events);
+}
+
+static void handle_ctcp(char *usr, char *src, char *msg,
+ char **caps, int ncaps)
+{
+ char *message;
+
+ message = caps[0];
+
+ ctcp_emit(usr, src, message);
+}
+
+int init()
+{
+ callback_register_privmsg_re(handle_ctcp, "^\001(.*)\001$");
+ return 0;
+}
+
+void finish()
+{
+}
+
View
11 plg/ctcp/ctcp.h
@@ -0,0 +1,11 @@
+#ifndef CTCP_H
+#define CTCP_H
+
+#include "bool.h"
+
+typedef void (*ctcp_callback)(char *usr, char *src, char *msg,
+ char **caps, int ncap);
+
+void ctcp_register(ctcp_callback call, char *pattern);
+
+#endif
View
13 plg/ctcp_ping/Makefile
@@ -0,0 +1,13 @@
+SO=ctcp_ping.so
+CFLAGS=-g -fPIC -I../..
+LDFLAGS=-g -fPIC -shared
+OBJS = ctcp_ping.o
+
+all: $(SO)
+
+clean:
+ $(RM) $(OBJS) $(SO)
+
+$(SO): $(OBJS)
+ $(CC) -o $(SO) $(OBJS) $(LDFLAGS)
+
View
21 plg/ctcp_ping/ctcp_ping.c
@@ -0,0 +1,21 @@
+#include "ircproto.h"
+#include "plg/ctcp/ctcp.h"
+
+static void ping(char *usr, char *src, char *msg,
+ char **caps, int ncaps)
+{
+ ircproto_notice(src, "\001PING %s\001", caps[0]);
+}
+
+int init()
+{
+ ctcp_register(ping, "^PING (.*)$");
+
+ return 0;
+}
+
+void finish()
+{
+
+}
+
View
13 plg/ctcp_version/Makefile
@@ -0,0 +1,13 @@
+SO=ctcp_version.so
+CFLAGS=-g -fPIC -I../..
+LDFLAGS=-g -fPIC -shared
+OBJS = ctcp_version.o
+
+all: $(SO)
+
+clean:
+ $(RM) $(OBJS) $(SO)
+
+$(SO): $(OBJS)
+ $(CC) -o $(SO) $(OBJS) $(LDFLAGS)
+
View
22 plg/ctcp_version/ctcp_version.c
@@ -0,0 +1,22 @@
+#include "ircproto.h"
+#include "yak.h"
+#include "plg/ctcp/ctcp.h"
+
+static void version(char *usr, char *src, char *msg,
+ char **caps, int ncaps)
+{
+ ircproto_notice(src, "\001VERSION yak %s\001", YAK_VERSION);
+}
+
+int init()
+{
+ ctcp_register(version, "^VERSION$");
+
+ return 0;
+}
+
+void finish()
+{
+
+}
+
View
39 plg/ui/ui.c
@@ -7,6 +7,7 @@
#include "ircproto.h"
#include "socket.h"
#include "thread.h"
+#include "yak.h"
#include "plg/eval/eval.h"
#include "plg/loggedin/loggedin.h"
@@ -19,9 +20,26 @@ static void cd(char *line, char **caps, int ncaps)
{
if (ncaps > 1 && *caps[1])
info("cd: must have one argument");
+
+ info("now talking on %s", caps[0]);
+
strcpy(chan, caps[0]);
}
+static void nick(char *line, char **caps, int ncaps)
+{
+ if (ncaps > 1 && *caps[1])
+ info("nick: must have one argument");
+
+ strcpy(bot_nick, caps[0]);
+ ircproto_nick(caps[0]);
+}
+
+static void msg(char *line, char **caps, int ncaps)
+{
+ ircproto_privmsg(caps[0], "%s", caps[1]);
+}
+
static void quit(char *line, char **caps, int ncaps)
{
safe_shutdown_and_die(0);
@@ -32,13 +50,7 @@ static void say(char *line)
if (*chan)
ircproto_privmsg(chan, "%s", line);
else
- info("please 'cd' into a channel first");
-}
-
-static void eval(char *line)
-{
- if (!eval_emit(line))
- say(line);
+ info("please '/cd' into a channel first");
}
static void *uimain(void *unused)
@@ -47,7 +59,13 @@ static void *uimain(void *unused)
while (line = readline("> ")) {
mutex_on();
- eval(line);
+ if(line[0] == '/') {
+ if (!eval_emit(line + 1)) {
+ info("invalid command: %s", line);
+ }
+ } else {
+ say(line);
+ }
mutex_off();
free(line);
}
@@ -76,12 +94,17 @@ int init()
socklog = newsocklog;
eval_register(cd, "^cd (\\S+)(.*)?");
+ eval_register(nick, "^nick (\\S+)(.*)?");
+ eval_register(msg, "^msg (\\S+) (.*)");
eval_register(quit, "^quit$");
onlogin(create_uithread);
+
return 0;
}
void finish()
{
+
}
+
View
9 plugins.txt.example
@@ -6,5 +6,12 @@ make
ping
quit
+ctcp
+ctcp_ping
+ctcp_version
+
eval
-ui
+#ui
+
+dyn_plg
+
View
4 usr.c
@@ -19,11 +19,11 @@ bool isme(char *prefix)
bang = strchr(prefix, '!');
if (bang) {
len = bang - prefix;
- return !strncmp(prefix, bot_nick, len) &&
+ return !strncasecmp(prefix, bot_nick, len) &&
strlen(bot_nick) == len;
}
else {
- return !strcmp(prefix, bot_nick);
+ return !strcasecmp(prefix, bot_nick);
}
}
View
2 yak.h
@@ -4,4 +4,6 @@
extern char *bot_nick;
extern char *bot_owners[];
+#define YAK_VERSION "0.2.2"
+
#endif

0 comments on commit 23e1761

Please sign in to comment.