Esempio n. 1
0
        public GameService(IWebSocketConnection connection, IComponents components)
        {
            this.connection = connection;

            connection.OnOpen    += OnConnectionEstablished;
            connection.OnClose   += OnConnectionClosed;
            connection.OnError   += OnErrorOccurred;
            connection.OnMessage += OnMessageReceived;

            id = components.Get <IIdGenerator>().GenerateId();
            sessionCollection   = components.Get <IWebSocketSessionCollection>();
            gameSceneCollection = components.Get <IGameSceneCollection>();

            jsonSerializer    = new NativeJsonSerializer();
            handlerCollection = new MessageHandlerCollection(jsonSerializer);
            player            = new PlayerGameObject(id, new IComponent[]
            {
                new AnimationData(),
                new CharacterData(),
                new PresenceMapProvider(),
                new MessageSender(jsonSerializer),
                new PositionChangedMessageSender(),
                new AnimationStateChangedMessageSender(),
                new PlayerAttackedMessageSender(),
                new BubbleNotificationMessageSender()
            });
        }
Esempio n. 2
0
        public TestServiceController(string id, IWebSocketConnection connection) : base(id, connection)
        {
            this.Connection.RequestTimeout = TimeSpan.FromSeconds(5);

            this.MessageHandlerCollection = MessageHandlerCollectionBuilder
                                            .Create()
                                            .SetHandler("echo", async message => await this.Connection.SendMessage(message.CreateResponse(message.GetBody <object>())))
                                            .SetHandler("id", async message => await this.Connection.SendMessage(message.CreateResponse(id)))
                                            .SetHandler("Exception", (m) => throw new Exception($"You asked me to throw an exception:\n{m}"))
                                            .SetDefaultHandler(async message => await this.Connection.SendMessage(message.CreateResponse(new
            {
                ThisIs      = "A response",
                RequestBody = message,
            })))
                                            .Build();
        }
 public TestClientController(IWebSocketConnection connection) : base(connection)
 {
     this.Handlers = MessageHandlerCollectionBuilder
                     .Create()
                     .Build();
 }