Ejemplo n.º 1
0
 private void Save(byte[] r, string type)
 {
     _multiStatus          = null;
     ReceivedPackets[type] = r;
 }
Ejemplo n.º 2
0
        // TODO: Currently we only support exact order, without exclusion: Info, Rules, Player.
        public byte[] Tick(byte[] response)
        {
            switch (State)
            {
            case EpStateState.Start:
                return(TransitionToInfoChallenge());

            case EpStateState.InfoChallenge: {
                _multiStatus = new MultiStatus();
                var r = _multiStatus.ProcessPacketHeader(response);
                return(r == null?TransitionToReceivingInfoState() : HandleInfoEnd(r));
            }

            case EpStateState.ReceivingInfo: {
                var r = _multiStatus.ProcessPacketHeader(response);
                return(r == null
                    ? null
                    : HandleInfoEnd(r));
            }

            case EpStateState.RulesChallenge: {
                _multiStatus = new MultiStatus();
                switch (response[4])
                {
                case ChallengeResponse: //challenge
                    return(TransitionToReceivingRulesState(response));

                case RulesResponse: //no challenge needed info
                    return(HandleRulesEnd(response));

                default:
                    throw new Exception(string.Format("Wrong packet tag: 0x{0:X} Expected: 0x41 or 0x45.", response[4]));
                }
            }

            case EpStateState.ReceivingRules: {
                var r = _multiStatus.ProcessPacketHeader(response);
                return(r != null
                    ? HandleRulesEnd(r)
                    : null);
            }

            case EpStateState.PlayerChallenge: {
                _multiStatus = new MultiStatus();
                switch (response[4])
                {
                case ChallengeResponse: //challenge
                    return(TransitionToReceivingPlayers(response));

                case PlayerResponse: //no challenge needed info
                    return(HandlePlayersEnd(response));

                default:
                    throw new Exception(string.Format("Wrong packet tag: 0x{0:X} Expected: 0x41 or 0x45.", response[4]));
                }
            }

            case EpStateState.ReceivingPlayers: {
                var r = _multiStatus.ProcessPacketHeader(response);
                return(r != null?HandlePlayersEnd(r) : null);
            }

            default: {
                throw new Exception("Is in invalid state");
            }
            }
        }