bool WorkingParameters::SetFTPInfo(LPCTSTR userName, LPCTSTR password) { TCHAR configFilePath[MAX_PATH]; GetModuleFileName(NULL, configFilePath, _countof(configFilePath)); PathRemoveFileSpec(configFilePath); PathAddBackslash(configFilePath); _tcscat(configFilePath, _T("FTPCONFIG.ini")); TCHAR serverIP[128]; GetPrivateProfileString(TEXT("Config"), TEXT("ServerIP"), NULL, serverIP, _countof(serverIP), configFilePath); int serverPort = GetPrivateProfileInt(TEXT("Config"), TEXT("ServerPort"), 21, configFilePath); FtpClient client; if (!client.Connect(serverIP, serverPort, userName, DecodePassword(password))) { return false; } else { WritePrivateProfileString(TEXT("Config"), TEXT("User"), CodePassword(userName), configFilePath); WritePrivateProfileString(TEXT("Config"), TEXT("Password"), password, configFilePath); WritePrivateProfileString(TEXT("Upload"), TEXT("User"), CodePassword(userName), configFilePath); WritePrivateProfileString(TEXT("Upload"), TEXT("Password"), password, configFilePath); return true; } }
void WriteGameSetup(int32_t scripthandle) { int dummy; dummy = gs.BorderNum; SCRIPT_PutNumber(scripthandle, "Options", "BorderNum",dummy,FALSE,FALSE); dummy = gs.Brightness; SCRIPT_PutNumber(scripthandle, "Options", "Brightness",dummy,FALSE,FALSE); dummy = gs.BorderTile; SCRIPT_PutNumber(scripthandle, "Options", "BorderTile",dummy,FALSE,FALSE); dummy = gs.Bobbing; SCRIPT_PutNumber(scripthandle, "Options", "Bobbing",dummy,FALSE,FALSE); dummy = gs.Tilting; SCRIPT_PutNumber(scripthandle, "Options", "Tilting",dummy,FALSE,FALSE); dummy = gs.Shadows; SCRIPT_PutNumber(scripthandle, "Options", "Shadows",dummy,FALSE,FALSE); dummy = gs.AutoRun; SCRIPT_PutNumber(scripthandle, "Options", "AutoRun",dummy,FALSE,FALSE); dummy = gs.Crosshair; SCRIPT_PutNumber(scripthandle, "Options", "Crosshair",dummy,FALSE,FALSE); dummy = gs.AutoAim; SCRIPT_PutNumber(scripthandle, "Options", "AutoAim",dummy,FALSE,FALSE); dummy = gs.Messages; SCRIPT_PutNumber(scripthandle, "Options", "Messages",dummy,FALSE,FALSE); dummy = gs.Talking; SCRIPT_PutNumber(scripthandle, "Options", "Talking",dummy,FALSE,FALSE); dummy = gs.Ambient; SCRIPT_PutNumber(scripthandle, "Options", "Ambient",dummy,FALSE,FALSE); dummy = gs.FxOn; SCRIPT_PutNumber(scripthandle, "Options", "FxOn",dummy,FALSE,FALSE); dummy = gs.MouseAimingType; SCRIPT_PutNumber(scripthandle, "Controls", "MouseAiming",dummy,FALSE,FALSE); dummy = gs.MusicOn; SCRIPT_PutNumber(scripthandle, "Options", "MusicOn",dummy,FALSE,FALSE); dummy = gs.NetGameType; SCRIPT_PutNumber(scripthandle, "Options", "NetGameType",dummy,FALSE,FALSE); dummy = gs.NetLevel; SCRIPT_PutNumber(scripthandle, "Options", "NetLevel",dummy,FALSE,FALSE); dummy = gs.NetMonsters; SCRIPT_PutNumber(scripthandle, "Options", "NetMonsters",dummy,FALSE,FALSE); dummy = gs.NetHurtTeammate; SCRIPT_PutNumber(scripthandle, "Options", "NetHurtTeammate",dummy,FALSE,FALSE); dummy = gs.NetSpawnMarkers; SCRIPT_PutNumber(scripthandle, "Options", "NetSpawnMarkers",dummy,FALSE,FALSE); dummy = gs.NetTeamPlay; SCRIPT_PutNumber(scripthandle, "Options", "NetTeamPlay",dummy,FALSE,FALSE); dummy = gs.NetKillLimit; SCRIPT_PutNumber(scripthandle, "Options", "NetKillLimit",dummy,FALSE,FALSE); dummy = gs.NetTimeLimit; SCRIPT_PutNumber(scripthandle, "Options", "NetTimeLimit",dummy,FALSE,FALSE); dummy = gs.NetColor; SCRIPT_PutNumber(scripthandle, "Options", "NetColor",dummy,FALSE,FALSE); dummy = gs.Voxels; SCRIPT_PutNumber(scripthandle, "Options", "Voxels",dummy,FALSE,FALSE); dummy = gs.MouseAimingOn; SCRIPT_PutNumber(scripthandle, "Options", "MouseAimingOn",dummy,FALSE,FALSE); dummy = gs.MouseInvert; SCRIPT_PutNumber(scripthandle, "Options", "MouseInvert",dummy,FALSE,FALSE); dummy = gs.Stats; SCRIPT_PutNumber(scripthandle, "Options", "Stats",dummy,FALSE,FALSE); EncodePassword(gs.Password); SCRIPT_PutString(scripthandle, "Options","Rooster",gs.Password); DecodePassword(gs.Password); dummy = gs.ParentalLock; SCRIPT_PutNumber(scripthandle, "Options", "Kiwi",dummy,FALSE,FALSE); dummy = gs.PlayCD; SCRIPT_PutNumber(scripthandle, "Options", "PlayCD",dummy,FALSE,FALSE); SCRIPT_PutNumber(scripthandle, "Options", "CDDevice",0,FALSE,FALSE); if (SW_SHAREWARE) { dummy = GamePlays; SCRIPT_PutNumber(scripthandle, "Options", "Chickens",dummy,FALSE,FALSE); } }
void ReadGameSetup(int32_t scripthandle) { int dummy; int ret; extern char WangBangMacro[10][64]; for (dummy = 0; dummy < 10; dummy++) { sprintf(ds,"CommbatMacro#%d",dummy); SCRIPT_GetString(scripthandle, "Comm Setup",ds,WangBangMacro[dummy]); } SCRIPT_GetString(scripthandle, "Options","Rooster",gs.Password); DecodePassword(gs.Password); // option stuff dummy = -1; ret = SCRIPT_GetNumber(scripthandle, "Options", "BorderNum",&dummy); if (dummy != -1) gs.BorderNum = dummy; dummy = -1; SCRIPT_GetNumber(scripthandle, "Options", "Brightness",&dummy); if (dummy != -1) gs.Brightness = dummy; dummy = -1; SCRIPT_GetNumber(scripthandle, "Options", "BorderTile",&dummy); if (dummy != -1) gs.BorderTile = dummy; dummy = -1; SCRIPT_GetNumber(scripthandle, "Options", "Bobbing",&dummy); if (dummy != -1) gs.Bobbing = dummy; dummy = -1; SCRIPT_GetNumber(scripthandle, "Options", "Tilting",&dummy); if (dummy != -1) gs.Tilting = dummy; dummy = -1; SCRIPT_GetNumber(scripthandle, "Options", "Shadows",&dummy); if (dummy != -1) gs.Shadows = dummy; dummy = -1; SCRIPT_GetNumber(scripthandle, "Options", "AutoRun",&dummy); if (dummy != -1) gs.AutoRun = dummy; dummy = -1; SCRIPT_GetNumber(scripthandle, "Options", "Crosshair",&dummy); if (dummy != -1) gs.Crosshair = dummy; dummy = -1; SCRIPT_GetNumber(scripthandle, "Options", "AutoAim",&dummy); if (dummy != -1) gs.AutoAim = dummy; dummy = -1; SCRIPT_GetNumber(scripthandle, "Options", "Messages",&dummy); if (dummy != -1) gs.Messages = dummy; dummy = -1; SCRIPT_GetNumber(scripthandle, "Options", "Talking",&dummy); if (dummy != -1) gs.Talking = dummy; dummy = -1; SCRIPT_GetNumber(scripthandle, "Options", "Ambient",&dummy); if (dummy != -1) gs.Ambient = dummy; dummy = -1; SCRIPT_GetNumber(scripthandle, "Options", "FxOn",&dummy); if (dummy != -1) gs.FxOn = dummy; dummy = -1; SCRIPT_GetNumber(scripthandle, "Options", "MusicOn",&dummy); if (dummy != -1) gs.MusicOn = dummy; dummy = -1; SCRIPT_GetNumber(scripthandle, "Controls", "MouseAiming",&dummy); if (dummy != -1) gs.MouseAimingType = dummy; dummy = -1; SCRIPT_GetNumber(scripthandle, "Options", "NetGameType",&dummy); if (dummy != -1) gs.NetGameType = dummy; dummy = -1; SCRIPT_GetNumber(scripthandle, "Options", "NetLevel",&dummy); if (dummy != -1) gs.NetLevel = dummy; dummy = -1; SCRIPT_GetNumber(scripthandle, "Options", "NetMonsters",&dummy); if (dummy != -1) gs.NetMonsters = dummy; dummy = -1; SCRIPT_GetNumber(scripthandle, "Options", "NetHurtTeammate",&dummy); if (dummy != -1) gs.NetHurtTeammate = dummy; dummy = -1; SCRIPT_GetNumber(scripthandle, "Options", "NetSpawnMarkers",&dummy); if (dummy != -1) gs.NetSpawnMarkers = dummy; dummy = -1; SCRIPT_GetNumber(scripthandle, "Options", "NetTeamPlay",&dummy); if (dummy != -1) gs.NetTeamPlay = dummy; dummy = -1; SCRIPT_GetNumber(scripthandle, "Options", "NetKillLimit",&dummy); if (dummy != -1) gs.NetKillLimit = dummy; dummy = -1; SCRIPT_GetNumber(scripthandle, "Options", "NetTimeLimit",&dummy); if (dummy != -1) gs.NetTimeLimit = dummy; dummy = -1; SCRIPT_GetNumber(scripthandle, "Options", "NetColor",&dummy); if (dummy != -1) gs.NetColor = dummy; dummy = -1; SCRIPT_GetNumber(scripthandle, "Options", "Voxels",&dummy); if (dummy != -1) gs.Voxels = dummy; dummy = -1; SCRIPT_GetNumber(scripthandle, "Options", "Stats",&dummy); if (dummy != -1) gs.Stats = dummy; dummy = -1; SCRIPT_GetNumber(scripthandle, "Options", "MouseAimingOn",&dummy); if (dummy != -1) gs.MouseAimingOn = dummy; dummy = -1; SCRIPT_GetNumber(scripthandle, "Options", "MouseInvert",&dummy); if (dummy != -1) gs.MouseInvert = dummy; dummy = -1; SCRIPT_GetNumber(scripthandle, "Options", "Kiwi",&dummy); if (dummy != -1) gs.ParentalLock = dummy; dummy = -1; SCRIPT_GetNumber(scripthandle, "Options", "PlayCD",&dummy); if (dummy != -1) gs.PlayCD = dummy; dummy = -1; SCRIPT_GetNumber(scripthandle, "Options", "CDDevice",&dummy); if (dummy < 0) dummy = -1; if (SW_SHAREWARE) { dummy = -1; SCRIPT_GetNumber(scripthandle, "Options", "Chickens",&dummy); if (dummy != -1) GamePlays = dummy; buildprintf( "\n" "You have played Shadow Warrior %d times. Please call and order the full\n" "version at 1(800)-3DREALMS or see the ORDER.FRM file.\n\n" ,GamePlays); GamePlays++; } }
bool WorkingParameters::LoadConfigFromServer() { LastErrorHolder errorHolder; TCHAR configFilePath[MAX_PATH]; GetModuleFileName(NULL, configFilePath, _countof(configFilePath)); PathRemoveFileSpec(configFilePath); PathAddBackslash(configFilePath); _tcscat(configFilePath, _T("FTPCONFIG.ini")); TCHAR serverIP[128]; GetPrivateProfileString(TEXT("Config"), TEXT("ServerIP"), NULL, serverIP, _countof(serverIP), configFilePath); int serverPort = GetPrivateProfileInt(TEXT("Config"), TEXT("ServerPort"), 21, configFilePath); TCHAR userName[128]; GetPrivateProfileString(TEXT("Config"), TEXT("User"), NULL, userName, _countof(userName), configFilePath); TCHAR password[128]; GetPrivateProfileString(TEXT("Config"), TEXT("Password"), NULL, password, _countof(password), configFilePath); FtpClient client; if (!client.Connect(serverIP, serverPort, DecodePassword(userName), DecodePassword(password))) { errorHolder.SaveLastError(); return false; } TCHAR appConfigPath[MAX_PATH]; GetAppDataPath(appConfigPath); PathAddBackslash(appConfigPath); _tcscat(appConfigPath, _T("config")); if (!CreateDirectoryRecusively(appConfigPath)) { errorHolder.SaveLastError(); return false; } PathAddBackslash(appConfigPath); TCHAR remoteTerminalPath[MAX_PATH]; GetPrivateProfileString(TEXT("Config"), TEXT("RemoteTerminalPath"), NULL, remoteTerminalPath, _countof(remoteTerminalPath), configFilePath); // 获取机器识别码 lux TCHAR id[200] = { 0 }; GetTerminalID(id); // 将机器识别码写入配置文件中,方便查询 WritePrivateProfileString(TEXT("Config"), TEXT("TerminalID"), id, configFilePath); // 根据设备唯一识别码下载相应可变配置文件 lux // 为了防止因服务器下载失败而清除本地配置文件,以临时文件的形式先保存,下载成功以后再覆盖原文件 TCHAR tempFilePath[MAX_PATH]; GetTempPath(_countof(tempFilePath), tempFilePath); GetTempFileName(tempFilePath, _T("~"), 0, tempFilePath); TCHAR remoteConfigFilePath[MAX_PATH]; _tcscpy(remoteConfigFilePath, remoteTerminalPath); _tcscat(remoteConfigFilePath, id); _tcscat(remoteConfigFilePath, _T(".ini")); if (!client.GetFile(remoteConfigFilePath, tempFilePath)) { errorHolder.SaveLastError(); return false; } TCHAR localConfigFilePath[MAX_PATH]; _tcscpy(localConfigFilePath, appConfigPath); _tcscat(localConfigFilePath, _T("model.ini")); BOOL bMoveSuccess = MoveFileEx(tempFilePath, localConfigFilePath, MOVEFILE_COPY_ALLOWED + MOVEFILE_REPLACE_EXISTING); if (bMoveSuccess) { DeleteFile(tempFilePath); } else { DeleteFile(tempFilePath); return false; } if (!LoadConfig()) { errorHolder.SaveLastError(); return false; } return true; }
bool WorkingParameters::LoadFromServer() { LastErrorHolder errorHolder; TCHAR configFilePath[MAX_PATH]; GetModuleFileName(NULL, configFilePath, _countof(configFilePath)); PathRemoveFileSpec(configFilePath); PathAddBackslash(configFilePath); _tcscat(configFilePath, _T("FTPCONFIG.ini")); TCHAR serverIP[128]; GetPrivateProfileString(TEXT("Config"), TEXT("ServerIP"), NULL, serverIP, _countof(serverIP), configFilePath); int serverPort = GetPrivateProfileInt(TEXT("Config"), TEXT("ServerPort"), 21, configFilePath); TCHAR userName[128]; GetPrivateProfileString(TEXT("Config"), TEXT("User"), NULL, userName, _countof(userName), configFilePath); TCHAR password[128]; GetPrivateProfileString(TEXT("Config"), TEXT("Password"), NULL, password, _countof(password), configFilePath); TCHAR remotePath[MAX_PATH]; GetPrivateProfileString(TEXT("Config"), TEXT("RemotePath"), NULL, remotePath, _countof(remotePath), configFilePath); FtpClient client; if (!client.Connect(serverIP, serverPort, DecodePassword(userName), DecodePassword(password))) { errorHolder.SaveLastError(); return false; } TCHAR appConfigPath[MAX_PATH]; GetAppDataPath(appConfigPath); PathAddBackslash(appConfigPath); _tcscat(appConfigPath, _T("config")); if (!CreateDirectoryRecusively(appConfigPath)) { errorHolder.SaveLastError(); return false; } PathAddBackslash(appConfigPath); TCHAR remoteManifestFilePath[MAX_PATH]; _tcscpy(remoteManifestFilePath, remotePath); _tcscat(remoteManifestFilePath, _T("manifest.xml")); TCHAR localManifestFilePath[MAX_PATH]; _tcscpy(localManifestFilePath, appConfigPath); _tcscat(localManifestFilePath, _T("manifest.xml")); if (!client.GetFile(remoteManifestFilePath, localManifestFilePath)) { errorHolder.SaveLastError(); return false; } if (!LoadXML()) { errorHolder.SaveLastError(); return false; } if (!theApp.IsSkipUpdate()) { ParameterBlock verBlock = SelectBlock(_T("Application\\LastVersion")); if (!verBlock.IsNull()) { CString lastVersion = verBlock.GetStringParameter(_T("version"), NULL); // 当且仅当服务器版本号高于当前版本号时才升级 int lastV1, lastV2, lastV3, lastV4; lastV1 = lastV2 = lastV3 = lastV4 = 999; swscanf(lastVersion, _T("%d.%d.%d.%d"), &lastV1, &lastV2, &lastV3, &lastV4); CString curVersion = AfxGetApp()->GetProfileString(_T(""), _T("Version")); int curV1, curV2, curV3, curV4; curV1 = curV2 = curV3 = curV4 = 0; swscanf(curVersion, _T("%d.%d.%d.%d"), &curV1, &curV2, &curV3, &curV4); bool skip = false; if ((lastV1 * 1000 + lastV2 * 100 + lastV3 * 10 + lastV4) > (curV1 * 1000 + curV2 * 100 + curV3 * 10 + curV4)) { //if (lastVersion != AfxGetApp()->GetProfileString(_T(""), _T("Version"))) { CString remotePath = verBlock.GetStringParameter(_T("path"), NULL); TCHAR updateFilePath[MAX_PATH]; _tcscpy(updateFilePath, appConfigPath); _tcscat(updateFilePath, _T("app_update.dat")); if (!client.GetFile(remotePath, updateFilePath)) { errorHolder.SaveLastError(); return false; } appUpdated_ = true; appUpdateFilePath_ = updateFilePath; lastAppVersion_ = lastVersion; } } } // update fireware files from server. ParameterBlock deviceBlock = SelectBlock(_T("Device")); if (deviceBlock.IsNull()) { errorHolder.SetError(ERROR_SERVER_CONFIG); return false; } ParameterBlock modelBlock = deviceBlock.GetFirstChildBlock(); if (modelBlock.IsNull()) { errorHolder.SetError(ERROR_SERVER_CONFIG); return false; } for (; !modelBlock.IsNull(); modelBlock = modelBlock.GetNextBlock()) { if (modelBlock.GetName() == _T("Model")) { int id = modelBlock.GetIntParameter(_T("id"), -1); if (id == -1) { errorHolder.SetError(ERROR_SERVER_CONFIG); return false; } CString localFirewarePath(appConfigPath); localFirewarePath.AppendFormat(_T("firmware_%d.dat"), id); ParameterBlock firmwareBlock = modelBlock.SelectBlock(_T("Firmware")); if (firmwareBlock.IsNull()) { errorHolder.SetError(ERROR_SERVER_CONFIG); return false; } bool getFile = true; CString remoteCheckSum = firmwareBlock.GetStringParameter(_T("checkSum"), NULL); CString localCheckSum; if (!remoteCheckSum.IsEmpty() && MD5::CalcFile(localFirewarePath, &localCheckSum)) { getFile = (remoteCheckSum != localCheckSum); } if (getFile) { CString path = firmwareBlock.GetStringParameter(_T("path"), NULL); if (!client.GetFile(path, localFirewarePath)) { errorHolder.SaveLastError(); return false; } } } } return true; }