Custom game launcher problem
#1

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.
Reply
#2

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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)