示例#1
0
        private void LClient_eGameHost(HostedGame game, bool unHosting, bool isGameListItem)
        {
            System.Threading.Thread thread = new System.Threading.Thread
            (
                new System.Threading.ThreadStart
                (
                    delegate()
                    {
                        rtbChat.Dispatcher.Invoke
                        (
                            System.Windows.Threading.DispatcherPriority.Normal,
                            new Action
                            (
                                delegate()
                                {
                                    if(unHosting)
                                    {
                                        for(int i = 0; i < Program.LClient.HostedGames.Count; i++)
                                        {
                                            if(Program.LClient.HostedGames[i].intUGameNum == game.intUGameNum)
                                                Program.LClient.HostedGames.RemoveAt(i);
                                        }
                                        return;
                                    }
                                    if(isGameListItem)
                                    {
                                        Program.LClient.HostedGames.Add(game);
                                    }
                                    else
                                    {
                                        if(game.strHostName == Program.LClient.strUserName)
                                        {
                                            IPHostEntry host = Dns.GetHostEntry(game.getStrHost()[0]);

                                            // Addres of the host.
                                            IPAddress[] addressList = host.AddressList;

                                            ips = new String[addressList.Length];
                                            int i = 0;
                                            foreach(IPAddress ip in addressList)
                                            {
                                                ips[i] = ip.ToString();
                                                i++;
                                            }
                                            Join_Game(ips, game.getIntPort());
                                            //Program.Client = new Networking.Client(addresslist[0], game.getIntPort());
                                            //Program.Client.Connect();
                                            //Program.LClient.isHosting = true;
                                        }
                                        Run r = new Run("#SYSTEM: ");
                                        Brush b = Brushes.Red;
                                        r.ToolTip = DateTime.Now.ToLongTimeString() + " " + DateTime.Now.ToLongDateString();
                                        r.Foreground = b;
                                        r.Cursor = Cursors.Hand;
                                        r.Background = Brushes.White;
                                        Paragraph p = new Paragraph();
                                        p.Inlines.Add(new Bold(r));
                                        r = new Run(game.strHostName + " is hosting a " + game.strGameName + " ");
                                        p.Inlines.Add(r);
                                        r = getGameRun(game.strHostName, game);
                                        p.Inlines.Add(r);
                                        r = new Run(": " + game.strName);
                                        p.Inlines.Add(r);
                                        rtbChat.Document.Blocks.Add(p);
                                        rtbChat.ScrollToEnd();
                                        if(Settings.Default.LobbySound)
                                        {
                                            System.Media.SoundPlayer sp = new System.Media.SoundPlayer(Properties.Resources.click);
                                            sp.Play();
                                        }

                                        Program.LClient.HostedGames.Add(game);
                                    }
                                }
                            )
                        );
                    }
                )
            );
            thread.Start();
        }
示例#2
0
        private Run getGameRun(String user, HostedGame game)
        {
            Run r = new Run("game");
            r.ToolTip = "Click to join " + user + "'s game";
            r.Cursor = Cursors.Hand;
            r.Foreground = Brushes.Blue;
            r.Background = Brushes.White;
            r.MouseEnter += delegate(object sender, MouseEventArgs e)
            {
                r.Background = new RadialGradientBrush(Colors.DarkGray, Colors.WhiteSmoke);
            };
            r.MouseLeave += delegate(object sender, MouseEventArgs e)
            {
                r.Background = Brushes.White;
            };
            r.AddHandler(UIElement.MouseLeftButtonDownEvent, new MouseButtonEventHandler(delegate(object sender, MouseButtonEventArgs e)
            {
                if(user.Equals(Program.LClient.strUserName))
                    return;
                if(!Program.LClient.isHosting && !Program.LClient.isJoining)
                {
                    if((Application.Current.MainWindow as Play.PlayWindow) != null)
                        Application.Current.MainWindow.Close();
                    else if((Application.Current.MainWindow as DeckBuilder.DeckBuilderWindow) != null)
                        Application.Current.MainWindow.Close();
                    Program.LClient.isJoining = true;
                    if(SelectGame(game.getStrGUID()))
                    {
                        intIpTried = 0;
                        port = game.getIntPort();
                        ips = game.getStrHost();

                        IPHostEntry host = Dns.GetHostEntry(ips[0]);

                        // Addres of the host.
                        IPAddress[] addressList = host.AddressList;

                        ips[0] = addressList[0].ToString();

                        Join_Game(ips, game.getIntPort());
                    }
                    else
                    {
                        //change_join_text("Join");
                        MessageBox.Show("You do not have the correct game installed.");
                        Program.LClient.isJoining = false;
                    }
                }
                else
                {
                    if(Program.LClient.isHosting)
                    {
                        MessageBox.Show("Please stop hosting first.");
                    }
                    if(Program.LClient.isJoining)
                    {
                        MessageBox.Show("Please stop joining first.");
                    }
                }
            }));
            return r;
        }