底层网络库 脱离protobuf 至此无任何依赖
This commit is contained in:
parent
52a24f979b
commit
f204fe1deb
49
NetLib/HaoYueNet.ClientNetwork/BaseData.cs
Normal file
49
NetLib/HaoYueNet.ClientNetwork/BaseData.cs
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace HaoYueNet.ClientNetwork
|
||||||
|
{
|
||||||
|
public static class BaseData
|
||||||
|
{
|
||||||
|
public static class HunterNet_S2C
|
||||||
|
{
|
||||||
|
public static byte[] CreatePkgData(UInt16 CmdID, UInt16 Error, byte[] data)
|
||||||
|
{
|
||||||
|
byte[] newdata = new byte[2 + 2 + data.Length];
|
||||||
|
BitConverter.GetBytes(CmdID).CopyTo(newdata, 0);
|
||||||
|
BitConverter.GetBytes(Error).CopyTo(newdata, 2);
|
||||||
|
Array.Copy(data, 0, newdata, 4, data.Length);
|
||||||
|
return newdata;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void AnalysisPkgData(byte[] srcdata,out UInt16 CmdID,out UInt16 Error,out byte[] data)
|
||||||
|
{
|
||||||
|
data = new byte[srcdata.Length - 2 - 2];
|
||||||
|
CmdID = BitConverter.ToUInt16(srcdata, 0);
|
||||||
|
Error = BitConverter.ToUInt16(srcdata, 2);
|
||||||
|
Array.Copy(srcdata, 4, data, 0, data.Length);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class HunterNet_C2S
|
||||||
|
{
|
||||||
|
public static byte[] CreatePkgData(UInt16 CmdID, byte[] data)
|
||||||
|
{
|
||||||
|
byte[] newdata = new byte[2 + data.Length];
|
||||||
|
BitConverter.GetBytes(CmdID).CopyTo(newdata, 0);
|
||||||
|
Array.Copy(data, 0, newdata, 2, data.Length);
|
||||||
|
return newdata;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void AnalysisPkgData(byte[] srcdata, out UInt16 CmdID, out byte[] data)
|
||||||
|
{
|
||||||
|
data = new byte[srcdata.Length - 2];
|
||||||
|
CmdID = BitConverter.ToUInt16(srcdata, 0);
|
||||||
|
Array.Copy(srcdata, 2, data, 0, data.Length);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -6,10 +6,4 @@
|
|||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<Reference Include="Google.Protobuf">
|
|
||||||
<HintPath>..\Google.Protobuf.dll</HintPath>
|
|
||||||
</Reference>
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
using Google.Protobuf;
|
//using HunterProtobufCore;
|
||||||
using HunterProtobufCore;
|
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Net.Sockets;
|
using System.Net.Sockets;
|
||||||
|
using static HaoYueNet.ClientNetwork.BaseData;
|
||||||
|
|
||||||
namespace HaoYueNet.ClientNetwork
|
namespace HaoYueNet.ClientNetwork
|
||||||
{
|
{
|
||||||
@ -168,10 +168,13 @@ namespace HaoYueNet.ClientNetwork
|
|||||||
public void SendToServer(int CMDID,byte[] data)
|
public void SendToServer(int CMDID,byte[] data)
|
||||||
{
|
{
|
||||||
//LogOut("准备数据 CMDID=> "+CMDID);
|
//LogOut("准备数据 CMDID=> "+CMDID);
|
||||||
|
/*
|
||||||
HunterNet_C2S _c2sdata = new HunterNet_C2S();
|
HunterNet_C2S _c2sdata = new HunterNet_C2S();
|
||||||
_c2sdata.HunterNetCoreCmdID = CMDID;
|
_c2sdata.HunterNetCoreCmdID = CMDID;
|
||||||
_c2sdata.HunterNetCoreData = ByteString.CopyFrom(data);
|
_c2sdata.HunterNetCoreData = ByteString.CopyFrom(data);
|
||||||
byte[] _finaldata = Serizlize(_c2sdata);
|
byte[] _finaldata = Serizlize(_c2sdata);
|
||||||
|
*/
|
||||||
|
byte[] _finaldata = HunterNet_C2S.CreatePkgData((ushort)CMDID, data);
|
||||||
SendToSocket(_finaldata);
|
SendToSocket(_finaldata);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -243,10 +246,15 @@ namespace HaoYueNet.ClientNetwork
|
|||||||
//LogOut("收到心跳包");
|
//LogOut("收到心跳包");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
HunterNet_S2C _c2s = DeSerizlize<HunterNet_S2C>(data);
|
HunterNet_S2C _c2s = DeSerizlize<HunterNet_S2C>(data);
|
||||||
|
|
||||||
OnReceiveData(_c2s.HunterNetCoreCmdID, _c2s.HunterNetCoreERRORCode, _c2s.HunterNetCoreData.ToArray());
|
OnReceiveData(_c2s.HunterNetCoreCmdID, _c2s.HunterNetCoreERRORCode, _c2s.HunterNetCoreData.ToArray());
|
||||||
|
*/
|
||||||
|
|
||||||
|
HunterNet_S2C.AnalysisPkgData(data, out ushort CmdID, out ushort Error, out byte[] resultdata);
|
||||||
|
OnReceiveData(CmdID, Error, resultdata);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -352,18 +360,6 @@ namespace HaoYueNet.ClientNetwork
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static byte[] Serizlize(IMessage msg)
|
|
||||||
{
|
|
||||||
return msg.ToByteArray();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static T DeSerizlize<T>(byte[] bytes)
|
|
||||||
{
|
|
||||||
var msgType = typeof(T);
|
|
||||||
object msg = Activator.CreateInstance(msgType);
|
|
||||||
((IMessage)msg).MergeFrom(bytes);
|
|
||||||
return (T)msg;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void LogOut(string Msg)
|
public void LogOut(string Msg)
|
||||||
{
|
{
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
using Google.Protobuf;
|
using System.Net;
|
||||||
using HunterProtobufCore;
|
|
||||||
using System.Net;
|
|
||||||
using System.Net.Sockets;
|
using System.Net.Sockets;
|
||||||
|
using static HaoYueNet.ClientNetwork.BaseData;
|
||||||
|
|
||||||
namespace HaoYueNet.ClientNetwork
|
namespace HaoYueNet.ClientNetwork
|
||||||
{
|
{
|
||||||
@ -165,11 +164,13 @@ namespace HaoYueNet.ClientNetwork
|
|||||||
public void SendToSocket(int CMDID, int ERRCODE, byte[] data)
|
public void SendToSocket(int CMDID, int ERRCODE, byte[] data)
|
||||||
{
|
{
|
||||||
//LogOut("准备数据 CMDID=> "+CMDID);
|
//LogOut("准备数据 CMDID=> "+CMDID);
|
||||||
HunterNet_S2C _s2sdata = new HunterNet_S2C();
|
/*HunterNet_S2C _s2sdata = new HunterNet_S2C();
|
||||||
_s2sdata.HunterNetCoreCmdID = CMDID;
|
_s2sdata.HunterNetCoreCmdID = CMDID;
|
||||||
_s2sdata.HunterNetCoreERRORCode = ERRCODE;
|
_s2sdata.HunterNetCoreERRORCode = ERRCODE;
|
||||||
_s2sdata.HunterNetCoreData = ByteString.CopyFrom(data);
|
_s2sdata.HunterNetCoreData = ByteString.CopyFrom(data);
|
||||||
byte[] _finaldata = Serizlize(_s2sdata);
|
byte[] _finaldata = Serizlize(_s2sdata);*/
|
||||||
|
|
||||||
|
byte[] _finaldata = HunterNet_S2C.CreatePkgData((ushort)CMDID, (ushort)ERRCODE, data);
|
||||||
SendToSocket(_finaldata);
|
SendToSocket(_finaldata);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -245,10 +246,13 @@ namespace HaoYueNet.ClientNetwork
|
|||||||
//LogOut("收到心跳包");
|
//LogOut("收到心跳包");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
HunterNet_S2C _c2s = DeSerizlize<HunterNet_S2C>(data);
|
HunterNet_S2C _c2s = DeSerizlize<HunterNet_S2C>(data);
|
||||||
|
|
||||||
OnDataCallBack(_c2s.HunterNetCoreCmdID, _c2s.HunterNetCoreERRORCode, _c2s.HunterNetCoreData.ToArray());
|
OnDataCallBack(_c2s.HunterNetCoreCmdID, _c2s.HunterNetCoreERRORCode, _c2s.HunterNetCoreData.ToArray());
|
||||||
|
*/
|
||||||
|
HunterNet_S2C.AnalysisPkgData(data, out ushort CmdID, out ushort Error, out byte[] resultdata);
|
||||||
|
OnDataCallBack(CmdID, Error, resultdata);
|
||||||
}
|
}
|
||||||
|
|
||||||
MemoryStream memoryStream = new MemoryStream();//开辟一个内存流
|
MemoryStream memoryStream = new MemoryStream();//开辟一个内存流
|
||||||
@ -354,19 +358,6 @@ namespace HaoYueNet.ClientNetwork
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static byte[] Serizlize(IMessage msg)
|
|
||||||
{
|
|
||||||
return msg.ToByteArray();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static T DeSerizlize<T>(byte[] bytes)
|
|
||||||
{
|
|
||||||
var msgType = typeof(T);
|
|
||||||
object msg = Activator.CreateInstance(msgType);
|
|
||||||
((IMessage)msg).MergeFrom(bytes);
|
|
||||||
return (T)msg;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void LogOut(string Msg)
|
public void LogOut(string Msg)
|
||||||
{
|
{
|
||||||
//Console.WriteLine(Msg);
|
//Console.WriteLine(Msg);
|
||||||
|
@ -1,505 +0,0 @@
|
|||||||
// <auto-generated>
|
|
||||||
// Generated by the protocol buffer compiler. DO NOT EDIT!
|
|
||||||
// source: protobuf_HunterNetCore.proto
|
|
||||||
// </auto-generated>
|
|
||||||
#pragma warning disable 1591, 0612, 3021
|
|
||||||
#region Designer generated code
|
|
||||||
|
|
||||||
using pb = global::Google.Protobuf;
|
|
||||||
using pbr = global::Google.Protobuf.Reflection;
|
|
||||||
namespace HunterProtobufCore
|
|
||||||
{
|
|
||||||
|
|
||||||
/// <summary>Holder for reflection information generated from protobuf_HunterNetCore.proto</summary>
|
|
||||||
public static partial class ProtobufHunterNetCoreReflection {
|
|
||||||
|
|
||||||
#region Descriptor
|
|
||||||
/// <summary>File descriptor for protobuf_HunterNetCore.proto</summary>
|
|
||||||
public static pbr::FileDescriptor Descriptor {
|
|
||||||
get { return descriptor; }
|
|
||||||
}
|
|
||||||
private static pbr::FileDescriptor descriptor;
|
|
||||||
|
|
||||||
static ProtobufHunterNetCoreReflection() {
|
|
||||||
byte[] descriptorData = global::System.Convert.FromBase64String(
|
|
||||||
string.Concat(
|
|
||||||
"Chxwcm90b2J1Zl9IdW50ZXJOZXRDb3JlLnByb3RvEhJIdW50ZXJQcm90b2J1",
|
|
||||||
"ZkNvcmUiSAoNSHVudGVyTmV0X0MyUxIbChNIdW50ZXJOZXRDb3JlX0NtZElE",
|
|
||||||
"GAEgASgFEhoKEkh1bnRlck5ldENvcmVfRGF0YRgCIAEoDCJpCg1IdW50ZXJO",
|
|
||||||
"ZXRfUzJDEhsKE0h1bnRlck5ldENvcmVfQ21kSUQYASABKAUSHwoXSHVudGVy",
|
|
||||||
"TmV0Q29yZV9FUlJPUkNvZGUYAiABKAUSGgoSSHVudGVyTmV0Q29yZV9EYXRh",
|
|
||||||
"GAMgASgMQgJIAWIGcHJvdG8z"));
|
|
||||||
descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData,
|
|
||||||
new pbr::FileDescriptor[] { },
|
|
||||||
new pbr::GeneratedClrTypeInfo(null, null, new pbr::GeneratedClrTypeInfo[] {
|
|
||||||
new pbr::GeneratedClrTypeInfo(typeof(global::HunterProtobufCore.HunterNet_C2S), global::HunterProtobufCore.HunterNet_C2S.Parser, new[]{ "HunterNetCoreCmdID", "HunterNetCoreData" }, null, null, null, null),
|
|
||||||
new pbr::GeneratedClrTypeInfo(typeof(global::HunterProtobufCore.HunterNet_S2C), global::HunterProtobufCore.HunterNet_S2C.Parser, new[]{ "HunterNetCoreCmdID", "HunterNetCoreERRORCode", "HunterNetCoreData" }, null, null, null, null)
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
}
|
|
||||||
#region Messages
|
|
||||||
/// <summary>
|
|
||||||
///上行
|
|
||||||
/// </summary>
|
|
||||||
public sealed partial class HunterNet_C2S : pb::IMessage<HunterNet_C2S>
|
|
||||||
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
|
|
||||||
, pb::IBufferMessage
|
|
||||||
#endif
|
|
||||||
{
|
|
||||||
private static readonly pb::MessageParser<HunterNet_C2S> _parser = new pb::MessageParser<HunterNet_C2S>(() => new HunterNet_C2S());
|
|
||||||
private pb::UnknownFieldSet _unknownFields;
|
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
|
||||||
public static pb::MessageParser<HunterNet_C2S> Parser { get { return _parser; } }
|
|
||||||
|
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
|
||||||
public static pbr::MessageDescriptor Descriptor {
|
|
||||||
get { return global::HunterProtobufCore.ProtobufHunterNetCoreReflection.Descriptor.MessageTypes[0]; }
|
|
||||||
}
|
|
||||||
|
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
|
||||||
pbr::MessageDescriptor pb::IMessage.Descriptor {
|
|
||||||
get { return Descriptor; }
|
|
||||||
}
|
|
||||||
|
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
|
||||||
public HunterNet_C2S() {
|
|
||||||
OnConstruction();
|
|
||||||
}
|
|
||||||
|
|
||||||
partial void OnConstruction();
|
|
||||||
|
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
|
||||||
public HunterNet_C2S(HunterNet_C2S other) : this() {
|
|
||||||
hunterNetCoreCmdID_ = other.hunterNetCoreCmdID_;
|
|
||||||
hunterNetCoreData_ = other.hunterNetCoreData_;
|
|
||||||
_unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
|
|
||||||
}
|
|
||||||
|
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
|
||||||
public HunterNet_C2S Clone() {
|
|
||||||
return new HunterNet_C2S(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>Field number for the "HunterNetCore_CmdID" field.</summary>
|
|
||||||
public const int HunterNetCoreCmdIDFieldNumber = 1;
|
|
||||||
private int hunterNetCoreCmdID_;
|
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
|
||||||
public int HunterNetCoreCmdID {
|
|
||||||
get { return hunterNetCoreCmdID_; }
|
|
||||||
set {
|
|
||||||
hunterNetCoreCmdID_ = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>Field number for the "HunterNetCore_Data" field.</summary>
|
|
||||||
public const int HunterNetCoreDataFieldNumber = 2;
|
|
||||||
private pb::ByteString hunterNetCoreData_ = pb::ByteString.Empty;
|
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
|
||||||
public pb::ByteString HunterNetCoreData {
|
|
||||||
get { return hunterNetCoreData_; }
|
|
||||||
set {
|
|
||||||
hunterNetCoreData_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
|
||||||
public override bool Equals(object other) {
|
|
||||||
return Equals(other as HunterNet_C2S);
|
|
||||||
}
|
|
||||||
|
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
|
||||||
public bool Equals(HunterNet_C2S other) {
|
|
||||||
if (ReferenceEquals(other, null)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (ReferenceEquals(other, this)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (HunterNetCoreCmdID != other.HunterNetCoreCmdID) return false;
|
|
||||||
if (HunterNetCoreData != other.HunterNetCoreData) return false;
|
|
||||||
return Equals(_unknownFields, other._unknownFields);
|
|
||||||
}
|
|
||||||
|
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
|
||||||
public override int GetHashCode() {
|
|
||||||
int hash = 1;
|
|
||||||
if (HunterNetCoreCmdID != 0) hash ^= HunterNetCoreCmdID.GetHashCode();
|
|
||||||
if (HunterNetCoreData.Length != 0) hash ^= HunterNetCoreData.GetHashCode();
|
|
||||||
if (_unknownFields != null) {
|
|
||||||
hash ^= _unknownFields.GetHashCode();
|
|
||||||
}
|
|
||||||
return hash;
|
|
||||||
}
|
|
||||||
|
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
|
||||||
public override string ToString() {
|
|
||||||
return pb::JsonFormatter.ToDiagnosticString(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
|
||||||
public void WriteTo(pb::CodedOutputStream output) {
|
|
||||||
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
|
|
||||||
output.WriteRawMessage(this);
|
|
||||||
#else
|
|
||||||
if (HunterNetCoreCmdID != 0) {
|
|
||||||
output.WriteRawTag(8);
|
|
||||||
output.WriteInt32(HunterNetCoreCmdID);
|
|
||||||
}
|
|
||||||
if (HunterNetCoreData.Length != 0) {
|
|
||||||
output.WriteRawTag(18);
|
|
||||||
output.WriteBytes(HunterNetCoreData);
|
|
||||||
}
|
|
||||||
if (_unknownFields != null) {
|
|
||||||
_unknownFields.WriteTo(output);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
|
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
|
||||||
void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
|
|
||||||
if (HunterNetCoreCmdID != 0) {
|
|
||||||
output.WriteRawTag(8);
|
|
||||||
output.WriteInt32(HunterNetCoreCmdID);
|
|
||||||
}
|
|
||||||
if (HunterNetCoreData.Length != 0) {
|
|
||||||
output.WriteRawTag(18);
|
|
||||||
output.WriteBytes(HunterNetCoreData);
|
|
||||||
}
|
|
||||||
if (_unknownFields != null) {
|
|
||||||
_unknownFields.WriteTo(ref output);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
|
||||||
public int CalculateSize() {
|
|
||||||
int size = 0;
|
|
||||||
if (HunterNetCoreCmdID != 0) {
|
|
||||||
size += 1 + pb::CodedOutputStream.ComputeInt32Size(HunterNetCoreCmdID);
|
|
||||||
}
|
|
||||||
if (HunterNetCoreData.Length != 0) {
|
|
||||||
size += 1 + pb::CodedOutputStream.ComputeBytesSize(HunterNetCoreData);
|
|
||||||
}
|
|
||||||
if (_unknownFields != null) {
|
|
||||||
size += _unknownFields.CalculateSize();
|
|
||||||
}
|
|
||||||
return size;
|
|
||||||
}
|
|
||||||
|
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
|
||||||
public void MergeFrom(HunterNet_C2S other) {
|
|
||||||
if (other == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (other.HunterNetCoreCmdID != 0) {
|
|
||||||
HunterNetCoreCmdID = other.HunterNetCoreCmdID;
|
|
||||||
}
|
|
||||||
if (other.HunterNetCoreData.Length != 0) {
|
|
||||||
HunterNetCoreData = other.HunterNetCoreData;
|
|
||||||
}
|
|
||||||
_unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
|
|
||||||
}
|
|
||||||
|
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
|
||||||
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: {
|
|
||||||
HunterNetCoreCmdID = input.ReadInt32();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 18: {
|
|
||||||
HunterNetCoreData = input.ReadBytes();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
|
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
|
||||||
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: {
|
|
||||||
HunterNetCoreCmdID = input.ReadInt32();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 18: {
|
|
||||||
HunterNetCoreData = input.ReadBytes();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
///下行
|
|
||||||
/// </summary>
|
|
||||||
public sealed partial class HunterNet_S2C : pb::IMessage<HunterNet_S2C>
|
|
||||||
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
|
|
||||||
, pb::IBufferMessage
|
|
||||||
#endif
|
|
||||||
{
|
|
||||||
private static readonly pb::MessageParser<HunterNet_S2C> _parser = new pb::MessageParser<HunterNet_S2C>(() => new HunterNet_S2C());
|
|
||||||
private pb::UnknownFieldSet _unknownFields;
|
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
|
||||||
public static pb::MessageParser<HunterNet_S2C> Parser { get { return _parser; } }
|
|
||||||
|
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
|
||||||
public static pbr::MessageDescriptor Descriptor {
|
|
||||||
get { return global::HunterProtobufCore.ProtobufHunterNetCoreReflection.Descriptor.MessageTypes[1]; }
|
|
||||||
}
|
|
||||||
|
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
|
||||||
pbr::MessageDescriptor pb::IMessage.Descriptor {
|
|
||||||
get { return Descriptor; }
|
|
||||||
}
|
|
||||||
|
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
|
||||||
public HunterNet_S2C() {
|
|
||||||
OnConstruction();
|
|
||||||
}
|
|
||||||
|
|
||||||
partial void OnConstruction();
|
|
||||||
|
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
|
||||||
public HunterNet_S2C(HunterNet_S2C other) : this() {
|
|
||||||
hunterNetCoreCmdID_ = other.hunterNetCoreCmdID_;
|
|
||||||
hunterNetCoreERRORCode_ = other.hunterNetCoreERRORCode_;
|
|
||||||
hunterNetCoreData_ = other.hunterNetCoreData_;
|
|
||||||
_unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
|
|
||||||
}
|
|
||||||
|
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
|
||||||
public HunterNet_S2C Clone() {
|
|
||||||
return new HunterNet_S2C(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>Field number for the "HunterNetCore_CmdID" field.</summary>
|
|
||||||
public const int HunterNetCoreCmdIDFieldNumber = 1;
|
|
||||||
private int hunterNetCoreCmdID_;
|
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
|
||||||
public int HunterNetCoreCmdID {
|
|
||||||
get { return hunterNetCoreCmdID_; }
|
|
||||||
set {
|
|
||||||
hunterNetCoreCmdID_ = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>Field number for the "HunterNetCore_ERRORCode" field.</summary>
|
|
||||||
public const int HunterNetCoreERRORCodeFieldNumber = 2;
|
|
||||||
private int hunterNetCoreERRORCode_;
|
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
|
||||||
public int HunterNetCoreERRORCode {
|
|
||||||
get { return hunterNetCoreERRORCode_; }
|
|
||||||
set {
|
|
||||||
hunterNetCoreERRORCode_ = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>Field number for the "HunterNetCore_Data" field.</summary>
|
|
||||||
public const int HunterNetCoreDataFieldNumber = 3;
|
|
||||||
private pb::ByteString hunterNetCoreData_ = pb::ByteString.Empty;
|
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
|
||||||
public pb::ByteString HunterNetCoreData {
|
|
||||||
get { return hunterNetCoreData_; }
|
|
||||||
set {
|
|
||||||
hunterNetCoreData_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
|
||||||
public override bool Equals(object other) {
|
|
||||||
return Equals(other as HunterNet_S2C);
|
|
||||||
}
|
|
||||||
|
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
|
||||||
public bool Equals(HunterNet_S2C other) {
|
|
||||||
if (ReferenceEquals(other, null)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (ReferenceEquals(other, this)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (HunterNetCoreCmdID != other.HunterNetCoreCmdID) return false;
|
|
||||||
if (HunterNetCoreERRORCode != other.HunterNetCoreERRORCode) return false;
|
|
||||||
if (HunterNetCoreData != other.HunterNetCoreData) return false;
|
|
||||||
return Equals(_unknownFields, other._unknownFields);
|
|
||||||
}
|
|
||||||
|
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
|
||||||
public override int GetHashCode() {
|
|
||||||
int hash = 1;
|
|
||||||
if (HunterNetCoreCmdID != 0) hash ^= HunterNetCoreCmdID.GetHashCode();
|
|
||||||
if (HunterNetCoreERRORCode != 0) hash ^= HunterNetCoreERRORCode.GetHashCode();
|
|
||||||
if (HunterNetCoreData.Length != 0) hash ^= HunterNetCoreData.GetHashCode();
|
|
||||||
if (_unknownFields != null) {
|
|
||||||
hash ^= _unknownFields.GetHashCode();
|
|
||||||
}
|
|
||||||
return hash;
|
|
||||||
}
|
|
||||||
|
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
|
||||||
public override string ToString() {
|
|
||||||
return pb::JsonFormatter.ToDiagnosticString(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
|
||||||
public void WriteTo(pb::CodedOutputStream output) {
|
|
||||||
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
|
|
||||||
output.WriteRawMessage(this);
|
|
||||||
#else
|
|
||||||
if (HunterNetCoreCmdID != 0) {
|
|
||||||
output.WriteRawTag(8);
|
|
||||||
output.WriteInt32(HunterNetCoreCmdID);
|
|
||||||
}
|
|
||||||
if (HunterNetCoreERRORCode != 0) {
|
|
||||||
output.WriteRawTag(16);
|
|
||||||
output.WriteInt32(HunterNetCoreERRORCode);
|
|
||||||
}
|
|
||||||
if (HunterNetCoreData.Length != 0) {
|
|
||||||
output.WriteRawTag(26);
|
|
||||||
output.WriteBytes(HunterNetCoreData);
|
|
||||||
}
|
|
||||||
if (_unknownFields != null) {
|
|
||||||
_unknownFields.WriteTo(output);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
|
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
|
||||||
void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
|
|
||||||
if (HunterNetCoreCmdID != 0) {
|
|
||||||
output.WriteRawTag(8);
|
|
||||||
output.WriteInt32(HunterNetCoreCmdID);
|
|
||||||
}
|
|
||||||
if (HunterNetCoreERRORCode != 0) {
|
|
||||||
output.WriteRawTag(16);
|
|
||||||
output.WriteInt32(HunterNetCoreERRORCode);
|
|
||||||
}
|
|
||||||
if (HunterNetCoreData.Length != 0) {
|
|
||||||
output.WriteRawTag(26);
|
|
||||||
output.WriteBytes(HunterNetCoreData);
|
|
||||||
}
|
|
||||||
if (_unknownFields != null) {
|
|
||||||
_unknownFields.WriteTo(ref output);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
|
||||||
public int CalculateSize() {
|
|
||||||
int size = 0;
|
|
||||||
if (HunterNetCoreCmdID != 0) {
|
|
||||||
size += 1 + pb::CodedOutputStream.ComputeInt32Size(HunterNetCoreCmdID);
|
|
||||||
}
|
|
||||||
if (HunterNetCoreERRORCode != 0) {
|
|
||||||
size += 1 + pb::CodedOutputStream.ComputeInt32Size(HunterNetCoreERRORCode);
|
|
||||||
}
|
|
||||||
if (HunterNetCoreData.Length != 0) {
|
|
||||||
size += 1 + pb::CodedOutputStream.ComputeBytesSize(HunterNetCoreData);
|
|
||||||
}
|
|
||||||
if (_unknownFields != null) {
|
|
||||||
size += _unknownFields.CalculateSize();
|
|
||||||
}
|
|
||||||
return size;
|
|
||||||
}
|
|
||||||
|
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
|
||||||
public void MergeFrom(HunterNet_S2C other) {
|
|
||||||
if (other == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (other.HunterNetCoreCmdID != 0) {
|
|
||||||
HunterNetCoreCmdID = other.HunterNetCoreCmdID;
|
|
||||||
}
|
|
||||||
if (other.HunterNetCoreERRORCode != 0) {
|
|
||||||
HunterNetCoreERRORCode = other.HunterNetCoreERRORCode;
|
|
||||||
}
|
|
||||||
if (other.HunterNetCoreData.Length != 0) {
|
|
||||||
HunterNetCoreData = other.HunterNetCoreData;
|
|
||||||
}
|
|
||||||
_unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
|
|
||||||
}
|
|
||||||
|
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
|
||||||
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: {
|
|
||||||
HunterNetCoreCmdID = input.ReadInt32();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 16: {
|
|
||||||
HunterNetCoreERRORCode = input.ReadInt32();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 26: {
|
|
||||||
HunterNetCoreData = input.ReadBytes();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
|
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
|
||||||
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: {
|
|
||||||
HunterNetCoreCmdID = input.ReadInt32();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 16: {
|
|
||||||
HunterNetCoreERRORCode = input.ReadInt32();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 26: {
|
|
||||||
HunterNetCoreData = input.ReadBytes();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion Designer generated code
|
|
49
NetLib/HaoYueNet.ClientNetworkNet4x/BaseData.cs
Normal file
49
NetLib/HaoYueNet.ClientNetworkNet4x/BaseData.cs
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace HaoYueNet.ClientNetworkNet4x
|
||||||
|
{
|
||||||
|
public static class BaseData
|
||||||
|
{
|
||||||
|
public static class HunterNet_S2C
|
||||||
|
{
|
||||||
|
public static byte[] CreatePkgData(UInt16 CmdID, UInt16 Error, byte[] data)
|
||||||
|
{
|
||||||
|
byte[] newdata = new byte[2 + 2 + data.Length];
|
||||||
|
BitConverter.GetBytes(CmdID).CopyTo(newdata, 0);
|
||||||
|
BitConverter.GetBytes(Error).CopyTo(newdata, 2);
|
||||||
|
Array.Copy(data, 0, newdata, 4, data.Length);
|
||||||
|
return newdata;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void AnalysisPkgData(byte[] srcdata,out UInt16 CmdID,out UInt16 Error,out byte[] data)
|
||||||
|
{
|
||||||
|
data = new byte[srcdata.Length - 2 - 2];
|
||||||
|
CmdID = BitConverter.ToUInt16(srcdata, 0);
|
||||||
|
Error = BitConverter.ToUInt16(srcdata, 2);
|
||||||
|
Array.Copy(srcdata, 4, data, 0, data.Length);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class HunterNet_C2S
|
||||||
|
{
|
||||||
|
public static byte[] CreatePkgData(UInt16 CmdID, byte[] data)
|
||||||
|
{
|
||||||
|
byte[] newdata = new byte[2 + data.Length];
|
||||||
|
BitConverter.GetBytes(CmdID).CopyTo(newdata, 0);
|
||||||
|
Array.Copy(data, 0, newdata, 2, data.Length);
|
||||||
|
return newdata;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void AnalysisPkgData(byte[] srcdata, out UInt16 CmdID, out byte[] data)
|
||||||
|
{
|
||||||
|
data = new byte[srcdata.Length - 2];
|
||||||
|
CmdID = BitConverter.ToUInt16(srcdata, 0);
|
||||||
|
Array.Copy(srcdata, 2, data, 0, data.Length);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -32,40 +32,18 @@
|
|||||||
<WarningLevel>4</WarningLevel>
|
<WarningLevel>4</WarningLevel>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Reference Include="Google.Protobuf">
|
|
||||||
<HintPath>..\Google.Protobuf.dll</HintPath>
|
|
||||||
</Reference>
|
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
<Reference Include="System.Buffers, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
|
||||||
<HintPath>..\..\packages\System.Buffers.4.5.1\lib\net461\System.Buffers.dll</HintPath>
|
|
||||||
</Reference>
|
|
||||||
<Reference Include="System.Core" />
|
|
||||||
<Reference Include="System.Memory, Version=4.0.1.2, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
|
||||||
<HintPath>..\..\packages\System.Memory.4.5.5\lib\net461\System.Memory.dll</HintPath>
|
|
||||||
</Reference>
|
|
||||||
<Reference Include="System.Numerics" />
|
|
||||||
<Reference Include="System.Numerics.Vectors, Version=4.1.4.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
|
||||||
<HintPath>..\..\packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll</HintPath>
|
|
||||||
</Reference>
|
|
||||||
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
|
||||||
<HintPath>..\..\packages\System.Runtime.CompilerServices.Unsafe.4.5.3\lib\net461\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
|
|
||||||
</Reference>
|
|
||||||
<Reference Include="System.Xml.Linq" />
|
|
||||||
<Reference Include="System.Data.DataSetExtensions" />
|
|
||||||
<Reference Include="Microsoft.CSharp" />
|
<Reference Include="Microsoft.CSharp" />
|
||||||
<Reference Include="System.Data" />
|
<Reference Include="System.Data" />
|
||||||
<Reference Include="System.Net.Http" />
|
|
||||||
<Reference Include="System.Xml" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Compile Include="BaseData.cs" />
|
||||||
<Compile Include="NetworkHelperCore.cs" />
|
<Compile Include="NetworkHelperCore.cs" />
|
||||||
<Compile Include="NetworkHelperP2PCore.cs" />
|
<Compile Include="NetworkHelperP2PCore.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Compile Include="ProtobufHunterNetCore.cs" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="app.config" />
|
<None Include="app.config" />
|
||||||
<None Include="packages.config" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
</Project>
|
</Project>
|
@ -1,11 +1,9 @@
|
|||||||
using Google.Protobuf;
|
using System;
|
||||||
using HunterProtobufCore;
|
|
||||||
using System;
|
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Net.Sockets;
|
using System.Net.Sockets;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
using static HaoYueNet.ClientNetworkNet4x.BaseData;
|
||||||
|
|
||||||
namespace HaoYueNet.ClientNetworkNet4x
|
namespace HaoYueNet.ClientNetworkNet4x
|
||||||
{
|
{
|
||||||
@ -40,9 +38,11 @@ namespace HaoYueNet.ClientNetworkNet4x
|
|||||||
|
|
||||||
private System.Timers.Timer _heartTimer;
|
private System.Timers.Timer _heartTimer;
|
||||||
|
|
||||||
public void Init(string IP, int port, bool bBindReuseAddress = false, int bBindport = 0)
|
public static string LastConnectIP;
|
||||||
{
|
public static int LastConnectPort;
|
||||||
|
|
||||||
|
public bool Init(string IP, int port, bool bBindReuseAddress = false, int bBindport = 0)
|
||||||
|
{
|
||||||
LogOut("==>初始化网络核心");
|
LogOut("==>初始化网络核心");
|
||||||
|
|
||||||
RevIndex = MaxRevIndexNum;
|
RevIndex = MaxRevIndexNum;
|
||||||
@ -55,10 +55,12 @@ namespace HaoYueNet.ClientNetworkNet4x
|
|||||||
IPEndPoint ipe = new IPEndPoint(IPAddress.Any, Convert.ToInt32(bBindport));
|
IPEndPoint ipe = new IPEndPoint(IPAddress.Any, Convert.ToInt32(bBindport));
|
||||||
client.Bind(ipe);
|
client.Bind(ipe);
|
||||||
}
|
}
|
||||||
Connect(IP, port);
|
LastConnectIP = IP;
|
||||||
|
LastConnectPort = port;
|
||||||
|
return Connect(IP, port);
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Connect(string IP, int port)
|
bool Connect(string IP, int port)
|
||||||
{
|
{
|
||||||
//带回调的
|
//带回调的
|
||||||
try
|
try
|
||||||
@ -168,10 +170,13 @@ namespace HaoYueNet.ClientNetworkNet4x
|
|||||||
public void SendToServer(int CMDID, byte[] data)
|
public void SendToServer(int CMDID, byte[] data)
|
||||||
{
|
{
|
||||||
//LogOut("准备数据 CMDID=> "+CMDID);
|
//LogOut("准备数据 CMDID=> "+CMDID);
|
||||||
|
/*
|
||||||
HunterNet_C2S _c2sdata = new HunterNet_C2S();
|
HunterNet_C2S _c2sdata = new HunterNet_C2S();
|
||||||
_c2sdata.HunterNetCoreCmdID = CMDID;
|
_c2sdata.HunterNetCoreCmdID = CMDID;
|
||||||
_c2sdata.HunterNetCoreData = ByteString.CopyFrom(data);
|
_c2sdata.HunterNetCoreData = ByteString.CopyFrom(data);
|
||||||
byte[] _finaldata = Serizlize(_c2sdata);
|
byte[] _finaldata = Serizlize(_c2sdata);
|
||||||
|
*/
|
||||||
|
byte[] _finaldata = HunterNet_C2S.CreatePkgData((ushort)CMDID, data);
|
||||||
SendToSocket(_finaldata);
|
SendToSocket(_finaldata);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -244,9 +249,14 @@ namespace HaoYueNet.ClientNetworkNet4x
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
HunterNet_S2C _c2s = DeSerizlize<HunterNet_S2C>(data);
|
HunterNet_S2C _c2s = DeSerizlize<HunterNet_S2C>(data);
|
||||||
|
|
||||||
OnReceiveData(_c2s.HunterNetCoreCmdID, _c2s.HunterNetCoreERRORCode, _c2s.HunterNetCoreData.ToArray());
|
OnReceiveData(_c2s.HunterNetCoreCmdID, _c2s.HunterNetCoreERRORCode, _c2s.HunterNetCoreData.ToArray());
|
||||||
|
*/
|
||||||
|
|
||||||
|
HunterNet_S2C.AnalysisPkgData(data, out ushort CmdID, out ushort Error, out byte[] resultdata);
|
||||||
|
OnReceiveData(CmdID, Error, resultdata);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -352,18 +362,6 @@ namespace HaoYueNet.ClientNetworkNet4x
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static byte[] Serizlize(IMessage msg)
|
|
||||||
{
|
|
||||||
return msg.ToByteArray();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static T DeSerizlize<T>(byte[] bytes)
|
|
||||||
{
|
|
||||||
var msgType = typeof(T);
|
|
||||||
object msg = Activator.CreateInstance(msgType);
|
|
||||||
((IMessage)msg).MergeFrom(bytes);
|
|
||||||
return (T)msg;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void LogOut(string Msg)
|
public void LogOut(string Msg)
|
||||||
{
|
{
|
||||||
|
@ -1,385 +1,378 @@
|
|||||||
using Google.Protobuf;
|
using System;
|
||||||
using HunterProtobufCore;
|
|
||||||
using System;
|
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Net.Sockets;
|
using System.Net.Sockets;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
using static HaoYueNet.ClientNetworkNet4x.BaseData;
|
||||||
|
|
||||||
namespace HaoYueNet.ClientNetworkNet4x
|
namespace HaoYueNet.ClientNetworkNet4x
|
||||||
{
|
{
|
||||||
public class NetworkHelperP2PCore
|
namespace HaoYueNet.ClientNetwork
|
||||||
{
|
{
|
||||||
private Socket client;
|
public class NetworkHelperP2PCore
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 心跳包数据
|
|
||||||
/// </summary>
|
|
||||||
private byte[] HeartbeatData = new byte[5] { 0x05, 0x00, 0x00, 0x00, 0x00 };
|
|
||||||
|
|
||||||
////响应倒计时计数最大值
|
|
||||||
//private static int MaxRevIndexNum = 6;
|
|
||||||
|
|
||||||
////发送倒计时计数最大值
|
|
||||||
//private static int MaxSendIndexNum = 3;
|
|
||||||
|
|
||||||
//响应倒计时计数最大值
|
|
||||||
private static int MaxRevIndexNum = 50;
|
|
||||||
|
|
||||||
//发送倒计时计数最大值
|
|
||||||
private static int MaxSendIndexNum = 3;
|
|
||||||
|
|
||||||
//响应倒计时计数
|
|
||||||
private static int RevIndex = 0;
|
|
||||||
//发送倒计时计数
|
|
||||||
private static int SendIndex = 0;
|
|
||||||
|
|
||||||
//计时器间隔
|
|
||||||
private static int TimerInterval = 3000;
|
|
||||||
|
|
||||||
private System.Timers.Timer _heartTimer;
|
|
||||||
|
|
||||||
public void Init(string IP, int port, bool bBindReuseAddress = false, int bBindport = 0)
|
|
||||||
{
|
{
|
||||||
|
private Socket client;
|
||||||
|
|
||||||
LogOut("==>初始化网络核心");
|
/// <summary>
|
||||||
|
/// 心跳包数据
|
||||||
|
/// </summary>
|
||||||
|
private byte[] HeartbeatData = new byte[5] { 0x05, 0x00, 0x00, 0x00, 0x00 };
|
||||||
|
|
||||||
RevIndex = MaxRevIndexNum;
|
////响应倒计时计数最大值
|
||||||
SendIndex = MaxSendIndexNum;
|
//private static int MaxRevIndexNum = 6;
|
||||||
|
|
||||||
client = new Socket(SocketType.Stream, ProtocolType.Tcp);
|
////发送倒计时计数最大值
|
||||||
if (bBindReuseAddress)
|
//private static int MaxSendIndexNum = 3;
|
||||||
|
|
||||||
|
//响应倒计时计数最大值
|
||||||
|
private static int MaxRevIndexNum = 50;
|
||||||
|
|
||||||
|
//发送倒计时计数最大值
|
||||||
|
private static int MaxSendIndexNum = 3;
|
||||||
|
|
||||||
|
//响应倒计时计数
|
||||||
|
private static int RevIndex = 0;
|
||||||
|
//发送倒计时计数
|
||||||
|
private static int SendIndex = 0;
|
||||||
|
|
||||||
|
//计时器间隔
|
||||||
|
private static int TimerInterval = 3000;
|
||||||
|
|
||||||
|
private System.Timers.Timer _heartTimer;
|
||||||
|
|
||||||
|
public void Init(string IP, int port, bool bBindReuseAddress = false, int bBindport = 0)
|
||||||
{
|
{
|
||||||
client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
|
|
||||||
IPEndPoint ipe = new IPEndPoint(IPAddress.Any, Convert.ToInt32(bBindport));
|
|
||||||
client.Bind(ipe);
|
|
||||||
}
|
|
||||||
Connect(IP, port);
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool Connect(string IP, int port)
|
LogOut("==>初始化网络核心");
|
||||||
{
|
|
||||||
//带回调的
|
|
||||||
try
|
|
||||||
{
|
|
||||||
LogOut("连接到远程IP " + IP + ":" + port);
|
|
||||||
client.Connect(IP, port);
|
|
||||||
Thread thread = new Thread(Recive);
|
|
||||||
thread.IsBackground = true;
|
|
||||||
thread.Start(client);
|
|
||||||
int localport = ((IPEndPoint)client.LocalEndPoint).Port;
|
|
||||||
LogOut($"连接成功!连接到远程IP->{IP}:{port} | 本地端口->{localport}");
|
|
||||||
|
|
||||||
if (_heartTimer == null)
|
RevIndex = MaxRevIndexNum;
|
||||||
|
SendIndex = MaxSendIndexNum;
|
||||||
|
|
||||||
|
client = new Socket(SocketType.Stream, ProtocolType.Tcp);
|
||||||
|
if (bBindReuseAddress)
|
||||||
{
|
{
|
||||||
_heartTimer = new System.Timers.Timer();
|
client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
|
||||||
|
IPEndPoint ipe = new IPEndPoint(IPAddress.Any, Convert.ToInt32(bBindport));
|
||||||
|
client.Bind(ipe);
|
||||||
}
|
}
|
||||||
_heartTimer.Interval = TimerInterval;
|
Connect(IP, port);
|
||||||
_heartTimer.Elapsed += CheckUpdatetimer_Elapsed;
|
|
||||||
_heartTimer.AutoReset = true;
|
|
||||||
_heartTimer.Enabled = true;
|
|
||||||
LogOut("开启心跳包检测");
|
|
||||||
|
|
||||||
OnConnected(true);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
LogOut("连接失败:" + ex.ToString());
|
|
||||||
OnConnected(false);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
~NetworkHelperP2PCore()
|
|
||||||
{
|
|
||||||
client.Close();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void SendToSocket(byte[] data)
|
|
||||||
{
|
|
||||||
data = SendDataWithHead(data);
|
|
||||||
try
|
|
||||||
{
|
|
||||||
SendWithIndex(data);
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
//连接断开
|
|
||||||
OnCloseReady();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
//LogOut("发送消息,消息长度=> "+data.Length);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void SendHeartbeat()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
SendWithIndex(HeartbeatData);
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
//连接断开
|
|
||||||
OnCloseReady();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
//LogOut("发送心跳包");
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 发送数据并计数
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="data"></param>
|
|
||||||
private void SendWithIndex(byte[] data)
|
|
||||||
{
|
|
||||||
//增加发送计数
|
|
||||||
SendIndex = MaxSendIndexNum;
|
|
||||||
//发送数据
|
|
||||||
client.Send(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
//拼接头长度
|
|
||||||
private byte[] SendDataWithHead(byte[] message)
|
|
||||||
{
|
|
||||||
|
|
||||||
MemoryStream memoryStream = new MemoryStream();//创建一个内存流
|
|
||||||
|
|
||||||
byte[] BagHead = BitConverter.GetBytes(message.Length + 4);//往字节数组中写入包头(包头自身的长度和消息体的长度)的长度
|
|
||||||
|
|
||||||
memoryStream.Write(BagHead, 0, BagHead.Length);//将包头写入内存流
|
|
||||||
|
|
||||||
memoryStream.Write(message, 0, message.Length);//将消息体写入内存流
|
|
||||||
|
|
||||||
byte[] HeadAndBody = memoryStream.ToArray();//将内存流中的数据写入字节数组
|
|
||||||
|
|
||||||
memoryStream.Close();//关闭内存
|
|
||||||
memoryStream.Dispose();//释放资源
|
|
||||||
|
|
||||||
return HeadAndBody;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 供外部调用 发送消息
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="CMDID"></param>
|
|
||||||
/// <param name="ERRCODE"></param>
|
|
||||||
/// <param name="data"></param>
|
|
||||||
public void SendToSocket(int CMDID, int ERRCODE, byte[] data)
|
|
||||||
{
|
|
||||||
//LogOut("准备数据 CMDID=> "+CMDID);
|
|
||||||
HunterNet_S2C _s2sdata = new HunterNet_S2C();
|
|
||||||
_s2sdata.HunterNetCoreCmdID = CMDID;
|
|
||||||
_s2sdata.HunterNetCoreERRORCode = ERRCODE;
|
|
||||||
_s2sdata.HunterNetCoreData = ByteString.CopyFrom(data);
|
|
||||||
byte[] _finaldata = Serizlize(_s2sdata);
|
|
||||||
SendToSocket(_finaldata);
|
|
||||||
}
|
|
||||||
|
|
||||||
public delegate void OnDataCallBack_Data(int CMDID, int ERRCODE, byte[] data);
|
|
||||||
|
|
||||||
public event OnDataCallBack_Data OnDataCallBack;
|
|
||||||
|
|
||||||
public delegate void delegate_NoData();
|
|
||||||
|
|
||||||
public delegate void delegate_Bool(bool IsConnected);
|
|
||||||
|
|
||||||
public event delegate_NoData OnClose;
|
|
||||||
|
|
||||||
public event delegate_Bool OnConnected;
|
|
||||||
|
|
||||||
public delegate void delegate_str(string Msg);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 网络库调试日志输出
|
|
||||||
/// </summary>
|
|
||||||
public event delegate_str OnLogOut;
|
|
||||||
|
|
||||||
///// <summary>
|
|
||||||
///// 用于调用者回调的虚函数
|
|
||||||
///// </summary>
|
|
||||||
///// <param name="data"></param>
|
|
||||||
//public virtual void DataCallBack(int CMDID,int ERRCODE,byte[] data)
|
|
||||||
//{
|
|
||||||
|
|
||||||
//}
|
|
||||||
|
|
||||||
///// <summary>
|
|
||||||
///// 断开连接
|
|
||||||
///// </summary>
|
|
||||||
///// <param name="sk"></param>
|
|
||||||
//public virtual void OnClose()
|
|
||||||
//{
|
|
||||||
|
|
||||||
//}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 做好处理的连接管理
|
|
||||||
/// </summary>
|
|
||||||
private void OnCloseReady()
|
|
||||||
{
|
|
||||||
LogOut("关闭心跳包计数");
|
|
||||||
_heartTimer.Enabled = false;
|
|
||||||
_heartTimer.Elapsed -= CheckUpdatetimer_Elapsed;
|
|
||||||
LogOut("关闭连接");
|
|
||||||
//关闭Socket连接
|
|
||||||
client.Close();
|
|
||||||
OnClose();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 主动关闭连接
|
|
||||||
/// </summary>
|
|
||||||
public void CloseConntect()
|
|
||||||
{
|
|
||||||
OnCloseReady();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void DataCallBackReady(byte[] data)
|
|
||||||
{
|
|
||||||
|
|
||||||
//增加接收计数
|
|
||||||
RevIndex = MaxRevIndexNum;
|
|
||||||
|
|
||||||
//不处理心跳包
|
|
||||||
if (data.Length == 1 && data[0] == 0x00)
|
|
||||||
{
|
|
||||||
//LogOut("收到心跳包");
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
HunterNet_S2C _c2s = DeSerizlize<HunterNet_S2C>(data);
|
public bool Connect(string IP, int port)
|
||||||
|
|
||||||
OnDataCallBack(_c2s.HunterNetCoreCmdID, _c2s.HunterNetCoreERRORCode, _c2s.HunterNetCoreData.ToArray());
|
|
||||||
}
|
|
||||||
|
|
||||||
MemoryStream memoryStream = new MemoryStream();//开辟一个内存流
|
|
||||||
private void Recive(object o)
|
|
||||||
{
|
|
||||||
var client = o as Socket;
|
|
||||||
//MemoryStream memoryStream = new MemoryStream();//开辟一个内存流
|
|
||||||
|
|
||||||
while (true)
|
|
||||||
{
|
{
|
||||||
byte[] buffer = new byte[1024 * 1024 * 2];
|
//带回调的
|
||||||
int effective = 0;
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
effective = client.Receive(buffer);
|
LogOut("连接到远程IP " + IP + ":" + port);
|
||||||
if (effective == 0)
|
client.Connect(IP, port);
|
||||||
|
Thread thread = new Thread(Recive);
|
||||||
|
thread.IsBackground = true;
|
||||||
|
thread.Start(client);
|
||||||
|
int localport = ((IPEndPoint)client.LocalEndPoint).Port;
|
||||||
|
LogOut($"连接成功!连接到远程IP->{IP}:{port} | 本地端口->{localport}");
|
||||||
|
|
||||||
|
if (_heartTimer == null)
|
||||||
{
|
{
|
||||||
continue;
|
_heartTimer = new System.Timers.Timer();
|
||||||
}
|
}
|
||||||
|
_heartTimer.Interval = TimerInterval;
|
||||||
|
_heartTimer.Elapsed += CheckUpdatetimer_Elapsed;
|
||||||
|
_heartTimer.AutoReset = true;
|
||||||
|
_heartTimer.Enabled = true;
|
||||||
|
LogOut("开启心跳包检测");
|
||||||
|
|
||||||
|
OnConnected(true);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
//远程主机强迫关闭了一个现有的连接
|
LogOut("连接失败:" + ex.ToString());
|
||||||
|
OnConnected(false);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
~NetworkHelperP2PCore()
|
||||||
|
{
|
||||||
|
client.Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SendToSocket(byte[] data)
|
||||||
|
{
|
||||||
|
data = SendDataWithHead(data);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
SendWithIndex(data);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
//连接断开
|
||||||
OnCloseReady();
|
OnCloseReady();
|
||||||
return;
|
return;
|
||||||
//断开连接
|
}
|
||||||
|
//LogOut("发送消息,消息长度=> "+data.Length);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SendHeartbeat()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
SendWithIndex(HeartbeatData);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
//连接断开
|
||||||
|
OnCloseReady();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
//LogOut("发送心跳包");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 发送数据并计数
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="data"></param>
|
||||||
|
private void SendWithIndex(byte[] data)
|
||||||
|
{
|
||||||
|
//增加发送计数
|
||||||
|
SendIndex = MaxSendIndexNum;
|
||||||
|
//发送数据
|
||||||
|
client.Send(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
//拼接头长度
|
||||||
|
private byte[] SendDataWithHead(byte[] message)
|
||||||
|
{
|
||||||
|
|
||||||
|
MemoryStream memoryStream = new MemoryStream();//创建一个内存流
|
||||||
|
|
||||||
|
byte[] BagHead = BitConverter.GetBytes(message.Length + 4);//往字节数组中写入包头(包头自身的长度和消息体的长度)的长度
|
||||||
|
|
||||||
|
memoryStream.Write(BagHead, 0, BagHead.Length);//将包头写入内存流
|
||||||
|
|
||||||
|
memoryStream.Write(message, 0, message.Length);//将消息体写入内存流
|
||||||
|
|
||||||
|
byte[] HeadAndBody = memoryStream.ToArray();//将内存流中的数据写入字节数组
|
||||||
|
|
||||||
|
memoryStream.Close();//关闭内存
|
||||||
|
memoryStream.Dispose();//释放资源
|
||||||
|
|
||||||
|
return HeadAndBody;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 供外部调用 发送消息
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="CMDID"></param>
|
||||||
|
/// <param name="ERRCODE"></param>
|
||||||
|
/// <param name="data"></param>
|
||||||
|
public void SendToSocket(int CMDID, int ERRCODE, byte[] data)
|
||||||
|
{
|
||||||
|
//LogOut("准备数据 CMDID=> "+CMDID);
|
||||||
|
/*HunterNet_S2C _s2sdata = new HunterNet_S2C();
|
||||||
|
_s2sdata.HunterNetCoreCmdID = CMDID;
|
||||||
|
_s2sdata.HunterNetCoreERRORCode = ERRCODE;
|
||||||
|
_s2sdata.HunterNetCoreData = ByteString.CopyFrom(data);
|
||||||
|
byte[] _finaldata = Serizlize(_s2sdata);*/
|
||||||
|
|
||||||
|
byte[] _finaldata = HunterNet_S2C.CreatePkgData((ushort)CMDID, (ushort)ERRCODE, data);
|
||||||
|
SendToSocket(_finaldata);
|
||||||
|
}
|
||||||
|
|
||||||
|
public delegate void OnDataCallBack_Data(int CMDID, int ERRCODE, byte[] data);
|
||||||
|
|
||||||
|
public event OnDataCallBack_Data OnDataCallBack;
|
||||||
|
|
||||||
|
public delegate void delegate_NoData();
|
||||||
|
|
||||||
|
public delegate void delegate_Bool(bool IsConnected);
|
||||||
|
|
||||||
|
public event delegate_NoData OnClose;
|
||||||
|
|
||||||
|
public event delegate_Bool OnConnected;
|
||||||
|
|
||||||
|
public delegate void delegate_str(string Msg);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 网络库调试日志输出
|
||||||
|
/// </summary>
|
||||||
|
public event delegate_str OnLogOut;
|
||||||
|
|
||||||
|
///// <summary>
|
||||||
|
///// 用于调用者回调的虚函数
|
||||||
|
///// </summary>
|
||||||
|
///// <param name="data"></param>
|
||||||
|
//public virtual void DataCallBack(int CMDID,int ERRCODE,byte[] data)
|
||||||
|
//{
|
||||||
|
|
||||||
|
//}
|
||||||
|
|
||||||
|
///// <summary>
|
||||||
|
///// 断开连接
|
||||||
|
///// </summary>
|
||||||
|
///// <param name="sk"></param>
|
||||||
|
//public virtual void OnClose()
|
||||||
|
//{
|
||||||
|
|
||||||
|
//}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 做好处理的连接管理
|
||||||
|
/// </summary>
|
||||||
|
private void OnCloseReady()
|
||||||
|
{
|
||||||
|
LogOut("关闭心跳包计数");
|
||||||
|
_heartTimer.Enabled = false;
|
||||||
|
_heartTimer.Elapsed -= CheckUpdatetimer_Elapsed;
|
||||||
|
LogOut("关闭连接");
|
||||||
|
//关闭Socket连接
|
||||||
|
client.Close();
|
||||||
|
OnClose();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 主动关闭连接
|
||||||
|
/// </summary>
|
||||||
|
public void CloseConntect()
|
||||||
|
{
|
||||||
|
OnCloseReady();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DataCallBackReady(byte[] data)
|
||||||
|
{
|
||||||
|
|
||||||
|
//增加接收计数
|
||||||
|
RevIndex = MaxRevIndexNum;
|
||||||
|
|
||||||
|
//不处理心跳包
|
||||||
|
if (data.Length == 1 && data[0] == 0x00)
|
||||||
|
{
|
||||||
|
//LogOut("收到心跳包");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
HunterNet_S2C _c2s = DeSerizlize<HunterNet_S2C>(data);
|
||||||
|
OnDataCallBack(_c2s.HunterNetCoreCmdID, _c2s.HunterNetCoreERRORCode, _c2s.HunterNetCoreData.ToArray());
|
||||||
|
*/
|
||||||
|
HunterNet_S2C.AnalysisPkgData(data, out ushort CmdID, out ushort Error, out byte[] resultdata);
|
||||||
|
OnDataCallBack(CmdID, Error, resultdata);
|
||||||
|
}
|
||||||
|
|
||||||
memoryStream.Write(buffer, 0, effective);//将接受到的数据写入内存流中
|
MemoryStream memoryStream = new MemoryStream();//开辟一个内存流
|
||||||
byte[] getData = memoryStream.ToArray();//将内存流中的消息体写入字节数组
|
private void Recive(object o)
|
||||||
int StartIndex = 0;//设置一个读取数据的起始下标
|
{
|
||||||
|
var client = o as Socket;
|
||||||
|
//MemoryStream memoryStream = new MemoryStream();//开辟一个内存流
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
|
byte[] buffer = new byte[1024 * 1024 * 2];
|
||||||
|
int effective = 0;
|
||||||
if (effective > 0)//如果接受到的消息不为0(不为空)
|
try
|
||||||
{
|
{
|
||||||
int HeadLength = 0;//包头长度(包头+包体)
|
effective = client.Receive(buffer);
|
||||||
if (getData.Length - StartIndex < 4)//包头接受不完整
|
if (effective == 0)
|
||||||
{
|
{
|
||||||
HeadLength = -1;
|
continue;
|
||||||
}
|
}
|
||||||
else
|
}
|
||||||
{
|
catch (Exception ex)
|
||||||
//如果包头接受完整 转换成int类型的数值
|
{
|
||||||
HeadLength = BitConverter.ToInt32(getData, StartIndex);
|
//远程主机强迫关闭了一个现有的连接
|
||||||
}
|
OnCloseReady();
|
||||||
//包头接受完整但是消息体不完整 //包头接受不完整
|
return;
|
||||||
//↓↓↓↓↓↓↓↓ ↓↓↓
|
//断开连接
|
||||||
if (getData.Length - StartIndex < HeadLength || HeadLength == -1)
|
}
|
||||||
{
|
|
||||||
/* 一种清空流的方式
|
|
||||||
memoryStream.Close();//关闭内存流
|
|
||||||
memoryStream.Dispose();//释放内存资源
|
|
||||||
memoryStream = new MemoryStream();//创建新的内存流
|
|
||||||
*/
|
|
||||||
|
|
||||||
//流复用的方式 不用重新new申请
|
|
||||||
memoryStream.Position = 0;
|
|
||||||
memoryStream.SetLength(0);
|
|
||||||
|
|
||||||
memoryStream.Write(getData, StartIndex, getData.Length - StartIndex);//从新将接受的消息写入内存流
|
memoryStream.Write(buffer, 0, effective);//将接受到的数据写入内存流中
|
||||||
break;
|
byte[] getData = memoryStream.ToArray();//将内存流中的消息体写入字节数组
|
||||||
}
|
int StartIndex = 0;//设置一个读取数据的起始下标
|
||||||
else
|
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
if (effective > 0)//如果接受到的消息不为0(不为空)
|
||||||
{
|
{
|
||||||
//把头去掉,就可以吃了,蛋白质是牛肉的六倍
|
int HeadLength = 0;//包头长度(包头+包体)
|
||||||
//DataCallBackReady(getData.Skip(StartIndex+4).Take(HeadLength-4).ToArray());
|
if (getData.Length - StartIndex < 4)//包头接受不完整
|
||||||
|
{
|
||||||
|
HeadLength = -1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//如果包头接受完整 转换成int类型的数值
|
||||||
|
HeadLength = BitConverter.ToInt32(getData, StartIndex);
|
||||||
|
}
|
||||||
|
//包头接受完整但是消息体不完整 //包头接受不完整
|
||||||
|
//↓↓↓↓↓↓↓↓ ↓↓↓
|
||||||
|
if (getData.Length - StartIndex < HeadLength || HeadLength == -1)
|
||||||
|
{
|
||||||
|
/* 一种清空流的方式
|
||||||
|
memoryStream.Close();//关闭内存流
|
||||||
|
memoryStream.Dispose();//释放内存资源
|
||||||
|
memoryStream = new MemoryStream();//创建新的内存流
|
||||||
|
*/
|
||||||
|
|
||||||
//改为Array.Copy 提升效率
|
//流复用的方式 不用重新new申请
|
||||||
int CoreLenght = HeadLength - 4;
|
memoryStream.Position = 0;
|
||||||
byte[] retData = new byte[CoreLenght];
|
memoryStream.SetLength(0);
|
||||||
Array.Copy(getData, StartIndex + 4, retData, 0, CoreLenght);
|
|
||||||
DataCallBackReady(retData);
|
memoryStream.Write(getData, StartIndex, getData.Length - StartIndex);//从新将接受的消息写入内存流
|
||||||
StartIndex += HeadLength;//当读取一条完整的数据后,读取数据的起始下标应为当前接受到的消息体的长度(当前数据的尾部或下一条消息的首部)
|
break;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//把头去掉,就可以吃了,蛋白质是牛肉的六倍
|
||||||
|
//DataCallBackReady(getData.Skip(StartIndex+4).Take(HeadLength-4).ToArray());
|
||||||
|
|
||||||
|
//改为Array.Copy 提升效率
|
||||||
|
int CoreLenght = HeadLength - 4;
|
||||||
|
byte[] retData = new byte[CoreLenght];
|
||||||
|
Array.Copy(getData, StartIndex + 4, retData, 0, CoreLenght);
|
||||||
|
DataCallBackReady(retData);
|
||||||
|
StartIndex += HeadLength;//当读取一条完整的数据后,读取数据的起始下标应为当前接受到的消息体的长度(当前数据的尾部或下一条消息的首部)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private void CheckUpdatetimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
|
private void CheckUpdatetimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
|
||||||
{
|
|
||||||
//接收服务器数据计数
|
|
||||||
RevIndex--;
|
|
||||||
if (RevIndex <= 0)
|
|
||||||
{
|
{
|
||||||
//判定掉线
|
//接收服务器数据计数
|
||||||
OnCloseReady();
|
RevIndex--;
|
||||||
return;
|
if (RevIndex <= 0)
|
||||||
|
{
|
||||||
|
//判定掉线
|
||||||
|
OnCloseReady();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//发送计数
|
||||||
|
SendIndex--;
|
||||||
|
if (SendIndex <= 0)//需要发送心跳包了
|
||||||
|
{
|
||||||
|
//重置倒计时计数
|
||||||
|
SendIndex = MaxSendIndexNum;
|
||||||
|
|
||||||
|
SendHeartbeat();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//发送计数
|
public void LogOut(string Msg)
|
||||||
SendIndex--;
|
|
||||||
if (SendIndex <= 0)//需要发送心跳包了
|
|
||||||
{
|
{
|
||||||
//重置倒计时计数
|
//Console.WriteLine(Msg);
|
||||||
SendIndex = MaxSendIndexNum;
|
OnLogOut(Msg);
|
||||||
|
|
||||||
SendHeartbeat();
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public static byte[] Serizlize(IMessage msg)
|
public Socket GetClientSocket()
|
||||||
{
|
{
|
||||||
return msg.ToByteArray();
|
return client;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static T DeSerizlize<T>(byte[] bytes)
|
|
||||||
{
|
|
||||||
var msgType = typeof(T);
|
|
||||||
object msg = Activator.CreateInstance(msgType);
|
|
||||||
((IMessage)msg).MergeFrom(bytes);
|
|
||||||
return (T)msg;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void LogOut(string Msg)
|
|
||||||
{
|
|
||||||
//Console.WriteLine(Msg);
|
|
||||||
OnLogOut(Msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Socket GetClientSocket()
|
|
||||||
{
|
|
||||||
return client;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,505 +0,0 @@
|
|||||||
// <auto-generated>
|
|
||||||
// Generated by the protocol buffer compiler. DO NOT EDIT!
|
|
||||||
// source: protobuf_HunterNetCore.proto
|
|
||||||
// </auto-generated>
|
|
||||||
#pragma warning disable 1591, 0612, 3021
|
|
||||||
#region Designer generated code
|
|
||||||
|
|
||||||
using pb = global::Google.Protobuf;
|
|
||||||
using pbr = global::Google.Protobuf.Reflection;
|
|
||||||
namespace HunterProtobufCore
|
|
||||||
{
|
|
||||||
|
|
||||||
/// <summary>Holder for reflection information generated from protobuf_HunterNetCore.proto</summary>
|
|
||||||
public static partial class ProtobufHunterNetCoreReflection {
|
|
||||||
|
|
||||||
#region Descriptor
|
|
||||||
/// <summary>File descriptor for protobuf_HunterNetCore.proto</summary>
|
|
||||||
public static pbr::FileDescriptor Descriptor {
|
|
||||||
get { return descriptor; }
|
|
||||||
}
|
|
||||||
private static pbr::FileDescriptor descriptor;
|
|
||||||
|
|
||||||
static ProtobufHunterNetCoreReflection() {
|
|
||||||
byte[] descriptorData = global::System.Convert.FromBase64String(
|
|
||||||
string.Concat(
|
|
||||||
"Chxwcm90b2J1Zl9IdW50ZXJOZXRDb3JlLnByb3RvEhJIdW50ZXJQcm90b2J1",
|
|
||||||
"ZkNvcmUiSAoNSHVudGVyTmV0X0MyUxIbChNIdW50ZXJOZXRDb3JlX0NtZElE",
|
|
||||||
"GAEgASgFEhoKEkh1bnRlck5ldENvcmVfRGF0YRgCIAEoDCJpCg1IdW50ZXJO",
|
|
||||||
"ZXRfUzJDEhsKE0h1bnRlck5ldENvcmVfQ21kSUQYASABKAUSHwoXSHVudGVy",
|
|
||||||
"TmV0Q29yZV9FUlJPUkNvZGUYAiABKAUSGgoSSHVudGVyTmV0Q29yZV9EYXRh",
|
|
||||||
"GAMgASgMQgJIAWIGcHJvdG8z"));
|
|
||||||
descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData,
|
|
||||||
new pbr::FileDescriptor[] { },
|
|
||||||
new pbr::GeneratedClrTypeInfo(null, null, new pbr::GeneratedClrTypeInfo[] {
|
|
||||||
new pbr::GeneratedClrTypeInfo(typeof(global::HunterProtobufCore.HunterNet_C2S), global::HunterProtobufCore.HunterNet_C2S.Parser, new[]{ "HunterNetCoreCmdID", "HunterNetCoreData" }, null, null, null, null),
|
|
||||||
new pbr::GeneratedClrTypeInfo(typeof(global::HunterProtobufCore.HunterNet_S2C), global::HunterProtobufCore.HunterNet_S2C.Parser, new[]{ "HunterNetCoreCmdID", "HunterNetCoreERRORCode", "HunterNetCoreData" }, null, null, null, null)
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
}
|
|
||||||
#region Messages
|
|
||||||
/// <summary>
|
|
||||||
///上行
|
|
||||||
/// </summary>
|
|
||||||
public sealed partial class HunterNet_C2S : pb::IMessage<HunterNet_C2S>
|
|
||||||
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
|
|
||||||
, pb::IBufferMessage
|
|
||||||
#endif
|
|
||||||
{
|
|
||||||
private static readonly pb::MessageParser<HunterNet_C2S> _parser = new pb::MessageParser<HunterNet_C2S>(() => new HunterNet_C2S());
|
|
||||||
private pb::UnknownFieldSet _unknownFields;
|
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
|
||||||
public static pb::MessageParser<HunterNet_C2S> Parser { get { return _parser; } }
|
|
||||||
|
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
|
||||||
public static pbr::MessageDescriptor Descriptor {
|
|
||||||
get { return global::HunterProtobufCore.ProtobufHunterNetCoreReflection.Descriptor.MessageTypes[0]; }
|
|
||||||
}
|
|
||||||
|
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
|
||||||
pbr::MessageDescriptor pb::IMessage.Descriptor {
|
|
||||||
get { return Descriptor; }
|
|
||||||
}
|
|
||||||
|
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
|
||||||
public HunterNet_C2S() {
|
|
||||||
OnConstruction();
|
|
||||||
}
|
|
||||||
|
|
||||||
partial void OnConstruction();
|
|
||||||
|
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
|
||||||
public HunterNet_C2S(HunterNet_C2S other) : this() {
|
|
||||||
hunterNetCoreCmdID_ = other.hunterNetCoreCmdID_;
|
|
||||||
hunterNetCoreData_ = other.hunterNetCoreData_;
|
|
||||||
_unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
|
|
||||||
}
|
|
||||||
|
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
|
||||||
public HunterNet_C2S Clone() {
|
|
||||||
return new HunterNet_C2S(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>Field number for the "HunterNetCore_CmdID" field.</summary>
|
|
||||||
public const int HunterNetCoreCmdIDFieldNumber = 1;
|
|
||||||
private int hunterNetCoreCmdID_;
|
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
|
||||||
public int HunterNetCoreCmdID {
|
|
||||||
get { return hunterNetCoreCmdID_; }
|
|
||||||
set {
|
|
||||||
hunterNetCoreCmdID_ = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>Field number for the "HunterNetCore_Data" field.</summary>
|
|
||||||
public const int HunterNetCoreDataFieldNumber = 2;
|
|
||||||
private pb::ByteString hunterNetCoreData_ = pb::ByteString.Empty;
|
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
|
||||||
public pb::ByteString HunterNetCoreData {
|
|
||||||
get { return hunterNetCoreData_; }
|
|
||||||
set {
|
|
||||||
hunterNetCoreData_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
|
||||||
public override bool Equals(object other) {
|
|
||||||
return Equals(other as HunterNet_C2S);
|
|
||||||
}
|
|
||||||
|
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
|
||||||
public bool Equals(HunterNet_C2S other) {
|
|
||||||
if (ReferenceEquals(other, null)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (ReferenceEquals(other, this)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (HunterNetCoreCmdID != other.HunterNetCoreCmdID) return false;
|
|
||||||
if (HunterNetCoreData != other.HunterNetCoreData) return false;
|
|
||||||
return Equals(_unknownFields, other._unknownFields);
|
|
||||||
}
|
|
||||||
|
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
|
||||||
public override int GetHashCode() {
|
|
||||||
int hash = 1;
|
|
||||||
if (HunterNetCoreCmdID != 0) hash ^= HunterNetCoreCmdID.GetHashCode();
|
|
||||||
if (HunterNetCoreData.Length != 0) hash ^= HunterNetCoreData.GetHashCode();
|
|
||||||
if (_unknownFields != null) {
|
|
||||||
hash ^= _unknownFields.GetHashCode();
|
|
||||||
}
|
|
||||||
return hash;
|
|
||||||
}
|
|
||||||
|
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
|
||||||
public override string ToString() {
|
|
||||||
return pb::JsonFormatter.ToDiagnosticString(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
|
||||||
public void WriteTo(pb::CodedOutputStream output) {
|
|
||||||
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
|
|
||||||
output.WriteRawMessage(this);
|
|
||||||
#else
|
|
||||||
if (HunterNetCoreCmdID != 0) {
|
|
||||||
output.WriteRawTag(8);
|
|
||||||
output.WriteInt32(HunterNetCoreCmdID);
|
|
||||||
}
|
|
||||||
if (HunterNetCoreData.Length != 0) {
|
|
||||||
output.WriteRawTag(18);
|
|
||||||
output.WriteBytes(HunterNetCoreData);
|
|
||||||
}
|
|
||||||
if (_unknownFields != null) {
|
|
||||||
_unknownFields.WriteTo(output);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
|
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
|
||||||
void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
|
|
||||||
if (HunterNetCoreCmdID != 0) {
|
|
||||||
output.WriteRawTag(8);
|
|
||||||
output.WriteInt32(HunterNetCoreCmdID);
|
|
||||||
}
|
|
||||||
if (HunterNetCoreData.Length != 0) {
|
|
||||||
output.WriteRawTag(18);
|
|
||||||
output.WriteBytes(HunterNetCoreData);
|
|
||||||
}
|
|
||||||
if (_unknownFields != null) {
|
|
||||||
_unknownFields.WriteTo(ref output);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
|
||||||
public int CalculateSize() {
|
|
||||||
int size = 0;
|
|
||||||
if (HunterNetCoreCmdID != 0) {
|
|
||||||
size += 1 + pb::CodedOutputStream.ComputeInt32Size(HunterNetCoreCmdID);
|
|
||||||
}
|
|
||||||
if (HunterNetCoreData.Length != 0) {
|
|
||||||
size += 1 + pb::CodedOutputStream.ComputeBytesSize(HunterNetCoreData);
|
|
||||||
}
|
|
||||||
if (_unknownFields != null) {
|
|
||||||
size += _unknownFields.CalculateSize();
|
|
||||||
}
|
|
||||||
return size;
|
|
||||||
}
|
|
||||||
|
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
|
||||||
public void MergeFrom(HunterNet_C2S other) {
|
|
||||||
if (other == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (other.HunterNetCoreCmdID != 0) {
|
|
||||||
HunterNetCoreCmdID = other.HunterNetCoreCmdID;
|
|
||||||
}
|
|
||||||
if (other.HunterNetCoreData.Length != 0) {
|
|
||||||
HunterNetCoreData = other.HunterNetCoreData;
|
|
||||||
}
|
|
||||||
_unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
|
|
||||||
}
|
|
||||||
|
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
|
||||||
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: {
|
|
||||||
HunterNetCoreCmdID = input.ReadInt32();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 18: {
|
|
||||||
HunterNetCoreData = input.ReadBytes();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
|
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
|
||||||
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: {
|
|
||||||
HunterNetCoreCmdID = input.ReadInt32();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 18: {
|
|
||||||
HunterNetCoreData = input.ReadBytes();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
///下行
|
|
||||||
/// </summary>
|
|
||||||
public sealed partial class HunterNet_S2C : pb::IMessage<HunterNet_S2C>
|
|
||||||
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
|
|
||||||
, pb::IBufferMessage
|
|
||||||
#endif
|
|
||||||
{
|
|
||||||
private static readonly pb::MessageParser<HunterNet_S2C> _parser = new pb::MessageParser<HunterNet_S2C>(() => new HunterNet_S2C());
|
|
||||||
private pb::UnknownFieldSet _unknownFields;
|
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
|
||||||
public static pb::MessageParser<HunterNet_S2C> Parser { get { return _parser; } }
|
|
||||||
|
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
|
||||||
public static pbr::MessageDescriptor Descriptor {
|
|
||||||
get { return global::HunterProtobufCore.ProtobufHunterNetCoreReflection.Descriptor.MessageTypes[1]; }
|
|
||||||
}
|
|
||||||
|
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
|
||||||
pbr::MessageDescriptor pb::IMessage.Descriptor {
|
|
||||||
get { return Descriptor; }
|
|
||||||
}
|
|
||||||
|
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
|
||||||
public HunterNet_S2C() {
|
|
||||||
OnConstruction();
|
|
||||||
}
|
|
||||||
|
|
||||||
partial void OnConstruction();
|
|
||||||
|
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
|
||||||
public HunterNet_S2C(HunterNet_S2C other) : this() {
|
|
||||||
hunterNetCoreCmdID_ = other.hunterNetCoreCmdID_;
|
|
||||||
hunterNetCoreERRORCode_ = other.hunterNetCoreERRORCode_;
|
|
||||||
hunterNetCoreData_ = other.hunterNetCoreData_;
|
|
||||||
_unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
|
|
||||||
}
|
|
||||||
|
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
|
||||||
public HunterNet_S2C Clone() {
|
|
||||||
return new HunterNet_S2C(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>Field number for the "HunterNetCore_CmdID" field.</summary>
|
|
||||||
public const int HunterNetCoreCmdIDFieldNumber = 1;
|
|
||||||
private int hunterNetCoreCmdID_;
|
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
|
||||||
public int HunterNetCoreCmdID {
|
|
||||||
get { return hunterNetCoreCmdID_; }
|
|
||||||
set {
|
|
||||||
hunterNetCoreCmdID_ = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>Field number for the "HunterNetCore_ERRORCode" field.</summary>
|
|
||||||
public const int HunterNetCoreERRORCodeFieldNumber = 2;
|
|
||||||
private int hunterNetCoreERRORCode_;
|
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
|
||||||
public int HunterNetCoreERRORCode {
|
|
||||||
get { return hunterNetCoreERRORCode_; }
|
|
||||||
set {
|
|
||||||
hunterNetCoreERRORCode_ = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>Field number for the "HunterNetCore_Data" field.</summary>
|
|
||||||
public const int HunterNetCoreDataFieldNumber = 3;
|
|
||||||
private pb::ByteString hunterNetCoreData_ = pb::ByteString.Empty;
|
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
|
||||||
public pb::ByteString HunterNetCoreData {
|
|
||||||
get { return hunterNetCoreData_; }
|
|
||||||
set {
|
|
||||||
hunterNetCoreData_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
|
||||||
public override bool Equals(object other) {
|
|
||||||
return Equals(other as HunterNet_S2C);
|
|
||||||
}
|
|
||||||
|
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
|
||||||
public bool Equals(HunterNet_S2C other) {
|
|
||||||
if (ReferenceEquals(other, null)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (ReferenceEquals(other, this)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (HunterNetCoreCmdID != other.HunterNetCoreCmdID) return false;
|
|
||||||
if (HunterNetCoreERRORCode != other.HunterNetCoreERRORCode) return false;
|
|
||||||
if (HunterNetCoreData != other.HunterNetCoreData) return false;
|
|
||||||
return Equals(_unknownFields, other._unknownFields);
|
|
||||||
}
|
|
||||||
|
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
|
||||||
public override int GetHashCode() {
|
|
||||||
int hash = 1;
|
|
||||||
if (HunterNetCoreCmdID != 0) hash ^= HunterNetCoreCmdID.GetHashCode();
|
|
||||||
if (HunterNetCoreERRORCode != 0) hash ^= HunterNetCoreERRORCode.GetHashCode();
|
|
||||||
if (HunterNetCoreData.Length != 0) hash ^= HunterNetCoreData.GetHashCode();
|
|
||||||
if (_unknownFields != null) {
|
|
||||||
hash ^= _unknownFields.GetHashCode();
|
|
||||||
}
|
|
||||||
return hash;
|
|
||||||
}
|
|
||||||
|
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
|
||||||
public override string ToString() {
|
|
||||||
return pb::JsonFormatter.ToDiagnosticString(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
|
||||||
public void WriteTo(pb::CodedOutputStream output) {
|
|
||||||
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
|
|
||||||
output.WriteRawMessage(this);
|
|
||||||
#else
|
|
||||||
if (HunterNetCoreCmdID != 0) {
|
|
||||||
output.WriteRawTag(8);
|
|
||||||
output.WriteInt32(HunterNetCoreCmdID);
|
|
||||||
}
|
|
||||||
if (HunterNetCoreERRORCode != 0) {
|
|
||||||
output.WriteRawTag(16);
|
|
||||||
output.WriteInt32(HunterNetCoreERRORCode);
|
|
||||||
}
|
|
||||||
if (HunterNetCoreData.Length != 0) {
|
|
||||||
output.WriteRawTag(26);
|
|
||||||
output.WriteBytes(HunterNetCoreData);
|
|
||||||
}
|
|
||||||
if (_unknownFields != null) {
|
|
||||||
_unknownFields.WriteTo(output);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
|
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
|
||||||
void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
|
|
||||||
if (HunterNetCoreCmdID != 0) {
|
|
||||||
output.WriteRawTag(8);
|
|
||||||
output.WriteInt32(HunterNetCoreCmdID);
|
|
||||||
}
|
|
||||||
if (HunterNetCoreERRORCode != 0) {
|
|
||||||
output.WriteRawTag(16);
|
|
||||||
output.WriteInt32(HunterNetCoreERRORCode);
|
|
||||||
}
|
|
||||||
if (HunterNetCoreData.Length != 0) {
|
|
||||||
output.WriteRawTag(26);
|
|
||||||
output.WriteBytes(HunterNetCoreData);
|
|
||||||
}
|
|
||||||
if (_unknownFields != null) {
|
|
||||||
_unknownFields.WriteTo(ref output);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
|
||||||
public int CalculateSize() {
|
|
||||||
int size = 0;
|
|
||||||
if (HunterNetCoreCmdID != 0) {
|
|
||||||
size += 1 + pb::CodedOutputStream.ComputeInt32Size(HunterNetCoreCmdID);
|
|
||||||
}
|
|
||||||
if (HunterNetCoreERRORCode != 0) {
|
|
||||||
size += 1 + pb::CodedOutputStream.ComputeInt32Size(HunterNetCoreERRORCode);
|
|
||||||
}
|
|
||||||
if (HunterNetCoreData.Length != 0) {
|
|
||||||
size += 1 + pb::CodedOutputStream.ComputeBytesSize(HunterNetCoreData);
|
|
||||||
}
|
|
||||||
if (_unknownFields != null) {
|
|
||||||
size += _unknownFields.CalculateSize();
|
|
||||||
}
|
|
||||||
return size;
|
|
||||||
}
|
|
||||||
|
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
|
||||||
public void MergeFrom(HunterNet_S2C other) {
|
|
||||||
if (other == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (other.HunterNetCoreCmdID != 0) {
|
|
||||||
HunterNetCoreCmdID = other.HunterNetCoreCmdID;
|
|
||||||
}
|
|
||||||
if (other.HunterNetCoreERRORCode != 0) {
|
|
||||||
HunterNetCoreERRORCode = other.HunterNetCoreERRORCode;
|
|
||||||
}
|
|
||||||
if (other.HunterNetCoreData.Length != 0) {
|
|
||||||
HunterNetCoreData = other.HunterNetCoreData;
|
|
||||||
}
|
|
||||||
_unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
|
|
||||||
}
|
|
||||||
|
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
|
||||||
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: {
|
|
||||||
HunterNetCoreCmdID = input.ReadInt32();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 16: {
|
|
||||||
HunterNetCoreERRORCode = input.ReadInt32();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 26: {
|
|
||||||
HunterNetCoreData = input.ReadBytes();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
|
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
|
||||||
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: {
|
|
||||||
HunterNetCoreCmdID = input.ReadInt32();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 16: {
|
|
||||||
HunterNetCoreERRORCode = input.ReadInt32();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 26: {
|
|
||||||
HunterNetCoreData = input.ReadBytes();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion Designer generated code
|
|
@ -1,7 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<packages>
|
|
||||||
<package id="System.Buffers" version="4.5.1" targetFramework="net48" />
|
|
||||||
<package id="System.Memory" version="4.5.5" targetFramework="net48" />
|
|
||||||
<package id="System.Numerics.Vectors" version="4.5.0" targetFramework="net48" />
|
|
||||||
<package id="System.Runtime.CompilerServices.Unsafe" version="4.5.3" targetFramework="net48" />
|
|
||||||
</packages>
|
|
49
NetLib/HaoYueNet.ServerNetwork/BaseData.cs
Normal file
49
NetLib/HaoYueNet.ServerNetwork/BaseData.cs
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace HaoYueNet.ServerNetwork
|
||||||
|
{
|
||||||
|
public static class BaseData
|
||||||
|
{
|
||||||
|
public static class HunterNet_S2C
|
||||||
|
{
|
||||||
|
public static byte[] CreatePkgData(UInt16 CmdID, UInt16 Error, byte[] data)
|
||||||
|
{
|
||||||
|
byte[] newdata = new byte[2 + 2 + data.Length];
|
||||||
|
BitConverter.GetBytes(CmdID).CopyTo(newdata, 0);
|
||||||
|
BitConverter.GetBytes(Error).CopyTo(newdata, 2);
|
||||||
|
Array.Copy(data, 0, newdata, 4, data.Length);
|
||||||
|
return newdata;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void AnalysisPkgData(byte[] srcdata, out UInt16 CmdID, out UInt16 Error, out byte[] data)
|
||||||
|
{
|
||||||
|
data = new byte[srcdata.Length - 2 - 2];
|
||||||
|
CmdID = BitConverter.ToUInt16(srcdata, 0);
|
||||||
|
Error = BitConverter.ToUInt16(srcdata, 2);
|
||||||
|
Array.Copy(srcdata, 4, data, 0, data.Length);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class HunterNet_C2S
|
||||||
|
{
|
||||||
|
public static byte[] CreatePkgData(UInt16 CmdID, byte[] data)
|
||||||
|
{
|
||||||
|
byte[] newdata = new byte[2 + data.Length];
|
||||||
|
BitConverter.GetBytes(CmdID).CopyTo(newdata, 0);
|
||||||
|
Array.Copy(data, 0, newdata, 2, data.Length);
|
||||||
|
return newdata;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void AnalysisPkgData(byte[] srcdata, out UInt16 CmdID, out byte[] data)
|
||||||
|
{
|
||||||
|
data = new byte[srcdata.Length - 2];
|
||||||
|
CmdID = BitConverter.ToUInt16(srcdata, 0);
|
||||||
|
Array.Copy(srcdata, 2, data, 0, data.Length);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -6,10 +6,4 @@
|
|||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<Reference Include="Google.Protobuf">
|
|
||||||
<HintPath>..\Google.Protobuf.dll</HintPath>
|
|
||||||
</Reference>
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
using Google.Protobuf;
|
//using HunterProtobufCore;
|
||||||
using HunterProtobufCore;
|
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Net.Sockets;
|
using System.Net.Sockets;
|
||||||
|
using static HaoYueNet.ServerNetwork.BaseData;
|
||||||
|
|
||||||
namespace HaoYueNet.ServerNetwork
|
namespace HaoYueNet.ServerNetwork
|
||||||
{
|
{
|
||||||
@ -646,11 +645,12 @@ namespace HaoYueNet.ServerNetwork
|
|||||||
public void SendToSocket(Socket sk, int CMDID, int ERRCODE, byte[] data)
|
public void SendToSocket(Socket sk, int CMDID, int ERRCODE, byte[] data)
|
||||||
{
|
{
|
||||||
AsyncUserToken token = GetAsyncUserTokenForSocket(sk);
|
AsyncUserToken token = GetAsyncUserTokenForSocket(sk);
|
||||||
HunterNet_S2C _s2cdata = new HunterNet_S2C();
|
/*HunterNet_S2C _s2cdata = new HunterNet_S2C();
|
||||||
_s2cdata.HunterNetCoreCmdID = CMDID;
|
_s2cdata.HunterNetCoreCmdID = CMDID;
|
||||||
_s2cdata.HunterNetCoreData = ByteString.CopyFrom(data);
|
_s2cdata.HunterNetCoreData = ByteString.CopyFrom(data);
|
||||||
_s2cdata.HunterNetCoreERRORCode = ERRCODE;
|
_s2cdata.HunterNetCoreERRORCode = ERRCODE;
|
||||||
byte[] _finaldata = Serizlize(_s2cdata);
|
byte[] _finaldata = Serizlize(_s2cdata);*/
|
||||||
|
byte[] _finaldata = HunterNet_S2C.CreatePkgData((ushort)CMDID, (ushort)ERRCODE, data);
|
||||||
SendWithIndex(token, _finaldata);
|
SendWithIndex(token, _finaldata);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -668,10 +668,14 @@ namespace HaoYueNet.ServerNetwork
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
HunterNet_C2S _s2c = DeSerizlize<HunterNet_C2S>(data);
|
|
||||||
//将数据包交给后台处理,这里你也可以新开个线程来处理.加快速度.
|
//将数据包交给后台处理,这里你也可以新开个线程来处理.加快速度.
|
||||||
|
/*
|
||||||
|
HunterNet_C2S _s2c = DeSerizlize<HunterNet_C2S>(data);
|
||||||
OnReceive?.Invoke(sk, (int)_s2c.HunterNetCoreCmdID, _s2c.HunterNetCoreData.ToArray());
|
OnReceive?.Invoke(sk, (int)_s2c.HunterNetCoreCmdID, _s2c.HunterNetCoreData.ToArray());
|
||||||
//DataCallBack(sk, (int)_s2c.HunterNetCoreCmdID, _s2c.HunterNetCoreData.ToArray());
|
//DataCallBack(sk, (int)_s2c.HunterNetCoreCmdID, _s2c.HunterNetCoreData.ToArray());
|
||||||
|
*/
|
||||||
|
HunterNet_C2S.AnalysisPkgData(data, out ushort CmdID, out byte[] resultdata);
|
||||||
|
OnReceive?.Invoke(sk, CmdID, resultdata);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@ -738,17 +742,5 @@ namespace HaoYueNet.ServerNetwork
|
|||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
public static byte[] Serizlize(IMessage msg)
|
|
||||||
{
|
|
||||||
return msg.ToByteArray();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static T DeSerizlize<T>(byte[] bytes)
|
|
||||||
{
|
|
||||||
var msgType = typeof(T);
|
|
||||||
object msg = Activator.CreateInstance(msgType);
|
|
||||||
((IMessage)msg).MergeFrom(bytes);
|
|
||||||
return (T)msg;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,506 +1,506 @@
|
|||||||
// <auto-generated>
|
//// <auto-generated>
|
||||||
// Generated by the protocol buffer compiler. DO NOT EDIT!
|
//// Generated by the protocol buffer compiler. DO NOT EDIT!
|
||||||
// source: protobuf_HunterNetCore.proto
|
//// source: protobuf_HunterNetCore.proto
|
||||||
// </auto-generated>
|
//// </auto-generated>
|
||||||
#pragma warning disable 1591, 0612, 3021
|
//#pragma warning disable 1591, 0612, 3021
|
||||||
#region Designer generated code
|
//#region Designer generated code
|
||||||
|
|
||||||
using pb = global::Google.Protobuf;
|
//using pb = global::Google.Protobuf;
|
||||||
using pbc = global::Google.Protobuf.Collections;
|
//using pbc = global::Google.Protobuf.Collections;
|
||||||
using pbr = global::Google.Protobuf.Reflection;
|
//using pbr = global::Google.Protobuf.Reflection;
|
||||||
using scg = global::System.Collections.Generic;
|
//using scg = global::System.Collections.Generic;
|
||||||
namespace HunterProtobufCore {
|
//namespace HunterProtobufCore {
|
||||||
|
|
||||||
/// <summary>Holder for reflection information generated from protobuf_HunterNetCore.proto</summary>
|
// /// <summary>Holder for reflection information generated from protobuf_HunterNetCore.proto</summary>
|
||||||
public static partial class ProtobufHunterNetCoreReflection {
|
// public static partial class ProtobufHunterNetCoreReflection {
|
||||||
|
|
||||||
#region Descriptor
|
// #region Descriptor
|
||||||
/// <summary>File descriptor for protobuf_HunterNetCore.proto</summary>
|
// /// <summary>File descriptor for protobuf_HunterNetCore.proto</summary>
|
||||||
public static pbr::FileDescriptor Descriptor {
|
// public static pbr::FileDescriptor Descriptor {
|
||||||
get { return descriptor; }
|
// get { return descriptor; }
|
||||||
}
|
// }
|
||||||
private static pbr::FileDescriptor descriptor;
|
// private static pbr::FileDescriptor descriptor;
|
||||||
|
|
||||||
static ProtobufHunterNetCoreReflection() {
|
// static ProtobufHunterNetCoreReflection() {
|
||||||
byte[] descriptorData = global::System.Convert.FromBase64String(
|
// byte[] descriptorData = global::System.Convert.FromBase64String(
|
||||||
string.Concat(
|
// string.Concat(
|
||||||
"Chxwcm90b2J1Zl9IdW50ZXJOZXRDb3JlLnByb3RvEhJIdW50ZXJQcm90b2J1",
|
// "Chxwcm90b2J1Zl9IdW50ZXJOZXRDb3JlLnByb3RvEhJIdW50ZXJQcm90b2J1",
|
||||||
"ZkNvcmUiSAoNSHVudGVyTmV0X0MyUxIbChNIdW50ZXJOZXRDb3JlX0NtZElE",
|
// "ZkNvcmUiSAoNSHVudGVyTmV0X0MyUxIbChNIdW50ZXJOZXRDb3JlX0NtZElE",
|
||||||
"GAEgASgFEhoKEkh1bnRlck5ldENvcmVfRGF0YRgCIAEoDCJpCg1IdW50ZXJO",
|
// "GAEgASgFEhoKEkh1bnRlck5ldENvcmVfRGF0YRgCIAEoDCJpCg1IdW50ZXJO",
|
||||||
"ZXRfUzJDEhsKE0h1bnRlck5ldENvcmVfQ21kSUQYASABKAUSHwoXSHVudGVy",
|
// "ZXRfUzJDEhsKE0h1bnRlck5ldENvcmVfQ21kSUQYASABKAUSHwoXSHVudGVy",
|
||||||
"TmV0Q29yZV9FUlJPUkNvZGUYAiABKAUSGgoSSHVudGVyTmV0Q29yZV9EYXRh",
|
// "TmV0Q29yZV9FUlJPUkNvZGUYAiABKAUSGgoSSHVudGVyTmV0Q29yZV9EYXRh",
|
||||||
"GAMgASgMQgJIAWIGcHJvdG8z"));
|
// "GAMgASgMQgJIAWIGcHJvdG8z"));
|
||||||
descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData,
|
// descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData,
|
||||||
new pbr::FileDescriptor[] { },
|
// new pbr::FileDescriptor[] { },
|
||||||
new pbr::GeneratedClrTypeInfo(null, null, new pbr::GeneratedClrTypeInfo[] {
|
// new pbr::GeneratedClrTypeInfo(null, null, new pbr::GeneratedClrTypeInfo[] {
|
||||||
new pbr::GeneratedClrTypeInfo(typeof(global::HunterProtobufCore.HunterNet_C2S), global::HunterProtobufCore.HunterNet_C2S.Parser, new[]{ "HunterNetCoreCmdID", "HunterNetCoreData" }, null, null, null, null),
|
// new pbr::GeneratedClrTypeInfo(typeof(global::HunterProtobufCore.HunterNet_C2S), global::HunterProtobufCore.HunterNet_C2S.Parser, new[]{ "HunterNetCoreCmdID", "HunterNetCoreData" }, null, null, null, null),
|
||||||
new pbr::GeneratedClrTypeInfo(typeof(global::HunterProtobufCore.HunterNet_S2C), global::HunterProtobufCore.HunterNet_S2C.Parser, new[]{ "HunterNetCoreCmdID", "HunterNetCoreERRORCode", "HunterNetCoreData" }, null, null, null, null)
|
// new pbr::GeneratedClrTypeInfo(typeof(global::HunterProtobufCore.HunterNet_S2C), global::HunterProtobufCore.HunterNet_S2C.Parser, new[]{ "HunterNetCoreCmdID", "HunterNetCoreERRORCode", "HunterNetCoreData" }, null, null, null, null)
|
||||||
}));
|
// }));
|
||||||
}
|
// }
|
||||||
#endregion
|
// #endregion
|
||||||
|
|
||||||
}
|
// }
|
||||||
#region Messages
|
// #region Messages
|
||||||
/// <summary>
|
// /// <summary>
|
||||||
///上行
|
// ///上行
|
||||||
/// </summary>
|
// /// </summary>
|
||||||
public sealed partial class HunterNet_C2S : pb::IMessage<HunterNet_C2S>
|
// public sealed partial class HunterNet_C2S : pb::IMessage<HunterNet_C2S>
|
||||||
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
|
// #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
|
||||||
, pb::IBufferMessage
|
// , pb::IBufferMessage
|
||||||
#endif
|
// #endif
|
||||||
{
|
// {
|
||||||
private static readonly pb::MessageParser<HunterNet_C2S> _parser = new pb::MessageParser<HunterNet_C2S>(() => new HunterNet_C2S());
|
// private static readonly pb::MessageParser<HunterNet_C2S> _parser = new pb::MessageParser<HunterNet_C2S>(() => new HunterNet_C2S());
|
||||||
private pb::UnknownFieldSet _unknownFields;
|
// private pb::UnknownFieldSet _unknownFields;
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
// [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||||
public static pb::MessageParser<HunterNet_C2S> Parser { get { return _parser; } }
|
// public static pb::MessageParser<HunterNet_C2S> Parser { get { return _parser; } }
|
||||||
|
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
// [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||||
public static pbr::MessageDescriptor Descriptor {
|
// public static pbr::MessageDescriptor Descriptor {
|
||||||
get { return global::HunterProtobufCore.ProtobufHunterNetCoreReflection.Descriptor.MessageTypes[0]; }
|
// get { return global::HunterProtobufCore.ProtobufHunterNetCoreReflection.Descriptor.MessageTypes[0]; }
|
||||||
}
|
// }
|
||||||
|
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
// [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||||
pbr::MessageDescriptor pb::IMessage.Descriptor {
|
// pbr::MessageDescriptor pb::IMessage.Descriptor {
|
||||||
get { return Descriptor; }
|
// get { return Descriptor; }
|
||||||
}
|
// }
|
||||||
|
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
// [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||||
public HunterNet_C2S() {
|
// public HunterNet_C2S() {
|
||||||
OnConstruction();
|
// OnConstruction();
|
||||||
}
|
// }
|
||||||
|
|
||||||
partial void OnConstruction();
|
// partial void OnConstruction();
|
||||||
|
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
// [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||||
public HunterNet_C2S(HunterNet_C2S other) : this() {
|
// public HunterNet_C2S(HunterNet_C2S other) : this() {
|
||||||
hunterNetCoreCmdID_ = other.hunterNetCoreCmdID_;
|
// hunterNetCoreCmdID_ = other.hunterNetCoreCmdID_;
|
||||||
hunterNetCoreData_ = other.hunterNetCoreData_;
|
// hunterNetCoreData_ = other.hunterNetCoreData_;
|
||||||
_unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
|
// _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
|
||||||
}
|
// }
|
||||||
|
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
// [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||||
public HunterNet_C2S Clone() {
|
// public HunterNet_C2S Clone() {
|
||||||
return new HunterNet_C2S(this);
|
// return new HunterNet_C2S(this);
|
||||||
}
|
// }
|
||||||
|
|
||||||
/// <summary>Field number for the "HunterNetCore_CmdID" field.</summary>
|
// /// <summary>Field number for the "HunterNetCore_CmdID" field.</summary>
|
||||||
public const int HunterNetCoreCmdIDFieldNumber = 1;
|
// public const int HunterNetCoreCmdIDFieldNumber = 1;
|
||||||
private int hunterNetCoreCmdID_;
|
// private int hunterNetCoreCmdID_;
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
// [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||||
public int HunterNetCoreCmdID {
|
// public int HunterNetCoreCmdID {
|
||||||
get { return hunterNetCoreCmdID_; }
|
// get { return hunterNetCoreCmdID_; }
|
||||||
set {
|
// set {
|
||||||
hunterNetCoreCmdID_ = value;
|
// hunterNetCoreCmdID_ = value;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
/// <summary>Field number for the "HunterNetCore_Data" field.</summary>
|
// /// <summary>Field number for the "HunterNetCore_Data" field.</summary>
|
||||||
public const int HunterNetCoreDataFieldNumber = 2;
|
// public const int HunterNetCoreDataFieldNumber = 2;
|
||||||
private pb::ByteString hunterNetCoreData_ = pb::ByteString.Empty;
|
// private pb::ByteString hunterNetCoreData_ = pb::ByteString.Empty;
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
// [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||||
public pb::ByteString HunterNetCoreData {
|
// public pb::ByteString HunterNetCoreData {
|
||||||
get { return hunterNetCoreData_; }
|
// get { return hunterNetCoreData_; }
|
||||||
set {
|
// set {
|
||||||
hunterNetCoreData_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
|
// hunterNetCoreData_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
// [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||||
public override bool Equals(object other) {
|
// public override bool Equals(object other) {
|
||||||
return Equals(other as HunterNet_C2S);
|
// return Equals(other as HunterNet_C2S);
|
||||||
}
|
// }
|
||||||
|
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
// [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||||
public bool Equals(HunterNet_C2S other) {
|
// public bool Equals(HunterNet_C2S other) {
|
||||||
if (ReferenceEquals(other, null)) {
|
// if (ReferenceEquals(other, null)) {
|
||||||
return false;
|
// return false;
|
||||||
}
|
// }
|
||||||
if (ReferenceEquals(other, this)) {
|
// if (ReferenceEquals(other, this)) {
|
||||||
return true;
|
// return true;
|
||||||
}
|
// }
|
||||||
if (HunterNetCoreCmdID != other.HunterNetCoreCmdID) return false;
|
// if (HunterNetCoreCmdID != other.HunterNetCoreCmdID) return false;
|
||||||
if (HunterNetCoreData != other.HunterNetCoreData) return false;
|
// if (HunterNetCoreData != other.HunterNetCoreData) return false;
|
||||||
return Equals(_unknownFields, other._unknownFields);
|
// return Equals(_unknownFields, other._unknownFields);
|
||||||
}
|
// }
|
||||||
|
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
// [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||||
public override int GetHashCode() {
|
// public override int GetHashCode() {
|
||||||
int hash = 1;
|
// int hash = 1;
|
||||||
if (HunterNetCoreCmdID != 0) hash ^= HunterNetCoreCmdID.GetHashCode();
|
// if (HunterNetCoreCmdID != 0) hash ^= HunterNetCoreCmdID.GetHashCode();
|
||||||
if (HunterNetCoreData.Length != 0) hash ^= HunterNetCoreData.GetHashCode();
|
// if (HunterNetCoreData.Length != 0) hash ^= HunterNetCoreData.GetHashCode();
|
||||||
if (_unknownFields != null) {
|
// if (_unknownFields != null) {
|
||||||
hash ^= _unknownFields.GetHashCode();
|
// hash ^= _unknownFields.GetHashCode();
|
||||||
}
|
// }
|
||||||
return hash;
|
// return hash;
|
||||||
}
|
// }
|
||||||
|
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
// [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||||
public override string ToString() {
|
// public override string ToString() {
|
||||||
return pb::JsonFormatter.ToDiagnosticString(this);
|
// return pb::JsonFormatter.ToDiagnosticString(this);
|
||||||
}
|
// }
|
||||||
|
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
// [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||||
public void WriteTo(pb::CodedOutputStream output) {
|
// public void WriteTo(pb::CodedOutputStream output) {
|
||||||
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
|
// #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
|
||||||
output.WriteRawMessage(this);
|
// output.WriteRawMessage(this);
|
||||||
#else
|
// #else
|
||||||
if (HunterNetCoreCmdID != 0) {
|
// if (HunterNetCoreCmdID != 0) {
|
||||||
output.WriteRawTag(8);
|
// output.WriteRawTag(8);
|
||||||
output.WriteInt32(HunterNetCoreCmdID);
|
// output.WriteInt32(HunterNetCoreCmdID);
|
||||||
}
|
// }
|
||||||
if (HunterNetCoreData.Length != 0) {
|
// if (HunterNetCoreData.Length != 0) {
|
||||||
output.WriteRawTag(18);
|
// output.WriteRawTag(18);
|
||||||
output.WriteBytes(HunterNetCoreData);
|
// output.WriteBytes(HunterNetCoreData);
|
||||||
}
|
// }
|
||||||
if (_unknownFields != null) {
|
// if (_unknownFields != null) {
|
||||||
_unknownFields.WriteTo(output);
|
// _unknownFields.WriteTo(output);
|
||||||
}
|
// }
|
||||||
#endif
|
// #endif
|
||||||
}
|
// }
|
||||||
|
|
||||||
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
|
// #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
// [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||||
void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
|
// void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
|
||||||
if (HunterNetCoreCmdID != 0) {
|
// if (HunterNetCoreCmdID != 0) {
|
||||||
output.WriteRawTag(8);
|
// output.WriteRawTag(8);
|
||||||
output.WriteInt32(HunterNetCoreCmdID);
|
// output.WriteInt32(HunterNetCoreCmdID);
|
||||||
}
|
// }
|
||||||
if (HunterNetCoreData.Length != 0) {
|
// if (HunterNetCoreData.Length != 0) {
|
||||||
output.WriteRawTag(18);
|
// output.WriteRawTag(18);
|
||||||
output.WriteBytes(HunterNetCoreData);
|
// output.WriteBytes(HunterNetCoreData);
|
||||||
}
|
// }
|
||||||
if (_unknownFields != null) {
|
// if (_unknownFields != null) {
|
||||||
_unknownFields.WriteTo(ref output);
|
// _unknownFields.WriteTo(ref output);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
#endif
|
// #endif
|
||||||
|
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
// [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||||
public int CalculateSize() {
|
// public int CalculateSize() {
|
||||||
int size = 0;
|
// int size = 0;
|
||||||
if (HunterNetCoreCmdID != 0) {
|
// if (HunterNetCoreCmdID != 0) {
|
||||||
size += 1 + pb::CodedOutputStream.ComputeInt32Size(HunterNetCoreCmdID);
|
// size += 1 + pb::CodedOutputStream.ComputeInt32Size(HunterNetCoreCmdID);
|
||||||
}
|
// }
|
||||||
if (HunterNetCoreData.Length != 0) {
|
// if (HunterNetCoreData.Length != 0) {
|
||||||
size += 1 + pb::CodedOutputStream.ComputeBytesSize(HunterNetCoreData);
|
// size += 1 + pb::CodedOutputStream.ComputeBytesSize(HunterNetCoreData);
|
||||||
}
|
// }
|
||||||
if (_unknownFields != null) {
|
// if (_unknownFields != null) {
|
||||||
size += _unknownFields.CalculateSize();
|
// size += _unknownFields.CalculateSize();
|
||||||
}
|
// }
|
||||||
return size;
|
// return size;
|
||||||
}
|
// }
|
||||||
|
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
// [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||||
public void MergeFrom(HunterNet_C2S other) {
|
// public void MergeFrom(HunterNet_C2S other) {
|
||||||
if (other == null) {
|
// if (other == null) {
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
if (other.HunterNetCoreCmdID != 0) {
|
// if (other.HunterNetCoreCmdID != 0) {
|
||||||
HunterNetCoreCmdID = other.HunterNetCoreCmdID;
|
// HunterNetCoreCmdID = other.HunterNetCoreCmdID;
|
||||||
}
|
// }
|
||||||
if (other.HunterNetCoreData.Length != 0) {
|
// if (other.HunterNetCoreData.Length != 0) {
|
||||||
HunterNetCoreData = other.HunterNetCoreData;
|
// HunterNetCoreData = other.HunterNetCoreData;
|
||||||
}
|
// }
|
||||||
_unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
|
// _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
|
||||||
}
|
// }
|
||||||
|
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
// [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||||
public void MergeFrom(pb::CodedInputStream input) {
|
// public void MergeFrom(pb::CodedInputStream input) {
|
||||||
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
|
// #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
|
||||||
input.ReadRawMessage(this);
|
// input.ReadRawMessage(this);
|
||||||
#else
|
// #else
|
||||||
uint tag;
|
// uint tag;
|
||||||
while ((tag = input.ReadTag()) != 0) {
|
// while ((tag = input.ReadTag()) != 0) {
|
||||||
switch(tag) {
|
// switch(tag) {
|
||||||
default:
|
// default:
|
||||||
_unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
|
// _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
|
||||||
break;
|
// break;
|
||||||
case 8: {
|
// case 8: {
|
||||||
HunterNetCoreCmdID = input.ReadInt32();
|
// HunterNetCoreCmdID = input.ReadInt32();
|
||||||
break;
|
// break;
|
||||||
}
|
// }
|
||||||
case 18: {
|
// case 18: {
|
||||||
HunterNetCoreData = input.ReadBytes();
|
// HunterNetCoreData = input.ReadBytes();
|
||||||
break;
|
// break;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
#endif
|
// #endif
|
||||||
}
|
// }
|
||||||
|
|
||||||
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
|
// #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
// [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||||
void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) {
|
// void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) {
|
||||||
uint tag;
|
// uint tag;
|
||||||
while ((tag = input.ReadTag()) != 0) {
|
// while ((tag = input.ReadTag()) != 0) {
|
||||||
switch(tag) {
|
// switch(tag) {
|
||||||
default:
|
// default:
|
||||||
_unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
|
// _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
|
||||||
break;
|
// break;
|
||||||
case 8: {
|
// case 8: {
|
||||||
HunterNetCoreCmdID = input.ReadInt32();
|
// HunterNetCoreCmdID = input.ReadInt32();
|
||||||
break;
|
// break;
|
||||||
}
|
// }
|
||||||
case 18: {
|
// case 18: {
|
||||||
HunterNetCoreData = input.ReadBytes();
|
// HunterNetCoreData = input.ReadBytes();
|
||||||
break;
|
// break;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
#endif
|
// #endif
|
||||||
|
|
||||||
}
|
// }
|
||||||
|
|
||||||
/// <summary>
|
// /// <summary>
|
||||||
///下行
|
// ///下行
|
||||||
/// </summary>
|
// /// </summary>
|
||||||
public sealed partial class HunterNet_S2C : pb::IMessage<HunterNet_S2C>
|
// public sealed partial class HunterNet_S2C : pb::IMessage<HunterNet_S2C>
|
||||||
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
|
// #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
|
||||||
, pb::IBufferMessage
|
// , pb::IBufferMessage
|
||||||
#endif
|
// #endif
|
||||||
{
|
// {
|
||||||
private static readonly pb::MessageParser<HunterNet_S2C> _parser = new pb::MessageParser<HunterNet_S2C>(() => new HunterNet_S2C());
|
// private static readonly pb::MessageParser<HunterNet_S2C> _parser = new pb::MessageParser<HunterNet_S2C>(() => new HunterNet_S2C());
|
||||||
private pb::UnknownFieldSet _unknownFields;
|
// private pb::UnknownFieldSet _unknownFields;
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
// [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||||
public static pb::MessageParser<HunterNet_S2C> Parser { get { return _parser; } }
|
// public static pb::MessageParser<HunterNet_S2C> Parser { get { return _parser; } }
|
||||||
|
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
// [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||||
public static pbr::MessageDescriptor Descriptor {
|
// public static pbr::MessageDescriptor Descriptor {
|
||||||
get { return global::HunterProtobufCore.ProtobufHunterNetCoreReflection.Descriptor.MessageTypes[1]; }
|
// get { return global::HunterProtobufCore.ProtobufHunterNetCoreReflection.Descriptor.MessageTypes[1]; }
|
||||||
}
|
// }
|
||||||
|
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
// [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||||
pbr::MessageDescriptor pb::IMessage.Descriptor {
|
// pbr::MessageDescriptor pb::IMessage.Descriptor {
|
||||||
get { return Descriptor; }
|
// get { return Descriptor; }
|
||||||
}
|
// }
|
||||||
|
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
// [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||||
public HunterNet_S2C() {
|
// public HunterNet_S2C() {
|
||||||
OnConstruction();
|
// OnConstruction();
|
||||||
}
|
// }
|
||||||
|
|
||||||
partial void OnConstruction();
|
// partial void OnConstruction();
|
||||||
|
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
// [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||||
public HunterNet_S2C(HunterNet_S2C other) : this() {
|
// public HunterNet_S2C(HunterNet_S2C other) : this() {
|
||||||
hunterNetCoreCmdID_ = other.hunterNetCoreCmdID_;
|
// hunterNetCoreCmdID_ = other.hunterNetCoreCmdID_;
|
||||||
hunterNetCoreERRORCode_ = other.hunterNetCoreERRORCode_;
|
// hunterNetCoreERRORCode_ = other.hunterNetCoreERRORCode_;
|
||||||
hunterNetCoreData_ = other.hunterNetCoreData_;
|
// hunterNetCoreData_ = other.hunterNetCoreData_;
|
||||||
_unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
|
// _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
|
||||||
}
|
// }
|
||||||
|
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
// [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||||
public HunterNet_S2C Clone() {
|
// public HunterNet_S2C Clone() {
|
||||||
return new HunterNet_S2C(this);
|
// return new HunterNet_S2C(this);
|
||||||
}
|
// }
|
||||||
|
|
||||||
/// <summary>Field number for the "HunterNetCore_CmdID" field.</summary>
|
// /// <summary>Field number for the "HunterNetCore_CmdID" field.</summary>
|
||||||
public const int HunterNetCoreCmdIDFieldNumber = 1;
|
// public const int HunterNetCoreCmdIDFieldNumber = 1;
|
||||||
private int hunterNetCoreCmdID_;
|
// private int hunterNetCoreCmdID_;
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
// [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||||
public int HunterNetCoreCmdID {
|
// public int HunterNetCoreCmdID {
|
||||||
get { return hunterNetCoreCmdID_; }
|
// get { return hunterNetCoreCmdID_; }
|
||||||
set {
|
// set {
|
||||||
hunterNetCoreCmdID_ = value;
|
// hunterNetCoreCmdID_ = value;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
/// <summary>Field number for the "HunterNetCore_ERRORCode" field.</summary>
|
// /// <summary>Field number for the "HunterNetCore_ERRORCode" field.</summary>
|
||||||
public const int HunterNetCoreERRORCodeFieldNumber = 2;
|
// public const int HunterNetCoreERRORCodeFieldNumber = 2;
|
||||||
private int hunterNetCoreERRORCode_;
|
// private int hunterNetCoreERRORCode_;
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
// [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||||
public int HunterNetCoreERRORCode {
|
// public int HunterNetCoreERRORCode {
|
||||||
get { return hunterNetCoreERRORCode_; }
|
// get { return hunterNetCoreERRORCode_; }
|
||||||
set {
|
// set {
|
||||||
hunterNetCoreERRORCode_ = value;
|
// hunterNetCoreERRORCode_ = value;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
/// <summary>Field number for the "HunterNetCore_Data" field.</summary>
|
// /// <summary>Field number for the "HunterNetCore_Data" field.</summary>
|
||||||
public const int HunterNetCoreDataFieldNumber = 3;
|
// public const int HunterNetCoreDataFieldNumber = 3;
|
||||||
private pb::ByteString hunterNetCoreData_ = pb::ByteString.Empty;
|
// private pb::ByteString hunterNetCoreData_ = pb::ByteString.Empty;
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
// [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||||
public pb::ByteString HunterNetCoreData {
|
// public pb::ByteString HunterNetCoreData {
|
||||||
get { return hunterNetCoreData_; }
|
// get { return hunterNetCoreData_; }
|
||||||
set {
|
// set {
|
||||||
hunterNetCoreData_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
|
// hunterNetCoreData_ = pb::ProtoPreconditions.CheckNotNull(value, "value");
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
// [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||||
public override bool Equals(object other) {
|
// public override bool Equals(object other) {
|
||||||
return Equals(other as HunterNet_S2C);
|
// return Equals(other as HunterNet_S2C);
|
||||||
}
|
// }
|
||||||
|
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
// [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||||
public bool Equals(HunterNet_S2C other) {
|
// public bool Equals(HunterNet_S2C other) {
|
||||||
if (ReferenceEquals(other, null)) {
|
// if (ReferenceEquals(other, null)) {
|
||||||
return false;
|
// return false;
|
||||||
}
|
// }
|
||||||
if (ReferenceEquals(other, this)) {
|
// if (ReferenceEquals(other, this)) {
|
||||||
return true;
|
// return true;
|
||||||
}
|
// }
|
||||||
if (HunterNetCoreCmdID != other.HunterNetCoreCmdID) return false;
|
// if (HunterNetCoreCmdID != other.HunterNetCoreCmdID) return false;
|
||||||
if (HunterNetCoreERRORCode != other.HunterNetCoreERRORCode) return false;
|
// if (HunterNetCoreERRORCode != other.HunterNetCoreERRORCode) return false;
|
||||||
if (HunterNetCoreData != other.HunterNetCoreData) return false;
|
// if (HunterNetCoreData != other.HunterNetCoreData) return false;
|
||||||
return Equals(_unknownFields, other._unknownFields);
|
// return Equals(_unknownFields, other._unknownFields);
|
||||||
}
|
// }
|
||||||
|
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
// [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||||
public override int GetHashCode() {
|
// public override int GetHashCode() {
|
||||||
int hash = 1;
|
// int hash = 1;
|
||||||
if (HunterNetCoreCmdID != 0) hash ^= HunterNetCoreCmdID.GetHashCode();
|
// if (HunterNetCoreCmdID != 0) hash ^= HunterNetCoreCmdID.GetHashCode();
|
||||||
if (HunterNetCoreERRORCode != 0) hash ^= HunterNetCoreERRORCode.GetHashCode();
|
// if (HunterNetCoreERRORCode != 0) hash ^= HunterNetCoreERRORCode.GetHashCode();
|
||||||
if (HunterNetCoreData.Length != 0) hash ^= HunterNetCoreData.GetHashCode();
|
// if (HunterNetCoreData.Length != 0) hash ^= HunterNetCoreData.GetHashCode();
|
||||||
if (_unknownFields != null) {
|
// if (_unknownFields != null) {
|
||||||
hash ^= _unknownFields.GetHashCode();
|
// hash ^= _unknownFields.GetHashCode();
|
||||||
}
|
// }
|
||||||
return hash;
|
// return hash;
|
||||||
}
|
// }
|
||||||
|
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
// [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||||
public override string ToString() {
|
// public override string ToString() {
|
||||||
return pb::JsonFormatter.ToDiagnosticString(this);
|
// return pb::JsonFormatter.ToDiagnosticString(this);
|
||||||
}
|
// }
|
||||||
|
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
// [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||||
public void WriteTo(pb::CodedOutputStream output) {
|
// public void WriteTo(pb::CodedOutputStream output) {
|
||||||
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
|
// #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
|
||||||
output.WriteRawMessage(this);
|
// output.WriteRawMessage(this);
|
||||||
#else
|
// #else
|
||||||
if (HunterNetCoreCmdID != 0) {
|
// if (HunterNetCoreCmdID != 0) {
|
||||||
output.WriteRawTag(8);
|
// output.WriteRawTag(8);
|
||||||
output.WriteInt32(HunterNetCoreCmdID);
|
// output.WriteInt32(HunterNetCoreCmdID);
|
||||||
}
|
// }
|
||||||
if (HunterNetCoreERRORCode != 0) {
|
// if (HunterNetCoreERRORCode != 0) {
|
||||||
output.WriteRawTag(16);
|
// output.WriteRawTag(16);
|
||||||
output.WriteInt32(HunterNetCoreERRORCode);
|
// output.WriteInt32(HunterNetCoreERRORCode);
|
||||||
}
|
// }
|
||||||
if (HunterNetCoreData.Length != 0) {
|
// if (HunterNetCoreData.Length != 0) {
|
||||||
output.WriteRawTag(26);
|
// output.WriteRawTag(26);
|
||||||
output.WriteBytes(HunterNetCoreData);
|
// output.WriteBytes(HunterNetCoreData);
|
||||||
}
|
// }
|
||||||
if (_unknownFields != null) {
|
// if (_unknownFields != null) {
|
||||||
_unknownFields.WriteTo(output);
|
// _unknownFields.WriteTo(output);
|
||||||
}
|
// }
|
||||||
#endif
|
// #endif
|
||||||
}
|
// }
|
||||||
|
|
||||||
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
|
// #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
// [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||||
void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
|
// void pb::IBufferMessage.InternalWriteTo(ref pb::WriteContext output) {
|
||||||
if (HunterNetCoreCmdID != 0) {
|
// if (HunterNetCoreCmdID != 0) {
|
||||||
output.WriteRawTag(8);
|
// output.WriteRawTag(8);
|
||||||
output.WriteInt32(HunterNetCoreCmdID);
|
// output.WriteInt32(HunterNetCoreCmdID);
|
||||||
}
|
// }
|
||||||
if (HunterNetCoreERRORCode != 0) {
|
// if (HunterNetCoreERRORCode != 0) {
|
||||||
output.WriteRawTag(16);
|
// output.WriteRawTag(16);
|
||||||
output.WriteInt32(HunterNetCoreERRORCode);
|
// output.WriteInt32(HunterNetCoreERRORCode);
|
||||||
}
|
// }
|
||||||
if (HunterNetCoreData.Length != 0) {
|
// if (HunterNetCoreData.Length != 0) {
|
||||||
output.WriteRawTag(26);
|
// output.WriteRawTag(26);
|
||||||
output.WriteBytes(HunterNetCoreData);
|
// output.WriteBytes(HunterNetCoreData);
|
||||||
}
|
// }
|
||||||
if (_unknownFields != null) {
|
// if (_unknownFields != null) {
|
||||||
_unknownFields.WriteTo(ref output);
|
// _unknownFields.WriteTo(ref output);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
#endif
|
// #endif
|
||||||
|
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
// [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||||
public int CalculateSize() {
|
// public int CalculateSize() {
|
||||||
int size = 0;
|
// int size = 0;
|
||||||
if (HunterNetCoreCmdID != 0) {
|
// if (HunterNetCoreCmdID != 0) {
|
||||||
size += 1 + pb::CodedOutputStream.ComputeInt32Size(HunterNetCoreCmdID);
|
// size += 1 + pb::CodedOutputStream.ComputeInt32Size(HunterNetCoreCmdID);
|
||||||
}
|
// }
|
||||||
if (HunterNetCoreERRORCode != 0) {
|
// if (HunterNetCoreERRORCode != 0) {
|
||||||
size += 1 + pb::CodedOutputStream.ComputeInt32Size(HunterNetCoreERRORCode);
|
// size += 1 + pb::CodedOutputStream.ComputeInt32Size(HunterNetCoreERRORCode);
|
||||||
}
|
// }
|
||||||
if (HunterNetCoreData.Length != 0) {
|
// if (HunterNetCoreData.Length != 0) {
|
||||||
size += 1 + pb::CodedOutputStream.ComputeBytesSize(HunterNetCoreData);
|
// size += 1 + pb::CodedOutputStream.ComputeBytesSize(HunterNetCoreData);
|
||||||
}
|
// }
|
||||||
if (_unknownFields != null) {
|
// if (_unknownFields != null) {
|
||||||
size += _unknownFields.CalculateSize();
|
// size += _unknownFields.CalculateSize();
|
||||||
}
|
// }
|
||||||
return size;
|
// return size;
|
||||||
}
|
// }
|
||||||
|
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
// [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||||
public void MergeFrom(HunterNet_S2C other) {
|
// public void MergeFrom(HunterNet_S2C other) {
|
||||||
if (other == null) {
|
// if (other == null) {
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
if (other.HunterNetCoreCmdID != 0) {
|
// if (other.HunterNetCoreCmdID != 0) {
|
||||||
HunterNetCoreCmdID = other.HunterNetCoreCmdID;
|
// HunterNetCoreCmdID = other.HunterNetCoreCmdID;
|
||||||
}
|
// }
|
||||||
if (other.HunterNetCoreERRORCode != 0) {
|
// if (other.HunterNetCoreERRORCode != 0) {
|
||||||
HunterNetCoreERRORCode = other.HunterNetCoreERRORCode;
|
// HunterNetCoreERRORCode = other.HunterNetCoreERRORCode;
|
||||||
}
|
// }
|
||||||
if (other.HunterNetCoreData.Length != 0) {
|
// if (other.HunterNetCoreData.Length != 0) {
|
||||||
HunterNetCoreData = other.HunterNetCoreData;
|
// HunterNetCoreData = other.HunterNetCoreData;
|
||||||
}
|
// }
|
||||||
_unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
|
// _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
|
||||||
}
|
// }
|
||||||
|
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
// [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||||
public void MergeFrom(pb::CodedInputStream input) {
|
// public void MergeFrom(pb::CodedInputStream input) {
|
||||||
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
|
// #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
|
||||||
input.ReadRawMessage(this);
|
// input.ReadRawMessage(this);
|
||||||
#else
|
// #else
|
||||||
uint tag;
|
// uint tag;
|
||||||
while ((tag = input.ReadTag()) != 0) {
|
// while ((tag = input.ReadTag()) != 0) {
|
||||||
switch(tag) {
|
// switch(tag) {
|
||||||
default:
|
// default:
|
||||||
_unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
|
// _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
|
||||||
break;
|
// break;
|
||||||
case 8: {
|
// case 8: {
|
||||||
HunterNetCoreCmdID = input.ReadInt32();
|
// HunterNetCoreCmdID = input.ReadInt32();
|
||||||
break;
|
// break;
|
||||||
}
|
// }
|
||||||
case 16: {
|
// case 16: {
|
||||||
HunterNetCoreERRORCode = input.ReadInt32();
|
// HunterNetCoreERRORCode = input.ReadInt32();
|
||||||
break;
|
// break;
|
||||||
}
|
// }
|
||||||
case 26: {
|
// case 26: {
|
||||||
HunterNetCoreData = input.ReadBytes();
|
// HunterNetCoreData = input.ReadBytes();
|
||||||
break;
|
// break;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
#endif
|
// #endif
|
||||||
}
|
// }
|
||||||
|
|
||||||
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
|
// #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
|
||||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
// [global::System.Diagnostics.DebuggerNonUserCodeAttribute]
|
||||||
void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) {
|
// void pb::IBufferMessage.InternalMergeFrom(ref pb::ParseContext input) {
|
||||||
uint tag;
|
// uint tag;
|
||||||
while ((tag = input.ReadTag()) != 0) {
|
// while ((tag = input.ReadTag()) != 0) {
|
||||||
switch(tag) {
|
// switch(tag) {
|
||||||
default:
|
// default:
|
||||||
_unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
|
// _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, ref input);
|
||||||
break;
|
// break;
|
||||||
case 8: {
|
// case 8: {
|
||||||
HunterNetCoreCmdID = input.ReadInt32();
|
// HunterNetCoreCmdID = input.ReadInt32();
|
||||||
break;
|
// break;
|
||||||
}
|
// }
|
||||||
case 16: {
|
// case 16: {
|
||||||
HunterNetCoreERRORCode = input.ReadInt32();
|
// HunterNetCoreERRORCode = input.ReadInt32();
|
||||||
break;
|
// break;
|
||||||
}
|
// }
|
||||||
case 26: {
|
// case 26: {
|
||||||
HunterNetCoreData = input.ReadBytes();
|
// HunterNetCoreData = input.ReadBytes();
|
||||||
break;
|
// break;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
#endif
|
// #endif
|
||||||
|
|
||||||
}
|
// }
|
||||||
|
|
||||||
#endregion
|
// #endregion
|
||||||
|
|
||||||
}
|
//}
|
||||||
|
|
||||||
#endregion Designer generated code
|
//#endregion Designer generated code
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
# HaoYueNet
|
# HaoYueNet
|
||||||
|
|
||||||
.Net 7 的,自建基于IOCP的TCP的高性能网络库
|
.Net 7 的,自建基于IOCP的TCP的高性能网络库
|
||||||
使用Protobuff作为基础协议
|
|
||||||
|
使用Protobuff作为基础协议(网络库本身不依赖Protobuff,仅上层示例依赖)
|
||||||
|
|
||||||
|
网络库本身无依赖,可以用于任何数据通讯
|
||||||
|
|
||||||
包含服务端和客户端双端库,可直接用于各类.Net程序或Unity程序,做TCP通讯底层库。
|
包含服务端和客户端双端库,可直接用于各类.Net程序或Unity程序,做TCP通讯底层库。
|
||||||
|
|
||||||
|
@ -4,12 +4,10 @@ namespace ClientCore.Common
|
|||||||
{
|
{
|
||||||
public static class ProtoBufHelper
|
public static class ProtoBufHelper
|
||||||
{
|
{
|
||||||
|
|
||||||
public static byte[] Serizlize(IMessage msg)
|
public static byte[] Serizlize(IMessage msg)
|
||||||
{
|
{
|
||||||
return msg.ToByteArray();
|
return msg.ToByteArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static T DeSerizlize<T>(byte[] bytes)
|
public static T DeSerizlize<T>(byte[] bytes)
|
||||||
{
|
{
|
||||||
var msgType = typeof(T);
|
var msgType = typeof(T);
|
||||||
|
@ -17,7 +17,7 @@ namespace ClientCore.Manager
|
|||||||
LoginType = 0,
|
LoginType = 0,
|
||||||
Account = Account,
|
Account = Account,
|
||||||
};
|
};
|
||||||
App.networkHelper.SendToServer((int)CommandID.CmdLogin, NetworkHelper.Serizlize(msg));
|
App.networkHelper.SendToServer((int)CommandID.CmdLogin, ProtoBufHelper.Serizlize(msg));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RecvLoginMsg(byte[] reqData)
|
public void RecvLoginMsg(byte[] reqData)
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using AxibugProtobuf;
|
using AxibugProtobuf;
|
||||||
|
using Google.Protobuf;
|
||||||
using HaoYueNet.ClientNetwork;
|
using HaoYueNet.ClientNetwork;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
Loading…
Reference in New Issue
Block a user