Exemplo n.º 1
0
        protected override sealed bool HandleMessages(byte[] message)
        {
            var deserd = BsonUtilities.Deserialise <BaseMessage>(message);

            switch (deserd.MessageType)
            {
            case MessageTypeEnum.Reponse:
            {
                HandleResponse(deserd as BaseResponse);
                break;
            }

            case MessageTypeEnum.Request:
            {
                HandleRequest(deserd as BaseRequest);
                break;
            }

            default:
            {
                throw new Exception("unknown stuff");
            }
            }
            return(true);
        }
Exemplo n.º 2
0
        protected override bool HandleMessages(byte[] message)
        {
            var ans = BsonUtilities.Deserialise <HandShakeOutcome>(message);

            this.state = ans.MessageType;
            Console.WriteLine($"HandShakeOutcome recieved:{state}");
            waitForLogin.Set();
            return(false);
        }
Exemplo n.º 3
0
        protected override bool HandleMessages(byte[] message)
        {
            try
            {
                HandShakeRequest msg = BsonUtilities.Deserialise <HandShakeRequest>(message);
                Console.WriteLine("HandShakeRequest rec");
                if (Config.Password.Equals(msg.AuthPassword))
                {
                    State = HandShakeState.Authorised;
                }
                else
                {
                    State = HandShakeState.NotAuthorised;
                }

                var waiter = new TaskCompletionSource <bool>();

                this.SendMessage(new HandShakeOutcome()
                {
                    MessageType = State == HandShakeState.Authorised ? MessageTypeEnum.AuthRequestOk : MessageTypeEnum.AuthRequestError,
                    ServerGuid  = State == HandShakeState.Authorised ? this._server.ServerGuid : Guid.Empty
                }, waiter);

                waiter.Task.Wait();
                if (waiter.Task.Result && State == HandShakeState.Authorised)
                {
                    if (msg.MessageType == MessageTypeEnum.ClientAuthRequest)
                    {
                        _server.ClientConnected(msg.RegisteredGuid, TemporaryID);
                    }
                    else if (msg.MessageType == MessageTypeEnum.ServerAuthRequest)
                    {
                        _server.ServerConnected(msg.RegisteredGuid, TemporaryID);
                    }
                }
                else
                {
                    _server.ConnectionFailed(this, TemporaryID);
                }
            }
            catch (Exception ex)
            {
                this.State = HandShakeState.ProtocolError;
                _server.ConnectionFailed(this, TemporaryID);
            }
            return(false);
        }
Exemplo n.º 4
0
 public void SendMessage <T>(T Message, TaskCompletionSource <bool> eventWait = null)
 {
     SendMessage(BsonUtilities.Serialise <T>(Message), false, eventWait);
 }