Пример #1
0
        void OnHosts(string data)
        {
            HostsDatabase.Clear(false);

            foreach (var entry in data.Split('|'))
            {
                var param = entry.Split('/');
                if (param.Length == 4)
                {
                    HostsDatabase.Add(false,
                                      param[0].Unescape(EscapeLanguage.Xml),
                                      param[1].Unescape(EscapeLanguage.Xml),
                                      param[2].Unescape(EscapeLanguage.Xml),
                                      param[3] == "1");
                }
            }

            HostsDatabase.Save();
            EventCallbackSystem.InvokeCallback("HostsListUpdated", true);

            HostsDatabase.Lock();
            int numberOfHosts = HostsDatabase.Hosts.Count();

            HostsDatabase.Unlock();
            Logger.Log(LogType.Debug, "Received {0} hosts from server.", numberOfHosts.FormatNumber());
        }
Пример #2
0
        void OnLogin(UserClient client, string data)
        {
            string server_keydata = string.Empty;

            if (!ServerConfiguration.GetValue("keydata", out server_keydata))
            {
                client.Disconnect("Server keydata is missing...");
                return;
            }

            if (data.Length != server_keydata.Length ||
                string.Compare(data, server_keydata) != 0)
            {
                IPLock.AddLock(client.NetworkClient.IP);
                client.Disconnect("Client keydata is invalid");
                return;
            }

            client.IsAuthorized = true;
            client.NetworkClient.Send("logedin\n");
            Logger.Log(LogType.Debug, "{0} successfully authorized.", client.NetworkClient.IP);

            // send hosts list and shit
            var sb = new StringBuilder();

            sb.Append("hosts ");
            int i = 0;

            HostsDatabase.Lock();
            foreach (var host in HostsDatabase.Hosts)
            {
                if (i++ > 0)
                {
                    sb.Append('|');
                }

                sb.AppendFormat(
                    "{0}/{1}/{2}/{3}",
                    host.Name.Escape(EscapeLanguage.Xml),
                    host.IP.Escape(EscapeLanguage.Xml),
                    host.Description.Escape(EscapeLanguage.Xml),
                    host.Hidden ? "1" : "0");
            }
            HostsDatabase.Unlock();
            sb.Append('\n');

            client.NetworkClient.Send(sb.ToString()); // host list
        }
Пример #3
0
        private void RegisterEvents()
        {
            EventCallbackSystem.RegisterCallback <ClientAuthorizedEvent>("ClientAuthorized", () =>
            {
                Logger.Log(LogType.Debug, "Authorized to server.");
            });

            EventCallbackSystem.RegisterCallback <HostsListUpdatedEvent>("HostsListUpdated", (changed) =>
            {
                lvHosts.BeginUpdate();
                lvLocalHosts.BeginUpdate();
                lvHosts.Items.Clear();
                lvLocalHosts.Items.Clear();
                HostsDatabase.Lock();

                var lviList = new List <ListViewItem>(Math.Max(HostsDatabase.Hosts.Count(), HostsDatabase.LocalHosts.Count()));

                foreach (var host in HostsDatabase.Hosts)
                {
                    if ((Configuration.ShowHiddenHosts ||
                         !host.Hidden) &&
                        _searchParameters.Matches(host))
                    {
                        var lvi = new ListViewItem(host.Name);
                        lvi.SubItems.Add(host.IP);
                        lvi.SubItems.Add(host.Description);
                        lvi.Tag = host;
                        //lvHosts.Items.Add(lvi);
                        lviList.Add(lvi);
                    }
                }
                lvHosts.Items.AddRange(lviList.ToArray());
                if (lvHosts.Items.Count < HostsDatabase.Hosts.Count())
                {
                    gbHosts.Text = string.Format(
                        "Domains ({0} of {1})",
                        lvHosts.Items.Count.FormatNumber(),
                        HostsDatabase.Hosts.Count().FormatNumber());
                }
                else
                {
                    gbHosts.Text = string.Format("Domains ({0})", lvHosts.Items.Count.FormatNumber());
                }
                lviList.Clear();

                foreach (var host in HostsDatabase.LocalHosts)
                {
                    if ((Configuration.ShowHiddenHosts ||
                         !host.Hidden) &&
                        _searchParameters.Matches(host))
                    {
                        var lvi = new ListViewItem(host.Name);
                        lvi.SubItems.Add(host.IP);
                        lvi.SubItems.Add(host.Description);
                        lvi.Tag = host;
                        //lvLocalHosts.Items.Add(lvi);
                        lviList.Add(lvi);
                    }
                }
                lvLocalHosts.Items.AddRange(lviList.ToArray());
                if (lvLocalHosts.Items.Count < HostsDatabase.LocalHosts.Count())
                {
                    gbLocalHosts.Text = string.Format(
                        "Local domains ({0} of {1})",
                        lvLocalHosts.Items.Count.FormatNumber(),
                        HostsDatabase.LocalHosts.Count().FormatNumber());
                }
                else
                {
                    gbLocalHosts.Text = string.Format("Local domains ({0})", lvLocalHosts.Items.Count.FormatNumber());
                }

                HostsDatabase.Unlock();
                lvHosts.EndUpdate();
                lvLocalHosts.EndUpdate();
                //Logger.Log(LogType.Debug, "Hosts list updated.");

                UpdateInterface();

                if (changed)      // only synchronize if the hostsdatabase was literally changed - ignore searching
                {
                    _synchronizer.PostSynchronize();
                }
            });
        }