tanghai hace 10 años
padre
commit
f9e6356406

+ 3 - 3
CSharp/Game/Controller/AddressHelper.cs

@@ -6,10 +6,10 @@ namespace Controller
 	{
 		public static string GetAddressByServerName(string serverName)
 		{
-			ServerInfoConfig serverInfoConfig = World.Instance.GetComponent<ConfigComponent>()
-						.GetCategory<ServerInfoCategory>()[serverName];
+			ServerInfoConfig serverInfoConfig =
+					World.Instance.GetComponent<ConfigComponent>().GetCategory<ServerInfoCategory>()[serverName];
 			string address = serverInfoConfig.Host + ":" + serverInfoConfig.Port;
 			return address;
 		}
 	}
-}
+}

+ 4 - 3
CSharp/Game/Controller/Event/GateRecvClientMessageEvent.cs

@@ -5,7 +5,7 @@ using Model;
 namespace Controller
 {
 	[Event(EventType.GateRecvClientMessage, ServerType.Gate)]
-	public class GateRecvClientMessageEvent : IEventSync
+	public class GateRecvClientMessageEvent: IEventSync
 	{
 		public void Run(Env env)
 		{
@@ -13,7 +13,8 @@ namespace Controller
 			AChannel channel = env.Get<AChannel>(EnvKey.Channel);
 
 			// 进行消息分发
-			ChannelUnitInfoComponent channelUnitInfoComponent = channel.GetComponent<ChannelUnitInfoComponent>();
+			ChannelUnitInfoComponent channelUnitInfoComponent =
+					channel.GetComponent<ChannelUnitInfoComponent>();
 			byte[] idBuffer = channelUnitInfoComponent.UnitId.ToByteArray();
 			byte[] buffer = new byte[message.Length + 12];
 			Array.Copy(message, 0, buffer, 0, 4);
@@ -23,4 +24,4 @@ namespace Controller
 			World.Instance.GetComponent<NetworkComponent>().SendAsync(address, buffer);
 		}
 	}
-}
+}

+ 2 - 2
CSharp/Game/Controller/Event/GateRecvServerMessageEvent.cs

@@ -5,7 +5,7 @@ using MongoDB.Bson;
 namespace Controller
 {
 	[Event(EventType.GateRecvServerMessage, ServerType.Gate)]
-	public class GateRecvServerMessageEvent : IEventSync
+	public class GateRecvServerMessageEvent: IEventSync
 	{
 		public void Run(Env env)
 		{
@@ -20,4 +20,4 @@ namespace Controller
 			World.Instance.GetComponent<GateNetworkComponent>().SendAsync(unitId, buffer);
 		}
 	}
-}
+}

+ 2 - 2
CSharp/Game/Controller/Event/LogicRecvMessageEvent.cs

@@ -5,7 +5,7 @@ using MongoDB.Bson;
 namespace Controller
 {
 	[Event(EventType.LogicRecvMessage, ServerType.All)]
-	public class LogicRecvMessageEvent : IEventSync
+	public class LogicRecvMessageEvent: IEventSync
 	{
 		public void Run(Env env)
 		{
@@ -30,4 +30,4 @@ namespace Controller
 			World.Instance.GetComponent<EventComponent<MessageAttribute>>().RunAsync(opcode, env);
 		}
 	}
-}
+}

+ 2 - 1
CSharp/Game/Controller/Message/CMsgLoginEvent.cs

@@ -20,7 +20,8 @@ namespace Controller.Message
 			Unit unit = World.Instance.GetComponent<FactoryComponent<Unit>>().Create(UnitType.GatePlayer, 1);
 
 			AChannel channel = env.Get<AChannel>(EnvKey.Channel);
-			ChannelUnitInfoComponent channelUnitInfoComponent = channel.AddComponent<ChannelUnitInfoComponent>();
+			ChannelUnitInfoComponent channelUnitInfoComponent =
+					channel.AddComponent<ChannelUnitInfoComponent>();
 			channelUnitInfoComponent.Account = cmsg.Account;
 			channelUnitInfoComponent.UnitId = unit.Id;
 			World.Instance.GetComponent<GateNetworkComponent>().AssociateUnitIdAndChannel(unit.Id, channel);

+ 1 - 0
CSharp/Game/Model/AEventAttribute.cs

@@ -12,6 +12,7 @@ namespace Model
 		protected AEventAttribute(int type, ServerType serverType)
 		{
 			this.Type = type;
+			this.ServerType = serverType;
 		}
 
 		public bool Contains(ServerType serverType)

+ 4 - 2
CSharp/Game/Model/Component/GateNetworkComponent.cs

@@ -15,7 +15,8 @@ namespace Model
 	{
 		private IService service;
 
-		private readonly Dictionary<ObjectId, AChannel> unitIdChannels = new Dictionary<ObjectId, AChannel>();
+		private readonly Dictionary<ObjectId, AChannel> unitIdChannels =
+				new Dictionary<ObjectId, AChannel>();
 
 		private void Accept(string host, int port, NetworkProtocol protocol = NetworkProtocol.TCP)
 		{
@@ -77,7 +78,8 @@ namespace Model
 					continue;
 				}
 
-				World.Instance.GetComponent<EventComponent<EventAttribute>>().Run(EventType.GateRecvClientMessage, env);
+				World.Instance.GetComponent<EventComponent<EventAttribute>>()
+						.Run(EventType.GateRecvClientMessage, env);
 			}
 		}
 

+ 11 - 8
CSharp/Game/Model/Component/NetworkComponent.cs

@@ -15,7 +15,8 @@ namespace Model
 
 		private int requestId;
 
-		private readonly Dictionary<int, Action<byte[], bool>> requestCallback = new Dictionary<int, Action<byte[], bool>>();
+		private readonly Dictionary<int, Action<byte[], bool>> requestCallback =
+				new Dictionary<int, Action<byte[], bool>>();
 
 		private readonly Dictionary<string, Queue<byte[]>> cache = new Dictionary<string, Queue<byte[]>>();
 
@@ -84,12 +85,14 @@ namespace Model
 				// 如果是发给client的消息,说明这是gate server,需要根据unitid查到channel,进行发送
 				if (MessageTypeHelper.IsServerMessage(opcode))
 				{
-					World.Instance.GetComponent<EventComponent<EventAttribute>>().Run(EventType.GateRecvServerMessage, env);
+					World.Instance.GetComponent<EventComponent<EventAttribute>>()
+							.Run(EventType.GateRecvServerMessage, env);
 					continue;
 				}
 
 				// 进行消息分发
-				World.Instance.GetComponent<EventComponent<EventAttribute>>().Run(EventType.LogicRecvMessage, env);
+				World.Instance.GetComponent<EventComponent<EventAttribute>>()
+						.Run(EventType.LogicRecvMessage, env);
 			}
 		}
 
@@ -130,16 +133,16 @@ namespace Model
 				}
 				else
 				{
-					tcs.SetException(new Exception(string.Format("rpc timeout {0} {1}", type, MongoHelper.ToJson(request))));
+					tcs.SetException(
+					                 new Exception(string.Format("rpc timeout {0} {1}", type,
+							                 MongoHelper.ToJson(request))));
 				}
 			};
 
 			if (waitTime > 0)
 			{
-				this.service.Timer.Add(TimeHelper.Now() + waitTime, () =>
-				{
-					this.RequestCallback(channel, this.requestId, null, false);
-				});
+				this.service.Timer.Add(TimeHelper.Now() + waitTime,
+						() => { this.RequestCallback(channel, this.requestId, null, false); });
 			}
 			return tcs.Task;
 		}

+ 1 - 3
CSharp/Game/Model/Component/RpcComponent.cs

@@ -1,10 +1,8 @@
-using System.Threading.Tasks;
-using Common.Base;
+using Common.Base;
 
 namespace Model
 {
 	public class RpcComponent: Component<World>
 	{
-
 	}
 }

+ 1 - 1
CSharp/Game/Model/ConfigAttribute.cs

@@ -14,7 +14,7 @@ namespace Model
 
 		public bool Contains(ServerType serverType)
 		{
-			if ((this.ServerType &  serverType) == 0)
+			if ((this.ServerType & serverType) == 0)
 			{
 				return false;
 			}

+ 1 - 3
CSharp/Game/Model/MessageAttribute.cs

@@ -1,6 +1,4 @@
-using System;
-
-namespace Model
+namespace Model
 {
 	/// <summary>
 	/// 搭配EventComponent用来分发消息

+ 13 - 8
CSharp/Game/Model/MessageType.cs

@@ -2,18 +2,23 @@
 {
 	public static class MessageType
 	{
-	#region client message 0
+		#region client message 0
+
 		public const int CMsgLogin = 1;
-	#endregion client message 10000
 
-	#region server message 10000
-	#endregion server message 20000
+		#endregion client message 10000
+
+		#region server message 10000
+
+		#endregion server message 20000
+
+		#region rpc request message 20000
+
+		#endregion rpc request message 30000
 
-	#region rpc request message 20000
-	#endregion rpc request message 30000
+		#region rpc request message 30000
 
-	#region rpc request message 30000
-	#endregion rpc request message 40000
+		#endregion rpc request message 40000
 	}
 
 	public static class MessageTypeHelper

+ 2 - 8
CSharp/Game/Model/NumDefine.cs

@@ -1,12 +1,6 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace Model
+namespace Model
 {
 	public enum NumDefine
 	{
 	}
-}
+}

+ 1 - 1
CSharp/Platform/Common/Helper/MongoHelper.cs

@@ -48,7 +48,7 @@ namespace Common.Helper
 			{
 				memoryStream.Seek(index, SeekOrigin.Begin);
 				memoryStream.Seek(index + count, SeekOrigin.End);
-				return (T)BsonSerializer.Deserialize(memoryStream, typeof(T));
+				return (T) BsonSerializer.Deserialize(memoryStream, typeof (T));
 			}
 		}
 	}

+ 0 - 1
CSharp/Platform/Common/Network/AChannel.cs

@@ -2,7 +2,6 @@
 using System.Collections.Generic;
 using System.Threading.Tasks;
 using Common.Base;
-using Common.Helper;
 
 namespace Common.Network
 {

+ 6 - 7
CSharp/Platform/TNet/TChannel.cs

@@ -33,8 +33,7 @@ namespace TNet
 			this.StartRecv();
 		}
 
-		public TChannel(TSocket socket, string host, int port, TService service)
-			: base(service)
+		public TChannel(TSocket socket, string host, int port, TService service): base(service)
 		{
 			this.socket = socket;
 			this.service = service;
@@ -105,14 +104,14 @@ namespace TNet
 		}
 
 		public override void SendAsync(
-			List<byte[]> buffers, byte channelID = 0, PacketFlags flags = PacketFlags.Reliable)
+				List<byte[]> buffers, byte channelID = 0, PacketFlags flags = PacketFlags.Reliable)
 		{
 			int size = buffers.Select(b => b.Length).Sum();
 			byte[] sizeBuffer = BitConverter.GetBytes(size);
 			this.sendBuffer.SendTo(sizeBuffer);
 			foreach (byte[] buffer in buffers)
 			{
-				this.sendBuffer.SendTo(buffer);	
+				this.sendBuffer.SendTo(buffer);
 			}
 			if (this.isConnected)
 			{
@@ -203,9 +202,9 @@ namespace TNet
 			{
 				while (true)
 				{
-					int n = await this.socket.RecvAsync(
-						this.recvBuffer.Last, this.recvBuffer.LastIndex,
-								TBuffer.ChunkSize - this.recvBuffer.LastIndex);
+					int n =
+							await this.socket.RecvAsync(this.recvBuffer.Last, this.recvBuffer.LastIndex,
+									TBuffer.ChunkSize - this.recvBuffer.LastIndex);
 					if (n == 0)
 					{
 						break;

+ 1 - 1
CSharp/Platform/TNet/TService.cs

@@ -121,7 +121,7 @@ namespace TNet
 				{
 					Log.Trace(e.ToString());
 				}
-				
+
 				await this.Timer.Sleep(5000);
 			}
 		}

+ 2 - 4
CSharp/Platform/UNet/UChannel.cs

@@ -2,7 +2,6 @@
 using System.Collections.Generic;
 using System.Linq;
 using System.Threading.Tasks;
-using Common.Logger;
 using Common.Network;
 
 namespace UNet
@@ -29,8 +28,7 @@ namespace UNet
 			this.remoteAddress = this.socket.RemoteAddress;
 		}
 
-		public UChannel(USocket socket, string host, int port, UService service)
-			: base(service)
+		public UChannel(USocket socket, string host, int port, UService service): base(service)
 		{
 			this.socket = socket;
 			this.service = service;
@@ -71,7 +69,7 @@ namespace UNet
 		{
 			string[] ss = this.RemoteAddress.Split(':');
 			int port = int.Parse(ss[1]);
-			bool result = await this.socket.ConnectAsync(ss[0], (ushort)port);
+			bool result = await this.socket.ConnectAsync(ss[0], (ushort) port);
 			this.isConnected = true;
 			while (this.queue.Count > 0)
 			{

+ 0 - 2
CSharp/Platform/UNet/USocket.cs

@@ -2,7 +2,6 @@
 using System.Collections.Generic;
 using System.Runtime.InteropServices;
 using System.Threading.Tasks;
-using Common.Logger;
 using Common.Network;
 
 namespace UNet
@@ -113,7 +112,6 @@ namespace UNet
 				{
 					tcs.TrySetException(new UException("socket disconnected in connect"));
 				}
-				Log.Debug("11111111111111, connect ok");
 				tcs.TrySetResult(true);
 			};
 			return tcs.Task;