+
+char *printallmodes(channel *cp) {
+ static char buf[1024];
+ char buf2[12];
+
+ if(IsLimit(cp))
+ snprintf(buf2, sizeof(buf2), "%d", cp->limit);
+
+ snprintf(buf, sizeof(buf), "%s %s%s%s", printflags(cp->flags, cmodeflags), IsLimit(cp)?buf2:"", IsLimit(cp)?" ":"", IsKey(cp)?cp->key->content:"");
+
+ return buf;
+}
+
+static char *printlimitedmodes(channel *cp, flag_t before) {
+ static char buf[1024];
+
+ snprintf(buf, sizeof(buf), "%s", printflags(cp->flags, cmodeflags));
+
+ return buf;
+}
+
+void lua_onmode(int hooknum, void *arg) {
+ void **arglist = (void **)arg;
+ channel *cp = (channel *)arglist[0];
+ chanindex *ci = cp->index;
+ nick *np = arglist[1];
+ flag_t beforeflags = (flag_t)(long)arglist[3];
+
+ if(np) {
+ lua_avpcall("irc_onmode", "Slss", ci->name, np->numeric, printallmodes(cp), printlimitedmodes(cp, beforeflags));
+ } else {
+ lua_avpcall("irc_onmode", "S0ss", ci->name, printallmodes(cp), printlimitedmodes(cp, beforeflags));
+ }
+}
+
+