/* NetworkIO.h-- simple networking class written for CS 559,
Spring 2011, Project 1, by Leslie Watkins
Adapted largely from MSDN's help file, "Creating a Basic Winsock
Application", which can be found here:
http://msdn.microsoft.com/en-us/library/ms737629(VS.85).aspx */

#pragma once

#include <winsock2.h>
#include <ws2tcpip.h>
#include <iphlpapi.h>
#include <cstdio>	
#include <cstring>
#include <cmath>

#pragma comment(lib, "Ws2_32.lib")
//add Ws2_32.lib to additional dependencies

enum Heading {
		North,
		South,
		East,
		West
	};

enum State {
		IWon,
		IQuit,
		YouWon,
		Racing
	};

const int Len = 50; //arbitrary value chosen for buffer size


class NetworkIO
{
private:
	SOCKET ClientSocket;
	int timeoutCt;
	template <typename T> char * addVar(char * buffer, T var);
	//adds a variable to a buffer string
	template <typename T> char * remVar(char * buffer, T & var);
	//removes a value from buffer string, assigns it to var

public:

	NetworkIO();

	NetworkIO(char * targetIP, int portNumber); 
	//if targetIP is null, I am the server
	//if I am the server, establish TCP socket and wait
	//if I am the client, attempt to reach the server and begin game

	~NetworkIO(void);

	void SendUpdate(int level);
	//tell the other guy the level of play
	void SendUpdate(long int time, int x, int y, Heading heading, State state);
	//tell the other guy where I am

	void GetUpdate(int & level);
	//find out the level of play
	void GetUpdate(long int & time, int & x, int & y, Heading & heading, State & state);
	//find out where the other guy is. I have to keep my own map for both me and him.
	
};
