Exemple #1
0
        public static void WipeDatabase()
        {
            AccountContext ctx;

            ctx = new AccountContext();
            ctx.Database.Delete();
        }
Exemple #2
0
 public static bool EnableDatabase()
 {
     if (accountContext == null)
     {
         accountContext = new AccountContext();
         accountContext.Database.ExecuteSqlCommand("SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;");
     }
     else return false;
     return true;
 }
Exemple #3
0
 public static bool EnableDatabase()
 {
     if (accountContext == null)
     {
         accountContext = new AccountContext();
         accountContext.Database.ExecuteSqlCommand("SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;");
     }
     else
     {
         return(false);
     }
     return(true);
 }
Exemple #4
0
 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();
 }
Exemple #5
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);
        }
Exemple #6
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);
        }
Exemple #7
0
 public static void WipeDatabase()
 {
     AccountContext ctx;
     ctx = new AccountContext();
     ctx.Database.Delete();
 }