Queries a TCP server for data regarding players online, message of the day, etc
 private void PingServer(ServerPinger pinger)
 {
     string error = "";
     ServerPingData ping = pinger.PingServer(Data.IP, Data.Port, out error);
     Ping = ping;
     //If no error
     if (error == string.Empty)
     {
         //Set the controls with the recieved data
         Stats.Text = ping.Online + "/" + ping.MaxOnline;
         Stats.Left = (ClientWidth - (int)Manager.Skin.Fonts["Default14"].Resource.MeasureString(Stats.Text).X) - 4 - 32;
         Motd.Text = ping.Description;
     }
     else
     {
         Motd.Text = error;
         Motd.TextColor = Color.Gold;
     }
 }
Beispiel #2
0
        public ServerDataControl(Manager manager, ServerPinger pinger, ServerSaveData server)
            : base(manager)
        {
            //Setup
            Passive = false;
            Height = 76;
            ClientWidth = 450 - 16;
            Data = server;

            //Background "gradient" image
            //TODO: Make an actual control. not a statusbar
            Gradient = new StatusBar(manager);
            Gradient.Init();
            Gradient.Alpha = .8f;
            Add(Gradient);

            //Add controls
            Name = new Label(Manager) { Width = this.Width, Text = server.Name, Left = 4, Top = 4, Font = FontSize.Default14, Alignment = Alignment.TopLeft};
            Name.Init();
            Add(Name);

            Stats = new Label(Manager) { Width = this.Width, Text = string.Empty, Alignment = Alignment.TopLeft, Top = 4, Font = FontSize.Default14, };
            Stats.Init();
            Add(Stats);

            Motd = new Label(Manager) { Width = this.Width, Left = 4, Top = Name.Bottom + 8, Font = FontSize.Default8, Alignment = Alignment.TopLeft };
            Motd.Init();
            Motd.Text = "Querying server for data...";
            Motd.Height = (int)Manager.Skin.Fonts["Default8"].Height * 2;
            Add(Motd);

            Host = new Label(Manager) { Width = this.Width, Text = server.GetHostString(), Alignment = Alignment.TopLeft, Left = 4, Top = Motd.Bottom, TextColor = Color.LightGray };
            Host.Init();
            Add(Host);

            //Ping the server for stats on a seperate thread
            new Thread(() => PingServer(pinger)).Start();
        }
Beispiel #3
0
        public ServerWindow(Manager manager)
            : base(manager)
        {
            //Setup server pinger/query
            Pinger = new ServerPinger();
            //Setup the window
            CaptionVisible = false;
            Caption.Text = "Welcome to Bricklayer!";
            Description.Text = "An open source, fully moddable and customizable 2D\nbuilding game built with the community in mind.";
            Movable = false;
            Resizable = false;
            Width = 450;
            Height = 350;
            Shadow = true;
            Center();

            //Player config
            NameLbl = new Label(Manager) { Left = 8, Top = TopPanel.Bottom + 10, Width = 64, Text = "Username:"******"Color:" };
            ColorLbl.Init();
            Add(ColorLbl);

            BodyClr = new ColorPicker(Manager) { Left = ColorLbl.Right + 4, Top = TopPanel.Bottom + 8, Width = 128, Saturation = GlobalSettings.ColorSaturation, Value = GlobalSettings.ColorValue };
            BodyClr.Init();
            BodyClr.ValueChanged += new TomShane.Neoforce.Controls.EventHandler(delegate(object o, TomShane.Neoforce.Controls.EventArgs e)
            {
                BodyImg.Color = BodyClr.SelectedColor;
                Game.MyColor = BodyClr.SelectedColor;
                Game.MyHue = BodyClr.Hue;
            });
            Add(BodyClr);

            BodyImg = new ImageBox(Manager) { Left = BodyClr.Right + 6, Top = TopPanel.Bottom + 8, Width = 18, Height = 18, Color = Game.MyColor, Image = ContentPack.Textures["entity\\body"] };
            BodyImg.Init();
            Add(BodyImg);

            SmileyImg = new ImageBox(Manager) { Left = BodyClr.Right + 6, Top = TopPanel.Bottom + 8, Width = 18, Height = 18, Image = ContentPack.Textures["entity\\smileys"], SourceRect = new Rectangle(0, 0, 18, 18) };
            SmileyImg.Init();
            SmileyImg.ToolTip.Text = "I love this color!";
            Add(SmileyImg);

            BodyClr.Hue = Game.MyHue;
            //Create main server list
            ServerListCtrl = new ControlList<ServerDataControl>(manager) { Left = 8, Top = TopPanel.Bottom + 34, Width = ClientWidth - 16, Height = ClientHeight - TopPanel.Height - BottomPanel.Height - 42 };
            ServerListCtrl.Init();
            Add(ServerListCtrl);
            RefreshServerList();

            //Add BottomPanel controls
            JoinBtn = new Button(manager) { Text = "Connect", Left = 24, Top = 8, Width = 100, };
            JoinBtn.Init();
            JoinBtn.Click += new TomShane.Neoforce.Controls.EventHandler(delegate(object o, TomShane.Neoforce.Controls.EventArgs e)
            {
                //Logical place to save name/color settings
                IO.SaveSettings(new Settings() { Username = Game.Username, Color = Game.MyHue, ContentPack = Game.ContentPackName, Resolution = new Point(Game.Resolution.Width, Game.Resolution.Height), UseVSync = Game.MainWindow.Manager.Graphics.SynchronizeWithVerticalRetrace });
                //Connect
                if (ServerListCtrl.Items.Count > 0)
                {
                    if ((ServerListCtrl.Items[ServerListCtrl.ItemIndex] as ServerDataControl).Ping != null && (ServerListCtrl.Items[ServerListCtrl.ItemIndex] as ServerDataControl).Ping.Error)
                        return;
                    //Create a world and connect
                    JoinBtn.Enabled = false;
                    JoinBtn.Text = "Connecting...";
                    Game.NetManager.Connect(Servers[ServerListCtrl.ItemIndex].IP, Servers[ServerListCtrl.ItemIndex].Port);
                }
            });
            BottomPanel.Add(JoinBtn);

            AddBtn = new Button(manager) { Text = "Add", Left = JoinBtn.Right + 8, Top = 8, Width = 64, };
            AddBtn.Init();
            AddBtn.Click += new TomShane.Neoforce.Controls.EventHandler(delegate(object o, TomShane.Neoforce.Controls.EventArgs e)
            {
                AddServerDialog window = new AddServerDialog(manager, this,ServerListCtrl.ItemIndex, false, string.Empty, string.Empty);
                window.Init();
                Manager.Add(window);
                window.Show();
            });
            BottomPanel.Add(AddBtn);

            EditBtn = new Button(manager) { Text = "Edit", Left = AddBtn.Right + 8, Top = 8, Width = 64, };
            EditBtn.Init();
            EditBtn.Click += new TomShane.Neoforce.Controls.EventHandler(delegate(object o, TomShane.Neoforce.Controls.EventArgs e)
            {
                if (ServerListCtrl.Items.Count > 0)
                {
                    AddServerDialog window = new AddServerDialog(manager, this, ServerListCtrl.ItemIndex, true, Servers[ServerListCtrl.ItemIndex].Name, Servers[ServerListCtrl.ItemIndex].GetHostString());
                    window.Init();
                    Manager.Add(window);
                    window.Show();
                }
            });
            BottomPanel.Add(EditBtn);

            RemoveBtn = new Button(manager) { Text = "Remove", Left = EditBtn.Right + 8, Top = 8, Width = 64 };
            RemoveBtn.Init();
            RemoveBtn.Click += new TomShane.Neoforce.Controls.EventHandler(delegate(object o, TomShane.Neoforce.Controls.EventArgs e)
            {
                if (ServerListCtrl.Items.Count > 0)
                {
                    MessageBox confirm = new MessageBox(manager, MessageBoxType.YesNo, "Are you sure you would like to remove\nthis server from your server list?", "[color:Red]Confirm Removal[/color]");
                    confirm.Init();
                    confirm.Closed += new WindowClosedEventHandler(delegate(object sender, WindowClosedEventArgs args)
                    {
                        if ((sender as Dialog).ModalResult == ModalResult.Yes) //If user clicked yes
                        {
                            Servers.RemoveAt(ServerListCtrl.ItemIndex);
                            ServerListCtrl.Items.RemoveAt(ServerListCtrl.ItemIndex);
                            IO.WriteServers(Servers);
                            RefreshServerList();
                        }
                    });
                    Manager.Add(confirm);
                    confirm.Show();
                }
            });
            BottomPanel.Add(RemoveBtn);

            RefreshBtn = new Button(manager) { Text = "Refresh", Left = RemoveBtn.Right + 8, Top = 8, Width = 64 };
            RefreshBtn.Init();
            RefreshBtn.Click += new TomShane.Neoforce.Controls.EventHandler(delegate(object o, TomShane.Neoforce.Controls.EventArgs e)
            {
                RefreshServerList();
            });
            BottomPanel.Add(RefreshBtn);
            MainWindow.ScreenManager.FadeIn();
            validateUsername();
        }