SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 08/12/2018, 07:05 PM   #1
Norbooo
Little Clucker
 
Join Date: Nov 2017
Posts: 11
Reputation: 0
Default Custom game launcher problem

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.
Norbooo is offline   Reply With Quote
Old 08/12/2018, 09:33 PM   #2
Chyakka
Little Clucker
 
Join Date: Jul 2015
Location: England
Posts: 37
Reputation: 10
Default Re: Custom game launcher problem

Not my code but the SAMPLauncherNET accomplished it, heres the code you'd probably want for your own implementation;

Code:
 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.
Chyakka is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[HELP] About sa-mp custom launcher C# chikov Scripting Help 4 13/12/2018 11:14 AM
Custom server launcher CarlosScripter Scripting Help 3 10/12/2018 05:56 AM
Making custom SAMP launcher Brooks1 Scripting Help 14 02/05/2018 06:37 PM
[Tutorial] Making a custom launcher for your server(SUPER EASY) Excelize Tutorials 22 09/03/2018 12:43 PM


All times are GMT. The time now is 06:56 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.