{"FUN_DICE_NUM", "I do not understand $b%s$b. Please use a single number above 1."}, /* {ARGS: "bla"} */
{"FUN_8BALL", "$b%s$b: %s"}, /* {ARGS: "TestUser", "Not a chance."} */
{"FUN_8BALL_REPLIES", "Not a chance.|In your dreams.|Absolutely!|Could be, could be.|No!"},
+ {"FUN_COOKIE", "gives %1%s a very big chocolate cookie. (%1$s got %2$d cookies - %3$d in this channel)"}, /* {ARGS: "TestUser", 20, 50} */
{NULL, NULL}
};
current_funcmd.send_notice = 0; \
}
-static void funcmd_reply(const char *text, ...) {
+#define REPLYTYPE_NORMAL 0
+#define REPLYTYPE_ACTION 1
+static void funcmd_reply(const char *text, int type, ...) {
+ if (!(current_funcmd.client->flags & SOCKET_FLAG_CONNECTED)) return;
const char *reply_format = get_language_string(current_funcmd.user, text);
if(reply_format)
text = reply_format;
char formatBuf[MAXLEN];
- if(current_funcmd.send_notice)
- sprintf(formatBuf, "NOTICE %s :%s", current_funcmd.user->nick, text);
- else
- sprintf(formatBuf, "PRIVMSG %s :%s", current_funcmd.chan->name, text);
+ if(current_funcmd.send_notice) {
+ if(type == REPLYTYPE_ACTION)
+ sprintf(formatBuf, "NOTICE %s :%s %s", current_funcmd.user->nick, current_funcmd.client->user->nick, text);
+ else
+ sprintf(formatBuf, "NOTICE %s :%s", current_funcmd.user->nick, text);
+ } else {
+ if(type == REPLYTYPE_ACTION)
+ sprintf(formatBuf, "PRIVMSG %s :\001ACTION %s\001", current_funcmd.chan->name, text);
+ else
+ sprintf(formatBuf, "PRIVMSG %s :%s", current_funcmd.chan->name, text);
+ }
va_list arg_list;
char sendBuf[MAXLEN];
int pos;
- if (!(current_funcmd.client->flags & SOCKET_FLAG_CONNECTED)) return;
sendBuf[0] = '\0';
va_start(arg_list, text);
pos = vsnprintf(sendBuf, MAXLEN - 2, formatBuf, arg_list);
write_socket(current_funcmd.client, sendBuf, pos+1);
}
+static char* getSetting(struct UserNode *user, struct ChanNode *chan, const char *setting) {
+ char *uname = "";
+ int cid = 0;
+ MYSQL_RES *res;
+ MYSQL_ROW row;
+ if(user) {
+ uname = ((user->flags & USERFLAG_ISAUTHED) ? user->auth : "*");
+ }
+ if(chan) {
+ loadChannelSettings(chan);
+ if(chan->flags & CHANFLAG_CHAN_REGISTERED)
+ cid = chan->channel_id;
+ }
+ printf_mysql_query("SELECT `value` FROM `fundata` WHERE `user` = '%s' AND `cid` = '%d' AND `name` = '%s'", escape_string(uname), cid, escape_string(setting));
+ res = mysql_use();
+ if ((row = mysql_fetch_row(res)) != NULL) {
+ return row[0];
+ } else
+ return NULL;
+}
+
+static void setSetting(struct UserNode *user, struct ChanNode *chan, const char *setting, const char *value) {
+ char *uname = "";
+ int cid = 0;
+ MYSQL_RES *res;
+ MYSQL_ROW row;
+ if(user) {
+ uname = ((user->flags & USERFLAG_ISAUTHED) ? user->auth : "*");
+ }
+ if(chan) {
+ loadChannelSettings(chan);
+ if(chan->flags & CHANFLAG_CHAN_REGISTERED)
+ cid = chan->channel_id;
+ }
+ printf_mysql_query("SELECT `id`, `value` FROM `fundata` WHERE `user` = '%s' AND `cid` = '%d' AND `name` = '%s'", escape_string(uname), cid, escape_string(setting));
+ res = mysql_use();
+ if ((row = mysql_fetch_row(res)) != NULL) {
+ if(strcmp(row[1], value))
+ printf_mysql_query("UPDATE `fundata` SET `value` = '%s' WHERE `id` = '%s'", escape_string(value), row[0]);
+ } else
+ printf_mysql_query("INSERT INTO `fundata` (`user`, `cid`, `name`, `value`) VALUES ('%s', '%d', '%s', '%s')", escape_string(uname), cid, escape_string(setting), escape_string(value));
+}
+
CMD_BIND(funcmd_ping) {
FUNCMD_HEADER;
- funcmd_reply("\002%s\002: Pong!", user->nick);
+ funcmd_reply("\002%s\002: Pong!", REPLYTYPE_NORMAL, user->nick);
}
CMD_BIND(funcmd_pong) {
FUNCMD_HEADER;
- funcmd_reply("\002%s\002: Ping!", user->nick);
+ funcmd_reply("\002%s\002: Ping!", REPLYTYPE_NORMAL, user->nick);
}
CMD_BIND(funcmd_dice) {
int max = atoi(argv[0]);
if(max > 1) {
int val = (rand() % max) + 1;
- funcmd_reply("FUN_DICE", user->nick, val, max);
+ funcmd_reply("FUN_DICE", REPLYTYPE_NORMAL, user->nick, val, max);
} else
- funcmd_reply("FUN_DICE_NUM", argv[0]);
+ funcmd_reply("FUN_DICE_NUM", REPLYTYPE_NORMAL, argv[0]);
}
CMD_BIND(funcmd_8ball) {
}
}
if(creply) {
- funcmd_reply("FUN_8BALL", user->nick, creply);
+ funcmd_reply("FUN_8BALL", REPLYTYPE_NORMAL, user->nick, creply);
+ }
+}
+
+CMD_BIND(funcmd_cookie) {
+ FUNCMD_HEADER;
+ if(argc) {
+ if(!(user = getUserByNick(argv[0])))
+ reply(current_funcmd.client, current_funcmd.user, "NS_USER_UNKNOWN", argv[0]);
}
+ char *tmp;
+ int user_count = ((tmp = getSetting(user, chan, "cookies")) ? atoi(tmp) : 0);
+ int total_count = ((tmp = getSetting(user, NULL, "cookies")) ? atoi(tmp) : 0);
+ user_count++;
+ total_count++;
+ char buf[10];
+ sprintf(buf, "%d", user_count);
+ setSetting(user, chan, "cookies", buf);
+ sprintf(buf, "%d", total_count);
+ setSetting(user, NULL, "cookies", buf);
+ funcmd_reply("FUN_COOKIE", REPLYTYPE_ACTION, user->nick, total_count, user_count);
}