예제 #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);
        }
예제 #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);
        }
예제 #3
0
파일: Logout.cs 프로젝트: McBits/DungeonR
 public LogoutCmd(Connection connection) : base(connection)
 {
     AccessLevel = None;
 }
예제 #4
0
파일: Unhide.cs 프로젝트: McBits/DungeonR
 public UnhideCmd(Connection connection)
     : base(connection)
 {
 }
예제 #5
0
파일: Register.cs 프로젝트: McBits/DungeonR
 public RegisterCmd(Connection connection) : base(connection)
 {
     this.AccessLevel = None;
 }
예제 #6
0
파일: Get.cs 프로젝트: McBits/DungeonR
 public GetCmd(Connection connection)
     : base(connection)
 {
 }
예제 #7
0
파일: Drop.cs 프로젝트: McBits/DungeonR
 public DropCmd(Connection connection)
     : base(connection)
 {
 }
예제 #8
0
파일: Eat.cs 프로젝트: McBits/DungeonR
 public EatCmd(Connection connection)
     : base(connection)
 {
 }
예제 #9
0
파일: Give.cs 프로젝트: McBits/DungeonR
 public GiveCmd(Connection connection)
     : base(connection)
 {
 }
예제 #10
0
파일: Score.cs 프로젝트: McBits/DungeonR
 public ScoreCmd(Connection connection) : base(connection)
 {
     AccessLevel = Guest;
 }
예제 #11
0
파일: Attack.cs 프로젝트: McBits/DungeonR
 public AttackCmd(Connection connection) : base(connection) { }
예제 #12
0
 public MoveToSceneCmd(Connection connection)
     : base(connection)
 {
 }
예제 #13
0
파일: HideItem.cs 프로젝트: McBits/DungeonR
 public HideItemCmd(Connection connection)
     : base(connection)
 {
 }
예제 #14
0
파일: Use.cs 프로젝트: McBits/DungeonR
 public UseCmd(Connection connection)
     : base(connection)
 {
 }
예제 #15
0
파일: Put.cs 프로젝트: McBits/DungeonR
 public PutCmd(Connection connection)
     : base(connection)
 {
 }