Procházet zdrojové kódy

protect from player use owner commands

Tigran před 4 roky
rodič
revize
7ad2289b07

+ 5 - 0
MafiaTelegramBot/Models/Commands/DissolveRoomCommand.cs

@@ -14,6 +14,11 @@ namespace MafiaTelegramBot.Models.Commands
         { 
             var user = await UserDao.GetPlayerById(UserId);
             var roomKey = RoomEncrypter.GetCode(user.GetRoomName());
+            var room = RoomController.GetRoom(roomKey);
+            if(room == null)
+                return await Bot.SendWithMarkdown2(ChatId, strings.room_does_not_exists);
+            if (!user.Equals(room.Owner))
+                return await Bot.SendWithMarkdown2(ChatId, $"{strings.command_not_found} _*({update.Message.Text})*_");
             var resultCode = await RoomController.LeaveFromGame(user);
             var result = resultCode == ResultCode.CodeOk
                 ? await Bot.SendWithMarkdown2(ChatId, strings.room_dissolved, user.IsAdmin ? Keyboard.AdminMainMenu : Keyboard.MainMenu)

+ 2 - 0
MafiaTelegramBot/Models/Commands/KickPlayerCommand.cs

@@ -17,6 +17,8 @@ namespace MafiaTelegramBot.Models.Commands
             var room = RoomController.GetRoom(roomKey);
             if(room == null)
                 return await Bot.SendWithMarkdown2(ChatId, strings.room_does_not_exists);
+            if (!user.Equals(room.Owner))
+                return await Bot.SendWithMarkdown2(ChatId, $"{strings.command_not_found} _*({update.Message.Text})*_");
             var players = await room.GetPlayers();
             if (players.Count > 0)
                 return await Bot.SendWithMarkdown2(ChatId, strings.kick_user, Keyboard.KickKeyboard(players));

+ 2 - 0
MafiaTelegramBot/Models/Commands/RoomSettingsCommand.cs

@@ -18,6 +18,8 @@ namespace MafiaTelegramBot.Models.Commands
             var room = RoomController.GetRoom(roomKey);
             if(room == null)
                 return await Bot.SendWithMarkdown2(ChatId, strings.room_does_not_exists);
+            if (!user.Equals(room.Owner))
+                return await Bot.SendWithMarkdown2(ChatId, $"{strings.command_not_found} _*({update.Message.Text})*_");
             var status = room.TimerEnabled ? strings.enabled : strings.disabled;
             return await Bot.SendWithMarkdown2(ChatId, strings.what_settings, 
                 Keyboard.SettingsRoomKeyboard(UserId, $"{strings.timer}: {status}"));

+ 6 - 4
MafiaTelegramBot/Models/Commands/StartGameCommand.cs

@@ -12,13 +12,15 @@ namespace MafiaTelegramBot.Models.Commands
         protected override string Name => keyboard.begin_game;
         protected override async Task<Message> Execute(Update update)
         {
-            var owner = await UserDao.GetPlayerById(UserId);
-            var roomKey = RoomEncrypter.GetCode(owner.GetRoomName());
+            var player = await UserDao.GetPlayerById(UserId);
+            var roomKey = RoomEncrypter.GetCode(player.GetRoomName());
             var room = RoomController.GetRoom(roomKey);
             if(room == null)
                 return await Bot.SendWithMarkdown2(ChatId, strings.room_does_not_exists);
-            if (room.IsExtended) return await Bot.SendWithMarkdown2(owner.ChatId, strings.continue_question, Keyboard.StartExtendedRoomKeyboard(UserId));
-            var result = await Bot.SendWithMarkdown2(owner.ChatId, strings.game_process_started);
+            if (!player.Equals(room.Owner))
+                return await Bot.SendWithMarkdown2(ChatId, $"{strings.command_not_found} _*({update.Message.Text})*_");
+            if (room.IsExtended) return await Bot.SendWithMarkdown2(player.ChatId, strings.continue_question, Keyboard.StartExtendedRoomKeyboard(UserId));
+            var result = await Bot.SendWithMarkdown2(player.ChatId, strings.game_process_started);
             var resultCode = await room.Prepare();
             if (resultCode != ResultCode.CodeOk) return await Utilities.GetResultCodeMessage(resultCode, ChatId);
             room.Start();