#include <stdio.h>
#include <string.h>

#include "global.h"
#include "custom.h"

#include "manhat-lib/shared_util.h"
#include "manhat-lib/shared_super_util.h"
#include "manhat-lib/shared_authenticate.h"
#include "manhat-lib/shared_cs_util.h"




void
get_chat_username (char *chat_username, SESSION *user)
{
  char *ptr;

  strncpy (chat_username, user->realname, MAX_NAME);
  for (ptr = chat_username; *ptr; ptr++)
    if (*ptr == ' ')
      *ptr = '-';
}





static void
send_chat_applet (const char *key, SESSION *user)
{

  char chat_username[MAX_NAME];
  char username[MAX_NAME];
  char url[MAX_PATH +1];

  get_chat_username (chat_username, user);
  snprintf(username, MAX_NAME, "%s:../tmp", chat_username);
  cs_set_value("chat_username", username);
  cs_set_server_name();
  cs_set_int_value("server_port", MELANGE_PORT);
  snprintf(url, MAX_PATH +1, "%s?id=%s", "super_chat_close", key);
  cs_set_value("return_url", url);
}





int
main ()
{
  char key[MAX_KEY + 1];	/* from id=? command line */
  SESSION user;

  cs_cgi_init();
  read_param ( key);
  validate_super_key (key, &user);	/* shared_super_util.c*/
  send_chat_applet ( key, &user);
  cs_cgi_display("super_chat_enter", 1);
  cs_cgi_destroy();
  return 0;			/* exit successfully */

}

