/// <summary>
        /// Establishes the handshake with the server.
        /// </summary>
        /// <returns></returns>
        private bool EstablishHandshake()
        {
            Logger.Info("Attempting to establish a handshake...");

            //We are establishing a lock and not releasing it until we sent the handshake message.
            // We need to set the key, and it would not be nice if someone did things between us setting the key.
            lock (l_states)
            {
                //Check its state
                if (_state != RpcState.Disconnected)
                {
                    Logger.Error("State must be disconnected in order to start a handshake!");
                    return(false);
                }

                //Send it off to the server
                Logger.Info("Sending Handshake...");
                if (!namedPipe.WriteFrame(new PipeFrame(Opcode.Handshake, new Handshake()
                {
                    Version = VERSION, ClientID = applicationID
                })))
                {
                    Logger.Error("Failed to write a handshake.");
                    return(false);
                }

                _state = RpcState.Connecting;
            }

            //Success
            return(true);
        }
Exemplo n.º 2
0
 public static void updateState(RpcState state)
 {
     BRSLog("Updating state to '" + state.StateName() + "'");
     rpcState       = state;
     presence.state = "State: " + state.StateName();
     DiscordRpc.UpdatePresence(presence);
 }
 /// <summary>
 /// Sets the current state of the pipe, locking the l_states object for thread saftey.
 /// </summary>
 /// <param name="state">The state to set it too.</param>
 private void SetConnectionState(RpcState state)
 {
     Logger.Info("Setting the connection state to {0}", state.ToString().ToSnakeCase().ToUpperInvariant());
     lock (l_states)
     {
         _state = state;
     }
 }
Exemplo n.º 4
0
 /// <summary>
 /// Sets the current state of the pipe, locking the l_states object for thread saftey.
 /// </summary>
 /// <param name="state">The state to set it too.</param>
 private void SetConnectionState(RpcState state)
 {
     Console.WriteLine($"Setting the connection state to {state.ToString().ToSnakeCase().ToUpperInvariant()}");
     lock (l_states)
     {
         _state = state;
     }
 }
Exemplo n.º 5
0
        public static string StateName(this RpcState state)
        {
            switch (state)
            {
            case RpcState.EDITMODE: return("Edit mode");

            case RpcState.PLAYMODE: return("Play mode");

            case RpcState.UPLOADPANEL: return("Upload panel");

            default: return("Error");
            }
        }
Exemplo n.º 6
0
        public static string StateName(this RpcState state)
        {
            switch (state)
            {
            case RpcState.EDITMODE: return("Modifying");

            case RpcState.PLAYMODE: return("Testing");

            case RpcState.UPLOADPANEL: return("Uploading");

            default: return("Fucky Wucky");
            }
        }
Exemplo n.º 7
0
        public static IServices Init(RequiredServices services)
        {
            AddDecoders();
            var config          = services.NdmConfig;
            var providerAddress = string.IsNullOrWhiteSpace(config.ProviderAddress)
                ? Address.Zero
                : new Address(config.ProviderAddress);
            var consumerAddress = string.IsNullOrWhiteSpace(config.ConsumerAddress)
                ? Address.Zero
                : new Address(config.ConsumerAddress);

            UnlockHardcodedAccounts(providerAddress, consumerAddress, services.Wallet);
            var readOnlyDbProvider = new ReadOnlyDbProvider(services.RocksProvider, false);
            var filterStore        = new FilterStore();
            var filterManager      = new FilterManager(filterStore, services.BlockProcessor, services.TransactionPool,
                                                       services.LogManager);
            var state = new RpcState(services.BlockTree, services.SpecProvider, readOnlyDbProvider,
                                     services.LogManager);
            var blockchainBridge = new BlockchainBridge(
                state.StateReader,
                state.StateProvider,
                state.StorageProvider,
                state.BlockTree,
                services.TransactionPool,
                services.TransactionPoolInfoProvider,
                services.ReceiptStorage,
                filterStore,
                filterManager,
                services.Wallet,
                state.TransactionProcessor,
                services.Ecdsa);
            var dataHeaderRlpDecoder = new DataHeaderDecoder();
            var encoder        = new AbiEncoder();
            var depositService = new DepositService(blockchainBridge, encoder, services.Wallet, config,
                                                    LimboLogs.Instance);
            var ndmConsumerChannelManager = services.NdmConsumerChannelManager;
            var ndmDataPublisher          = services.NdmDataPublisher;
            var jsonRpcNdmConsumerChannel = new JsonRpcNdmConsumerChannel();

//            ndmConsumerChannelManager.Add(jsonRpcNdmConsumerChannel);

            return(new Services(services, new CreatedServices(consumerAddress, encoder, dataHeaderRlpDecoder,
                                                              depositService, ndmDataPublisher, jsonRpcNdmConsumerChannel, ndmConsumerChannelManager,
                                                              blockchainBridge)));
        }
 private void SetConnectionState(RpcState state)
 {
     this.Logger.Info("Setting the connection state to {0}", (object)state.ToString().ToSnakeCase().ToUpperInvariant());
     lock (this.l_states)
         this._state = state;
 }
        /// <summary>Handles the response from the pipe and calls appropriate events and changes states.</summary>
        /// <param name="response">The response received by the server.</param>
        private void ProcessFrame(EventPayload response)
        {
            Logger.Info("Handling Response. Cmd: {0}, Event: {1}", response.Command, response.Event);

            //Check if it is an error
            if (response.Event.HasValue && response.Event.Value == ServerEvent.Error)
            {
                //We have an error
                Logger.Error("Error received from the RPC");

                //Create the event objetc and push it to the queue
                ErrorMessage err = response.GetObject <ErrorMessage>();
                Logger.Error("Server responded with an error message: ({0}) {1}", err.Code.ToString(), err.Message);

                //Enqueue the messsage and then end
                EnqueueMessage(err);
                return;
            }

            //Check if its a handshake
            if (State == RpcState.Connecting)
            {
                if (response.Command == Command.Dispatch && response.Event.HasValue && response.Event.Value == ServerEvent.Ready)
                {
                    Logger.Info("Connection established with the RPC");
                    lock (l_states) _state = RpcState.Connected;

                    //Prepare the object
                    ReadyMessage ready = response.GetObject <ReadyMessage>();
                    lock (l_config)
                    {
                        _configuration = ready.Configuration;
                        ready.User.SetConfiguration(_configuration);
                    }

                    //Enqueue the message
                    EnqueueMessage(ready);
                    return;
                }
            }

            if (State == RpcState.Connected)
            {
                switch (response.Command)
                {
                //We were sent a dispatch, better process it
                case Command.Dispatch:
                    ProcessDispatch(response);
                    break;

                //We were sent a Activity Update, better enqueue it
                case Command.SetActivity:
                    if (response.Data == null)
                    {
                        EnqueueMessage(new PresenceMessage());
                    }
                    else
                    {
                        RichPresenceResponse rp = response.GetObject <RichPresenceResponse>();
                        EnqueueMessage(new PresenceMessage(rp));
                    }
                    break;

                case Command.Unsubscribe:
                case Command.Subscribe:

                    //Prepare a serializer that can account for snake_case enums.
                    JsonSerializer serializer = new JsonSerializer();
                    serializer.Converters.Add(new Converters.EnumSnakeCaseConverter());

                    //Go through the data, looking for the evt property, casting it to a server event
                    var evt = response.Data.GetValue("evt").ToObject <ServerEvent>(serializer);

                    //Enqueue the appropriate message.
                    if (response.Command == Command.Subscribe)
                    {
                        EnqueueMessage(new SubscribeMessage(evt));
                    }
                    else
                    {
                        EnqueueMessage(new UnsubscribeMessage(evt));
                    }

                    break;


                case Command.SendActivityJoinInvite:
                    Logger.Info("Got invite response ack.");
                    break;

                case Command.CloseActivityJoinRequest:
                    Logger.Info("Got invite response reject ack.");
                    break;

                //we have no idea what we were sent
                default:
                    Logger.Error("Unkown frame was received! {0}", response.Command);
                    return;
                }
                return;
            }

            Logger.Info("Received a frame while we are disconnected. Ignoring. Cmd: {0}, Event: {1}", response.Command, response.Event);
        }