Bladeren bron

Dissolving room complete

Tigran 4 jaren geleden
bovenliggende
commit
ab1b53b472

+ 2 - 2
MafiaTelegramBot.sln.DotSettings.user

@@ -1,11 +1,11 @@
 <wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
 	<s:Boolean x:Key="/Default/ResxEditorPersonal/CheckedGroups/=MafiaTelegramBot_002Fappsettings/@EntryIndexedValue">True</s:Boolean>
 	
-	<s:Boolean x:Key="/Default/ResxEditorPersonal/CheckedGroups/=MafiaTelegramBot_002FResources_002Fkeyboard/@EntryIndexedValue">True</s:Boolean>
+	<s:Boolean x:Key="/Default/ResxEditorPersonal/CheckedGroups/=MafiaTelegramBot_002FResources_002Fkeyboard/@EntryIndexedValue">False</s:Boolean>
 	
 	
 	
-	<s:Boolean x:Key="/Default/ResxEditorPersonal/CheckedGroups/=MafiaTelegramBot_002FResources_002Fstrings/@EntryIndexedValue">False</s:Boolean>
+	<s:Boolean x:Key="/Default/ResxEditorPersonal/CheckedGroups/=MafiaTelegramBot_002FResources_002Fstrings/@EntryIndexedValue">True</s:Boolean>
 	<s:Boolean x:Key="/Default/ResxEditorPersonal/CheckedGroups/=MafiaTelegramBot_002Fstrings/@EntryIndexedValue">True</s:Boolean>
 	
 	<s:Boolean x:Key="/Default/ResxEditorPersonal/Initialized/@EntryValue">True</s:Boolean>

+ 17 - 0
MafiaTelegramBot/Controllers/RoomController.cs

@@ -3,6 +3,7 @@ using System.Linq;
 using System.Threading.Tasks;
 using MafiaTelegramBot.DataBase;
 using MafiaTelegramBot.Game;
+using MafiaTelegramBot.Models;
 using MafiaTelegramBot.Resources;
 
 namespace MafiaTelegramBot.Controllers
@@ -65,6 +66,22 @@ namespace MafiaTelegramBot.Controllers
                 return ResultCode.CodeOk;
             });
         }
+        
+        public static async Task DissolveRoom(string roomKey)
+        {
+            await Task.Run(async () =>
+            {
+                if (OpenedGames.ContainsKey(roomKey))
+                    foreach (var player in OpenedGames[roomKey].Players.Values)
+                    {
+                        await player.RemoveGame();
+                        RoomEncrypter.RemoveShortName(OpenedGames[roomKey].RoomName);
+                        if(OpenedGames[roomKey].IsPrivate) RoomEncrypter.Remove(OpenedGames[roomKey].RoomName);
+                        OpenedGames.Remove(roomKey);
+                        await Bot.SendWithMarkdown2(player.ChatId, strings.room_dissolved, Keyboards.MainMenu);
+                    }
+            });
+        }
 
         public static async Task<List<GameRoom>> GetPublicRooms()
         {

+ 2 - 1
MafiaTelegramBot/Models/Bot.cs

@@ -53,7 +53,8 @@ namespace MafiaTelegramBot.Models
                 new RoomSettingsCommand(),
                 new LeaveCommand(),
                 new LookPlayersListCommand(),
-                new KickPlayerCommand()
+                new KickPlayerCommand(),
+                new DissolveRoomCommand(),
             };
         }
         

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

@@ -0,0 +1,24 @@
+using System.Threading.Tasks;
+using MafiaTelegramBot.Controllers;
+using MafiaTelegramBot.DataBase;
+using MafiaTelegramBot.Resources;
+using Telegram.Bot.Types;
+
+namespace MafiaTelegramBot.Models.Commands
+{
+    public class DissolveRoomCommand : Command
+    {
+        protected override string Name => keyboard.dissolve_room;
+        protected override async Task<Message> Execute(Update update)
+        { 
+            var user = await UserDao.GetUserById(UserId);
+            var roomKey = user.GetRoomKey();
+            var resultCode = await RoomController.LeaveFromGame(user);
+            var result = resultCode == ResultCode.CodeOk
+                ? await Bot.SendWithMarkdown2(ChatId, strings.room_dissolved, Keyboards.MainMenu)
+                : await Utilities.GetResultCodeMessage(resultCode, ChatId);
+            if (resultCode == ResultCode.CodeOk) await RoomController.DissolveRoom(roomKey);
+            return result;
+        }
+    }
+}

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

@@ -1,4 +1,3 @@
-using System;
 using System.Threading.Tasks;
 using MafiaTelegramBot.Controllers;
 using MafiaTelegramBot.DataBase;

+ 3 - 6
MafiaTelegramBot/Models/Inlines/KickSelectedPlayerQuery.cs

@@ -13,12 +13,9 @@ namespace MafiaTelegramBot.Models.Inlines
         {
             var user = await UserDao.GetUserById(UserId);
             var resultCode = await RoomController.LeaveFromGame(user);
-            if (resultCode == ResultCode.CodeOk)
-            {
-                await Bot.SendWithMarkdown2(ChatId, $"{strings.kick_user_success}");
-                return await Bot.SendWithMarkdown2(user.ChatId, $"{strings.you_were_kicked}", Keyboards.MainMenu);
-            }
-            return await Utilities.GetResultCodeMessage(resultCode, ChatId);
+            if (resultCode != ResultCode.CodeOk) return await Utilities.GetResultCodeMessage(resultCode, ChatId);
+            await Bot.SendWithMarkdown2(ChatId, $"{strings.kick_user_success}");
+            return await Bot.SendWithMarkdown2(user.ChatId, $"{strings.you_were_kicked}", Keyboards.MainMenu);
         }
     }
 }

+ 1 - 1
MafiaTelegramBot/Resources/Keyboards.cs

@@ -18,7 +18,7 @@ namespace MafiaTelegramBot.Resources
             {
                 new KeyboardButton[] {keyboard.begin_game, keyboard.room_settings},
                 new KeyboardButton[] {keyboard.kick_player, keyboard.look_players_list},
-                new KeyboardButton[] {keyboard.show_profile, keyboard.leave}
+                new KeyboardButton[] {keyboard.show_profile, keyboard.dissolve_room}
             }, true
         );
         

+ 9 - 0
MafiaTelegramBot/Resources/keyboard.Designer.cs

@@ -87,6 +87,15 @@ namespace MafiaTelegramBot.Resources {
             }
         }
         
+        /// <summary>
+        ///   Looks up a localized string similar to Распустить комнату.
+        /// </summary>
+        internal static string dissolve_room {
+            get {
+                return ResourceManager.GetString("dissolve_room", resourceCulture);
+            }
+        }
+        
         /// <summary>
         ///   Looks up a localized string similar to Исключить игрока.
         /// </summary>

+ 3 - 0
MafiaTelegramBot/Resources/keyboard.resx

@@ -42,4 +42,7 @@
     <data name="leave" xml:space="preserve">
         <value>Покинуть игру</value>
     </data>
+    <data name="dissolve_room" xml:space="preserve">
+        <value>Распустить комнату</value>
+    </data>
 </root>

+ 9 - 0
MafiaTelegramBot/Resources/strings.Designer.cs

@@ -330,6 +330,15 @@ namespace MafiaTelegramBot {
             }
         }
         
+        /// <summary>
+        ///   Looks up a localized string similar to Комната распущена.
+        /// </summary>
+        internal static string room_dissolved {
+            get {
+                return ResourceManager.GetString("room_dissolved", resourceCulture);
+            }
+        }
+        
         /// <summary>
         ///   Looks up a localized string similar to Комната не существует.
         /// </summary>

+ 3 - 0
MafiaTelegramBot/Resources/strings.resx

@@ -183,4 +183,7 @@
     <data name="you_were_kicked" xml:space="preserve">
         <value>Вы были исключены</value>
     </data>
+    <data name="room_dissolved" xml:space="preserve">
+        <value>Комната распущена</value>
+    </data>
 </root>