void topic(t_server *serv, t_user *user, char *cmd) { t_channel *ch; char *topic; char ret[512]; if (user->ch != NULL) { ch = get_channel_by_name(serv->channels, user->ch); topic = split_string(cmd, ' ', 1); if (topic != NULL && strlen(topic) < 128) { ch->topic = strdup(topic); free(topic); } if (ch->topic != NULL) sprintf(ret, "332 RPL_TOPIC :%s\r\n", ch->topic); else sprintf(ret, "331 RPL_NOTOPIC :No topic is set\r\n"); swrite(user->fd, ret); } else swrite(user->fd, "461 ERR_USERNOTINCHANNEL :You're not in a channel\r\n"); }
/* * @function: Sends an action to a channel. * @return: void */ void module_privmsg(struct user *from, const char *target, const char *message, ...) { static char buf[512]; va_list ap; va_start(ap, message); vsprintf(buf, message, ap); va_end(ap); // Don't send this message to a non valid target, kthx. if (get_channel_by_name(target) == NULL && get_user_by_numericstr(target) == NULL) return; send_format("%s P %s :%s", from->numericstr, target, buf); }
/* * @function: Makes a fake client join a channel, if it exists, or create it if it doesn't. * @return: void */ void module_join_channel(struct user *from, const char *channel, int auto_op) { struct channel *chan = get_channel_by_name(channel); if (chan == NULL) { // Channel doesn't exist - lets create it. send_format("%s C %s %ld", from->numericstr, channel, now); } else { send_format("%s J %s %ld", from->numericstr, chan->name, chan->ts); if (auto_op) { send_format("%s M %s +o %s", me->numericstr, chan->name, from->numericstr); } } }
void hPRIVMSG(struct entity *from, char *target, char *msg) { struct user *u = (struct user *)from; if (!verify_user(u)) return; if (u->server == me) return; if (*target == '#') hook_call("onchanmsg", pack_args(arg_user(u), arg_chan(get_channel_by_name(target)), arg_str(msg))); else hook_call("onprivmsg", pack_args(arg_user(u), arg_user(get_user_by_numeric(str2unum(target))), arg_str(msg))); }
void hPART(struct user *user, char *channels, char *reason) { struct manyargs chlist; struct channel *c; int i; VERIFY_USER(user); split(&chlist, channels, ','); for (i = 0; i < chlist.c; i++) { c = get_channel_by_name(chlist.v[i]); VERIFY_CHANNEL(c); hook_call("onpart", pack_args(arg_user(user), arg_chan(c), arg_str(reason ? reason : ""))); chanusers_leave(user, c); } }
void hCREATE(struct user *from, char *channels, time_t *ts) { int i; struct manyargs chlist; struct channel *c; VERIFY_USER(from); split(&chlist, channels, ','); for (i = 0; i < chlist.c; i++) { c = get_channel_by_name(chlist.v[i]); if (c) { logfmt(LOG_WARNING, "CREATE for existing channel: %s. Deleting.", chlist.v[i]); del_channel(c); } c = add_channel(chlist.v[i], *ts); chanusers_join(from, c); channel_plsprefix(c, from, 'o'); } }
static void cmd_anki_vehicle_lights_pattern(int argcp, char **argvp) { uint8_t *value; size_t plen; int handle; if (conn_state != STATE_CONNECTED) { failed("Disconnected\n"); return; } if (argcp < 6) { rl_printf("Usage: %s <channel> <effect> <start> <end> <cycles_per_min>\n", argvp[0]); rl_printf(" channels: RED, TAIL, BLUE, GREEN, FRONTL, FRONTR\n"); rl_printf(" effects: STEADY, FADE, THROB, FLASH, RANDOM\n"); return; } handle = vehicle.write_char.value_handle; uint8_t channel = get_channel_by_name(argvp[1]); if (channel == channel_invalid) { rl_printf("Unrecognized channel: %s\n", argvp[1]); return; } uint8_t effect = get_effect_by_name(argvp[2]); if (effect == effect_invalid) { rl_printf("Unrecognized channel: %s\n", argvp[2]); return; } uint8_t start = atoi(argvp[3]); uint8_t end = atoi(argvp[4]); uint16_t cycles_per_min = atoi(argvp[5]); anki_vehicle_msg_t msg; plen = anki_vehicle_msg_lights_pattern(&msg, channel, effect, start, end, cycles_per_min); value = (uint8_t *)&msg; gatt_write_char(attrib, handle, value, plen, NULL, NULL); }
void names(t_server *serv, t_user *user, char *cmd) { t_channel *chan; char *ch; char ret[512]; if ((ch = split_string(cmd, ' ', 1)) != NULL) { if ((chan = get_channel_by_name(serv->channels, ch)) != NULL) aff_names(serv, user, chan); else swrite(user->fd, "403 ERR_NOSUCHCHANEL :No such channel\r\n"); } else { if (user->ch != NULL) { sprintf(ret, "/names %s", user->ch); names(serv, user, ret); } else swrite(user->fd, "461 ERR_USERNOTINCHAN :You're not in a channel\r\n"); } }
/* * @function: Makes a fakeclient part a channel. * @return: void */ void module_part_channel(struct user *from, const char *channel) { // Don't try to part a channel that doesn't exist :) if (get_channel_by_name(channel) == NULL) return; send_format("%s L %s", from->numericstr, channel); }
void hBURST(struct server *from, char *chan, time_t *ts, struct manyargs *rest) { struct manyargs list; struct channel *c; struct user *u; char *tmp, *burstmode = ""; int nextpos, i; VERIFY_SERVER(from); if (from->protocol[0] == 'P') { logtxt(LOG_ERROR, "BURST after END_OF_BURST!"); return; } c = get_channel_by_name(chan); if (!c) c = add_channel(chan, *ts); if (!rest->c) return; /* handle modes if present */ nextpos = 0; tmp = rest->v[nextpos]; if (tmp && tmp[0] == '+') nextpos = 1 + channel_apply_mode((struct entity *)from, c, rest->v[0], rest, 1); /* rest->v[nextpos] is now the next parameter after the modes */ /* check the last parameter for leading % */ tmp = rest->v[nextpos]; if (rest->c - 1 > nextpos) tmp = rest->v[rest->c - 1]; if (tmp && tmp[0] == '%') { split(&list, rest->v[rest->c - 1] + 1, ' '); for (i = 0; i < list.c; i++) channel_plsban(c, NULL, list.v[i]); rest->c--; } /* no channel users */ if (!tmp) return; assert(nextpos+1 == rest->c); split(&list, rest->v[nextpos], ','); /* all that's left from rest->v[i .. rest->c] are user entries with tmps */ for (i = 0; i < list.c; i++) { tmp = list.v[i]; if ((tmp = strchr(tmp, ':'))) { *tmp++ = '\0'; burstmode = tmp; } u = get_user_by_numericstr(list.v[i]); if (!u) { logtxt(LOG_WARNING, "Burst join for non-existant user."); continue; } chanusers_join(u, c); channel_burstmode(c, u, burstmode); } }