#include "CServices.h"

CServices::CServices (CNetServer *server) : exist (0), identified (0),
  services_privmsg (0), nickserv_pass (MSG_SIZE), nickserv_mask (MASK_SIZE),
  nickserv_auth (MSG_SIZE), s (server)
{
}

void
CServices::irc_services (c_char service, c_char msg) const
{
  if (services_privmsg)
    s->irc_privmsg (service, "%s", msg);
  else
    s->writeln ("%s %s", service, msg);
}

void
CServices::irc_nickserv (c_char msg) const
{
  irc_services (NICKSERV, msg);
}

void
CServices::nick_identify (void)
{
  stm.seekp (0);
  stm << "identify " << nickserv_pass << ends;
  irc_nickserv (stm.str ());
}

void
CServices::irc_chanserv (c_char msg) const
{
  irc_services (CHANSERV, msg);
}

void
CServices::chan_invite (c_char channel)
{
  stm.seekp (0);
  stm << "invite " << channel << ends;
  irc_chanserv (stm.str ());
}

void
CServices::chan_unban (c_char channel)
{
  stm.seekp (0);
  stm << "unban " << channel << ends;
  irc_chanserv (stm.str ());
}

void
CServices::chan_op (c_char channel, c_char nick)
{
  stm.seekp (0);
  stm << "op " << channel << " " << nick << ends;
  irc_chanserv (stm.str ());
}

void
CServices::chan_deop (c_char channel, c_char nick)
{
  stm.seekp (0);
  stm << "deop " << channel << " " << nick << ends;
  irc_chanserv (stm.str ());
}

