/**
*
* \file Asura_Player.cpp
*
* Created by Kevin Lea - 02/01/2002 15:28:19
*
* Copyright (C) 2001 Rebellion, All Rights Reserved.
*
* \brief
*
**/

#include "Core/Asura.h"
#include "Network/Asura_Player.h"

#include "Network/Asura_Network.h"
#include "Network/Asura_Message.h"

Asura_Hashed_List<Asura_Entity_Player> Asura_Entity_Player::s_xList;

Asura_Entity_Player::Asura_Entity_Player( Asura_Guid uForcedGUID, bool bShouldSendPlayerConnectedMsg )
{
    Guid = ( ASURA_GUID_UNREGISTERED == uForcedGUID ? Asura_Network::GetNewClientGuid() : uForcedGUID );

	s_xList.AddToList(this);

    if( bShouldSendPlayerConnectedMsg )
    {
        SendPlayerConnectedMsg();
    }
}


void Asura_Entity_Player::SendPlayerConnectedMsg( void )
{
	Asura_Message* message = Asura_Network::CreateMessage(ASURA_MSG_PLAYERCONNECTED,sizeof(Asura_MsgData_PlayerConnected));
	
	if(message)
	{
		Asura_MsgData_PlayerConnected* data = (Asura_MsgData_PlayerConnected*) message->GetData();

		data->PlayerGuid = Guid;

		message->To = ASURA_GUID_SERVER;
		message->UseGuaranteedDelivery();

		Asura_Network::Send(message);
	}
}


Asura_Entity_Player::~Asura_Entity_Player()
{
	s_xList.RemoveFromList(this);
}

