#include #include #include #include "hash.h" #include "client.h" #include "channel.h" #include "hermes.h" Client* mkclient(int data, int ctl) { Client *c; c = mallocz(sizeof(*c), 1); c->data = data; c->ctl = ctl; c->io = ioproc(); c->info = getnetconninfo(nil, c->data); c->channels = newhash(); return c; } void freeclient(Client *c) { if(c == nil) return; qlock(c); if(c->data >= 0) close(c->data); if(c->ctl >= 0){ hangup(c->ctl); close(c->ctl); } if(c->io != nil){ iointerrupt(c->io); closeioproc(c->io); } if(c->info != nil) freenetconninfo(c->info); free(c); } int csend(Ioproc *io, Client *c, char *fmt, ...) { char buf[1024]; int n, r; va_list arg; va_start(arg, fmt); n = vsnprint(buf, sizeof(buf)-3, fmt, arg); va_end(arg); strcat(buf, "\r\n"); n += 2; if((r = iowrite(io, c->data, buf, n)) != n){ fprint(2, "write: %r\n"); } return r; } int cnumeric(Client *c, int code, char *msg) { return csend(c->io, c, ":%s %03d %s :%s", myname, code, c->nick, msg); } void cmotd(Client *c) { char buf[256]; sprint(buf, "welcome %s!%s@%s", c->nick, c->user, c->info->rsys); cnumeric(c, 1, buf); cnumeric(c, 2, "hermes ircd"); cnumeric(c, 3, "booted sometime"); sprint(buf, "%s hermes v m", myname); cnumeric(c, 4, buf); cnumeric(c, 251, "there are 0 users and 0 services on 1 servers"); cnumeric(c, 375, "- motd -"); cnumeric(c, 372, "it works!"); cnumeric(c, 376, "- eom -"); }