📄 netstart.cpp
字号:
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);
}
if (!NetStart_SelectJoinHost(hDlg))
{
EndDialog(hDlg, DLG_ERROR);
}
EndDialog(hDlg, DLG_NEXT);
return(TRUE);
}
else if (wParam == ID_FILLSTUFF)
{
if (!NetStart_FillServiceList(GetDlgItem(hDlg, IDC_SERVICELIST)))
{
s_nErrorString = IDS_NETERR_SELECTSERVICE;
EndDialog(hDlg, DLG_ERROR);
}
if (s_nInternalJoinHost == NET_HOST)
{
ShowWindow(GetDlgItem(hDlg, IDC_HOSTNOTE), SW_NORMAL);
}
if (s_nInternalJoinHost == NET_UNKNOWN)
{
ShowWindow(GetDlgItem(hDlg, IDC_HOSTNOTE), SW_NORMAL);
ShowWindow(GetDlgItem(hDlg, IDC_JOINHOST_TITLE), SW_NORMAL);
ShowWindow(GetDlgItem(hDlg, IDC_JOIN), SW_NORMAL);
ShowWindow(GetDlgItem(hDlg, IDC_HOST), SW_NORMAL);
CheckDlgButton(hDlg, IDC_JOIN, (s_nNetJoinHost == NET_JOIN));
CheckDlgButton(hDlg, IDC_HOST, (s_nNetJoinHost == NET_HOST));
}
else
{
CheckDlgButton(hDlg, IDC_JOIN, (s_nInternalJoinHost == NET_JOIN));
CheckDlgButton(hDlg, IDC_HOST, (s_nInternalJoinHost == NET_HOST));
}
return(TRUE);
}
}
}
return(FALSE);
}
// ----------------------------------------------------------------------- //
// TCP/IP address dialog proc.
// ----------------------------------------------------------------------- //
BOOL CALLBACK IPDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch(uMsg)
{
case WM_INITDIALOG:
{
return 1;
}
case WM_COMMAND:
{
if (LOWORD(wParam) == IDOK)
{
char sIp[IPM_MAX_ADDRESS + 2];
GetDlgItemText(hDlg, IDC_IPADDRESS, sIp, IPM_MAX_ADDRESS);
s_IpMgr.AddIp(sIp);
EndDialog(hDlg, IDOK);
}
}
break;
}
return 0;
}
BOOL CALLBACK AddIPDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch(uMsg)
{
case WM_INITDIALOG:
{
return 1;
}
case WM_COMMAND:
{
if (LOWORD(wParam) == IDOK)
{
GetDlgItemText(hDlg, IDC_IPADDRESS, g_DlgIP, g_DlgIPLen);
EndDialog(hDlg, IDOK);
}
else if(LOWORD(wParam) == IDCANCEL)
{
EndDialog(hDlg, IDCANCEL);
}
}
break;
}
return 0;
}
// ----------------------------------------------------------------------- //
//
// ROUTINE: NetStart_FillSessionList
//
// PURPOSE: Fills a list box with the available sessions
//
// ----------------------------------------------------------------------- //
int NetStart_FillSessionList(HWND hDlg)
{
// Sanity checks...
if (!hDlg) return(0);
// Get our list box...
HWND hList = GetDlgItem(hDlg, IDC_SESSIONLIST);
if (!hList) return(0);
// Get the currently selected session (if any) so we can restore the selection...
char sSel[128];
int iSel = SendMessage(hList, LB_GETCURSEL, 0, 0);
if (iSel != LB_ERR)
{
SendMessage(hList, LB_GETTEXT, iSel, (LPARAM)sSel);
}
else
{
sSel[0] = '\0';
}
char *pInfo = "";
DDWORD flags;
DWORD i;
char tempIPText[256];
// If it's TCP/IP, ask the user for an address.
flags = GetSelectedServiceFlags();
if(flags & NETSERVICE_TCPIP)
{
g_DlgIP = tempIPText;
g_DlgIPLen = sizeof(tempIPText);
// Ask them for an address.
DialogBox(s_hInst, "NET_TCPIPADDRESS", hDlg, (DLGPROC)IPDlgProc);
pInfo = g_DlgIP;
}
// Get the session list...
NetSession* pCur = NULL;
NetSession* pListHead = NULL;
pListHead = NetStart_GetSessionList(s_pClient, pInfo);
if (!pListHead) return(0);
// Remove the current net games from the manager...
s_NinfoMgr.RemoveGames();
// Add each Session to the list box...
int c = 0;
SET_NODRAW(hList);
SendMessage(hList, LB_RESETCONTENT, 0, 0);
for (pCur=pListHead; pCur; pCur=pCur->m_pNext)
{
// Add a new net game via the manager...
CNinfoGame* pGame = s_NinfoMgr.AddGame(pCur->m_sName, pCur, pCur->m_dwCurPlayers);
if (pGame)
{
int iItem = SendMessage(hList, LB_ADDSTRING, 0, (LPARAM)(LPCSTR)pGame->GetName());
if (iItem != LB_ERR)
{
c++;
SendMessage(hList, LB_SETITEMDATA, iItem, (LPARAM)pGame->GetSessionPointer());
}
}
}
// Select the appropriate session in the list...
iSel = 0;
for (i = 0; i < (DWORD)c; i++)
{
char sText[128];
if (SendMessage(hList, LB_GETTEXT, i, (LPARAM)sText) != LB_ERR)
{
if (strcmp(sText, sSel) == 0)
{
iSel = i;
i = c;
}
}
}
SendMessage(hList, LB_SETCURSEL, iSel, 0);
SET_REDRAW(hList);
// Update the selected session info...
if (!NetStart_DisplaySelectedSessionInfo(hDlg))
{
NetStart_ClearSelectedSessionInfo(hDlg);
}
// All done...
return(c);
}
// ----------------------------------------------------------------------- //
//
// ROUTINE: NetStart_DisplaySelectedSessionInfo
//
// PURPOSE: Display information about the selected session
//
// ----------------------------------------------------------------------- //
BOOL NetStart_DisplaySelectedSessionInfo(HWND hDlg)
{
// Sanity checks...
if (!hDlg) return(FALSE);
// Get our list box...
HWND hList = GetDlgItem(hDlg, IDC_SESSIONLIST);
if (!hList) return(DFALSE);
// 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);
NetSession* pNetSession = (NetSession*)nRet;
if (!pNetSession) return(FALSE);
// Get the net game info object form the session handle...
CNinfoGame* pGame = s_NinfoMgr.GetGame(pNetSession);
if (!pGame) return(FALSE);
// Set all the info...
SetDlgItemText(hDlg, IDC_HOSTNAME, pGame->GetHost());
SetDlgItemText(hDlg, IDC_GAMETYPE, pGame->GetTypeString());
SetDlgItemText(hDlg, IDC_LEVEL, pGame->GetLevel());
int cPlayers = pGame->GetNumPlayers();
if (cPlayers == 0) cPlayers = pGame->GetNumDPlayPlayers();
SetDlgItemInt(hDlg, IDC_NUMPLAYERS, cPlayers, TRUE);
// Fill the player list...
hList = GetDlgItem(hDlg, IDC_PLAYERLIST);
if (!hList) return(DFALSE);
SET_NODRAW(hList)
SendMessage(hList, LB_RESETCONTENT, 0, 0);
CNinfoPlayer* pPlayer = pGame->GetFirstPlayer();
if (!pPlayer && cPlayers > 0)
{
SendMessage(hList, LB_ADDSTRING, 0, (LPARAM)(LPCSTR)s_sPlayerInfoNotSent);
}
while (pPlayer)
{
char sPlayer[256];
wsprintf(sPlayer, "%s\t%i", pPlayer->GetName(), pPlayer->GetFrags());
SendMessage(hList, LB_ADDSTRING, 0, (LPARAM)(LPCSTR)sPlayer);
pPlayer = pGame->GetNextPlayer();
}
SET_REDRAW(hList);
// All done...
return(TRUE);
}
// ----------------------------------------------------------------------- //
//
// ROUTINE: NetStart_ClearSelectedSessionInfo
//
// PURPOSE: Clears the information about the selected session
//
// ----------------------------------------------------------------------- //
BOOL NetStart_ClearSelectedSessionInfo(HWND hDlg)
{
// Sanity checks...
if (!hDlg) return(FALSE);
// Clear all the info...
SetDlgItemText(hDlg, IDC_HOSTNAME, "");
SetDlgItemText(hDlg, IDC_GAMETYPE, "");
SetDlgItemText(hDlg, IDC_LEVEL, "");
SetDlgItemText(hDlg, IDC_NUMPLAYERS, "");
// Clear the player list...
HWND hList = GetDlgItem(hDlg, IDC_PLAYERLIST);
if (!hList) return(DFALSE);
SendMessage(hList, LB_RESETCONTENT, 0, 0);
// All done...
return(TRUE);
}
// ----------------------------------------------------------------------- //
//
// ROUTINE: NetStart_JoinCurrentSession
//
// PURPOSE: Joins the currently selected Session in the list box
//
// ----------------------------------------------------------------------- //
BOOL NetStart_JoinCurrentSession(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);
NetSession* pNetSession = (NetSession*)nRet;
if (!pNetSession) return(FALSE);
// Select the Session by storing the handle in the NetStart structure...
s_pNetStart->m_pNetSession = pNetSession;
// All done...
return(TRUE);
}
// ----------------------------------------------------------------------- //
//
// ROUTINE: NetStart_JoinHost
//
// PURPOSE: Does the JOINHOST dialog
//
// ----------------------------------------------------------------------- //
BOOL CALLBACK NetDlg_JoinHost(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_INITDIALOG:
{
ForceActiveFocus(hDlg);
CheckDlgButton(hDlg, IDC_JOIN, (s_nNetJoinHost == NET_JOIN));
CheckDlgButton(hDlg, IDC_HOST, (s_nNetJoinHost == NET_HOST));
return(TRUE);
}
case WM_COMMAND:
{
if (NetStart_HandleDefaultDialogCommands(hDlg, wParam))
{
return(TRUE);
}
else if (wParam == IDC_NEXT)
{
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;
}
EndDialog(hDlg, DLG_NEXT);
return(TRUE);
}
}
}
return(FALSE);
}
// ----------------------------------------------------------------------- //
//
// ROUTINE: NetStart_HostSession
//
// PURPOSE: Hosts a new session
//
// ----------------------------------------------------------------------- //
BOOL NetStart_HostSession1(HWND hDlg)
{
// Sanity checks...
if (!hDlg) return(FALSE);
// Get the session name...
char sName[128];
sName[0] = '\0';
GetDlgItemText(hDlg, IDC_NAME, sName, 120);
if (strlen(sName) == 0)
{
if (strlen(s_sPlayerName) > 0)
{
wsprintf(sName, "%s with %s", s_sDefaultSessionName, s_sPlayerName);
}
else
{
strcpy(sName, s_sDefaultSessionName);
}
}
strcpy(s_sSessionName, sName);
// All done with part 1...
return(TRUE);
}
BOOL NetStart_HostSession2(HWND hDlg)
{
// Sanity checks...
if (!hDlg) return(FALSE);
// Create the big string with all the game parameters...
char sString[1024];
sString[0] = '\0';
if (!CNinfoMgr::CreateSessionString(sString, s_sSessionName, s_pNetStart->m_sPlayer, s_sFirstLevel, s_nGameType))
{
strcpy(sString, s_sSessionName);
}
// Fill out a NetHost structure in the NetStart structure...
memset(&s_pNetStart->m_NetHost, 0, sizeof(NetHost));
s_pNetStart->m_NetHost.m_dwMaxPlayers = s_nMaxPlayers;
strcpy(s_pNetStart->m_NetHost.m_sName, sString);
s_pNetStart->m_NetHost.m_Port = g_HostPort;
// All done...
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -