示例#1
0
        public ActionResult JoinRoom(int id)
        {
            var recall = ReCallUserGameRoom(id);

            if (recall == "waitroom")
            {
                return(RedirectToAction("WaitRoom", "Room", new { id }));
            }

            var isGameStart = IsGameStart(Singleton.User().UserId, id);

            if (isGameStart)
            {
                return(RedirectToAction("Index", "GameStart", new { id }));
            }

            RenderJobType(null);
            RenderAvartar(null);
            var model = new GameRoomModel
            {
                GameRoomId = id,
            };

            return(View("Join", model));
        }
        public async Task <IActionResult> Edit(string id, [Bind("Id,GameCode,UserCount,MaxUserCount,IsOpen,CreationTime")] GameRoomModel gameRoom)
        {
            if (id != gameRoom.GameCode)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    await gameRepo.UpdateGameRoomAsync(gameRoom);
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (null == gameRepo.FindGameRoom(gameRoom.GameCode))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(gameRoom));
        }
        public async Task <IActionResult> LeaveGameRoom([FromHeader] string authToken)
        {
            var errMsg = string.Empty;

            var user   = UserContext.User;
            var room   = user.GameRoomRef;
            var roomId = room.Id;

            //todo wtf again with UserContext.User....UserContext.User?
            user.GameRoomRef.Leave(user);

            if (user.GameRoomRef != null)
            {
                return(await GenericResponse(ResponseType.UnexpectedError, Constants.Instance.ErrorMessage.You_Cant_Leave_This_Game_Room));
            }

            if (user.GameRoomRef != null && room.Players.Count == 0)
            {
                ServerContext.Current.Chat.DropChannel(user, roomId);
            }

            var broadcast = new GameRoomModel(room).GetInfo(new RoomModelViewOptions()
            {
                UserCount       = true,
                UserViewOptions = new UserModelViewOptions(false)
                {
                    Id = true
                }
            }).AddItem(BroadcastReason, Request.Path.Value);

            ServerContext.Current.DuplexNetwork.Broadcast(broadcast, room.Id, SubscriberType.Room);

            //todo why it is possible you couldn't leave room? Need to determine corrent status code here
            return(await SuccessResponse(true));
        }
        public async Task <IActionResult> SetReadyMarkTo([FromHeader] string authToken, [FromBody] ToggleReadyModel toggleModel)
        {
            var user = UserContext.User;

            var toggleResponse = EnergoServer.Current.RouteAction(new ToggleReadyAction(user, toggleModel.State));

            //there are couldn't be actually errors, because current method is expecting you are in game and we user
            //YOUR (user) game for sure. So only possible is Unexpected error
            if (!toggleResponse.IsSuccess)
            {
                return(await GenericResponse(ResponseType.UnexpectedError, toggleResponse.ErrorMsg));
            }

            var room      = user.GameRoomRef;
            var broadcast = new GameRoomModel(room).GetInfo(new RoomModelViewOptions()
            {
                UserViewOptions = new UserModelViewOptions(false)
                {
                    ReadyMark = true, Id = true
                }
            }).AddItem(BroadcastReason, Request.Path.Value);

            ServerContext.Current.DuplexNetwork.Broadcast(broadcast, room.Id, SubscriberType.Room);

            return(await SuccessResponse(toggleResponse.CurrentState));
        }
        public async Task <IActionResult> StartGame([FromHeader] string authToken)
        {
            var user = UserContext.User;

            //todo start game only if creator

            var startResponse = EnergoServer.Current.RouteAction(new StartGameAction(user));

            if (!startResponse.IsSuccess)
            {
                return(await GenericResponse(ResponseType.NotAllowed, errMsg : startResponse.ErrorMsg));
            }

            var broadcast = new GameRoomModel(user.GameRoomRef).GetInfo(new RoomModelViewOptions()
            {
                Id              = true,
                IsInGame        = true,
                UserCount       = true,
                UserViewOptions = new UserModelViewOptions(false)
            }).AddItem(BroadcastReason, Request.Path.Value);

            ServerContext.Current.DuplexNetwork.Broadcast(broadcast);

            return(await GenericResponse(ResponseType.Ok, data : startResponse));
        }
示例#6
0
        private GameWindow(GameRoomModel room, PlayerModel player, HttpClient client)
        {
            InitializeComponent();

            _client = client;
            _player = player;
            _room   = room;

            _boomModels = new ConcurrentStack <BoomModel>();
            _explosions = new List <Explosion>();
            // TODO RK: Chwilowo jest statycznie wstawiane ile żyć jak i ilość czołgów - potem dodawać ładniej
            _tanks = new List <Tank>()
            {
                new Tank(7.5f, 0)
                {
                    FillColor = Color.Green, Position = new Vector2f(100f, 400f)
                },
                new Tank(7.5f, 1)
                {
                    FillColor = Color.Magenta, Position = new Vector2f(650f, 400f), TurretAngle = -90,
                },
            };
            _tanks.ForEach(tank => tank.TankHp = 4);
            _bullets = new List <Bullet>();
            _colBox  = new FrameCollisionBox();

            CreateRenderWindow();
            CreateSignalRRequestLoop();
        }
示例#7
0
        public async Task <GameRoomModel> CreateGameRoomAsync(GameRoomModel gameRoom)
        {
            await db.AddAsync(gameRoom);

            await db.SaveChangesAsync();

            return(gameRoom);
        }
示例#8
0
        public async Task DeleteGameRoomAsync(GameRoomModel gameRoom)
        {
            var users = db.GameUser.Where(u => u.GameRoomId == gameRoom.Id);

            db.GameUser.RemoveRange(users);
            db.Remove(gameRoom);
            await db.SaveChangesAsync();
        }
示例#9
0
        public static async Task <GameWindow> Create(GameRoomModel room, PlayerModel player, HttpClient client)
        {
            var window = new GameWindow(room, player, client);
            await window.InitHub();

            window.Text += $" - player {player.IdInMatch}";
            return(window);
        }
示例#10
0
        private GameUserModel JoinGameUser(string userId, GameRoomModel gameRoom)
        {
            var gameUser = FindGameUser(userId);

            gameUser.GameRoomId = gameRoom.Id;
            db.Update(gameUser);
            db.SaveChanges();

            return(gameUser);
        }
示例#11
0
        private async Task <GameRoomModel> GetActualRoomMate(int Id)
        {
            GameRoomModel       room     = null;
            HttpResponseMessage response = await client.GetAsync($"api/GameRooms/{this.room.Id}");

            if (response.IsSuccessStatusCode)
            {
                room = await response.Content.ReadAsAsync <GameRoomModel>();
            }
            return(room);
        }
示例#12
0
 public PublicRoom(Uri logged, GameRoomModel room, HttpClient clt, UserModel user, PlayerModel player)
 {
     this.url    = logged;
     this.user   = user;
     this.player = player;
     client      = clt;
     this.room   = room;
     InitializeComponent();
     t = new Thread(checkUsers);
     t.Start();
 }
示例#13
0
        private async Task <GameRoomModel> GetRoomAsync(string path)
        {
            GameRoomModel       room     = null;
            HttpResponseMessage response = await client.GetAsync(path);

            if (response.IsSuccessStatusCode)
            {
                room = await response.Content.ReadAsAsync <GameRoomModel>();
            }
            return(room);
        }
示例#14
0
        public async Task <IActionResult> Create([Bind("Id,GameCode,UserCount,MaxUserCount,IsOpen,CreationTime")] GameRoomModel gameRoom)
        {
            if (ModelState.IsValid)
            {
                gameRoom.Validate();
                await gameRepo.CreateGameRoomAsync(gameRoom.MaxUserCount);

                return(RedirectToAction(nameof(Index)));
            }
            return(View(gameRoom));
        }
示例#15
0
        public ActionResult GetPlayerResult(int id)
        {
            var userGameRoom = _service.GameRoom().GetAllUserGameRoom(id);
            var model        = new GameRoomModel
            {
                GameRoomId    = id,
                UserGameRooms = userGameRoom.OrderByDescending(x => x.MoneyValue).ToList()
            };

            return(PartialView("_PlayerResult", model));
        }
示例#16
0
        private async Task <GameRoomModel> AddPlayerToRoomAsync(int id)
        {
            GameRoomModel       room     = null;
            HttpResponseMessage response = await client.GetAsync($"api/GameRooms/FindEmptyRoom/ForUser/{id}");

            response.EnsureSuccessStatusCode();
            if (response.IsSuccessStatusCode)
            {
                room = await response.Content.ReadAsAsync <GameRoomModel>();
            }
            return(room);
        }
示例#17
0
        public ActionResult WaitRoom(int id)
        {
            ReCallUserGameRoom(id);
            var gameRoom = _service.GameRoom().GetRoomById(id);
            var model    = new GameRoomModel
            {
                GameRoomId   = id,
                SoftwareType = gameRoom.SoftwareType,
                MoneyInGame  = gameRoom.MoneyValue,
            };

            return(View("WaitRoom", model));
        }
示例#18
0
 public void SetGameRoom(GameRoomModel game)
 {
     if (null != game)
     {
         gameCodeText.text = game.GameCode;
         SetReadyInfo(game);
     }
     else
     {
         gameCodeText.text  = "****";
         readyInfoText.text = "0 / 0";
     }
 }
示例#19
0
        public void Setup()
        {
            chapter = DataManager.Get().ChapterData[1];
            GameManager.Get().CurrentChapter = chapter;
            var stageJsonText = Resources.Load <TextAsset>("Data/Stage/Stage01");

            stage = JObject.Parse(stageJsonText.text).ToObject <StageModel>();
            var mapJsonText = Resources.Load <TextAsset>($"Data/Map/{stage.MapName}");

            map = JObject.Parse(mapJsonText.text).ToObject <MapModel>();
            GameManager.Get().CurrentStage = stage;
            GameManager.Get().GameRoom     = GameRoomModel.GetSoloPlay();
            SceneManager.LoadScene("GameScene");
        }
        public async Task <IActionResult> Kick([FromHeader] string authToken, string username)
        {
            var errMsg = string.Empty;
            var leader = UserContext.User;

            var gameRoom = leader.GameRoomRef;

            var user = ServerContext.Current.Server.LookupUserByName(username);

            //Allow to kick player even In Game.. Possible todo don't kick instantly, but only in case All players will agree
            //with this or He will agree himself or even leave
            if (user == null || user.GameRoomRef == null || leader.GameRoomRef == null || user.GameRoomRef.Id != leader.GameRoomRef.Id)
            {
                return(await ErrorResponse(Constants.Instance.ErrorMessage.There_No_Such_User, ResponseType.NotFound));
            }

            var userId = gameRoom.Kick(leader, user, out errMsg);

            if (!string.IsNullOrWhiteSpace(errMsg))
            {
                //todo find what is reason for error
                return(await GenericResponse(ResponseType.NotAllowed, errMsg));
            }

            if (gameRoom.Players.ContainsKey(userId))
            {
                errMsg = Constants.Instance.ErrorMessage.You_Cant_Kick_This_User;
            }

            var broadcast = new GameRoomModel(gameRoom).GetInfo(new RoomModelViewOptions()
            {
                UserCount       = true,
                UserViewOptions = new UserModelViewOptions(false)
                {
                    Id = true
                }
            }).AddItem(BroadcastReason, Request.Path.Value);

            ServerContext.Current.DuplexNetwork.Broadcast(broadcast, gameRoom.Id, SubscriberType.Room);

            var broadcastToKicked = new UserModel(user).GetInfo(new UserModelViewOptions()
            {
                Id = true, GameRoomId = true
            })
                                    .AddItem(BroadcastReason, Request.Path.Value);;

            ServerContext.Current.DuplexNetwork.Broadcast(broadcastToKicked, user.Id, SubscriberType.User);

            return(await GenericResponse(ResponseType.UnexpectedError, errMsg));
        }
示例#21
0
        private IEnumerator UpdateGameRoomCoroutine()
        {
            string gameCode = gameManager.GameRoom.GameCode;

            while (isRunning)
            {
                netManager.GetRequest(UrlTable.GetFindGameUrl(gameCode)
                                      , (response) =>
                {
                    var game = GameRoomModel.Parse(response);
                    SetGameRoom(game);
                });
                yield return(new WaitForSecondsRealtime(.5f));
            }
        }
示例#22
0
        public async Task <GameRoomModel> CreateGameRoomAsync(int maxUserCount)
        {
            var           gameCode = MakeGameCode();
            GameRoomModel newGame  = new GameRoomModel(gameCode, maxUserCount);

            newGame = await CreateGameRoomAsync(newGame);

            var gameOwner = JoinGameRoom(newGame.GameCode);

            newGame.OwnerUserId = gameOwner.UserId;
            db.Update(newGame);
            await db.SaveChangesAsync();

            return(newGame);
        }
示例#23
0
        public ActionResult GetPlayer(int id)
        {
            var userGameRoom = _service.GameRoom().GetAllUserGameRoom(id);
            var gameRoom     = _service.GameRoom().GetRoomById(id);
            var model        = new GameRoomModel
            {
                GameRoomId     = id,
                UserGameRooms  = userGameRoom.ToList(),
                MaxPlayer      = gameRoom.Multiplayer,
                Player         = userGameRoom.Count(),
                CreateByUserId = gameRoom.UserId,
            };

            return(PartialView("_PlayerList", model));
        }
示例#24
0
        public void OnClickCreateGameButton()
        {
            int maxUserCount = int.Parse(maxUserCountText.text);

            netManager.GetRequest(UrlTable.GetCreateGameUrl(maxUserCount),
                                  (response) =>
            {
                var game = GameRoomModel.Parse(response);
                if (null != game)
                {
                    gameManager.GameRoom   = game;
                    gameManager.GameUserId = game.OwnerUserId;
                    gameCodeText.text      = game.GameCode;
                    StartCoroutine(StartGame());
                }
            });
        }
        public async Task <IActionResult> CreateGameRoom([FromHeader] string authToken, [FromBody] CreateRoomModel room)
        {
            var errMsg = string.Empty;

            if (UserContext.User.IsInRoom())
            {
                return(await GenericResponse(ResponseType.NotAllowed, Constants.Instance.ErrorMessage.Is_In_Game_Room));
            }

            var gameRoom = EnergoServer.Current.CreateGameRoom(UserContext.User, room.Name, out errMsg);

            if (!string.IsNullOrWhiteSpace(errMsg))
            {
                return(await GenericResponse(ResponseType.InvalidModel, errMsg));
            }

            ToggleReadyResponse response = null;

            if (room.SetReadyMark)
            {
                response = EnergoServer.Current.RouteAction(new ToggleReadyAction(UserContext.User));
            }

            return(await SuccessResponse(() =>
            {
                ServerContext.Current.Chat.AddChannel(UserContext.User, ChatChannelType.Room, gameRoom.Id);

                var broadcast = new GameRoomModel(gameRoom).GetInfo(new RoomModelViewOptions(true)
                {
                    UserViewOptions = new UserModelViewOptions(false)
                }).AddItem(BroadcastReason, Request.Path.Value);

                ServerContext.Current.DuplexNetwork.Broadcast(broadcast);

                return new GameRoomModel(gameRoom).GetInfo(new RoomModelViewOptions(true)
                {
                    IsInGame = false,
                    UserCount = false,
                    UserViewOptions = new UserModelViewOptions(false)
                    {
                        ReadyMark = true
                    }
                });
            }).Invoke());
        }
示例#26
0
        public void OnClickConfirmButton()
        {
            string gameCode = gameManager.GameRoom.GameCode;

            netManager.GetRequest(UrlTable.GetStartGameUrl(gameCode)
                                  , (response) =>
            {
                var gameRoom = GameRoomModel.Parse(response);
                if (true == gameRoom.IsOpen)
                {
                    Log.Info("NOT READY");
                }
                else
                {
                    Close();
                }
            });
        }
        public async Task <IActionResult> JoinGameRoom([FromHeader] string authToken, [FromBody] JoinRoomModel joinModel)
        {
            var errMsg   = string.Empty;
            var gameRoom = EnergoServer.Current.LookupGameRoom(UserContext.User, joinModel.RoomId, out errMsg);

            if (!string.IsNullOrWhiteSpace(errMsg))
            {
                return(await GenericResponse(ResponseType.NotFound, errMsg));
            }

            gameRoom.Join(UserContext.User, out errMsg);

            if (!string.IsNullOrWhiteSpace(errMsg))
            {
                return(await GenericResponse(ResponseType.NotAllowed, errMsg));
            }

            return(await SuccessResponse(() =>
            {
                var broadcast = new GameRoomModel(gameRoom).GetInfo(new RoomModelViewOptions()
                {
                    UserCount = true,
                    UserViewOptions = new UserModelViewOptions(false)
                    {
                        Id = true
                    }
                }).AddItem(BroadcastReason, Request.Path.Value);

                ServerContext.Current.DuplexNetwork.Broadcast(broadcast, gameRoom.Id, SubscriberType.Room);

                return new GameRoomModel(gameRoom).GetInfo(
                    new RoomModelViewOptions
                {
                    Id = true,
                    Name = true,
                    UserCount = true,
                    UserDetails = true,
                    UserViewOptions = new UserModelViewOptions {
                        Id = true, Name = true, ReadyMark = true
                    }
                });
            }).Invoke());
        }
示例#28
0
        private async void enterToGameButton_Click(object sender, EventArgs e)
        {
            t.Abort();
            //aktualizacja pokoju
            var roomBuf = await GetActualRoomMate(this.room.Id);

            this.room = roomBuf;
            //Zmiana statusu
            if (room.Players.Count == room.PlayersLimit)
            {
                this.Hide();
                var game = await GameWindow.Create(room, player, client);

                game.Closed += (s, ev) => this.Close();
                game.Show();
            }
            else
            {
                MessageBox.Show("Pokoj nie jest pełny. Nie można rozpocząć gry!");
            }
        }
示例#29
0
        private async void leaveRoomButton_Click(object sender, EventArgs e)
        {
            this.Enabled = false;
            t.Abort();
            try
            {
                var roomBuf = await GetActualRoomMate(this.room.Id);

                this.room = roomBuf;
                if (roomBuf.Players.Count == room.PlayersLimit)
                {
                    //usuwanie gracza z pokoju
                    //Dunno.
                    await DeleteProductAsync(player.Id);

                    this.Hide();
                    var panel = new UserPanel(url, client, user);
                    panel.Closed += (s, ev) => this.Close();
                    panel.Show();
                }
                else if (room.Players.Count == 1)
                {
                    //usuwanie gracza
                    //usuwanie pokoju
                    //Dunno.
                    this.Hide();
                    var panel = new UserPanel(url, client, user);
                    panel.Closed += (s, ev) => this.Close();
                    panel.Show();
                }
            }
            catch (Exception excp)
            {
                MessageBox.Show(excp.Message);
            }
            finally
            {
                this.Enabled = true;
            }
        }
示例#30
0
        private async void checkUsers()
        {
            while (true)
            {
                playerListLabel.Text = "";
                try
                {
                    var roomBuf = await GetActualRoomMate(this.room.Id);

                    this.room = roomBuf;
                    foreach (var p in room.Players)
                    {
                        playerListLabel.Text += p.User.Name + " " + p.User.status + "\r\n";
                    }
                }
                catch (Exception excp)
                {
                    MessageBox.Show(excp.Message);
                }
                Thread.Sleep(1000);
            }
        }