// Asura_PC_SteamworksLobby.h
// Thomas Young - 23.04.09
// Copyright (C) 2009 Rebellion, All Rights Reserved.

// F I L E   W R A P P E R ///////////////////////////////////////////////////

#ifdef ASURA_USE_PRAGMA_ONCE
#pragma once
#endif

#ifndef ___ASURA_PC_STEAMWORKSLOBBY_H__
#define ___ASURA_PC_STEAMWORKSLOBBY_H__ 1

// I N C L U D E S ///////////////////////////////////////////////////////////

#include "Core/Asura.h"

#ifdef ASURA_PC_SUPPORT_STEAMWORKS

#include "Steam/Steam_API.h"

// E N U M E R A T I O N S ///////////////////////////////////////////////////

enum ASURA_STEAM_LOBBY_STATE
{
	ASURA_STEAM_LOBBY_STATE_IDLE,

	ASURA_STEAM_LOBBY_STATE_CREATING,
	ASURA_STEAM_LOBBY_STATE_JOINING,
	
	ASURA_STEAM_LOBBY_STATE_ERROR,

	ASURA_STEAM_LOBBY_STATE_ACTIVE
};

// T Y P E D E F S ///////////////////////////////////////////////////////////

typedef u_int Asura_PC_SteamLobbyHandle;

// C O N S T A N T S /////////////////////////////////////////////////////////

const u_int Asura_PC_SteamInvalidLobbyHandle = ( u_int )( -1 );

// F O R W A R D   D E C L A R A T I O N S ///////////////////////////////////

struct LobbyEnter_t;
struct LobbyCreated_t;

class Asura_PC_Steamworks_KeyValuePair;

template< class Asura_PC_Steamworks_KeyValuePair >	class Asura_List;
template< class Asura_PC_SteamworksLobby >			class Asura_List;

// C L A S S   D E C L A R A T I O N S ///////////////////////////////////////

// ______________________________ Asura_PC_SteamworksLobby _________________________________

class Asura_PC_SteamworksLobby
{
	friend class Asura_PC_SteamworksLobby_System;

	public:

		// _______________________ Functions _______________________

		Asura_PC_SteamworksLobby	( );
		~Asura_PC_SteamworksLobby	( );

		void						Join				( CSteamID xLobbySteamID );
		void						Create				( const Asura_List<Asura_PC_Steamworks_KeyValuePair>* pxMetaData, const bool bPrivate = false );
		
		bool						IsActive			( ) const;
		ASURA_STEAM_LOBBY_STATE		GetState			( ) const;
		
		CSteamID					GetSteamID			( ) const;
		uint64						GetSteamID_uint64	( ) const;
		CSteamID					GetOwner			( ) const;
		bool						OwnerIsMe			( ) const;

		void						SetServer			( const CSteamID xServerSteamID, const u_int uServerIP, const u_short usServerPort );
		void						UpdateMetaData		( Asura_List<Asura_PC_Steamworks_KeyValuePair>* pxMetaData );

		Asura_PC_SteamLobbyHandle	GetHandle			( ) const;

	protected:

		void SetHandle ( const Asura_PC_SteamLobbyHandle xHandle );

	private:

		// _______________________ Functions _______________________

		void Callback_LobbyCreated	( LobbyCreated_t *pxParam, bool bIOFailure );
		void Callback_EnterLobby	( LobbyEnter_t* pxParam, bool bIOFailure );

		// _______________________ Variables _______________________

		CSteamID m_xSteamID;

		ASURA_STEAM_LOBBY_STATE m_eState;
		
		Asura_List<Asura_PC_Steamworks_KeyValuePair> m_xMetaData;
		
		CCallResult<Asura_PC_SteamworksLobby, LobbyCreated_t>	m_xCallResult_LobbyCreated;
		CCallResult<Asura_PC_SteamworksLobby, LobbyEnter_t>		m_xCallResult_EnterLobby;

		Asura_PC_SteamLobbyHandle m_xHandle;
};

// ______________________________ Asura_PC_SteamworksLobby_System _________________________________

class Asura_PC_SteamworksLobby_System
{
	friend class Asura_PC_Steamworks;

	public:

		// _______________________ Functions _______________________

		Asura_PC_SteamworksLobby_System		( ) {};
		~Asura_PC_SteamworksLobby_System	( ) {};

		static Asura_PC_SteamLobbyHandle	CreateLobby	( const Asura_List<Asura_PC_Steamworks_KeyValuePair>* pxMetaData, const bool bPrivate = false );
		static Asura_PC_SteamLobbyHandle	JoinLobby	( const CSteamID xLobbySteamID );

		static void							LeaveLobby	( const Asura_PC_SteamLobbyHandle xHandle );
		
		static Asura_PC_SteamworksLobby*	GetLobby	( const CSteamID xSteamID );
		static Asura_PC_SteamworksLobby*	GetLobby	( const Asura_PC_SteamLobbyHandle xHandle );
		
	protected:

		// _______________________ Functions _______________________

		static void	Initialise	( );		// Called by Asura_PC_Steamworks
		static void	Update		( );
		static void	Shutdown	( );

	private:

		static Asura_List< Asura_PC_SteamworksLobby > s_xLobbyList;

		static Asura_PC_SteamLobbyHandle s_xNextLobbyHandle;
};

#endif	// ASURA_PC_SUPPORT_STEAMWORKS

#endif // ___ASURA_PC_STEAMWORKSLOBBY_H__

//eof
