Ejemplo n.º 1
0
 /// <summary>
 /// Create a new Instance of <see cref="FriendsManager"/>
 /// </summary>
 public FriendsManager(IObjectDatabase Database)
 {
     this.Database             = Database;
     PlayersFriendsListsCache  = new ReaderWriterDictionary <GamePlayer, string[]>();
     PlayersFriendsStatusCache = new ReaderWriterDictionary <GamePlayer, FriendStatus[]>();
     GameEventMgr.AddHandler(GameClientEvent.StateChanged, OnClientStateChanged);
     GameEventMgr.AddHandler(GamePlayerEvent.GameEntered, OnPlayerGameEntered);
     GameEventMgr.AddHandler(GamePlayerEvent.Quit, OnPlayerQuit);
     GameEventMgr.AddHandler(GamePlayerEvent.ChangeAnonymous, OnPlayerChangeAnonymous);
 }
Ejemplo n.º 2
0
		/// <summary>
		/// Create a new Instance of <see cref="FriendsManager"/>
		/// </summary>
		public FriendsManager(IObjectDatabase Database)
		{
			this.Database = Database;
			PlayersFriendsListsCache = new ReaderWriterDictionary<GamePlayer, string[]>();
			PlayersFriendsStatusCache = new ReaderWriterDictionary<GamePlayer, FriendStatus[]>();
			GameEventMgr.AddHandler(GameClientEvent.StateChanged, OnClientStateChanged);
			GameEventMgr.AddHandler(GamePlayerEvent.GameEntered, OnPlayerGameEntered);
			GameEventMgr.AddHandler(GamePlayerEvent.Quit, OnPlayerQuit);
			GameEventMgr.AddHandler(GamePlayerEvent.ChangeAnonymous, OnPlayerChangeAnonymous);
		}
Ejemplo n.º 3
0
		/// <summary>
		/// Constructor for a game client
		/// </summary>
		/// <param name="srvr">The server that's communicating with this client</param>
		public GameClient(BaseServer srvr)
			: base(srvr)
		{
			m_clientVersion = eClientVersion.VersionNotChecked;
			m_player = null;
			m_activeCharIndex = -1; //No character loaded yet!
			m_GameObjectUpdateArray = new ReaderWriterDictionary<Tuple<ushort, ushort>, long>();
			m_HouseUpdateArray = new ReaderWriterDictionary<Tuple<ushort, ushort>, long>();
		}
Ejemplo n.º 4
0
        public void MaintainCache()
        {
            // If we're not initialied yet, do nothing
            if( !Initialized.WaitOne(0) )
            {
                return;
            }

            // Ensure no new connection can come online while we're doing cache work
            lock( Connections )
            {
                // If there are no active connections, then we can do cache upkeep
                if( Connections.Count == 0 )
                {
                    // Relocate the cache if requested
                    if( CacheRelocationRequested )
                    {
                        // Simply call init cache to re-read location and recreate what we need
                        InitCache();
                        CacheRelocationRequested = false;
                    }
                    // If a full cache clearing out has been requested
                    if( CacheClearRequested )
                    {
                        Log( EVerbosityLevel.Informative, ELogColour.Green, "[CleanCache] Clearing out the cache by user request" );

                        // Delete everything in the persistent cache
                        string[] PersistentCacheContents = Directory.GetFiles( AgentApplication.Options.CacheFolder );
                        bool CacheCleared = true;
                        foreach( string PersistentCacheEntry in PersistentCacheContents )
                        {
                            try
                            {
                                File.Delete( PersistentCacheEntry );
                            }
                            catch ( Exception Ex )
                            {
                                Log( EVerbosityLevel.Informative, ELogColour.Orange, "[CleanCache] Failed to delete the file " + PersistentCacheEntry + ", it may be in use..." );
                                Log( EVerbosityLevel.Informative, ELogColour.Orange, "[CleanCache] Exception was: " + Ex.Message.TrimEnd( '\n' ) );
                                CacheCleared = false;
                            }
                        }
                        if( CacheCleared )
                        {
                            Log( EVerbosityLevel.Informative, ELogColour.Green, "[CleanCache] Cache successfully cleared" );
                        }
                        else
                        {
                            Log( EVerbosityLevel.Informative, ELogColour.Green, "[CleanCache] Cache not cleared, some files were not deleted, but the Agent will pretend they're gone" );
                        }

                        // Clear out the hash set
                        ChannelHashValues.Clear();

                        // Reset the requesting boolean
                        CacheClearRequested = false;
                    }
                    // If a cache validation has been requested, perform one now
                    else if( CacheValidateRequested )
                    {
                        // Iterate through the entire cache and compare newly generated values
                        Log( EVerbosityLevel.Informative, ELogColour.Green, "[MaintainCache] Validating all cache entries and hashes" );
                        DirectoryInfo CacheFolderDirectory = new DirectoryInfo( AgentApplication.Options.CacheFolder );

                        // Walk through all existing files and compare new hashes with their existing hashes
                        ReaderWriterDictionary<string, byte[]> ValidatedChannelHashValues = new ReaderWriterDictionary<string, byte[]>();

                        bool AllFilesUpdated = true;
                        foreach( FileInfo NextFile in CacheFolderDirectory.GetFiles() )
                        {
                            // Each iteration, check to see if a local connection request has come in
                            if( LocalConnectionRequestWaiting.WaitOne( 0 ) )
                            {
                                // If there is, then break out of this work loop
                                Log( EVerbosityLevel.Informative, ELogColour.Green, "[MaintainCache] Canceling validation due to incoming local connection" );
                                AllFilesUpdated = false;
                                break;
                            }

                            Log( EVerbosityLevel.Informative, ELogColour.Green, " ............ validating hash for " + NextFile.Name );

                            // Create the hash value and add it to the new set
                            byte[] HashValue = ComputeHash( File.ReadAllBytes( NextFile.FullName ) );
                            ValidatedChannelHashValues.Add( NextFile.Name, HashValue );

                            // Look it up in the old set
                            byte[] ExistingHash;
                            if( ChannelHashValues.TryGetValue( NextFile.Name, out ExistingHash ) )
                            {
                                // Compare the length as an easy out
                                bool HashMatches = false;
                                if( ExistingHash.Length == HashValue.Length )
                                {
                                    // Compare each entry in the hash value
                                    HashMatches = true;
                                    for( Int32 Index = 0; Index < ExistingHash.Length; Index++ )
                                    {
                                        if( ExistingHash[Index] != HashValue[Index] )
                                        {
                                            HashMatches = false;
                                            break;
                                        }
                                    }
                                }
                                // Report whether it matched
                                if( !HashMatches )
                                {
                                    Log( EVerbosityLevel.Informative, ELogColour.Orange, " ............     hash mismatch, updated" );
                                }
                                else
                                {
                                    Log( EVerbosityLevel.Verbose, ELogColour.Green, " ............     hash validated" );
                                }
                                // Remove the entry from the old set
                                ChannelHashValues.Remove( NextFile.Name );
                            }
                            else
                            {
                                Log( EVerbosityLevel.Informative, ELogColour.Orange, " ............     hash missing, updated" );
                            }
                        }

                        if( AllFilesUpdated )
                        {
                            // Report all remaining hashes that do not correspond to existing files
                            if( ChannelHashValues.Count > 0 )
                            {
                                Log( EVerbosityLevel.Informative, ELogColour.Orange, " ............ Found orphaned hashes for the following missing channels:" );
                                foreach( string OrphanChannelName in ChannelHashValues.Keys )
                                {
                                    Log( EVerbosityLevel.Informative, ELogColour.Orange, " ............     " + OrphanChannelName );
                                }
                                // Clear out the old set
                                ChannelHashValues.Clear();
                            }

                            // Set the new, validated set
                            ChannelHashValues = ValidatedChannelHashValues;

                            Log( EVerbosityLevel.Informative, ELogColour.Green, "[MaintainCache] Cache hashes validated and up to date" );
                        }

                        // Reset the requesting boolean
                        CacheValidateRequested = false;
                    }
                    // Otherwise, if it's been long enough since we last ran the clean up routine
                    else if (DateTime.UtcNow > NextCleanUpCacheTime)
                    {
                        Log( EVerbosityLevel.Verbose, ELogColour.Green, "[MaintainCache] Performing cache clean up" );

                        Thread CacheAgingThread = new Thread( new ThreadStart( CacheAgingThreadProc ) );
                        CacheAgingThread.Name = "Cache Aging Thread";
                        CacheAgingThread.Start();

                        bool KeepRunning = true;
                        while( KeepRunning )
                        {
                            // If a local connection request comes in, quit immediately
                            if( LocalConnectionRequestWaiting.WaitOne( 0 ) )
                            {
                                CacheAgingThread.Abort();
                                KeepRunning = false;
                            }
                            else if( CacheAgingThread.Join( 100 ) )
                            {
                                // If the thread is done, quit
                                KeepRunning = false;
                            }
                        }

                        // Set the next clean up time
                        NextCleanUpCacheTime = DateTime.UtcNow + TimeSpan.FromMinutes(10);

                        Log( EVerbosityLevel.Verbose, ELogColour.Green, "[MaintainCache] Cache clean up complete" );
                    }
                }
            }
        }
Ejemplo n.º 5
0
		public AgentJobRecord()
		{
			Specification = null;
			WorkerAgentNames = new List<string>();
			WorkerAgentIPAddresses = new List<string>();
			AllTasks = new ReaderWriterDictionary<AgentGuid, AgentTask>();
			AgentToGoldenTaskQueueMapping = new ReaderWriterDictionary<string, Queue<AgentTask>>();
			AgentToTaskQueueMapping = new ReaderWriterDictionary<string, Queue<AgentTask>>();
		}
Ejemplo n.º 6
0
 public PropertyIndexer(int fixSize)
 {
     m_propDict = new ReaderWriterDictionary <int, int>(fixSize);
 }
Ejemplo n.º 7
0
 public PropertyIndexer()
 {
     m_propDict = new ReaderWriterDictionary <int, int>();
 }
Ejemplo n.º 8
0
		public PerfTimer()
		{
			Timings = new ReaderWriterDictionary<String, PerfTiming>();
			LastTimers = new Stack<PerfTiming>();
		}
Ejemplo n.º 9
0
		FSwarmInterface()
		{
			AgentProcess = null;
			AgentProcessOwner = false;
			Connection = null;
			ConnectionHandle = Constants.INVALID;
			ConnectionMessageThread = null;
			ConnectionMonitorThread = null;
			ConnectionConfiguration = null;
			ConnectionCallback = null;
			BaseChannelHandle = 0;
			PendingTasks = null;
			NetworkChannel = null;
			PerfTimerInstance = null;

			OpenChannels = new ReaderWriterDictionary<Int32, ChannelInfo>();
			FreeChannelWriteBuffers = new Stack<byte[]>();
			CleanupClosedConnectionLock = new Object();

			// TODO: Delete old files
		}
Ejemplo n.º 10
0
		public PropertyIndexer(int fixSize)
		{
			m_propDict = new ReaderWriterDictionary<int, int>(fixSize);
		}
Ejemplo n.º 11
0
		public PropertyIndexer()
		{
			m_propDict = new ReaderWriterDictionary<int, int>();
		}