Central logging class. Logs to file, relays messages to the frontend, submits crash reports.
예제 #1
0
        /// <summary> Loads contents of PlayerDB. </summary>
        /// <exception cref="InvalidOperationException"> If PlayerDB is akready loaded. </exception>
        /// <exception cref="MisconfigurationException"> If an unknown PlayerDBProviderType is specified. </exception>
        /// <exception cref="TypeLoadException"> If MySqlPlayerDBProvider could not be found. </exception>
        public static void Load() {
            using( GetWriteLock() ) {
                if( IsLoaded ) throw new InvalidOperationException( "PlayerDB is already loaded." );
                Stopwatch sw = Stopwatch.StartNew();

                switch( ProviderType ) {
                    case PlayerDBProviderType.Flatfile:
                        provider = new FlatfilePlayerDBProvider();
                        break;
                    case PlayerDBProviderType.MySql:
                        Assembly mySqlAsm =
                            Assembly.LoadFile( Path.Combine( Paths.WorkingPath, Paths.MySqlPlayerDBProviderModule ) );
                        provider = (IPlayerDBProvider)mySqlAsm.CreateInstance( MySqlPlayerDBProviderType );
                        if( provider == null ) {
                            throw new TypeLoadException( "PlayerDB.Load: Could not find MySqlPlayerDBProvider." );
                        }
                        break;
                    default:
                        throw new MisconfigurationException( "PlayerDB.Load: Unknown ProviderType: " + ProviderType );
                }

                var playerList = provider.Load();

                if( playerList != null ) {
                    List.AddRange( playerList );
                    sw.Stop();
                    Logger.Log( LogType.Debug,
                                "PlayerDB.Load: Done loading ({0} records read) in {1}ms",
                                List.Count, sw.ElapsedMilliseconds );
                } else {
                    Logger.Log( LogType.Debug,
                                "PlayerDB.Load: No records loaded." );
                }

                Logger.Log( LogType.SystemActivity, "PlayerDB: Checking consistency of player records..." );
                List.Sort( PlayerInfo.ComparerByID );

                int unhid = 0, unfroze = 0, unmuted = 0;
                for( int i = 0; i < List.Count; i++ ) {
                    if( List[i].IsBanned ) {
                        if( List[i].IsHidden ) {
                            unhid++;
                            List[i].IsHidden = false;
                        }

                        if( List[i].IsFrozen ) {
                            List[i].Unfreeze();
                            unfroze++;
                        }

                        if( List[i].IsMuted ) {
                            List[i].Unmute();
                            unmuted++;
                        }
                    }
                    List[i].RaisePropertyChangedEvents = true;
                }
                if( unhid != 0 || unfroze != 0 || unmuted != 0 ) {
                    Logger.Log( LogType.SystemActivity,
                                "PlayerDB: Unhid {0}, unfroze {1}, and unmuted {2} banned accounts.",
                                unhid, unfroze, unmuted );
                }

                IsLoaded = true;

                // Import everything from flatfile
                //provider.Import( new FlatfilePlayerDBProvider().Load() );
            }
        }
예제 #2
0
        public Map AcceptPlayer( [NotNull] Player player, bool announce ) {
            if( player == null ) throw new ArgumentNullException( "player" );

            lock( SyncRoot ) {
                if( IsFull ) {
                    if( player.Info.Rank.ReservedSlot ) {
                        Player idlestPlayer = Players.Where( p => p.Info.Rank.IdleKickTimer != 0 )
                                                     .OrderBy( p => p.LastActiveTime )
                                                     .FirstOrDefault();
                        if( idlestPlayer != null ) {
                            idlestPlayer.Kick( Player.Console, "Auto-kicked to make room (idle).",
                                               LeaveReason.IdleKick, false, false, false );

                            Server.Players
                                  .CanSee( player )
                                  .Message( "&SPlayer {0}&S was auto-kicked to make room for {1}",
                                            idlestPlayer.ClassyName, player.ClassyName );
                            Server.Players
                                  .CantSee( player )
                                  .Message( "{0}&S was kicked for being idle for {1} min",
                                            player.ClassyName, player.Info.Rank.IdleKickTimer );
                        } else {
                            return null;
                        }
                    } else {
                        return null;
                    }
                }

                if( playerIndex.ContainsKey( player.Name.ToLower() ) ) {
                    Logger.Log( LogType.Error,
                                "This world already contains the player by name ({0}). " +
                                "Some sort of state corruption must have occured.",
                                player.Name );
                    playerIndex.Remove( player.Name.ToLower() );
                }

                playerIndex.Add( player.Name.ToLower(), player );

                // load the map, if it's not yet loaded
                IsPendingMapUnload = false;
                Map = LoadMap();

                if( ConfigKey.BackupOnJoin.Enabled() && (Map.HasChangedSinceBackup || !ConfigKey.BackupOnlyWhenChanged.Enabled()) ) {
                    string backupFileName = String.Format( JoinBackupFormat,
                                                           Name, DateTime.Now, player.Name ); // localized
                    Map.SaveBackup( MapFileName,
                                    Path.Combine( Paths.BackupPath, backupFileName ) );
                }

                UpdatePlayerList();

                if (!IsRealm && announce && ConfigKey.ShowJoinedWorldMessages.Enabled())
                {
                    Server.Players.CanSee(player)
                                  .Message("&SPlayer {0}&S joined world {1}",
                                            player.ClassyName, ClassyName);

                }

                //realm joining announcer
                if (IsRealm && announce && ConfigKey.ShowJoinedWorldMessages.Enabled())
                {
                    Server.Players.CanSee(player)
                                  .Message("&SPlayer {0}&S joined realm {1}",
                                            player.ClassyName, ClassyName);
                }

                if (IsRealm)
                {
                    Logger.Log(LogType.ChangedWorld,
                    "Player {0} joined realm {1}.",
                    player.Name, Name);
                }

                if (!IsRealm)
                {
                    Logger.Log(LogType.ChangedWorld,
                    "Player {0} joined world {1}.",
                    player.Name, Name);
                }

                if( IsLocked ) {
                    player.Message( "&WThis map is currently locked (read-only)." );
                }

                if( player.Info.IsHidden ) {
                    player.Message( "&8Reminder: You are still hidden." );
                }

                return Map;
            }
        }