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

📄 netstart.cpp

📁 Blood 2全套源码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
	if (nRet == DLG_ERROR) goto Failure;
	if (nRet == DLG_CANCEL) goto Cancel;


	// If necessary, do the team options dialog...

TeamOptionsDlg:
	if (s_nGameType != NGT_TEAMS) goto CtfOptionsDlg;

	nRet = DialogBox(hInst, "NET_OPTIONS_TEAMS", hParentWnd, (DLGPROC)NetDlg_TeamOptions);

	if (nRet == DLG_BACK) goto GameDlg;
	if (nRet == DLG_CANCEL) return(DFALSE);
	if (nRet == DLG_ERROR) goto Failure;


	// If necessary, do the ctf options dialog...

CtfOptionsDlg:
	if (s_nGameType != NGT_CAPTUREFLAG) goto SoccerOptionsDlg;

	nRet = DialogBox(hInst, "NET_OPTIONS_CTF", hParentWnd, (DLGPROC)NetDlg_CtfOptions);

	if (nRet == DLG_BACK) goto GameDlg;
	if (nRet == DLG_CANCEL) return(DFALSE);
	if (nRet == DLG_ERROR) goto Failure;


	// If necessary, do the ctf options dialog...

SoccerOptionsDlg:
	if (s_nGameType != NGT_SOCCER) goto GameItemsDlg;

	nRet = DialogBox(hInst, "NET_OPTIONS_SOCCER", hParentWnd, (DLGPROC)NetDlg_SoccerOptions);

	if (nRet == DLG_BACK) goto GameDlg;
	if (nRet == DLG_CANCEL) return(DFALSE);
	if (nRet == DLG_ERROR) goto Failure;


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

GameItemsDlg:
	nRet = DialogBox(hInst, "NET_GAMEITEMS", hParentWnd, (DLGPROC)NetDlg_GameItems);

	if (nRet == DLG_BACK)
	{
		if (s_nGameType == NGT_SOCCER) goto SoccerOptionsDlg;
		if (s_nGameType == NGT_CAPTUREFLAG) goto CtfOptionsDlg;
		if (s_nGameType == NGT_TEAMS) goto TeamOptionsDlg;
		goto GameDlg;
	}

	if (nRet == DLG_CANCEL) return(DFALSE);
	if (nRet == DLG_ERROR) goto Failure;


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

GameDamageDlg:
	nRet = DialogBox(hInst, "NET_GAMEDAMAGE", hParentWnd, (DLGPROC)NetDlg_GameDamage);

	if (nRet == DLG_BACK) goto GameItemsDlg;
	if (nRet == DLG_CANCEL) return(DFALSE);
	if (nRet == DLG_ERROR) goto Failure;


	// Do the options dialog...

OptionsDlg:
	nRet = DialogBox(hInst, "NET_OPTIONS", hParentWnd, (DLGPROC)NetDlg_Options);

	if (nRet == DLG_BACK) goto GameDamageDlg;
	if (nRet == DLG_ERROR) goto Failure;
	if (nRet == DLG_CANCEL) goto Cancel;


	// Do the game levels dialog...

	if (!bAddedResources)
	{
		CWaitCursor wc;

		if (!GetTheApp()->AddResources(s_collRezFiles))
		{
			goto Failure;
		}

		bAddedResources = TRUE;
	}

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

	if (nRet == DLG_BACK) goto OptionsDlg;
	if (nRet == DLG_ERROR) goto Failure;
	if (nRet == DLG_CANCEL) goto Cancel;


	// Display the "-go" info if we haven't already...

	if (!s_bDashGoInfo)
	{
		DoOptionHelp(NULL, IDS_HELP_DASHGO, IDS_TITLE_DASHGO);
	}

	SaveLevelStrings();


	// All done...

	return(TRUE);


	// Cancel...

Cancel:
	return(FALSE);


	// Failure...

Failure:
	NetStart_DisplayError();
	return(FALSE);
}

void NetStart_DisplayError()
{
	AfxMessageBox(s_nErrorString);
}

int NetStart_GetPort()
{
	return(s_nPort);
}


// ----------------------------------------------------------------------- //
//
//	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);
	if (!s_pServerMgr) return(FALSE);


	// Get the service list...

	NetService *pCur, *pListHead = NULL;

	BOOL bRet = s_pServerMgr->GetServiceList(pListHead);
	if (!bRet) return(FALSE);

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


	// Add each service to the list box...

	SendMessage(hList, LB_RESETCONTENT, 0, 0);

	for (pCur=pListHead; pCur; pCur=pCur->m_pNext)
	{
		NetService* pService = pCur;

		int iItem = SendMessage(hList, LB_ADDSTRING, 0, (LPARAM)(LPCSTR)pService->m_sName);
		if (iItem != LB_ERR)
		{
			SendMessage(hList, LB_SETITEMDATA, iItem, (LPARAM)pService->m_handle);
		}
	}


	// 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_pServerMgr->FreeServiceList(pListHead);


	// All done...

	return(TRUE);
}


// ----------------------------------------------------------------------- //
//
//	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...

	BOOL bRet = s_pServerMgr->SelectService(hNetService);
	if (!bRet) return(FALSE);

	s_nNetService = nIndex;


	// Get the string name...

	char sBuf[128];
	nRet = SendMessage(hList, LB_GETTEXT, nIndex, (LPARAM)sBuf);
	if (nRet == LB_ERR) s_pServerInfo->m_sService[0] = '\0';
	else
	{
		strcpy(s_pServerInfo->m_sService, sBuf);
		strcpy(s_sServiceName, s_pServerInfo->m_sService);
		strlwr(sBuf);

		if (strstr(sBuf, "ipx")) strcpy(s_pServerInfo->m_sService, "Ipx");
		else if (strstr(sBuf, "modem")) strcpy(s_pServerInfo->m_sService, "Modem");
		else if (strstr(sBuf, "serial")) strcpy(s_pServerInfo->m_sService, "Serial Cable");
		else if (strstr(sBuf, "tcp"))
		{
			strcpy(s_pServerInfo->m_sService, "Tcp/ip");
			s_bIsTcpIp = TRUE;
		}
	}


	// 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:
		{
			s_bIsTcpIp = FALSE;

			SetIcon(hDlg);
			ForceActiveFocus(hDlg);

			if (!NetStart_FillServiceList(GetDlgItem(hDlg, IDC_SERVICELIST)))
			{
				s_nErrorString = IDS_NETERR_FILLSERVICE;
				EndDialog(hDlg, DLG_ERROR);
			}

			CheckDlgButton(hDlg, IDC_USEGAMESPY, s_bUseGameSpy ? BST_CHECKED : BST_UNCHECKED);
			CheckDlgButton(hDlg, IDC_UPDATEINFO, s_bUpdateInfo ? BST_CHECKED : BST_UNCHECKED);
			CheckDlgButton(hDlg, IDC_SERVERREG, s_bServerReg ? BST_CHECKED : BST_UNCHECKED);

			return(TRUE);
		}

		case WM_COMMAND:
		{
			if (NetStart_HandleDefaultDialogCommands(hDlg, wParam))
			{
				return(TRUE);
			}
			else if (wParam == IDC_NEXT)
			{
				if (!NetStart_SelectCurrentService(GetDlgItem(hDlg, IDC_SERVICELIST)))
				{
					s_nErrorString = IDS_NETERR_SELECTSERVICE;
					EndDialog(hDlg, DLG_ERROR);
				}
				else
				{
					s_bUpdateInfo = IsDlgButtonChecked(hDlg, IDC_UPDATEINFO) == BST_CHECKED;
					s_bServerReg  = IsDlgButtonChecked(hDlg, IDC_SERVERREG) == BST_CHECKED;
					s_bUseGameSpy = IsDlgButtonChecked(hDlg, IDC_USEGAMESPY) == BST_CHECKED;

					s_pServerInfo->m_bUseGameSpy     = s_bUseGameSpy;
					s_pServerInfo->m_bUpdateGameInfo = s_bUpdateInfo;
					s_pServerInfo->m_bRegisterServer = s_bServerReg;

					EndDialog(hDlg, DLG_NEXT);
				}
				return(TRUE);
			}

			return(TRUE);
		}
	}

	return(FALSE);
}


// ----------------------------------------------------------------------- //
//
//	ROUTINE:	NetStart_FillGameInfo
//
//	PURPOSE:	Fills the game info from the dialog
//
// ----------------------------------------------------------------------- //

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

	if (!hDlg) return(FALSE);


	// Get the server name...

	char sName[128];
	sName[0] = '\0';

	GetDlgItemText(hDlg, IDC_NAME, sName, 120);

	if (strlen(sName) == 0)
	{
#ifdef _ADDON
		LoadString(s_hInst, IDS_DEFAULTSERVERNAME_AO, sName, 124);
#else
		LoadString(s_hInst, IDS_DEFAULTSERVERNAME, sName, 124);
#endif
	}

	strcpy(s_pServerInfo->m_sName, sName);
	strcpy(s_sServerName, sName);


	// All done...

	return(TRUE);
}


// ----------------------------------------------------------------------- //
//
//	ROUTINE:	NetStart_Game
//
//	PURPOSE:	Does the GAME dialog
//
// ----------------------------------------------------------------------- //

BOOL CALLBACK NetDlg_Game(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	switch (uMsg)
	{
		case WM_INITDIALOG:
		{
			SetIcon(hDlg);
			ForceActiveFocus(hDlg);
			SetDlgItemText(hDlg, IDC_NAME, s_sServerName);
			NetStart_SetEndGameInfo(hDlg);
			NetStart_InitGameType(hDlg);

			return(TRUE);
		}

		case WM_COMMAND:
		{
			if (NetStart_HandleDefaultDialogCommands(hDlg, wParam))
			{
				return(TRUE);
			}
			else if (wParam == IDC_NEXT)
			{
				if (!NetStart_FillGameInfo(hDlg))
				{
					EndDialog(hDlg, DLG_ERROR);
				}

				if (!NetStart_FillGameEnd(hDlg))
				{
					EndDialog(hDlg, DLG_ERROR);
				}

				if (!NetStart_FillGameType(hDlg))
				{
					EndDialog(hDlg, DLG_ERROR);
				}

				EndDialog(hDlg, DLG_NEXT);
				return(TRUE);
			}

			return(TRUE);
		}
	}

	return(FALSE);
}

void ForceActiveFocus(HWND hWnd)
{
	SetActiveWindow(hWnd);
	BringWindowToTop(hWnd);
	SetForegroundWindow(hWnd);
	SetFocus(hWnd);
}

void SetIcon(HWND hWnd)
{
	SendMessage(hWnd, WM_SETICON, ICON_BIG, (LPARAM)s_hIcon);
}


// ----------------------------------------------------------------------- //
//
//	ROUTINE:	NetStart_Welcome
//
//	PURPOSE:	Does the WELCOME dialog
//
// ----------------------------------------------------------------------- //

BOOL CALLBACK NetDlg_Welcome(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	switch (uMsg)
	{
		case WM_INITDIALOG:
		{
			SetIcon(hDlg);
			ForceActiveFocus(hDlg);
			SetTimer(hDlg, 1, 500, NULL);
			return(TRUE);
		}

		case WM_TIMER:
		{
			KillTimer(hDlg, 1);
			ForceActiveFocus(hDlg);
			return(TRUE);
		}

		case WM_COMMAND:
		{
			if (NetStart_HandleDefaultDialogCommands(hDlg, wParam))
			{
				return(TRUE);
			}
			else if (wParam == IDC_NEXT)
			{
				EndDialog(hDlg, DLG_NEXT);
				return(TRUE);
			}
		}
	}

	return(FALSE);
}


// ----------------------------------------------------------------------- //
//
//	ROUTINE:	NetStart_Finished
//
//	PURPOSE:	Does the FINISHED dialog
//
// ----------------------------------------------------------------------- //

BOOL CALLBACK NetDlg_Finished(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	switch (uMsg)
	{
		case WM_INITDIALOG:
		{
			SetIcon(hDlg);
			ForceActiveFocus(hDlg);
			return(TRUE);
		}

		case WM_COMMAND:
		{
			if (NetStart_HandleDefaultDialogCommands(hDlg, wParam))

⌨️ 快捷键说明

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