Exemplo n.º 1
0
CIVPlayerInfo::CIVPlayerInfo( )
{
	// Mark as not created by us
	m_bCreatedByUs = false;

	// Set the player info
	SetPlayerInfo( NULL );
}
Exemplo n.º 2
0
CIVPlayerInfo::CIVPlayerInfo( IVPlayerInfo * pPlayerInfo )
{
	// Mark as not created by us
	m_bCreatedByUs = false;

	// Set the player info
	SetPlayerInfo( pPlayerInfo );
}
Exemplo n.º 3
0
int AngelFight::handle_db_return( sprite_t* p, uint32_t id, const void* buf, int len, uint32_t ret_code )
{
    DEBUG_LOG("AngelFight Get DB return GameState=[%d]", int32_t(m_nGameState) );

    switch( m_nGameState )
    {
    case GS_WAIT_DB:
    {
        if( 0 != SetPlayerInfo( p,(char*)buf, len ) )
        {
            return GER_game_system_err;
        }
    }
    break;
    case GS_WAIT_DB_FRIEND:
    {
        return SetFriendInfo( id,(char*)buf, len );
    }
    break;
    //验证当前关卡是否可进入
    case GS_WAIT_DB_LEVEL:
    {
        Player* player = GetPlayer(p);
        if( !player )
        {
            return GER_game_system_err;
        }

        int32_t levelOK = *(int32_t*)buf;
        if( 1 == levelOK/* || true */)
        {
            SelectMonster( player );
        }
        else
        {
            DEBUG_LOG( "Forward Level Hasn't Completed" );
            return GER_end_of_game;
        }
    }
    break;
    case GS_OVER:
    {
        int len = sizeof(protocol_t);
        ant::pack( pkg, m_nWinnerTeam, len );
        ant::pack( pkg, PLAYER_COUNT, len );
        int32_t playerIdx;
        for( uint32_t j = 0; j < PLAYER_COUNT; ++j )
        {
            ant::pack( pkg, m_pPlayers[j]->GetTeamID(), len );

            playerIdx = 0;
            Player* pTemp = m_pTeam[j];
            while( pTemp && m_pPlayers[j] != pTemp )
            {
                playerIdx++;
                pTemp = pTemp->GetPartner();
            }
            if( !pTemp )
            {
                playerIdx = 0;
                ERROR_LOG( "Get Player Idx Failed" );
            }
            DEBUG_LOG( "Team:[%d] Idx:[%d] HP:[%d] MP:[%d]", m_pPlayers[j]->GetTeamID(), playerIdx, m_pPlayers[j]->GetHP(), m_pPlayers[j]->GetMP() );
            ant::pack( pkg, playerIdx, len );
            ant::pack( pkg, m_pPlayers[j]->GetHP(), len );
            ant::pack( pkg, m_pPlayers[j]->GetMP(), len );
        }
        init_proto_head( pkg, AFP_NOTIFY_GAME_OVER, len );

        send_to_player( p, pkg, len );
        m_nDBInfoCount--;
        if( 0 == m_nDBInfoCount )
        {
            return GER_end_of_game;
        }
    }
    break;
    default:
        break;
    }
    return 0;
}
Exemplo n.º 4
0
CIVPlayerInfo::~CIVPlayerInfo( )
{
	// Set the player info
	SetPlayerInfo( NULL );
}
Exemplo n.º 5
0
//==============================================================================
// InitServer()
//
//  Initializes the DarkPeer instance as a server.
//==============================================================================
void CDarkPeer::InitServer()
{
	try
	{
		HRESULT hRes;	
		DPN_APPLICATION_DESC dpnAppDesc;
		DPN_SP_CAPS caps;

		g_Net = STATE_Host;

		hRes = (CoCreateInstance(CLSID_DirectPlay8Peer, NULL, CLSCTX_INPROC_SERVER, IID_IDirectPlay8Peer, 
			(LPVOID*) &m_pDP));
		hRes = CoCreateInstance(CLSID_DirectPlay8Address, NULL, 
										CLSCTX_INPROC_SERVER, IID_IDirectPlay8Address, (LPVOID*) &m_pDeviceAddress);
		
		if (FAILED(hRes)) throw DPlayException("COM initialization failed", hRes);

		m_pSessionMgr = new CDarkSessionManager(m_pDP);

		g_pNetMan->PreFlush();

		ZeroMemory(&dpnAppDesc, sizeof(DPN_APPLICATION_DESC));
		dpnAppDesc.dwSize = sizeof(DPN_APPLICATION_DESC);
		dpnAppDesc.dwMaxPlayers = Cfg.GetInt("MaximumPlayers");
		dpnAppDesc.dwFlags = DPNSESSION_NODPNSVR;
		dpnAppDesc.guidApplication = GAME_GUID;

		wchar_t sessionName[kMaxGameName * 2];
		AnsiToWide(sessionName, Cfg.GetString("ServerName"), kMaxGameName);

		dpnAppDesc.pwszSessionName = sessionName;

		if (strlen(Cfg.GetString("Password")))
		{
			wchar_t buff[512];
			AnsiToWide(buff, Cfg.GetString("Password"), sizeof(buff));

			dpnAppDesc.pwszPassword = buff;
			dpnAppDesc.dwFlags |= DPNSESSION_REQUIREPASSWORD;
		}

		// Initialize DirectPlay
		hRes = m_pDP->Initialize(this, StaticMessageHandler, 0);
		if (FAILED(hRes)) throw DPlayException("Could not initialize DirectPlay", hRes);

		// Set service provider and port
		hRes = m_pDeviceAddress->SetSP(&CLSID_DP8SP_TCPIP);
		if (FAILED(hRes)) throw DPlayException("SetSP() failed", hRes);

		caps.dwSize = sizeof(DPN_SP_CAPS);
		hRes = m_pDP->GetSPCaps(&CLSID_DP8SP_TCPIP, &caps, NULL);
		if (FAILED(hRes)) throw DPlayException("GetSPCaps() failed", hRes);

		caps.dwSystemBufferSize = Cfg.GetInt("BufferSize");
		hRes = m_pDP->SetSPCaps(&CLSID_DP8SP_TCPIP, &caps, NULL);
		if (FAILED(hRes)) throw DPlayException("SetSPCaps() failed", hRes);

		int port = Cfg.GetInt("ServerPort");
		hRes = m_pDeviceAddress->AddComponent(DPNA_KEY_PORT, &port, sizeof(port), DPNA_DATATYPE_DWORD);
		if (FAILED(hRes)) throw DPlayException("AddComponent() failed", hRes);

		hRes = SetPlayerInfo();
		if (FAILED(hRes)) throw DPlayException("SetPeerInfo() failed", hRes);

		hRes = m_pDP->Host(&dpnAppDesc, &m_pDeviceAddress, 1, NULL, NULL, this, NULL);
		if (FAILED(hRes)) throw DPlayException("Host() failed", hRes);

		m_pSessionMgr->SetApplicationDesc(&dpnAppDesc);
		m_pSessionMgr->UpdateSessionInfo();
	}

	catch (DPlayException error)
	{
		// Release DirectPlay objects

		SAFE_RELEASE(m_pDeviceAddress);
		SAFE_RELEASE(m_pDP);

		throw error;
	}
}
Exemplo n.º 6
0
//==============================================================================
// OnEnumerationResponse()
//
// Handles host enumeration responses, and connects to the returned session.
//==============================================================================
void CDarkPeer::OnEnumerationResponse(PDPNMSG_ENUM_HOSTS_RESPONSE pEnumHostsResponseMsg)
{
#if (GAME == GAME_THIEF || GAME == GAME_DROMED)
	if (!g_ConnectAttempt.IsActive())
	{
		return;
	}
#endif

	HRESULT hRes;
	const DPN_APPLICATION_DESC* pAppDesc = pEnumHostsResponseMsg->pApplicationDescription;

#if (GAME == GAME_THIEF || GAME == GAME_DROMED)
	m_pSessionMgr->SetSessionInfo(pEnumHostsResponseMsg->pApplicationDescription);
	const SessionInfo& info = GetSessionInfo();

	if (info.build != TMP_BUILD)
	{
		ConPrintF("Server version (%d) does not match client version. Connection failed.", info.build);
		CancelEnumeration();
		return;
	}

	NString sessName = pEnumHostsResponseMsg->pApplicationDescription->pwszSessionName;
	ConPrintF("Game found: %s  Players: %d/%d  Build: %d.", sessName.Str(), pAppDesc->dwCurrentPlayers, pAppDesc->dwMaxPlayers, info.build);
#endif

	hRes = SetPlayerInfo();
	if (FAILED(hRes))
		return Log.Print("Failed to set peer info.");

	// Set the password, if we have one
	if (g_ConnectAttempt.GetPassword())
	{
		(WCHAR*)pAppDesc->pwszPassword = (WCHAR*)g_ConnectAttempt.GetPassword();
	}

	hRes = m_pDP->Connect(pAppDesc, pEnumHostsResponseMsg->pAddressSender, pEnumHostsResponseMsg->pAddressDevice, 
		NULL, NULL, NULL, 0, this, NULL, NULL, DPNCONNECT_SYNC);

	g_ConnectAttempt.Clear();

	switch (hRes)
	{
	case DPN_OK:
#ifdef ALLOW_LATE_JOINS
		if (info.gameStarted)
		{
			g_bNeedSnapshot = true;
			CNetMsg_RequestSnapshot msg;

			DbgPrint("Requesting snapshot");

			g_pNetMan->m_numStartedSynch = g_pNetMan->NumPlayers(); // 8/8/10 //g_pDarkNet->GetSessionManager()->GetApplicationDesc()->dwCurrentPlayers - 1;
			DbgPrint("Other players: %d", g_pNetMan->m_numStartedSynch);

			cNetManagerFns::_LoopFunc((void*)0x006C9420, kMsgBeginFrame, NULL);

			SendToHost((void*)&msg, sizeof(CNetMsg_RequestSnapshot), DPNSEND_GUARANTEED);
		}
#endif
		break; // Connection successful
	case DPNERR_INVALIDPASSWORD:
		ConPrintF("Incorrect password.");
		CancelEnumeration();
		break;
	case DPNERR_SESSIONFULL:
		ConPrintF("The server is full.");
		CancelEnumeration();
		break;
	case DPNERR_HOSTREJECTEDCONNECTION:
		ConPrintF("Cannot join server: the host has already started the mission.");
		CancelEnumeration();
		break;
	default:
		ConPrintF("Failed to connect to server. (%x)", DPlayErrorToString(hRes)); // Unknown error
		CancelEnumeration();
	}
}
Exemplo n.º 7
0
CIVPlayerInfo::~CIVPlayerInfo()
{
	SetPlayerInfo(NULL);
}
Exemplo n.º 8
0
CIVPlayerInfo::CIVPlayerInfo(IVPlayerInfo * pPlayerInfo)
	: m_bCreatedByUs(false)
{
	SetPlayerInfo(pPlayerInfo);
}
Exemplo n.º 9
0
CIVPlayerInfo::CIVPlayerInfo(IVPlayerInfo * pPlayerInfo)
{
	m_bCreatedByUs = false;
	SetPlayerInfo(pPlayerInfo);
}