Exemplo n.º 1
0
        private void ReceiveLoop()
        {
            Game.RegisterCurrentThread();
            while (true)
            {
                GameDataPacket packet = Receive();
                if (packet == null)
                {
                    break;
                }
                try
                {
                    if (packet is GameResponse)
                    {
                        semaPakArrival.WaitOne();
                    }
                    var handler2 = OnGameDataPacketReceived;
                    if (handler2 != null)
                    {
                        handler2(packet);
                    }
                }
                catch (Exception e)
                {
                    while (e.InnerException != null)
                    {
                        e = e.InnerException;
                    }

                    Trace.TraceError(e.StackTrace);
                    Trace.Assert(false, e.StackTrace);

                    var crashReport = new StreamWriter(FileRotator.CreateFile("./Crash", "crash", ".dmp", 1000));
                    crashReport.WriteLine(e);
                    crashReport.Close();
                    break;
                }
            }
            receiveThread = null;
        }
Exemplo n.º 2
0
        public void SubmitBugReport(System.IO.Stream s)
        {
            if (s == null)
            {
                return;
            }
            try
            {
                Stream file = FileRotator.CreateFile("./Reports", "crashdmp", ".rpt", 1000);

                if (s != null)
                {
                    s.CopyTo(file);
                    s.Flush();
                    s.Close();
                }
                file.Flush();
                file.Close();
            }
            catch (Exception)
            {
            }
        }
Exemplo 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;

            LobbyViewModel.Instance.OnChat -= LobbyModel_OnChat;
            chatBox.Document.Blocks.Clear();

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

            worker.DoWork += (o, ea) =>
            {
                try
                {
                    ea.Result = false;
                    var stream = FileRotator.CreateFile("./Replays", "SGSREPLAY", ".sgs", 10);

                    stream.Write(BitConverter.GetBytes((int)0), 0, 4);
                    client.RecordStream = stream;
                    client.Start(stream, LobbyModel.LoginToken);

                    MainGame game = null;

                    Application.Current.Dispatcher.Invoke((ThreadStart) delegate()
                    {
                        try
                        {
                            game = new MainGame();
                            game.OnNavigateBack += (oo, s) =>
                            {
                                s.Navigate(this);
                            };
                            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);
                }
            };

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

            worker.RunWorkerAsync();
        }
Exemplo n.º 4
0
        private void _OnGameEnds(int roomId)
        {
            if (accountContext != null)
            {
                try
                {
                    lock (accountContext)
                    {
                        accountContext.SaveChanges();
                    }
                }
                catch (Exception e)
                {
                    var crashReport = new StreamWriter(FileRotator.CreateFile("./Crash", "crash", ".dmp", 1000));
                    crashReport.WriteLine(e);
                    crashReport.WriteLine(e.Message);
                    crashReport.Close();
                    accountContext = new AccountContext();
                }
            }
            if (rooms.ContainsKey(roomId))
            {
                var room = rooms[roomId];
                lock (room.Room)
                {
                    room.Room.State = RoomState.Waiting;
                    foreach (var seat in room.Room.Seats)
                    {
                        if (seat.Account == null)
                        {
                            continue;
                        }
                        lock (loggedInAccounts)
                        {
                            if (loggedInAccounts.ContainsKey(seat.Account.UserName))
                            {
                                try
                                {
                                    loggedInAccounts[seat.Account.UserName].CallbackChannel.Ping();
                                }
                                catch (Exception)
                                {
                                    _Logout(loggedInAccounts[seat.Account.UserName], true);
                                    seat.Account = null;
                                    seat.State   = SeatState.Empty;
                                    continue;
                                }
                            }
                            else
                            {
                                seat.State   = SeatState.Empty;
                                seat.Account = null;
                            }

                            if (seat.State != SeatState.Host)
                            {
                                seat.State = SeatState.GuestTaken;
                            }

                            if (seat.Account != null && (loggedInAccounts.ContainsKey(seat.Account.UserName) && loggedInAccounts[seat.Account.UserName].CurrentRoom != rooms[roomId]))
                            {
                                seat.Account = null;
                                seat.State   = SeatState.Empty;
                            }
                        }
                    }

                    if (_DestroyRoomIfEmpty(room))
                    {
                        return;
                    }
                    if (!room.Room.Seats.Any(st => st.State == SeatState.Host))
                    {
                        var f = room.Room.Seats.First(st => st.State == SeatState.GuestTaken);
                        f.State = SeatState.Host;
                    }
                }
            }
            _NotifyRoomLayoutChanged(roomId);
        }
Exemplo n.º 5
0
 private void btnSubmitBug_Click(object sender, RoutedEventArgs e)
 {
     tbBuggyReplayFileName.Text = FileRotator.GetLatestFileName("./Replays", string.Empty, ".sgs");
     tbBugMessage.Clear();
     submitBugWindow.Show();
 }