Procházet zdrojové kódy

服务端已经可以运行

tanghai před 9 roky
rodič
revize
b45c3735e5

+ 8 - 5
Server/App/Program.cs

@@ -7,9 +7,9 @@ using Object = Base.Object;
 
 namespace App
 {
-	class Program
+	internal static class Program
 	{
-		static void Main(string[] args)
+		private static void Main(string[] args)
 		{
 			try
 			{
@@ -21,12 +21,15 @@ namespace App
 				byte[] pdbBytes = File.ReadAllBytes("./Controller.pdb");
 				Assembly controller = Assembly.Load(dllBytes, pdbBytes);
 				Object.ObjectManager.Register("Controller", controller);
-				
+
 				Game.Scene.AddComponent<EventComponent>();
 				TimeComponent timeComponent = Game.Scene.AddComponent<TimeComponent>();
 				Game.Scene.AddComponent<TimerComponent, TimeComponent>(timeComponent);
-				Game.Scene.AddComponent<NetworkComponent, NetworkProtocol>(NetworkProtocol.UDP);
-				Game.Scene.AddComponent<MessageHandlerComponent, MessageType>(MessageType.Realm);
+
+				Options options = Game.Scene.AddComponent<OptionsComponent, string[]>(args).Options;
+
+				Game.Scene.AddComponent<NetworkComponent, NetworkProtocol, string, int>(options.Protocol, options.Host, options.Port);
+				Game.Scene.AddComponent<MessageHandlerComponent, string>(options.AppType);
 
 				while (true)
 				{

+ 0 - 6
Server/App/Server.App.csproj

@@ -35,12 +35,6 @@
   <ItemGroup>
     <Reference Include="System" />
     <Reference Include="System.Core" />
-    <Reference Include="System.Xml.Linq" />
-    <Reference Include="System.Data.DataSetExtensions" />
-    <Reference Include="Microsoft.CSharp" />
-    <Reference Include="System.Data" />
-    <Reference Include="System.Net.Http" />
-    <Reference Include="System.Xml" />
   </ItemGroup>
   <ItemGroup>
     <Compile Include="Program.cs" />

+ 0 - 5
Server/Base/Server.Base.csproj

@@ -44,11 +44,6 @@
     </Reference>
     <Reference Include="System" />
     <Reference Include="System.Core" />
-    <Reference Include="System.Xml.Linq" />
-    <Reference Include="System.Data.DataSetExtensions" />
-    <Reference Include="Microsoft.CSharp" />
-    <Reference Include="System.Data" />
-    <Reference Include="System.Net.Http" />
     <Reference Include="System.Xml" />
   </ItemGroup>
   <ItemGroup>

+ 15 - 0
Server/Controller/C2S_LoginEvent.cs

@@ -0,0 +1,15 @@
+using Base;
+using Model;
+
+namespace Controller
+{
+	[Message(AppType.Realm, Opcode.S2C_InitBuffInfo)]
+	public class C2S_LoginEvent: AMEvent<C2S_Login>
+	{
+		public override void Run(Entity scene, C2S_Login message)
+		{
+			Log.Info(MongoHelper.ToJson(message));
+			scene.GetComponent<MessageComponent>().Send(new S2C_Login {ErrorMessage = new ErrorMessage() });
+		}
+	}
+}

+ 1 - 6
Server/Controller/Server.Controller.csproj

@@ -32,15 +32,10 @@
   <ItemGroup>
     <Reference Include="System" />
     <Reference Include="System.Core" />
-    <Reference Include="System.Xml.Linq" />
-    <Reference Include="System.Data.DataSetExtensions" />
-    <Reference Include="Microsoft.CSharp" />
-    <Reference Include="System.Data" />
-    <Reference Include="System.Net.Http" />
-    <Reference Include="System.Xml" />
   </ItemGroup>
   <ItemGroup>
     <Compile Include="Properties\AssemblyInfo.cs" />
+    <Compile Include="C2S_LoginEvent.cs" />
   </ItemGroup>
   <ItemGroup>
     <ProjectReference Include="..\Base\Server.Base.csproj">

binární
Server/Lib/CommandLine.dll


+ 66 - 0
Server/Model/Component/OptionsComponent.cs

@@ -0,0 +1,66 @@
+using System;
+using System.Text;
+using Base;
+using CommandLine;
+
+namespace Model
+{
+	public class Options
+	{
+		[Option("appType", Required = true, HelpText = "AppType: realm gate")]
+		public string AppType { get; set; }
+
+		[Option("name", Required = true, HelpText = "Name.")]
+		public string Name { get; set; }
+
+		[Option("protocol", Required = false, HelpText = "Protocol, tcp or udp.", DefaultValue = NetworkProtocol.UDP)]
+		public NetworkProtocol Protocol { get; set; }
+
+		[Option("host", Required = true, HelpText = "Host.")]
+		public string Host { get; set; }
+
+		[Option("port", Required = true, HelpText = "Port.")]
+		public int Port { get; set; }
+
+		[Option("gateHost", Required = false, HelpText = "GateHost.")]
+		public string GateHost { get; set; }
+
+		[Option("gatePort", Required = false, HelpText = "GatePort.")]
+		public int GatePort { get; set; }
+
+		[Option('v', HelpText = "Print details during execution.")]
+		public bool Verbose { get; set; }
+
+		[HelpOption]
+		public string GetUsage()
+		{
+			// this without using CommandLine.Text
+			StringBuilder usage = new StringBuilder();
+			usage.AppendLine("Quickstart Application 1.0");
+			usage.AppendLine("Read user manual for usage instructions...");
+			return usage.ToString();
+		}
+	}
+
+	[ObjectEvent]
+	public class OptionsComponentEvent : ObjectEvent<OptionsComponent>, IAwake<string[]>
+	{
+		public void Awake(string[] args)
+		{
+			this.GetValue().Awake(args);
+		}
+	}
+
+	public class OptionsComponent: Component
+	{
+		public Options Options = new Options();
+
+		public void Awake(string[] args)
+		{
+			if (!Parser.Default.ParseArguments(args, this.Options))
+			{
+				throw new Exception($"命令行格式错误!");
+			}
+		}
+	}
+}

+ 8 - 6
Server/Model/Server.Model.csproj

@@ -30,19 +30,20 @@
     <WarningLevel>4</WarningLevel>
   </PropertyGroup>
   <ItemGroup>
+    <Reference Include="CommandLine, Version=1.9.71.2, Culture=neutral, PublicKeyToken=de6f01bd326f8c32, processorArchitecture=MSIL">
+      <SpecificVersion>False</SpecificVersion>
+      <HintPath>..\Lib\CommandLine.dll</HintPath>
+    </Reference>
     <Reference Include="MongoDB.Bson">
       <HintPath>..\Lib\MongoDB.Bson.dll</HintPath>
     </Reference>
     <Reference Include="System" />
     <Reference Include="System.Core" />
-    <Reference Include="System.Xml.Linq" />
-    <Reference Include="System.Data.DataSetExtensions" />
-    <Reference Include="Microsoft.CSharp" />
-    <Reference Include="System.Data" />
-    <Reference Include="System.Net.Http" />
-    <Reference Include="System.Xml" />
   </ItemGroup>
   <ItemGroup>
+    <Compile Include="..\..\Unity\Assets\Scripts\Message\AppType.cs">
+      <Link>Message\AppType.cs</Link>
+    </Compile>
     <Compile Include="..\..\Unity\Assets\Scripts\Message\ErrorCode.cs">
       <Link>Message\ErrorCode.cs</Link>
     </Compile>
@@ -55,6 +56,7 @@
     <Compile Include="..\..\Unity\Assets\Scripts\Message\OpcodeHelper.cs">
       <Link>Message\OpcodeHelper.cs</Link>
     </Compile>
+    <Compile Include="Component\OptionsComponent.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
   </ItemGroup>
   <ItemGroup>

+ 15 - 0
Server/Server.sln

@@ -15,6 +15,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ENet", "ThirdParty\ENet\ENe
 EndProject
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Server.App", "App\Server.App.csproj", "{3F8DC04C-9E05-403F-B6A5-36293EB99937}"
 EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nuget", "ThirdParty\Nuget\Nuget.csproj", "{F6F8E6AB-632C-4C6E-BFB1-B39570FF2135}"
+EndProject
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
 		Debug|Any CPU = Debug|Any CPU
@@ -83,11 +85,24 @@ Global
 		{3F8DC04C-9E05-403F-B6A5-36293EB99937}.Release|x64.Build.0 = Release|Any CPU
 		{3F8DC04C-9E05-403F-B6A5-36293EB99937}.Release|x86.ActiveCfg = Release|Any CPU
 		{3F8DC04C-9E05-403F-B6A5-36293EB99937}.Release|x86.Build.0 = Release|Any CPU
+		{F6F8E6AB-632C-4C6E-BFB1-B39570FF2135}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{F6F8E6AB-632C-4C6E-BFB1-B39570FF2135}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{F6F8E6AB-632C-4C6E-BFB1-B39570FF2135}.Debug|x64.ActiveCfg = Debug|Any CPU
+		{F6F8E6AB-632C-4C6E-BFB1-B39570FF2135}.Debug|x64.Build.0 = Debug|Any CPU
+		{F6F8E6AB-632C-4C6E-BFB1-B39570FF2135}.Debug|x86.ActiveCfg = Debug|Any CPU
+		{F6F8E6AB-632C-4C6E-BFB1-B39570FF2135}.Debug|x86.Build.0 = Debug|Any CPU
+		{F6F8E6AB-632C-4C6E-BFB1-B39570FF2135}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{F6F8E6AB-632C-4C6E-BFB1-B39570FF2135}.Release|Any CPU.Build.0 = Release|Any CPU
+		{F6F8E6AB-632C-4C6E-BFB1-B39570FF2135}.Release|x64.ActiveCfg = Release|Any CPU
+		{F6F8E6AB-632C-4C6E-BFB1-B39570FF2135}.Release|x64.Build.0 = Release|Any CPU
+		{F6F8E6AB-632C-4C6E-BFB1-B39570FF2135}.Release|x86.ActiveCfg = Release|Any CPU
+		{F6F8E6AB-632C-4C6E-BFB1-B39570FF2135}.Release|x86.Build.0 = Release|Any CPU
 	EndGlobalSection
 	GlobalSection(SolutionProperties) = preSolution
 		HideSolutionNode = FALSE
 	EndGlobalSection
 	GlobalSection(NestedProjects) = preSolution
 		{C9992B7C-313E-4C9F-A954-640D01EDFB58} = {01CCAD69-09B1-42F9-8A39-489268BEE18D}
+		{F6F8E6AB-632C-4C6E-BFB1-B39570FF2135} = {01CCAD69-09B1-42F9-8A39-489268BEE18D}
 	EndGlobalSection
 EndGlobal

+ 4 - 0
Server/ThirdParty/Nuget/Nuget.csproj

@@ -30,6 +30,10 @@
     <WarningLevel>4</WarningLevel>
   </PropertyGroup>
   <ItemGroup>
+    <Reference Include="CommandLine, Version=1.9.71.2, Culture=neutral, PublicKeyToken=de6f01bd326f8c32, processorArchitecture=MSIL">
+      <HintPath>..\..\packages\CommandLineParser.1.9.71\lib\net45\CommandLine.dll</HintPath>
+      <Private>True</Private>
+    </Reference>
     <Reference Include="ICSharpCode.SharpZipLib, Version=0.86.0.518, Culture=neutral, PublicKeyToken=1b03e6acf1164f73, processorArchitecture=MSIL">
       <HintPath>..\packages\SharpZipLib.0.86.0\lib\20\ICSharpCode.SharpZipLib.dll</HintPath>
       <Private>True</Private>

+ 1 - 0
Server/ThirdParty/Nuget/packages.config

@@ -1,5 +1,6 @@
 <?xml version="1.0" encoding="utf-8"?>
 <packages>
+  <package id="CommandLineParser" version="1.9.71" targetFramework="net461" />
   <package id="MongoDB.Bson" version="2.3.0" targetFramework="net461" />
   <package id="NLog" version="4.3.10" targetFramework="net461" />
   <package id="protobuf-net" version="2.1.0" targetFramework="net461" />

+ 0 - 2
Unity/Assets/Plugins/Base/Component/EventComponent.cs

@@ -1,8 +1,6 @@
 using System;
 using System.Collections.Generic;
 using System.Reflection;
-using Base;
-using Object = Base.Object;
 
 namespace Base
 {

+ 4 - 4
Unity/Assets/Plugins/Base/Component/MessageComponent.cs

@@ -115,9 +115,9 @@ namespace Base
 				{
 					Response response = MongoHelper.FromBson<Response>(bytes, offset, count);
 					ushort opcode = this.messageHandler.MessageOpcode[request.GetType()];
-					if (response.ErrorMessage.errno != 0)
+					if (response.ErrorMessage.Errno != 0)
 					{
-						tcs.SetException(new RpcException(response.ErrorMessage.errno, response.ErrorMessage.msg.Utf8ToStr()));
+						tcs.SetException(new RpcException(response.ErrorMessage.Errno, response.ErrorMessage.Message));
 						return;
 					}
 					tcs.SetResult(response);
@@ -149,9 +149,9 @@ namespace Base
 				try
 				{
 					Response response = MongoHelper.FromBson<Response>(bytes, offset, count);
-					if (response.ErrorMessage.errno != 0)
+					if (response.ErrorMessage.Errno != 0)
 					{
-						tcs.SetException(new RpcException(response.ErrorMessage.errno,  response.ErrorMessage.msg.Utf8ToStr()));
+						tcs.SetException(new RpcException(response.ErrorMessage.Errno,  response.ErrorMessage.Message));
 						return;
 					}
 					tcs.SetResult(response);

+ 7 - 7
Unity/Assets/Plugins/Base/Component/MessageHandlerComponent.cs

@@ -5,16 +5,16 @@ using System.Reflection;
 namespace Base
 {
 	[ObjectEvent]
-	public class MessageHandlerComponentEvent : ObjectEvent<MessageHandlerComponent>, ILoader, IAwake<MessageType>
+	public class MessageHandlerComponentEvent : ObjectEvent<MessageHandlerComponent>, ILoader, IAwake<string>
 	{
 		public void Load()
 		{
 			this.GetValue().Load();
 		}
 
-		public void Awake(MessageType messageType)
+		public void Awake(string appType)
 		{
-			this.GetValue().Awake(messageType);
+			this.GetValue().Awake(appType);
 		}
 	}
 	
@@ -23,13 +23,13 @@ namespace Base
 	/// </summary>
 	public class MessageHandlerComponent: Component
 	{
-		private MessageType MessageType;
+		private string AppType;
 		private Dictionary<ushort, List<Action<Entity, byte[], int, int>>> events;
 		public Dictionary<Type, ushort> MessageOpcode { get; private set; } = new Dictionary<Type, ushort>();
 		
-		public void Awake(MessageType messageType)
+		public void Awake(string appType)
 		{
-			this.MessageType = messageType;
+			this.AppType = appType;
 			this.Load();
 		}
 
@@ -51,7 +51,7 @@ namespace Base
 					}
 
 					MessageAttribute messageAttribute = (MessageAttribute)attrs[0];
-					if (messageAttribute.MessageType != this.MessageType)
+					if (messageAttribute.AppType != this.AppType)
 					{
 						continue;
 					}

+ 13 - 37
Unity/Assets/Plugins/Base/Component/NetworkComponent.cs

@@ -4,7 +4,7 @@ using System.Net.Sockets;
 namespace Base
 {
 	[ObjectEvent]
-	public class NetworkComponentEvent : ObjectEvent<NetworkComponent>, IUpdate, IAwake<NetworkProtocol>
+	public class NetworkComponentEvent : ObjectEvent<NetworkComponent>, IUpdate, IAwake<NetworkProtocol, string, int>
 	{
 		public void Update()
 		{
@@ -12,19 +12,19 @@ namespace Base
 			component.Update();
 		}
 
-		public void Awake(NetworkProtocol protocol)
+		public void Awake(NetworkProtocol protocol, string host, int port)
 		{
-			this.GetValue().Awake(protocol);
+			this.GetValue().Awake(protocol, host, port);
 		}
 	}
 
 	public class NetworkComponent: Component
 	{
-		private AService service;
+		public AService Service;
 		
 		private void Dispose(bool disposing)
 		{
-			if (this.service == null)
+			if (this.Service == null)
 			{
 				return;
 			}
@@ -33,10 +33,10 @@ namespace Base
 
 			if (disposing)
 			{
-				this.service.Dispose();
+				this.Service.Dispose();
 			}
 
-			this.service = null;
+			this.Service = null;
 		}
 
 		public override void Dispose()
@@ -48,15 +48,15 @@ namespace Base
 			this.Dispose(true);
 		}
 
-		public void Awake(NetworkProtocol protocol)
+		public void Awake(NetworkProtocol protocol, string host, int port)
 		{
 			switch (protocol)
 			{
 				case NetworkProtocol.TCP:
-					this.service = new TService { OnError = this.OnError };
+					this.Service = new TService(host, port) { OnError = this.OnError };
 					break;
 				case NetworkProtocol.UDP:
-					this.service = new UService { OnError = this.OnError };
+					this.Service = new UService(host, port) { OnError = this.OnError };
 					break;
 				default:
 					throw new ArgumentOutOfRangeException();
@@ -65,42 +65,18 @@ namespace Base
 
 		public void Update()
 		{
-			if (this.service == null)
+			if (this.Service == null)
 			{
 				return;
 			}
-			this.service.Update();
+			this.Service.Update();
 		}
-
-		public AChannel GetChannel(long channelId)
-		{
-			AChannel channel = this.service?.GetChannel(channelId);
-			return channel;
-		}
-
-
-		public AChannel ConnectChannel(string host, int port)
-		{
-			AChannel channel = this.service.GetChannel(host, port);
-			return channel;
-		}
-
+		
 		public void OnError(long id, SocketError error)
 		{
 			Env env = new Env();
 			env[EnvBaseKey.ChannelError] = error;
 			Game.Scene.GetComponent<EventComponent>().Run(EventBaseType.NetworkChannelError, env);
 		}
-
-		public void RemoveChannel(long channelId)
-		{
-			AChannel channel = this.service?.GetChannel(channelId);
-			if (channel == null)
-			{
-				return;
-			}
-			this.service.Remove(channelId);
-			channel.Dispose();
-		}
 	}
 }

+ 3 - 3
Unity/Assets/Plugins/Base/Message/IErrorMessage.cs

@@ -5,12 +5,12 @@
 	/// </summary>
 	public interface IErrorMessage
 	{
-		ErrorMessage ErrorMessage { get; }
+		ErrorMessage ErrorMessage { get; set; }
 	}
 	
 	public class ErrorMessage
 	{
-		public int errno = 0;
-		public byte[] msg = "".ToByteArray();
+		public int Errno = 0;
+		public string Message = "";
 	}
 }

+ 4 - 14
Unity/Assets/Plugins/Base/Message/MessageAttribute.cs

@@ -2,28 +2,18 @@
 
 namespace Base
 {
-	public enum MessageType
-	{
-		Client,
-		Realm,
-		Gate,
-	}
-
 	/// <summary>
 	/// 搭配MessageComponent用来分发消息
 	/// </summary>
 	public class MessageAttribute : Attribute
 	{
 		public ushort Opcode { get; private set; }
+		
+		public string AppType { get; private set; }
 
-		/// <summary>
-		/// MessageComponent所有者的SceneType必须相同,这个Message Handle才会注册到MessageComponent里面
-		/// </summary>
-		public MessageType MessageType { get; private set; }
-
-		public MessageAttribute(MessageType messageType, ushort opcode)
+		public MessageAttribute(string appType, ushort opcode)
 		{
-			this.MessageType = messageType;
+			this.AppType = appType;
 			this.Opcode = opcode;
 		}
 	}

binární
Unity/Assets/Resources/Code.prefab


+ 12 - 2
Unity/Assets/Scripts/Init.cs

@@ -1,5 +1,7 @@
-using Base;
+using System.Reflection;
+using Base;
 using UnityEngine;
+using Object = Base.Object;
 
 namespace Model
 {
@@ -7,7 +9,15 @@ namespace Model
 	{
 		private void Start()
 		{
-			Share.Scene.GetComponent<EventComponent>().Run(EventIdType.InitSceneStart);
+			Object.ObjectManager.Register("Base", typeof(Game).Assembly);
+
+			GameObject code = (GameObject)Resources.Load("Code");
+			byte[] assBytes = code.Get<TextAsset>("Controller.dll").bytes;
+			byte[] mdbBytes = code.Get<TextAsset>("Controller.dll.mdb").bytes;
+			Assembly assembly = Assembly.Load(assBytes, mdbBytes);
+			Object.ObjectManager.Register("Controller", assembly);
+
+			Game.Scene.AddComponent<EventComponent>().Run(EventIdType.InitSceneStart);
 		}
 
 		private void Update()

+ 11 - 0
Unity/Assets/Scripts/Message/AppType.cs

@@ -0,0 +1,11 @@
+namespace Model
+{
+	public static class AppType
+	{
+		public const string Client = "Client";
+		public const string Robot = "Robot";
+
+		public const string Realm = "Realm";
+		public const string Gate = "Gate";
+	}
+}

+ 12 - 0
Unity/Assets/Scripts/Message/AppType.cs.meta

@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: 1486b49b78eabf64898a2f3b9ab415e8
+timeCreated: 1476436787
+licenseType: Pro
+MonoImporter:
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 4 - 89
Unity/Assets/Scripts/Message/Message.cs

@@ -4,100 +4,15 @@ using MongoDB.Bson.Serialization.Attributes;
 namespace Model
 {
 	[BsonIgnoreExtraElements]
-	public class C2S_LoginGate
+	public class C2S_Login
 	{
 		public string Account;
-		
-		public string Passwd;
-		
-		public string Token;
-		
-		public string Mac;
-
-	}
-
-	[BsonIgnoreExtraElements]
-	public class ReconnectBattle
-	{
-		public long RoomGuid;
-		
-		public string BattleIp;
-		
-		public short BattlePort;
-
+		public string Password;
 	}
 
 	[BsonIgnoreExtraElements]
-	public class S2C_LoginGate: IErrorMessage
+	public class S2C_Login: IErrorMessage
 	{
-		public ErrorMessage Errmsg;
-		
-		public long PlayerGuid;
-		
-		public string PlayerName;
-
-		//1 登录大厅
-		//2 断线重连
-		//3 取名字
-		public int Type;
-		
-		public ReconnectBattle Reconnect;
-
-		public ErrorMessage ErrorMessage { get { return this.Errmsg; } }
-	}
-
-	[BsonIgnoreExtraElements]
-	public class C2S_FetchServerTime
-	{
-	}
-
-	[BsonIgnoreExtraElements]
-	public class S2C_FetchServerTime: IErrorMessage
-	{
-		public ErrorMessage Errmsg;
-
-		//服务器的真实时间
-		public long ServerTime;
-
-		public ErrorMessage ErrorMessage { get { return this.Errmsg; } }
-	}
-
-	[BsonIgnoreExtraElements]
-	public class C2S_LogoutGate
-	{
-	}
-
-	[BsonIgnoreExtraElements]
-	public class S2C_LogoutGate: IErrorMessage
-	{
-		public ErrorMessage Errmsg;
-
-		public ErrorMessage ErrorMessage { get { return this.Errmsg; } }
-	}
-	
-	public class S2C_InitBuffInfo
-	{
-		/// <summary>
-		/// buff所有者
-		/// </summary>
-		public int UnitGuid;
-
-		public int BuffGuid;
-
-		public int BuffId;
-
-		public int Level = 1;
-
-		//叠层数量
-		public int StackCount = 1;
-
-		//总时间和剩余持续时间,单位毫秒,如果是0,表示一个永久的BUFF
-		public int TotalTime = 0;
-
-		public long ExpiredTick = 0;
-
-		//来源GUID
-		public int CasterGuid = 0;
-
+		public ErrorMessage ErrorMessage { get; set; }
 	}
 }

+ 2 - 1
Unity/Assets/Scripts/Message/Opcode.cs

@@ -3,7 +3,8 @@ namespace Model
 {
 	public static class Opcode
 	{
-		public const ushort S2C_InitBuffInfo = 1;
+		public const ushort C2S_Login = 1;
+		public const ushort S2C_InitBuffInfo = 2;
 		public const ushort S2C_StartGame = 4;
 	}
 }

+ 2 - 9
Unity/Controller/Event/InitSceneStartEvent_InitGame.cs

@@ -15,20 +15,13 @@ namespace Controller
 	{
 		public async void Run()
 		{
-			GameObject code = (GameObject)Resources.Load("Code/Code");
-			byte[] assBytes = code.Get<TextAsset>("Controller.dll").bytes;
-			byte[] mdbBytes = code.Get<TextAsset>("Controller.dll.mdb").bytes;
-			Assembly assembly = Assembly.Load(assBytes, mdbBytes);
-			Object.ObjectManager.Register("Controller", assembly);
-			Object.ObjectManager.Register("Base", typeof(Game).Assembly);
-
 			Game.Scene.AddComponent<MessageComponent>();
 			Game.Scene.AddComponent<ChildrenComponent>();
 
 			try
 			{
-				S2C_FetchServerTime s2CFetchServerTime = await Game.Scene.GetComponent<MessageComponent>().CallAsync<S2C_FetchServerTime>(new C2S_FetchServerTime());
-				Log.Info($"server time is: {s2CFetchServerTime.ServerTime}");
+				S2C_Login s2CLogin = await Game.Scene.GetComponent<MessageComponent>().CallAsync<S2C_Login>(new C2S_Login {Account = "tanghai", Password = "1111111"});
+				Log.Info(MongoHelper.ToJson(s2CLogin));
 			}
 			catch (RpcException e)
 			{

+ 0 - 14
Unity/Controller/Message/S2C_InitBuffInfoEvent.cs

@@ -1,14 +0,0 @@
-using Base;
-using Model;
-
-namespace Controller
-{
-	[Message(MessageType.Client, Opcode.S2C_InitBuffInfo)]
-	public class S2C_InitBuffInfoEvent: AMEvent<S2C_InitBuffInfo>
-	{
-		public override void Run(Entity scene, S2C_InitBuffInfo buffInfo)
-		{
-			Log.Info(MongoHelper.ToJson(buffInfo));
-		}
-	}
-}

+ 1 - 1
Unity/Controller/Unity.Controller.csproj

@@ -54,7 +54,6 @@
   </ItemGroup>
   <ItemGroup>
     <Compile Include="Event\InitSceneStartEvent_InitGame.cs" />
-    <Compile Include="Message\S2C_InitBuffInfoEvent.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
   </ItemGroup>
   <ItemGroup>
@@ -71,6 +70,7 @@
     <Folder Include="Factory\" />
     <Folder Include="Helper\" />
     <Folder Include="Logic\" />
+    <Folder Include="Message\" />
   </ItemGroup>
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
   <PropertyGroup>

+ 1 - 0
Unity/Unity.CSharp.csproj

@@ -90,6 +90,7 @@
     <Compile Include="Assets\Scripts\Event\EnvKey.cs" />
     <Compile Include="Assets\Scripts\GameObjectHelper.cs" />
     <Compile Include="Assets\Scripts\Init.cs" />
+    <Compile Include="Assets\Scripts\Message\AppType.cs" />
     <Compile Include="Assets\Scripts\Message\ErrorCode.cs" />
     <Compile Include="Assets\Scripts\Message\Message.cs" />
     <Compile Include="Assets\Scripts\Message\Opcode.cs" />