//===========================================================================//
// File:	NetClientServerController.hpp				
// Contents : All movement messages and rewind capabilites				
//---------------------------------------------------------------------------//
//   Date    Who  Modification                                               //
// --------  ---  ---------------------------------------------------------- //
// 01/18/1999  JSE  Inital coding
//---------------------------------------------------------------------------//
// Copyright (C) 1998, Microsoft Corp.										 //
// All Rights reserved worldwide                                             //
// This unpublished sourcecode is PROPRIETARY and CONFIDENTIAL               //
//===========================================================================//



#pragma once

namespace MechWarrior4 
{
	class ServerController;
	class ClientController;
}

#include "NetConstants.hpp"
#include "NetUpdateManager.hpp"
//#include "Mech.hpp"
#include <Adept\Application.hpp>
#include "MWEntityManager.hpp"

namespace MechWarrior4 
{


	struct SecurityQueryInfo
	{

		int		lastSecurityKey;
		GUID	lastSecurityAnswer;

		int		securityKey;
		GUID	securityAnswer;
		
		
		int		otherSidesKey;


		Scalar  securityTimer;

		bool needInit;

		SecurityQueryInfo();
		void Reset(void);
	};


	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


	class ServerController
	{
	
	public:
		MWEntityManager *m_EntityManager;
		
		ServerController();
		~ServerController();

		double clockDifference[Maximum_Players];
		double lowestLatency[Maximum_Players];


		BYTE lastControlPacketID[Maximum_Players];
		Scalar lastPingDelta[Maximum_Players]; //t2-t1
		Scalar lastControlPacket[Maximum_Players];
		Scalar lastControlPacketLocal[Maximum_Players];
		Scalar lastTimeFailure[Maximum_Players];
		Point3D lastReportedPosition[Maximum_Players];
		BYTE positionErrors[Maximum_Players];
		BYTE latencyDelay[Maximum_Players];

	
	
		bool waitingForRespawn[Maximum_Players];


		SecurityQueryInfo securityQuery[Maximum_Players];	

		void RespawnClient(int connection_id, Point3D trans);
		void Reset();
		void ResetClient(int connection_id);

		void ThrottleTest(int connection_id);

		bool SendWeaponCommands();
		void SendAIWeaponCommands();
		void ReceiveWeaponCommand(int connection, int message_type, Stuff::MemoryStream *message);

		void ReceivePlayerControl(int connection, Stuff::MemoryStream *message);
		void ReceivePlayerObserverControl(int connection, Stuff::MemoryStream *message);
		
		void SendFullConfirmation(int connection);
	};


	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


	class ClientController
	{
	public:
		
		MWEntityManager *m_EntityManager;

		Scalar controlUpdateTimer;
		
		BYTE lastControlPacketID;
		Scalar lastPingDelta; //t2-t1

		SecurityQueryInfo securityQuery;		

		ClientController();
		~ClientController();

		void RespawnClient(int connection_id);
		void Reset();

		void SendControlPacketToServer(Scalar time_slice);
		void ReceiveSmallConfirmation(Stuff::MemoryStream *message){};
		void ReceiveFullConfirmation(Stuff::MemoryStream *message);
		
		void SendWeaponCommands(void);
		void ReceiveWeaponCommand(int connection, int message_type, Stuff::MemoryStream *message);
		void ReceiveWeaponBundle(int connection, int message_type, Stuff::MemoryStream *message);

	};
};