Просмотр исходного кода

禁止命令大部分是相同的,使用ComboBox来选择禁止的类型

tanghai 13 лет назад
Родитель
Сommit
c86be2b94b

+ 0 - 28
CSharp/App/BossCommand/BCAllowBuy.cs

@@ -1,28 +0,0 @@
-using System.Threading.Tasks;
-using BossBase;
-
-namespace BossCommand
-{
-	public class BCAllowBuy: ABossCommand
-	{
-		public BCAllowBuy(IMessageChannel iMessageChannel): base(iMessageChannel)
-		{
-		}
-
-		public string Guid { get; set; }
-
-		public override async Task<object> DoAsync()
-		{
-			this.SendMessage(new CMSG_Boss_Gm
-			{
-				Message = string.Format("forbidden_buy_item {0} 0", this.Guid)
-			});
-			var smsgBossCommandResponse = await RecvMessage<SMSG_Boss_Command_Response>();
-			if (smsgBossCommandResponse.ErrorCode == ErrorCode.RESPONSE_SUCCESS)
-			{
-				return ErrorCode.RESPONSE_SUCCESS;
-			}
-			return smsgBossCommandResponse.ErrorCode;
-		}
-	}
-}

+ 5 - 4
CSharp/App/BossCommand/BCForbiddenAccountLogin.cs → CSharp/App/BossCommand/BCForbidLogin.cs

@@ -3,11 +3,12 @@ using BossBase;
 
 namespace BossCommand
 {
-	public class BCForbiddenAccountLogin: ABossCommand
+	public class BCForbidLogin: ABossCommand
 	{
-		public string Account { get; set; }
+		public string Command { get; set; }
+		public string Content { get; set; }
 		public string ForbiddenLoginTime { get; set; }
-		public BCForbiddenAccountLogin(IMessageChannel iMessageChannel): base(iMessageChannel)
+		public BCForbidLogin(IMessageChannel iMessageChannel): base(iMessageChannel)
 		{
 		}
 
@@ -15,7 +16,7 @@ namespace BossCommand
 		{
 			this.SendMessage(new CMSG_Boss_Gm
 			{
-				Message = string.Format("forbid_account {0} {1}", this.Account, this.ForbiddenLoginTime)
+				Message = string.Format("{0} {1} {2}", this.Command, this.Content, this.ForbiddenLoginTime)
 			});
 			var smsgBossCommandResponse = await RecvMessage<SMSG_Boss_Command_Response>();
 			return smsgBossCommandResponse.ErrorCode;

+ 5 - 7
CSharp/App/BossCommand/BCForbiddenBuy.cs → CSharp/App/BossCommand/BCForbiddenCharacter.cs

@@ -3,25 +3,23 @@ using BossBase;
 
 namespace BossCommand
 {
-	public class BCForbiddenBuy: ABossCommand
+	public class BCForbiddenCharacter: ABossCommand
 	{
-		public BCForbiddenBuy(IMessageChannel iMessageChannel): base(iMessageChannel)
+		public BCForbiddenCharacter(IMessageChannel iMessageChannel): base(iMessageChannel)
 		{
 		}
 
 		public string Guid { get; set; }
+		public string Command { get; set; }
+		public string ForbiddenTime { get; set; }
 		public override async Task<object> DoAsync()
 		{
 			this.SendMessage(new CMSG_Boss_Gm
 			{
-				Message = string.Format("forbidden_buy_item {0} {1}", this.Guid, 365 * 24 * 3600)
+				Message = string.Format("{0} {1} {2}", this.Command, this.Guid, this.ForbiddenTime)
 			});
 
 			var smsgBossCommandResponse = await this.RecvMessage<SMSG_Boss_Command_Response>();
-			if (smsgBossCommandResponse.ErrorCode == ErrorCode.RESPONSE_SUCCESS)
-			{
-				return ErrorCode.RESPONSE_SUCCESS;
-			}
 			return smsgBossCommandResponse.ErrorCode;
 		}
 	}

+ 2 - 3
CSharp/App/BossCommand/BossCommand.csproj

@@ -38,13 +38,12 @@
   </ItemGroup>
   <ItemGroup>
     <Compile Include="ABossCommand.cs" />
-    <Compile Include="BCForbiddenAccountLogin.cs" />
-    <Compile Include="BCAllowBuy.cs" />
+    <Compile Include="BCForbidLogin.cs" />
     <Compile Include="BCCommand.cs" />
     <Compile Include="BCGetCharacterInfo.cs" />
     <Compile Include="BCServerInfo.cs" />
     <Compile Include="BCReloadWorld.cs" />
-    <Compile Include="BCForbiddenBuy.cs" />
+    <Compile Include="BCForbiddenCharacter.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
   </ItemGroup>
   <ItemGroup>

+ 9 - 0
CSharp/App/Modules/Robot/ComboBoxForbiddenType.cs

@@ -0,0 +1,9 @@
+
+namespace Modules.Robot
+{
+	public class ComboBoxForbiddenType
+	{
+		public string Name { get; set; }
+		public string Value { get; set; }
+	}
+}

+ 1 - 0
CSharp/App/Modules/Robot/Robot.csproj

@@ -59,6 +59,7 @@
     </Reference>
   </ItemGroup>
   <ItemGroup>
+    <Compile Include="ComboBoxForbiddenType.cs" />
     <Compile Include="Robot.cs" />
     <Compile Include="RobotModule.cs" />
     <Compile Include="RobotViewModel.cs" />

+ 28 - 9
CSharp/App/Modules/Robot/RobotView.xaml

@@ -7,6 +7,17 @@
 		x:Class="Modules.Robot.RobotView"
 		mc:Ignorable="d" 
 		d:DesignHeight="750" d:DesignWidth="1280" d:DataContext="{d:DesignInstance {x:Type Robot:RobotViewModel}}">
+	<UserControl.Resources>
+		<x:Array x:Key="ComboBoxForbiddenTypeKey" Type="Robot:ComboBoxForbiddenType">
+			<Robot:ComboBoxForbiddenType Name="帐号" Value="forbid_buy_item"></Robot:ComboBoxForbiddenType>
+			<Robot:ComboBoxForbiddenType Name="IP" Value="forbid_match"></Robot:ComboBoxForbiddenType>
+		</x:Array>
+		<x:Array x:Key="ComboBoxCharacterForbiddenTypeKey" Type="Robot:ComboBoxForbiddenType">
+			<Robot:ComboBoxForbiddenType Name="购买" Value="forbid_buy_item"></Robot:ComboBoxForbiddenType>
+			<Robot:ComboBoxForbiddenType Name="匹配" Value="forbid_match"></Robot:ComboBoxForbiddenType>
+			<Robot:ComboBoxForbiddenType Name="聊天" Value="forbid_chat"></Robot:ComboBoxForbiddenType>
+		</x:Array>
+	</UserControl.Resources>
 	<Grid>
 		<DockPanel x:Name="dock" Visibility="{Binding DockPanelVisiable}">
 			<Menu DockPanel.Dock="Top" Margin="0,2" >
@@ -34,12 +45,14 @@
 						</TabItem>
 						<TabItem Header="帐号">
 							<Canvas>
-								<TextBox Text="{Binding Account}" Height="23" Canvas.Left="69" Canvas.Top="19" Width="120"/>
-								<Button Content="禁止帐号登录" Canvas.Left="194" Canvas.Top="47" Width="83" Click="btnForbiddenAccountLoginButton_Click"/>
-								<Button Content="允许帐号登录" Canvas.Left="194" Canvas.Top="19" Width="83" Click="btnAllowAccountLogin_Click"/>
-								<Label Content="帐号:" Canvas.Left="10" Canvas.Top="19" Width="38"/>
-								<TextBox Text="{Binding ForbiddenLoginTime}" Height="23" Canvas.Left="69" Canvas.Top="47" Width="120"/>
-								<Label Content="禁止时间:" Canvas.Left="10" Canvas.Top="47"/>
+								<ComboBox Name="cbForbiddenLogin" Canvas.Left="12" Canvas.Top="10" Width="51" SelectedIndex="0"	
+										ItemsSource="{StaticResource ResourceKey=ComboBoxForbiddenTypeKey}" 
+										DisplayMemberPath="Name" SelectedValuePath="Value" />
+								<TextBox Name="tbForbiddenLoginContent" Height="23" Canvas.Left="71" Canvas.Top="10" Width="120"/>
+								<TextBox Name="tbForbiddenLoginTime" Height="23" Canvas.Left="241" Canvas.Top="10" Width="83" />
+								<Label Content="时间:" Canvas.Left="196" Canvas.Top="7"/>
+								<Button Content="禁止" Canvas.Left="12" Canvas.Top="39" Width="75" Click="btnForbiddenLogin_Click"/>
+								<Button Content="允许" Canvas.Left="102" Canvas.Top="39" Width="75" Click="btnAllowLogin_Click"/>
 							</Canvas>
 						</TabItem>
 						<TabItem Header="角色">
@@ -59,7 +72,7 @@
 										<TextBox Text="{Binding Name}" Grid.Row="2" Grid.Column="1" IsReadOnly="True" Height="25" Canvas.Left="88" Canvas.Top="84" Width="204"/>
 										<Label Content="GUID:" Grid.Row="3" Grid.Column="0" HorizontalAlignment="Center" Canvas.Left="32" Canvas.Top="114" />
 										<TextBox Text="{Binding Guid}" Grid.Row="3" Grid.Column="1" IsReadOnly="True" Height="25" Canvas.Left="88" Canvas.Top="114" Width="204"/>
-										<TabControl Height="541" Canvas.Top="160" Width="722" IsEnabled="{Binding IsGMEnable}">
+										<TabControl Name="tcCharacterInfo" Height="541" Canvas.Top="160" Width="722" IsEnabled="False">
 											<TabItem Header="信息">
 												<Grid Margin="0,0,8,36"/>
 											</TabItem>
@@ -74,8 +87,14 @@
 											</TabItem>
 											<TabItem Header="GM">
 												<Canvas>
-													<Button x:Name="btnForbiddenBuy" Content="禁止交易" Canvas.Left="11" Canvas.Top="10" Width="75" Click="btnForbiddenBuy_Click"/>
-													<Button x:Name="btnAllowBuy" Content="允许交易" Canvas.Left="11" Canvas.Top="38" Width="75" Click="btnAllowBuy_Click" />
+													<Button x:Name="btnForbiddenBuy" Content="禁止" Canvas.Left="186" Canvas.Top="40" Width="75" Click="btnForbidCharacter_Click" />
+													<Button x:Name="btnAllowBuy" Content="允许" Canvas.Left="186" Canvas.Top="10" Width="75" Click="btnAllowCharacter_Click" />
+													<ComboBox Name="cbForbiddenType" SelectedIndex="0" Canvas.Left="61" Canvas.Top="11" Width="120" 
+															ItemsSource="{StaticResource ResourceKey=ComboBoxCharacterForbiddenTypeKey}" 
+															DisplayMemberPath="Name" SelectedValuePath="Value" />
+													<TextBox Name="tbForbiddenTime" Height="23" Canvas.Left="61" Canvas.Top="40" Width="120"/>
+													<Label Content="类型:" Canvas.Left="10" Canvas.Top="11"/>
+													<Label Content="时间:" Canvas.Left="10" Canvas.Top="37"/>
 												</Canvas>
 											</TabItem>
 										</TabControl>

+ 14 - 10
CSharp/App/Modules/Robot/RobotView.xaml.cs

@@ -34,9 +34,10 @@ namespace Modules.Robot
 			this.ViewModel.Reload();
 		}
 
-		private void btnFindPlayer_Click(object sender, RoutedEventArgs e)
+		private async void btnFindPlayer_Click(object sender, RoutedEventArgs e)
 		{
-			this.ViewModel.GetCharacterInfo();
+			await this.ViewModel.GetCharacterInfo();
+			this.tcCharacterInfo.IsEnabled = true;
 			this.tbLog.AppendText(Environment.NewLine + this.ViewModel.ErrorInfo);
 			this.tbLog.ScrollToEnd();
 		}
@@ -54,16 +55,16 @@ namespace Modules.Robot
 			this.tbLog.ScrollToEnd();
 		}
 
-		private async void btnForbiddenBuy_Click(object sender, RoutedEventArgs e)
+		private async void btnForbidCharacter_Click(object sender, RoutedEventArgs e)
 		{
-			await this.ViewModel.ForbiddenBuy();
+			await this.ViewModel.ForbidCharacter(cbForbiddenType.SelectedValue.ToString(), tbForbiddenTime.Text);
 			this.tbLog.AppendText(Environment.NewLine + this.ViewModel.ErrorInfo);
 			this.tbLog.ScrollToEnd();
 		}
 
-		private async void btnAllowBuy_Click(object sender, RoutedEventArgs e)
+		private async void btnAllowCharacter_Click(object sender, RoutedEventArgs e)
 		{
-			await this.ViewModel.AllowBuy();
+			await this.ViewModel.ForbidCharacter(cbForbiddenType.SelectedValue.ToString(), "-1");
 			this.tbLog.AppendText(Environment.NewLine + this.ViewModel.ErrorInfo);
 			this.tbLog.ScrollToEnd();
 		}
@@ -75,16 +76,19 @@ namespace Modules.Robot
 			this.tbLog.ScrollToEnd();
 		}
 
-		private async void btnForbiddenAccountLoginButton_Click(object sender, RoutedEventArgs e)
+		private async void btnForbiddenLogin_Click(object sender, RoutedEventArgs e)
 		{
-			await this.ViewModel.ForbiddenAccountLogin();
+			await this.ViewModel.ForbiddenLogin(
+				cbForbiddenLogin.SelectedValue.ToString(), 
+				tbForbiddenLoginContent.Text, tbForbiddenLoginTime.Text);
 			this.tbLog.AppendText(Environment.NewLine + this.ViewModel.ErrorInfo);
 			this.tbLog.ScrollToEnd();
 		}
 
-		private async void btnAllowAccountLogin_Click(object sender, RoutedEventArgs e)
+		private async void btnAllowLogin_Click(object sender, RoutedEventArgs e)
 		{
-			await this.ViewModel.AllowAccountLogin();
+			await this.ViewModel.ForbiddenLogin(
+				cbForbiddenLogin.SelectedValue.ToString(), tbForbiddenLoginContent.Text, "-1");
 			this.tbLog.AppendText(Environment.NewLine + this.ViewModel.ErrorInfo);
 			this.tbLog.ScrollToEnd();
 		}

+ 55 - 118
CSharp/App/Modules/Robot/RobotViewModel.cs

@@ -5,8 +5,8 @@ using System.Globalization;
 using System.Threading.Tasks;
 using System.Windows;
 using BossCommand;
-using BossBase;
-using Helper;
+using BossBase;
+using Helper;
 using Log;
 using Microsoft.Practices.Prism.Events;
 using Microsoft.Practices.Prism.ViewModel;
@@ -21,12 +21,11 @@ namespace Modules.Robot
 
 		private string errorInfo = "";
 		private int findTypeIndex;
-		private string account = "";
+		private string account = "";
 		private string findType = "egametang@126.com";
 		private string name = "";
 		private string guid = "";
-		private string command = "";
-		private string forbiddenLoginTime = "";
+		private string command = "";
 		private bool isGMEnable;
 		private Visibility dockPanelVisiable = Visibility.Hidden;
 		private readonly BossClient.BossClient bossClient = new BossClient.BossClient();
@@ -162,40 +161,6 @@ namespace Modules.Robot
 			}
 		}
 
-		public bool IsGMEnable
-		{
-			get
-			{
-				return this.isGMEnable;
-			}
-			set
-			{
-				if (this.isGMEnable == value)
-				{
-					return;
-				}
-				this.isGMEnable = value;
-				this.RaisePropertyChanged("IsGMEnable");
-			}
-		}
-
-		public string ForbiddenLoginTime
-		{
-			get
-			{
-				return this.forbiddenLoginTime;
-			}
-			set
-			{
-				if (this.forbiddenLoginTime == value)
-				{
-					return;
-				}
-				this.forbiddenLoginTime = value;
-				this.RaisePropertyChanged("ForbiddenLoginTime");
-			}
-		}
-
 		public string Command
 		{
 			get
@@ -274,27 +239,28 @@ namespace Modules.Robot
 			bossCommand.DoAsync();
 		}
 
-		public async void GetCharacterInfo()
+		public async Task GetCharacterInfo()
 		{
 			ABossCommand bossCommand = new BCGetCharacterInfo(this.IMessageChannel)
 			{
 				FindTypeIndex = this.FindTypeIndex, 
 				FindType = this.FindType
-			};
-			var result = await bossCommand.DoAsync();
-			if (result == null)
-			{
-				this.ErrorInfo = string.Format("获取玩家信息失败");
-				return;
-			}
-			this.ErrorInfo = "获取玩家信息成功";
-			var characterInfo = (CharacterInfo)result;
-			this.Account = characterInfo.Account;
-			this.Name = characterInfo.Name;
-			this.Guid = characterInfo.Guid.ToString();
+			};
+			var result = await bossCommand.DoAsync();
+			if (result == null)
+			{
+				this.ErrorInfo = string.Format("获取玩家信息失败");
+				return;
+			}
+			var characterInfo = (CharacterInfo)result;
+
+			this.ErrorInfo = "获取玩家信息成功";
+			this.Account = characterInfo.Account;
+			this.Name = characterInfo.Name;
+			this.Guid = characterInfo.Guid.ToString();
 		}
 
-		public async Task ForbiddenBuy()
+		public async Task ForbidCharacter(string forbiddenCommand, string forbiddenTime)
 		{
 			if (this.Guid == "")
 			{
@@ -302,95 +268,66 @@ namespace Modules.Robot
 				return;
 			}
 
-			ABossCommand bossCommand = new BCForbiddenBuy(this.IMessageChannel)
+			int time = 0;
+			if (!int.TryParse(forbiddenTime, out time))
+			{
+				this.ErrorInfo = "时间请输入数字";
+				return;
+			}
+
+			ABossCommand bossCommand = new BCForbiddenCharacter(this.IMessageChannel)
 			{
-				Guid = this.Guid
+				Guid = this.Guid,
+				Command = forbiddenCommand,
+				ForbiddenTime = forbiddenTime
 			};
 			var result = await bossCommand.DoAsync();
 
-			var errorCode = (int)result;
+			var errorCode = (uint)result;
 
 			if (errorCode == ErrorCode.RESPONSE_SUCCESS)
 			{
-				this.ErrorInfo = "禁止交易成功";
+				this.ErrorInfo = string.Format(
+					"{0} {1} {2} Succeed!", forbiddenCommand, this.Guid, forbiddenTime);
 				return;
 			}
-			this.ErrorInfo = string.Format("禁止交易失败, error code: {0}", errorCode);
+			this.ErrorInfo = string.Format("{0} Fail, error code: {1}", forbiddenCommand, errorCode);
 		}
 
-		public async Task AllowBuy()
+		public async Task ForbiddenLogin(
+			string forbiddenCommand, string forbiddenContent, string forbiddenTime)
 		{
-			if (this.Guid == "")
+			int time = 0;
+			if (!int.TryParse(forbiddenTime, out time))
 			{
-				this.ErrorInfo = "请先指定玩家";
+				this.ErrorInfo = "时间请输入数字";
 				return;
 			}
-			ABossCommand bossCommand = new BCAllowBuy(this.IMessageChannel)
+
+			ABossCommand bossCommand = new BCForbidLogin(this.IMessageChannel)
 			{
-				Guid = this.Guid
+				Command = forbiddenCommand,
+				Content = forbiddenContent,
+				ForbiddenLoginTime = forbiddenTime
 			};
 			var result = await bossCommand.DoAsync();
-			var errorCode = (uint) result;
+
+			var errorCode = (uint)result;
+
 			if (errorCode == ErrorCode.RESPONSE_SUCCESS)
 			{
-				this.ErrorInfo = "允许交易成功";
+				this.ErrorInfo = string.Format(
+					"{0} {1} {2} Succeed!", forbiddenCommand, forbiddenContent, forbiddenTime);
 				return;
 			}
-
-			this.ErrorInfo = errorCode.ToString();
-		}
-
-		public async Task ForbiddenAccountLogin()
-		{
-			int time = 0;
-			if (!int.TryParse(this.ForbiddenLoginTime, out time))
-			{
-				this.ErrorInfo = "禁止时间请输入数字";
-				return;
-			}
-			if (time < 0)
-			{
-				this.ErrorInfo = "禁止时间必须>=0";
-				return;
-			}
-
-			ABossCommand bossCommand = new BCForbiddenAccountLogin(this.IMessageChannel) 
-			{ Account = this.Account, ForbiddenLoginTime = this.ForbiddenLoginTime };
-			var result = await bossCommand.DoAsync();
-
-			var errorCode = (uint)result;
-
-			if (errorCode == ErrorCode.RESPONSE_SUCCESS)
-			{
-				this.ErrorInfo = "禁止帐号登录成功";
-				return;
-			}
-			this.ErrorInfo = string.Format("禁止帐号登录失败, error code: {0}", errorCode);
-		}
-
-		public async Task AllowAccountLogin()
-		{
-			ABossCommand bossCommand = new BCForbiddenAccountLogin(this.IMessageChannel)
-			{
-				Account = this.Account, ForbiddenLoginTime = "-1"
-			};
-			var result = await bossCommand.DoAsync();
-
-			var errorCode = (uint)result;
-
-			if (errorCode == ErrorCode.RESPONSE_SUCCESS)
-			{
-				this.ErrorInfo = "允许帐号登录成功";
-				return;
-			}
-			this.ErrorInfo = string.Format("允许帐号登录失败, error code: {0}", errorCode);
+			this.ErrorInfo = string.Format("{0}, error code: {1}", forbiddenCommand, errorCode);
 		}
 
 		public async Task SendCommand()
-		{
-			if (this.Command.StartsWith("gm ", true, CultureInfo.CurrentCulture))
-			{
-				this.Command = this.Command.Substring(3);
+		{
+			if (this.Command.StartsWith("gm ", true, CultureInfo.CurrentCulture))
+			{
+				this.Command = this.Command.Substring(3);
 			}
 			ABossCommand bossCommand = new BCCommand(this.IMessageChannel)
 			{ Command = this.Command };
@@ -404,7 +341,7 @@ namespace Modules.Robot
 			{
 				Logger.Trace(e.ToString());
 				return;
-			}
+			}
 			var smsgBossCommandResponse = (SMSG_Boss_Command_Response)result;
 			this.ErrorInfo = string.Format(" send command: {0}, error code: {1}", 
 				commandString, JsonHelper.ToString(smsgBossCommandResponse));