Exemplo n.º 1
0
        public async Task ProcessWebSocket(HttpContext context, WebSocket webSocket)
        {
            var connection = new Connection(context, webSocket);
            Console.WriteLine("Connect: {0}", context.Connection.RemoteIpAddress);

            var cancelToken = CancellationToken.None;
            var buffer = new byte[1024];
            WebSocketReceiveResult received =
                await webSocket.ReceiveAsync(new ArraySegment<byte>(buffer), cancelToken);

            while (!webSocket.CloseStatus.HasValue)
            {
                string text = System.Text.Encoding.UTF8.GetString(buffer, 0, received.Count);

                Console.WriteLine("Recd: {0}", text);

                try
                {
                    Cmd.Parse(text, connection)?.Run();
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Unhandled exception: {0}", ex);
                }

                received = await webSocket.ReceiveAsync(new ArraySegment<byte>(buffer), cancelToken);
            }

            await webSocket.CloseAsync(webSocket.CloseStatus.Value, webSocket.CloseStatusDescription, cancelToken);
        }
Exemplo n.º 2
0
        public async Task ProcessWebSocket(HttpContext context, WebSocket webSocket)
        {
            var connection = new Connection(context, webSocket);
            _allConnections.Add(connection);
            Console.WriteLine("Connect: {0}", context.Connection.RemoteIpAddress);

            var cancelToken = CancellationToken.None;
            var buffer = new byte[1024];
            WebSocketReceiveResult received =
                await webSocket.ReceiveAsync(new ArraySegment<byte>(buffer), cancelToken);

            while (!webSocket.CloseStatus.HasValue)
            {
                string text = System.Text.Encoding.UTF8.GetString(buffer, 0, received.Count);

                Console.WriteLine("Recd: {0}", text);

                try
                {
                    var cmd = Cmd.Parse(text, connection);
                    if (cmd != null) {
                        // TODO: Remove these dependencies from Cmd
                        cmd.SpawnDaemon = _spawnDaemon;
                        cmd.DecayDaemon = _decayDaemon;
                        cmd.Run();
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Unhandled exception: {0}", ex);
                }

                received = await webSocket.ReceiveAsync(new ArraySegment<byte>(buffer), cancelToken);
            }

            _allConnections.Remove(connection);
            await webSocket.CloseAsync(webSocket.CloseStatus.Value, webSocket.CloseStatusDescription, cancelToken);
        }
Exemplo n.º 3
0
 public LogoutCmd(Connection connection) : base(connection)
 {
     AccessLevel = None;
 }
Exemplo n.º 4
0
 public UnhideCmd(Connection connection)
     : base(connection)
 {
 }
Exemplo n.º 5
0
 public RegisterCmd(Connection connection) : base(connection)
 {
     this.AccessLevel = None;
 }
Exemplo n.º 6
0
 public GetCmd(Connection connection)
     : base(connection)
 {
 }
Exemplo n.º 7
0
 public DropCmd(Connection connection)
     : base(connection)
 {
 }
Exemplo n.º 8
0
 public EatCmd(Connection connection)
     : base(connection)
 {
 }
Exemplo n.º 9
0
 public GiveCmd(Connection connection)
     : base(connection)
 {
 }
Exemplo n.º 10
0
 public ScoreCmd(Connection connection) : base(connection)
 {
     AccessLevel = Guest;
 }
Exemplo n.º 11
0
 public AttackCmd(Connection connection) : base(connection) { }
Exemplo n.º 12
0
 public MoveToSceneCmd(Connection connection)
     : base(connection)
 {
 }
Exemplo n.º 13
0
 public HideItemCmd(Connection connection)
     : base(connection)
 {
 }
Exemplo n.º 14
0
 public UseCmd(Connection connection)
     : base(connection)
 {
 }
Exemplo n.º 15
0
 public PutCmd(Connection connection)
     : base(connection)
 {
 }