This commit is contained in:
PC-20230316NUNE\Administrator
2024-09-29 20:18:48 +08:00
parent e822544d9c
commit c5700ce655
1797 changed files with 40580 additions and 23804 deletions

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: dd0b2e123a2647faa14dc3c101cb9924
timeCreated: 1706264437

View File

@@ -0,0 +1,39 @@
namespace Plugins.JNGame.Network.Action
{
public enum NActionEnum : int
{
Ping = 1, //PING
NActionDemo = 2, //Demo 消息
NActionDemo2 = 3, //Demo 消息
LocalClientConnect = 11, //客户端连接 (用于客户端通知)
LocalClientDisconnect = 12, //客户端断开 (用于客户端通知)
ServerClientConnect = 13, //服务器客户端连接 (用于业务服务端通知)
ServerClientDisconnect = 14, //服务器客户端断开 (用于业务服务端通知)
NSyncFrameStart = 100, //帧同步开始
NSyncFrameEnd = 101, //帧同步结束
NSyncFrameBack = 102, //帧同步回调
NSyncFrameInput = 103, //帧同步输入
NSyncFrameReset = 104, //重置帧同步
NSyncStateStartRequest = 110, //状态同步开始
NSyncStateEndRequest = 111, //状态同步结束
NSyncStateBackResponse = 112, //状态同步回调
NSyncStateDataUpdateRequest = 113, //状态同步更新
NSyncStateAllUpdateRequest = 114, //状态全量更新
NSyncStateAllBackResponse = 115, //状态同步全量回调
NSyncStateDataUpdate = 121, //状态同步更新
NSyncStateAllUpdate = 122, //状态全量更新
NSyncStateAllUpdateBack = 123, //状态同步全量回调
NSyncTileInput = 131, //区块Tile同步输入
NSyncTileAllUpdate = 132, //区块全量更新
NSyncTileAllUpdateBack = 133, //区块同步全量回调
NSyncTileGetTileInfo = 134, //获取指定区块的全量信息
NAddTileServer = 141, //添加区块服务器
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 07d3dc0f03a24e18b4bee8832eef7a47
timeCreated: 1706264441

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 7d3cabfc01539db4dbf0d4961f07368c
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,50 @@
using System;
using Google.Protobuf;
namespace Plugins.JNGame.Network.Entity
{
public class JNetParam
{
//请求处理 Id (用来找到处理方法)
private int _hId;
public int HId => _hId;
//请求Id (请求标识)
private int _id;
public int ID => _id;
//请求参数
private IMessage _data;
public IMessage Data => _data;
private byte[] _bytes;
public byte[] Bytes => _bytes;
public JNetParam(int id,int hId)
{
_hId = hId;
_id = id;
_bytes = Array.Empty<byte>();
}
//构造器
public static JNetParam Build(int id,int hId){
return new JNetParam(id,hId);
}
public JNetParam SetData(IMessage data){
this._data = data;
return this;
}
public JNetParam SetByte(byte[] bytes){
this._bytes = bytes;
return this;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: f311c8c368584fab839dd72819fc55da
timeCreated: 1706004134

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 991b566ca2e345839d3047cb0a0870c9
timeCreated: 1723169977

View File

@@ -0,0 +1,76 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Cysharp.Threading.Tasks;
using Google.Protobuf;
using Plugins.JNGame.Network.Entity;
using Plugins.JNGame.Network.Util;
using Plugins.JNGame.System;
using Plugins.JNGame.Util;
namespace Plugins.JNGame.Network.Group
{
public class JNClientGroup<T> : SystemBase where T : JNClientBase
{
//创建通知
protected EventDispatcher _event = new();
//客户端组
public List<T> group = new List<T>();
public override async Task OnInit()
{
await UniTask.NextFrame();
}
public override void OnClose()
{
base.OnClose();
foreach (var client in group)
{
client.OnClose();
}
group.Clear();
}
public virtual void AddClient(T client)
{
group.Add(client);
client.SetEvent(_event);
client.OnInit();
}
public virtual void RemoveClient(T client)
{
client.SetEvent(new EventDispatcher());
client.OnClose();
group.Remove(client);
}
//外部监听消息
public void AddListener(int hId,Action<byte[]> listener)
{
_event.AddListener($"{hId}",listener);
}
//删除外部监听
public void RemoveListener(int hId,Action<byte[]> listener)
{
_event.RemoveListener($"{hId}",listener);
}
//向服务器发送消息
public void Send(int hId,IMessage data = null,Func<T,bool> filter = null)
{
filter ??= (T client) => true;
group.ForEach(child =>
{
if (filter(child))
{
child.Send(hId,data);
}
});
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 285c1ebc46554e9aa51b6831fc09a650
timeCreated: 1723170178

View File

@@ -0,0 +1,107 @@
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Threading.Tasks;
using AppGame;
using Cysharp.Threading.Tasks;
using DotRecast.Core.Collections;
using Google.Protobuf;
using Plugins.JNGame.Network.Entity;
using Plugins.JNGame.Network.Util;
using Plugins.JNGame.System;
using Plugins.JNGame.Util;
namespace Plugins.JNGame.Network
{
/// <summary>
/// 基础客户端网络类
/// </summary>
public abstract class JNClientBase : SystemBase
{
//消息Id
protected int _id = 0;
//创建通知
protected EventDispatcher _event = new();
//计入字节大小
protected Dictionary<int, int> _byteSize = new();
//回调消息
protected Dictionary<int, UniTaskCompletionSource<byte[]>> _callback = new ();
public void SetEvent(EventDispatcher dispatcher)
{
_event = dispatcher;
}
//外部监听消息
public void AddListener(int hId,Action<byte[]> listener)
{
_event.AddListener($"{hId}",listener);
}
//删除外部监听
public void RemoveListener(int hId,Action<byte[]> listener)
{
_event.RemoveListener($"{hId}",listener);
}
//通知消息
public virtual void Dispatch(JNetParam data)
{
_byteSize[data.HId] = data.Bytes.Length;
//判断是否是回调消息
if (data.HId <= 0)
{
//回调消息
_callback.TryGetValue(data.ID,out var task);
if (task is null) return;
task.TrySetResult(data.Bytes);
}
else
{
//通知消息
_event.Dispatch($"{data.HId}",data.Bytes);
}
}
//向服务器发送消息
public virtual void Send(int hId,IMessage data = null)
{
var bytes = NDataUtil.Encrypt(JNetParam.Build(this._id++, hId).SetData(data));
_byteSize[hId] = bytes.Length;
SendBytes(bytes);
}
//向服务器发送消息(有回调的消息)
public virtual async Task<byte[]> SendCallback(int hId,IMessage data = null,int timeout = 1000)
{
var id = this._id++;
_callback[id] = new UniTaskCompletionSource<byte[]>();
var bytes = NDataUtil.Encrypt(JNetParam.Build(id, hId).SetData(data));
SendBytes(bytes);
var message = await UniTask.WhenAny(_callback[id].Task, UniTask.Delay(timeout));
return message.result;
}
public virtual void SendBytes(byte[] data){ }
//获取字节大小
public int GetByteSize(int hId = 0)
{
if (hId == 0)
{
int size = 0;
_byteSize.ForEach(child =>
{
size += child.Value;
});
return size;
}
return _byteSize.GetValueOrDefault(hId, 0);
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 1fd9f54f293b4a56834c2eb1297eeb25
timeCreated: 1722411861

View File

@@ -0,0 +1,86 @@
using System;
using System.Collections.Generic;
using System.Net.Sockets;
using System.Reflection;
using DotRecast.Core.Collections;
using Google.Protobuf;
using Plugins.JNGame.Network.Entity;
using Plugins.JNGame.Network.Util;
using Plugins.JNGame.System;
using Plugins.JNGame.Util;
namespace Plugins.JNGame.Network
{
public class JNServerParam
{
public string Client;
public int MessageID;
public byte[] Message;
}
/// <summary>
/// 基础服务端网络类
/// </summary>
public abstract class JNServerBase : SystemBase
{
//消息Id
protected int _id = 0;
//创建通知
protected EventDispatcher _event = new();
//计入字节大小
protected Dictionary<int, int> _byteSize = new();
/// <summary>
/// 监听服务端事件
/// </summary>
/// <param name="hId"></param>
/// <param name="listener"></param>
public void AddListener(int hId,Action<JNServerParam> listener)
{
_event.AddListener($"{hId}",listener);
}
/// <summary>
/// 发送消息
/// </summary>
/// <param name="hId"></param>
/// <param name="data"></param>
public void Dispatch(int hId,JNServerParam data)
{
_event.Dispatch($"{hId}",data);
}
//获取字节大小
public int GetByteSize(int hId = 0)
{
if (hId == 0)
{
int size = 0;
try
{
_byteSize.ForEach(child =>
{
size += child.Value;
});
}
catch (Exception e)
{
// ignored
}
return size;
}
return _byteSize.GetValueOrDefault(hId, 0);
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 6e9eb4fd951a46468c406606ec2107bd
timeCreated: 1722413222

View File

@@ -0,0 +1,77 @@
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Threading.Tasks;
using BestHTTP.WebSocket;
using Cysharp.Threading.Tasks;
using DotRecast.Core.Collections;
using Google.Protobuf;
using Plugins.JNGame.Network.Entity;
using Plugins.JNGame.Network.Util;
using Plugins.JNGame.Util;
using TouchSocket.Core;
using TouchSocket.Http.WebSockets;
using TouchSocket.Sockets;
using UnityEngine;
namespace Plugins.JNGame.Network
{
public abstract class JNSocket : JNClientBase
{
private WebSocketClient client;
public override async Task OnInit()
{
await StartConnect();
}
public async Task StartConnect()
{
client = new WebSocketClient();
await client.SetupAsync(new TouchSocketConfig()
.SetRemoteIPHost(await this.GetUrl())
.ConfigurePlugins(a =>
{
a.UseReconnection(-1, true, 1000); //如需永远尝试连接tryCount设置为-1即可。
})
.ConfigureContainer(a =>
{
a.AddConsoleLogger();
}));
client.Received += OnReceived;
client.Connect();
Debug.Log($"[JNSocket]连接WebSocket成功");
}
public override void OnClose()
{
client?.Close();
client?.Dispose();
Debug.Log($"[JNTCPClient] 关闭对象");
base.OnClose();
}
private Task OnReceived(WebSocketClient webSocketClient, WSDataFrameEventArgs e)
{
if (e.DataFrame.Opcode == WSDataType.Binary && e.DataFrame.FIN)
{
Dispatch(NDataUtil.Parse(e.DataFrame.PayloadData));
}
return Task.CompletedTask;
}
protected abstract UniTask<string> GetUrl();
public override void SendBytes(byte[] data)
{
client.SendAsync(data);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 85daeb9010873c6408e58fd210d7ec47
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,124 @@
using System;
using System.Net;
using System.Threading.Tasks;
using Cysharp.Threading.Tasks;
using Plugins.JNGame.Network;
using Plugins.JNGame.Network.Action;
using Plugins.JNGame.Network.Entity;
using Plugins.JNGame.Network.Util;
using TouchSocket.Core;
using TouchSocket.Sockets;
using UnityEngine;
using NotImplementedException = System.NotImplementedException;
namespace JNGame.Network
{
public class JNTCPClient : JNClientBase
{
private TcpClient tcpClient;
public bool IsOpen => tcpClient is not null && tcpClient.Online;
public override async Task OnInit()
{
tcpClient = new TcpClient();
await tcpClient.SetupAsync(
new TouchSocketConfig()
.ConfigurePlugins(a =>
{
a.UseReconnection(-1, true, 1000); //如需永远尝试连接tryCount设置为-1即可。
})
.SetTcpDataHandlingAdapter(() => new FixedHeaderPackageAdapter())
);
tcpClient.Connecting = OnConnecting;
tcpClient.Connected = OnConnected;//成功连接到服务器
tcpClient.Disconnected = OnDisconnected;//从服务器断开连接,当连接不成功时不会触发。
tcpClient.Received = OnReceived;
await tcpClient.ConnectAsync(await GetEndPoint());
}
/// <summary>
///
/// </summary>
/// <param name="client"></param>
/// <param name="e"></param>
/// <returns></returns>
/// <exception cref="NotImplementedException"></exception>
private async Task OnConnecting(ITcpClient client, ConnectingEventArgs e)
{
Debug.Log($"[JNTCPClient] 开始连接服务器 {await GetEndPoint()}");
}
/// <summary>
/// 成功连接到服务器
/// </summary>
/// <param name="client"></param>
/// <param name="e"></param>
/// <returns></returns>
/// <exception cref="NotImplementedException"></exception>
private Task OnConnected(ITcpClient client, ConnectedEventArgs e)
{
Debug.Log($"[JNTCPClient] 服务器连接成功");
Dispatch(new JNetParam(_id++,(int)NActionEnum.LocalClientConnect));
return Task.CompletedTask;
}
/// <summary>
/// 从服务器断开连接,当连接不成功时不会触发。
/// </summary>
/// <param name="client"></param>
/// <param name="e"></param>
/// <returns></returns>
/// <exception cref="NotImplementedException"></exception>
private Task OnDisconnected(ITcpClientBase client, DisconnectEventArgs e)
{
Debug.Log($"[JNTCPClient] 服务器断开");
Dispatch(new JNetParam(_id++,(int)NActionEnum.LocalClientDisconnect));
return Task.CompletedTask;
}
/// <summary>
/// 接收到消息
/// </summary>
/// <param name="client"></param>
/// <param name="e"></param>
/// <returns></returns>
private Task OnReceived(TcpClient client, ReceivedDataEventArgs e)
{
byte[] data = new byte[e.ByteBlock.Len];
Array.Copy(e.ByteBlock.Buffer,data, data.Length);
var param = NDataUtil.Parse(data);
Dispatch(param);
return Task.CompletedTask;
}
public override void SendBytes(byte[] data)
{
if (IsOpen)
{
tcpClient.Send(data);
}
}
public override void OnClose()
{
tcpClient.Close();
tcpClient.Dispose();
Debug.Log($"[JNTCPClient] 关闭对象");
base.OnClose();
}
protected virtual async UniTask<string> GetEndPoint()
{
await UniTask.NextFrame();
return "127.0.0.1:9001";
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 1fd761856d3b4ea397624b0de69911e9
timeCreated: 1722409435

View File

@@ -0,0 +1,158 @@

using System;
using System.Net;
using System.Net.Sockets;
using System.Threading.Tasks;
using Cysharp.Threading.Tasks;
using DotRecast.Core.Collections;
using Google.Protobuf;
using Plugins.JNGame.Network;
using Plugins.JNGame.Network.Action;
using Plugins.JNGame.Network.Entity;
using Plugins.JNGame.Network.Util;
using TouchSocket.Core;
using TouchSocket.Sockets;
using UnityEngine;
namespace JNGame.Network
{
public class JNTCPServer : JNServerBase
{
private TcpService service;
private int _port;
public int Port => _port;
public override async Task OnInit()
{
service = new TcpService();
await service.SetupAsync(
new TouchSocketConfig()
.SetTcpDataHandlingAdapter(() => new FixedHeaderPackageAdapter())
);
service.Connecting = OnConnecting;//有客户端正在连接
service.Connected = OnConnected;//有客户端连接
service.Disconnected = OnDisconnected;//有客户端断开连接
service.Received = OnReceived;//客户端接收到消息
Debug.Log($"[JNTCPServer] 启动服务端中");
await service.StartAsync(_port = await GetPort());//启动
Debug.Log($"[JNTCPServer] 启动服务端成功");
}
/// <summary>
/// 有客户端正在连接
/// </summary>
/// <param name="client"></param>
/// <param name="e"></param>
private Task OnConnecting(SocketClient client, ConnectingEventArgs e)
{
Debug.Log($"[JNTCPServer] 有客户端正在连接");
return Task.CompletedTask;
}
/// <summary>
/// 有客户端连接
/// </summary>
/// <param name="client"></param>
/// <param name="e"></param>
/// <returns></returns>
/// <exception cref="NotImplementedException"></exception>
private Task OnConnected(SocketClient client, ConnectedEventArgs e)
{
Debug.Log($"[JNTCPServer] 有客户端连接成功");
Dispatch((int)NActionEnum.LocalClientConnect,new JNServerParam()
{
Client = client.Id
});
return Task.CompletedTask;
}
/// <summary>
/// 有客户端断开连接
/// </summary>
/// <param name="client"></param>
/// <param name="e"></param>
/// <returns></returns>
/// <exception cref="NotImplementedException"></exception>
private Task OnDisconnected(SocketClient client, DisconnectEventArgs e)
{
Debug.Log($"[JNTCPServer] 有客户端断开连接");
Dispatch((int)NActionEnum.LocalClientDisconnect,new JNServerParam()
{
Client = client.Id
});
return Task.CompletedTask;
}
/// <summary>
/// 客户端接收到消息
/// </summary>
/// <param name="client"></param>
/// <param name="e"></param>
/// <returns></returns>
/// <exception cref="NotImplementedException"></exception>
private async Task OnReceived(SocketClient client, ReceivedDataEventArgs e)
{
byte[] data = new byte[e.ByteBlock.Len];
Array.Copy(e.ByteBlock.Buffer,data, data.Length);
var param = NDataUtil.Parse(data);
Dispatch(param.HId,new JNServerParam()
{
Client = client.Id,
MessageID = param.ID,
Message = param.Bytes,
});
await UniTask.NextFrame();
}
public override void OnClose()
{
base.OnClose();
service.Stop();
}
protected virtual async UniTask<int> GetPort()
{
await UniTask.NextFrame();
return 9001;
}
public void Send(SocketClient client,int hId,IMessage data = null)
{
Send(client.Id,hId,data);
}
public void Send(string client,int hId,IMessage data = null)
{
var bytes = NDataUtil.Encrypt(JNetParam.Build(this._id++, hId).SetData(data));
_byteSize[hId] = bytes.Length;
service.SendAsync(client, bytes);
}
public void SendCallback(string client,int id,IMessage data = null)
{
var bytes = NDataUtil.Encrypt(JNetParam.Build(id, 0).SetData(data));
service.SendAsync(client, bytes);
}
public void AllSend(int hId,IMessage data = null,Func<SocketClient,bool> filter = null)
{
filter ??= (SocketClient client) => true;
service.GetClients().ForEach(client =>
{
if (filter(client))
{
Send(client, hId, data);
}
});
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 8ec8c583ae4a4a8686002cec976893b0
timeCreated: 1722409447

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 48ddea52cea7e1145b20a9674aeeca02
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 417922a615a577540b5a5f446a197bdc
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,84 @@
syntax = "proto3";
option java_package = "cn.jisol.ngame.proto";
// ---------------------- 状态 --------------------------
//连接客户端
message JNClientConnect{
string clientId = 1; //客户端Id
}
//断开客户端
message JNClientDisconnect{
string clientId = 1; //客户端Id
}
// ---------------------- 帧同步 --------------------------
//帧同步输入
message JNFrameInput{
int32 nId = 1; //输入的Id
optional bytes input = 2; //输入内容
int32 clientId = 3; //输入所属的客户端Id
}
//帧输入列表
message JNFrameInputs {
repeated JNFrameInput inputs = 1; //输入列表
}
//帧同步消息
message JNFrameInfo {
int32 index = 1; //帧数
repeated JNFrameInput messages = 2; //消息bytes
}
//帧同步集合
message JNFrameInfos{
repeated JNFrameInfo frames = 1; //帧数集
}
//帧同步输入
message JNInput {
optional string message = 1;
}
// ---------------------- 状态同步 --------------------------
// 状态数据
message JNStateData{
optional bytes data = 2; //数据
}
// 更新状态
message JNStateItemData{
int32 NetID = 1; //同步Id
map<uint64 ,JNStateData> messages = 2; //状态bytes
}
// 全量状态
message JNStateAllData{
repeated JNStateItemData data = 2; //数据
}
// --------------------- 状态Tile同步 -----------------------
// 状态Tile输入
message JNStateTileInputs{
int32 tId = 1; //区块Id
JNFrameInputs message = 2; //inputs
}
// Tile更新全量状态
message JNStateTileAllData{
int32 tId = 1; //区块Id
JNStateAllData data = 2;
}
// 获取指定区块的全量数据
message NSyncTileGetTileInfoRequest{
int32 tId = 1; //区块Id
}
//Tile服务器区块信息
message JNAddTileServer{
int32 tile = 1; //TileId
string ip = 2; //IP
int32 port = 3; //端口
bool master = 4; //是否是主服务器
}

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: f5033772dc466fc46a8ac64d8dbc5d00
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,445 @@
// <auto-generated>
// Generated by the protocol buffer compiler. DO NOT EDIT!
// source: NActionMessage.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;
/// <summary>Holder for reflection information generated from NActionMessage.proto</summary>
public static partial class NActionMessageReflection {
#region Descriptor
/// <summary>File descriptor for NActionMessage.proto</summary>
public static pbr::FileDescriptor Descriptor {
get { return descriptor; }
}
private static pbr::FileDescriptor descriptor;
static NActionMessageReflection() {
byte[] descriptorData = global::System.Convert.FromBase64String(
string.Concat(
"ChROQWN0aW9uTWVzc2FnZS5wcm90byIvCgtOQWN0aW9uRGVtbxIUCgdtZXNz",
"YWdlGAEgASgJSACIAQFCCgoIX21lc3NhZ2UiMAoMTkFjdGlvbkRlbW8yEhQK",
"B21lc3NhZ2UYASABKAlIAIgBAUIKCghfbWVzc2FnZUIWChRjbi5qaXNvbC5u",
"Z2FtZS5wcm90b2IGcHJvdG8z"));
descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData,
new pbr::FileDescriptor[] { },
new pbr::GeneratedClrTypeInfo(null, null, new pbr::GeneratedClrTypeInfo[] {
new pbr::GeneratedClrTypeInfo(typeof(global::NActionDemo), global::NActionDemo.Parser, new[]{ "Message" }, new[]{ "Message" }, null, null, null),
new pbr::GeneratedClrTypeInfo(typeof(global::NActionDemo2), global::NActionDemo2.Parser, new[]{ "Message" }, new[]{ "Message" }, null, null, null)
}));
}
#endregion
}
#region Messages
public sealed partial class NActionDemo : pb::IMessage<NActionDemo>
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
, pb::IBufferMessage
#endif
{
private static readonly pb::MessageParser<NActionDemo> _parser = new pb::MessageParser<NActionDemo>(() => new NActionDemo());
private pb::UnknownFieldSet _unknownFields;
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public static pb::MessageParser<NActionDemo> Parser { get { return _parser; } }
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public static pbr::MessageDescriptor Descriptor {
get { return global::NActionMessageReflection.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 NActionDemo() {
OnConstruction();
}
partial void OnConstruction();
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public NActionDemo(NActionDemo other) : this() {
message_ = other.message_;
_unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public NActionDemo Clone() {
return new NActionDemo(this);
}
/// <summary>Field number for the "message" field.</summary>
public const int MessageFieldNumber = 1;
private string message_;
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public string Message {
get { return message_ ?? ""; }
set {
message_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
}
}
/// <summary>Gets whether the "message" field is set</summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public bool HasMessage {
get { return message_ != null; }
}
/// <summary>Clears the value of the "message" field</summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public void ClearMessage() {
message_ = null;
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public override bool Equals(object other) {
return Equals(other as NActionDemo);
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public bool Equals(NActionDemo other) {
if (ReferenceEquals(other, null)) {
return false;
}
if (ReferenceEquals(other, this)) {
return true;
}
if (Message != other.Message) 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 (HasMessage) hash ^= Message.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 (HasMessage) {
output.WriteRawTag(10);
output.WriteString(Message);
}
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 (HasMessage) {
output.WriteRawTag(10);
output.WriteString(Message);
}
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 (HasMessage) {
size += 1 + pb::CodedOutputStream.ComputeStringSize(Message);
}
if (_unknownFields != null) {
size += _unknownFields.CalculateSize();
}
return size;
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public void MergeFrom(NActionDemo other) {
if (other == null) {
return;
}
if (other.HasMessage) {
Message = other.Message;
}
_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 10: {
Message = input.ReadString();
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 10: {
Message = input.ReadString();
break;
}
}
}
}
#endif
}
public sealed partial class NActionDemo2 : pb::IMessage<NActionDemo2>
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
, pb::IBufferMessage
#endif
{
private static readonly pb::MessageParser<NActionDemo2> _parser = new pb::MessageParser<NActionDemo2>(() => new NActionDemo2());
private pb::UnknownFieldSet _unknownFields;
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public static pb::MessageParser<NActionDemo2> Parser { get { return _parser; } }
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public static pbr::MessageDescriptor Descriptor {
get { return global::NActionMessageReflection.Descriptor.MessageTypes[1]; }
}
[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 NActionDemo2() {
OnConstruction();
}
partial void OnConstruction();
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public NActionDemo2(NActionDemo2 other) : this() {
message_ = other.message_;
_unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public NActionDemo2 Clone() {
return new NActionDemo2(this);
}
/// <summary>Field number for the "message" field.</summary>
public const int MessageFieldNumber = 1;
private string message_;
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public string Message {
get { return message_ ?? ""; }
set {
message_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
}
}
/// <summary>Gets whether the "message" field is set</summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public bool HasMessage {
get { return message_ != null; }
}
/// <summary>Clears the value of the "message" field</summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public void ClearMessage() {
message_ = null;
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public override bool Equals(object other) {
return Equals(other as NActionDemo2);
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public bool Equals(NActionDemo2 other) {
if (ReferenceEquals(other, null)) {
return false;
}
if (ReferenceEquals(other, this)) {
return true;
}
if (Message != other.Message) 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 (HasMessage) hash ^= Message.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 (HasMessage) {
output.WriteRawTag(10);
output.WriteString(Message);
}
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 (HasMessage) {
output.WriteRawTag(10);
output.WriteString(Message);
}
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 (HasMessage) {
size += 1 + pb::CodedOutputStream.ComputeStringSize(Message);
}
if (_unknownFields != null) {
size += _unknownFields.CalculateSize();
}
return size;
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
[global::System.CodeDom.Compiler.GeneratedCode("protoc", null)]
public void MergeFrom(NActionDemo2 other) {
if (other == null) {
return;
}
if (other.HasMessage) {
Message = other.Message;
}
_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 10: {
Message = input.ReadString();
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 10: {
Message = input.ReadString();
break;
}
}
}
}
#endif
}
#endregion
#endregion Designer generated code

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 7a64c8e0d9371ec4a8dc561dbfe81026
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,12 @@
syntax = "proto3";
option java_package = "cn.jisol.ngame.proto";
message NActionDemo {
optional string message = 1;
}
message NActionDemo2 {
optional string message = 1;
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: e48e0afd082b466081556cb81d66935f
timeCreated: 1705996154

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: f297d4999ae14dd7a046a1faebd6845a
timeCreated: 1706004786

View File

@@ -0,0 +1,45 @@
using System;
using System.Linq;
using System.Reflection;
using Google.Protobuf;
using Plugins.JNGame.Network.Entity;
using Plugins.JNGame.Util;
namespace Plugins.JNGame.Network.Util
{
// 网络数据工具类 [请求Id*4,处理Id*4,...参数数据*N]
public static class NDataUtil
{
// 解析
public static JNetParam Parse(byte[] data)
{
return JNetParam.Build(
ToUtil.Byte4ToInt(data.Skip(0).Take(4).ToArray()),
ToUtil.Byte4ToInt(data.Skip(4).Take(4).ToArray()))
.SetByte(data.Skip(8).Take(data.Length - 8).ToArray());
}
// 编码
public static byte[] Encrypt(JNetParam param)
{
byte[] id = ToUtil.IntToByte4(param.ID);
byte[] hId = ToUtil.IntToByte4(param.HId);
byte[] data = Array.Empty<byte>();
if(param.Data != null)
data = param.Data.ToByteArray();
byte[] datas = new byte[hId.Length+id.Length+data.Length];
Array.Copy(id, 0, datas, 0, id.Length);
Array.Copy(hId, 0, datas, id.Length, hId.Length);
Array.Copy(data, 0, datas, id.Length + hId.Length, data.Length);
return datas;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 8b05544adb2f44b4af8f86b2bc66a035
timeCreated: 1706004790