#ifdef WIN32
#define STL_USING_ALL
#include "stl.h"
#endif

#include <GL/glut.h>
#include <iostream>
#include <string>
#include <vector>

#include "glpng/glpng.h"

#include "CTexture.h"
#include "CMove.h"
#include "Pieces.h"
#include "CWindow.h"
#include "CActiveWin.h"
#include "CBoard.h"
#include "CWindowSection.h"
#include "CSectionBoard.h"
#include "CMainWin.h"

#include "Network.h"
#include "CException.h"
#include "CNetMessage.h"
#include "CNetStream.h"

#include "CGameInfo.h"

CNetStream* n_in_out;


void* ListenNetworkMessage(void *)
{
  static CNetMessage Mess;

  while (!(n_in_out->Fail()))
    {
      n_in_out >> Mess;
      Mess.Handle();
    }

  return 0;
}



void CNetMessage::Handle(void)
{
  CMove tempmove;

  switch (GetType())
    {
    case (MESSAGE_MOVE):
      memcpy(&tempmove, data, sizeof(CMove));
      p_MainWin->GetBoard().Move(tempmove);
      p_MainWin->GetBoard().SwitchTurn();
      glutPostRedisplay();
      break;
    case (MESSAGE_PROMOTION):
      p_MainWin->GetBoard().SetPromotion((type_piece) ntohl(*(long *) data));
      break;
    default: break;
    }
}
