Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: jamer/yak
base: 39059020c0
...
head fork: jamer/yak
compare: 3c76d17c40
Checking mergeability… Don't worry, you can still create the pull request.
  • 15 commits
  • 19 files changed
  • 0 commit comments
  • 2 contributors
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
18 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;
@@ -155,7 +167,7 @@ void ircproto_topic(char *chan_name, char *format, ...)
vsnprintf(topic, sizeof(topic), format, args);
va_end(args);
- sock_sendline("TOPIC %s :%s\n", chan_name, topic);
+ sock_sendline("TOPIC %s :%s", chan_name, topic);
}
void ircproto_kick(char *chan_name, char *nick, char *format, ...)
@@ -167,10 +179,10 @@ void ircproto_kick(char *chan_name, char *nick, char *format, ...)
vsnprintf(message, sizeof(message), format, args);
va_end(args);
- sock_sendline("KICK %s %s :%s\n", chan_name, nick, message);
+ sock_sendline("KICK %s %s :%s", chan_name, nick, message);
}
void ircproto_mode(char *chan_name, char *modes)
{
- sock_sendline("MODE %s %s\n", chan_name, modes);
+ sock_sendline("MODE %s %s", chan_name, modes);
}
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
20 plg/handle_nicknameinuse/handle_nicknameinuse.c
@@ -1,27 +1,16 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-
#include "bool.h"
#include "callback.h"
#include "ircproto.h"
-#include "yak.h" /* bot_nick */
+#include "yak.h"
static void handle_nicknameinuse(char *prefix, int ncmd, char *params)
{
- static bool firsttime = true;
- char *old, *new;
-
- old = bot_nick;
- new = malloc(strlen(old) + 2);
- sprintf(new, "%s_", old);
- bot_nick = new;
-
- if (firsttime)
- firsttime = false;
- else
- free(bot_nick);
- bot_nick = new;
+ int len = strlen(bot_nick);
+ bot_nick[len++] = '_';
+ bot_nick[len] = '\0';
ircproto_nick(bot_nick);
}
@@ -34,4 +23,3 @@ int init()
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
4 yak.c
@@ -18,7 +18,7 @@
char *host;
int port;
-char *bot_nick;
+char bot_nick[512];
char *bot_user;
char *bot_real;
char *nickservnick;
@@ -36,7 +36,7 @@ static void load_whoiam()
host = pref_get("host");
port_str = pref_get("port");
- bot_nick = pref_get("nick");
+ strcpy(bot_nick, pref_get("nick"));
bot_user = pref_get("user");
bot_real = pref_get("real");
nickservnick = pref_get("nickserv-nick");
View
4 yak.h
@@ -1,7 +1,9 @@
#ifndef YAK_H
#define YAK_H
-extern char *bot_nick;
+extern char bot_nick[];
extern char *bot_owners[];
+#define YAK_VERSION "0.2.2"
+
#endif

No commit comments for this range

Something went wrong with that request. Please try again.