Example #1
0
        private async void MasterServerRefreshButton_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrWhiteSpace(MasterServerBox.Text))
            {
                try
                {
                    serverList.Clear();

                    await LoadServerInfoFromFile("http://" + MasterServerBox.Text + "/serverlist.txt");

                    ServerListView.BeginUpdate();
                    ServerListView.Clear();

                    if (serverList.Count > 0)
                    {
                        var ColumnName = new ColumnHeader();
                        ColumnName.Text      = "Name";
                        ColumnName.TextAlign = HorizontalAlignment.Center;
                        ColumnName.Width     = 284;
                        ServerListView.Columns.Add(ColumnName);

                        var ColumnClient = new ColumnHeader();
                        ColumnClient.Text      = "Client";
                        ColumnClient.TextAlign = HorizontalAlignment.Center;
                        ColumnClient.Width     = 75;
                        ServerListView.Columns.Add(ColumnClient);

                        foreach (var server in serverList)
                        {
                            var serverItem = new ListViewItem(server.ServerName);

                            var serverClient = new ListViewSubItem(serverItem, server.ServerClient);
                            serverItem.SubItems.Add(serverClient);

                            ServerListView.Items.Add(serverItem);
                        }
                    }
                    else
                    {
                        MessageBox.Show("There are no servers available on this master server.");
                    }

                    ServerListView.EndUpdate();
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Unable to load servers. (" + ex + ")");
                }
            }
        }
Example #2
0
        async Task LoadServers()
        {
            string oldText = Text;

            Text = Text + " (Loading Servers...)";

            if (!string.IsNullOrWhiteSpace(MasterServerBox.Text))
            {
                try
                {
                    serverList.Clear();
                    Task info = await Task.Factory.StartNew(() => LoadServerInfoFromFile("http://" + MasterServerBox.Text + "/serverlist.txt"));

                    Task.WaitAll(info);

                    ServerListView.BeginUpdate();
                    ServerListView.Clear();

                    if (serverList.Count > 0)
                    {
                        var ColumnName = new ColumnHeader();
                        ColumnName.Text      = "Name";
                        ColumnName.TextAlign = HorizontalAlignment.Center;
                        ColumnName.Width     = 284;
                        ServerListView.Columns.Add(ColumnName);

                        var ColumnClient = new ColumnHeader();
                        ColumnClient.Text      = "Client";
                        ColumnClient.TextAlign = HorizontalAlignment.Center;
                        ColumnClient.Width     = 75;
                        ServerListView.Columns.Add(ColumnClient);

                        var ColumnVersion = new ColumnHeader();
                        ColumnVersion.Text      = "Version";
                        ColumnVersion.TextAlign = HorizontalAlignment.Center;
                        ColumnVersion.Width     = 110;
                        ServerListView.Columns.Add(ColumnVersion);

                        foreach (var server in serverList)
                        {
                            var serverItem = new ListViewItem(server.ServerName);
                            serverItem.UseItemStyleForSubItems = false;

                            var serverClient = new ListViewItem.ListViewSubItem(serverItem, server.ServerClient);
                            serverItem.SubItems.Add(serverClient);

                            var serverVersion = new ListViewItem.ListViewSubItem(serverItem, server.ServerVersion);

                            if (serverVersion.Text != GlobalVars.ProgramInformation.Version)
                            {
                                serverVersion.ForeColor = Color.Red;
                            }

                            serverItem.SubItems.Add(serverVersion);

                            ServerListView.Items.Add(serverItem);
                        }
                    }
                    else
                    {
                        MessageBox.Show("There are no servers available on this master server.", "Novetus - Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }

                    ServerListView.EndUpdate();
                }
                catch (Exception ex)
                {
                    string message = "Unable to load servers (" + ex.GetBaseException().Message + ").\n\nMake sure you have a master server address other than 'localhost' in the textbox.\nIf the server still does not load properly, consult the administrator of the server for more information.";
                    if (ex.GetBaseException().Message.Contains("404"))
                    {
                        message = "There are no servers available on this master server.";
                    }

                    GlobalFuncs.LogExceptions(ex);
                    MessageBox.Show(message, "Novetus - Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    ServerListView.Clear();
                }
                finally
                {
                    Text = oldText;
                }
            }
        }