This isn't allowed right?
#1

Quote:
Originally Posted by Martin Cleveland
Посмотреть сообщение
Introduction
I've been working on my own SA-MP client. I was bored and I was up for a challenge so I thought why not? I have no intention of releasing it anytime soon. The UI (design) is simple, but I've overcome some big challenges and I'm proud of that. Below you'll find a list of some features.

Features:
- Links to the SA-MP website, forums and wiki.
- Ability to save/delete favorites.
- Ability to add/remove usernames.
- Ability to launch samp-server.exe
- Ability to edit server.cfg (config)
- Ability to launch samp_debug.exe
- Client will scan the game directory for any CLEO files.
- Ability to directly connect to a SA-MP server.
- If you click on an IP it will retrieve the server ID, hostname, players and locked status.

Added in V2:
- Ability to launch samp_debug.exe, launch server.cfg and launch the localhost server.
- Ability to save & remove usernames.
- Ability to import & export favorites.
- Ability to save chatlogs.

I'm pretty proud of it because I've learned so much. Some parts were pretty difficult but untill now I've always managed to find a solution or workaround. I'll show some examples below.

Launching GTA
This was one of the first challenges I faced. After some searching I found a video on *******, but I still had to add some things such as password support. In the spoiler you'll find the snippet.
Код:
            Registry.SetValue("HKEY_CURRENT_USER\\Software\\SAMP", "PlayerName", tbPlayername.Text);
            string arguments = tbIP.Text + " " + tbPassword.Text;
            System.Diagnostics.ProcessStartInfo procStartInfo = new    System.Diagnostics.ProcessStartInfo(path + "\\samp.exe", arguments);
            System.Diagnostics.Process proc = new System.Diagnostics.Process();
            proc.StartInfo = procStartInfo;
            proc.Start();
As you can see it's pretty tricky. I had to edit a registry value which stores the PlayerName and launch samp.exe with two arguments: IP and password. It took me quite a while to figure out how to run samp.exe with multiple arguments.

Retrieving server information
This was also very tricky. I used the SACNR API to retrieve the server information. I had to sent a request, store the request and cut out the pieces I needed. (such as the hostname) The API is written in JSON I believe, so I either had to find a JSON parser to come up with my own solution. Below you'll find a snippet.
Код:
WebRequest request = WebRequest.Create("http://monitor.sacnr.com/api/?IP=" + IP + "&Port=" + port +"&Action=info");
                WebResponse response = request.GetResponse();
                Stream dataStream = response.GetResponseStream();
                StreamReader reader = new StreamReader(dataStream);
                string responseFromServer = reader.ReadToEnd();
                reader.Close();
                response.Close();
Storing the IPs, path, serverpath and usernames
I had several options. Store the data in a .db file and use SQLite queries to write and read data or store the data internally. I found a way to store the data in the application so I don't have to rely on any external files. I stored the data in the so called 'properties' which are in a small .xml file. (appdata/local)

Код:
<setting name="Path" serializeAs="String">
                <value>C:\Program Files (x86)\Rockstar Games\GTA San Andreas</value>
            </setting>
            <setting name="Favorites" serializeAs="Xml">
                <value>
                    <ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                        xmlns:xsd="http://www.w3.org/2001/XMLSchema">
                    </ArrayOfString>
                </value>
            </setting>
Custom IP to regular IP
In SA-MP you can have a custom IP such as samp.*servername*.net, but because the API requires a regular IP and port, I had to convert it. I used a built-in function to retrieve the IP. Below you'll find a snippet.
Код:
        private string getIP(string IP)
        {
            IPAddress[] addresslist = Dns.GetHostAddresses(IP);
            foreach (IPAddress i in addresslist)
            {
                IP = i.ToString();
            }
            return IP;
        }
It probably pings the address and retrieves the IP. For those who have some experience in programming, you can see the IPs are stored in an array, however a SA-MP server only has 1 IP so that's why this workaround works.

Formats
This was probably the biggest issue I encountered. You can connect to a SA-MP server by using several formats: IP, IP: port, samp.*servername*.net, samp.*servernet*.net: port. IP and IP: port weren't really a big problem because I could just check if the string contains a ":" and cut out the port. The third format is a bit harder because Dns.GetHostAddress(IP) does not support a port, so I'd have to have to cut out the port, convert the IP and paste the port back.

Chatlogs
I figured it'd be useful if you could save your chatlogs. The way it works right now is that the application copies the chatlog.txt file from the GTA User Files to another folder. Below you'll find a snippet.

Код:
        void gta_Exited(object sender, EventArgs e)
        {
            if (Properties.Settings.Default.Logging == 1)
            {
                string date = DateTime.Now.ToString("dd-MM-yyyy_HH-mm-ss");
                string fileName = "chatlog_" + date + ".txt";
                try
                {
                    if (Directory.Exists(System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\GTA San Andreas User Files\\SAMP\\chatlogs"))
                    {
                        File.Copy((System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)) + "\\GTA San Andreas User Files\\SAMP\\chatlog.txt", System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\GTA San Andreas User Files\\SAMP\\chatlogs\\" + fileName);
                    }
                    else
                    {
                        DirectoryInfo di = Directory.CreateDirectory(System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\GTA San Andreas User Files\\SAMP\\chatlogs");
                        File.Copy((System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)) + "\\GTA San Andreas User Files\\SAMP\\chatlog.txt", System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\GTA San Andreas User Files\\SAMP\\chatlogs\\" + fileName);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Something went wrong with saving the chatlogs, please try again.");
                }
            }
        }
Conclusion
I've had a great time developing this application because I've learned many things. I didn't know 75% of the things I've used, but that's what programming is about. You'll always encounter problems and you have to come up with a solution for them. Be creative and don't be afraid to ask for help! (stackoverflow)

Video
[video=*******_share;UkRhUNnt6mA]http://*********/UkRhUNnt6mA[/video]

Screenshots (v2)




- No, I am not the creator. I am just wanting to get someones opinion from here before I have it removed.
Reply


Messages In This Thread
This isn't allowed right? - by Akira297 - 24.01.2015, 22:18
Re: This isn't allowed right? - by Abagail - 24.01.2015, 22:24
Re: This isn't allowed right? - by Akira297 - 24.01.2015, 22:26
Re: This isn't allowed right? - by Infinity - 24.01.2015, 22:27
Re: This isn't allowed right? - by Akira297 - 24.01.2015, 22:31
Re: This isn't allowed right? - by TakeiT - 24.01.2015, 22:31
Re: This isn't allowed right? - by Alex Magaсa - 24.01.2015, 22:40
Re: This isn't allowed right? - by SickAttack - 24.01.2015, 22:48
AW: This isn't allowed right? - by Khanz - 24.01.2015, 22:50
Re: This isn't allowed right? - by dugi - 24.01.2015, 22:53

Forum Jump:


Users browsing this thread: 1 Guest(s)