⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 netstart.cpp

📁 Blood 2全套源码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
	s_nEndTime     = GetConsoleInt("NetEndTime", 15);
	s_nNetService  = GetConsoleInt("NetService", 0);
	s_nNetJoinHost = GetConsoleInt("NetJoinHost", 0);
	s_nNetLatency  = GetConsoleInt("UpdateRate", DEFAULT_UPDATERATE);
	s_nMaxPlayers  = GetConsoleInt("NetMaxPlayers", MAX_MULTI_PLAYERS_DISPLAY);
	s_nFpsLimit    = GetConsoleInt("NetFpsLimit", s_nFpsLimit);
	s_bLimitFps    = GetConsoleInt("NetLimitFps", s_bLimitFps);


	// Update info from the lobby info...

	if (strlen(pDplConn->lpSessionDesc->lpszSessionNameA) > 0)
	{
		strcpy(s_sSessionName, pDplConn->lpSessionDesc->lpszSessionNameA);
	}

	if (strlen(pDplConn->lpPlayerName->lpszShortNameA) > 0)
	{
		strcpy(s_sPlayerName, pDplConn->lpPlayerName->lpszShortNameA);
	}

	PostProcessName(s_sPlayerName);


	// Set our join host info...

	if (pDplConn->dwFlags & DPLCONNECTION_CREATESESSION)
	{
		s_pNetStart->m_bHost = DTRUE;
	}
	else
	{
		s_pNetStart->m_bHost = DFALSE;
	}


	// Do the player dialog...

PlayerDlg:
	nRet = DialogBox(hInst, "NET_PLAYER", hParentWnd, (DLGPROC)NetDlg_Player);

	if (nRet == DLG_CANCEL) return(DFALSE);
	if (nRet == DLG_ERROR)
	{
		NetStart_DisplayError(hInst);
		return(DFALSE);
	}

	if (!s_pNetStart->m_bHost) goto Launch;


	// Do the game dialog (host only)...

GameDlg:

#ifdef _ADDON
	nRet = DialogBox(hInst, "NET_GAME_AO", hParentWnd, (DLGPROC)NetDlg_Game);
#else
	nRet = DialogBox(hInst, "NET_GAME", hParentWnd, (DLGPROC)NetDlg_Game);
#endif

	if (nRet == DLG_BACK) goto PlayerDlg;
	if (nRet == DLG_CANCEL) return(DFALSE);
	if (nRet == DLG_ERROR)
	{
		NetStart_DisplayError(hInst);
		return(DFALSE);
	}


	// Do the game levels dialog (host only)...

	nRet = DialogBox(hInst, "NET_GAMELEVELS", hParentWnd, (DLGPROC)NetDlg_GameLevels);

	if (nRet == DLG_BACK) goto GameDlg;
	if (nRet == DLG_CANCEL) return(DFALSE);
	if (nRet == DLG_ERROR)
	{
		NetStart_DisplayError(hInst);
		return(DFALSE);
	}


	// Launch the game...

Launch:
	StartGameRequest req;
	memset(&req, 0, sizeof(req));

	req.m_flags = SG_LOBBY;	// flag that we were lobby launched

	if (s_pNetStart->m_bHost)
	{
		req.m_Type = STARTGAME_HOST;

		strcpy(req.m_WorldName, ns.m_sLevel);
		memcpy(&req.m_HostInfo, &ns.m_NetHost, sizeof(NetHost));
	}
	else
	{
		req.m_Type        = STARTGAME_CLIENT;
		req.m_pNetSession = ns.m_pNetSession;
	}

	req.m_pGameInfo   = NetStart_GetGameStruct();
	req.m_GameInfoLen = sizeof(NetGame_t);

	dr = pClient->StartGame(&req);

	NetStart_FreeSessionList(pClient);

	if (dr != LT_OK)
	{
		s_nErrorString = IDS_NETERR_INIT;
		NetStart_DisplayError(hInst);
		return(DFALSE);
	}


	// Write out some console values...

	if (s_pNetStart->m_bHost)
	{
		WriteConsoleString("NetSessionName", s_sSessionName);

		WriteConsoleInt("NetGameType", s_nGameType);
		WriteConsoleInt("NetGameEnd", s_nEndType);
		WriteConsoleInt("NetEndFrags", s_nEndFrags);
		WriteConsoleInt("NetEndTime", s_nEndTime);
		WriteConsoleInt("NetMaxPlayers", s_nMaxPlayers);
	}

	PostProcessName(s_sPlayerName);
	WriteConsoleString("NetPlayerName", s_sPlayerName);

	WriteConsoleInt("NetPlayerColor", s_nPlayerColor);
	WriteConsoleInt("NetMech", s_nMech);
	WriteConsoleInt("NetLatency", s_nNetLatency);


	// Display a loading screen...

	DDWORD cxLoading, cyLoading, cxScreen, cyScreen;
	HSURFACE hLoading = pClient->CreateSurfaceFromBitmap ("interface/loading.pcx");
	pClient->GetSurfaceDims (hLoading, &cxLoading, &cyLoading);
	HSURFACE hScreen = pClient->GetScreenSurface();
	pClient->GetSurfaceDims (hScreen, &cxScreen, &cyScreen);

	pClient->ClearScreen(DNULL, CLEARSCREEN_SCREEN);
	pClient->Start3D();
	pClient->StartOptimized2D();
	pClient->DrawSurfaceToSurface(hScreen, hLoading, DNULL, ((int)cxScreen - (int)cxLoading) / 2, ((int)cyScreen - (int)cyLoading) / 2);
	pClient->EndOptimized2D();
	pClient->End3D();
	pClient->FlipScreen(FLIPSCREEN_CANDRAWCONSOLE);


	// All done...

	return(DTRUE);
}


// ----------------------------------------------------------------------- //
//
//	ROUTINE:	NetStart_MinimizeMainWnd
//
//	PURPOSE:	Minimizes the main window
//
// ----------------------------------------------------------------------- //

DBOOL NetStart_MinimizeMainWnd(CClientDE* pClient)
{
	// Sanity checks...

	if (!pClient) return(DFALSE);


	// Get the window handle...

	s_hMainWnd = NULL;

	DRESULT dr = pClient->GetEngineHook("HWND", &s_hMainWnd);
	if (dr != LT_OK || !s_hMainWnd)
	{
		s_hMainWnd = GetActiveWindow();
	}


	// Save the current render mode...

	pClient->GetRenderMode(&s_RMode);


	// Shutdown the renderer, minimize it, and hide it...

	pClient->ShutdownRender(RSHUTDOWN_MINIMIZEWINDOW | RSHUTDOWN_HIDEWINDOW);


	// All done...

	return(DTRUE);
}


// ----------------------------------------------------------------------- //
//
//	ROUTINE:	NetStart_RestoreMainWnd
//
//	PURPOSE:	Restores the main window
//
// ----------------------------------------------------------------------- //

DBOOL NetStart_RestoreMainWnd()
{
	// Sanity checks...

	if (!s_pClient) return(DFALSE);


	// Restore the main window as necessary...

	DRESULT dr = s_pClient->SetRenderMode(&s_RMode);
	if (dr != LT_OK) return(DFALSE);


	// All done...

	return(DTRUE);
}


// ----------------------------------------------------------------------- //
//
//	ROUTINE:	NetStart_HandleDefaultDialogCommands
//
//	PURPOSE:	Handles default dialog commands (next, back, cancel, etc)
//
// ----------------------------------------------------------------------- //

BOOL NetStart_HandleDefaultDialogCommands(HWND hDlg, WPARAM wParam)
{
	// Handle any default commands...

	switch (wParam)
	{
		case IDC_BACK:
		{
			EndDialog(hDlg, DLG_BACK);
			return(TRUE);
		}

		case IDCANCEL:
		{
			EndDialog(hDlg, DLG_CANCEL);
			return(TRUE);
		}
	}


	// If we get here, it's not a default command...

	return(FALSE);
}


// ----------------------------------------------------------------------- //
//
//	ROUTINE:	NetStart_FillServiceList
//
//	PURPOSE:	Fills a list box with the available services
//
// ----------------------------------------------------------------------- //

BOOL NetStart_FillServiceList(HWND hList)
{
	// Sanity checks...

	if (!hList) return(FALSE);


	// Get the service list...

	NetService *pCur, *pListHead = NULL;

	DRESULT dr = s_pClient->GetServiceList(pListHead);
	if (dr != LT_OK) return(FALSE);

	if (!pListHead)
	{
		return(FALSE);
	}


	// Add each service to the list box...
	DWORD iCurInfo=0;

	SendMessage(hList, LB_RESETCONTENT, 0, 0);

	for (pCur=pListHead; pCur; pCur=pCur->m_pNext)
	{
		int iItem = SendMessage(hList, LB_ADDSTRING, 0, (LPARAM)(LPCSTR)pCur->m_sName);
		if (iItem != LB_ERR)
		{
			SendMessage(hList, LB_SETITEMDATA, iItem, (LPARAM)pCur->m_handle);
			if(iCurInfo < MAX_NETSTART_SERVICES)
			{
				g_ServiceHandles[iCurInfo] = pCur->m_handle;
				g_ServiceFlags[iCurInfo] = pCur->m_dwFlags;
				++iCurInfo;
			}
		}
	}


	// Select the last used service...

	int nRet = SendMessage(hList, LB_SETCURSEL, s_nNetService, 0);
	if (nRet == LB_ERR)
	{
		SendMessage(hList, LB_SETCURSEL, 0, 0);
	}


	// Free the service list...

	s_pClient->FreeServiceList(pListHead);


	// All done...

	return(TRUE);
}

BOOL NetStart_FillNetSpeed(HWND hDlg)
{
	char str[128];

	// Sanity checks...

	if (!hDlg) return(FALSE);


	// Fill the combo box with our options...

	HWND hComboBox = GetDlgItem(hDlg, IDC_NETCONNECTION);
	if (!hComboBox) return(FALSE);

	SendMessage(hComboBox, CB_RESETCONTENT, 0, 0);

	sprintf(str, "%s (%d)", s_sHighPing, HIGHPING_UPDATERATE);
	AddComboInfo(hComboBox, str, HIGHPING_UPDATERATE);
	
	sprintf(str, "%s (%d)", s_sModem, MODEM_UPDATERATE);
	AddComboInfo(hComboBox, str, MODEM_UPDATERATE);
	
	sprintf(str, "%s (%d)", s_sIsdn, ISDN_UPDATERATE);
	AddComboInfo(hComboBox, str, ISDN_UPDATERATE);
	
	sprintf(str, "%s (%d)", s_sLan, LAN_UPDATERATE);
	AddComboInfo(hComboBox, str, LAN_UPDATERATE);

	SendMessage(hComboBox, CB_SETCURSEL, 0, 0);


	// Set the current selection...

	s_nNetLatency  = GetConsoleInt("UpdateRate", DEFAULT_UPDATERATE);
	int nVal = s_nNetLatency;
	if (nVal == 0) nVal = 200;

	int count = SendMessage(hComboBox, CB_GETCOUNT, 0, 0);
	if (count == CB_ERR) return(TRUE);

	BOOL bFound = FALSE;

	for (int i = 0; i < count; i++)
	{
		int nItemData = SendMessage(hComboBox, CB_GETITEMDATA, i, 0);
		if (nItemData != CB_ERR)
		{
			if (nItemData == nVal)
			{
				SendMessage(hComboBox, CB_SETCURSEL, i, 0);
				i = count;
				bFound = TRUE;
			}
		}
	}


	// Set a custom value if necessary...

	if (!bFound)
	{
		sprintf(str, "%s (%d)", s_sCustom, nVal);
		int nIndex = AddComboInfo(hComboBox, str, nVal);
		if (nIndex != CB_ERR)
		{
			SendMessage(hComboBox, CB_SETCURSEL, nIndex, 0);
		}
	}


	// All done...

	return(TRUE);
}

int AddComboInfo(HWND hComboBox, char* sText, DWORD dwValue)
{
	int nIndex = SendMessage(hComboBox, CB_ADDSTRING, 0, (LPARAM)(LPCSTR)sText);
	if (nIndex == CB_ERR) return(CB_ERR);
	SendMessage(hComboBox, CB_SETITEMDATA, nIndex, dwValue);
	return(nIndex);
}


// ----------------------------------------------------------------------- //
//
//	ROUTINE:	NetStart_SelectCurrentService
//
//	PURPOSE:	Selects the currently selected service in the list box
//
// ----------------------------------------------------------------------- //

BOOL NetStart_SelectCurrentService(HWND hList)
{
	// Sanity checks...

	if (!hList) return(FALSE);


	// Get the currently select list-box item...

	int nIndex = SendMessage(hList, LB_GETCURSEL, 0, 0);
	if (nIndex == LB_ERR) return(FALSE);


	// Get the item data for this index...

	int nRet = SendMessage(hList, LB_GETITEMDATA, nIndex, 0);
	if (nRet == LB_ERR) return(FALSE);

	HNETSERVICE hNetService = (HNETSERVICE)nRet;
	if (!hNetService) return(FALSE);


	// Select the service...

	DRESULT dr = s_pClient->SelectService(hNetService);
	if (dr != LT_OK) return(FALSE);

	s_nNetService = nIndex;
	g_SelectedService = hNetService;


	// All done...

	return(TRUE);
}

BOOL NetStart_SelectJoinHost(HWND hDlg)
{
	// Sanity checks...

	if (!hDlg) return(FALSE);


	// Get the join host selection...

	if (IsDlgButtonChecked(hDlg, IDC_JOIN))
	{
		s_pNetStart->m_bHost = FALSE;
		s_nNetJoinHost       = NET_JOIN;
	}
	else if (IsDlgButtonChecked(hDlg, IDC_HOST))
	{
		s_pNetStart->m_bHost = TRUE;
		s_nNetJoinHost       = NET_HOST;
	}


	// All done...

	return(TRUE);
}

BOOL NetStart_SelectNetSpeed(HWND hComboBox)
{
	// Sanity checks...

	if (!hComboBox) return(FALSE);


	// Get the latency...

	s_NetPlayer.m_dwLatency = MODEM_UPDATERATE;

	int nIndex = SendMessage(hComboBox, CB_GETCURSEL, 0, 0);
	if (nIndex == CB_ERR) return(FALSE);

	int nVal = SendMessage(hComboBox, CB_GETITEMDATA, nIndex, 0);
	if (nVal == CB_ERR) return(FALSE);

	s_nNetLatency           = nVal;
	s_NetPlayer.m_dwLatency = nVal;


	// All done...

	return(TRUE);
}


// ----------------------------------------------------------------------- //
//
//	ROUTINE:	NetStart_Services
//
//	PURPOSE:	Does the SERVICES dialog
//
// ----------------------------------------------------------------------- //

BOOL CALLBACK NetDlg_Services(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	switch (uMsg)
	{
		case WM_INITDIALOG:
		{
			ForceActiveFocus(hDlg);
			PostMessage(hDlg, WM_COMMAND, ID_FILLSTUFF, 0);
			return(TRUE);
		}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -