Ejemplo n.º 1
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="messageRouter">The message router.</param>
 /// <param name="messageRouterResultHandler">A MessageRouterResultHandler instance for
 /// handling possible routing actions such as accepting connection requests.</param>
 /// <param name="connectionRequestHandler">The connection request handler.</param>
 /// <param name="permittedAggregationChannels">Permitted aggregation channels.
 /// Null list means all channels are allowed.</param>
 public CommandHandler(
     MessageRouter messageRouter,
     MessageRouterResultHandler messageRouterResultHandler,
     ConnectionRequestHandler connectionRequestHandler,
     IList <string> permittedAggregationChannels = null)
 {
     _messageRouter = messageRouter;
     _messageRouterResultHandler   = messageRouterResultHandler;
     _connectionRequestHandler     = connectionRequestHandler;
     _permittedAggregationChannels = permittedAggregationChannels;
 }
Ejemplo n.º 2
0
        /// <summary>
        ///     When we get a message from a client, we handle the message here
        ///     and perform any necessary tasks.
        /// </summary>
        private void ListenerOnNetworkReceiveEvent(NetPeer peer, NetPacketReader reader, DeliveryMethod deliveryMethod)
        {
            try
            {
                // Handle ConnectionRequest as special case
                if (reader.PeekByte() == 0)
                {
                    Command.Parse(reader, out CommandHandler handler, out byte[] message);
                    ConnectionRequestHandler requestHandler = (ConnectionRequestHandler)handler;
                    requestHandler.HandleOnServer(message, peer);
                    return;
                }

                // Parse this message
                ConnectedPlayers.TryGetValue(peer.Id, out Player player);
                bool relayOnServer = Command.ParseOnServer(reader, player);

                if (relayOnServer)
                {
                    // Copy relevant message part (exclude protocol headers)
                    byte[] data = new byte[reader.UserDataSize];
                    Array.Copy(reader.RawData, reader.UserDataOffset, data, 0, reader.UserDataSize);

                    // Send this message to all other clients
                    var peers = _netServer.ConnectedPeerList;
                    foreach (var client in peers)
                    {
                        // Don't send the message back to the client that sent it.
                        if (client.Id == peer.Id)
                        {
                            continue;
                        }

                        // Send the message so the other client can stay in sync
                        client.Send(data, DeliveryMethod.ReliableOrdered);
                    }
                }
            }
            catch (Exception ex)
            {
                ChatLogPanel.PrintGameMessage(ChatLogPanel.MessageType.Error, "Error while parsing command. See log.");
                _logger.Error(ex, $"Encountered an error while reading command from {peer.EndPoint.Address}:{peer.EndPoint.Port}:");
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        ///     Called when all SpeedPauseReached commands to a request have been received.
        ///     This will allow the player to press the buttons again.
        /// </summary>
        public static void StateReached()
        {
            if (_state == SpeedPauseState.PlayingWaiting)
            {
                _state = SpeedPauseState.Playing;
            }
            else if (_state == SpeedPauseState.PausedWaiting)
            {
                _state = SpeedPauseState.Paused;

                // If a connection request is pending, we complete it here, since now all games are paused.
                if (ConnectionRequestHandler.WorldLoadingPlayer != null)
                {
                    ConnectionRequestHandler.AllGamesBlocked();
                }
            }

            Log.Debug($"[SpeedPauseHelper] State {_state} reached!");
        }
        public HandoffMiddlewareBase(IConfiguration configuration, ILoggerFactory loggerFactory)
        {
            Configuration = configuration;
            _logger       = loggerFactory.CreateLogger <HandoffMiddlewareBase>();

            string            connectionString = Configuration[KeyAzureTableStorageConnectionString];
            IRoutingDataStore routingDataStore = null;

            if (string.IsNullOrEmpty(connectionString))
            {
                _logger.LogDebug($"WARNING!!! No connection string found - using {nameof(InMemoryRoutingDataStore)}");
                routingDataStore = new InMemoryRoutingDataStore();
            }
            else
            {
                _logger.LogDebug($"Found a connection string - using {nameof(AzureTableRoutingDataStore)}");
                routingDataStore = new AzureTableRoutingDataStore(connectionString,
                                                                  new Underscore.Bot.MessageRouting.Logging.ConsoleLogger(loggerFactory.CreateLogger <AzureTableRoutingDataStore>()));
            }

            MessageRouter = new MessageRouter(
                routingDataStore,
                new MicrosoftAppCredentials(Configuration["MicrosoftAppId"], Configuration["MicrosoftAppPassword"]),
                logger: new Underscore.Bot.MessageRouting.Logging.ConsoleLogger(loggerFactory.CreateLogger <MessageRouter>())
                );

            //MessageRouter.Logger = new Logging.AggregationChannelLogger(MessageRouter);

            MessageRouterResultHandler = new MessageRouterResultHandler(MessageRouter);

            ConnectionRequestHandler connectionRequestHandler =
                new ConnectionRequestHandler(GetChannelList(KeyNoDirectConversationsWithChannels));

            CommandHandler = new CommandHandler(
                MessageRouter,
                MessageRouterResultHandler,
                connectionRequestHandler,
                GetChannelList(KeyPermittedAggregationChannels),
                new Underscore.Bot.MessageRouting.Logging.ConsoleLogger(loggerFactory.CreateLogger <CommandHandler>()));

            MessageLogs = new MessageLogs(connectionString, new Underscore.Bot.MessageRouting.Logging.ConsoleLogger(loggerFactory.CreateLogger <MessageLogs>()));
        }
Ejemplo n.º 5
0
        /// <summary>
        ///     When we get a message from a client, we handle the message here
        ///     and perform any necessary tasks.
        /// </summary>
        private void ListenerOnNetworkReceiveEvent(NetPeer peer, NetDataReader reader)
        {
            try
            {
                // Handle ConnectionRequest as special case
                if (reader.Data[0] == 0)
                {
                    Command.Parse(reader.Data, out CommandHandler handler, out byte[] message);
                    ConnectionRequestHandler requestHandler = (ConnectionRequestHandler)handler;
                    requestHandler.HandleOnServer(message, peer);
                    return;
                }

                this.ConnectedPlayers.TryGetValue(peer.ConnectId, out Player player);

                Command.ParseOnServer(reader.Data, player);
            }
            catch (Exception ex)
            {
                CSM.Log($"Encountered an error from {peer.EndPoint.Host}:{peer.EndPoint.Port} while reading command. Message: {ex.Message}");
            }
        }
Ejemplo n.º 6
0
        public HandoffMiddleware(IConfiguration configuration, ConversationState conversationState, UserState userState)
        {
            Configuration      = configuration;
            _conversationState = conversationState;
            _userState         = userState;
            string            connectionString = Configuration[KeyAzureTableStorageConnectionString];
            IRoutingDataStore routingDataStore = null;

            if (string.IsNullOrEmpty(connectionString))
            {
                System.Diagnostics.Debug.WriteLine($"WARNING!!! No connection string found - using {nameof(InMemoryRoutingDataStore)}");
                routingDataStore = new InMemoryRoutingDataStore();
            }
            else
            {
                System.Diagnostics.Debug.WriteLine($"Found a connection string - using {nameof(AzureTableRoutingDataStore)}");
                routingDataStore = new AzureTableRoutingDataStore(connectionString);
            }

            MessageRouter = new MessageRouter(
                routingDataStore,
                new MicrosoftAppCredentials(Configuration["MicrosoftAppId"], Configuration["MicrosoftAppPassword"]));

            //MessageRouter.Logger = new Logging.AggregationChannelLogger(MessageRouter);

            MessageRouterResultHandler = new MessageRouterResultHandler(MessageRouter);

            ConnectionRequestHandler connectionRequestHandler =
                new ConnectionRequestHandler(GetChannelList(KeyNoDirectConversationsWithChannels));

            CommandHandler = new CommandHandler(
                MessageRouter,
                MessageRouterResultHandler,
                connectionRequestHandler,
                GetChannelList(KeyPermittedAggregationChannels));

            MessageLogs = new MessageLogs(connectionString);
        }
Ejemplo n.º 7
0
        /// <summary>
        ///     When we get a message from a client, we handle the message here
        ///     and perform any necessary tasks.
        /// </summary>
        private void ListenerOnNetworkReceiveEvent(NetPeer peer, NetDataReader reader)
        {
            try
            {
                // Handle ConnectionRequest as special case
                if (reader.Data[0] == 0)
                {
                    Command.Parse(reader.Data, out CommandHandler handler, out byte[] message);
                    ConnectionRequestHandler requestHandler = (ConnectionRequestHandler)handler;
                    requestHandler.HandleOnServer(message, peer);
                    return;
                }

                // Parse this message
                ConnectedPlayers.TryGetValue(peer.ConnectId, out Player player);
                Command.ParseOnServer(reader.Data, player);

                // Send this message to all other clients
                var peers = _netServer.GetPeers();
                foreach (var client in peers)
                {
                    // Don't send the message back to the client that sent it.
                    if (client.ConnectId == peer.ConnectId)
                    {
                        continue;
                    }

                    // Send the message so the other client can stay in sync
                    client.Send(reader.Data, SendOptions.ReliableOrdered);
                }
            }
            catch (Exception ex)
            {
                CSM.Log($"Encountered an error while reading command from {peer.EndPoint.Host}:{peer.EndPoint.Port}:");
                CSM.Log(ex.ToString());
            }
        }
Ejemplo n.º 8
0
 /// <summary>
 /// Sets a callback handler for connection request. The user can allow (returning true) or deny (returning false)
 /// the connection attempt. If no handler is installed every new connection will be accepted.
 /// </summary>
 /// <param name="handler">Handler.</param>
 /// <param name="parameter">Parameter.</param>
 public void SetConnectionRequestHandler(ConnectionRequestHandler handler, object parameter)
 {
     this.connectionRequestHandler          = handler;
     this.connectionRequestHandlerParameter = parameter;
 }
Ejemplo n.º 9
0
 // REQUIRED FOR IN-SKILL PURHCASES TO WORK
 public Function()
 {
     ConnectionRequestHandler.AddToRequestConverter();
 }