上传战斗服务

This commit is contained in:
liwei1dao 2022-11-23 19:08:31 +08:00
parent e5a41d5f6e
commit 93d1bb60f9
23 changed files with 571 additions and 7 deletions

64
Client.cs Normal file
View File

@ -0,0 +1,64 @@
using Fleck;
using System;
using pb = global::Google.Protobuf;
namespace BattleServer
{
/// <summary>
/// 客户端链接对象
/// </summary>
class Client
{
private IWebSocketConnection socket;
public Client(IWebSocketConnection _socket)
{
socket = _socket;
socket.OnMessage = domessage;
socket.OnBinary = doBinary;
}
private void domessage(string message)
{
}
/// <summary>
/// 接收rpc数据
/// </summary>
/// <param name="message"></param>
private void doBinary(byte[] message)
{
Pb.RpcMessage msg = Deserialize<Pb.RpcMessage>(message);
Task.Run(() =>
{
handle(msg);
});
}
/// <summary>
/// 处理远程请求
/// </summary>
/// <param name="msg"></param>
private void handle(Pb.RpcMessage msg)
{
}
/// <summary>
/// 反序列化protobuf
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="dataBytes"></param>
/// <returns></returns>
public static T Deserialize<T>(byte[] dataBytes) where T : pb.IMessage, new()
{
T msg = new T();
msg = (T)msg.Descriptor.Parser.ParseFrom(dataBytes);
return msg;
}
}
}

View File

@ -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();
}
}
}

29
Service.cs Normal file
View File

@ -0,0 +1,29 @@
using Fleck;
using System;
namespace BattleServer
{
/// <summary>
/// 服务端
/// </summary>
class Service
{
private WebSocketServer server;
private List<Client> clients;
public Service()
{
var server = new WebSocketServer("ws://127.0.0.1:9898"); //创建webscoket服务端实例
server.Start(onAccept);
clients = new List<Client>();
}
private void onAccept(IWebSocketConnection webSocket)
{
Client client = new Client(webSocket);
clients.Add(client);
}
}
}

View File

@ -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": ""
}
}
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,9 @@
{
"runtimeOptions": {
"tfm": "net6.0",
"framework": {
"name": "Microsoft.NETCore.App",
"version": "6.0.0"
}
}
}

View File

@ -7,4 +7,9 @@
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Fleck" Version="1.2.0" />
<PackageReference Include="Google.Protobuf" Version="3.21.9" />
</ItemGroup>
</Project>

Binary file not shown.

View File

@ -0,0 +1 @@
e2d38b4f8971f223869a8c99d5ae024a414a4f80

View File

@ -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

Binary file not shown.

View File

@ -0,0 +1 @@
a887c8022839817bde2d68d56c282db270cf08e1

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -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",

View File

@ -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",

View File

@ -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": []
}

318
pb/Comm.cs Normal file
View File

@ -0,0 +1,318 @@
// <auto-generated>
// Generated by the protocol buffer compiler. DO NOT EDIT!
// source: comm.proto
// </auto-generated>
#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 {
/// <summary>Holder for reflection information generated from comm.proto</summary>
public static partial class CommReflection {
#region Descriptor
/// <summary>File descriptor for comm.proto</summary>
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
/// <summary>
///公用消息结构代码
/// </summary>
public sealed partial class RpcMessage : pb::IMessage<RpcMessage>
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
, pb::IBufferMessage
#endif
{
private static readonly pb::MessageParser<RpcMessage> _parser = new pb::MessageParser<RpcMessage>(() => new RpcMessage());
private pb::UnknownFieldSet _unknownFields;
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public static pb::MessageParser<RpcMessage> 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);
}
/// <summary>Field number for the "rid" field.</summary>
public const int RidFieldNumber = 1;
private ulong rid_;
/// <summary>
///服务回调id
/// </summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public ulong Rid {
get { return rid_; }
set {
rid_ = value;
}
}
/// <summary>Field number for the "method" field.</summary>
public const int MethodFieldNumber = 2;
private string method_ = "";
/// <summary>
///方法名
/// </summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public string Method {
get { return method_; }
set {
method_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
}
}
/// <summary>Field number for the "data" field.</summary>
public const int DataFieldNumber = 3;
private pb::ByteString data_ = pb::ByteString.Empty;
/// <summary>
///数据
/// </summary>
[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