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); }
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); }
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); }