Пример #1
0
        public Resources()
        {
            Configuration = new Configuration();
            Configuration.Initialize();

            _logger = new Logger();

            Csv         = new Csv();
            Fingerprint = new Fingerprint();

            _mysql = new MySQL();

            if (!string.IsNullOrEmpty(Configuration.RedisPassword) && !string.IsNullOrEmpty(Configuration.RedisServer))
            {
                _redis = new Redis();
            }

            _messagefactory      = new LogicMagicMessageFactory();
            _commandfactory      = new LogicCommandManager();
            _debugcommandfactory = new DebugCommandFactory();

            Levels           = new Levels();
            PlayerCache      = new PlayerCache();
            AllianceCache    = new AllianceCache();
            LeaderboardCache = new LeaderboardCache();

            ChatManager = new LogicGlobalChatManager();

            Gateway = new Gateway();
        }
Пример #2
0
 public void Dispose()
 {
     Csv                  = null;
     Gateway              = null;
     PlayerCache          = null;
     Configuration        = null;
     Levels               = null;
     Fingerprint          = null;
     _messagefactory      = null;
     _commandfactory      = null;
     _debugcommandfactory = null;
     _mysql               = null;
     _logger              = null;
 }
Пример #3
0
        public Resources()
        {
            Configuration = new Configuration();
            Configuration.Initialize();

            _logger = new Logger();

            Logger.Log($"ENV: {(Utils.IsLinux ? "Linux" : "Windows")}");

            Csv         = new Csv();
            Fingerprint = new Fingerprint();

            _playerDb   = new PlayerDb();
            _replayDb   = new ReplayDb();
            _allianceDb = new AllianceDb();

            if (!string.IsNullOrEmpty(Configuration.RedisPassword) && !string.IsNullOrEmpty(Configuration.RedisServer))
            {
                _redis = new Redis();
            }

            _messagefactory      = new LogicMagicMessageFactory();
            _commandfactory      = new LogicCommandManager();
            _debugcommandfactory = new DebugCommandFactory();

            Levels           = new Levels();
            PlayerCache      = new PlayerCache();
            AllianceCache    = new AllianceCache();
            LeaderboardCache = new LeaderboardCache();

            ChatManager = new LogicGlobalChatManager();

            Gateway = new Gateway();

            StartDateTime = DateTime.UtcNow;

            Gateway.StartAsync().Wait();
        }
Пример #4
0
        /// <summary>
        ///     Called when the connection receive a block of bytes.
        /// </summary>
        public void OnReceive(Connection connection)
        {
            byte[] buffer = this._connection.Buffer;
            int    length = buffer.Length;

            if (length >= 7)
            {
                length -= 7;

                int messageType    = buffer[1] | (buffer[0] << 8);
                int messageLength  = buffer[4] | (buffer[3] << 8) | (buffer[2] << 16);
                int messageVersion = buffer[6] | (buffer[5] << 8);

                if (length >= messageLength)
                {
                    this._connection.RemoveBlocking(messageLength + 7);

                    byte[] encodingByteArray = new byte[messageLength];
                    Array.Copy(buffer, 7, encodingByteArray, 0, messageLength);

                    if (this._receiveEncrypter != null)
                    {
                        byte[] encryptedByteArray = encodingByteArray;
                        byte[] decryptedByteArray = new byte[messageLength - this._receiveEncrypter.GetOverheadEncryption()];

                        Array.Copy(buffer, 7, encryptedByteArray, 0, messageLength);

                        this._receiveEncrypter.Decrypt(encryptedByteArray, decryptedByteArray, messageLength);

                        encodingByteArray = decryptedByteArray;
                    }

                    PiranhaMessage message = LogicMagicMessageFactory.CreateMessageByType(messageType);

                    if (message != null)
                    {
                        message.SetMessageVersion((short)messageVersion);
                        message.GetByteStream().SetByteArray(encodingByteArray, messageLength);

                        if (this._pepperState != 1)
                        {
                            if (this._pepperState == 2)
                            {
                                this._receiveMessageQueue.Enqueue(message);
                            }

                            message.Decode();

                            this._receiveMessageQueue.Enqueue(message);

                            Debugger.Log("Messaging::onReceive message " + message.GetType().Name + " received");
                        }
                    }
                    else
                    {
                        Debugger.Warning("Messaging::onReceive ignoring message of unknown type " + messageType);
                    }

                    if (length - messageLength >= 7)
                    {
                        this.OnReceive(connection);
                    }
                }
            }
        }