📄 netstart.cpp
字号:
if (!hDlg) return(FALSE);
SetDlgItemInt(hDlg, IDC_MAXPLAYERS, s_nMaxPlayers, FALSE);
SetDlgItemInt(hDlg, IDC_FRAGS, s_nEndFrags, FALSE);
SetDlgItemInt(hDlg, IDC_MINUTES, s_nEndTime, FALSE);
CheckDlgButton(hDlg, IDC_AFTERFRAGS, ((s_nEndType == NGE_FRAGS) || (s_nEndType == NGE_FRAGSANDTIME)) ? BST_CHECKED : BST_UNCHECKED);
CheckDlgButton(hDlg, IDC_AFTERMINUTES, ((s_nEndType == NGE_TIME) || (s_nEndType == NGE_FRAGSANDTIME)) ? BST_CHECKED : BST_UNCHECKED);
return(TRUE);
}
// ----------------------------------------------------------------------- //
//
// ROUTINE: SaveLevelStrings
//
// PURPOSE: Saves all the level strings to the registry
//
// ----------------------------------------------------------------------- //
void SaveLevelStrings()
{
// Save the levels...
POSITION pos = s_collLevels.GetHeadPosition();
int count = 0;
while (pos)
{
CString sRez = s_collLevels.GetNext(pos);
if (!sRez.IsEmpty())
{
char sLabel[32];
wsprintf(sLabel, "Level%i", count);
SetGameVar(sLabel, sRez);
count++;
}
}
// Write out the level count...
SetGameVar("NumLevels", count);
}
// ----------------------------------------------------------------------- //
//
// ROUTINE: LoadLevelStrings
//
// PURPOSE: Loads all the level strings from the registry
//
// ----------------------------------------------------------------------- //
void LoadLevelStrings()
{
// Load the level count...
int count = 0;
NS_GetGameVar("NumLevels", count);
// Load the strings...
s_collLevels.RemoveAll();
for (int i = 0; i < count; i++)
{
char sLabel[32];
char sLevel[128];
wsprintf(sLabel, "Level%i", i);
strcpy(sLevel, "");
NS_GetGameVar(sLabel, sLevel, 120);
if (sLevel[0] != '\0')
{
s_collLevels.AddTail(sLevel);
}
}
}
// ----------------------------------------------------------------------- //
//
// ROUTINE: NetStart_GoNoDialogs
//
// PURPOSE: Sets everything up using saved values instead of dialogs
//
// ----------------------------------------------------------------------- //
BOOL NetStart_GoNoDialogs(ServerInfo* pServerInfo, NetGame* pNetGame)
{
// Sanity checks...
if (!pServerInfo) return(FALSE);
if (!pNetGame) return(FALSE);
// Make sure we have a service name...
if (strlen(s_sServiceName) <= 0) return(FALSE);
// Make sure we have some levels...
if (s_collLevels.GetCount() <= 0) return(FALSE);
// Get the service list...
NetService *pCur, *pListHead = NULL;
BOOL bRet = s_pServerMgr->GetServiceList(pListHead);
if (!bRet) return(FALSE);
if (!pListHead)
{
return(FALSE);
}
// Find the service we want...
int nIndex = -1;
NetService *pFound = NULL;
for (pCur=pListHead; pCur; pCur=pCur->m_pNext)
{
if (stricmp(pCur->m_sName, s_sServiceName) == 0)
{
pFound = pCur;
break;
}
}
if (!pFound)
{
s_pServerMgr->FreeServiceList(pListHead);
return(FALSE);
}
NetService* pService = pFound;
HNETSERVICE hNetService = pService->m_handle;
s_pServerMgr->FreeServiceList(pListHead);
// Select the service...
bRet = s_pServerMgr->SelectService(hNetService);
if (!bRet) return(FALSE);
strcpy(s_pServerInfo->m_sService, s_sServiceName);
strlwr(s_pServerInfo->m_sService);
if (strstr(s_pServerInfo->m_sService, "ipx")) strcpy(s_pServerInfo->m_sService, "Ipx");
else if (strstr(s_pServerInfo->m_sService, "tcp")) strcpy(s_pServerInfo->m_sService, "Tcp/ip");
else if (strstr(s_pServerInfo->m_sService, "modem")) strcpy(s_pServerInfo->m_sService, "Modem");
else if (strstr(s_pServerInfo->m_sService, "serial")) strcpy(s_pServerInfo->m_sService, "Serial Cable");
// Fill in the update options...
pServerInfo->m_bUpdateGameInfo = s_bUpdateInfo;
pServerInfo->m_bRegisterServer = s_bServerReg;
pServerInfo->m_bUseGameSpy = s_bUseGameSpy;
// Set the server name...
strcpy(pServerInfo->m_sName, s_sServerName);
// Get the max players...
pServerInfo->m_dwMaxPlayers = s_nMaxPlayers;
// Set the game end info...
pNetGame->m_byType = s_nGameType;
pNetGame->m_byEnd = s_nEndType;
pNetGame->m_dwEndTime = s_nEndTime;
pNetGame->m_dwEndFrags = s_nEndFrags;
// Set the other game options...
pNetGame->m_nAmmoLevel = s_nAmmoLevel;
pNetGame->m_nAmmoRespawn = s_nAmmoRespawn;
pNetGame->m_nArmorLevel = s_nArmorLevel;
pNetGame->m_nArmorRespawn = s_nArmorRespawn;
pNetGame->m_nHealthLevel = s_nHealthLevel;
pNetGame->m_nHealthRespawn = s_nHealthRespawn;
pNetGame->m_nPowerupsLevel = s_nPowerupsLevel;
pNetGame->m_nPowerupsRespawn = s_nPowerupsRespawn;
pNetGame->m_nHealingRate = s_nHealingRate;
pNetGame->m_bFallDamage = s_bFallDamage;
pNetGame->m_bFriendlyFire = s_bFriendlyFire;
pNetGame->m_bNegTeamFrags = s_bNegTeamFrags;
pNetGame->m_bOnlyFlagScores = s_bOnlyFlagScores;
pNetGame->m_bOnlyGoalScores = s_bOnlyGoalScores;
pNetGame->m_bUseTeamSize = s_bUseTeamSize;
pNetGame->m_nFlagValue = s_nFlagValue;
pNetGame->m_nGoalValue = s_nGoalValue;
pNetGame->m_nSocBallSkin = s_nSocBallSkin;
// Add the resources...
if (!GetTheApp()->AddResources(s_collRezFiles))
{
return(FALSE);
}
// Add each level from our collection...
pNetGame->m_byNumLevels = 0;
for (int j = 0; j < MAX_GAME_LEVELS; j++) s_pNetGame->m_sLevels[j][0] = '\0';
int nCount = s_collLevels.GetCount();
POSITION pos = s_collLevels.GetHeadPosition();
if (!pos) return(FALSE);
while (pos)
{
CString sLevel = s_collLevels.GetNext(pos);
strcpy(pNetGame->m_sLevels[pNetGame->m_byNumLevels], sLevel);
pNetGame->m_byNumLevels++;
}
// All done...
return(TRUE);
}
// ----------------------------------------------------------------------- //
//
// ROUTINE: NetStart_RezFiles
//
// PURPOSE: Does the REZFILES dialog
//
// ----------------------------------------------------------------------- //
BOOL CALLBACK NetDlg_RezFiles(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_INITDIALOG:
{
SetIcon(hDlg);
ForceActiveFocus(hDlg);
if (FillAvailableRez(GetDlgItem(hDlg, IDC_SOURCELIST)) <= 0)
{
EndDialog(hDlg, DLG_NEXT);
}
FillSelectedRez(GetDlgItem(hDlg, IDC_DESTLIST));
return(TRUE);
}
case WM_COMMAND:
{
if (NetStart_HandleDefaultDialogCommands(hDlg, wParam))
{
KillTimer(hDlg, 1);
return(TRUE);
}
else if (wParam == IDC_NEXT)
{
AddSelectedToList(GetDlgItem(hDlg, IDC_DESTLIST));
SaveRezStrings();
EndDialog(hDlg, DLG_NEXT);
return(TRUE);
}
else if (wParam == IDC_ADD)
{
AddSelectedRez(GetDlgItem(hDlg, IDC_SOURCELIST), GetDlgItem(hDlg, IDC_DESTLIST));
UpdateRezControls(hDlg);
}
else if (wParam == IDC_REMOVE)
{
RemoveSelectedRez(GetDlgItem(hDlg, IDC_SOURCELIST), GetDlgItem(hDlg, IDC_DESTLIST));
UpdateRezControls(hDlg);
}
else if (HIWORD(wParam) == LBN_SELCHANGE)
{
UpdateRezControls(hDlg);
}
else if (HIWORD(wParam) == LBN_DBLCLK)
{
if (LOWORD(wParam) == IDC_SOURCELIST)
{
AddSelectedRez(GetDlgItem(hDlg, IDC_SOURCELIST), GetDlgItem(hDlg, IDC_DESTLIST));
UpdateRezControls(hDlg);
}
else if (LOWORD(wParam) == IDC_DESTLIST)
{
RemoveSelectedRez(GetDlgItem(hDlg, IDC_SOURCELIST), GetDlgItem(hDlg, IDC_DESTLIST));
UpdateRezControls(hDlg);
}
}
}
}
return(FALSE);
}
// ----------------------------------------------------------------------- //
//
// ROUTINE: FillAvailableRez
//
// PURPOSE: Fills the given list box with the available rez files
//
// ----------------------------------------------------------------------- //
int FillAvailableRez(HWND hList)
{
// Remove the current list contents...
if (hList) SendMessage(hList, LB_RESETCONTENT, 0, 0);
// Change to the "custom" direcotry...
if (chdir("Custom") != 0) return(0);
// Enumerate the available rez files and add them to the list box...
int count = 0;
long hFile;
struct _finddata_t fd;
hFile = _findfirst("*.rez", &fd);
if (hFile == -1)
{
chdir ("..");
return(0);
}
if (hList) SendMessage(hList, LB_ADDSTRING, 0, (LPARAM)(LPCSTR)fd.name);
count++;
BOOL bContinue = TRUE;
while (bContinue)
{
if (_findnext(hFile, &fd) != 0)
{
bContinue = FALSE;
}
else
{
if (hList) SendMessage(hList, LB_ADDSTRING, 0, (LPARAM)(LPCSTR)fd.name);
count++;
}
}
// Restore the directory...
chdir ("..");
// All done...
return(count);
}
// ----------------------------------------------------------------------- //
//
// ROUTINE: FillSelectedRez
//
// PURPOSE: Fills the given list box with the selected rez files
//
// ----------------------------------------------------------------------- //
int FillSelectedRez(HWND hList)
{
// Sanity checks...
if (!hList) return(0);
// Remove the current list contents...
SendMessage(hList, LB_RESETCONTENT, 0, 0);
// Enumerate the selected rez files and add them to the list box...
POSITION pos = s_collRezFiles.GetHeadPosition();
int count = 0;
while (pos)
{
CString sRez = s_collRezFiles.GetNext(pos);
char sTemp[128];
strncpy(sTemp, sRez, 125);
strupr(sTemp);
if (strncmp(sTemp, "CUSTOM\\", 7) == 0)
{
strncpy(sTemp, sRez, 125);
sRez = &sTemp[7];
}
SendMessage(hList, LB_ADDSTRING, 0, (LPARAM)(LPCSTR)sRez);
count++;
}
// All done...
return(count);
}
// ----------------------------------------------------------------------- //
//
// ROUTINE: AddSelectedRez
//
// PURPOSE: Adds the selected source rez to the dest list
//
// ----------------------------------------------------------------------- //
BOOL AddSelectedRez(HWND hSourceList, HWND hDestList)
{
// Sanity checks...
if (!hSourceList) return(FALSE);
if (!hDestList) return(FALSE);
// Get the selected item from the source list...
int nIndex = SendMessage(hSourceList, LB_GETCURSEL, 0, 0);
if (nIndex == LB_ERR) return(FALSE);
char sRez[256];
int nRet = SendMessage(hSourceList, LB_GETTEXT, nIndex, (LPARAM)(LPCSTR)sRez);
if (nRet == LB_ERR) return(FALSE);
// Check if this rez is already selected...
if (IsRezSelected(hDestList, sRez))
{
return(TRUE);
}
// Add the selected string to our list...
nRet = SendMessage(hDestList, LB_ADDSTRING, 0, (LPARAM)(LPCSTR)sRez);
if (nRet == LB_ERR) return(FALSE);
// All done...
return(TRUE);
}
// ----------------------------------------------------------------------- //
//
// ROUTINE: RemoveSelectedRez
//
// PURPOSE: Removes the selected dest rez to the dest list
//
// ----------------------------------------------------------------------- //
BOOL RemoveSelectedRez(HWND hSourceList, HWND hDestList)
{
// Sanity checks...
if (!hSourceList) return(FALSE);
if (!hDestList) return(FALSE);
// Get the selected rez in the dest list...
int nIndex = SendMessage(hDestList, LB_GETCURSEL, 0, 0);
if (nIndex == LB_ERR) return(FALSE);
// Remove the current item from the dest list...
int nRet = SendMessage(hDestList, LB_DELETESTRING, nIndex, 0);
if (!nRet == LB_ERR) return(FALSE);
// Try to select the previous item...
nRet = SendMessage(hDestList, LB_SETCURSEL, nIndex, 0);
if (nRet == LB_ERR && nIndex > 0)
{
SendMessage(hDestList, LB_SETCURSEL, nIndex-1, 0);
}
// All done...
return(TRUE);
}
// ----------------------------------------------------------------------- //
//
// ROUTINE: IsRezSelected
//
// PURPOSE: Determines if the given rez is in the dest list
//
// ----------------------------------------------------------------------- //
BOOL IsRezSelected(HWND hDestList, const char* sRez)
{
// Sanity checks...
if (!hDestList) return(FALSE);
if (!sRez) return(FALSE);
// Look for this string in the list...
int nCount = SendMessage(hDestList, LB_GETCOUNT, 0, 0);
if (nCount == LB_ERR) return(FALSE);
for (int i = 0; i < nCount; i++)
{
char sText[256];
int nRet = SendMessage(hDestList, LB_GETTEXT, i, (LPARAM)(LPSTR)sText);
if (nRet != LB_ERR)
{
if (strcmp(sRez, sText) == 0) return(TRUE);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -