Răsfoiți Sursa

1.gate封包zip解析正确
2.nuget签入版本库中保存
3.boss使用发送,再等待响应模式

tanghai 13 ani în urmă
părinte
comite
a44967f08f

+ 24 - 26
.gitignore

@@ -1,26 +1,24 @@
-.cproject
-.project
-.pydevproject
-.sconsign.dblite
-
-*.pyc
-*.suo
-*.user
-
-.settings/
-Dbg/
-Opt/
-
-*/Temp/
-*/TestResults/
-
-bin/
-Bin/
-obj/
-Packages/
-packages/
-_ReSharper.CSharp/
-.nuget/
-
-*.opensdf
-*.sdf
+.cproject
+.project
+.pydevproject
+.sconsign.dblite
+
+*.pyc
+*.suo
+*.user
+
+.settings/
+Dbg/
+Opt/
+
+*/Temp/
+*/TestResults/
+
+bin/
+Bin/
+obj/
+Packages/
+packages/
+_ReSharper.CSharp/
+*.opensdf
+*.sdf

+ 6 - 0
CSharp/.nuget/NuGet.Config

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8"?>
+<configuration>
+  <solution>
+    <add key="disableSourceControlIntegration" value="true" />
+  </solution>
+</configuration>

BIN
CSharp/.nuget/NuGet.exe


+ 153 - 0
CSharp/.nuget/NuGet.targets

@@ -0,0 +1,153 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+    <PropertyGroup>
+        <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">$(MSBuildProjectDirectory)\..\</SolutionDir>
+        
+        <!-- Enable the restore command to run before builds -->
+        <RestorePackages Condition="  '$(RestorePackages)' == '' ">false</RestorePackages>
+
+        <!-- Property that enables building a package from a project -->
+        <BuildPackage Condition=" '$(BuildPackage)' == '' ">false</BuildPackage>
+
+        <!-- Determines if package restore consent is required to restore packages -->
+        <RequireRestoreConsent Condition=" '$(RequireRestoreConsent)' != 'false' ">true</RequireRestoreConsent>
+        
+        <!-- Download NuGet.exe if it does not already exist -->
+        <DownloadNuGetExe Condition=" '$(DownloadNuGetExe)' == '' ">false</DownloadNuGetExe>
+    </PropertyGroup>
+    
+    <ItemGroup Condition=" '$(PackageSources)' == '' ">
+        <!-- Package sources used to restore packages. By default, registered sources under %APPDATA%\NuGet\NuGet.Config will be used -->
+        <!-- The official NuGet package source (https://nuget.org/api/v2/) will be excluded if package sources are specified and it does not appear in the list -->
+        <!--
+            <PackageSource Include="https://nuget.org/api/v2/" />
+            <PackageSource Include="https://my-nuget-source/nuget/" />
+        -->
+    </ItemGroup>
+
+    <PropertyGroup Condition=" '$(OS)' == 'Windows_NT'">
+        <!-- Windows specific commands -->
+        <NuGetToolsPath>$([System.IO.Path]::Combine($(SolutionDir), ".nuget"))</NuGetToolsPath>
+        <PackagesConfig>$([System.IO.Path]::Combine($(ProjectDir), "packages.config"))</PackagesConfig>
+        <PackagesDir>$([System.IO.Path]::Combine($(SolutionDir), "packages"))</PackagesDir>
+    </PropertyGroup>
+    
+    <PropertyGroup Condition=" '$(OS)' != 'Windows_NT'">
+        <!-- We need to launch nuget.exe with the mono command if we're not on windows -->
+        <NuGetToolsPath>$(SolutionDir).nuget</NuGetToolsPath>
+        <PackagesConfig>packages.config</PackagesConfig>
+        <PackagesDir>$(SolutionDir)packages</PackagesDir>
+    </PropertyGroup>
+    
+    <PropertyGroup>
+        <!-- NuGet command -->
+        <NuGetExePath Condition=" '$(NuGetExePath)' == '' ">$(NuGetToolsPath)\nuget.exe</NuGetExePath>
+        <PackageSources Condition=" $(PackageSources) == '' ">@(PackageSource)</PackageSources>
+        
+        <NuGetCommand Condition=" '$(OS)' == 'Windows_NT'">"$(NuGetExePath)"</NuGetCommand>
+        <NuGetCommand Condition=" '$(OS)' != 'Windows_NT' ">mono --runtime=v4.0.30319 $(NuGetExePath)</NuGetCommand>
+
+        <PackageOutputDir Condition="$(PackageOutputDir) == ''">$(TargetDir.Trim('\\'))</PackageOutputDir>
+        
+        <RequireConsentSwitch Condition=" $(RequireRestoreConsent) == 'true' ">-RequireConsent</RequireConsentSwitch>
+        <!-- Commands -->
+        <RestoreCommand>$(NuGetCommand) install "$(PackagesConfig)" -source "$(PackageSources)"  $(RequireConsentSwitch) -o "$(PackagesDir)"</RestoreCommand>
+        <BuildCommand>$(NuGetCommand) pack "$(ProjectPath)" -p Configuration=$(Configuration) -o "$(PackageOutputDir)" -symbols</BuildCommand>
+
+        <!-- We need to ensure packages are restored prior to assembly resolve -->
+        <BuildDependsOn Condition="$(RestorePackages) == 'true'">
+            RestorePackages;
+            $(BuildDependsOn);
+        </BuildDependsOn>
+
+        <!-- Make the build depend on restore packages -->
+        <BuildDependsOn Condition="$(BuildPackage) == 'true'">
+            $(BuildDependsOn);
+            BuildPackage;
+        </BuildDependsOn>
+    </PropertyGroup>
+
+    <Target Name="CheckPrerequisites">
+        <!-- Raise an error if we're unable to locate nuget.exe  -->
+        <Error Condition="'$(DownloadNuGetExe)' != 'true' AND !Exists('$(NuGetExePath)')" Text="Unable to locate '$(NuGetExePath)'" />
+        <SetEnvironmentVariable EnvKey="VisualStudioVersion" EnvValue="$(VisualStudioVersion)" Condition=" '$(VisualStudioVersion)' != '' AND '$(OS)' == 'Windows_NT' " />
+        <!--
+        Take advantage of MsBuild's build dependency tracking to make sure that we only ever download nuget.exe once.
+        This effectively acts as a lock that makes sure that the download operation will only happen once and all
+        parallel builds will have to wait for it to complete.
+        -->
+        <MsBuild Targets="_DownloadNuGet" Projects="$(MSBuildThisFileFullPath)" Properties="Configuration=NOT_IMPORTANT" />
+    </Target>
+
+    <Target Name="_DownloadNuGet">
+        <DownloadNuGet OutputFilename="$(NuGetExePath)" Condition=" '$(DownloadNuGetExe)' == 'true' AND !Exists('$(NuGetExePath)')" />
+    </Target>
+
+    <Target Name="RestorePackages" DependsOnTargets="CheckPrerequisites">
+        <Exec Command="$(RestoreCommand)"
+              Condition="'$(OS)' != 'Windows_NT' And Exists('$(PackagesConfig)')" />
+              
+        <Exec Command="$(RestoreCommand)"
+              LogStandardErrorAsError="true"
+              Condition="'$(OS)' == 'Windows_NT' And Exists('$(PackagesConfig)')" />
+    </Target>
+
+    <Target Name="BuildPackage" DependsOnTargets="CheckPrerequisites">
+        <Exec Command="$(BuildCommand)" 
+              Condition=" '$(OS)' != 'Windows_NT' " />
+              
+        <Exec Command="$(BuildCommand)"
+              LogStandardErrorAsError="true"
+              Condition=" '$(OS)' == 'Windows_NT' " />
+    </Target>
+    
+    <UsingTask TaskName="DownloadNuGet" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">
+        <ParameterGroup>
+            <OutputFilename ParameterType="System.String" Required="true" />
+        </ParameterGroup>
+        <Task>
+            <Reference Include="System.Core" />
+            <Using Namespace="System" />
+            <Using Namespace="System.IO" />
+            <Using Namespace="System.Net" />
+            <Using Namespace="Microsoft.Build.Framework" />
+            <Using Namespace="Microsoft.Build.Utilities" />
+            <Code Type="Fragment" Language="cs">
+                <![CDATA[
+                try {
+                    OutputFilename = Path.GetFullPath(OutputFilename);
+
+                    Log.LogMessage("Downloading latest version of NuGet.exe...");
+                    WebClient webClient = new WebClient();
+                    webClient.DownloadFile("https://nuget.org/nuget.exe", OutputFilename);
+
+                    return true;
+                }
+                catch (Exception ex) {
+                    Log.LogErrorFromException(ex);
+                    return false;
+                }
+            ]]>
+            </Code>
+        </Task>
+    </UsingTask>
+    
+     <UsingTask TaskName="SetEnvironmentVariable" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">
+        <ParameterGroup>
+            <EnvKey ParameterType="System.String" Required="true" />
+            <EnvValue ParameterType="System.String" Required="true" />
+        </ParameterGroup>
+        <Task>
+            <Using Namespace="System" />
+            <Code Type="Fragment" Language="cs">
+                <![CDATA[
+                try {
+                    Environment.SetEnvironmentVariable(EnvKey, EnvValue, System.EnvironmentVariableTarget.Process);
+                }
+                catch  {
+                }
+            ]]>
+            </Code>
+        </Task>
+    </UsingTask>
+</Project>

+ 3 - 2
CSharp/App/BossClient/ENetChannel.cs

@@ -39,7 +39,7 @@ namespace BossClient
 				byte[] bytes = packet.Bytes;
 				const int opcodeSize = sizeof(ushort);
 				ushort opcode = BitConverter.ToUInt16(bytes, 0);
-				byte flag = bytes[0];
+				byte flag = bytes[2];
 				if (flag == 0)
 				{
 					var messageBytes = new byte[packet.Length - opcodeSize - 1];
@@ -50,7 +50,8 @@ namespace BossClient
 				{
 					var messageBytes = new byte[packet.Length - opcodeSize - 5];
 					Array.Copy(bytes, opcodeSize + 5, messageBytes, 0, messageBytes.Length);
-					return Tuple.Create(opcode, ZlibStream.UncompressBuffer(messageBytes));
+					messageBytes = ZlibStream.UncompressBuffer(messageBytes);
+					return Tuple.Create(opcode, messageBytes);
 				}
 			}
 		}

+ 0 - 3
CSharp/App/BossClient/IMessageChannel.cs

@@ -1,7 +1,4 @@
 using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
 using System.Threading.Tasks;
 
 namespace BossClient

+ 2 - 0
CSharp/App/BossClient/Messages.cs

@@ -82,7 +82,9 @@ namespace BossClient
 
 
 		// 其它error code
+		public const int RESPONSE_SUCCESS = 0;
 		public const int AUTH_OK = 12;
+		public const int BOSS_PLAYER_NOT_FOUND = 164000;
 	}
 
 	[DataContract]

+ 2 - 13
CSharp/App/Editor/Shell.xaml

@@ -3,18 +3,7 @@
 		xmlns:prism="http://www.codeplex.com/prism" Title="Editor" Height="800" Width="1280"
 		WindowStartupLocation="CenterScreen">
 	<Grid>
-		<ContentControl Name="login" prism:RegionManager.RegionName="LoginRegion" />
-		<ContentControl Name="robot" prism:RegionManager.RegionName="RobotRegion" />
-		<!--<TabControl>
-			<TabItem Height="25" Width="80" Header="机器人">
-				<ContentControl Name="robot" prism:RegionManager.RegionName="RobotRegion" />
-			</TabItem>
-			<TabItem Height="25" Width="80" Header="行为树">
-				<ContentControl Name="treeCanvas" prism:RegionManager.RegionName="TreeCanvasRegion" />
-			</TabItem>
-			<TabItem Height="25" Width="80" Header="外挂">
-				<ContentControl Name="waigua" prism:RegionManager.RegionName="WaiGuaRegion" />
-			</TabItem>
-		</TabControl>-->
+		<ContentControl Name="login" prism:RegionManager.RegionName="LoginRegion" HorizontalAlignment="Center" VerticalAlignment="Center" />
+		<ContentControl Name="robot" prism:RegionManager.RegionName="RobotRegion" HorizontalAlignment="Left" VerticalAlignment="Top" />
 	</Grid>
 </Window>

+ 0 - 4
CSharp/App/Infrastructure/ViewExportAttribute.cs

@@ -31,10 +31,6 @@ namespace Infrastructure
 		{
 		}
 
-		#region IViewRegionRegistration Members
-
 		public string RegionName { get; set; }
-
-		#endregion
 	}
 }

+ 1 - 1
CSharp/App/Modules/Login/LoginViewModel.cs

@@ -15,7 +15,7 @@ namespace Modules.Login
 	internal class LoginViewModel : NotificationObject
 	{
 		private IEventAggregator EventAggregator { get; set; }
-		private string account = "egametang@163.com";
+		private string account = "egametang@126.com";
 		private string password = "163bio1";
 		private Visibility loginWindowVisiable = Visibility.Visible;
 		private readonly BossClient.BossClient bossClient = new BossClient.BossClient();

+ 73 - 74
CSharp/App/Modules/Robot/RobotView.xaml

@@ -1,74 +1,73 @@
-<UserControl x:Class="Modules.Robot.RobotView"
-		xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
-		xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
-		xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
-		xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
-		xmlns:Robot="clr-namespace:Modules.Robot"
-		mc:Ignorable="d" 
-		d:DesignHeight="600" d:DesignWidth="1280" d:DataContext="{d:DesignInstance Robot:RobotViewModel}">
-	<Grid>
-		<DockPanel Name="dock" Visibility="{Binding DockPanelVisiable}">
-			<Menu DockPanel.Dock="Top" >
-				<MenuItem Header="登录" Name="menuLogin" Click="menuLogin_Click" ></MenuItem>
-			</Menu>
-			<StackPanel Orientation="Horizontal" DockPanel.Dock="Top" Height="27" >
-				<Button Name="btnServers" Content="服务器列表" Click="btnServers_Click" ></Button>
-				<Button Name="btnReload" Content="Reload" Click="btnReload_Click" ></Button>
-			</StackPanel>
-			<ListBox Width="119" SelectionMode="Multiple" ItemsSource="{Binding ServerInfos}" 
-					d:DataContext="{d:DesignInstance Robot:RobotViewModel}" >
-				<ListBox.ItemTemplate>
-					<DataTemplate>
-						<Label Content="{Binding Name}" ></Label>
-					</DataTemplate>
-				</ListBox.ItemTemplate>
-			</ListBox>
-			<Grid>
-				<Canvas>
-					<GroupBox Header="角色信息" Canvas.Left="40" Canvas.Top="22" Height="518" Width="660">
-						<Canvas>
-							<StackPanel Orientation="Horizontal" Grid.Column="0" Grid.Row="0" Grid.ColumnSpan="2" Canvas.Left="32" Canvas.Top="23">
-								<ComboBox x:Name="cbFindType" SelectedIndex="{Binding FindTypeIndex}">
-									<ComboBoxItem Content="帐号"/>
-									<ComboBoxItem Content="名字"/>
-									<ComboBoxItem Content="GUID"/>
-								</ComboBox>
-								<TextBox Width="178" Text="{Binding FindType}"/>
-								<Button Name="btnFind" Content="查询" Click="btnFind_Click"></Button>
-							</StackPanel>
-							<Label Content="帐号:" Grid.Row="1" Grid.Column="0" HorizontalAlignment="Center" Canvas.Left="32" Canvas.Top="52" />
-							<TextBox Text="{Binding Account}"  Grid.Row="1" Grid.Column="1" IsReadOnly="True" Height="25" Canvas.Left="88" Canvas.Top="53" Width="146"/>
-							<Label Content="名字:" Grid.Row="2" Grid.Column="0" HorizontalAlignment="Center" Canvas.Left="32" Canvas.Top="83" />
-							<TextBox Text="{Binding Name}" Grid.Row="2" Grid.Column="1" IsReadOnly="True" Height="25" Canvas.Left="88" Canvas.Top="84" Width="146"/>
-							<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="146"/>
-							<TabControl Height="315" Canvas.Top="180" Width="648">
-								<TabItem Header="信息">
-									<Grid/>
-								</TabItem>
-								<TabItem Header="包裹">
-									<Grid/>
-								</TabItem>
-								<TabItem Header="BUFF">
-									<Grid/>
-								</TabItem>
-								<TabItem Header="装备">
-									<Canvas>
-
-									</Canvas>
-								</TabItem>
-								<TabItem Header="GM">
-									<Canvas>
-										<Button Name="btnForbiddenBuy" Content="禁止交易" Canvas.Left="11" Canvas.Top="10" Width="75" Click="btnForbiddenBuy_Click"/>
-										<Button Content="允许交易" Canvas.Left="11" Canvas.Top="38" Width="75"/>
-									</Canvas>
-								</TabItem>
-							</TabControl>
-							<Label Name="lblErrorInfo" Content="{Binding ErrorInfo}" Canvas.Left="281" Canvas.Top="114" Width="201" Height="25"/>
-						</Canvas>
-					</GroupBox>
-				</Canvas>
-			</Grid>
-		</DockPanel>
-	</Grid>
-</UserControl>
+<UserControl x:Class="Modules.Robot.RobotView"
+		xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+		xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+		xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
+		xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
+		xmlns:Robot="clr-namespace:Modules.Robot"
+		mc:Ignorable="d" 
+		d:DesignHeight="750" d:DesignWidth="1280" d:DataContext="{d:DesignInstance Robot:RobotViewModel}">
+	<Grid>
+		<DockPanel Name="dock" Visibility="{Binding DockPanelVisiable}">
+			<Menu DockPanel.Dock="Top" Margin="0,2" >
+				<MenuItem Header="登录" Name="menuLogin" Click="menuLogin_Click" ></MenuItem>
+				<MenuItem Header="服务器"  >
+					<MenuItem Name="menuServers" Header="显示服务器" Click="menuServers_Click"></MenuItem>
+					<MenuItem Name="menuReload" Header="Reload World" Click="menuReload_Click"></MenuItem>
+				</MenuItem>
+			</Menu>
+			<ListBox Height="723" Width="119" SelectionMode="Multiple" ItemsSource="{Binding ServerInfos}" 
+					d:DataContext="{d:DesignInstance Robot:RobotViewModel}" 
+					BorderThickness="3" BorderBrush="BurlyWood" >
+				<ListBox.ItemTemplate>
+					<DataTemplate>
+						<Label Content="{Binding Name}" ></Label>
+					</DataTemplate>
+				</ListBox.ItemTemplate>
+			</ListBox>
+			<Grid>
+				<Canvas>
+					<GroupBox Header="角色信息" Canvas.Left="10" Height="723" Width="734" BorderBrush="BurlyWood">
+						<Canvas>
+							<ComboBox x:Name="cbFindType" SelectedIndex="{Binding FindTypeIndex}" Canvas.Left="32" Canvas.Top="23" Height="25">
+								<ComboBoxItem Content="帐 号"/>
+								<ComboBoxItem Content="名 字"/>
+								<ComboBoxItem Content="GUID"/>
+							</ComboBox>
+							<TextBox Width="166" Text="{Binding FindType}" Canvas.Left="88" Canvas.Top="23" Height="25"/>
+							<Button Name="btnFind" Content="查询" Click="btnFind_Click" RenderTransformOrigin="9.161,1.435" Canvas.Left="261" Canvas.Top="23" Height="25"></Button>
+							<Label Content="帐 号:" Grid.Row="1" Grid.Column="0" HorizontalAlignment="Center" Canvas.Left="32" Canvas.Top="52" />
+							<TextBox Text="{Binding Account}"  Grid.Row="1" Grid.Column="1" IsReadOnly="True" Height="25" Canvas.Left="88" Canvas.Top="53" Width="204"/>
+							<Label Content="名 字:" Grid.Row="2" Grid.Column="0" HorizontalAlignment="Center" Canvas.Left="32" Canvas.Top="83" />
+							<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}">
+								<TabItem Header="信息">
+									<Grid Margin="0,0,8,36"/>
+								</TabItem>
+								<TabItem Header="包裹">
+									<Grid/>
+								</TabItem>
+								<TabItem Header="BUFF">
+									<Grid/>
+								</TabItem>
+								<TabItem Header="装备">
+									<Canvas>
+
+									</Canvas>
+								</TabItem>
+								<TabItem Header="GM">
+									<Canvas>
+										<Button Name="btnForbiddenBuy" Content="禁止交易" Canvas.Left="11" Canvas.Top="10" Width="75" Click="btnForbiddenBuy_Click"/>
+										<Button Content="允许交易" Canvas.Left="11" Canvas.Top="38" Width="75"/>
+									</Canvas>
+								</TabItem>
+							</TabControl>
+							<Label Name="lblErrorInfo" Content="{Binding ErrorInfo}" Canvas.Left="315" Canvas.Top="114" Width="201" Height="25"/>
+						</Canvas>
+					</GroupBox>
+				</Canvas>
+			</Grid>
+		</DockPanel>
+	</Grid>
+</UserControl>

+ 6 - 6
CSharp/App/Modules/Robot/RobotView.xaml.cs

@@ -28,12 +28,7 @@ namespace Modules.Robot
 			}
 		}
 
-		private void btnServers_Click(object sender, RoutedEventArgs e)
-		{
-			this.ViewModel.Servers();
-		}
-
-		private void btnReload_Click(object sender, RoutedEventArgs e)
+		private void menuReload_Click(object sender, RoutedEventArgs e)
 		{
 			this.ViewModel.Reload();
 		}
@@ -47,6 +42,11 @@ namespace Modules.Robot
 		{
 		}
 
+		private void menuServers_Click(object sender, RoutedEventArgs e)
+		{
+			this.ViewModel.Servers();
+		}
+
 		private void btnForbiddenBuy_Click(object sender, RoutedEventArgs e)
 		{
 			this.ViewModel.ForbiddenBuy();

+ 75 - 40
CSharp/App/Modules/Robot/RobotViewModel.cs

@@ -2,11 +2,10 @@
 using System.Collections.Generic;
 using System.Collections.ObjectModel;
 using System.ComponentModel.Composition;
-using System.Configuration;
 using System.Globalization;
 using System.Linq;
+using System.Threading.Tasks;
 using System.Windows;
-using System.Windows.Threading;
 using BossClient;
 using DataCenter;
 using Events;
@@ -26,6 +25,7 @@ namespace Modules.Robot
 		private string findType = "";
 		private string name = "";
 		private string guid = "";
+		private bool isGMEnable;
 		private Visibility dockPanelVisiable = Visibility.Hidden;
 		private readonly BossClient.BossClient bossClient = new BossClient.BossClient();
 		private readonly ObservableCollection<ServerViewModel> serverInfos = 
@@ -165,14 +165,26 @@ namespace Modules.Robot
 			}
 		}
 
+		public bool IsGMEnable
+		{
+			get
+			{
+				return this.isGMEnable;
+			}
+			set
+			{
+				if (this.isGMEnable == value)
+				{
+					return;
+				}
+				this.isGMEnable = value;
+				this.RaisePropertyChanged("IsGMEnable");
+			}
+		}
+
 		[ImportingConstructor]
 		public RobotViewModel(IEventAggregator eventAggregator)
 		{
-			this.messageHandlers.Add(
-				MessageOpcode.SMSG_BOSS_SERVERSINFO, this.Handle_SMSG_Boss_ServersInfo);
-			this.messageHandlers.Add(
-				MessageOpcode.SMSG_BOSS_COMMAND_RESPONSE, this.Handle_SMSG_Boss_Command_Response);
-
 			eventAggregator.GetEvent<LoginOKEvent>().Subscribe(this.OnLoginOK);
 		}
 
@@ -192,30 +204,10 @@ namespace Modules.Robot
 			this.bossClient.Dispose();
 		}
 
-		public async void OnLoginOK(IMessageChannel messageChannel)
+		public void OnLoginOK(IMessageChannel messageChannel)
 		{
 			this.DockPanelVisiable = Visibility.Visible;
 			this.IMessageChannel = messageChannel;
-			try
-			{
-				while (true)
-				{
-					var result = await this.IMessageChannel.RecvMessage();
-					ushort opcode = result.Item1;
-					byte[] message = result.Item2;
-					if (!messageHandlers.ContainsKey(opcode))
-					{
-						Logger.Debug("not found opcode: {0}", opcode);
-						continue;
-					}
-					messageHandlers[opcode](message);
-				}
-			}
-			catch (Exception e)
-			{
-				this.dockPanelVisiable = Visibility.Hidden;
-				Logger.Trace(e.ToString());
-			}
 		}
 
 		public void SendCommand(string command)
@@ -228,26 +220,35 @@ namespace Modules.Robot
 			this.IMessageChannel.SendMessage(MessageOpcode.CMSG_BOSS_GM, cmsgBossGm);
 		}
 
-		public void Servers()
+		public async Task<T> RecvMessage<T>()
 		{
-			this.SendCommand("servers");
-		}
+			var result = await this.IMessageChannel.RecvMessage();
+			ushort opcode = result.Item1;
+			byte[] content = result.Item2;
 
-		public void Handle_SMSG_Boss_Command_Response(byte[] message)
-		{
-			var smsgBossCommandResponse = ProtobufHelper.FromBytes<SMSG_Boss_Command_Response>(message);
-			this.ErrorInfo = smsgBossCommandResponse.ErrorCode.ToString();
+			try
+			{
+				var message = ProtobufHelper.FromBytes<T>(content);
+				return message;
+			}
+			catch (Exception e)
+			{
+				Logger.Trace("parse message fail, opcode: {0}", opcode);
+				throw;
+			}
 		}
 
-		public void Handle_SMSG_Boss_ServersInfo(byte[] message)
+		public async void Servers()
 		{
-			var smsgBossServersInfo = ProtobufHelper.FromBytes<SMSG_Boss_ServersInfo>(message);
+			this.SendCommand("servers");
+			var smsgBossServersInfo = await this.RecvMessage<SMSG_Boss_ServersInfo>();
 
 			this.ServerInfos.Clear();
 			foreach (var nm in smsgBossServersInfo.Name)
 			{
 				this.ServerInfos.Add(new ServerViewModel { Name = nm });
 			}
+			this.ErrorInfo = "查询服务器成功!";
 		}
 
 		public void Reload()
@@ -285,19 +286,53 @@ namespace Modules.Robot
 			
 				if (result == null)
 				{
-					Logger.Debug("not find charactor info!");
+					this.ErrorInfo = "没有找到该玩家!";
 					return;
 				}
 				
 				this.Account = result.account;
 				this.Name = result.character_name;
 				this.Guid = result.character_guid.ToString(CultureInfo.InvariantCulture);
+				this.IsGMEnable = true;
+				this.ErrorInfo = "查询成功";
 			}
 		}
 
-		public void ForbiddenBuy()
+		public async void ForbiddenBuy()
 		{
-			this.SendCommand(string.Format("{0} 600", guid));
+			if (this.Guid == "")
+			{
+				this.ErrorInfo = "请先指定玩家";
+				return;
+			}
+			this.SendCommand(string.Format("forbidden_buy_item {0} 600", guid));
+			var smsgBossCommandResponse = await RecvMessage<SMSG_Boss_Command_Response>();
+			if (smsgBossCommandResponse.ErrorCode == ErrorCode.RESPONSE_SUCCESS)
+			{
+				this.ErrorInfo = "禁止交易成功";
+				return;
+			}
+			if (smsgBossCommandResponse.ErrorCode == ErrorCode.BOSS_PLAYER_NOT_FOUND)
+			{
+				using (var entitys = new DataCenterEntities())
+				{
+					var newBuff = new t_city_buff
+					{
+						buff_guid = RandomHelper.RandUInt64(),
+						buff_id = 660100,
+						buff_time = 0,
+						buff_values = "{}".ToByteArray(),
+						character_guid = decimal.Parse(this.Guid),
+						create_time = DateTime.Now,
+						modify_time = DateTime.Now,
+						stack = 1
+					};
+					entitys.t_city_buff.Add(newBuff);
+					entitys.SaveChanges();
+				}
+				this.ErrorInfo = "禁止交易成功";
+			}
+			this.ErrorInfo = smsgBossCommandResponse.ErrorCode.ToString();
 		}
 	}
 }

+ 1 - 0
CSharp/Platform/Helper/Helper.csproj

@@ -48,6 +48,7 @@
     <Compile Include="JsonHelper.cs" />
     <Compile Include="LoaderHelper.cs" />
     <Compile Include="ProtobufHelper.cs" />
+    <Compile Include="RandomHelper.cs" />
     <Compile Include="StringHelper.cs" />
     <Compile Include="TimeHelper.cs" />
     <Compile Include="XmlHelper.cs" />

+ 15 - 0
CSharp/Platform/Helper/RandomHelper.cs

@@ -0,0 +1,15 @@
+using System;
+
+namespace Helper
+{
+	public static class RandomHelper
+	{
+		public static UInt64 RandUInt64()
+		{
+			var bytes = new byte[8];
+			var random = new Random();
+			random.NextBytes(bytes);
+			return BitConverter.ToUInt64(bytes, 0);
+		}
+	}
+}