/* * phandler.C: Generic protocol handling routines. * Rights to this code are documented in doc/pod/license.pod. * * Copyright © 2005-2007 Atheme Project (http://www.atheme.org) */ static char const rcsid[] = "$Id: phandler.C,v 1.4 2007/08/28 17:08:12 pippijn Exp $"; #include "atheme.h" #include #include "uplink.h" namespace protocol { unsigned int handler::server_login (void) { /* Nothing to do here. */ return 0; } void handler::introduce_nick (user_t *u) { /* Nothing to do here. */ } void handler::wallops_sts (char const * const text) { slog (LG_INFO, "Don't know how to send wallops: %s", text); } void handler::join_sts (channel_t *c, user_t *u, bool isnew, char const * const modes) { /* We can't do anything here. Bail. */ } void handler::chan_lowerts (channel_t *c, user_t *u) { slog (LG_ERROR, "chan_lowerts() called but not supported!"); join_sts (c, u, true, channel_modes (c, true)); } void handler::kick (char const * const from, char const * const channel, char const * const to, char const * const reason) { /* We can't do anything here. Bail. */ } void handler::mdchange (char const *target, char const *key, char const *value) { /* We can't do anything here. Bail. */ } void handler::privmsg (char const * const from, char const * const target, char const * const fmt, ...) { va_list ap; char *buf; va_start (ap, fmt); vasprintf (&buf, fmt, ap); va_end (ap); slog (LG_INFO, "Cannot send message to %s (%s): don't know how. Load a protocol module perhaps?", target, buf); sfree (buf); } void handler::notice_user_sts (user_t *from, user_t *target, char const * const text) { slog (LG_INFO, "Cannot send notice to %s (%s): don't know how. Load a protocol module perhaps?", target->nick, text); } void handler::notice_global_sts (user_t *from, char const * const mask, char const * const text) { slog (LG_INFO, "Cannot send global notice to %s (%s): don't know how. Load a protocol module perhaps?", mask, text); } void handler::notice_channel_sts (user_t *from, channel_t *target, char const * const text) { slog (LG_INFO, "Cannot send notice to %s (%s): don't know how. Load a protocol module perhaps?", target->name, text); } void handler::wallchops (user_t *sender, channel_t *channel, char const * const message) { /* ugly, but always works -- jilles */ node_t *n; chanuser_t *cu; LIST_FOREACH (n, channel->members.head) { cu = (chanuser_t *) n->data; if (cu->user->server != me.me && cu->modes & CMODE_OP) notice (sender->nick, cu->user->nick, "[@%s] %s", channel->name, message); } } void handler::numeric_sts (char const * const from, int numeric, char const * const target, char const * const fmt, ...) { va_list va; char *buf; va_start (va, fmt); vasprintf (&buf, fmt, va); va_end (va); sts (":%s %d %s %s", from, numeric, target, buf); sfree (buf); } void handler::skill (char const * const from, char const * const nick, char const * const fmt, ...) { /* cant do anything here. bail. */ } void handler::part_sts (channel_t *c, user_t *u) { /* cant do anything here. bail. */ } void handler::kline_sts (char const * const server, char const * const user, char const * const host, long duration, char const * const reason) { /* cant do anything here. bail. */ } void handler::unkline_sts (char const * const server, char const * const user, char const * const host) { /* cant do anything here. bail. */ } void handler::topic_sts (channel_t *c, char const * const setter, time_t ts, time_t prevts, char const * const topic) { /* cant do anything here. bail. */ } void handler::mode_sts (char const * const sender, channel_t *target, char const * const modes) { /* cant do anything here. bail. */ } void handler::ping_sts (void) { /* cant do anything here. bail. */ } void handler::quit_sts (user_t *u, char const * const reason) { /* cant do anything here. bail. */ } void handler::ircd_on_login (char const * const origin, char const * const user, char const * const wantedhost) { /* nothing to do here. */ } bool handler::ircd_on_logout (char const * const origin, char const * const user, char const * const wantedhost) { /* nothing to do here. */ return false; } void handler::jupe (char const * const server, char const * const reason) { /* nothing to do here. */ } void handler::sethost_sts (char const * const source, char const * const target, char const * const host) { /* nothing to do here. */ } void handler::fnc_sts (user_t *source, user_t *u, char const * const newnick, int type) { if (type == FNC_FORCE) skill (source->nick, u->nick, "Nickname enforcement (%s)", u->nick); } void handler::holdnick_sts (user_t *source, int duration, char const * const nick, myuser_t *account) { /* nothing to do here. */ } void handler::invite_sts (user_t *source, user_t *target, channel_t *channel) { /* nothing to do here. */ } void handler::svslogin_sts (char const * const target, char const * const nick, char const * const user, char const * const host, char const * const login) { /* nothing to do here. */ } void handler::sasl_sts (char const * const target, char const mode, char const * const data) { /* nothing to do here. */ } node_t * handler::next_matching_ban (channel_t *c, user_t *u, int type, node_t *first) { chanban_t *cb; node_t *n; char hostbuf[NICKLEN + USERLEN + HOSTLEN]; char realbuf[NICKLEN + USERLEN + HOSTLEN]; char ipbuf[NICKLEN + USERLEN + HOSTLEN]; snprintf (hostbuf, sizeof hostbuf, "%s!%s@%s", u->nick, u->user, u->vhost); snprintf (realbuf, sizeof realbuf, "%s!%s@%s", u->nick, u->user, u->host); /* will be nick!user@ if ip unknown, doesn't matter */ snprintf (ipbuf, sizeof ipbuf, "%s!%s@%s", u->nick, u->user, u->ip); LIST_FOREACH (n, first) { cb = static_cast (n->data); if (cb->type == type && (!match (cb->mask, hostbuf) || !match (cb->mask, realbuf) || !match (cb->mask, ipbuf) || (ircd->flags & IRCD_CIDR_BANS && !match_cidr (cb->mask, ipbuf)))) return n; } return NULL; } node_t * handler::next_matching_host_chanacs (mychan_t *mc, user_t *u, node_t *first) { chanacs_t *ca; node_t *n; char hostbuf[NICKLEN + USERLEN + HOSTLEN]; char ipbuf[NICKLEN + USERLEN + HOSTLEN]; snprintf (hostbuf, sizeof hostbuf, "%s!%s@%s", u->nick, u->user, u->vhost); /* will be nick!user@ if ip unknown, doesn't matter */ snprintf (ipbuf, sizeof ipbuf, "%s!%s@%s", u->nick, u->user, u->ip); LIST_FOREACH (n, first) { ca = static_cast (n->data); if (ca->myuser != NULL) continue; if (!match (ca->host, hostbuf) || !match (ca->host, ipbuf) || (ircd->flags & IRCD_CIDR_BANS && !match_cidr (ca->host, ipbuf))) return n; } return NULL; } } // namespace protocol