Custom game launcher problem - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Custom game launcher problem (
/showthread.php?tid=661583)
Custom game launcher problem -
Norbooo - 08.12.2018
Hey guys,
I am currently try to build a game launcher for my server using c#. The server is password protected, and I want to implement the password in the code (of the launcher ),
but when the launcher connects to the server it is always says "wrong server password". I searched for information about this, looked up a lot of threads, but none of it helped me. I would really appreciate some help!
Saw some threads about launching samp.exe or gta_sa.exe with parameters, but it doesn't really worked for me.
Thank you in advance.
Re: Custom game launcher problem -
Chyakka - 08.12.2018
Not my code but the SAMPLauncherNET accomplished it, heres the code you'd probably want for your own implementation;
Код:
public static void LaunchSAMP(Server server, string username, string serverPassword, string rconPassword, bool debug, bool quitWhenDone, bool createSessionLog, PluginDataContract[] plugins, Form f)
{
if ((server != null) || debug)
{
if (debug || server.IsValid)
{
IntPtr mh = Kernel32.GetModuleHandle("kernel32.dll");
if (mh != IntPtr.Zero)
{
IntPtr load_library_w = Kernel32.GetProcAddress(mh, "LoadLibraryW");
if (load_library_w != IntPtr.Zero)
{
Kernel32.PROCESS_INFORMATION process_info;
Kernel32.STARTUPINFO startup_info = new Kernel32.STARTUPINFO();
if (CheckIfGTASanAndreasIsLaunchable)
{
string modified_username = ((username == null) ? "" : username.Trim().Replace(' ', '_'));
if (createSessionLog)
{
lastMediaState = SessionProvider.GetCurrentMediaState();
lastSessionData = new SessionDataContract(DateTime.Now, TimeSpan.Zero, SAMPProvider.CurrentVersion.Name, modified_username, (server == null) ? "" : server.IPPortString, (server == null) ? "" : server.Hostname, (server == null) ? "" : server.Gamemode, (server == null) ? "" : server.Language);
}
if (Kernel32.CreateProcess(GTASAExe, debug ? "-d" : "-c " + ((rconPassword == null) ? "" : rconPassword) + " -h " + server.IPv4AddressString + " -p " + server.Port + " -n " + modified_username + ((serverPassword == null) ? "" : (" -z " + serverPassword)), IntPtr.Zero, IntPtr.Zero, false, /* DETACHED_PROCESS */ 0x8 | /* CREATE_SUSPENDED */ 0x4, IntPtr.Zero, ExeDir, ref startup_info, out process_info))
{
InjectPlugin(SAMPDLLPath, process_info.hProcess, load_library_w);
PluginDataContract[] load_plugins = ((plugins == null) ? PluginsDataIO : plugins);
foreach (PluginDataContract plugin in load_plugins)
{
if (plugin != null)
{
if (plugin.Enabled)
{
InstalledPlugin installed_plugin = PluginProvider.Update(plugin);
if (installed_plugin != null)
{
InjectPlugin(installed_plugin.Path, process_info.hProcess, load_library_w);
}
}
}
}
Kernel32.ResumeThread(process_info.hThread);
Kernel32.CloseHandle(process_info.hProcess);
if ((f != null))
{
if (quitWhenDone && (!createSessionLog))
{
f.Close();
}
f.WindowState = FormWindowState.Minimized;
}
}
}
}
}
}
}
}
By the looks of it the '-z' parameter is passed for the executable if it has a server password.