Example #1
0
void CInput::ProcessInput(CString strInput)
{
	// Get the command and parameters
	size_t sSplit = strInput.Find(' ', 0);
	CString strCommand = strInput.Substring(0, sSplit++);
	CString strParameters = strInput.Substring(sSplit, (strInput.GetLength() - sSplit));

	if(strCommand.IsEmpty())
		return;
	else if(strCommand == "quit" || strCommand == "Quit" || strCommand == "exit") {
		CLogFile::Print("[Server] Server is going to shutdown NOW ....");
		g_bClose = true;
		return;

	} else if(strCommand == "help" || strCommand == "?" || strCommand == "--usage") {
		printf("========== Available console commands: ==========\n");
		printf("say <text>\n");
		printf("uptime\n");
		printf("resources\n");
		printf("players\n");
		printf("loadresource <name>\n");
		printf("reloadresource <name>\n");
		printf("unloadresource <name>\n");
		printf("exit\n");
		return;
	}
	else if (strCommand == "setSyncRate") {
		int rate = atoi(strParameters.Get());
		CServer::GetInstance()->SetSyncRate(rate);
	}
	else if (strCommand == "setMaxFPS") {
		int fps = atoi(strParameters.Get());
		CServer::GetInstance()->SetMaximumFPS(fps);
	}
}
Example #2
0
rc_t CKDirectory::CheckAccess(const CString &path,
    bool &updated, bool isPrivate, bool verbose) const
{
    updated = false;
    const String *str = path.Get();
    if (str == NULL) {
        return 0;
    }
    uint32_t access = 0;
    if (verbose) {
        OUTMSG(("checking %S file mode... ", path.Get()));
    }
    rc_t rc = KDirectoryAccess(m_Self, &access, str->addr);
    if (rc != 0) {
        OUTMSG(("failed\n"));
    }
    else {
        if (verbose) {
            OUTMSG(("%o\n", access));
        }
        if (isPrivate) {
            if (access != m_PrivateAccess) {
                uint32_t access = 0777;
                if (verbose) {
                    OUTMSG(("updating %S to %o... ", str, access));
                }
                rc = KDirectorySetAccess(m_Self, false,
                    m_PrivateAccess, access, str->addr);
                if (rc == 0) {
                    OUTMSG(("ok\n"));
                    updated = true;
                }
                else {
                    OUTMSG(("failed\n"));
                }
            }
        }
        else {
            if ((access & m_PrivateAccess) != m_PrivateAccess) {
                uint32_t access = 0700;
                if (verbose) {
                    OUTMSG(("updating %S to %o... ", str, access));
                }
                rc = KDirectorySetAccess(m_Self, false,
                    m_PrivateAccess, access, str->addr);
                if (rc == 0) {
                    OUTMSG(("ok\n"));
                    updated = true;
                }
                else {
                    OUTMSG(("failed\n"));
                }
            }
        }
    }
    return rc;
}
const char *getValue<const char *>(CScriptVM* pVM, int idx)
{
	CString str;
	pVM->SetStackIndex(idx - (pVM->GetVMType() == LUA_VM ? 0 : 1));
	pVM->Pop(str);
	return str.Get();
}
Example #4
0
bool CKDirectory::Exists(const CString &path) const {
    const String *str = path.Get();

    if (str == NULL) {
        return false;
    }
    return Exists(str->addr);
}
Example #5
0
rc_t CKConfig::UpdateUserRepositoryRootPath(const CString &path) {
    const String *str = path.Get();

    if (str == NULL) {
        return 0;
    }
    return UpdateUserRepositoryRootPath(str->addr, str->size);
}
Example #6
0
rc_t CKDirectory::CreateNonExistingDir(const CString &path,
    uint32_t access, bool verbose) const
{
    const String *str = path.Get();
    if (str == NULL) {
        return 0;
    }

    if (verbose) {
        OUTMSG(("checking whether %S exists... ", str));
    }

    if (Exists(str->addr)) {
        if (verbose) {
            OUTMSG(("found\n"));
        }
        return 0;
    }

    if (verbose) {
        OUTMSG(("creating... "));
    }

    rc_t rc = KDirectoryCreateDir(m_Self, access,
        (kcmCreate | kcmParents), str->addr);
    if (verbose) {
        if (rc == 0) {
            OUTMSG(("ok\n"));
        }
        else {
            OUTMSG(("failed\n"));
        }
    }

    return rc;
}
Example #7
0
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
	// Get the GTA IV install directory from the registry
	char szInstallDirectory[MAX_PATH];
	bool bFoundCustomDirectory = false, bRenewProtocol = false;
	std::string strReNewEntries = lpCmdLine;

	if(SharedUtility::ReadRegistryString(HKEY_CURRENT_USER, "Software\\IVMP", "gtaivdir", NULL,
		szInstallDirectory, sizeof(szInstallDirectory)) ||
		!SharedUtility::Exists(szInstallDirectory))
	{
		char szProtocolDirectory[MAX_PATH];
		CString strCommand = CString("\"%s\" \"%%1\"",SharedUtility::GetAbsolutePath("Client.Launcher.exe"));

		if(strcmp(szProtocolDirectory, strCommand.Get()))
			bRenewProtocol = true;
	}

	// Check if protocol 'ivmp' and 'ivmultiplayer' is avaiable in registry
	if(!SharedUtility::ReadRegistryString(HKEY_CLASSES_ROOT, "ivmp", NULL, "", NULL, NULL)
		|| !SharedUtility::ReadRegistryString(HKEY_CLASSES_ROOT, "ivmultiplayer", NULL, "", NULL, NULL)
		|| bRenewProtocol)               
	{
		// Update
		SharedUtility::WriteRegistryString(HKEY_CLASSES_ROOT,"ivmp","","IVMultiplayer",strlen("IVMultiplayer"));
		SharedUtility::WriteRegistryString(HKEY_CLASSES_ROOT,"ivmultiplayer","","IVMultiplayer",strlen("IVMultiplayer"));

		CString strcommand = CString("\"%s\" \"%%1\"",SharedUtility::GetAbsolutePath("Client.Launcher.exe"));

		SharedUtility::WriteRegistryString(HKEY_CLASSES_ROOT,"ivmp","Url Protocol","",0);
		SharedUtility::WriteRegistryString(HKEY_CLASSES_ROOT,"ivmp\\shell\\open\\command\\","",strcommand.GetData(),strcommand.GetLength());
		SharedUtility::WriteRegistryString(HKEY_CLASSES_ROOT,"ivmp\\DefaultIcon","", CString("Client.Launcher.exe,1").GetData(),strlen("Client.Launcher.exe,1"));

		SharedUtility::WriteRegistryString(HKEY_CLASSES_ROOT,"ivmultiplayer","Url Protocol","",0);
		SharedUtility::WriteRegistryString(HKEY_CLASSES_ROOT,"ivmultiplayer\\shell\\open\\command\\","",strcommand.GetData(),strcommand.GetLength());
		SharedUtility::WriteRegistryString(HKEY_CLASSES_ROOT,"ivmultiplayer\\DefaultIcon","", CString("Client.Launcher.exe,1").GetData(),strlen("Client.Launcher.exe,1"));
	}

	// TODO: Steam registry entry support(or the client should just pick the directory via data browser)
	if(!SharedUtility::ReadRegistryString(HKEY_LOCAL_MACHINE, "Software\\Rockstar Games\\Grand Theft Auto IV",
		"InstallFolder", NULL, szInstallDirectory, sizeof(szInstallDirectory)) ||
		!SharedUtility::Exists(szInstallDirectory)) {

		if(!SharedUtility::ReadRegistryString(HKEY_CURRENT_USER, "Software\\IVMP", "gtaivdir", NULL,
			szInstallDirectory, sizeof(szInstallDirectory)) ||
			!SharedUtility::Exists(szInstallDirectory)) {

			if(ShowMessageBox("Failed to retrieve GTA IV install directory from registry. Specify your GTA IV path now?",
				(MB_ICONEXCLAMATION | MB_OKCANCEL)) == IDOK)  {
				
				// Taken from http://vcfaq.mvps.org/sdk/20.htm
				BROWSEINFO browseInfo = { 0 };
				browseInfo.lpszTitle = "Pick a Directory";
				ITEMIDLIST * pItemIdList = SHBrowseForFolder(&browseInfo);

				if(pItemIdList != NULL) {
					// Get the name of the selected folder
					if(SHGetPathFromIDList(pItemIdList, szInstallDirectory))
						bFoundCustomDirectory = true;

					// Free any memory used
					IMalloc * pIMalloc = 0;
					if(SUCCEEDED(SHGetMalloc(&pIMalloc))) {
						pIMalloc->Free(pItemIdList);
						pIMalloc->Release();
					}
				}
			}

			if(!bFoundCustomDirectory) {
				ShowMessageBox("Failed to retrieve GTA IV install directory from registry or browser window. Cannot launch IV: Multiplayer.");
				return 1;
			}
		}
	}

	// Get the full path to LaunchGTAIV.exe
	CString strApplicationPath("%s\\LaunchGTAIV.exe", szInstallDirectory);

	// Check if LaunchGTAIV.exe exists
	if(!SharedUtility::Exists(strApplicationPath.Get()))
		return ShowMessageBox("Failed to find LaunchGTAIV.exe. Cannot launch IV: Multiplayer.");

	// If we have a custom directory save it
	if(bFoundCustomDirectory)
		SharedUtility::WriteRegistryString(HKEY_CURRENT_USER, "Software\\IVMP", "gtaivdir", szInstallDirectory, strlen(szInstallDirectory));

	// Get the full path of the client core
	CString strClientCore(SharedUtility::GetAbsolutePath(CLIENT_CORE_NAME DEBUG_SUFFIX LIBRARY_EXTENSION));

	// Check if the client core exists
	if(!SharedUtility::Exists(strClientCore.Get()))
		return ShowMessageBox("Failed to find " CLIENT_CORE_NAME DEBUG_SUFFIX LIBRARY_EXTENSION ". Cannot launch IV: Multiplayer.");

	// Get the full path of the launch helper
	CString strLaunchHelper(SharedUtility::GetAbsolutePath(CLIENT_LAUNCH_HELPER_NAME DEBUG_SUFFIX LIBRARY_EXTENSION));

	// Check if the launch helper exists
	if(!SharedUtility::Exists(strLaunchHelper.Get()))
		return ShowMessageBox("Failed to find " CLIENT_LAUNCH_HELPER_NAME DEBUG_SUFFIX LIBRARY_EXTENSION". Cannot launch IV: Multiplayer.");

	// Check if GTAIV is already running
	if(SharedUtility::IsProcessRunning("GTAIV.exe")) {
		if(ShowMessageBox("GTAIV is already running and needs to be terminated before IV: Multiplayer can be started. Do you want to do that now?",
			MB_ICONQUESTION | MB_YESNO ) == IDYES) {
			if(!SharedUtility::_TerminateProcess("GTAIV.exe"))
				return ShowMessageBox("GTAIV.exe could not be terminated. Cannot launch IV: Multiplayer.");
		}
		else
			return ShowMessageBox("GTAIV.exe is already running. Cannot launch IV: Multiplayer.");
	}

	// Check if LaunchGTAIV.exe is already running
	if(SharedUtility::IsProcessRunning("LaunchGTAIV.exe")) {
		if(ShowMessageBox("LaunchGTAIV is already running and needs to be terminated before IV: Multiplayer can be started. Do you want to do that now?",
			MB_ICONQUESTION | MB_YESNO ) == IDYES) {
			if(!SharedUtility::_TerminateProcess("LaunchGTAIV.exe")) {

				// Wait until we've successfully terminated the process
				Sleep(3000);
				if(SharedUtility::IsProcessRunning("LaunchGTAIV.exe")) {
					if(!SharedUtility::_TerminateProcess("LaunchGTAIV.exe"))
						return ShowMessageBox("LaunchGTAIV.exe could not be terminated. Cannot launch IV: Multiplayer.");
				}
			}
		}
		else
			return ShowMessageBox("LaunchGTAIV.exe is already running. Cannot launch IV: Multiplayer.");
	}

	// TODO ADD WINDOW COMMANDLINE SUPPORT!

	// Check if we have an server connect command
	CString strServer, strPort;
	std::string strServerCheck = CString(lpCmdLine);
	std::size_t sizetCMDFound = strServerCheck.find("-ivmp");// -[1]i[2]v[3]m[4]p[5]*space*[6]***.***.***.***
	int iOffset = 0;
	bool bCommandFound = false;
	CString strNewCommandLine = lpCmdLine;

	// Check for shortcut commandline
	if(sizetCMDFound != std::string::npos) {
		iOffset = 6;
		bCommandFound = true;
	}

	// Check for ivmp protocol
	if(!bCommandFound) {
		sizetCMDFound = strServerCheck.find("ivmp://"); // i[1]v[2]m[3]p[4]:[5]/[6]/[7]***.***.***
		if(sizetCMDFound != std::string::npos) {
			iOffset = 7;
			bCommandFound = true;
		}
	}

	// Check for ivmultiplayer protocol
	if(!bCommandFound) {
		sizetCMDFound = strServerCheck.find("ivmultiplayer://");// i[1]v[2]m[3]u[4]l[5]t[6]i[7]p[8]l[9]a[10]y[11]e[12]r[13]:[14]/[15]/[16]***.***.***
		if(sizetCMDFound != std::string::npos) {
			iOffset = 16;
			bCommandFound = true;
		}
	}

	// Open default clientsettings
	CSettings::Open(SharedUtility::GetAbsolutePath(CLIENT_SETTINGS_FILE), true, true, true);

	// If we have found an direct connect force
	if(bCommandFound)
	{
		std::string strServerInst = strServerCheck.substr(sizetCMDFound+iOffset,strServerCheck.length());
		std::size_t sizetCMDFound_2 = strServerInst.find(":");

		// Have we an : in our instruction
		if(sizetCMDFound_2 != std::string::npos) {
			// Grab our connect data
			strServer = CString("%s",strServerInst.substr(0,sizetCMDFound_2).c_str());
			strPort = CString("%s",strServerInst.substr(sizetCMDFound_2+1,strServerInst.length()).c_str());

			// Parse the command line
			CSettings::ParseCommandLine(GetCommandLine());

			// Write connect data to settings xml
			CVAR_SET_STRING("currentconnect_server",strServer.Get());
			CVAR_SET_INTEGER("currentconnect_port",strPort.ToInteger());

			// Generate new commandline
			strNewCommandLine = CString("%s -directconnect", lpCmdLine);
		}
		else // Something is wrong with our URI 
		{
			if(ShowMessageBox("Something is wrong with your server direct-connect URI, do you want to start IV:MP without direct-connect?", MB_ICONQUESTION | MB_YESNO ) == IDYES)
			{
				// Set default server direct connect values
				CVAR_SET_STRING("currentconnect_server","0.0.0.0");
				CVAR_SET_INTEGER("currentconnect_port",9999);

				strNewCommandLine = lpCmdLine;
			}
			else // Terminate IV:MP
			{
				if(!SharedUtility::_TerminateProcess("Client.Launcher.exe"))
					return ShowMessageBox("LaunchGTAIV.exe could not be terminated. Cannot launch IV: Multiplayer.");
			}

		}
	}
	else {
		CSettings::ParseCommandLine(GetCommandLine());
		// If we haven't found a server connect command, delte the old instructions( if the client had crashed before )
		CVAR_SET_STRING("currentconnect_server","0.0.0.0");
		CVAR_SET_INTEGER("currentconnect_port",9999);
	}

	// Close settings...
	CSettings::Close();

	// Generate the command line
	CString strCommandLine("%s %s", strApplicationPath.Get(), strNewCommandLine.Get());

	// Start LaunchGTAIV.exe
	STARTUPINFO siStartupInfo;
	PROCESS_INFORMATION piProcessInfo;
	memset(&siStartupInfo, 0, sizeof(siStartupInfo));
	memset(&piProcessInfo, 0, sizeof(piProcessInfo));
	siStartupInfo.cb = sizeof(siStartupInfo);

	if(!CreateProcess(strApplicationPath.Get(), (char *)strCommandLine.Get(), NULL, NULL, TRUE, CREATE_SUSPENDED, NULL,
		SharedUtility::GetAppPath(), &siStartupInfo, &piProcessInfo)) {
		ShowMessageBox("Failed to start LaunchGTAIV.exe. Cannot launch IV: Multiplayer.");
		return 1;
	}

	// Inject LauncherLibrary.dll into LaunchGTAIV.exe
	int iReturn = SharedUtility::InjectLibraryIntoProcess(piProcessInfo.hProcess, strLaunchHelper.Get());

	// Did the injection fail?
	if(iReturn > 0) {
		// Terminate the process
		TerminateProcess(piProcessInfo.hProcess, 0);

		// Show the error message
		CString strError("Unknown error. Cannot launch IV: Multiplayer.");

		if(iReturn == 1)
			strError = "Failed to write library path into remote process. Cannot launch IV: Multiplayer.";
		else if(iReturn == 2)
			strError = "Failed to create remote thread in remote process. Cannot launch IV: Multiplayer.";
		else if(iReturn == 3)
			strError = "Failed to open the remote process, Cannot launch IV: Multiplayer.";

		ShowMessageBox(strError.Get());
		return 1;
	}

	// Resume the LaunchGTAIV.exe thread
	ResumeThread(piProcessInfo.hThread);
	return 0;
}
Example #8
0
rc_t CKDirectory::CanWriteFile(const CString &dir, bool verbose) const {
    bool ok = true;
    rc_t rc = 0;
    char path[PATH_MAX] = "";
    if (verbose) {
        OUTMSG(("checking whether %S is writable... ", dir.Get()));
    }
    for (int i = 0; i < 10000 && rc == 0; ++i) {
        size_t path_len = 0;
        rc = string_printf(path, sizeof path, &path_len,
            "%S/.tmp%d.tmp", dir.Get(), i);
        if (rc != 0) {
            break;
        }
        assert(path_len <= sizeof path);
        if (Exists(path)) {
            KDirectoryRemove(m_Self, false, path);
        }
        else {
            KFile *f = NULL;
            rc = KDirectoryCreateFile(m_Self,
                &f, false, m_PrivateAccess, kcmCreate, path);
            if (rc == 0) {
                rc = KFileWrite(f, 0, path, path_len, NULL);
            }
            RELEASE(KFile, f);
            const KFile *cf = NULL;
            if (rc == 0) {
                rc = KDirectoryOpenFileRead(m_Self, &cf, path);
            }
            char buffer[PATH_MAX] = "";
            size_t num_read = 0;
            if (rc == 0) {
                rc = KFileRead(cf, 0, buffer, sizeof buffer, &num_read);
            }
            if (rc == 0) {
                if (path_len != num_read || string_cmp(path,
                    path_len, buffer, num_read, sizeof buffer) != 0)
                {
                    if (verbose) {
                        OUTMSG(("no\n"));
                    }
                    OUTMSG(("Warning: "
                        "NCBI Home directory is not writable"));
                    ok = false;
                }
            }
            RELEASE(KFile, cf);
            if (rc == 0) {
                KDirectoryRemove(m_Self, false, path);
            }
            break;
        }
    }
    if (verbose && ok) {
        if (rc == 0) {
            OUTMSG(("yes\n"));
        }
        else {
            OUTMSG(("failed\n"));
        }
    }
    return rc;
}