#include "main.h"
#include "game.h"
#include "console.h"
#include "network_client.h"

BITMAP *gui;
clientState *client;

void enter_game() {
  PALETTE pal;
  u_short port;
  gui = load_bitmap("data/images/gui.pcx", pal);
  const char *login, *passw, *character;
  char *loginfo;

	wsock_init();

	// gets server port from config file
  port = (u_short)get_config_int("net", "serverport", DEFAULT_PORT);

  // initializes game console
  console_init();

  client = (clientState*)malloc(sizeof(struct clientState));
  client->queue = NULL;
  console_addline("Connecting to WoU server");
	client_connect(&client, "pvt.ath.cx", port);

	// login to server
	login = get_config_string("user", "login", "null");
	passw = get_config_string("user", "password", "null");
	character = get_config_string("user", "character", "null");
  loginfo = (char*)malloc(strlen(login)+strlen(passw)+strlen(character)+3);
  strcpy(loginfo, login);
  strcat(loginfo, "#");
  strcat(loginfo, passw);
  strcat(loginfo, "#");
  strcat(loginfo, character);
  console_addline("Sending login information...");
	client_addPacket(&client, PACKET_CLIENT_LOGIN, loginfo);
	free(loginfo);

	RENDER = TRUE;
}

void game_logic() {
}


void render_playarea(BITMAP *bmp) {
  // blit gui
  blit(gui, bmp, 0, 0, 0, 0, gui->w, gui->h);
}
