Ejemplo n.º 1
0
        public JsonResult CreateRoom(PlayerRoom room)
        {
            bool flag = roomList.Add(new PlayerRoom {
                TotalLimit = room.TotalLimit,
                Name       = room.Name,
                PlayerList = new List <Player>(),
            });

            if (flag)
            {
                var query       = roomList.FindAll(x => string.Equals(x.Name, room.Name));
                var queryPlayer = playerList.FindAll(x => string.Equals(x.ConnectionId, Context.ConnectionId));
                if (query != null && query.Count > 0)
                {
                    if (queryPlayer != null && queryPlayer.Count > 0)
                    {
                        queryPlayer.FirstOrDefault().RoomName = room.Name;
                        query.FirstOrDefault().PlayerList.Add(queryPlayer.FirstOrDefault());
                        Groups.Add(Context.ConnectionId, room.Name);
                        CurrentRoomList();
                        return(new JsonResult {
                            Data = new { result = true, data = JavaScriptObjectParser.Parse(roomList) }
                        });
                    }
                    else
                    {
                        return(new JsonResult {
                            Data = new { result = false }
                        });
                    }
                }
                else
                {
                    return(new JsonResult {
                        Data = new { result = false }
                    });
                }
            }
            else
            {
                return(new JsonResult {
                    Data = new { result = false }
                });
            }
        }