Beispiel #1
0
        void ShowProjectPage(ServerListItem item)
        {
            try
            {
                Configuration.SetActiveProject(item);
                lProjectTitle.Content = item.Name;
                lProjectIP.Content    = item.IP + " : " + item.Port;

                projectGrid.Visibility = Visibility.Visible;
                serverGrid.Visibility  = Visibility.Hidden;

                progressBar.Value  = 0;
                image.Source       = null;
                textBlock.Text     = null;
                bWebsite.IsEnabled = false;
                SetStartButton(StartButtonSetting.Disabled);

                updateThread = new Thread(CheckForUpdates);
                updateThread.Start();
            }
            catch (Exception e)
            {
                File.WriteAllText("exceptions.txt", e.ToString());
            }
        }
Beispiel #2
0
 public static void AddServer(string address)
 {
     if (ServerListItem.TryGetAddress(address, out string ip, out ushort port))
     {
         servers.Add(new ServerListItem(ip, port));
         Save();
     }
 }
Beispiel #3
0
        static void Load()
        {
            servers.Clear();

            if (!File.Exists(ConfigFile))
            {
                return;
            }

            using (StreamReader sr = new StreamReader(ConfigFile))
            {
                string line = sr.ReadLine();
                if (line != null && (line = line.Trim()).StartsWith("Language="))
                {
                    if (int.TryParse(line.Substring("Language=".Length).TrimStart(), out int language))
                    {
                        LangStrings.LanguageIndex = language;
                    }
                }

                line = sr.ReadLine();
                if (line != null && (line = line.Trim()).StartsWith("Path="))
                {
                    gothicPath = Path.GetFullPath(line.Substring("Path=".Length).TrimStart());
                }

                line = sr.ReadLine();
                if (line != null && (line = line.Trim()).StartsWith("zSpy="))
                {
                    if (int.TryParse(line.Substring("zSpy=".Length).TrimStart(), out int spy))
                    {
                        zSpyLevel = spy;
                    }
                }

                sr.ReadLine();
                while (!sr.EndOfStream)
                {
                    var item = ServerListItem.ReadNew(sr);

                    if (string.Compare(sr.ReadLine(), "active", true) == 0)
                    {
                        activeProject = item;
                    }

                    if (item != null)
                    {
                        servers.Add(item);
                    }
                }
            }
        }
Beispiel #4
0
        public static ServerListItem ReadNew(StreamReader sr)
        {
            string addressLine  = sr.ReadLine();
            string passwordLine = sr.ReadLine();

            if (TryGetAddress(addressLine, out string address, out ushort port))
            {
                ServerListItem item = new ServerListItem(address, port);
                item.Password = string.IsNullOrEmpty(passwordLine) ? null : Convert.FromBase64String(passwordLine);
                return(item);
            }
            return(null);
        }
Beispiel #5
0
        void ShowPasswordPage(ServerListItem item, bool wrongPW = false)
        {
            var pw = ShowInputBox(LangStrings.Get(wrongPW ? "Password_Wrong" : "Password_Needed"));

            if (pw == null)
            {
                return;
            }

            byte[] hash;
            using (MD5 md5 = new MD5CryptoServiceProvider())
            {
                hash = md5.ComputeHash(Encoding.Unicode.GetBytes(pw));
            }

            TryOpenProjectPage(item, hash);
        }
Beispiel #6
0
        void bConnect_Click(object sender, RoutedEventArgs args)
        {
            try
            {
                if (lvServerList.SelectedIndex < 0)
                {
                    return;
                }

                ServerListItem item = (ServerListItem)lvServerList.SelectedItem;
                TryOpenProjectPage(item, item.Password);
            }
            catch (Exception e)
            {
                ShowException(e);
            }
        }
Beispiel #7
0
        static void Refresh(object obj)
        {
            ServerListItem item = (ServerListItem)obj;

            TcpClient client = new TcpClient();

            try
            {
                if (client.ConnectAsync(item.IP, 9054).Wait(1000))
                {
                    var stream = client.GetStream();
                    if (stream.WriteAsync(NetIDRefresh, 0, 1).Wait(1000))
                    {
                        byte[] buf = new byte[byte.MaxValue];
                        if (stream.ReadAsync(buf, 0, 4).Wait(1000))
                        {
                            int count   = buf[0];
                            int slots   = buf[1];
                            int pw      = buf[2];
                            int nameLen = buf[3];

                            if (stream.ReadAsync(buf, 0, nameLen).Wait(1000))
                            {
                                client.Close();

                                item.Name    = Encoding.UTF8.GetString(buf, 0, nameLen);
                                item.Players = count + "/" + slots;
                                item.HasPW   = pw > 0;
                                item.Ping    = new Ping().Send(item.IP, 1000).RoundtripTime.ToString();
                                return;
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                File.AppendAllText("exceptions.txt", e.ToString());
            }

            client.Close();
            item.Ping = "Offline";
        }
Beispiel #8
0
        void TryOpenProjectPage(ServerListItem item, byte[] password, bool initload = false)
        {
            if (item.HasPW && password == null)
            {
                if (initload)
                {
                    return;
                }

                ShowPasswordPage(item);
                return;
            }

            TcpClient client   = new TcpClient();
            int       waitTime = initload ? 400 : 1000;

            if (client.ConnectAsync(item.IP, item.Port).Wait(waitTime))
            {
                var    stream = client.GetStream();
                byte[] buf    = new byte[byte.MaxValue];
                buf[0] = 1;

                if (password != null)
                {
                    Array.Copy(password, 0, buf, 1, 16);
                }

                if (stream.WriteAsync(buf, 0, 17).Wait(waitTime))
                {
                    if (stream.ReadAsync(buf, 0, 1).Wait(waitTime))
                    {
                        if (buf[0] == 0)
                        {
                            // wrong password
                            client.Close();
                            ShowPasswordPage(item, true);
                            return;
                        }
                        else if (stream.ReadAsync(buf, 0, 1).Wait(waitTime))
                        {
                            // correct password!
                            item.Password = password;
                            Configuration.Save();

                            int byteLen = buf[0];
                            if (stream.ReadAsync(buf, 0, byteLen).Wait(waitTime))
                            {
                                dlLink = Encoding.UTF8.GetString(buf, 0, byteLen);
                                client.Close();
                                ShowProjectPage(item);
                                return;
                            }
                        }
                    }
                }
            }
            client.Close();

            //Could not connect
            if (!initload)
            {
                ShowInfoBox(LangStrings.Get("Connection_Failed"));
            }
        }
Beispiel #9
0
 public static void SetActiveProject(ServerListItem item)
 {
     activeProject = item;
     Save();
 }