提交 b4cdeac0 编写于 作者: T tanghai

格式化一下代码

上级 539e9d42
......@@ -30,7 +30,9 @@ namespace Editor
protected override IRegionBehaviorFactory ConfigureDefaultRegionBehaviors()
{
IRegionBehaviorFactory factory = base.ConfigureDefaultRegionBehaviors();
factory.AddIfMissing("AutoPopulateExportedViewsBehavior", typeof (AutoPopulateExportedViewsBehavior));
factory.AddIfMissing(
"AutoPopulateExportedViewsBehavior",
typeof (AutoPopulateExportedViewsBehavior));
return factory;
}
......
......@@ -25,11 +25,7 @@ namespace Infrastructure
public class AutoPopulateExportedViewsBehavior: RegionBehavior, IPartImportsSatisfiedNotification
{
[ImportMany(AllowRecomposition = true)]
public Lazy<object, IViewRegionRegistration>[] RegisteredViews
{
get;
set;
}
public Lazy<object, IViewRegionRegistration>[] RegisteredViews { get; set; }
#region IPartImportsSatisfiedNotification Members
......
......@@ -19,9 +19,6 @@ namespace Infrastructure
{
public interface IViewRegionRegistration
{
string RegionName
{
get;
}
string RegionName { get; }
}
}
\ No newline at end of file
......@@ -33,11 +33,7 @@ namespace Infrastructure
#region IViewRegionRegistration Members
public string RegionName
{
get;
set;
}
public string RegionName { get; set; }
#endregion
}
......
......@@ -11,7 +11,8 @@ namespace Modules.BehaviorTree
private static double rootOffsetX;
private static double rootOffsetY;
private static TreeNodeViewModel LeftMostOffspring(TreeNodeViewModel treeNode, int currentLevel, int searchLevel)
private static TreeNodeViewModel LeftMostOffspring(
TreeNodeViewModel treeNode, int currentLevel, int searchLevel)
{
if (currentLevel == searchLevel)
{
......@@ -31,7 +32,8 @@ namespace Modules.BehaviorTree
return null;
}
private static TreeNodeViewModel RightMostOffspring(TreeNodeViewModel treeNode, int currentLevel, int searchLevel)
private static TreeNodeViewModel RightMostOffspring(
TreeNodeViewModel treeNode, int currentLevel, int searchLevel)
{
if (currentLevel == searchLevel)
{
......@@ -126,10 +128,12 @@ namespace Modules.BehaviorTree
treeNode.Prelim = prelim;
treeNode.Modify = modify;
Logger.Debug("Num: " + treeNode.Num + " Prelim: " + treeNode.Prelim + " Modify: " + treeNode.Modify);
Logger.Debug("Num: " + treeNode.Num + " Prelim: " + treeNode.Prelim + " Modify: " +
treeNode.Modify);
}
private static void CalculateRelativeXAndY(TreeNodeViewModel treeNode, int level, double totalModify)
private static void CalculateRelativeXAndY(
TreeNodeViewModel treeNode, int level, double totalModify)
{
foreach (TreeNodeViewModel node in treeNode.Children)
{
......
......@@ -3,10 +3,12 @@ using System.ComponentModel.Composition;
namespace Modules.BehaviorTree
{
[Export(contractType: typeof (BehaviorTreeViewModel)), PartCreationPolicy(creationPolicy: CreationPolicy.NonShared)]
[Export(contractType: typeof (BehaviorTreeViewModel)),
PartCreationPolicy(creationPolicy: CreationPolicy.NonShared)]
internal class BehaviorTreeViewModel
{
private readonly ObservableCollection<TreeNodeViewModel> treeNodes = new ObservableCollection<TreeNodeViewModel>();
private readonly ObservableCollection<TreeNodeViewModel> treeNodes =
new ObservableCollection<TreeNodeViewModel>();
public ObservableCollection<TreeNodeViewModel> TreeNodes
{
......
......@@ -8,22 +8,10 @@
this.Y = y;
}
public double X
{
get;
set;
}
public double X { get; set; }
public double Y
{
get;
set;
}
public double Y { get; set; }
public int Type
{
get;
set;
}
public int Type { get; set; }
}
}
\ No newline at end of file
......@@ -16,7 +16,9 @@ namespace Modules.BehaviorTree
private double modify;
private double ancestorModify;
private TreeNodeViewModel parent;
private ObservableCollection<TreeNodeViewModel> children = new ObservableCollection<TreeNodeViewModel>();
private ObservableCollection<TreeNodeViewModel> children =
new ObservableCollection<TreeNodeViewModel>();
public TreeNodeViewModel(TreeNode treeNode, TreeNodeViewModel parent)
{
......
......@@ -2,8 +2,6 @@
<packages>
<package id="BouncyCastle" version="1.7.0" targetFramework="net45" />
<package id="CommonServiceLocator" version="1.0" targetFramework="net45" />
<package id="Google.ProtocolBuffers" version="2.4.1.473" targetFramework="net45" />
<package id="Prism" version="4.1.0.0" targetFramework="net45" />
<package id="Prism.MEFExtensions" version="4.1.0.0" targetFramework="net45" />
<package id="protobuf-net" version="2.0.0.621" targetFramework="net45" />
</packages>
\ No newline at end of file
using System.Collections.Generic;
using System.Runtime.Serialization;
using ProtoBuf;
namespace Robot.Protos
{
......@@ -23,83 +22,85 @@ namespace Robot.Protos
public class CMSG_AuthLogonPermit
{
[DataMember(Order = 1, IsRequired = true)]
public string Account
{
get;
set;
}
public string Account { get; set; }
[DataMember(Order = 2, IsRequired = true)]
public string PasswordMd5
{
get;
set;
}
public string PasswordMd5 { get; set; }
}
[DataContract]
public class SMSG_Lock_For_Safe_Time
{
[DataMember(Order = 1, IsRequired = true)]
public uint Time
{
get;
set;
}
public uint Time { get; set; }
}
[DataContract]
public class SMSG_Password_Protect_Type
{
[DataMember(Order = 1, IsRequired = true)]
public uint Code
{
get;
set;
}
public uint Code { get; set; }
[DataMember(Order = 2, IsRequired = true)]
public uint SubCode
{
get;
set;
}
public uint SubCode { get; set; }
[DataMember(Order = 3, IsRequired = true)]
public uint PasswordProtectType
{
get;
set;
}
public uint PasswordProtectType { get; set; }
[DataMember(Order = 4, IsRequired = false)]
public byte[] PpcCoordinate
{
get;
set;
}
public byte[] PpcCoordinate { get; set; }
}
[DataContract]
public class SMSG_Auth_Challenge
{
[DataMember(Order = 1, IsRequired = true)]
public uint Num
{
get;
set;
}
public uint Num { get; set; }
[DataMember(Order = 2, IsRequired = true)]
public uint Seed
{
get;
set;
}
public uint Seed { get; set; }
[DataMember(Order = 3)]
public List<uint> Random
{
get;
set;
}
public List<uint> Random { get; set; }
}
[DataContract]
public class CMSG_AuthLogonChallenge
{
[DataMember(Order = 1, IsRequired = true)]
public string GameName { get; set; }
[DataMember(Order = 2, IsRequired = true)]
public uint Version1 { get; set; }
[DataMember(Order = 3, IsRequired = true)]
public uint Version2 { get; set; }
[DataMember(Order = 4, IsRequired = true)]
public uint Version3 { get; set; }
[DataMember(Order = 5, IsRequired = true)]
public uint Build { get; set; }
[DataMember(Order = 6, IsRequired = true)]
public uint Platform { get; set; }
[DataMember(Order = 7, IsRequired = true)]
public uint OS { get; set; }
[DataMember(Order = 8, IsRequired = true)]
public uint Country { get; set; }
[DataMember(Order = 9, IsRequired = true)]
public uint TimeMapBias { get; set; }
[DataMember(Order = 10, IsRequired = true)]
public uint IP { get; set; }
[DataMember(Order = 11, IsRequired = true)]
public byte[] Password { get; set; }
[DataMember(Order = 12, IsRequired = true)]
public byte[] I { get; set; }
}
}
}
\ No newline at end of file
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Robot
{
......@@ -12,4 +8,4 @@ namespace Robot
{
}
}
}
}
\ No newline at end of file
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Robot.Protos;
using Robot.Protos;
namespace Robot
{
public class RealmInfo
{
public SMSG_Password_Protect_Type SmsgPasswordProtectType
{
get;
set;
}
public SMSG_Password_Protect_Type SmsgPasswordProtectType { get; set; }
}
}
}
\ No newline at end of file
using System;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Threading.Tasks;
using Helper;
using Log;
using Org.BouncyCastle.Crypto.Digests;
using Org.BouncyCastle.Utilities.Encoders;
using ProtoBuf;
using Robot.Protos;
using Helper;
using Org.BouncyCastle.Crypto.Digests;
namespace Robot
{
public class RealmSession: IDisposable
{
private readonly NetworkStream networkStream;
private RealmInfo realmInfo = new RealmInfo();
private readonly RealmInfo realmInfo = new RealmInfo();
public RealmSession(string host, ushort port)
{
Socket socket = ConnectSocket(host, port);
networkStream = new NetworkStream(socket);
this.networkStream = new NetworkStream(socket);
}
public void Dispose()
{
networkStream.Dispose();
this.networkStream.Dispose();
}
public static Socket ConnectSocket(string host, ushort port)
......@@ -54,27 +51,27 @@ namespace Robot
public async void SendMessage<T>(ushort opcode, T message)
{
byte[] protoBytes = ProtobufHelper.ToBytes(message);
var neworkBytes = new byte[sizeof(int) + sizeof(ushort) + protoBytes.Length];
var neworkBytes = new byte[sizeof (int) + sizeof (ushort) + protoBytes.Length];
int totalSize = sizeof (ushort) + protoBytes.Length;
int totalSize = sizeof(ushort) + protoBytes.Length;
var totalSizeBytes = BitConverter.GetBytes(totalSize);
totalSizeBytes.CopyTo(neworkBytes, 0);
var opcodeBytes = BitConverter.GetBytes(opcode);
opcodeBytes.CopyTo(neworkBytes, sizeof(int));
protoBytes.CopyTo(neworkBytes, sizeof(int) + sizeof(ushort));
opcodeBytes.CopyTo(neworkBytes, sizeof (int));
protoBytes.CopyTo(neworkBytes, sizeof (int) + sizeof (ushort));
await networkStream.WriteAsync(neworkBytes, 0, neworkBytes.Length);
await this.networkStream.WriteAsync(neworkBytes, 0, neworkBytes.Length);
}
public async Task<bool> Handle_CMSG_AuthLogonPermit_Response()
{
var result = await RecvMessage();
var result = await this.RecvMessage();
ushort opcode = result.Item1;
byte[] message = result.Item2;
if (opcode == 0)
{
Logger.Trace("opcode == 0");
......@@ -83,8 +80,7 @@ namespace Robot
if (opcode == MessageOpcode.SMSG_LOCK_FOR_SAFE_TIME)
{
var smsgLockForSafeTime =
ProtobufHelper.FromBytes<SMSG_Lock_For_Safe_Time>(message);
var smsgLockForSafeTime = ProtobufHelper.FromBytes<SMSG_Lock_For_Safe_Time>(message);
Logger.Trace("account lock time: {0}", smsgLockForSafeTime.Time);
return false;
}
......@@ -94,8 +90,7 @@ namespace Robot
throw new RealmException(string.Format("error opcode: {0}", opcode));
}
var smsgPasswordProtectType =
ProtobufHelper.FromBytes<SMSG_Password_Protect_Type>(message);
var smsgPasswordProtectType = ProtobufHelper.FromBytes<SMSG_Password_Protect_Type>(message);
this.realmInfo.SmsgPasswordProtectType = smsgPasswordProtectType;
Logger.Trace("message: {0}", JsonHelper.ToString(smsgPasswordProtectType));
......@@ -115,10 +110,11 @@ namespace Robot
var packetBytes = new byte[needReadSize];
while (totalReadSize != needReadSize)
{
int readSize = await networkStream.ReadAsync(packetBytes, totalReadSize, packetBytes.Length);
int readSize = await this.networkStream.ReadAsync(
packetBytes, totalReadSize, packetBytes.Length);
if (readSize == 0)
{
return new Tuple<ushort, byte[]>(0, new byte[] {});
return new Tuple<ushort, byte[]>(0, new byte[] { });
}
totalReadSize += readSize;
}
......@@ -131,15 +127,16 @@ namespace Robot
var contentBytes = new byte[needReadSize];
while (totalReadSize != needReadSize)
{
int readSize = await networkStream.ReadAsync(contentBytes, totalReadSize, contentBytes.Length);
int readSize = await this.networkStream.ReadAsync(
contentBytes, totalReadSize, contentBytes.Length);
if (readSize == 0)
{
return new Tuple<ushort, byte[]>(0, new byte[] {});
return new Tuple<ushort, byte[]>(0, new byte[] { });
}
totalReadSize += readSize;
}
ushort opcode = BitConverter.ToUInt16(contentBytes, 0);
var messageBytes = new byte[needReadSize - sizeof(ushort)];
var messageBytes = new byte[needReadSize - sizeof (ushort)];
Array.Copy(contentBytes, sizeof (ushort), messageBytes, 0, messageBytes.Length);
return new Tuple<ushort, byte[]>(opcode, messageBytes);
......@@ -155,21 +152,23 @@ namespace Robot
digest.DoFinal(passwordMd5, 0);
var cmsgAuthLogonPermit = new CMSG_AuthLogonPermit
{
Account = account,
PasswordMd5 = Hex.ToHexString(passwordMd5)
{
Account = account,
PasswordMd5 = Hex.ToHexString(passwordMd5)
};
this.SendMessage(MessageOpcode.CMSG_AUTHLOGONPERMIT, cmsgAuthLogonPermit);
bool result = await Handle_CMSG_AuthLogonPermit_Response();
bool result = await this.Handle_CMSG_AuthLogonPermit_Response();
if (result == false)
{
return false;
}
var cmsgAuthLogonChallenge = new CMSG_AuthLogonChallenge { };
return true;
}
}
}
}
\ No newline at end of file
......@@ -35,12 +35,6 @@
<Reference Include="BouncyCastle.Crypto">
<HintPath>..\..\..\packages\BouncyCastle.1.7.0\lib\Net20\BouncyCastle.Crypto.dll</HintPath>
</Reference>
<Reference Include="Google.ProtocolBuffers">
<HintPath>..\..\..\packages\Google.ProtocolBuffers.2.4.1.473\lib\net40\Google.ProtocolBuffers.dll</HintPath>
</Reference>
<Reference Include="Google.ProtocolBuffers.Serialization">
<HintPath>..\..\..\packages\Google.ProtocolBuffers.2.4.1.473\lib\net40\Google.ProtocolBuffers.Serialization.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Practices.Prism">
<HintPath>..\..\..\packages\Prism.4.1.0.0\lib\NET40\Microsoft.Practices.Prism.dll</HintPath>
</Reference>
......@@ -49,10 +43,6 @@
</Reference>
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
<Reference Include="protobuf-net, Version=2.0.0.621, Culture=neutral, PublicKeyToken=257b51d87d2e4d67, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\packages\protobuf-net.2.0.0.621\lib\net40\protobuf-net.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.ComponentModel.Composition" />
<Reference Include="System.Core" />
......
using System.ComponentModel.Composition;
using System.Windows;
using System.Windows.Controls;
using Infrastructure;
namespace Modules.Robot
......
......@@ -8,7 +8,8 @@ using Robot;
namespace Modules.Robot
{
[Export(contractType: typeof (RobotViewModel)), PartCreationPolicy(creationPolicy: CreationPolicy.NonShared)]
[Export(contractType: typeof (RobotViewModel)),
PartCreationPolicy(creationPolicy: CreationPolicy.NonShared)]
internal sealed class RobotViewModel: NotificationObject, IDisposable
{
private readonly ClientHost clientHost;
......@@ -72,7 +73,7 @@ namespace Modules.Robot
}
private void Disposing(bool disposing)
{
{
this.clientHost.Dispose();
}
......
......@@ -4,7 +4,8 @@ using Microsoft.Practices.Prism.ViewModel;
namespace Modules.WaiGua
{
[Export(contractType: typeof (WaiGuaViewModel)), PartCreationPolicy(creationPolicy: CreationPolicy.NonShared)]
[Export(contractType: typeof (WaiGuaViewModel)),
PartCreationPolicy(creationPolicy: CreationPolicy.NonShared)]
internal class WaiGuaViewModel: NotificationObject
{
private string logText = "";
......
......@@ -35,7 +35,7 @@
<s:Int64 x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/KEEP_BLANK_LINES_IN_DECLARATIONS/@EntryValue">1</s:Int64>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/KEEP_USER_LINEBREAKS/@EntryValue">False</s:Boolean>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/MODIFIERS_ORDER/@EntryValue">private public protected internal new abstract virtual override sealed static readonly extern unsafe volatile async</s:String>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/PLACE_ABSTRACT_ACCESSORHOLDER_ON_SINGLE_LINE/@EntryValue">False</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/PLACE_FIELD_ATTRIBUTE_ON_SAME_LINE/@EntryValue">False</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/PLACE_SIMPLE_ACCESSOR_ON_SINGLE_LINE/@EntryValue">False</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/PLACE_WHILE_ON_NEW_LINE/@EntryValue">True</s:Boolean>
......@@ -50,6 +50,7 @@
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/WRAP_AFTER_INVOCATION_LPAR/@EntryValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/WRAP_BEFORE_FIRST_TYPE_PARAMETER_CONSTRAINT/@EntryValue">True</s:Boolean>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/WRAP_FOR_STMT_HEADER_STYLE/@EntryValue">WRAP_IF_LONG</s:String>
<s:Int64 x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/WRAP_LIMIT/@EntryValue">100</s:Int64>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/WRAP_MULTIPLE_DECLARATION_STYLE/@EntryValue">WRAP_IF_LONG</s:String>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/WRAP_TERNARY_EXPR_STYLE/@EntryValue">WRAP_IF_LONG</s:String>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/JavaScriptCodeFormatting/JavaScriptFormatOther/ALIGN_MULTIPLE_DECLARATION/@EntryValue">True</s:Boolean>
......
......@@ -3,8 +3,8 @@
namespace RealmContract
{
[ServiceContract(Name = "Calculator", Namespace = "http://www.egametang.com/")]
public interface ICalculator
public interface ICalculator
{
double Add(double x, double y);
}
}
}
\ No newline at end of file
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// 有关程序集的常规信息通过以下
// 特性集控制。更改这些特性值可修改
// 与程序集关联的信息。
[assembly: AssemblyTitle("RealmContract")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
......@@ -17,9 +17,11 @@ using System.Runtime.InteropServices;
// 将 ComVisible 设置为 false 使此程序集中的类型
// 对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型,
// 则将该类型上的 ComVisible 特性设置为 true。
[assembly: ComVisible(false)]
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
[assembly: Guid("6c384393-17fe-4ebb-9b3e-5e913544999c")]
// 程序集的版本信息由下面四个值组成:
......@@ -32,5 +34,6 @@ using System.Runtime.InteropServices;
// 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
// 方法是按如下所示使用“*”:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
\ No newline at end of file
using System;
using System.Threading.Tasks;
using Log;
namespace ENet
{
public sealed class ClientHost : Host
public sealed class ClientHost: Host
{
public ClientHost(uint peerLimit = NativeMethods.ENET_PROTOCOL_MAXIMUM_PEER_ID,
uint channelLimit = 0, uint incomingBandwidth = 0,
uint outgoingBandwidth = 0, bool enableCrc = true)
public ClientHost(
uint peerLimit = NativeMethods.ENET_PROTOCOL_MAXIMUM_PEER_ID, uint channelLimit = 0,
uint incomingBandwidth = 0, uint outgoingBandwidth = 0, bool enableCrc = true)
{
if (peerLimit > NativeMethods.ENET_PROTOCOL_MAXIMUM_PEER_ID)
{
......@@ -16,7 +15,8 @@ namespace ENet
}
CheckChannelLimit(channelLimit);
this.host = NativeMethods.enet_host_create(IntPtr.Zero, peerLimit, channelLimit, incomingBandwidth, outgoingBandwidth);
this.host = NativeMethods.enet_host_create(
IntPtr.Zero, peerLimit, channelLimit, incomingBandwidth, outgoingBandwidth);
if (this.host == IntPtr.Zero)
{
......@@ -29,14 +29,16 @@ namespace ENet
}
}
public Task<Peer> ConnectAsync(
Address address, uint channelLimit = NativeMethods.ENET_PROTOCOL_MAXIMUM_CHANNEL_COUNT, uint data = 0)
public Task<Peer> ConnectAsync(Address address,
uint channelLimit = NativeMethods.ENET_PROTOCOL_MAXIMUM_CHANNEL_COUNT,
uint data = 0)
{
CheckChannelLimit(channelLimit);
var tcs = new TaskCompletionSource<Peer>();
ENetAddress nativeAddress = address.Struct;
IntPtr peerPtr = NativeMethods.enet_host_connect(this.host, ref nativeAddress, channelLimit, data);
IntPtr peerPtr = NativeMethods.enet_host_connect(
this.host, ref nativeAddress, channelLimit, data);
if (peerPtr == IntPtr.Zero)
{
throw new ENetException(0, "Host connect call failed.");
......@@ -99,12 +101,12 @@ namespace ENet
}
}
}
public void Start(int timeout = 0)
{
while (isRunning)
while (this.isRunning)
{
RunOnce(timeout);
this.RunOnce(timeout);
}
}
}
......
......@@ -9,10 +9,6 @@ namespace ENet
this.Code = code;
}
public int Code
{
get;
private set;
}
public int Code { get; private set; }
}
}
\ No newline at end of file
......@@ -22,11 +22,11 @@ namespace ENet
{
get
{
return peerState;
return this.peerState;
}
set
{
peerState = value;
this.peerState = value;
}
}
......@@ -42,7 +42,7 @@ namespace ENet
{
get
{
return Ev.packet;
return this.Ev.packet;
}
}
......
using System;
using System.Threading.Tasks;
namespace ENet
{
......@@ -24,7 +23,7 @@ namespace ENet
protected bool isRunning = true;
private readonly object eventsLock = new object();
private Action events;
~Host()
{
this.Dispose(false);
......@@ -144,7 +143,7 @@ namespace ENet
public void Stop()
{
isRunning = false;
this.isRunning = false;
}
}
}
\ No newline at end of file
......@@ -23,10 +23,12 @@ namespace ENet
internal static extern int enet_address_set_host(ref ENetAddress address, string hostName);
[DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
internal static extern int enet_address_get_host(ref ENetAddress address, StringBuilder hostName, uint nameLength);
internal static extern int enet_address_get_host(
ref ENetAddress address, StringBuilder hostName, uint nameLength);
[DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
internal static extern int enet_address_get_host_ip(ref ENetAddress address, StringBuilder hostIp, uint ipLength);
internal static extern int enet_address_get_host_ip(
ref ENetAddress address, StringBuilder hostIp, uint ipLength);
[DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
internal static extern void enet_deinitialize();
......@@ -45,17 +47,20 @@ namespace ENet
[DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
internal static extern IntPtr enet_host_create(
ref ENetAddress address, uint peerLimit, uint channelLimit, uint incomingBandwidth, uint outgoingBandwidth);
ref ENetAddress address, uint peerLimit, uint channelLimit, uint incomingBandwidth,
uint outgoingBandwidth);
[DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
internal static extern IntPtr enet_host_create(
IntPtr address, uint peerLimit, uint channelLimit, uint incomingBandwidth, uint outgoingBandwidth);
IntPtr address, uint peerLimit, uint channelLimit, uint incomingBandwidth,
uint outgoingBandwidth);
[DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
internal static extern void enet_host_destroy(IntPtr host);
[DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
internal static extern IntPtr enet_host_connect(IntPtr host, ref ENetAddress address, uint channelCount, uint data);
internal static extern IntPtr enet_host_connect(
IntPtr host, ref ENetAddress address, uint channelCount, uint data);
[DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
internal static extern void enet_host_broadcast(IntPtr host, byte channelID, IntPtr packet);
......@@ -67,7 +72,8 @@ namespace ENet
internal static extern void enet_host_channel_limit(IntPtr host, uint channelLimit);
[DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
internal static extern void enet_host_bandwidth_limit(IntPtr host, uint incomingBandwidth, uint outgoingBandwidth);
internal static extern void enet_host_bandwidth_limit(
IntPtr host, uint incomingBandwidth, uint outgoingBandwidth);
[DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
internal static extern void enet_host_flush(IntPtr host);
......@@ -85,7 +91,8 @@ namespace ENet
internal static extern void enet_time_set(uint newTimeBase);
[DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
internal static extern IntPtr enet_packet_create(byte[] data, uint dataLength, PacketFlags flags);
internal static extern IntPtr enet_packet_create(
byte[] data, uint dataLength, PacketFlags flags);
[DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
internal static extern void enet_packet_destroy(IntPtr packet);
......
......@@ -54,7 +54,9 @@ namespace ENet
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void no_memory_cb();
private IntPtr malloc, free, no_memory;
private readonly IntPtr malloc;
private readonly IntPtr free;
private readonly IntPtr no_memory;
}
[StructLayout(LayoutKind.Sequential)]
......@@ -62,10 +64,12 @@ namespace ENet
{
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void compress_cb(
IntPtr context, IntPtr inBuffers, IntPtr inBufferCount, IntPtr inLimit, IntPtr outData, IntPtr outLimit);
IntPtr context, IntPtr inBuffers, IntPtr inBufferCount, IntPtr inLimit,
IntPtr outData, IntPtr outLimit);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void decompress_cb(IntPtr context, IntPtr inData, IntPtr inLimit, IntPtr outData, IntPtr outLimit);
public delegate void decompress_cb(
IntPtr context, IntPtr inData, IntPtr inLimit, IntPtr outData, IntPtr outLimit);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void destroy_cb(IntPtr context);
......
using System;
using System.IO;
using System.Runtime.InteropServices;
using Log;
namespace ENet
{
......
using System;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using Log;
namespace ENet
{
......
using System;
using System.Threading.Tasks;
using Log;
namespace ENet
{
public sealed class ServerHost : Host
public sealed class ServerHost: Host
{
private Action<Peer> acceptEvent;
public ServerHost(Address address,
uint peerLimit = NativeMethods.ENET_PROTOCOL_MAXIMUM_PEER_ID,
uint channelLimit = 0, uint incomingBandwidth = 0,
uint outgoingBandwidth = 0, bool enableCrc = true)
public ServerHost(
Address address, uint peerLimit = NativeMethods.ENET_PROTOCOL_MAXIMUM_PEER_ID,
uint channelLimit = 0, uint incomingBandwidth = 0, uint outgoingBandwidth = 0,
bool enableCrc = true)
{
if (peerLimit > NativeMethods.ENET_PROTOCOL_MAXIMUM_PEER_ID)
{
......@@ -21,8 +20,8 @@ namespace ENet
ENetAddress nativeAddress = address.Struct;
this.host = NativeMethods.enet_host_create(
ref nativeAddress, peerLimit,
channelLimit, incomingBandwidth, outgoingBandwidth);
ref nativeAddress, peerLimit, channelLimit, incomingBandwidth,
outgoingBandwidth);
if (this.host == IntPtr.Zero)
{
......@@ -35,7 +34,7 @@ namespace ENet
}
}
public Task<Peer>AcceptAsync()
public Task<Peer> AcceptAsync()
{
if (this.PeersManager.ContainsKey(IntPtr.Zero))
{
......@@ -65,7 +64,7 @@ namespace ENet
case EventType.Connect:
{
var peer = this.PeersManager[IntPtr.Zero];
this.PeersManager.Remove(IntPtr.Zero);
peer.PeerPtr = ev.PeerPtr;
......@@ -92,7 +91,7 @@ namespace ENet
this.PeersManager.Remove(ev.PeerPtr);
// enet_peer_disconnect 会 reset Peer,这里设置为0,防止再次Dispose
peer.PeerPtr = IntPtr.Zero;
if (peerEvent.Received != null)
{
peerEvent.OnReceived(ev);
......@@ -109,9 +108,9 @@ namespace ENet
public void Start(int timeout = 0)
{
while (isRunning)
while (this.isRunning)
{
RunOnce(timeout);
this.RunOnce(timeout);
}
}
}
......
......@@ -24,7 +24,7 @@ namespace ENetCSTest
}
await peer.DisconnectAsync();
host.Stop();
}
......@@ -75,4 +75,4 @@ namespace ENetCSTest
clientThread.Join();
}
}
}
}
\ No newline at end of file
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// 有关程序集的常规信息通过以下特性集
// 控制。更改这些特性值可修改
// 与程序集关联的信息。
[assembly: AssemblyTitle("ENetCSTest")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
......@@ -17,9 +17,11 @@ using System.Runtime.InteropServices;
// 将 ComVisible 设置为 false 会使此程序集中的类型
// 对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型,
// 请将该类型上的 ComVisible 特性设置为 true。
[assembly: ComVisible(false)]
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
[assembly: Guid("b52f4804-3f6e-4268-810a-08fe8ca12bd0")]
// 程序集的版本信息由以下四个值组成:
......@@ -32,5 +34,6 @@ using System.Runtime.InteropServices;
// 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
// 方法是按如下所示使用“*”:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
\ No newline at end of file
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Globalization;
using System.Text;
......@@ -9,12 +8,12 @@ namespace Helper
{
public static string ToHex(this byte b)
{
return b.ToString("X2");
return b.ToString("X2");
}
public static string ToHex(this IEnumerable<byte> bytes)
{
var stringBuilder = new StringBuilder();
var stringBuilder = new StringBuilder();
foreach (byte b in bytes)
{
stringBuilder.Append(b.ToString("X2"));
......@@ -32,4 +31,4 @@ namespace Helper
return stringBuilder.ToString();
}
}
}
}
\ No newline at end of file
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.IO;
using System.Runtime.Serialization.Json;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.Serialization.Json;
namespace Helper
{
......@@ -12,7 +8,7 @@ namespace Helper
{
public static string ToString<T>(T obj)
{
var serializer = new DataContractJsonSerializer(typeof(T));
var serializer = new DataContractJsonSerializer(typeof (T));
using (var ms = new MemoryStream())
{
serializer.WriteObject(ms, obj);
......@@ -23,12 +19,12 @@ namespace Helper
public static T FromString<T>(string str)
{
var serializer = new DataContractJsonSerializer(typeof(T));
var serializer = new DataContractJsonSerializer(typeof (T));
using (var ms = new MemoryStream(Encoding.Default.GetBytes(str)))
{
var obj = (T)serializer.ReadObject(ms);
var obj = (T) serializer.ReadObject(ms);
return obj;
}
}
}
}
}
\ No newline at end of file
using System;
using System.Collections.Generic;
using System.IO;
using System.IO;
using System.Reflection;
namespace Helper
......@@ -14,4 +12,4 @@ namespace Helper
return assembly;
}
}
}
}
\ No newline at end of file
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// 有关程序集的常规信息通过以下
// 特性集控制。更改这些特性值可修改
// 与程序集关联的信息。
[assembly: AssemblyTitle("Helper")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
......@@ -17,9 +17,11 @@ using System.Runtime.InteropServices;
// 将 ComVisible 设置为 false 使此程序集中的类型
// 对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型,
// 则将该类型上的 ComVisible 特性设置为 true。
[assembly: ComVisible(false)]
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
[assembly: Guid("cfce4237-03ff-4f48-9213-aac7ddc7f15e")]
// 程序集的版本信息由下面四个值组成:
......@@ -32,5 +34,6 @@ using System.Runtime.InteropServices;
// 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
// 方法是按如下所示使用“*”:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
\ No newline at end of file
......@@ -18,4 +18,4 @@ namespace Helper
return Serializer.Deserialize<T>(ms);
}
}
}
}
\ No newline at end of file
......@@ -17,4 +17,4 @@ namespace Helper
return byteArray;
}
}
}
}
\ No newline at end of file
......@@ -6,15 +6,15 @@ using System.Xml.Serialization;
namespace Helper
{
public static class XmlHelper
{
public static class XmlHelper
{
/// <summary>
/// 对象序列化成 XML String
/// </summary>
public static string XmlSerialize<T>(T obj)
{
string xmlString = string.Empty;
var xmlSerializer = new XmlSerializer(typeof(T));
var xmlSerializer = new XmlSerializer(typeof (T));
using (var ms = new MemoryStream())
{
xmlSerializer.Serialize(ms, obj);
......@@ -29,14 +29,14 @@ namespace Helper
public static T XmlDeserialize<T>(string xmlString)
{
T t = default(T);
var xmlSerializer = new XmlSerializer(typeof(T));
var xmlSerializer = new XmlSerializer(typeof (T));
Stream xmlStream = new MemoryStream(Encoding.UTF8.GetBytes(xmlString));
using (var xmlReader = XmlReader.Create(xmlStream))
{
Object obj = xmlSerializer.Deserialize(xmlReader);
t = (T)obj;
t = (T) obj;
}
return t;
}
}
}
}
}
\ No newline at end of file
......@@ -5,7 +5,8 @@ using Log;
namespace Hooks
{
[UnmanagedFunctionPointer(CallingConvention.StdCall, CharSet = CharSet.Unicode, SetLastError = true)]
[UnmanagedFunctionPointer(CallingConvention.StdCall, CharSet = CharSet.Unicode,
SetLastError = true)]
public delegate int DRecv(IntPtr handle, IntPtr buf, int count, int flag);
public class RecvHook: IDisposable
......@@ -19,7 +20,8 @@ namespace Hooks
{
try
{
this.localHook = LocalHook.Create(LocalHook.GetProcAddress("Ws2_32.dll", "recv"), new DRecv(dRecv), this);
this.localHook = LocalHook.Create(
LocalHook.GetProcAddress("Ws2_32.dll", "recv"), new DRecv(dRecv), this);
this.localHook.ThreadACL.SetInclusiveACL(new[] { 0 });
}
catch (Exception)
......
......@@ -5,7 +5,8 @@ using Log;
namespace Hooks
{
[UnmanagedFunctionPointer(CallingConvention.StdCall, CharSet = CharSet.Unicode, SetLastError = true)]
[UnmanagedFunctionPointer(CallingConvention.StdCall, CharSet = CharSet.Unicode,
SetLastError = true)]
public delegate int DSend(IntPtr handle, IntPtr buf, int count, int flag);
public class SendHook: IDisposable
......@@ -19,7 +20,8 @@ namespace Hooks
{
try
{
this.localHook = LocalHook.Create(LocalHook.GetProcAddress("Ws2_32.dll", "send"), new DSend(dSend), this);
this.localHook = LocalHook.Create(
LocalHook.GetProcAddress("Ws2_32.dll", "send"), new DSend(dSend), this);
this.localHook.ThreadACL.SetInclusiveACL(new[] { 0 });
}
catch (Exception)
......
......@@ -11,17 +11,9 @@ namespace Log
this.FileLineNumber = true;
}
public bool FileName
{
get;
set;
}
public bool FileName { get; set; }
public bool FileLineNumber
{
get;
set;
}
public bool FileLineNumber { get; set; }
public override string Decorate(string message)
{
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册