diff --git a/Client.cs b/Client.cs new file mode 100644 index 0000000..fde6302 --- /dev/null +++ b/Client.cs @@ -0,0 +1,64 @@ +using Fleck; +using System; +using pb = global::Google.Protobuf; + +namespace BattleServer +{ + /// + /// 客户端链接对象 + /// + class Client + { + private IWebSocketConnection socket; + + public Client(IWebSocketConnection _socket) + { + socket = _socket; + socket.OnMessage = domessage; + socket.OnBinary = doBinary; + } + private void domessage(string message) + { + + } + + /// + /// 接收rpc数据 + /// + /// + private void doBinary(byte[] message) + { + Pb.RpcMessage msg = Deserialize(message); + Task.Run(() => + { + handle(msg); + }); + + } + + /// + /// 处理远程请求 + /// + /// + private void handle(Pb.RpcMessage msg) + { + + } + + + /// + /// 反序列化protobuf + /// + /// + /// + /// + public static T Deserialize(byte[] dataBytes) where T : pb.IMessage, new() + { + T msg = new T(); + msg = (T)msg.Descriptor.Parser.ParseFrom(dataBytes); + return msg; + } + + + } +} \ No newline at end of file diff --git a/Program.cs b/Program.cs index 3751555..72554ed 100644 --- a/Program.cs +++ b/Program.cs @@ -1,2 +1,17 @@ -// See https://aka.ms/new-console-template for more information -Console.WriteLine("Hello, World!"); +using Fleck; +using System; + + +namespace BattleServer +{ + class Program + { + static void Main(string[] args) + { + // Console.WriteLine("BattleServer Start!"); + + // Console.ReadKey(); + + } + } +} \ No newline at end of file diff --git a/Service.cs b/Service.cs new file mode 100644 index 0000000..54e7e1b --- /dev/null +++ b/Service.cs @@ -0,0 +1,29 @@ +using Fleck; +using System; + + +namespace BattleServer +{ + + /// + /// 服务端 + /// + class Service + { + private WebSocketServer server; + private List clients; + + public Service() + { + var server = new WebSocketServer("ws://127.0.0.1:9898"); //创建webscoket服务端实例 + server.Start(onAccept); + clients = new List(); + } + + private void onAccept(IWebSocketConnection webSocket) + { + Client client = new Client(webSocket); + clients.Add(client); + } + } +} \ No newline at end of file diff --git a/bin/Debug/net6.0/dfbattle.deps.json b/bin/Debug/net6.0/dfbattle.deps.json new file mode 100644 index 0000000..a8b12b5 --- /dev/null +++ b/bin/Debug/net6.0/dfbattle.deps.json @@ -0,0 +1,23 @@ +{ + "runtimeTarget": { + "name": ".NETCoreApp,Version=v6.0", + "signature": "" + }, + "compilationOptions": {}, + "targets": { + ".NETCoreApp,Version=v6.0": { + "dfbattle/1.0.0": { + "runtime": { + "dfbattle.dll": {} + } + } + } + }, + "libraries": { + "dfbattle/1.0.0": { + "type": "project", + "serviceable": false, + "sha512": "" + } + } +} \ No newline at end of file diff --git a/bin/Debug/net6.0/dfbattle.dll b/bin/Debug/net6.0/dfbattle.dll new file mode 100644 index 0000000..4627d3f Binary files /dev/null and b/bin/Debug/net6.0/dfbattle.dll differ diff --git a/bin/Debug/net6.0/dfbattle.exe b/bin/Debug/net6.0/dfbattle.exe new file mode 100644 index 0000000..864f1f2 Binary files /dev/null and b/bin/Debug/net6.0/dfbattle.exe differ diff --git a/bin/Debug/net6.0/dfbattle.pdb b/bin/Debug/net6.0/dfbattle.pdb new file mode 100644 index 0000000..907940e Binary files /dev/null and b/bin/Debug/net6.0/dfbattle.pdb differ diff --git a/bin/Debug/net6.0/dfbattle.runtimeconfig.json b/bin/Debug/net6.0/dfbattle.runtimeconfig.json new file mode 100644 index 0000000..4986d16 --- /dev/null +++ b/bin/Debug/net6.0/dfbattle.runtimeconfig.json @@ -0,0 +1,9 @@ +{ + "runtimeOptions": { + "tfm": "net6.0", + "framework": { + "name": "Microsoft.NETCore.App", + "version": "6.0.0" + } + } +} \ No newline at end of file diff --git a/dfbattle.csproj b/dfbattle.csproj index 74abf5c..1a5551c 100644 --- a/dfbattle.csproj +++ b/dfbattle.csproj @@ -7,4 +7,9 @@ enable + + + + + diff --git a/obj/Debug/net6.0/apphost.exe b/obj/Debug/net6.0/apphost.exe new file mode 100644 index 0000000..864f1f2 Binary files /dev/null and b/obj/Debug/net6.0/apphost.exe differ diff --git a/obj/Debug/net6.0/dfbattle.assets.cache b/obj/Debug/net6.0/dfbattle.assets.cache index 0554c4d..2b32cf2 100644 Binary files a/obj/Debug/net6.0/dfbattle.assets.cache and b/obj/Debug/net6.0/dfbattle.assets.cache differ diff --git a/obj/Debug/net6.0/dfbattle.csproj.AssemblyReference.cache b/obj/Debug/net6.0/dfbattle.csproj.AssemblyReference.cache index 53467be..5bc15e6 100644 Binary files a/obj/Debug/net6.0/dfbattle.csproj.AssemblyReference.cache and b/obj/Debug/net6.0/dfbattle.csproj.AssemblyReference.cache differ diff --git a/obj/Debug/net6.0/dfbattle.csproj.CoreCompileInputs.cache b/obj/Debug/net6.0/dfbattle.csproj.CoreCompileInputs.cache new file mode 100644 index 0000000..b5a73c5 --- /dev/null +++ b/obj/Debug/net6.0/dfbattle.csproj.CoreCompileInputs.cache @@ -0,0 +1 @@ +e2d38b4f8971f223869a8c99d5ae024a414a4f80 diff --git a/obj/Debug/net6.0/dfbattle.csproj.FileListAbsolute.txt b/obj/Debug/net6.0/dfbattle.csproj.FileListAbsolute.txt new file mode 100644 index 0000000..fe253fa --- /dev/null +++ b/obj/Debug/net6.0/dfbattle.csproj.FileListAbsolute.txt @@ -0,0 +1,15 @@ +E:\c#\dfbattle\bin\Debug\net6.0\dfbattle.exe +E:\c#\dfbattle\bin\Debug\net6.0\dfbattle.deps.json +E:\c#\dfbattle\bin\Debug\net6.0\dfbattle.runtimeconfig.json +E:\c#\dfbattle\bin\Debug\net6.0\dfbattle.dll +E:\c#\dfbattle\bin\Debug\net6.0\dfbattle.pdb +E:\c#\dfbattle\obj\Debug\net6.0\dfbattle.csproj.AssemblyReference.cache +E:\c#\dfbattle\obj\Debug\net6.0\dfbattle.GeneratedMSBuildEditorConfig.editorconfig +E:\c#\dfbattle\obj\Debug\net6.0\dfbattle.AssemblyInfoInputs.cache +E:\c#\dfbattle\obj\Debug\net6.0\dfbattle.AssemblyInfo.cs +E:\c#\dfbattle\obj\Debug\net6.0\dfbattle.csproj.CoreCompileInputs.cache +E:\c#\dfbattle\obj\Debug\net6.0\dfbattle.dll +E:\c#\dfbattle\obj\Debug\net6.0\refint\dfbattle.dll +E:\c#\dfbattle\obj\Debug\net6.0\dfbattle.pdb +E:\c#\dfbattle\obj\Debug\net6.0\dfbattle.genruntimeconfig.cache +E:\c#\dfbattle\obj\Debug\net6.0\ref\dfbattle.dll diff --git a/obj/Debug/net6.0/dfbattle.dll b/obj/Debug/net6.0/dfbattle.dll new file mode 100644 index 0000000..4627d3f Binary files /dev/null and b/obj/Debug/net6.0/dfbattle.dll differ diff --git a/obj/Debug/net6.0/dfbattle.genruntimeconfig.cache b/obj/Debug/net6.0/dfbattle.genruntimeconfig.cache new file mode 100644 index 0000000..b2623cb --- /dev/null +++ b/obj/Debug/net6.0/dfbattle.genruntimeconfig.cache @@ -0,0 +1 @@ +a887c8022839817bde2d68d56c282db270cf08e1 diff --git a/obj/Debug/net6.0/dfbattle.pdb b/obj/Debug/net6.0/dfbattle.pdb new file mode 100644 index 0000000..907940e Binary files /dev/null and b/obj/Debug/net6.0/dfbattle.pdb differ diff --git a/obj/Debug/net6.0/ref/dfbattle.dll b/obj/Debug/net6.0/ref/dfbattle.dll new file mode 100644 index 0000000..a934f9f Binary files /dev/null and b/obj/Debug/net6.0/ref/dfbattle.dll differ diff --git a/obj/Debug/net6.0/refint/dfbattle.dll b/obj/Debug/net6.0/refint/dfbattle.dll new file mode 100644 index 0000000..a934f9f Binary files /dev/null and b/obj/Debug/net6.0/refint/dfbattle.dll differ diff --git a/obj/dfbattle.csproj.nuget.dgspec.json b/obj/dfbattle.csproj.nuget.dgspec.json index d6dd5a9..26a6e0d 100644 --- a/obj/dfbattle.csproj.nuget.dgspec.json +++ b/obj/dfbattle.csproj.nuget.dgspec.json @@ -37,6 +37,16 @@ "frameworks": { "net6.0": { "targetAlias": "net6.0", + "dependencies": { + "Fleck": { + "target": "Package", + "version": "[1.2.0, )" + }, + "Google.Protobuf": { + "target": "Package", + "version": "[3.21.9, )" + } + }, "imports": [ "net461", "net462", diff --git a/obj/project.assets.json b/obj/project.assets.json index 654c894..bd77e61 100644 --- a/obj/project.assets.json +++ b/obj/project.assets.json @@ -1,11 +1,72 @@ { "version": 3, "targets": { - "net6.0": {} + "net6.0": { + "Fleck/1.2.0": { + "type": "package", + "compile": { + "lib/netcoreapp2.0/Fleck.dll": {} + }, + "runtime": { + "lib/netcoreapp2.0/Fleck.dll": {} + } + }, + "Google.Protobuf/3.21.9": { + "type": "package", + "compile": { + "lib/net5.0/Google.Protobuf.dll": {} + }, + "runtime": { + "lib/net5.0/Google.Protobuf.dll": {} + } + } + } + }, + "libraries": { + "Fleck/1.2.0": { + "sha512": "bPLXn6QbLAFoviur6XbrKB0Zn6x04E8VibHXyHZeJsoC7bkUl5DVtzM5cZgDuqHkIrBqAXJyTNJwSNIc6wBJ2Q==", + "type": "package", + "path": "fleck/1.2.0", + "files": [ + ".nupkg.metadata", + ".signature.p7s", + "fleck.1.2.0.nupkg.sha512", + "fleck.nuspec", + "lib/net40/Fleck.dll", + "lib/net45/Fleck.dll", + "lib/netcoreapp2.0/Fleck.dll", + "lib/netstandard2.0/Fleck.dll" + ] + }, + "Google.Protobuf/3.21.9": { + "sha512": "OTpFujTgkmqMLbg3KT7F/iuKi1rg6s5FCS2M9XcVLDn40zL8wgXm37CY/F6MeOEXKjdcnXGCN/h7oyMkVydVsg==", + "type": "package", + "path": "google.protobuf/3.21.9", + "files": [ + ".nupkg.metadata", + ".signature.p7s", + "google.protobuf.3.21.9.nupkg.sha512", + "google.protobuf.nuspec", + "lib/net45/Google.Protobuf.dll", + "lib/net45/Google.Protobuf.pdb", + "lib/net45/Google.Protobuf.xml", + "lib/net5.0/Google.Protobuf.dll", + "lib/net5.0/Google.Protobuf.pdb", + "lib/net5.0/Google.Protobuf.xml", + "lib/netstandard1.1/Google.Protobuf.dll", + "lib/netstandard1.1/Google.Protobuf.pdb", + "lib/netstandard1.1/Google.Protobuf.xml", + "lib/netstandard2.0/Google.Protobuf.dll", + "lib/netstandard2.0/Google.Protobuf.pdb", + "lib/netstandard2.0/Google.Protobuf.xml" + ] + } }, - "libraries": {}, "projectFileDependencyGroups": { - "net6.0": [] + "net6.0": [ + "Fleck >= 1.2.0", + "Google.Protobuf >= 3.21.9" + ] }, "packageFolders": { "C:\\Users\\liwei1dao\\.nuget\\packages\\": {} @@ -43,6 +104,16 @@ "frameworks": { "net6.0": { "targetAlias": "net6.0", + "dependencies": { + "Fleck": { + "target": "Package", + "version": "[1.2.0, )" + }, + "Google.Protobuf": { + "target": "Package", + "version": "[3.21.9, )" + } + }, "imports": [ "net461", "net462", diff --git a/obj/project.nuget.cache b/obj/project.nuget.cache index 6acf619..61c74cf 100644 --- a/obj/project.nuget.cache +++ b/obj/project.nuget.cache @@ -1,8 +1,11 @@ { "version": 2, - "dgSpecHash": "kWd931FWgjxS/qlRWHPe6xqHFH6xbMHPbiEJq3WaIsCWGAkkVxmmLsfWmLcGmnG3AjYQUJAWIXPu+xkEhdUrOg==", + "dgSpecHash": "s9XIzWQ6HRV29gxJPILhV4DPvFYneeFqjFz7eLOSIrOeL1EmSxlxD4wgKwKlxq0Bw79nFNhIwrWdojuZ2uwodA==", "success": true, "projectFilePath": "E:\\c#\\dfbattle\\dfbattle.csproj", - "expectedPackageFiles": [], + "expectedPackageFiles": [ + "C:\\Users\\liwei1dao\\.nuget\\packages\\fleck\\1.2.0\\fleck.1.2.0.nupkg.sha512", + "C:\\Users\\liwei1dao\\.nuget\\packages\\google.protobuf\\3.21.9\\google.protobuf.3.21.9.nupkg.sha512" + ], "logs": [] } \ No newline at end of file diff --git a/pb/Comm.cs b/pb/Comm.cs new file mode 100644 index 0000000..4512512 --- /dev/null +++ b/pb/Comm.cs @@ -0,0 +1,318 @@ +// +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: comm.proto +// +#pragma warning disable 1591, 0612, 3021, 8981 +#region Designer generated code + +using pb = global::Google.Protobuf; +using pbc = global::Google.Protobuf.Collections; +using pbr = global::Google.Protobuf.Reflection; +using scg = global::System.Collections.Generic; +namespace Pb { + + /// Holder for reflection information generated from comm.proto + public static partial class CommReflection { + + #region Descriptor + /// File descriptor for comm.proto + public static pbr::FileDescriptor Descriptor { + get { return descriptor; } + } + private static pbr::FileDescriptor descriptor; + + static CommReflection() { + byte[] descriptorData = global::System.Convert.FromBase64String( + string.Concat( + "Cgpjb21tLnByb3RvEgJwYiI3CgpScGNNZXNzYWdlEgsKA3JpZBgBIAEoBBIO", + "CgZtZXRob2QYAiABKAkSDAoEZGF0YRgDIAEoDGIGcHJvdG8z")); + descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData, + new pbr::FileDescriptor[] { }, + new pbr::GeneratedClrTypeInfo(null, null, new pbr::GeneratedClrTypeInfo[] { + new pbr::GeneratedClrTypeInfo(typeof(global::Pb.RpcMessage), global::Pb.RpcMessage.Parser, new[]{ "Rid", "Method", "Data" }, null, null, null, null) + })); + } + #endregion + + } + #region Messages + /// + ///公用消息结构代码 + /// + public sealed partial class RpcMessage : pb::IMessage + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + , pb::IBufferMessage + #endif + { + private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new RpcMessage()); + private pb::UnknownFieldSet _unknownFields; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public static pb::MessageParser Parser { get { return _parser; } } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public static pbr::MessageDescriptor Descriptor { + get { return global::Pb.CommReflection.Descriptor.MessageTypes[0]; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + pbr::MessageDescriptor pb::IMessage.Descriptor { + get { return Descriptor; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public RpcMessage() { + OnConstruction(); + } + + partial void OnConstruction(); + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public RpcMessage(RpcMessage other) : this() { + rid_ = other.rid_; + method_ = other.method_; + data_ = other.data_; + _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public RpcMessage Clone() { + return new RpcMessage(this); + } + + /// Field number for the "rid" field. + public const int RidFieldNumber = 1; + private ulong rid_; + /// + ///服务回调id + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public ulong Rid { + get { return rid_; } + set { + rid_ = value; + } + } + + /// Field number for the "method" field. + public const int MethodFieldNumber = 2; + private string method_ = ""; + /// + ///方法名 + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public string Method { + get { return method_; } + set { + method_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + + /// Field number for the "data" field. + public const int DataFieldNumber = 3; + private pb::ByteString data_ = pb::ByteString.Empty; + /// + ///数据 + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public pb::ByteString Data { + get { return data_; } + set { + data_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public override bool Equals(object other) { + return Equals(other as RpcMessage); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public bool Equals(RpcMessage other) { + if (ReferenceEquals(other, null)) { + return false; + } + if (ReferenceEquals(other, this)) { + return true; + } + if (Rid != other.Rid) return false; + if (Method != other.Method) return false; + if (Data != other.Data) return false; + return Equals(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public override int GetHashCode() { + int hash = 1; + if (Rid != 0UL) hash ^= Rid.GetHashCode(); + if (Method.Length != 0) hash ^= Method.GetHashCode(); + if (Data.Length != 0) hash ^= Data.GetHashCode(); + if (_unknownFields != null) { + hash ^= _unknownFields.GetHashCode(); + } + return hash; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public override string ToString() { + return pb::JsonFormatter.ToDiagnosticString(this); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public void WriteTo(pb::CodedOutputStream output) { + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + output.WriteRawMessage(this); + #else + if (Rid != 0UL) { + output.WriteRawTag(8); + output.WriteUInt64(Rid); + } + if (Method.Length != 0) { + output.WriteRawTag(18); + output.WriteString(Method); + } + if (Data.Length != 0) { + output.WriteRawTag(26); + output.WriteBytes(Data); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(output); + } + #endif + } + + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) { + if (Rid != 0UL) { + output.WriteRawTag(8); + output.WriteUInt64(Rid); + } + if (Method.Length != 0) { + output.WriteRawTag(18); + output.WriteString(Method); + } + if (Data.Length != 0) { + output.WriteRawTag(26); + output.WriteBytes(Data); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public int CalculateSize() { + int size = 0; + if (Rid != 0UL) { + size += 1 + pb::CodedOutputStream.ComputeUInt64Size(Rid); + } + if (Method.Length != 0) { + size += 1 + pb::CodedOutputStream.ComputeStringSize(Method); + } + if (Data.Length != 0) { + size += 1 + pb::CodedOutputStream.ComputeBytesSize(Data); + } + if (_unknownFields != null) { + size += _unknownFields.CalculateSize(); + } + return size; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public void MergeFrom(RpcMessage other) { + if (other == null) { + return; + } + if (other.Rid != 0UL) { + Rid = other.Rid; + } + if (other.Method.Length != 0) { + Method = other.Method; + } + if (other.Data.Length != 0) { + Data = other.Data; + } + _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + public void MergeFrom(pb::CodedInputStream input) { + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + input.ReadRawMessage(this); + #else + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); + break; + case 8: { + Rid = input.ReadUInt64(); + break; + } + case 18: { + Method = input.ReadString(); + break; + } + case 26: { + Data = input.ReadBytes(); + break; + } + } + } + #endif + } + + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + [global::System.CodeDom.Compiler.GeneratedCode("protoc", null)] + void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input); + break; + case 8: { + Rid = input.ReadUInt64(); + break; + } + case 18: { + Method = input.ReadString(); + break; + } + case 26: { + Data = input.ReadBytes(); + break; + } + } + } + } + #endif + + } + + #endregion + +} + +#endregion Designer generated code