Ejemplo n.º 1
0
 public ClientNetworkUiProxy(IUiProxy p, Client c, bool a)
 {
     proxy = p;
     client = c;
     active = a;
     lastTS = 0;
 }
Ejemplo n.º 2
0
 public ClientNetworkProxy(IPlayerProxy uiProxy, Client client)
 {
     this.uiProxy = uiProxy;
     this.client = client;
     lastTS = 0;
     numQuestionsAsked = 0;
 }
Ejemplo n.º 3
0
        public void StartGame()
        {
            Client client;

            client = new Client();
            string addr = LobbyModel.GameServerConnectionString;
            string[] args = addr.Split(':');
            Trace.Assert(args.Length == 2);
            client.IpString = args[0];
            client.PortNumber = int.Parse(args[1]);

            busyIndicator.BusyContent = Resources["Busy.JoinGame"];
            busyIndicator.IsBusy = true;

            //client.Start(isReplay, FileStream = file.open(...))
            BackgroundWorker worker = new BackgroundWorker();

            worker.DoWork += (o, ea) =>
            {
                try
                {
                    ea.Result = false;
                    client.Start(null, LobbyModel.LoginToken);
                    client.RecordStream = FileRotator.CreateFile("./Replays", "SGSREPLAY", ".sgs", 10);
                    ea.Result = true;
                }
                catch (Exception e)
                {
                    Trace.TraceError("Connection failure : " + e.StackTrace);
                    Trace.Assert(false);
                }
            };

            worker.RunWorkerCompleted += (o, ea) =>
            {
                busyIndicator.IsBusy = false;
                if ((bool)ea.Result)
                {
                    chatBox.Document.Blocks.Clear();
                    LobbyViewModel.Instance.OnChat -= chatEventHandler;
                    MainGame game = new MainGame();
                    game.NetworkClient = client;
                    this.NavigationService.Navigate(game);
                    return;
                }
                else
                {
                    MessageBox.Show("Failed to create connection for " + LobbyModel.GameServerConnectionString);
                    Trace.Assert(false);
                }
            };

            worker.RunWorkerAsync();
        }
Ejemplo n.º 4
0
        private void btnReplay_Click(object sender, RoutedEventArgs e)
        {
            if (!Directory.Exists("./Replays"))
            {
                Directory.CreateDirectory("./Replays");
            }
            OpenFileDialog dlg = new OpenFileDialog();
            dlg.InitialDirectory = Directory.GetCurrentDirectory() + "\\Replays";
            dlg.DefaultExt = ".sgs"; // Default file extension
            dlg.Filter = "Replay File (.sgs)|*.sgs|All Files (*.*)|*.*"; // Filter files by extension
            bool? result = dlg.ShowDialog();
            if (result != true) return;

            string fileName = dlg.FileName;

            Client client;
            MainGame game = null;
            try
            {
                client = new Client();
                client.StartReplay(File.Open(fileName, FileMode.Open));
                game = new MainGame();
                game.NetworkClient = client;
            }
            catch (Exception)
            {
                MessageBox.Show("Failed to open replay file.");
                return;
            }
            if (game != null)
            {
                this.NavigationService.Navigate(game);
            }
        }
Ejemplo n.º 5
0
        private void btnReplay_Click(object sender, RoutedEventArgs e)
        {
            if (!Directory.Exists("./Replays"))
            {
                Directory.CreateDirectory("./Replays");
            }
            OpenFileDialog dlg = new OpenFileDialog();
            dlg.InitialDirectory = Directory.GetCurrentDirectory() + "\\Replays";
            dlg.DefaultExt = ".sgs"; // Default file extension
            dlg.Filter = "Replay File (.sgs)|*.sgs|Crash Report File (.rpt)|*.rpt|All Files (*.*)|*.*"; // Filter files by extension
            bool? result = dlg.ShowDialog();
            if (result != true) return;

            string fileName = dlg.FileName;

            Client client;
            MainGame game = null;
            try
            {
                client = new Client();
                game = new MainGame();
                game.OnNavigateBack += game_OnNavigateBack;
                Stream stream = File.Open(fileName, FileMode.Open);
                byte[] bytes = new byte[4];
                stream.Read(bytes, 0, 4);
                int length = BitConverter.ToInt32(bytes, 0);
                stream.Seek(length, SeekOrigin.Current);
                client.StartReplay(stream);
                game.NetworkClient = client;
            }
            catch (Exception)
            {
                MessageBox.Show("Failed to open replay file.");
                return;
            }
            if (game != null)
            {
                MainGame.BackwardNavigationService = this.NavigationService;
                game.Start();
                // this.NavigationService.Navigate(game);
            }
        }
Ejemplo n.º 6
0
        private void btnReplay_Click(object sender, RoutedEventArgs e)
        {
            if (!Directory.Exists("./Replays"))
            {
                Directory.CreateDirectory("./Replays");
            }
            OpenFileDialog dlg = new OpenFileDialog();
            dlg.InitialDirectory = Directory.GetCurrentDirectory() + "\\Replays";
            dlg.DefaultExt = ".sgs"; // Default file extension
            dlg.Filter = "Replay File (.sgs)|*.sgs|Crash Report File (.rpt)|*.rpt|All Files (*.*)|*.*"; // Filter files by extension
            bool? result = dlg.ShowDialog();
            if (result != true) return;

            string fileName = dlg.FileName;

            Client client;
            MainGame game = null;
            try
            {
                client = new Client();
                game = new MainGame();
                game.OnNavigateBack += game_OnNavigateBack;
                Stream stream = File.Open(fileName, FileMode.Open);
                byte[] seed = new byte[8];
                stream.Seek(-16, SeekOrigin.End);
                stream.Read(seed, 0, 8);
                if (System.Text.Encoding.Default.GetString(seed).Equals(Misc.MagicAnimal.ToString("X8")))
                {
                    stream.Read(seed, 0, 8);
                    game.HasSeed = Convert.ToInt32(System.Text.Encoding.Default.GetString(seed), 16);
                }
                stream.Seek(0, SeekOrigin.Begin);

                byte[] bytes = new byte[4];
                stream.Read(bytes, 0, 4);
                int length = BitConverter.ToInt32(bytes, 0);
                if (length != 0)
                {
                    byte[] msg = new byte[length];
                    stream.Read(msg, 0, length);
                    UnicodeEncoding uniEncoding = new UnicodeEncoding();
                    MessageBox.Show(new String(uniEncoding.GetChars(msg)));
                }
                client.StartReplay(stream);
                game.NetworkClient = client;
            }
            catch (Exception)
            {
                MessageBox.Show("Failed to open replay file.");
                return;
            }
            if (game != null)
            {
                MainGame.BackwardNavigationService = this.NavigationService;
                game.Start();
                // this.NavigationService.Navigate(game);
            }
        }
Ejemplo n.º 7
0
        private void _StartGame()
        {
            Application.Current.Dispatcher.Invoke((ThreadStart)delegate()
            {
                Client client;

                client = new Client();
                string addr = LobbyModel.GameServerConnectionString;
                string[] args = addr.Split(':');
                Trace.Assert(args.Length == 2);
                client.IpString = args[0];
                client.PortNumber = int.Parse(args[1]);

                busyIndicator.BusyContent = Resources["Busy.JoinGame"];
                busyIndicator.IsBusy = true;

                //client.Start(isReplay, FileStream = file.open(...))
                BackgroundWorker worker = new BackgroundWorker();

                worker.DoWork += (o, ea) =>
                {
                    try
                    {
                        ea.Result = false;
                        client.Start();
                        client.RecordStream = FileRotator.CreateFile("./Replays", "SGSREPLAY", ".sgs", 10);
                        ea.Result = true;
                    }
                    catch (Exception)
                    {
                    }
                };

                worker.RunWorkerCompleted += (o, ea) =>
                {
                    busyIndicator.IsBusy = false;
                    if ((bool)ea.Result)
                    {
                        MainGame game = new MainGame();
                        game.NetworkClient = client;
                        this.NavigationService.Navigate(game);
                        return;
                    }
                    else
                    {
                        MessageBox.Show("Failed to create connection for " + LobbyModel.GameServerConnectionString);
                    }
                };

                worker.RunWorkerAsync();
            });
        }
Ejemplo n.º 8
0
        public void StartGame()
        {
            Client client;

            client = new Client();
            string addr = LobbyModel.GameServerConnectionString;
            string[] args = addr.Split(':');
            Trace.Assert(args.Length == 2);
            client.IpString = args[0];
            client.PortNumber = int.Parse(args[1]);

            busyIndicator.BusyContent = Resources["Busy.JoinGame"];
            busyIndicator.IsBusy = true;

            //client.Start(isReplay, FileStream = file.open(...))
            BackgroundWorker worker = new BackgroundWorker();

            worker.DoWork += (o, ea) =>
            {
                try
                {
                    ea.Result = false;
                    client.Start(null, LobbyModel.LoginToken);
                    var stream = FileRotator.CreateFile("./Replays", "SGSREPLAY", ".sgs", 10);
                    byte[] zeroBytes = { 0, 0, 0, 0 };
                    stream.Write(zeroBytes, 0, 4);
                    client.RecordStream = stream;

                    MainGame game = null;

                    Application.Current.Dispatcher.Invoke((ThreadStart)delegate()
                    {
                        try
                        {
                            game = new MainGame();
                            game.OnNavigateBack += (oo, s) =>
                            {
                                s.Navigate(this);
                                this.Reload();
                            };
                            game.NetworkClient = client;
                            if (NavigationService != null)
                            {
                                MainGame.BackwardNavigationService = this.NavigationService;
                            }
                            else
                            {
                                ViewModelBase.IsDetached = true;
                            }
                        }
                        catch (Exception)
                        {
                            game = null;
                        }
                    });

                    if (game != null)
                    {
                        game.Start();
                        ea.Result = true;
                    }
                }
                catch (Exception e)
                {
                    Trace.TraceError("Connection failure : " + e.StackTrace);
                    Trace.Assert(false);
                }
            };

            worker.RunWorkerCompleted += (o, ea) =>
            {
                if ((bool)ea.Result)
                {
                    chatBox.Document.Blocks.Clear();
                    LobbyViewModel.Instance.OnChat -= chatEventHandler;
                    return;
                }
                else
                {
                    busyIndicator.IsBusy = false;
                    MessageBox.Show("Failed to create connection for " + LobbyModel.GameServerConnectionString);
                    Trace.Assert(false);
                }
            };

            worker.RunWorkerAsync();
        }
Ejemplo n.º 9
0
        private void btnReplay_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog dlg = new OpenFileDialog();
            dlg.DefaultExt = ".sgs"; // Default file extension
            dlg.Filter = "Replay File (.sgs)|*.sgs|All Files (*.*)|*.*"; // Filter files by extension
            bool? result = dlg.ShowDialog();
            if (result != true) return;

            string fileName = dlg.FileName;

            Client client;
            int mainSeat = 0;
            MainGame game = null;
            try
            {
                client = new Client();
                client.Start(true, File.Open(fileName, FileMode.Open));
                mainSeat = (int)client.Receive();
                client.SelfId = mainSeat;
                game = new MainGame();
                game.MainSeat = mainSeat;
                game.NetworkClient = client;
            }
            catch (Exception)
            {
                MessageBox.Show("Failed to open replay file.");
                return;
            }
            if (game != null)
            {
                this.NavigationService.Navigate(game);
            }
        }
Ejemplo n.º 10
0
        private void startButton_Click(object sender, RoutedEventArgs e)
        {
            if (loginTab.SelectedIndex == 0)
            {
                Client client;
                int mainSeat = 0;

                client = new Client();
                string addr = tab0HostName.Text;
                string[] args = addr.Split(':');
                client.IpString = args[0];
                if (args.Length >= 2)
                {
                    client.PortNumber = int.Parse(args[1]);
                }
                else
                {
                    client.PortNumber = 12345;
                }
                busyIndicator.BusyContent = Resources["Busy.ConnectServer"];
                busyIndicator.IsBusy = true;

                //client.Start(isReplay, FileStream = file.open(...))
                BackgroundWorker worker = new BackgroundWorker();

                worker.DoWork += (o, ea) =>
                {
                    try
                    {
                        ea.Result = false;
                        client.Start();
                        mainSeat = (int)client.Receive();
                        client.SelfId = mainSeat;
                        ea.Result = true;
                    }
                    catch (Exception)
                    {
                    }
                };

                worker.RunWorkerCompleted += (o, ea) =>
                {
                    busyIndicator.IsBusy = false;
                    if ((bool)ea.Result)
                    {
                        MainGame game = new MainGame();
                        game.MainSeat = mainSeat;
                        game.NetworkClient = client;
                        this.NavigationService.Navigate(game);
                        return;
                    }
                    else
                    {
                        MessageBox.Show("Failed to create connection");
                    }
                };

                worker.RunWorkerAsync();
            }
        }