Beispiel #1
0
        public ShamanClientPeerLegacy(IMessageDeserializer messageDeserializer, IShamanLogger logger, ITaskSchedulerFactory taskSchedulerFactory, int pollPackageQueueIntervalMs, ISerializer serializer, IRequestSender requestSender, bool startOtherThreadMessageProcessing = true, int maxPacketSize = 300, int sendTickMs = 33)
        {
            _status = ClientStatusLegacy.Offline;

            _messageDeserializer = messageDeserializer;
            _logger        = logger;
            _taskScheduler = taskSchedulerFactory.GetTaskScheduler();
            _serializer    = serializer;
//            _serializer.InitializeDefaultSerializers(0, "client");
            _clientPeer    = new ClientPeer(logger, taskSchedulerFactory, maxPacketSize, sendTickMs);
            _requestSender = requestSender;
            _clientPeer.OnDisconnectedFromServer += (reason) =>
            {
                switch (_status)
                {
                case ClientStatusLegacy.ConnectingGameServer:
                case ClientStatusLegacy.AuthorizingGameServer:
                case ClientStatusLegacy.JoiningRoom:
                case ClientStatusLegacy.InRoom:
                case ClientStatusLegacy.LeavingRoom:
                    OnDisconnectedFromGameServer?.Invoke(reason);
                    break;

                case ClientStatusLegacy.ConnectingMatchMaking:
                case ClientStatusLegacy.AuthorizingMatchMaking:
                case ClientStatusLegacy.JoiningMatchMaking:
                case ClientStatusLegacy.OnMatchMaking:
                case ClientStatusLegacy.LeavingMatchMaking:
                    OnDisconnectedFromMmServer?.Invoke(reason);
                    break;
                }
                OnDisconnected?.Invoke(reason);
                ResetState();
            };
            _pollPackageQueueIntervalMs = pollPackageQueueIntervalMs;

            if (startOtherThreadMessageProcessing)
            {
                StartProcessingMessagesLoop();
            }
        }