コード例 #1
0
        public static void WipeDatabase()
        {
            AccountContext ctx;

            ctx = new AccountContext();
            ctx.Database.Delete();
        }
コード例 #2
0
ファイル: LobbyServiceImpl.cs プロジェクト: kradchen/sgs
 public static bool EnableDatabase()
 {
     if (accountContext == null)
     {
         accountContext = new AccountContext();
         accountContext.Database.ExecuteSqlCommand("SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;");
     }
     else return false;
     return true;
 }
コード例 #3
0
ファイル: LobbyServiceImpl.cs プロジェクト: kradchen/sgs
 public static bool EnableDatabase()
 {
     if (accountContext == null)
     {
         accountContext = new AccountContext();
         accountContext.Database.ExecuteSqlCommand("SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;");
     }
     else
     {
         return(false);
     }
     return(true);
 }
コード例 #4
0
ファイル: LobbyServiceImpl.cs プロジェクト: h1398123/sgs
 public LobbyServiceImpl(bool noDatabase = true)
 {
     rooms = new Dictionary<int, Room>();
     loggedInGuidToAccount = new Dictionary<Guid, Account>();
     loggedInGuidToChannel = new Dictionary<Guid, IGameClient>();
     loggedInAccountToGuid = new Dictionary<Account, Guid>();
     loggedInChannelsToGuid = new Dictionary<IGameClient, Guid>();
     loggedInGuidToRoom = new Dictionary<Guid, Room>();
     newRoomId = 1;
     newAccountId = 1;
     CheatEnabled = false;
     accounts = new List<Account>();
     if (noDatabase) accountContext = null;
     else accountContext = new AccountContext();
 }
コード例 #5
0
ファイル: LobbyServiceImpl.cs プロジェクト: kradchen/sgs
        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);
        }
コード例 #6
0
ファイル: LobbyServiceImpl.cs プロジェクト: kradchen/sgs
        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);
        }
コード例 #7
0
ファイル: LobbyServiceImpl.cs プロジェクト: kradchen/sgs
 public static void WipeDatabase()
 {
     AccountContext ctx;
     ctx = new AccountContext();
     ctx.Database.Delete();
 }