事件 和 网络管理等

This commit is contained in:
sin365 2023-05-25 18:30:22 +08:00
parent fb264af37b
commit 6cbff804b9
45 changed files with 5569 additions and 102 deletions

Binary file not shown.

View File

@ -1,8 +1,13 @@
using ClientCore; using ClientCore;
using ClientCore.Event;
App.Init("127.0.0.1", 23846); App.Init("127.0.0.1", 23846);
//注册 //注册事件
App.chat.OnChatMsg += OnChatMsg; EventSystem.Instance.RegisterEvent<long>(EEvent.UserJoin, OnUserJoin);
EventSystem.Instance.RegisterEvent<long>(EEvent.UserLeave, OnUserLeave);
EventSystem.Instance.RegisterEvent<string, string>(EEvent.OnChatMsg, OnChatMsg);
while (true) while (true)
{ {
@ -39,3 +44,12 @@ void OnChatMsg(string str1, string str2)
{ {
Console.WriteLine($"[Chat]{str1}:{str2}"); Console.WriteLine($"[Chat]{str1}:{str2}");
} }
void OnUserJoin(long UID)
{
Console.WriteLine($"[User]用户{UID}上线");
}
void OnUserLeave(long UID)
{
Console.WriteLine($"[User]用户{UID}下线");
}

View File

@ -3,6 +3,8 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using ClientCore.Manager;
using ClientCore.Network;
namespace ClientCore namespace ClientCore
{ {
@ -12,15 +14,19 @@ namespace ClientCore
public static long RID = -1; public static long RID = -1;
public static string IP; public static string IP;
public static int Port; public static int Port;
public static LogManager log;
public static NetworkHelper networkHelper; public static NetworkHelper networkHelper;
public static AppLogin login; public static AppLogin login;
public static AppChat chat; public static AppChat chat;
public static UserMgr userMgr;
public static void Init(string IP, int port) public static void Init(string IP, int port)
{ {
log = new LogManager();
networkHelper = new NetworkHelper(); networkHelper = new NetworkHelper();
login = new AppLogin(); login = new AppLogin();
chat = new AppChat(); chat = new AppChat();
userMgr = new UserMgr();
networkHelper.Init(IP, port); networkHelper.Init(IP, port);
} }
} }

View File

@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>net7.0</TargetFramework> <TargetFramework>net7.0</TargetFramework>

View File

@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ClientCore.Common
{
public static class Helper
{
public static long GetNowTimeStamp()
{
return GetTimeStamp(DateTime.Now);
}
/// <summary>
/// 获取时间戳
/// </summary>
/// <returns></returns>
public static long GetTimeStamp(DateTime dt)
{
TimeSpan ts = dt - new DateTime(1970, 1, 1, 0, 0, 0, 0);
return Convert.ToInt64(ts.TotalSeconds);
}
}
}

View File

@ -1,8 +1,8 @@
using Google.Protobuf; using Google.Protobuf;
namespace ServerCore namespace ClientCore.Common
{ {
public static class NetBase public static class ProtoBufHelper
{ {
public static byte[] Serizlize(IMessage msg) public static byte[] Serizlize(IMessage msg)

View File

@ -1,15 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static HaoYueNet.ClientNetwork.NetworkHelperCore;
namespace ClientCore.Event
{
public class DelegateClass
{
public delegate void dg_Str(string Msg);
public delegate void dg_Str_Str(string Str1, string Str2);
}
}

View File

@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ClientCore.Event
{
public enum EEvent
{
// 添加你自己需要的事件类型
UserJoin,
UserLeave,
OnChatMsg,
}
}

View File

@ -0,0 +1,245 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ClientCore.Event
{
public class EventData
{
private static long BaseUid = 0;
private static long GenUid()
{
return (++BaseUid);
}
/// <summary>
/// 唯一id
/// </summary>
public long uid { get; private set; }
/// <summary>
/// 回调
/// </summary>
public Delegate callback { get; private set; }
public EventData(Delegate d)
{
uid = GenUid();
callback = d;
}
}
public class EventSystem
{
private static EventSystem instance = new EventSystem();
public static EventSystem Instance { get { return instance; } }
private Dictionary<EEvent, List<Delegate>> eventDic = new Dictionary<EEvent, List<Delegate>>(128);
private EventSystem() { }
#region RegisterEvent
public void RegisterEvent(EEvent evt, Action callback)
{
InterRegisterEvent(evt, callback);
}
public void RegisterEvent<T1>(EEvent evt, Action<T1> callback)
{
InterRegisterEvent(evt, callback);
}
public void RegisterEvent<T1, T2>(EEvent evt, Action<T1, T2> callback)
{
InterRegisterEvent(evt, callback);
}
public void RegisterEvent<T1, T2, T3>(EEvent evt, Action<T1, T2, T3> callback)
{
InterRegisterEvent(evt, callback);
}
public void RegisterEvent<T1, T2, T3, T4>(EEvent evt, Action<T1, T2, T3, T4> callback)
{
InterRegisterEvent(evt, callback);
}
private void InterRegisterEvent(EEvent evt, Delegate callback)
{
if (eventDic.ContainsKey(evt))
{
if (eventDic[evt].IndexOf(callback) < 0)
{
eventDic[evt].Add(callback);
}
}
else
{
eventDic.Add(evt, new List<Delegate>() { callback });
}
}
#endregion
#region UnregisterEvent
public void UnregisterEvent(EEvent evt, Action callback)
{
Delegate tempDelegate = callback;
InterUnregisterEvent(evt, tempDelegate);
}
public void UnregisterEvent<T1>(EEvent evt, Action<T1> callback)
{
Delegate tempDelegate = callback;
InterUnregisterEvent(evt, tempDelegate);
}
public void UnregisterEvent<T1, T2>(EEvent evt, Action<T1, T2> callback)
{
Delegate tempDelegate = callback;
InterUnregisterEvent(evt, tempDelegate);
}
public void UnregisterEvent<T1, T2, T3>(EEvent evt, Action<T1, T2, T3> callback)
{
Delegate tempDelegate = callback;
InterUnregisterEvent(evt, tempDelegate);
}
public void UnregisterEvent<T1, T2, T3, T4>(EEvent evt, Action<T1, T2, T3, T4> callback)
{
Delegate tempDelegate = callback;
InterUnregisterEvent(evt, tempDelegate);
}
private void InterUnregisterEvent(EEvent evt, Delegate callback)
{
if (eventDic.ContainsKey(evt))
{
eventDic[evt].Remove(callback);
if (eventDic[evt].Count == 0) eventDic.Remove(evt);
}
}
#endregion
#region PostEvent
public void PostEvent<T1, T2, T3, T4>(EEvent evt, T1 arg1, T2 arg2, T3 arg3, T4 arg4)
{
List<Delegate> eventList = GetEventList(evt);
if (eventList != null)
{
foreach (Delegate callback in eventList)
{
try
{
((Action<T1, T2, T3, T4>)callback)(arg1, arg2, arg3, arg4);
}
catch (Exception e)
{
App.log.Error(e.Message);
}
}
}
}
public void PostEvent<T1, T2, T3>(EEvent evt, T1 arg1, T2 arg2, T3 arg3)
{
List<Delegate> eventList = GetEventList(evt);
if (eventList != null)
{
foreach (Delegate callback in eventList)
{
try
{
((Action<T1, T2, T3>)callback)(arg1, arg2, arg3);
}
catch (Exception e)
{
App.log.Error(e.Message);
}
}
}
}
public void PostEvent<T1, T2>(EEvent evt, T1 arg1, T2 arg2)
{
List<Delegate> eventList = GetEventList(evt);
if (eventList != null)
{
foreach (Delegate callback in eventList)
{
try
{
((Action<T1, T2>)callback)(arg1, arg2);
}
catch (Exception e)
{
App.log.Error(e.Message);
}
}
}
}
public void PostEvent<T>(EEvent evt, T arg)
{
List<Delegate> eventList = GetEventList(evt);
if (eventList != null)
{
foreach (Delegate callback in eventList)
{
try
{
((Action<T>)callback)(arg);
}
catch (Exception e)
{
App.log.Error(e.Message + ", method name : " + callback.Method);
}
}
}
}
public void PostEvent(EEvent evt)
{
List<Delegate> eventList = GetEventList(evt);
if (eventList != null)
{
foreach (Delegate callback in eventList)
{
try
{
((Action)callback)();
}
catch (Exception e)
{
App.log.Error(e.Message);
}
}
}
}
#endregion
/// <summary>
/// 获取所有事件
/// </summary>
/// <param name="evt"></param>
/// <returns></returns>
private List<Delegate> GetEventList(EEvent evt)
{
if (eventDic.ContainsKey(evt))
{
List<Delegate> tempList = eventDic[evt];
if (null != tempList)
{
return tempList;
}
}
return null;
}
}
}

View File

@ -1,13 +1,16 @@
using AxibugProtobuf; using AxibugProtobuf;
using System.Net.Sockets; using ClientCore.Common;
using static ClientCore.Event.DelegateClass; using ClientCore.Event;
using static HaoYueNet.ClientNetwork.NetworkHelperCore; using ClientCore.Network;
namespace ClientCore namespace ClientCore.Manager
{ {
public class AppChat public class AppChat
{ {
public event dg_Str_Str OnChatMsg; public AppChat()
{
NetMsg.Instance.RegNetMsgEvent((int)CommandID.CmdChatmsg, RecvChatMsg);
}
public void SendChatMsg(string ChatMsg) public void SendChatMsg(string ChatMsg)
{ {
@ -15,13 +18,13 @@ namespace ClientCore
{ {
ChatMsg = ChatMsg, ChatMsg = ChatMsg,
}; };
App.networkHelper.SendToServer((int)CommandID.CmdChatmsg, NetBase.Serizlize(msg)); App.networkHelper.SendToServer((int)CommandID.CmdChatmsg, ProtoBufHelper.Serizlize(msg));
} }
public void RecvChatMsg(byte[] reqData) public void RecvChatMsg(byte[] reqData)
{ {
Protobuf_ChatMsg_RESP msg = NetBase.DeSerizlize<Protobuf_ChatMsg_RESP>(reqData); Protobuf_ChatMsg_RESP msg = ProtoBufHelper.DeSerizlize<Protobuf_ChatMsg_RESP>(reqData);
OnChatMsg(msg.NickName, msg.ChatMsg); EventSystem.Instance.PostEvent(EEvent.OnChatMsg, msg.NickName, msg.ChatMsg);
} }
} }
} }

View File

@ -1,6 +1,7 @@
using AxibugProtobuf; using AxibugProtobuf;
using ClientCore.Common;
namespace ClientCore namespace ClientCore.Manager
{ {
public class AppLogin public class AppLogin
{ {
@ -11,7 +12,7 @@ namespace ClientCore
LoginType = 0, LoginType = 0,
Account = Account, Account = Account,
}; };
App.networkHelper.SendToServer((int)CommandID.CmdLogin, NetBase.Serizlize(msg)); App.networkHelper.SendToServer((int)CommandID.CmdLogin, ProtoBufHelper.Serizlize(msg));
} }
} }
} }

View File

@ -0,0 +1,20 @@
namespace ClientCore.Manager
{
public class LogManager
{
public void Debug(string str)
{
Console.WriteLine(str);
}
public void Warning(string str)
{
Console.WriteLine(str);
}
public void Error(string str)
{
Console.WriteLine(str);
}
}
}

View File

@ -0,0 +1,90 @@
using AxibugProtobuf;
using ClientCore.Common;
using ClientCore.Event;
using ClientCore.Network;
using System;
using System.Security.Cryptography;
namespace ClientCore.Manager
{
public class UserInfo
{
public long UID;//用户ID
public string NickName;//昵称
public int State;//状态
}
public class UserMgr
{
public Dictionary<long, UserInfo> DictUID2User = new Dictionary<long, UserInfo>();
public UserMgr()
{
NetMsg.Instance.RegNetMsgEvent((int)CommandID.CmdUserOnlinelist, RecvUserOnlinelist);
NetMsg.Instance.RegNetMsgEvent((int)CommandID.CmdUserJoin, RecvCmdUserJoin);
NetMsg.Instance.RegNetMsgEvent((int)CommandID.CmdUserLeave, RecvGetUserLeave);
}
public void RecvUserOnlinelist(byte[] reqData)
{
Protobuf_UserList_RESP msg = ProtoBufHelper.DeSerizlize<Protobuf_UserList_RESP>(reqData);
for(int i = 0;i < msg.UserList.Count;i++)
{
UserMiniInfo mi = msg.UserList[i];
UpdateOrAddUser(mi);
}
}
public void RecvCmdUserJoin(byte[] reqData)
{
Protobuf_UserJoin_RESP msg = ProtoBufHelper.DeSerizlize<Protobuf_UserJoin_RESP>(reqData);
UpdateOrAddUser(msg.UserInfo);
}
public void RecvGetUserLeave(byte[] reqData)
{
Protobuf_UserLeave_RESP msg = ProtoBufHelper.DeSerizlize<Protobuf_UserLeave_RESP>(reqData);
RemoveUser(msg.UID);
}
public void UpdateOrAddUser(UserMiniInfo minfo)
{
lock (DictUID2User)
{
if (!DictUID2User.ContainsKey(minfo.UID))
{
DictUID2User[minfo.UID] = new UserInfo()
{
UID = minfo.UID,
State = minfo.State,
NickName = minfo.NickName,
};
}
else
{
DictUID2User[minfo.UID].State = minfo.State;
DictUID2User[minfo.UID].NickName= minfo.NickName;
}
}
//抛出用户加入事件
EventSystem.Instance.PostEvent(EEvent.UserJoin, minfo.UID);
}
public void RemoveUser(long UID)
{
bool bflag = false;
lock (DictUID2User)
{
if (DictUID2User.ContainsKey(UID))
{
DictUID2User.Remove(UID);
bflag = true;
}
}
if (bflag)
{
//抛出用户离开事件
EventSystem.Instance.PostEvent(EEvent.UserLeave, UID);
}
}
}
}

View File

@ -0,0 +1,94 @@
namespace ClientCore.Network
{
public class NetMsg
{
private static NetMsg instance = new NetMsg();
public static NetMsg Instance { get { return instance; } }
private Dictionary<int, List<Delegate>> netEventDic = new Dictionary<int, List<Delegate>>(128);
private NetMsg() { }
#region RegisterMsgEvent
public void RegNetMsgEvent(int cmd, Action<byte[]> callback)
{
InterRegNetMsgEvent(cmd, callback);
}
private void InterRegNetMsgEvent(int cmd, Delegate callback)
{
if (netEventDic.ContainsKey(cmd))
{
if (netEventDic[cmd].IndexOf(callback) < 0)
{
netEventDic[cmd].Add(callback);
}
}
else
{
netEventDic.Add(cmd, new List<Delegate>() { callback });
}
}
#endregion
#region UnregisterCMD
public void UnregisterCMD(int evt, Action<byte[]> callback)
{
Delegate tempDelegate = callback;
InterUnregisterCMD(evt, tempDelegate);
}
private void InterUnregisterCMD(int cmd, Delegate callback)
{
if (netEventDic.ContainsKey(cmd))
{
netEventDic[cmd].Remove(callback);
if (netEventDic[cmd].Count == 0) netEventDic.Remove(cmd);
}
}
#endregion
#region PostEvent
public void PostNetMsgEvent(int cmd, byte[] arg)
{
List<Delegate> eventList = GetNetEventDicList(cmd);
if (eventList != null)
{
foreach (Delegate callback in eventList)
{
try
{
((Action<byte[]>)callback)(arg);
}
catch (Exception e)
{
App.log.Error(e.Message);
}
}
}
}
#endregion
/// <summary>
/// 获取所有事件
/// </summary>
/// <param name="cmd"></param>
/// <returns></returns>
private List<Delegate> GetNetEventDicList(int cmd)
{
if (netEventDic.ContainsKey(cmd))
{
List<Delegate> tempList = netEventDic[cmd];
if (null != tempList)
{
return tempList;
}
}
return null;
}
}
}

View File

@ -6,7 +6,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace ClientCore namespace ClientCore.Network
{ {
/// <summary> /// <summary>
/// 继承网络库,以支持网络功能 /// 继承网络库,以支持网络功能
@ -55,12 +55,8 @@ namespace ClientCore
NetworkDeBugLog("收到消息 CMDID =>" + CMDID + " ERRCODE =>" + ERRCODE + " 数据长度=>" + data.Length); NetworkDeBugLog("收到消息 CMDID =>" + CMDID + " ERRCODE =>" + ERRCODE + " 数据长度=>" + data.Length);
try try
{ {
//根据协议ID走不同逻辑 //抛出网络数据
switch ((CommandID)CMDID) NetMsg.Instance.PostNetMsgEvent(CMDID, data);
{
case CommandID.CmdLogin: break;
case CommandID.CmdChatmsg: App.chat.RecvChatMsg(data); break;
}
} }
catch (Exception ex) catch (Exception ex)
{ {

View File

@ -33,15 +33,17 @@ namespace AxibugProtobuf {
"dHVzGAQgASgOMiEuQXhpYnVnUHJvdG9idWYuTG9naW5SZXN1bHRTdGF0dXMi", "dHVzGAQgASgOMiEuQXhpYnVnUHJvdG9idWYuTG9naW5SZXN1bHRTdGF0dXMi",
"IwoQUHJvdG9idWZfQ2hhdE1zZxIPCgdDaGF0TXNnGAEgASgJIkgKFVByb3Rv", "IwoQUHJvdG9idWZfQ2hhdE1zZxIPCgdDaGF0TXNnGAEgASgJIkgKFVByb3Rv",
"YnVmX0NoYXRNc2dfUkVTUBIQCghOaWNrTmFtZRgBIAEoCRIPCgdDaGF0TXNn", "YnVmX0NoYXRNc2dfUkVTUBIQCghOaWNrTmFtZRgBIAEoCRIPCgdDaGF0TXNn",
"GAIgASgJEgwKBERhdGUYAyABKAMqPQoJQ29tbWFuZElEEg4KCkNNRF9ERUZB", "GAIgASgJEgwKBERhdGUYAyABKAMqnAEKCUNvbW1hbmRJRBIOCgpDTURfREVG",
"VUwQABIOCglDTURfTE9HSU4Q0Q8SEAoLQ01EX0NIQVRNU0cQoR8qKwoJRXJy", "QVVMEAASDgoJQ01EX0xPR0lOENAPEhAKC0NNRF9DSEFUTVNHEKAfEhgKE0NN",
"b3JDb2RlEhAKDEVSUk9SX0RFRkFVTBAAEgwKCEVSUk9SX09LEAEqPgoJTG9n", "RF9VU0VSX09OTElORUxJU1QQiCcSEgoNQ01EX1VTRVJfSk9JThCnJxITCg5D",
"aW5UeXBlEg8KC0Jhc2VEZWZhdWx0EAASDgoKSGFvWXVlQXV0aBABEgcKA0JG", "TURfVVNFUl9MRUFWRRCoJxIaChVDTURfVVNFUl9TVEFURV9VUERBVEUQqScq",
"MxADEgcKA0JGNBAEKksKCkRldmljZVR5cGUSFgoSRGV2aWNlVHlwZV9EZWZh", "KwoJRXJyb3JDb2RlEhAKDEVSUk9SX0RFRkFVTBAAEgwKCEVSUk9SX09LEAEq",
"dWx0EAASBgoCUEMQARILCgdBbmRyb2lkEAISBwoDSU9TEAMSBwoDUFNWEAQq", "PgoJTG9naW5UeXBlEg8KC0Jhc2VEZWZhdWx0EAASDgoKSGFvWXVlQXV0aBAB",
"TgoRTG9naW5SZXN1bHRTdGF0dXMSIQodTG9naW5SZXN1bHRTdGF0dXNfQmFz", "EgcKA0JGMxADEgcKA0JGNBAEKksKCkRldmljZVR5cGUSFgoSRGV2aWNlVHlw",
"ZURlZmF1bHQQABIGCgJPSxABEg4KCkFjY291bnRFcnIQAkICSAFiBnByb3Rv", "ZV9EZWZhdWx0EAASBgoCUEMQARILCgdBbmRyb2lkEAISBwoDSU9TEAMSBwoD",
"Mw==")); "UFNWEAQqTgoRTG9naW5SZXN1bHRTdGF0dXMSIQodTG9naW5SZXN1bHRTdGF0",
"dXNfQmFzZURlZmF1bHQQABIGCgJPSxABEg4KCkFjY291bnRFcnIQAkICSAFi",
"BnByb3RvMw=="));
descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData, descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData,
new pbr::FileDescriptor[] { }, new pbr::FileDescriptor[] { },
new pbr::GeneratedClrTypeInfo(new[] {typeof(global::AxibugProtobuf.CommandID), typeof(global::AxibugProtobuf.ErrorCode), typeof(global::AxibugProtobuf.LoginType), typeof(global::AxibugProtobuf.DeviceType), typeof(global::AxibugProtobuf.LoginResultStatus), }, null, new pbr::GeneratedClrTypeInfo[] { new pbr::GeneratedClrTypeInfo(new[] {typeof(global::AxibugProtobuf.CommandID), typeof(global::AxibugProtobuf.ErrorCode), typeof(global::AxibugProtobuf.LoginType), typeof(global::AxibugProtobuf.DeviceType), typeof(global::AxibugProtobuf.LoginResultStatus), }, null, new pbr::GeneratedClrTypeInfo[] {
@ -61,13 +63,29 @@ namespace AxibugProtobuf {
/// </summary> /// </summary>
[pbr::OriginalName("CMD_DEFAUL")] CmdDefaul = 0, [pbr::OriginalName("CMD_DEFAUL")] CmdDefaul = 0,
/// <summary> /// <summary>
///登录上行 | 下行 对应 Protobuf_Login | Protobuf_Login_RESP ///登录 上行 | 下行 对应 Protobuf_Login | Protobuf_Login_RESP
/// </summary> /// </summary>
[pbr::OriginalName("CMD_LOGIN")] CmdLogin = 2001, [pbr::OriginalName("CMD_LOGIN")] CmdLogin = 2000,
/// <summary> /// <summary>
///登录上行 | 下行 对应 Protobuf_ChatMsg | Protobuf_ChatMsg_RESP ///聊天 上行 | 下行 对应 Protobuf_ChatMsg | Protobuf_ChatMsg_RESP
/// </summary> /// </summary>
[pbr::OriginalName("CMD_CHATMSG")] CmdChatmsg = 4001, [pbr::OriginalName("CMD_CHATMSG")] CmdChatmsg = 4000,
/// <summary>
///获取在线用户列表 上行 | 下行 对应 Protobuf_UserList | Protobuf_UserList_RESP
/// </summary>
[pbr::OriginalName("CMD_USER_ONLINELIST")] CmdUserOnlinelist = 5000,
/// <summary>
///用户上线 下行 对应 Protobuf_UserOnline_RESP
/// </summary>
[pbr::OriginalName("CMD_USER_JOIN")] CmdUserJoin = 5031,
/// <summary>
///用户下线 下行 对应 Protobuf_UserOffline_RESP
/// </summary>
[pbr::OriginalName("CMD_USER_LEAVE")] CmdUserLeave = 5032,
/// <summary>
///更新在线用户状态 下行 对应 Protobuf_UserState_RESP
/// </summary>
[pbr::OriginalName("CMD_USER_STATE_UPDATE")] CmdUserStateUpdate = 5033,
} }
public enum ErrorCode { public enum ErrorCode {

1595
Protobuf/ProtobufTunnel.cs Normal file

File diff suppressed because it is too large Load Diff

597
Protobuf/ProtobufUDP.cs Normal file
View File

@ -0,0 +1,597 @@
// <auto-generated>
// Generated by the protocol buffer compiler. DO NOT EDIT!
// source: protobuf_UDP.proto
// </auto-generated>
#pragma warning disable 1591, 0612, 3021
#region Designer generated code
using pb = global::Google.Protobuf;
using pbc = global::Google.Protobuf.Collections;
using pbr = global::Google.Protobuf.Reflection;
using scg = global::System.Collections.Generic;
namespace AxibugProtobuf {
/// <summary>Holder for reflection information generated from protobuf_UDP.proto</summary>
public static partial class ProtobufUDPReflection {
#region Descriptor
/// <summary>File descriptor for protobuf_UDP.proto</summary>
public static pbr::FileDescriptor Descriptor {
get { return descriptor; }
}
private static pbr::FileDescriptor descriptor;
static ProtobufUDPReflection() {
byte[] descriptorData = global::System.Convert.FromBase64String(
string.Concat(
"ChJwcm90b2J1Zl9VRFAucHJvdG8SDkF4aWJ1Z1Byb3RvYnVmIisKHFByb3Rv",
"YnVmX1VEUF9UT19TRVJWRVJfSEVMTE8SCwoDVUlEGAEgASgDIjAKIVByb3Rv",
"YnVmX1VEUF9UT19TRVJWRVJfSEVMTE9fUkVTUBILCgNVSUQYASABKAMiJQoW",
"UHJvdG9idWZfVURQX1AyUF9IRUxMTxILCgNVSUQYASABKAMqQAoMVURQQ29t",
"bWFuZElEEhIKDkNNRF9VRFBfREVGQVVMEAASHAoWQ01EX1VEUF9Ub1NlcnZl",
"cl9IRUxMTxCgnAFCAkgBYgZwcm90bzM="));
descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData,
new pbr::FileDescriptor[] { },
new pbr::GeneratedClrTypeInfo(new[] {typeof(global::AxibugProtobuf.UDPCommandID), }, null, new pbr::GeneratedClrTypeInfo[] {
new pbr::GeneratedClrTypeInfo(typeof(global::AxibugProtobuf.Protobuf_UDP_TO_SERVER_HELLO), global::AxibugProtobuf.Protobuf_UDP_TO_SERVER_HELLO.Parser, new[]{ "UID" }, null, null, null, null),
new pbr::GeneratedClrTypeInfo(typeof(global::AxibugProtobuf.Protobuf_UDP_TO_SERVER_HELLO_RESP), global::AxibugProtobuf.Protobuf_UDP_TO_SERVER_HELLO_RESP.Parser, new[]{ "UID" }, null, null, null, null),
new pbr::GeneratedClrTypeInfo(typeof(global::AxibugProtobuf.Protobuf_UDP_P2P_HELLO), global::AxibugProtobuf.Protobuf_UDP_P2P_HELLO.Parser, new[]{ "UID" }, null, null, null, null)
}));
}
#endregion
}
#region Enums
public enum UDPCommandID {
/// <summary>
///缺省不使用
/// </summary>
[pbr::OriginalName("CMD_UDP_DEFAUL")] CmdUdpDefaul = 0,
/// <summary>
///和服务器UDP建立连接 下行 对应 Protobuf_MakeTunnel_RESP
/// </summary>
[pbr::OriginalName("CMD_UDP_ToServer_HELLO")] CmdUdpToServerHello = 20000,
}
#endregion
#region Messages
/// <summary>
///ToServer Hello
/// </summary>
public sealed partial class Protobuf_UDP_TO_SERVER_HELLO : pb::IMessage<Protobuf_UDP_TO_SERVER_HELLO>
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
, pb::IBufferMessage
#endif
{
private static readonly pb::MessageParser<Protobuf_UDP_TO_SERVER_HELLO> _parser = new pb::MessageParser<Protobuf_UDP_TO_SERVER_HELLO>(() => new Protobuf_UDP_TO_SERVER_HELLO());
private pb::UnknownFieldSet _unknownFields;
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public static pb::MessageParser<Protobuf_UDP_TO_SERVER_HELLO> Parser { get { return _parser; } }
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public static pbr::MessageDescriptor Descriptor {
get { return global::AxibugProtobuf.ProtobufUDPReflection.Descriptor.MessageTypes[0]; }
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
pbr::MessageDescriptor pb::IMessage.Descriptor {
get { return Descriptor; }
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public Protobuf_UDP_TO_SERVER_HELLO() {
OnConstruction();
}
partial void OnConstruction();
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public Protobuf_UDP_TO_SERVER_HELLO(Protobuf_UDP_TO_SERVER_HELLO other) : this() {
uID_ = other.uID_;
_unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public Protobuf_UDP_TO_SERVER_HELLO Clone() {
return new Protobuf_UDP_TO_SERVER_HELLO(this);
}
/// <summary>Field number for the "UID" field.</summary>
public const int UIDFieldNumber = 1;
private long uID_;
/// <summary>
///用户ID
/// </summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public long UID {
get { return uID_; }
set {
uID_ = value;
}
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public override bool Equals(object other) {
return Equals(other as Protobuf_UDP_TO_SERVER_HELLO);
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public bool Equals(Protobuf_UDP_TO_SERVER_HELLO other) {
if (ReferenceEquals(other, null)) {
return false;
}
if (ReferenceEquals(other, this)) {
return true;
}
if (UID != other.UID) return false;
return Equals(_unknownFields, other._unknownFields);
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public override int GetHashCode() {
int hash = 1;
if (UID != 0L) hash ^= UID.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 (UID != 0L) {
output.WriteRawTag(8);
output.WriteInt64(UID);
}
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 (UID != 0L) {
output.WriteRawTag(8);
output.WriteInt64(UID);
}
if (_unknownFields != null) {
_unknownFields.WriteTo(ref output);
}
}
#endif
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
int size = 0;
if (UID != 0L) {
size += 1 + pb::CodedOutputStream.ComputeInt64Size(UID);
}
if (_unknownFields != null) {
size += _unknownFields.CalculateSize();
}
return size;
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void MergeFrom(Protobuf_UDP_TO_SERVER_HELLO other) {
if (other == null) {
return;
}
if (other.UID != 0L) {
UID = other.UID;
}
_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: {
UID = input.ReadInt64();
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: {
UID = input.ReadInt64();
break;
}
}
}
}
#endif
}
/// <summary>
///ToServer Hello
/// </summary>
public sealed partial class Protobuf_UDP_TO_SERVER_HELLO_RESP : pb::IMessage<Protobuf_UDP_TO_SERVER_HELLO_RESP>
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
, pb::IBufferMessage
#endif
{
private static readonly pb::MessageParser<Protobuf_UDP_TO_SERVER_HELLO_RESP> _parser = new pb::MessageParser<Protobuf_UDP_TO_SERVER_HELLO_RESP>(() => new Protobuf_UDP_TO_SERVER_HELLO_RESP());
private pb::UnknownFieldSet _unknownFields;
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public static pb::MessageParser<Protobuf_UDP_TO_SERVER_HELLO_RESP> Parser { get { return _parser; } }
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public static pbr::MessageDescriptor Descriptor {
get { return global::AxibugProtobuf.ProtobufUDPReflection.Descriptor.MessageTypes[1]; }
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
pbr::MessageDescriptor pb::IMessage.Descriptor {
get { return Descriptor; }
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public Protobuf_UDP_TO_SERVER_HELLO_RESP() {
OnConstruction();
}
partial void OnConstruction();
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public Protobuf_UDP_TO_SERVER_HELLO_RESP(Protobuf_UDP_TO_SERVER_HELLO_RESP other) : this() {
uID_ = other.uID_;
_unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public Protobuf_UDP_TO_SERVER_HELLO_RESP Clone() {
return new Protobuf_UDP_TO_SERVER_HELLO_RESP(this);
}
/// <summary>Field number for the "UID" field.</summary>
public const int UIDFieldNumber = 1;
private long uID_;
/// <summary>
///用户ID
/// </summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public long UID {
get { return uID_; }
set {
uID_ = value;
}
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public override bool Equals(object other) {
return Equals(other as Protobuf_UDP_TO_SERVER_HELLO_RESP);
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public bool Equals(Protobuf_UDP_TO_SERVER_HELLO_RESP other) {
if (ReferenceEquals(other, null)) {
return false;
}
if (ReferenceEquals(other, this)) {
return true;
}
if (UID != other.UID) return false;
return Equals(_unknownFields, other._unknownFields);
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public override int GetHashCode() {
int hash = 1;
if (UID != 0L) hash ^= UID.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 (UID != 0L) {
output.WriteRawTag(8);
output.WriteInt64(UID);
}
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 (UID != 0L) {
output.WriteRawTag(8);
output.WriteInt64(UID);
}
if (_unknownFields != null) {
_unknownFields.WriteTo(ref output);
}
}
#endif
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
int size = 0;
if (UID != 0L) {
size += 1 + pb::CodedOutputStream.ComputeInt64Size(UID);
}
if (_unknownFields != null) {
size += _unknownFields.CalculateSize();
}
return size;
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void MergeFrom(Protobuf_UDP_TO_SERVER_HELLO_RESP other) {
if (other == null) {
return;
}
if (other.UID != 0L) {
UID = other.UID;
}
_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: {
UID = input.ReadInt64();
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: {
UID = input.ReadInt64();
break;
}
}
}
}
#endif
}
/// <summary>
///P2PHello
/// </summary>
public sealed partial class Protobuf_UDP_P2P_HELLO : pb::IMessage<Protobuf_UDP_P2P_HELLO>
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
, pb::IBufferMessage
#endif
{
private static readonly pb::MessageParser<Protobuf_UDP_P2P_HELLO> _parser = new pb::MessageParser<Protobuf_UDP_P2P_HELLO>(() => new Protobuf_UDP_P2P_HELLO());
private pb::UnknownFieldSet _unknownFields;
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public static pb::MessageParser<Protobuf_UDP_P2P_HELLO> Parser { get { return _parser; } }
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public static pbr::MessageDescriptor Descriptor {
get { return global::AxibugProtobuf.ProtobufUDPReflection.Descriptor.MessageTypes[2]; }
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
pbr::MessageDescriptor pb::IMessage.Descriptor {
get { return Descriptor; }
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public Protobuf_UDP_P2P_HELLO() {
OnConstruction();
}
partial void OnConstruction();
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public Protobuf_UDP_P2P_HELLO(Protobuf_UDP_P2P_HELLO other) : this() {
uID_ = other.uID_;
_unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public Protobuf_UDP_P2P_HELLO Clone() {
return new Protobuf_UDP_P2P_HELLO(this);
}
/// <summary>Field number for the "UID" field.</summary>
public const int UIDFieldNumber = 1;
private long uID_;
/// <summary>
///用户ID
/// </summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public long UID {
get { return uID_; }
set {
uID_ = value;
}
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public override bool Equals(object other) {
return Equals(other as Protobuf_UDP_P2P_HELLO);
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public bool Equals(Protobuf_UDP_P2P_HELLO other) {
if (ReferenceEquals(other, null)) {
return false;
}
if (ReferenceEquals(other, this)) {
return true;
}
if (UID != other.UID) return false;
return Equals(_unknownFields, other._unknownFields);
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public override int GetHashCode() {
int hash = 1;
if (UID != 0L) hash ^= UID.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 (UID != 0L) {
output.WriteRawTag(8);
output.WriteInt64(UID);
}
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 (UID != 0L) {
output.WriteRawTag(8);
output.WriteInt64(UID);
}
if (_unknownFields != null) {
_unknownFields.WriteTo(ref output);
}
}
#endif
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
int size = 0;
if (UID != 0L) {
size += 1 + pb::CodedOutputStream.ComputeInt64Size(UID);
}
if (_unknownFields != null) {
size += _unknownFields.CalculateSize();
}
return size;
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void MergeFrom(Protobuf_UDP_P2P_HELLO other) {
if (other == null) {
return;
}
if (other.UID != 0L) {
UID = other.UID;
}
_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: {
UID = input.ReadInt64();
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: {
UID = input.ReadInt64();
break;
}
}
}
}
#endif
}
#endregion
}
#endregion Designer generated code

View File

@ -33,15 +33,17 @@ namespace AxibugProtobuf {
"dHVzGAQgASgOMiEuQXhpYnVnUHJvdG9idWYuTG9naW5SZXN1bHRTdGF0dXMi", "dHVzGAQgASgOMiEuQXhpYnVnUHJvdG9idWYuTG9naW5SZXN1bHRTdGF0dXMi",
"IwoQUHJvdG9idWZfQ2hhdE1zZxIPCgdDaGF0TXNnGAEgASgJIkgKFVByb3Rv", "IwoQUHJvdG9idWZfQ2hhdE1zZxIPCgdDaGF0TXNnGAEgASgJIkgKFVByb3Rv",
"YnVmX0NoYXRNc2dfUkVTUBIQCghOaWNrTmFtZRgBIAEoCRIPCgdDaGF0TXNn", "YnVmX0NoYXRNc2dfUkVTUBIQCghOaWNrTmFtZRgBIAEoCRIPCgdDaGF0TXNn",
"GAIgASgJEgwKBERhdGUYAyABKAMqPQoJQ29tbWFuZElEEg4KCkNNRF9ERUZB", "GAIgASgJEgwKBERhdGUYAyABKAMqnAEKCUNvbW1hbmRJRBIOCgpDTURfREVG",
"VUwQABIOCglDTURfTE9HSU4Q0Q8SEAoLQ01EX0NIQVRNU0cQoR8qKwoJRXJy", "QVVMEAASDgoJQ01EX0xPR0lOENAPEhAKC0NNRF9DSEFUTVNHEKAfEhgKE0NN",
"b3JDb2RlEhAKDEVSUk9SX0RFRkFVTBAAEgwKCEVSUk9SX09LEAEqPgoJTG9n", "RF9VU0VSX09OTElORUxJU1QQiCcSEgoNQ01EX1VTRVJfSk9JThCnJxITCg5D",
"aW5UeXBlEg8KC0Jhc2VEZWZhdWx0EAASDgoKSGFvWXVlQXV0aBABEgcKA0JG", "TURfVVNFUl9MRUFWRRCoJxIaChVDTURfVVNFUl9TVEFURV9VUERBVEUQqScq",
"MxADEgcKA0JGNBAEKksKCkRldmljZVR5cGUSFgoSRGV2aWNlVHlwZV9EZWZh", "KwoJRXJyb3JDb2RlEhAKDEVSUk9SX0RFRkFVTBAAEgwKCEVSUk9SX09LEAEq",
"dWx0EAASBgoCUEMQARILCgdBbmRyb2lkEAISBwoDSU9TEAMSBwoDUFNWEAQq", "PgoJTG9naW5UeXBlEg8KC0Jhc2VEZWZhdWx0EAASDgoKSGFvWXVlQXV0aBAB",
"TgoRTG9naW5SZXN1bHRTdGF0dXMSIQodTG9naW5SZXN1bHRTdGF0dXNfQmFz", "EgcKA0JGMxADEgcKA0JGNBAEKksKCkRldmljZVR5cGUSFgoSRGV2aWNlVHlw",
"ZURlZmF1bHQQABIGCgJPSxABEg4KCkFjY291bnRFcnIQAkICSAFiBnByb3Rv", "ZV9EZWZhdWx0EAASBgoCUEMQARILCgdBbmRyb2lkEAISBwoDSU9TEAMSBwoD",
"Mw==")); "UFNWEAQqTgoRTG9naW5SZXN1bHRTdGF0dXMSIQodTG9naW5SZXN1bHRTdGF0",
"dXNfQmFzZURlZmF1bHQQABIGCgJPSxABEg4KCkFjY291bnRFcnIQAkICSAFi",
"BnByb3RvMw=="));
descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData, descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData,
new pbr::FileDescriptor[] { }, new pbr::FileDescriptor[] { },
new pbr::GeneratedClrTypeInfo(new[] {typeof(global::AxibugProtobuf.CommandID), typeof(global::AxibugProtobuf.ErrorCode), typeof(global::AxibugProtobuf.LoginType), typeof(global::AxibugProtobuf.DeviceType), typeof(global::AxibugProtobuf.LoginResultStatus), }, null, new pbr::GeneratedClrTypeInfo[] { new pbr::GeneratedClrTypeInfo(new[] {typeof(global::AxibugProtobuf.CommandID), typeof(global::AxibugProtobuf.ErrorCode), typeof(global::AxibugProtobuf.LoginType), typeof(global::AxibugProtobuf.DeviceType), typeof(global::AxibugProtobuf.LoginResultStatus), }, null, new pbr::GeneratedClrTypeInfo[] {
@ -61,13 +63,29 @@ namespace AxibugProtobuf {
/// </summary> /// </summary>
[pbr::OriginalName("CMD_DEFAUL")] CmdDefaul = 0, [pbr::OriginalName("CMD_DEFAUL")] CmdDefaul = 0,
/// <summary> /// <summary>
///登录上行 | 下行 对应 Protobuf_Login | Protobuf_Login_RESP ///登录 上行 | 下行 对应 Protobuf_Login | Protobuf_Login_RESP
/// </summary> /// </summary>
[pbr::OriginalName("CMD_LOGIN")] CmdLogin = 2001, [pbr::OriginalName("CMD_LOGIN")] CmdLogin = 2000,
/// <summary> /// <summary>
///登录上行 | 下行 对应 Protobuf_ChatMsg | Protobuf_ChatMsg_RESP ///聊天 上行 | 下行 对应 Protobuf_ChatMsg | Protobuf_ChatMsg_RESP
/// </summary> /// </summary>
[pbr::OriginalName("CMD_CHATMSG")] CmdChatmsg = 4001, [pbr::OriginalName("CMD_CHATMSG")] CmdChatmsg = 4000,
/// <summary>
///获取在线用户列表 上行 | 下行 对应 Protobuf_UserList | Protobuf_UserList_RESP
/// </summary>
[pbr::OriginalName("CMD_USER_ONLINELIST")] CmdUserOnlinelist = 5000,
/// <summary>
///用户上线 下行 对应 Protobuf_UserOnline_RESP
/// </summary>
[pbr::OriginalName("CMD_USER_JOIN")] CmdUserJoin = 5031,
/// <summary>
///用户下线 下行 对应 Protobuf_UserOffline_RESP
/// </summary>
[pbr::OriginalName("CMD_USER_LEAVE")] CmdUserLeave = 5032,
/// <summary>
///更新在线用户状态 下行 对应 Protobuf_UserState_RESP
/// </summary>
[pbr::OriginalName("CMD_USER_STATE_UPDATE")] CmdUserStateUpdate = 5033,
} }
public enum ErrorCode { public enum ErrorCode {

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,597 @@
// <auto-generated>
// Generated by the protocol buffer compiler. DO NOT EDIT!
// source: protobuf_UDP.proto
// </auto-generated>
#pragma warning disable 1591, 0612, 3021
#region Designer generated code
using pb = global::Google.Protobuf;
using pbc = global::Google.Protobuf.Collections;
using pbr = global::Google.Protobuf.Reflection;
using scg = global::System.Collections.Generic;
namespace AxibugProtobuf {
/// <summary>Holder for reflection information generated from protobuf_UDP.proto</summary>
public static partial class ProtobufUDPReflection {
#region Descriptor
/// <summary>File descriptor for protobuf_UDP.proto</summary>
public static pbr::FileDescriptor Descriptor {
get { return descriptor; }
}
private static pbr::FileDescriptor descriptor;
static ProtobufUDPReflection() {
byte[] descriptorData = global::System.Convert.FromBase64String(
string.Concat(
"ChJwcm90b2J1Zl9VRFAucHJvdG8SDkF4aWJ1Z1Byb3RvYnVmIisKHFByb3Rv",
"YnVmX1VEUF9UT19TRVJWRVJfSEVMTE8SCwoDVUlEGAEgASgDIjAKIVByb3Rv",
"YnVmX1VEUF9UT19TRVJWRVJfSEVMTE9fUkVTUBILCgNVSUQYASABKAMiJQoW",
"UHJvdG9idWZfVURQX1AyUF9IRUxMTxILCgNVSUQYASABKAMqQAoMVURQQ29t",
"bWFuZElEEhIKDkNNRF9VRFBfREVGQVVMEAASHAoWQ01EX1VEUF9Ub1NlcnZl",
"cl9IRUxMTxCgnAFCAkgBYgZwcm90bzM="));
descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData,
new pbr::FileDescriptor[] { },
new pbr::GeneratedClrTypeInfo(new[] {typeof(global::AxibugProtobuf.UDPCommandID), }, null, new pbr::GeneratedClrTypeInfo[] {
new pbr::GeneratedClrTypeInfo(typeof(global::AxibugProtobuf.Protobuf_UDP_TO_SERVER_HELLO), global::AxibugProtobuf.Protobuf_UDP_TO_SERVER_HELLO.Parser, new[]{ "UID" }, null, null, null, null),
new pbr::GeneratedClrTypeInfo(typeof(global::AxibugProtobuf.Protobuf_UDP_TO_SERVER_HELLO_RESP), global::AxibugProtobuf.Protobuf_UDP_TO_SERVER_HELLO_RESP.Parser, new[]{ "UID" }, null, null, null, null),
new pbr::GeneratedClrTypeInfo(typeof(global::AxibugProtobuf.Protobuf_UDP_P2P_HELLO), global::AxibugProtobuf.Protobuf_UDP_P2P_HELLO.Parser, new[]{ "UID" }, null, null, null, null)
}));
}
#endregion
}
#region Enums
public enum UDPCommandID {
/// <summary>
///缺省不使用
/// </summary>
[pbr::OriginalName("CMD_UDP_DEFAUL")] CmdUdpDefaul = 0,
/// <summary>
///和服务器UDP建立连接 下行 对应 Protobuf_MakeTunnel_RESP
/// </summary>
[pbr::OriginalName("CMD_UDP_ToServer_HELLO")] CmdUdpToServerHello = 20000,
}
#endregion
#region Messages
/// <summary>
///ToServer Hello
/// </summary>
public sealed partial class Protobuf_UDP_TO_SERVER_HELLO : pb::IMessage<Protobuf_UDP_TO_SERVER_HELLO>
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
, pb::IBufferMessage
#endif
{
private static readonly pb::MessageParser<Protobuf_UDP_TO_SERVER_HELLO> _parser = new pb::MessageParser<Protobuf_UDP_TO_SERVER_HELLO>(() => new Protobuf_UDP_TO_SERVER_HELLO());
private pb::UnknownFieldSet _unknownFields;
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public static pb::MessageParser<Protobuf_UDP_TO_SERVER_HELLO> Parser { get { return _parser; } }
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public static pbr::MessageDescriptor Descriptor {
get { return global::AxibugProtobuf.ProtobufUDPReflection.Descriptor.MessageTypes[0]; }
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
pbr::MessageDescriptor pb::IMessage.Descriptor {
get { return Descriptor; }
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public Protobuf_UDP_TO_SERVER_HELLO() {
OnConstruction();
}
partial void OnConstruction();
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public Protobuf_UDP_TO_SERVER_HELLO(Protobuf_UDP_TO_SERVER_HELLO other) : this() {
uID_ = other.uID_;
_unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public Protobuf_UDP_TO_SERVER_HELLO Clone() {
return new Protobuf_UDP_TO_SERVER_HELLO(this);
}
/// <summary>Field number for the "UID" field.</summary>
public const int UIDFieldNumber = 1;
private long uID_;
/// <summary>
///用户ID
/// </summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public long UID {
get { return uID_; }
set {
uID_ = value;
}
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public override bool Equals(object other) {
return Equals(other as Protobuf_UDP_TO_SERVER_HELLO);
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public bool Equals(Protobuf_UDP_TO_SERVER_HELLO other) {
if (ReferenceEquals(other, null)) {
return false;
}
if (ReferenceEquals(other, this)) {
return true;
}
if (UID != other.UID) return false;
return Equals(_unknownFields, other._unknownFields);
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public override int GetHashCode() {
int hash = 1;
if (UID != 0L) hash ^= UID.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 (UID != 0L) {
output.WriteRawTag(8);
output.WriteInt64(UID);
}
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 (UID != 0L) {
output.WriteRawTag(8);
output.WriteInt64(UID);
}
if (_unknownFields != null) {
_unknownFields.WriteTo(ref output);
}
}
#endif
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
int size = 0;
if (UID != 0L) {
size += 1 + pb::CodedOutputStream.ComputeInt64Size(UID);
}
if (_unknownFields != null) {
size += _unknownFields.CalculateSize();
}
return size;
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void MergeFrom(Protobuf_UDP_TO_SERVER_HELLO other) {
if (other == null) {
return;
}
if (other.UID != 0L) {
UID = other.UID;
}
_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: {
UID = input.ReadInt64();
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: {
UID = input.ReadInt64();
break;
}
}
}
}
#endif
}
/// <summary>
///ToServer Hello
/// </summary>
public sealed partial class Protobuf_UDP_TO_SERVER_HELLO_RESP : pb::IMessage<Protobuf_UDP_TO_SERVER_HELLO_RESP>
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
, pb::IBufferMessage
#endif
{
private static readonly pb::MessageParser<Protobuf_UDP_TO_SERVER_HELLO_RESP> _parser = new pb::MessageParser<Protobuf_UDP_TO_SERVER_HELLO_RESP>(() => new Protobuf_UDP_TO_SERVER_HELLO_RESP());
private pb::UnknownFieldSet _unknownFields;
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public static pb::MessageParser<Protobuf_UDP_TO_SERVER_HELLO_RESP> Parser { get { return _parser; } }
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public static pbr::MessageDescriptor Descriptor {
get { return global::AxibugProtobuf.ProtobufUDPReflection.Descriptor.MessageTypes[1]; }
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
pbr::MessageDescriptor pb::IMessage.Descriptor {
get { return Descriptor; }
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public Protobuf_UDP_TO_SERVER_HELLO_RESP() {
OnConstruction();
}
partial void OnConstruction();
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public Protobuf_UDP_TO_SERVER_HELLO_RESP(Protobuf_UDP_TO_SERVER_HELLO_RESP other) : this() {
uID_ = other.uID_;
_unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public Protobuf_UDP_TO_SERVER_HELLO_RESP Clone() {
return new Protobuf_UDP_TO_SERVER_HELLO_RESP(this);
}
/// <summary>Field number for the "UID" field.</summary>
public const int UIDFieldNumber = 1;
private long uID_;
/// <summary>
///用户ID
/// </summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public long UID {
get { return uID_; }
set {
uID_ = value;
}
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public override bool Equals(object other) {
return Equals(other as Protobuf_UDP_TO_SERVER_HELLO_RESP);
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public bool Equals(Protobuf_UDP_TO_SERVER_HELLO_RESP other) {
if (ReferenceEquals(other, null)) {
return false;
}
if (ReferenceEquals(other, this)) {
return true;
}
if (UID != other.UID) return false;
return Equals(_unknownFields, other._unknownFields);
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public override int GetHashCode() {
int hash = 1;
if (UID != 0L) hash ^= UID.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 (UID != 0L) {
output.WriteRawTag(8);
output.WriteInt64(UID);
}
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 (UID != 0L) {
output.WriteRawTag(8);
output.WriteInt64(UID);
}
if (_unknownFields != null) {
_unknownFields.WriteTo(ref output);
}
}
#endif
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
int size = 0;
if (UID != 0L) {
size += 1 + pb::CodedOutputStream.ComputeInt64Size(UID);
}
if (_unknownFields != null) {
size += _unknownFields.CalculateSize();
}
return size;
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void MergeFrom(Protobuf_UDP_TO_SERVER_HELLO_RESP other) {
if (other == null) {
return;
}
if (other.UID != 0L) {
UID = other.UID;
}
_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: {
UID = input.ReadInt64();
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: {
UID = input.ReadInt64();
break;
}
}
}
}
#endif
}
/// <summary>
///P2PHello
/// </summary>
public sealed partial class Protobuf_UDP_P2P_HELLO : pb::IMessage<Protobuf_UDP_P2P_HELLO>
#if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE
, pb::IBufferMessage
#endif
{
private static readonly pb::MessageParser<Protobuf_UDP_P2P_HELLO> _parser = new pb::MessageParser<Protobuf_UDP_P2P_HELLO>(() => new Protobuf_UDP_P2P_HELLO());
private pb::UnknownFieldSet _unknownFields;
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public static pb::MessageParser<Protobuf_UDP_P2P_HELLO> Parser { get { return _parser; } }
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public static pbr::MessageDescriptor Descriptor {
get { return global::AxibugProtobuf.ProtobufUDPReflection.Descriptor.MessageTypes[2]; }
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
pbr::MessageDescriptor pb::IMessage.Descriptor {
get { return Descriptor; }
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public Protobuf_UDP_P2P_HELLO() {
OnConstruction();
}
partial void OnConstruction();
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public Protobuf_UDP_P2P_HELLO(Protobuf_UDP_P2P_HELLO other) : this() {
uID_ = other.uID_;
_unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields);
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public Protobuf_UDP_P2P_HELLO Clone() {
return new Protobuf_UDP_P2P_HELLO(this);
}
/// <summary>Field number for the "UID" field.</summary>
public const int UIDFieldNumber = 1;
private long uID_;
/// <summary>
///用户ID
/// </summary>
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public long UID {
get { return uID_; }
set {
uID_ = value;
}
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public override bool Equals(object other) {
return Equals(other as Protobuf_UDP_P2P_HELLO);
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public bool Equals(Protobuf_UDP_P2P_HELLO other) {
if (ReferenceEquals(other, null)) {
return false;
}
if (ReferenceEquals(other, this)) {
return true;
}
if (UID != other.UID) return false;
return Equals(_unknownFields, other._unknownFields);
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public override int GetHashCode() {
int hash = 1;
if (UID != 0L) hash ^= UID.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 (UID != 0L) {
output.WriteRawTag(8);
output.WriteInt64(UID);
}
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 (UID != 0L) {
output.WriteRawTag(8);
output.WriteInt64(UID);
}
if (_unknownFields != null) {
_unknownFields.WriteTo(ref output);
}
}
#endif
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public int CalculateSize() {
int size = 0;
if (UID != 0L) {
size += 1 + pb::CodedOutputStream.ComputeInt64Size(UID);
}
if (_unknownFields != null) {
size += _unknownFields.CalculateSize();
}
return size;
}
[global::System.Diagnostics.DebuggerNonUserCodeAttribute]
public void MergeFrom(Protobuf_UDP_P2P_HELLO other) {
if (other == null) {
return;
}
if (other.UID != 0L) {
UID = other.UID;
}
_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: {
UID = input.ReadInt64();
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: {
UID = input.ReadInt64();
break;
}
}
}
}
#endif
}
#endregion
}
#endregion Designer generated code

View File

@ -6,9 +6,18 @@ enum CommandID
{ {
CMD_DEFAUL = 0;//使 CMD_DEFAUL = 0;//使
CMD_LOGIN = 2001; // | Protobuf_Login | Protobuf_Login_RESP CMD_LOGIN = 2000; // | Protobuf_Login | Protobuf_Login_RESP
CMD_CHATMSG = 4001; // | Protobuf_ChatMsg | Protobuf_ChatMsg_RESP CMD_CHATMSG = 4000; // | Protobuf_ChatMsg | Protobuf_ChatMsg_RESP
CMD_USER_ONLINELIST = 5000; //线 | Protobuf_UserList | Protobuf_UserList_RESP
CMD_USER_JOIN = 5031; //线 Protobuf_UserOnline_RESP
CMD_USER_LEAVE = 5032; //线 Protobuf_UserOffline_RESP
CMD_USER_STATE_UPDATE = 5033; //线 Protobuf_UserState_RESP
//CMD_TUNNEL_UDPSERVER_INFO = 6000; //UDP服务器信息 | Protobuf_UDPServer_Info | Protobuf_UDPServer_Info_RESP
//CMD_TUNNEL_2Server_OK = 6001; //UDP建立连接 Protobuf_MakeTunnel_RESP
//CMD_TUNNEL_MAKE = 6002; // | Protobuf_MakeTunnel | Protobuf_MakeTunnel_RESP
} }
enum ErrorCode enum ErrorCode

View File

@ -0,0 +1,56 @@
syntax = "proto3";
package AxibugProtobuf;
option optimize_for = SPEED;
//线
message Protobuf_UserList
{
}
//线
message Protobuf_UserList_RESP
{
int32 UserCount = 1;//
repeated UserMiniInfo UserList = 2;//
}
//线
message Protobuf_UserJoin_RESP
{
UserMiniInfo UserInfo = 1;//
}
//线
message Protobuf_UserLeave_RESP
{
int64 UID = 1;//ID
}
//线
message Protobuf_UserState_RESP
{
int64 UID = 1;//ID
int32 State = 2;//
}
message UserMiniInfo
{
int64 UID = 1;//ID
string NickName = 2;//
int32 State = 3;//
}
////////////////////
//UDP服务器信息
message Protobuf_UDPServer_Info
{
}
//UDP服务器信息
message Protobuf_UDPServer_Info_RESP
{
string UDPSev_IP = 1;//UDP服务器IP
int32 UDPSev_Port = 2;//UDP服务器端口
}

View File

@ -0,0 +1,27 @@
syntax = "proto3";
package AxibugProtobuf;
option optimize_for = SPEED;
enum UDPCommandID
{
CMD_UDP_DEFAUL = 0;//使
CMD_UDP_ToServer_HELLO = 20000; //UDP建立连接 Protobuf_MakeTunnel_RESP
}
//ToServer Hello
message Protobuf_UDP_TO_SERVER_HELLO
{
int64 UID = 1;//ID
}
//ToServer Hello
message Protobuf_UDP_TO_SERVER_HELLO_RESP
{
int64 UID = 1;//ID
}
//P2PHello
message Protobuf_UDP_P2P_HELLO
{
int64 UID = 1;//ID
}

View File

@ -1,4 +1,4 @@
using ServerCore; using ServerCore.Manager;
ServerManager.InitServer(23846); ServerManager.InitServer(23846);
@ -10,7 +10,7 @@ while (true)
switch (Command) switch (Command)
{ {
case "list": case "list":
Console.WriteLine("当前在线:" + ServerManager.g_ClientMgr.GetOnlineClient()); Console.WriteLine("当前在线:" + ServerManager.g_ClientMgr.GetOnlineClientCount());
break; break;
default: default:
Console.WriteLine("未知命令" + CommandStr); Console.WriteLine("未知命令" + CommandStr);

View File

@ -1,9 +1,10 @@
using Google.Protobuf; using Google.Protobuf;
namespace ClientCore namespace ServerCore.Common
{ {
public static class NetBase public static class ProtoBufHelper
{ {
public static byte[] Serizlize(IMessage msg) public static byte[] Serizlize(IMessage msg)
{ {
return msg.ToByteArray(); return msg.ToByteArray();

View File

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ServerCore.Event
{
public enum EEvent
{
// 添加你自己需要的事件类型
OnUserJoin,
OnUserLeave
}
}

View File

@ -0,0 +1,222 @@
using ServerCore.Manager;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ServerCore.Event
{
public class EventSystem
{
private static EventSystem instance = new EventSystem();
public static EventSystem Instance { get { return instance; } }
private Dictionary<EEvent, List<Delegate>> eventDic = new Dictionary<EEvent, List<Delegate>>(128);
private EventSystem() { }
#region RegisterEvent
public void RegisterEvent(EEvent evt, Action callback)
{
InterRegisterEvent(evt, callback);
}
public void RegisterEvent<T1>(EEvent evt, Action<T1> callback)
{
InterRegisterEvent(evt, callback);
}
public void RegisterEvent<T1, T2>(EEvent evt, Action<T1, T2> callback)
{
InterRegisterEvent(evt, callback);
}
public void RegisterEvent<T1, T2, T3>(EEvent evt, Action<T1, T2, T3> callback)
{
InterRegisterEvent(evt, callback);
}
public void RegisterEvent<T1, T2, T3, T4>(EEvent evt, Action<T1, T2, T3, T4> callback)
{
InterRegisterEvent(evt, callback);
}
private void InterRegisterEvent(EEvent evt, Delegate callback)
{
if (eventDic.ContainsKey(evt))
{
if (eventDic[evt].IndexOf(callback) < 0)
{
eventDic[evt].Add(callback);
}
}
else
{
eventDic.Add(evt, new List<Delegate>() { callback });
}
}
#endregion
#region UnregisterEvent
public void UnregisterEvent(EEvent evt, Action callback)
{
Delegate tempDelegate = callback;
InterUnregisterEvent(evt, tempDelegate);
}
public void UnregisterEvent<T1>(EEvent evt, Action<T1> callback)
{
Delegate tempDelegate = callback;
InterUnregisterEvent(evt, tempDelegate);
}
public void UnregisterEvent<T1, T2>(EEvent evt, Action<T1, T2> callback)
{
Delegate tempDelegate = callback;
InterUnregisterEvent(evt, tempDelegate);
}
public void UnregisterEvent<T1, T2, T3>(EEvent evt, Action<T1, T2, T3> callback)
{
Delegate tempDelegate = callback;
InterUnregisterEvent(evt, tempDelegate);
}
public void UnregisterEvent<T1, T2, T3, T4>(EEvent evt, Action<T1, T2, T3, T4> callback)
{
Delegate tempDelegate = callback;
InterUnregisterEvent(evt, tempDelegate);
}
private void InterUnregisterEvent(EEvent evt, Delegate callback)
{
if (eventDic.ContainsKey(evt))
{
eventDic[evt].Remove(callback);
if (eventDic[evt].Count == 0) eventDic.Remove(evt);
}
}
#endregion
#region PostEvent
public void PostEvent<T1, T2, T3, T4>(EEvent evt, T1 arg1, T2 arg2, T3 arg3, T4 arg4)
{
List<Delegate> eventList = GetEventList(evt);
if (eventList != null)
{
foreach (Delegate callback in eventList)
{
try
{
((Action<T1, T2, T3, T4>)callback)(arg1, arg2, arg3, arg4);
}
catch (Exception e)
{
ServerManager.g_Log.Error(e.Message);
}
}
}
}
public void PostEvent<T1, T2, T3>(EEvent evt, T1 arg1, T2 arg2, T3 arg3)
{
List<Delegate> eventList = GetEventList(evt);
if (eventList != null)
{
foreach (Delegate callback in eventList)
{
try
{
((Action<T1, T2, T3>)callback)(arg1, arg2, arg3);
}
catch (Exception e)
{
ServerManager.g_Log.Error(e.Message);
}
}
}
}
public void PostEvent<T1, T2>(EEvent evt, T1 arg1, T2 arg2)
{
List<Delegate> eventList = GetEventList(evt);
if (eventList != null)
{
foreach (Delegate callback in eventList)
{
try
{
((Action<T1, T2>)callback)(arg1, arg2);
}
catch (Exception e)
{
ServerManager.g_Log.Error(e.Message);
}
}
}
}
public void PostEvent<T>(EEvent evt, T arg)
{
List<Delegate> eventList = GetEventList(evt);
if (eventList != null)
{
foreach (Delegate callback in eventList)
{
try
{
((Action<T>)callback)(arg);
}
catch (Exception e)
{
ServerManager.g_Log.Error(e.Message + ", method name : " + callback.Method);
}
}
}
}
public void PostEvent(EEvent evt)
{
List<Delegate> eventList = GetEventList(evt);
if (eventList != null)
{
foreach (Delegate callback in eventList)
{
try
{
((Action)callback)();
}
catch (Exception e)
{
ServerManager.g_Log.Error(e.Message);
}
}
}
}
#endregion
/// <summary>
/// 获取所有事件
/// </summary>
/// <param name="evt"></param>
/// <returns></returns>
private List<Delegate> GetEventList(EEvent evt)
{
if (eventDic.ContainsKey(evt))
{
List<Delegate> tempList = eventDic[evt];
if (null != tempList)
{
return tempList;
}
}
return null;
}
}
}

View File

@ -1,20 +1,26 @@
using AxibugProtobuf; using AxibugProtobuf;
using ServerCore.Common; using ServerCore.Common;
using ServerCore.NetWork;
using System.Net.Sockets; using System.Net.Sockets;
namespace ServerCore namespace ServerCore.Manager
{ {
public class ChatManager public class ChatManager
{ {
public ChatManager()
{
NetMsg.Instance.RegNetMsgEvent((int)CommandID.CmdChatmsg, RecvPlayerChatMsg);
}
public void RecvPlayerChatMsg(Socket sk, byte[] reqData) public void RecvPlayerChatMsg(Socket sk, byte[] reqData)
{ {
ClientInfo _c = ServerManager.g_ClientMgr.GetClientForSocket(sk); ClientInfo _c = ServerManager.g_ClientMgr.GetClientForSocket(sk);
ServerManager.g_Log.Debug("收到新的登录请求"); ServerManager.g_Log.Debug("收到新的登录请求");
Protobuf_ChatMsg msg = NetBase.DeSerizlize<Protobuf_ChatMsg>(reqData); Protobuf_ChatMsg msg = ProtoBufHelper.DeSerizlize<Protobuf_ChatMsg>(reqData);
byte[] respData = NetBase.Serizlize(new Protobuf_ChatMsg_RESP() byte[] respData = ProtoBufHelper.Serizlize(new Protobuf_ChatMsg_RESP()
{ {
ChatMsg = msg.ChatMsg, ChatMsg = msg.ChatMsg,
NickName = _c.Account, NickName = _c.NickName,
Date = Helper.GetNowTimeStamp() Date = Helper.GetNowTimeStamp()
}); });
ServerManager.g_ClientMgr.ClientSendALL((int)CommandID.CmdChatmsg, (int)ErrorCode.ErrorOk, respData); ServerManager.g_ClientMgr.ClientSendALL((int)CommandID.CmdChatmsg, (int)ErrorCode.ErrorOk, respData);

View File

@ -1,27 +1,36 @@
using AxibugProtobuf; using AxibugProtobuf;
using ServerCore.Event;
using System.Net.Sockets; using System.Net.Sockets;
using System.Timers; using System.Timers;
namespace ServerCore namespace ServerCore.Manager
{ {
public class ClientInfo public class ClientInfo
{ {
public long UID { get; set; } public long UID { get; set; }
public string Account { get; set; } public string NickName { get; set; }
public Socket _socket { get; set; } public Socket _socket { get; set; }
public bool IsOffline { get; set; } = false; public bool IsOffline { get; set; } = false;
public DateTime LogOutDT { get; set; } public DateTime LogOutDT { get; set; }
public int State { get; set; } = 0;
} }
public class ClientManager public class ClientManager
{ {
private List<ClientInfo> ClientList = new List<ClientInfo>(); private List<ClientInfo> ClientList = new List<ClientInfo>();
private Dictionary<Socket, ClientInfo> _DictSocketClient = new Dictionary<Socket, ClientInfo>(); private Dictionary<Socket, ClientInfo> _DictSocketClient = new Dictionary<Socket, ClientInfo>();
private Dictionary<long?, ClientInfo> _DictUIDClient = new Dictionary<long?, ClientInfo>(); private Dictionary<long, ClientInfo> _DictUIDClient = new Dictionary<long, ClientInfo>();
private long TestUIDSeed = 0; private long TestUIDSeed = 0;
private System.Timers.Timer _ClientCheckTimer; private System.Timers.Timer _ClientCheckTimer;
private long _RemoveOfflineCacheMin; private long _RemoveOfflineCacheMin;
#region
#endregion
public void Init(long ticktime, long RemoveOfflineCacheMin) public void Init(long ticktime, long RemoveOfflineCacheMin)
{ {
//换算成毫秒 //换算成毫秒
@ -38,7 +47,7 @@ namespace ServerCore
return ++TestUIDSeed; return ++TestUIDSeed;
} }
private void ClientCheckClearOffline_Elapsed(object sender, System.Timers.ElapsedEventArgs e) private void ClientCheckClearOffline_Elapsed(object sender, ElapsedEventArgs e)
{ {
DateTime CheckDT = DateTime.Now.AddMinutes(-1 * _RemoveOfflineCacheMin); DateTime CheckDT = DateTime.Now.AddMinutes(-1 * _RemoveOfflineCacheMin);
ClientInfo[] OfflineClientlist = ClientList.Where(w => w.IsOffline == true && w.LogOutDT < CheckDT).ToArray(); ClientInfo[] OfflineClientlist = ClientList.Where(w => w.IsOffline == true && w.LogOutDT < CheckDT).ToArray();
@ -72,11 +81,12 @@ namespace ServerCore
{ {
UID = GetNextUID(), UID = GetNextUID(),
_socket = _socket, _socket = _socket,
Account = data.Account, NickName = data.Account,
IsOffline = false, IsOffline = false,
}; };
AddClient(cinfo); AddClient(cinfo);
} }
EventSystem.Instance.PostEvent(EEvent.OnUserJoin, cinfo.UID);
return cinfo; return cinfo;
} }
@ -88,7 +98,7 @@ namespace ServerCore
{ {
try try
{ {
Console.WriteLine("追加连接玩家 UID=>" + clientInfo.UID + " | " + clientInfo.Account); Console.WriteLine("追加连接玩家 UID=>" + clientInfo.UID + " | " + clientInfo.NickName);
lock (ClientList) lock (ClientList)
{ {
_DictUIDClient.Add(clientInfo.UID, clientInfo); _DictUIDClient.Add(clientInfo.UID, clientInfo);
@ -120,6 +130,10 @@ namespace ServerCore
} }
} }
public ClientInfo GetClientForUID(long UID)
{
return _DictUIDClient.ContainsKey(UID) ? _DictUIDClient[UID] : null;
}
public ClientInfo GetClientForSocket(Socket sk) public ClientInfo GetClientForSocket(Socket sk)
{ {
@ -130,9 +144,9 @@ namespace ServerCore
/// 获取在线玩家 /// 获取在线玩家
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
public List<ClientInfo> GetOnlineClientList() public ClientInfo[] GetOnlineClientList()
{ {
return ClientList.Where(w => w.IsOffline == false).ToList(); return ClientList.Where(w => w.IsOffline == false).ToArray();
} }
@ -148,6 +162,7 @@ namespace ServerCore
Console.WriteLine("标记玩家UID" + _DictSocketClient[sk].UID + "为离线"); Console.WriteLine("标记玩家UID" + _DictSocketClient[sk].UID + "为离线");
_DictSocketClient[sk].IsOffline = true; _DictSocketClient[sk].IsOffline = true;
_DictSocketClient[sk].LogOutDT = DateTime.Now; _DictSocketClient[sk].LogOutDT = DateTime.Now;
EventSystem.Instance.PostEvent(EEvent.OnUserLeave, _DictSocketClient[sk].UID);
} }
public void RemoveClientForSocket(Socket sk) public void RemoveClientForSocket(Socket sk)
@ -162,7 +177,7 @@ namespace ServerCore
public void ClientSendALL(int CMDID, int ERRCODE, byte[] data) public void ClientSendALL(int CMDID, int ERRCODE, byte[] data)
{ {
ClientSend(ClientList,CMDID, ERRCODE, data); ClientSend(ClientList, CMDID, ERRCODE, data);
} }
/// <summary> /// <summary>
@ -174,11 +189,11 @@ namespace ServerCore
/// <param name="data"></param> /// <param name="data"></param>
public void ClientSend(List<ClientInfo> _toclientlist, int CMDID, int ERRCODE, byte[] data) public void ClientSend(List<ClientInfo> _toclientlist, int CMDID, int ERRCODE, byte[] data)
{ {
for (int i = 0; i < _toclientlist.Count();i++) for (int i = 0; i < _toclientlist.Count(); i++)
{ {
if (_toclientlist[i] == null || _toclientlist[i].IsOffline) if (_toclientlist[i] == null || _toclientlist[i].IsOffline)
continue; continue;
ServerManager.g_SocketMgr.SendToSocket(_toclientlist[i]._socket, CMDID,ERRCODE,data); ServerManager.g_SocketMgr.SendToSocket(_toclientlist[i]._socket, CMDID, ERRCODE, data);
} }
} }
@ -202,7 +217,7 @@ namespace ServerCore
ServerManager.g_SocketMgr.SendToSocket(_c._socket, CMDID, ERRCODE, data); ServerManager.g_SocketMgr.SendToSocket(_c._socket, CMDID, ERRCODE, data);
} }
public int GetOnlineClient() public int GetOnlineClientCount()
{ {
return ClientList.Where(w => !w.IsOffline).Count(); return ClientList.Where(w => !w.IsOffline).Count();
} }

View File

@ -1,4 +1,4 @@
namespace ServerCore namespace ServerCore.Manager
{ {
public class LogManager public class LogManager
{ {

View File

@ -1,17 +1,24 @@
using AxibugProtobuf; using AxibugProtobuf;
using ServerCore.Common;
using ServerCore.NetWork;
using System.Net.Sockets; using System.Net.Sockets;
namespace ServerCore namespace ServerCore.Manager
{ {
public class LoginManager public class LoginManager
{ {
public void UserLogin(Socket _socket,byte[] reqData) public LoginManager()
{
NetMsg.Instance.RegNetMsgEvent((int)CommandID.CmdLogin, UserLogin);
}
public void UserLogin(Socket _socket, byte[] reqData)
{ {
ServerManager.g_Log.Debug("收到新的登录请求"); ServerManager.g_Log.Debug("收到新的登录请求");
Protobuf_Login msg = NetBase.DeSerizlize<Protobuf_Login>(reqData); Protobuf_Login msg = ProtoBufHelper.DeSerizlize<Protobuf_Login>(reqData);
ClientInfo cinfo = ServerManager.g_ClientMgr.JoinNewClient(msg,_socket); ClientInfo cinfo = ServerManager.g_ClientMgr.JoinNewClient(msg, _socket);
byte[] respData = NetBase.Serizlize(new Protobuf_Login_RESP() byte[] respData = ProtoBufHelper.Serizlize(new Protobuf_Login_RESP()
{ {
Status = LoginResultStatus.Ok, Status = LoginResultStatus.Ok,
RegDate = "", RegDate = "",
@ -19,7 +26,7 @@ namespace ServerCore
Token = "" Token = ""
}); });
ServerManager.g_ClientMgr.ClientSend(cinfo,(int)CommandID.CmdLogin,(int)ErrorCode.ErrorOk,respData); ServerManager.g_ClientMgr.ClientSend(cinfo, (int)CommandID.CmdLogin, (int)ErrorCode.ErrorOk, respData);
} }
} }
} }

View File

@ -0,0 +1,88 @@
using AxibugProtobuf;
using Google.Protobuf;
using ServerCore.Common;
using ServerCore.Event;
using ServerCore.NetWork;
using System.Diagnostics;
using System.Net.Sockets;
using System.Timers;
namespace ServerCore.Manager
{
public class P2PUserManager
{
public P2PUserManager()
{
NetMsg.Instance.RegNetMsgEvent((int)CommandID.CmdUserOnlinelist, RecvGetUserList);
//事件
EventSystem.Instance.RegisterEvent<long>(EEvent.OnUserJoin, OnUserJoin);
EventSystem.Instance.RegisterEvent<long>(EEvent.OnUserLeave, OnUserLeave);
}
#region
void OnUserJoin(long UID)
{
ServerManager.g_Log.Debug($"P2PUserManager->OnUserJoin UID->{UID}");
SendUserJoin(UID);
}
void OnUserLeave(long UID)
{
ServerManager.g_Log.Debug($"P2PUserManager->OnUserLeave UID->{UID}");
SendUserLeave(UID);
}
#endregion
public void RecvGetUserList(Socket _socket, byte[] reqData)
{
Protobuf_UserList msg = ProtoBufHelper.DeSerizlize<Protobuf_UserList>(reqData);
ClientInfo _c = ServerManager.g_ClientMgr.GetClientForSocket(_socket);
Protobuf_UserList_RESP respData = new Protobuf_UserList_RESP();
ClientInfo[] cArr = ServerManager.g_ClientMgr.GetOnlineClientList();
respData.UserCount = cArr.Length;
for (int i = 0; i < cArr.Length; i++)
{
ClientInfo client = cArr[i];
respData.UserList.Add(new UserMiniInfo()
{
State = client.State,
NickName = client.NickName,
UID = client.UID,
});
}
ServerManager.g_Log.Debug($"拉取用户列表->{respData.UserCount}个用户");
ServerManager.g_ClientMgr.ClientSend(_c, (int)CommandID.CmdUserOnlinelist, (int)ErrorCode.ErrorOk, ProtoBufHelper.Serizlize(respData));
}
public void SendUserJoin(long UID)
{
ClientInfo _c = ServerManager.g_ClientMgr.GetClientForUID(UID);
if (_c == null)
return;
Protobuf_UserJoin_RESP resp = new Protobuf_UserJoin_RESP()
{
UserInfo = new UserMiniInfo()
{
State = _c.State,
NickName = _c.NickName,
UID = _c.UID,
}
};
ServerManager.g_ClientMgr.ClientSendALL((int)CommandID.CmdUserJoin, (int)ErrorCode.ErrorOk, ProtoBufHelper.Serizlize(resp));
}
public void SendUserLeave(long UID)
{
Protobuf_UserLeave_RESP resp = new Protobuf_UserLeave_RESP()
{
UID = UID,
};
ServerManager.g_ClientMgr.ClientSendALL((int)CommandID.CmdUserLeave, (int)ErrorCode.ErrorOk, ProtoBufHelper.Serizlize(resp));
}
}
}

View File

@ -1,6 +1,8 @@
using System.Net; using ServerCore.Event;
using ServerCore.NetWork;
using System.Net;
namespace ServerCore namespace ServerCore.Manager
{ {
public static class ServerManager public static class ServerManager
{ {
@ -8,6 +10,7 @@ namespace ServerCore
public static LogManager g_Log; public static LogManager g_Log;
public static LoginManager g_Login; public static LoginManager g_Login;
public static ChatManager g_Chat; public static ChatManager g_Chat;
public static P2PUserManager g_P2PMgr;
public static IOCPNetWork g_SocketMgr; public static IOCPNetWork g_SocketMgr;
public static void InitServer(int port) public static void InitServer(int port)
@ -16,6 +19,7 @@ namespace ServerCore
g_Log = new LogManager(); g_Log = new LogManager();
g_Login = new LoginManager(); g_Login = new LoginManager();
g_Chat = new ChatManager(); g_Chat = new ChatManager();
g_P2PMgr = new P2PUserManager();
g_SocketMgr = new IOCPNetWork(1024, 1024); g_SocketMgr = new IOCPNetWork(1024, 1024);
g_SocketMgr.Init(); g_SocketMgr.Init();
g_SocketMgr.Start(new IPEndPoint(IPAddress.Any.Address, port)); g_SocketMgr.Start(new IPEndPoint(IPAddress.Any.Address, port));

View File

@ -1,8 +1,9 @@
using AxibugProtobuf; using AxibugProtobuf;
using HaoYueNet.ServerNetwork; using HaoYueNet.ServerNetwork;
using ServerCore.Manager;
using System.Net.Sockets; using System.Net.Sockets;
namespace ServerCore namespace ServerCore.NetWork
{ {
public class IOCPNetWork : SocketManager public class IOCPNetWork : SocketManager
{ {
@ -45,11 +46,8 @@ namespace ServerCore
ServerManager.g_Log.Debug("收到消息 CMDID =>" + CMDID + " 数据长度=>" + data.Length); ServerManager.g_Log.Debug("收到消息 CMDID =>" + CMDID + " 数据长度=>" + data.Length);
try try
{ {
switch ((CommandID)CMDID) //抛出网络数据
{ NetMsg.Instance.PostNetMsgEvent(CMDID, sk, data);
case CommandID.CmdLogin: ServerManager.g_Login.UserLogin(sk, data); break;
case CommandID.CmdChatmsg: ServerManager.g_Chat.RecvPlayerChatMsg(sk, data);break;
}
} }
catch (Exception ex) catch (Exception ex)
{ {

View File

@ -0,0 +1,103 @@
using ServerCore.Manager;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;
namespace ServerCore.NetWork
{
public class NetMsg
{
private static NetMsg instance = new NetMsg();
public static NetMsg Instance { get { return instance; } }
private Dictionary<int, List<Delegate>> netEventDic = new Dictionary<int, List<Delegate>>(128);
private NetMsg() { }
#region RegisterMsgEvent
public void RegNetMsgEvent(int cmd, Action<Socket, byte[]> callback)
{
InterRegNetMsgEvent(cmd, callback);
}
private void InterRegNetMsgEvent(int cmd, Delegate callback)
{
if (netEventDic.ContainsKey(cmd))
{
if (netEventDic[cmd].IndexOf(callback) < 0)
{
netEventDic[cmd].Add(callback);
}
}
else
{
netEventDic.Add(cmd, new List<Delegate>() { callback });
}
}
#endregion
#region UnregisterCMD
public void UnregisterCMD(int cmd, Action<Socket, byte[]> callback)
{
Delegate tempDelegate = callback;
InterUnregisterCMD(cmd, tempDelegate);
}
private void InterUnregisterCMD(int cmd, Delegate callback)
{
if (netEventDic.ContainsKey(cmd))
{
netEventDic[cmd].Remove(callback);
if (netEventDic[cmd].Count == 0) netEventDic.Remove(cmd);
}
}
#endregion
#region PostEvent
public void PostNetMsgEvent(int cmd, Socket arg1, byte[] arg2)
{
List<Delegate> eventList = GetNetEventDicList(cmd);
if (eventList != null)
{
foreach (Delegate callback in eventList)
{
try
{
((Action<Socket, byte[]>)callback)(arg1, arg2);
}
catch (Exception e)
{
ServerManager.g_Log.Error(e.Message);
}
}
}
}
#endregion
/// <summary>
/// 获取所有事件
/// </summary>
/// <param name="cmd"></param>
/// <returns></returns>
private List<Delegate> GetNetEventDicList(int cmd)
{
if (netEventDic.ContainsKey(cmd))
{
List<Delegate> tempList = netEventDic[cmd];
if (null != tempList)
{
return tempList;
}
}
return null;
}
}
}