#include "command.h"
#include "client.h"

extern const char* servername;

void cmd_quit(struct client* c, struct token* p, int n) {
  struct member_list listeners;

  client_listeners(c, &listeners);
  client_remove_from_list(c, &listeners);

  channel_message_start(&listeners, c->nick, "QUIT");
  if(n) {
    channel_puts(&listeners, ":");
    channel_put(&listeners, p[0].s, p[0].len);
  }
  channel_puts(&listeners, "\r\n");

  client_puts(c, "ERROR :Closing link\r\n");
  client_flush(c);
  client_drop(c);
}
