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

protobuf-net的protogen不支持import,所以还是手动写proto类吧,所有的Proto类放到Protos目录下面

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

+ 0 - 30
CSharp/App/Modules/Robot/Person.pb.cs

@@ -1,30 +0,0 @@
-//------------------------------------------------------------------------------
-// <auto-generated>
-//     This code was generated by a tool.
-//
-//     Changes to this file may cause incorrect behavior and will be lost if
-//     the code is regenerated.
-// </auto-generated>
-//------------------------------------------------------------------------------
-
-// Generated from: Person.proto
-namespace Person
-{
-  [global::System.Serializable, global::ProtoBuf.ProtoContract(Name=@"Person")]
-  public partial class Person : global::ProtoBuf.IExtensible
-  {
-    public Person() {}
-    
-    private int _guid;
-    [global::ProtoBuf.ProtoMember(1, IsRequired = true, Name=@"guid", DataFormat = global::ProtoBuf.DataFormat.TwosComplement)]
-    public int guid
-    {
-      get { return _guid; }
-      set { _guid = value; }
-    }
-    private global::ProtoBuf.IExtension extensionObject;
-    global::ProtoBuf.IExtension global::ProtoBuf.IExtensible.GetExtensionObject(bool createIfMissing)
-      { return global::ProtoBuf.Extensible.GetExtensionObject(ref extensionObject, createIfMissing); }
-  }
-  
-}

+ 0 - 4
CSharp/App/Modules/Robot/Person.proto

@@ -1,4 +0,0 @@
-message Person
-{
-	required int32 guid = 1;
-}

+ 28 - 0
CSharp/App/Modules/Robot/Protos/Messages.cs

@@ -0,0 +1,28 @@
+using System.Collections.Generic;
+using ProtoBuf;
+
+namespace Robot.Protos
+{
+	[ProtoContract]
+	public class SMSG_Auth_Challenge
+	{
+		[ProtoMember(1, IsRequired = true)]
+		public uint Num
+		{
+			get;
+			set;
+		}
+		[ProtoMember(2, IsRequired = true)]
+		public uint Seed
+		{
+			get;
+			set;
+		}
+		[ProtoMember(3)]
+		public List<uint> Random
+		{
+			get;
+			set;
+		}
+	}
+}

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

@@ -54,12 +54,7 @@
     <Reference Include="WindowsBase" />
   </ItemGroup>
   <ItemGroup>
-    <Compile Include="Person.pb.cs">
-      <AutoGen>True</AutoGen>
-      <DesignTime>True</DesignTime>
-      <DesignTimeSharedInput>True</DesignTimeSharedInput>
-      <DependentUpon>Person.proto</DependentUpon>
-    </Compile>
+    <Compile Include="Protos\Messages.cs" />
     <Compile Include="Robot.cs" />
     <Compile Include="RobotModule.cs" />
     <Compile Include="RobotViewModel.cs" />
@@ -92,10 +87,6 @@
   </ItemGroup>
   <ItemGroup>
     <None Include="Packages.config" />
-    <None Include="Person.proto">
-      <Generator>ProtobufTool</Generator>
-      <LastGenOutput>Person.pb.cs</LastGenOutput>
-    </None>
   </ItemGroup>
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
   <Import Project="$(SolutionDir)\.nuget\nuget.targets" />

+ 14 - 2
CSharp/App/Modules/Robot/RobotViewModel.cs

@@ -1,9 +1,13 @@
 using System;
 using System.ComponentModel.Composition;
+using System.IO;
+using System.Text;
 using System.Windows.Threading;
 using ENet;
 using Log;
 using Microsoft.Practices.Prism.ViewModel;
+using ProtoBuf;
+using Robot.Protos;
 
 namespace Modules.Robot
 {
@@ -52,7 +56,15 @@ namespace Modules.Robot
 					using (Packet packet = await peer.ReceiveAsync())
 					{
 						Logger.Debug(packet.Length + " " + packet.Data);
-
+						var bytes = Encoding.Default.GetBytes(packet.Data);
+						var builder = new StringBuilder();
+						foreach (var b in bytes)
+						{
+							builder.Append(b.ToString("X2"));
+						}
+						Logger.Debug(string.Format("HEX string: {0}", builder));
+						var smsg = Serializer.Deserialize<SMSG_Auth_Challenge>(new MemoryStream(bytes));
+						Logger.Debug(string.Format("{0}, {1}", smsg.Num, smsg.Seed));
 						await peer.DisconnectLaterAsync();
 					}
 				}
@@ -65,7 +77,7 @@ namespace Modules.Robot
 
 		public void Start()
 		{
-			for (int i = 0; i < 4095; ++i)
+			for (int i = 0; i < 1; ++i)
 			{
 				this.StartClient();
 			}