diff --git a/.vs/HaoYueTunnel/DesignTimeBuild/.dtbcache.v2 b/.vs/HaoYueTunnel/DesignTimeBuild/.dtbcache.v2 index 701d70f..1a45616 100644 Binary files a/.vs/HaoYueTunnel/DesignTimeBuild/.dtbcache.v2 and b/.vs/HaoYueTunnel/DesignTimeBuild/.dtbcache.v2 differ diff --git a/.vs/HaoYueTunnel/FileContentIndex/0a4428b4-ee9a-43ba-8191-f076b1e55819.vsidx b/.vs/HaoYueTunnel/FileContentIndex/0a4428b4-ee9a-43ba-8191-f076b1e55819.vsidx deleted file mode 100644 index 1dc44e3..0000000 Binary files a/.vs/HaoYueTunnel/FileContentIndex/0a4428b4-ee9a-43ba-8191-f076b1e55819.vsidx and /dev/null differ diff --git a/.vs/HaoYueTunnel/FileContentIndex/0bb77ab0-dd88-4efe-9fca-4316002cece6.vsidx b/.vs/HaoYueTunnel/FileContentIndex/0bb77ab0-dd88-4efe-9fca-4316002cece6.vsidx deleted file mode 100644 index 81e9c26..0000000 Binary files a/.vs/HaoYueTunnel/FileContentIndex/0bb77ab0-dd88-4efe-9fca-4316002cece6.vsidx and /dev/null differ diff --git a/.vs/HaoYueTunnel/FileContentIndex/442de58a-c9d4-4609-9d0d-66c6235e3430.vsidx b/.vs/HaoYueTunnel/FileContentIndex/442de58a-c9d4-4609-9d0d-66c6235e3430.vsidx new file mode 100644 index 0000000..b66784d Binary files /dev/null and b/.vs/HaoYueTunnel/FileContentIndex/442de58a-c9d4-4609-9d0d-66c6235e3430.vsidx differ diff --git a/.vs/HaoYueTunnel/FileContentIndex/4a56e640-2dbd-4fe3-9539-17f589dd9d88.vsidx b/.vs/HaoYueTunnel/FileContentIndex/4a56e640-2dbd-4fe3-9539-17f589dd9d88.vsidx new file mode 100644 index 0000000..346be33 Binary files /dev/null and b/.vs/HaoYueTunnel/FileContentIndex/4a56e640-2dbd-4fe3-9539-17f589dd9d88.vsidx differ diff --git a/.vs/HaoYueTunnel/FileContentIndex/51c343b2-77d6-48c8-821e-55e1845b6807.vsidx b/.vs/HaoYueTunnel/FileContentIndex/51c343b2-77d6-48c8-821e-55e1845b6807.vsidx new file mode 100644 index 0000000..7891078 Binary files /dev/null and b/.vs/HaoYueTunnel/FileContentIndex/51c343b2-77d6-48c8-821e-55e1845b6807.vsidx differ diff --git a/.vs/HaoYueTunnel/FileContentIndex/74ef9a83-47c0-4c94-bc53-97852d1c488c.vsidx b/.vs/HaoYueTunnel/FileContentIndex/74ef9a83-47c0-4c94-bc53-97852d1c488c.vsidx deleted file mode 100644 index 286130e..0000000 Binary files a/.vs/HaoYueTunnel/FileContentIndex/74ef9a83-47c0-4c94-bc53-97852d1c488c.vsidx and /dev/null differ diff --git a/.vs/HaoYueTunnel/FileContentIndex/810b85e7-530a-466e-a571-647e20d64794.vsidx b/.vs/HaoYueTunnel/FileContentIndex/810b85e7-530a-466e-a571-647e20d64794.vsidx deleted file mode 100644 index 08e7240..0000000 Binary files a/.vs/HaoYueTunnel/FileContentIndex/810b85e7-530a-466e-a571-647e20d64794.vsidx and /dev/null differ diff --git a/.vs/HaoYueTunnel/FileContentIndex/8724dabf-7aa7-42a1-8f9f-bd24ede189e3.vsidx b/.vs/HaoYueTunnel/FileContentIndex/8724dabf-7aa7-42a1-8f9f-bd24ede189e3.vsidx new file mode 100644 index 0000000..0a7e546 Binary files /dev/null and b/.vs/HaoYueTunnel/FileContentIndex/8724dabf-7aa7-42a1-8f9f-bd24ede189e3.vsidx differ diff --git a/.vs/HaoYueTunnel/FileContentIndex/8cf87acb-c50f-48bf-a078-36be13ef7520.vsidx b/.vs/HaoYueTunnel/FileContentIndex/8cf87acb-c50f-48bf-a078-36be13ef7520.vsidx deleted file mode 100644 index ec7466d..0000000 Binary files a/.vs/HaoYueTunnel/FileContentIndex/8cf87acb-c50f-48bf-a078-36be13ef7520.vsidx and /dev/null differ diff --git a/.vs/HaoYueTunnel/FileContentIndex/9c2e2e29-2b04-42ee-9948-aed7f262407b.vsidx b/.vs/HaoYueTunnel/FileContentIndex/9c2e2e29-2b04-42ee-9948-aed7f262407b.vsidx deleted file mode 100644 index c1e57ae..0000000 Binary files a/.vs/HaoYueTunnel/FileContentIndex/9c2e2e29-2b04-42ee-9948-aed7f262407b.vsidx and /dev/null differ diff --git a/.vs/HaoYueTunnel/FileContentIndex/dd414659-cf95-4718-99e0-2a9630f40bb8.vsidx b/.vs/HaoYueTunnel/FileContentIndex/dd414659-cf95-4718-99e0-2a9630f40bb8.vsidx deleted file mode 100644 index febfcc5..0000000 Binary files a/.vs/HaoYueTunnel/FileContentIndex/dd414659-cf95-4718-99e0-2a9630f40bb8.vsidx and /dev/null differ diff --git a/.vs/HaoYueTunnel/FileContentIndex/f206be68-8809-4859-a92e-8deb5f741e0d.vsidx b/.vs/HaoYueTunnel/FileContentIndex/f206be68-8809-4859-a92e-8deb5f741e0d.vsidx deleted file mode 100644 index 0be0931..0000000 Binary files a/.vs/HaoYueTunnel/FileContentIndex/f206be68-8809-4859-a92e-8deb5f741e0d.vsidx and /dev/null differ diff --git a/.vs/HaoYueTunnel/v17/.futdcache.v2 b/.vs/HaoYueTunnel/v17/.futdcache.v2 index da5b4e8..2653e04 100644 Binary files a/.vs/HaoYueTunnel/v17/.futdcache.v2 and b/.vs/HaoYueTunnel/v17/.futdcache.v2 differ diff --git a/.vs/HaoYueTunnel/v17/.suo b/.vs/HaoYueTunnel/v17/.suo index 5bf54d5..889b95a 100644 Binary files a/.vs/HaoYueTunnel/v17/.suo and b/.vs/HaoYueTunnel/v17/.suo differ diff --git a/.vs/ProjectEvaluation/haoyuetunnel.metadata.v5.2 b/.vs/ProjectEvaluation/haoyuetunnel.metadata.v5.2 index 8a218e4..7ed727c 100644 Binary files a/.vs/ProjectEvaluation/haoyuetunnel.metadata.v5.2 and b/.vs/ProjectEvaluation/haoyuetunnel.metadata.v5.2 differ diff --git a/.vs/ProjectEvaluation/haoyuetunnel.projects.v5.2 b/.vs/ProjectEvaluation/haoyuetunnel.projects.v5.2 index f737e8e..a44d8df 100644 Binary files a/.vs/ProjectEvaluation/haoyuetunnel.projects.v5.2 and b/.vs/ProjectEvaluation/haoyuetunnel.projects.v5.2 differ diff --git a/Client-Cli/Program.cs b/Client-Cli/Program.cs index d987a77..750bca0 100644 --- a/Client-Cli/Program.cs +++ b/Client-Cli/Program.cs @@ -1,12 +1,14 @@ using ClientCore; +using ClientCore.Data; using ClientCore.Event; -App.Init("127.0.0.1", 23846); +App.Init("127.0.0.1", 23846, 23847); //注册事件 +EventSystem.Instance.RegisterEvent(EEvent.UserLogin, OnUserLogin); +EventSystem.Instance.RegisterEvent(EEvent.TcpTunnelHelloResp, OnTcpTunnelHelloResp); EventSystem.Instance.RegisterEvent(EEvent.UserJoin, OnUserJoin); EventSystem.Instance.RegisterEvent(EEvent.UserLeave, OnUserLeave); - EventSystem.Instance.RegisterEvent(EEvent.OnChatMsg, OnChatMsg); while (true) @@ -17,6 +19,15 @@ while (true) string[] CmdArr = CommandStr.Split(' '); switch (Command) { + case "info": + { + Console.WriteLine($"IsLogin:{App.userMgr.bLogin}"); + if (App.userMgr.bLogin) + { + Console.WriteLine($"UID:{App.userMgr.MainPlayer.UID} NickName:{App.userMgr.MainPlayer.NickName}"); + } + } + break; case "login": case "l": if (CmdArr.Length < 2) @@ -26,6 +37,18 @@ while (true) } App.login.Login(CmdArr[1]); break; + case "tcphey": + case "they": + App.p2ptcp.SendHellToSev(); + break; + case "tu": + if (CmdArr.Length < 2) + { + Console.WriteLine("缺省用户名"); + return; + } + App.p2ptcp.SendDoTunnel(Convert.ToInt64(CmdArr[1])); + break; case "say": if (CmdArr.Length < 2) { @@ -34,22 +57,46 @@ while (true) } App.chat.SendChatMsg(CmdArr[1]); break; + case "ulist": + { + UserInfo[] ulist = App.userMgr.GetUserInfo(); + Console.WriteLine("User总数"+ ulist.Length); + for (int i = 0; i < ulist.Length; i++) + { + Console.WriteLine($"[{i}] UID->{ulist[i].UID} | NickName->{ulist[i].NickName} | State->{ulist[i].State}"); + } + } + break; default: Console.WriteLine("未知命令" + CommandStr); break; } } -void OnChatMsg(string str1, string str2) +void OnUserLogin() { - Console.WriteLine($"[Chat]{str1}:{str2}"); + Console.WriteLine($"[User]登录成功"); + App.userMgr.Send_GetUserList(); + + App.clientMgr.ConnectTcpTunnelServer(); +} + +void OnTcpTunnelHelloResp() +{ + Console.WriteLine($"[TcpTunnel]TcpTunnelHelloResp"); } void OnUserJoin(long UID) { Console.WriteLine($"[User]用户{UID}上线"); } + void OnUserLeave(long UID) { Console.WriteLine($"[User]用户{UID}下线"); -} \ No newline at end of file +} + +void OnChatMsg(string str1, string str2) +{ + Console.WriteLine($"[Chat]{str1}:{str2}"); +} diff --git a/ClientCore/App.cs b/ClientCore/App.cs index f6779b0..228da01 100644 --- a/ClientCore/App.cs +++ b/ClientCore/App.cs @@ -15,19 +15,27 @@ namespace ClientCore public static string IP; public static int Port; public static LogManager log; - public static NetworkHelper networkHelper; + public static ClientManager clientMgr; + public static P2PTcp p2ptcp; + public static NetworkHelper networkMain; + public static NetworkHelper networkTcp2S; public static AppLogin login; public static AppChat chat; public static UserMgr userMgr; - public static void Init(string IP, int port) + public static void Init(string IP, int port, int tcptunnelport) { log = new LogManager(); - networkHelper = new NetworkHelper(); login = new AppLogin(); chat = new AppChat(); userMgr = new UserMgr(); - networkHelper.Init(IP, port); + clientMgr = new ClientManager(); + clientMgr.SetIpData(IP, port, tcptunnelport); + p2ptcp = new P2PTcp(); + networkMain = new NetworkHelper(Enum.ServerType.MainServer); + networkMain.Init(IP, port); + //networkTcp2S = new NetworkHelper(Enum.ServerType.TcpTunnelServer); + //networkTcp2S.Init(IP, tcptunnelport); } } diff --git a/ClientCore/Data/UserData.cs b/ClientCore/Data/UserData.cs new file mode 100644 index 0000000..dadbc36 --- /dev/null +++ b/ClientCore/Data/UserData.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ClientCore.Data +{ + public class UserInfo + { + public long UID;//用户ID + public string NickName;//昵称 + public int State;//状态 + } +} diff --git a/ClientCore/Enum/CommEnum.cs b/ClientCore/Enum/CommEnum.cs new file mode 100644 index 0000000..1964474 --- /dev/null +++ b/ClientCore/Enum/CommEnum.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ClientCore.Enum +{ + public enum ServerType + { + MainServer, + TcpTunnelServer, + + TcpP2PTarget + } +} diff --git a/ClientCore/Event/EEvent.cs b/ClientCore/Event/EEvent.cs index b0969be..7c52d8a 100644 --- a/ClientCore/Event/EEvent.cs +++ b/ClientCore/Event/EEvent.cs @@ -9,8 +9,16 @@ namespace ClientCore.Event public enum EEvent { // 添加你自己需要的事件类型 + UserLogin, UserJoin, UserLeave, OnChatMsg, + + //打洞流程 + TcpTunnelHelloResp, + + //连接管理 + OnSocketConnect, + OnSocketDisconnect, } } diff --git a/ClientCore/Manager/AppChat.cs b/ClientCore/Manager/AppChat.cs index 0e0bdb9..dcca67f 100644 --- a/ClientCore/Manager/AppChat.cs +++ b/ClientCore/Manager/AppChat.cs @@ -18,7 +18,7 @@ namespace ClientCore.Manager { ChatMsg = ChatMsg, }; - App.networkHelper.SendToServer((int)CommandID.CmdChatmsg, ProtoBufHelper.Serizlize(msg)); + App.networkMain.SendToServer((int)CommandID.CmdChatmsg, ProtoBufHelper.Serizlize(msg)); } public void RecvChatMsg(byte[] reqData) diff --git a/ClientCore/Manager/AppLogin.cs b/ClientCore/Manager/AppLogin.cs index aa34bd8..96b0dbc 100644 --- a/ClientCore/Manager/AppLogin.cs +++ b/ClientCore/Manager/AppLogin.cs @@ -1,10 +1,17 @@ using AxibugProtobuf; using ClientCore.Common; +using ClientCore.Event; +using ClientCore.Network; namespace ClientCore.Manager { public class AppLogin { + public AppLogin() + { + NetMsg.Instance.RegNetMsgEvent((int)CommandID.CmdLogin, RecvCmdLogin); + } + public void Login(string Account) { Protobuf_Login msg = new Protobuf_Login() @@ -12,7 +19,14 @@ namespace ClientCore.Manager LoginType = 0, Account = Account, }; - App.networkHelper.SendToServer((int)CommandID.CmdLogin, ProtoBufHelper.Serizlize(msg)); + App.networkMain.SendToServer((int)CommandID.CmdLogin, ProtoBufHelper.Serizlize(msg)); + } + + public void RecvCmdLogin(byte[] reqData) + { + Protobuf_Login_RESP msg = ProtoBufHelper.DeSerizlize(reqData); + App.userMgr.SetMainPlayer(msg.UID, msg.NickName, 0); + EventSystem.Instance.PostEvent(EEvent.UserLogin); } } } diff --git a/ClientCore/Manager/ClientManager.cs b/ClientCore/Manager/ClientManager.cs new file mode 100644 index 0000000..90c3198 --- /dev/null +++ b/ClientCore/Manager/ClientManager.cs @@ -0,0 +1,208 @@ +using AxibugProtobuf; +using ClientCore.Common; +using ClientCore.Enum; +using ClientCore.Event; +using ClientCore.Network; +using System.Net.Sockets; +using System.Timers; + +namespace ClientCore.Manager +{ + public class ClientManager + { + bool bTryReConTcpTunnelServer = false; + string IP; + int port; + int tcptunnelport; + int LastlocalPort = 0; + + Dictionary DictUID2TcpTaret = new Dictionary(); + + public ClientManager() + { + //注册事件 + EventSystem.Instance.RegisterEvent(EEvent.OnSocketConnect, OnSocketConnect); + EventSystem.Instance.RegisterEvent(EEvent.OnSocketDisconnect, OnSocketDisconnect); + } + + public void SetIpData(string IP, int port, int tcptunnelport) + { + this.IP = IP; + this.port = port; + this.tcptunnelport = tcptunnelport; + } + + void OnSocketConnect(ServerType servertype, bool IsOk) + { + switch (servertype) + { + case ServerType.MainServer: + { + if (IsOk) + { + Console.WriteLine("MainServer连接成功"); + + } + else + { + Console.WriteLine("MainServer连接失败"); + + } + } + break; + case ServerType.TcpTunnelServer: + { + bTryReConTcpTunnelServer = false; + if (IsOk) + { + Console.WriteLine("TcpTunnelServer连接成功"); + App.p2ptcp.SendHellToSev(); + } + else + { + Console.WriteLine("TcpTunnelServer连接失败"); + } + } + break; + case ServerType.TcpP2PTarget: + { + if (IsOk) + { + Console.WriteLine("TcpP2PTarget连接成功"); + } + } + break; + } + } + void OnSocketDisconnect(ServerType servertype, long uid) + { + switch (servertype) + { + case ServerType.MainServer: + { + Console.WriteLine("MainServer连接断开"); + } + break; + case ServerType.TcpTunnelServer: + { + Console.WriteLine("TcpTunnelServer连接断开"); + Console.WriteLine("TcpTunnelServer,尝试重连"); + ReConnectTcpTunnelServer(); + } + break; + case ServerType.TcpP2PTarget: + { + Console.WriteLine("TcpP2PTarget连接断开"); + RemoveTargetSocket(uid); + } + break; + } + } + + public void ConnectTcpTunnelServer() + { + App.networkTcp2S = new NetworkHelper(Enum.ServerType.TcpTunnelServer); + App.networkTcp2S.Init(IP, tcptunnelport); + } + + public void ReConnectTcpTunnelServer() + { + //TODO 因TEST 暂不重连 + return; + + if (bTryReConTcpTunnelServer) + return; + if (App.networkTcp2S != null && App.networkTcp2S.GetClientSocket() != null && App.networkTcp2S.GetClientSocket().Connected) + return; + bTryReConTcpTunnelServer = true; + + Thread thread = new Thread(ReConnectTcpTunnelServerThread); + thread.IsBackground = true; + thread.Start(); + + } + + private void ReConnectTcpTunnelServerThread() + { + Thread.Sleep(1000); + App.networkTcp2S.Init(IP, tcptunnelport); + } + + + #region P2PTarget 管理 + void AddTargetSocket(NetworkHelper targetSocket) + { + DictUID2TcpTaret[targetSocket.mUID] = targetSocket; + } + + void RemoveTargetSocket(long UID) + { + if (DictUID2TcpTaret.ContainsKey(UID)) + { + DictUID2TcpTaret.Remove(UID); + } + } + + NetworkHelper GetTargetSocket(long UID) + { + if (DictUID2TcpTaret.ContainsKey(UID)) + { + return DictUID2TcpTaret[UID]; + } + return null; + } + + /// + /// 发送给指定UID消息 + /// + /// + /// + /// + public void SendToTargetSocket(long UID,int CMDID,byte[] data) + { + NetworkHelper target = GetTargetSocket(UID); + if (target == null) + return; + target.SendToServer((int)CMDID, data); + } + #endregion + + + #region TCP打洞对连 + + public void ConnectTCPTargetP2P(Protobuf_TcpTunnel_DoTunnel_RESP msg, int localPort) + { + LastlocalPort = localPort; + Thread thread = new Thread(ConnectTCPTargetP2PThread); + thread.IsBackground = true; + thread.Start(msg); + } + + public void ConnectTCPTargetP2PThread(object obj) + { + Thread.Sleep(1000); + int userBindPort = LastlocalPort; + Protobuf_TcpTunnel_DoTunnel_RESP msg = (Protobuf_TcpTunnel_DoTunnel_RESP)obj; + Console.WriteLine("LocalEndPoint Port:" + userBindPort); + NetworkHelper targetSocket = new NetworkHelper(Enum.ServerType.TcpP2PTarget, msg.TargetUID); + targetSocket.Init(msg.OtherIP, msg.OtherPort, true, userBindPort); + //尝试5次连接 + for (int j = 0; j < 5; j++) + { + try + { + targetSocket.Connect(msg.OtherIP, msg.OtherPort); + Console.WriteLine("Connect:成功{0},{1}", msg.OtherIP, msg.OtherPort); + AddTargetSocket(targetSocket); + break; + } + catch (Exception) + { + Console.WriteLine("Connect:失败"); + } + } + } + + #endregion + } +} diff --git a/ClientCore/Manager/P2PChat.cs b/ClientCore/Manager/P2PChat.cs new file mode 100644 index 0000000..574f5f7 --- /dev/null +++ b/ClientCore/Manager/P2PChat.cs @@ -0,0 +1,23 @@ +using AxibugProtobuf; +using ClientCore.Common; +using ClientCore.Event; +using ClientCore.Network; + +namespace ClientCore.Manager +{ + public class P2PChat + { + public P2PChat() + { + //NetMsg.Instance.RegNetMsgEvent((int)CommandID.CmdChatmsg, RecvChatMsg); + } + public void SendChatMsg(long UID,string ChatMsg) + { + Protobuf_TcpP2P_Chat msg = new Protobuf_TcpP2P_Chat() + { + ChatMsg = ChatMsg, + }; + App.clientMgr.SendToTargetSocket(UID,(int)CommandID.CmdTcpP2PChat ,ProtoBufHelper.Serizlize(msg)); + } + } +} diff --git a/ClientCore/Manager/P2PTcp.cs b/ClientCore/Manager/P2PTcp.cs new file mode 100644 index 0000000..5134619 --- /dev/null +++ b/ClientCore/Manager/P2PTcp.cs @@ -0,0 +1,61 @@ +using AxibugProtobuf; +using ClientCore.Common; +using ClientCore.Event; +using ClientCore.Network; +using System.Net; +using System.Net.Sockets; + +namespace ClientCore.Manager +{ + public class P2PTcp + { + bool bRegToSev = false; + public P2PTcp() + { + NetMsg.Instance.RegNetMsgEvent((int)CommandID.CmdTcptunnelHello, RecvTcptunnelHello); + NetMsg.Instance.RegNetMsgEvent((int)CommandID.CmdTcptunnelDo, RecvCmdTcptunnelDo); + } + + public void SendHellToSev() + { + Protobuf_TcpTunnel_HellToSev msg = new Protobuf_TcpTunnel_HellToSev() + { + UID = App.userMgr.MainPlayer.UID + }; + App.networkTcp2S.SendToServer((int)CommandID.CmdTcptunnelHello, ProtoBufHelper.Serizlize(msg)); + } + + public void RecvTcptunnelHello(byte[] reqData) + { + Protobuf_TcpTunnel_HellToSev_RESP msg = ProtoBufHelper.DeSerizlize(reqData); + bRegToSev = true; + EventSystem.Instance.PostEvent(EEvent.TcpTunnelHelloResp); + } + + + public void SendDoTunnel(long targetUID) + { + Protobuf_TcpTunnel_DoTunnel msg = new Protobuf_TcpTunnel_DoTunnel() + { + UID = App.userMgr.MainPlayer.UID, + TargetUID = targetUID + }; + App.networkTcp2S.SendToServer((int)CommandID.CmdTcptunnelDo, ProtoBufHelper.Serizlize(msg)); + } + + public void RecvCmdTcptunnelDo(byte[] reqData) + { + Protobuf_TcpTunnel_DoTunnel_RESP msg = ProtoBufHelper.DeSerizlize(reqData); + //TODO 打洞 + Console.WriteLine($"打洞目标信息 {msg.TargetUID} {msg.OtherIP} {msg.OtherPort}"); + + int localPort = ((IPEndPoint)App.networkTcp2S.GetClientSocket().LocalEndPoint).Port; + + //断开连接 + App.networkTcp2S.CloseConntect(); + + App.clientMgr.ConnectTCPTargetP2P(msg, localPort); + } + + } +} \ No newline at end of file diff --git a/ClientCore/Manager/UserMgr.cs b/ClientCore/Manager/UserMgr.cs index facb5ce..f58b0df 100644 --- a/ClientCore/Manager/UserMgr.cs +++ b/ClientCore/Manager/UserMgr.cs @@ -1,5 +1,6 @@ using AxibugProtobuf; using ClientCore.Common; +using ClientCore.Data; using ClientCore.Event; using ClientCore.Network; using System; @@ -7,27 +8,41 @@ 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 DictUID2User = new Dictionary(); + public UserInfo MainPlayer { get; private set; } + public bool bLogin => MainPlayer != null; + Dictionary DictUID2User = new Dictionary(); 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 SetMainPlayer(long uid,string account,int state) + { + MainPlayer = new UserInfo() + { + State = state, + NickName = account, + UID = uid + }; + } + + public void Send_GetUserList() + { + Protobuf_UserList msg = new Protobuf_UserList() + { + }; + App.networkMain.SendToServer((int)CommandID.CmdUserOnlinelist, ProtoBufHelper.Serizlize(msg)); + } + public void RecvUserOnlinelist(byte[] reqData) { Protobuf_UserList_RESP msg = ProtoBufHelper.DeSerizlize(reqData); - for(int i = 0;i < msg.UserList.Count;i++) { UserMiniInfo mi = msg.UserList[i]; @@ -86,5 +101,16 @@ namespace ClientCore.Manager EventSystem.Instance.PostEvent(EEvent.UserLeave, UID); } } + + public UserInfo[] GetUserInfo() + { + UserInfo[] ulist = new UserInfo[DictUID2User.Count]; + long[] UIDs = DictUID2User.Keys.ToArray(); + for (int i = 0; i < UIDs.Length; i++) + { + ulist[i] = DictUID2User[UIDs[i]]; + } + return ulist; + } } } diff --git a/ClientCore/Network/NetworkHelper.cs b/ClientCore/Network/NetworkHelper.cs index 4c45fcc..bd87060 100644 --- a/ClientCore/Network/NetworkHelper.cs +++ b/ClientCore/Network/NetworkHelper.cs @@ -1,4 +1,6 @@ using AxibugProtobuf; +using ClientCore.Enum; +using ClientCore.Event; using HaoYueNet.ClientNetwork; using System; using System.Collections.Generic; @@ -13,7 +15,9 @@ namespace ClientCore.Network /// public class NetworkHelper : NetworkHelperCore { - public NetworkHelper() + ServerType mServerType; + public long mUID { get; private set; } = -1; + public NetworkHelper(ServerType serverType,long UID = -1) { //指定接收服务器数据事件 OnDataCallBack += GetDataCallBack; @@ -22,15 +26,21 @@ namespace ClientCore.Network //网络库调试信息输出事件,用于打印连接断开,收发事件 OnLogOut += NetworkDeBugLog; OnConnected += NetworkConnected; + mServerType = serverType; + mUID = UID; } public void NetworkConnected(bool IsConnect) { if (IsConnect) + { + EventSystem.Instance.PostEvent(EEvent.OnSocketConnect, mServerType, true); NetworkDeBugLog("服务器连接成功"); + } else { + EventSystem.Instance.PostEvent(EEvent.OnSocketConnect, mServerType, false); NetworkDeBugLog("服务器连接失败"); //to do 重连逻辑 } @@ -71,6 +81,7 @@ namespace ClientCore.Network public void OnConnectClose() { NetworkDeBugLog("OnConnectClose"); + EventSystem.Instance.PostEvent(EEvent.OnSocketDisconnect, mServerType, mUID); } } } diff --git a/NetLib/HaoYueNet.ClientNetwork.dll b/NetLib/HaoYueNet.ClientNetwork.dll index 3e5d2f5..e212c60 100644 Binary files a/NetLib/HaoYueNet.ClientNetwork.dll and b/NetLib/HaoYueNet.ClientNetwork.dll differ diff --git a/Protobuf/ProtobufAuth.cs b/Protobuf/ProtobufAuth.cs index b2b5cad..3fdc87c 100644 --- a/Protobuf/ProtobufAuth.cs +++ b/Protobuf/ProtobufAuth.cs @@ -28,28 +28,29 @@ namespace AxibugProtobuf { "dG9idWZfTG9naW4SLAoJbG9naW5UeXBlGAEgASgOMhkuQXhpYnVnUHJvdG9i", "dWYuTG9naW5UeXBlEi4KCmRldmljZVR5cGUYAiABKA4yGi5BeGlidWdQcm90", "b2J1Zi5EZXZpY2VUeXBlEg8KB0FjY291bnQYAyABKAkSEAoIUGFzc3dvcmQY", - "BCABKAkifwoTUHJvdG9idWZfTG9naW5fUkVTUBINCgVUb2tlbhgBIAEoCRIV", - "Cg1MYXN0TG9naW5EYXRlGAIgASgJEg8KB1JlZ0RhdGUYAyABKAkSMQoGU3Rh", - "dHVzGAQgASgOMiEuQXhpYnVnUHJvdG9idWYuTG9naW5SZXN1bHRTdGF0dXMi", - "IwoQUHJvdG9idWZfQ2hhdE1zZxIPCgdDaGF0TXNnGAEgASgJIkgKFVByb3Rv", - "YnVmX0NoYXRNc2dfUkVTUBIQCghOaWNrTmFtZRgBIAEoCRIPCgdDaGF0TXNn", - "GAIgASgJEgwKBERhdGUYAyABKAMqzQEKCUNvbW1hbmRJRBIOCgpDTURfREVG", - "QVVMEAASDgoJQ01EX0xPR0lOENAPEhAKC0NNRF9DSEFUTVNHEKAfEhgKE0NN", - "RF9VU0VSX09OTElORUxJU1QQiCcSEgoNQ01EX1VTRVJfSk9JThCnJxITCg5D", - "TURfVVNFUl9MRUFWRRCoJxIaChVDTURfVVNFUl9TVEFURV9VUERBVEUQqScS", - "GAoTQ01EX1RDUFRVTk5FTF9IRUxMTxCJJxIVChBDTURfVENQVFVOTkVMX0RP", - "EIonKj4KCUVycm9yQ29kZRIQCgxFUlJPUl9ERUZBVUwQABIMCghFUlJPUl9P", - "SxABEhEKDUVSUk9SX05PVEZBTkQQZCo+CglMb2dpblR5cGUSDwoLQmFzZURl", - "ZmF1bHQQABIOCgpIYW9ZdWVBdXRoEAESBwoDQkYzEAMSBwoDQkY0EAQqSwoK", - "RGV2aWNlVHlwZRIWChJEZXZpY2VUeXBlX0RlZmF1bHQQABIGCgJQQxABEgsK", - "B0FuZHJvaWQQAhIHCgNJT1MQAxIHCgNQU1YQBCpOChFMb2dpblJlc3VsdFN0", - "YXR1cxIhCh1Mb2dpblJlc3VsdFN0YXR1c19CYXNlRGVmYXVsdBAAEgYKAk9L", - "EAESDgoKQWNjb3VudEVychACQgJIAWIGcHJvdG8z")); + "BCABKAkingEKE1Byb3RvYnVmX0xvZ2luX1JFU1ASDQoFVG9rZW4YASABKAkS", + "FQoNTGFzdExvZ2luRGF0ZRgCIAEoCRIPCgdSZWdEYXRlGAMgASgJEjEKBlN0", + "YXR1cxgEIAEoDjIhLkF4aWJ1Z1Byb3RvYnVmLkxvZ2luUmVzdWx0U3RhdHVz", + "EgsKA1VJRBgFIAEoAxIQCghOaWNrTmFtZRgGIAEoCSIjChBQcm90b2J1Zl9D", + "aGF0TXNnEg8KB0NoYXRNc2cYASABKAkiSAoVUHJvdG9idWZfQ2hhdE1zZ19S", + "RVNQEhAKCE5pY2tOYW1lGAEgASgJEg8KB0NoYXRNc2cYAiABKAkSDAoERGF0", + "ZRgDIAEoAyrkAQoJQ29tbWFuZElEEg4KCkNNRF9ERUZBVUwQABIOCglDTURf", + "TE9HSU4Q0A8SEAoLQ01EX0NIQVRNU0cQoB8SGAoTQ01EX1VTRVJfT05MSU5F", + "TElTVBCIJxISCg1DTURfVVNFUl9KT0lOEKcnEhMKDkNNRF9VU0VSX0xFQVZF", + "EKgnEhoKFUNNRF9VU0VSX1NUQVRFX1VQREFURRCpJxIYChNDTURfVENQVFVO", + "TkVMX0hFTExPEIknEhUKEENNRF9UQ1BUVU5ORUxfRE8QiicSFQoQQ01EX1RD", + "UF9QMlBfQ0hBVBCRTio+CglFcnJvckNvZGUSEAoMRVJST1JfREVGQVVMEAAS", + "DAoIRVJST1JfT0sQARIRCg1FUlJPUl9OT1RGSU5EEGQqPgoJTG9naW5UeXBl", + "Eg8KC0Jhc2VEZWZhdWx0EAASDgoKSGFvWXVlQXV0aBABEgcKA0JGMxADEgcK", + "A0JGNBAEKksKCkRldmljZVR5cGUSFgoSRGV2aWNlVHlwZV9EZWZhdWx0EAAS", + "BgoCUEMQARILCgdBbmRyb2lkEAISBwoDSU9TEAMSBwoDUFNWEAQqTgoRTG9n", + "aW5SZXN1bHRTdGF0dXMSIQodTG9naW5SZXN1bHRTdGF0dXNfQmFzZURlZmF1", + "bHQQABIGCgJPSxABEg4KCkFjY291bnRFcnIQAkICSAFiBnByb3RvMw==")); descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData, 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(typeof(global::AxibugProtobuf.Protobuf_Login), global::AxibugProtobuf.Protobuf_Login.Parser, new[]{ "LoginType", "DeviceType", "Account", "Password" }, null, null, null, null), - new pbr::GeneratedClrTypeInfo(typeof(global::AxibugProtobuf.Protobuf_Login_RESP), global::AxibugProtobuf.Protobuf_Login_RESP.Parser, new[]{ "Token", "LastLoginDate", "RegDate", "Status" }, null, null, null, null), + new pbr::GeneratedClrTypeInfo(typeof(global::AxibugProtobuf.Protobuf_Login_RESP), global::AxibugProtobuf.Protobuf_Login_RESP.Parser, new[]{ "Token", "LastLoginDate", "RegDate", "Status", "UID", "NickName" }, null, null, null, null), new pbr::GeneratedClrTypeInfo(typeof(global::AxibugProtobuf.Protobuf_ChatMsg), global::AxibugProtobuf.Protobuf_ChatMsg.Parser, new[]{ "ChatMsg" }, null, null, null, null), new pbr::GeneratedClrTypeInfo(typeof(global::AxibugProtobuf.Protobuf_ChatMsg_RESP), global::AxibugProtobuf.Protobuf_ChatMsg_RESP.Parser, new[]{ "NickName", "ChatMsg", "Date" }, null, null, null, null) })); @@ -95,6 +96,10 @@ namespace AxibugProtobuf { ///TCP打洞请求 下行 对应 Protobuf_TcpTunnel_DoTunnel | Protobuf_TcpTunnel_DoTunnel_RESP /// [pbr::OriginalName("CMD_TCPTUNNEL_DO")] CmdTcptunnelDo = 5002, + /// + ///TCPP2P聊天 Protobuf_TcpP2P_Chat + /// + [pbr::OriginalName("CMD_TCP_P2P_CHAT")] CmdTcpP2PChat = 10001, } public enum ErrorCode { @@ -109,7 +114,7 @@ namespace AxibugProtobuf { /// ///用户不存在 /// - [pbr::OriginalName("ERROR_NOTFAND")] ErrorNotfand = 100, + [pbr::OriginalName("ERROR_NOTFIND")] ErrorNotfind = 100, } public enum LoginType { @@ -476,6 +481,8 @@ namespace AxibugProtobuf { lastLoginDate_ = other.lastLoginDate_; regDate_ = other.regDate_; status_ = other.status_; + uID_ = other.uID_; + nickName_ = other.nickName_; _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); } @@ -540,6 +547,34 @@ namespace AxibugProtobuf { } } + /// Field number for the "UID" field. + public const int UIDFieldNumber = 5; + private long uID_; + /// + ///UID + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public long UID { + get { return uID_; } + set { + uID_ = value; + } + } + + /// Field number for the "NickName" field. + public const int NickNameFieldNumber = 6; + private string nickName_ = ""; + /// + ///昵称 + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public string NickName { + get { return nickName_; } + set { + nickName_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public override bool Equals(object other) { return Equals(other as Protobuf_Login_RESP); @@ -557,6 +592,8 @@ namespace AxibugProtobuf { if (LastLoginDate != other.LastLoginDate) return false; if (RegDate != other.RegDate) return false; if (Status != other.Status) return false; + if (UID != other.UID) return false; + if (NickName != other.NickName) return false; return Equals(_unknownFields, other._unknownFields); } @@ -567,6 +604,8 @@ namespace AxibugProtobuf { if (LastLoginDate.Length != 0) hash ^= LastLoginDate.GetHashCode(); if (RegDate.Length != 0) hash ^= RegDate.GetHashCode(); if (Status != global::AxibugProtobuf.LoginResultStatus.BaseDefault) hash ^= Status.GetHashCode(); + if (UID != 0L) hash ^= UID.GetHashCode(); + if (NickName.Length != 0) hash ^= NickName.GetHashCode(); if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); } @@ -599,6 +638,14 @@ namespace AxibugProtobuf { output.WriteRawTag(32); output.WriteEnum((int) Status); } + if (UID != 0L) { + output.WriteRawTag(40); + output.WriteInt64(UID); + } + if (NickName.Length != 0) { + output.WriteRawTag(50); + output.WriteString(NickName); + } if (_unknownFields != null) { _unknownFields.WriteTo(output); } @@ -624,6 +671,14 @@ namespace AxibugProtobuf { output.WriteRawTag(32); output.WriteEnum((int) Status); } + if (UID != 0L) { + output.WriteRawTag(40); + output.WriteInt64(UID); + } + if (NickName.Length != 0) { + output.WriteRawTag(50); + output.WriteString(NickName); + } if (_unknownFields != null) { _unknownFields.WriteTo(ref output); } @@ -645,6 +700,12 @@ namespace AxibugProtobuf { if (Status != global::AxibugProtobuf.LoginResultStatus.BaseDefault) { size += 1 + pb::CodedOutputStream.ComputeEnumSize((int) Status); } + if (UID != 0L) { + size += 1 + pb::CodedOutputStream.ComputeInt64Size(UID); + } + if (NickName.Length != 0) { + size += 1 + pb::CodedOutputStream.ComputeStringSize(NickName); + } if (_unknownFields != null) { size += _unknownFields.CalculateSize(); } @@ -668,6 +729,12 @@ namespace AxibugProtobuf { if (other.Status != global::AxibugProtobuf.LoginResultStatus.BaseDefault) { Status = other.Status; } + if (other.UID != 0L) { + UID = other.UID; + } + if (other.NickName.Length != 0) { + NickName = other.NickName; + } _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); } @@ -698,6 +765,14 @@ namespace AxibugProtobuf { Status = (global::AxibugProtobuf.LoginResultStatus) input.ReadEnum(); break; } + case 40: { + UID = input.ReadInt64(); + break; + } + case 50: { + NickName = input.ReadString(); + break; + } } } #endif @@ -728,6 +803,14 @@ namespace AxibugProtobuf { Status = (global::AxibugProtobuf.LoginResultStatus) input.ReadEnum(); break; } + case 40: { + UID = input.ReadInt64(); + break; + } + case 50: { + NickName = input.ReadString(); + break; + } } } } diff --git a/Protobuf/ProtobufTcpTunnel.cs b/Protobuf/ProtobufTcpTunnel.cs index 3c26d84..bb80caa 100644 --- a/Protobuf/ProtobufTcpTunnel.cs +++ b/Protobuf/ProtobufTcpTunnel.cs @@ -30,15 +30,17 @@ namespace AxibugProtobuf { "Zl9UY3BUdW5uZWxfRG9UdW5uZWwSCwoDVUlEGAEgASgDEhEKCXRhcmdldFVJ", "RBgCIAEoAyJ3CiBQcm90b2J1Zl9UY3BUdW5uZWxfRG9UdW5uZWxfUkVTUBIR", "Cgl0YXJnZXRVSUQYASABKAMSDAoEbXlJUBgCIAEoCRIOCgZteVBvcnQYAyAB", - "KAUSDwoHb3RoZXJJUBgEIAEoCRIRCglvdGhlclBvcnQYBSABKAVCAkgBYgZw", - "cm90bzM=")); + "KAUSDwoHb3RoZXJJUBgEIAEoCRIRCglvdGhlclBvcnQYBSABKAUiJwoUUHJv", + "dG9idWZfVGNwUDJQX0NoYXQSDwoHQ2hhdE1zZxgBIAEoCUICSAFiBnByb3Rv", + "Mw==")); descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData, new pbr::FileDescriptor[] { }, new pbr::GeneratedClrTypeInfo(null, null, new pbr::GeneratedClrTypeInfo[] { new pbr::GeneratedClrTypeInfo(typeof(global::AxibugProtobuf.Protobuf_TcpTunnel_HellToSev), global::AxibugProtobuf.Protobuf_TcpTunnel_HellToSev.Parser, new[]{ "UID" }, null, null, null, null), new pbr::GeneratedClrTypeInfo(typeof(global::AxibugProtobuf.Protobuf_TcpTunnel_HellToSev_RESP), global::AxibugProtobuf.Protobuf_TcpTunnel_HellToSev_RESP.Parser, null, null, null, null, null), new pbr::GeneratedClrTypeInfo(typeof(global::AxibugProtobuf.Protobuf_TcpTunnel_DoTunnel), global::AxibugProtobuf.Protobuf_TcpTunnel_DoTunnel.Parser, new[]{ "UID", "TargetUID" }, null, null, null, null), - new pbr::GeneratedClrTypeInfo(typeof(global::AxibugProtobuf.Protobuf_TcpTunnel_DoTunnel_RESP), global::AxibugProtobuf.Protobuf_TcpTunnel_DoTunnel_RESP.Parser, new[]{ "TargetUID", "MyIP", "MyPort", "OtherIP", "OtherPort" }, null, null, null, null) + new pbr::GeneratedClrTypeInfo(typeof(global::AxibugProtobuf.Protobuf_TcpTunnel_DoTunnel_RESP), global::AxibugProtobuf.Protobuf_TcpTunnel_DoTunnel_RESP.Parser, new[]{ "TargetUID", "MyIP", "MyPort", "OtherIP", "OtherPort" }, null, null, null, null), + new pbr::GeneratedClrTypeInfo(typeof(global::AxibugProtobuf.Protobuf_TcpP2P_Chat), global::AxibugProtobuf.Protobuf_TcpP2P_Chat.Parser, new[]{ "ChatMsg" }, null, null, null, null) })); } #endregion @@ -913,6 +915,184 @@ namespace AxibugProtobuf { } + /// + ///TCPP2P聊天 + /// + public sealed partial class Protobuf_TcpP2P_Chat : pb::IMessage + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + , pb::IBufferMessage + #endif + { + private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new Protobuf_TcpP2P_Chat()); + private pb::UnknownFieldSet _unknownFields; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pb::MessageParser Parser { get { return _parser; } } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pbr::MessageDescriptor Descriptor { + get { return global::AxibugProtobuf.ProtobufTcpTunnelReflection.Descriptor.MessageTypes[4]; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + pbr::MessageDescriptor pb::IMessage.Descriptor { + get { return Descriptor; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public Protobuf_TcpP2P_Chat() { + OnConstruction(); + } + + partial void OnConstruction(); + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public Protobuf_TcpP2P_Chat(Protobuf_TcpP2P_Chat other) : this() { + chatMsg_ = other.chatMsg_; + _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public Protobuf_TcpP2P_Chat Clone() { + return new Protobuf_TcpP2P_Chat(this); + } + + /// Field number for the "ChatMsg" field. + public const int ChatMsgFieldNumber = 1; + private string chatMsg_ = ""; + /// + ///消息 + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public string ChatMsg { + get { return chatMsg_; } + set { + chatMsg_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override bool Equals(object other) { + return Equals(other as Protobuf_TcpP2P_Chat); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool Equals(Protobuf_TcpP2P_Chat other) { + if (ReferenceEquals(other, null)) { + return false; + } + if (ReferenceEquals(other, this)) { + return true; + } + if (ChatMsg != other.ChatMsg) return false; + return Equals(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override int GetHashCode() { + int hash = 1; + if (ChatMsg.Length != 0) hash ^= ChatMsg.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 (ChatMsg.Length != 0) { + output.WriteRawTag(10); + output.WriteString(ChatMsg); + } + 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 (ChatMsg.Length != 0) { + output.WriteRawTag(10); + output.WriteString(ChatMsg); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public int CalculateSize() { + int size = 0; + if (ChatMsg.Length != 0) { + size += 1 + pb::CodedOutputStream.ComputeStringSize(ChatMsg); + } + if (_unknownFields != null) { + size += _unknownFields.CalculateSize(); + } + return size; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(Protobuf_TcpP2P_Chat other) { + if (other == null) { + return; + } + if (other.ChatMsg.Length != 0) { + ChatMsg = other.ChatMsg; + } + _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 10: { + ChatMsg = input.ReadString(); + 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 10: { + ChatMsg = input.ReadString(); + break; + } + } + } + } + #endif + + } + #endregion } diff --git a/ProtobufCore/out/ProtobufAuth.cs b/ProtobufCore/out/ProtobufAuth.cs index b2b5cad..3fdc87c 100644 --- a/ProtobufCore/out/ProtobufAuth.cs +++ b/ProtobufCore/out/ProtobufAuth.cs @@ -28,28 +28,29 @@ namespace AxibugProtobuf { "dG9idWZfTG9naW4SLAoJbG9naW5UeXBlGAEgASgOMhkuQXhpYnVnUHJvdG9i", "dWYuTG9naW5UeXBlEi4KCmRldmljZVR5cGUYAiABKA4yGi5BeGlidWdQcm90", "b2J1Zi5EZXZpY2VUeXBlEg8KB0FjY291bnQYAyABKAkSEAoIUGFzc3dvcmQY", - "BCABKAkifwoTUHJvdG9idWZfTG9naW5fUkVTUBINCgVUb2tlbhgBIAEoCRIV", - "Cg1MYXN0TG9naW5EYXRlGAIgASgJEg8KB1JlZ0RhdGUYAyABKAkSMQoGU3Rh", - "dHVzGAQgASgOMiEuQXhpYnVnUHJvdG9idWYuTG9naW5SZXN1bHRTdGF0dXMi", - "IwoQUHJvdG9idWZfQ2hhdE1zZxIPCgdDaGF0TXNnGAEgASgJIkgKFVByb3Rv", - "YnVmX0NoYXRNc2dfUkVTUBIQCghOaWNrTmFtZRgBIAEoCRIPCgdDaGF0TXNn", - "GAIgASgJEgwKBERhdGUYAyABKAMqzQEKCUNvbW1hbmRJRBIOCgpDTURfREVG", - "QVVMEAASDgoJQ01EX0xPR0lOENAPEhAKC0NNRF9DSEFUTVNHEKAfEhgKE0NN", - "RF9VU0VSX09OTElORUxJU1QQiCcSEgoNQ01EX1VTRVJfSk9JThCnJxITCg5D", - "TURfVVNFUl9MRUFWRRCoJxIaChVDTURfVVNFUl9TVEFURV9VUERBVEUQqScS", - "GAoTQ01EX1RDUFRVTk5FTF9IRUxMTxCJJxIVChBDTURfVENQVFVOTkVMX0RP", - "EIonKj4KCUVycm9yQ29kZRIQCgxFUlJPUl9ERUZBVUwQABIMCghFUlJPUl9P", - "SxABEhEKDUVSUk9SX05PVEZBTkQQZCo+CglMb2dpblR5cGUSDwoLQmFzZURl", - "ZmF1bHQQABIOCgpIYW9ZdWVBdXRoEAESBwoDQkYzEAMSBwoDQkY0EAQqSwoK", - "RGV2aWNlVHlwZRIWChJEZXZpY2VUeXBlX0RlZmF1bHQQABIGCgJQQxABEgsK", - "B0FuZHJvaWQQAhIHCgNJT1MQAxIHCgNQU1YQBCpOChFMb2dpblJlc3VsdFN0", - "YXR1cxIhCh1Mb2dpblJlc3VsdFN0YXR1c19CYXNlRGVmYXVsdBAAEgYKAk9L", - "EAESDgoKQWNjb3VudEVychACQgJIAWIGcHJvdG8z")); + "BCABKAkingEKE1Byb3RvYnVmX0xvZ2luX1JFU1ASDQoFVG9rZW4YASABKAkS", + "FQoNTGFzdExvZ2luRGF0ZRgCIAEoCRIPCgdSZWdEYXRlGAMgASgJEjEKBlN0", + "YXR1cxgEIAEoDjIhLkF4aWJ1Z1Byb3RvYnVmLkxvZ2luUmVzdWx0U3RhdHVz", + "EgsKA1VJRBgFIAEoAxIQCghOaWNrTmFtZRgGIAEoCSIjChBQcm90b2J1Zl9D", + "aGF0TXNnEg8KB0NoYXRNc2cYASABKAkiSAoVUHJvdG9idWZfQ2hhdE1zZ19S", + "RVNQEhAKCE5pY2tOYW1lGAEgASgJEg8KB0NoYXRNc2cYAiABKAkSDAoERGF0", + "ZRgDIAEoAyrkAQoJQ29tbWFuZElEEg4KCkNNRF9ERUZBVUwQABIOCglDTURf", + "TE9HSU4Q0A8SEAoLQ01EX0NIQVRNU0cQoB8SGAoTQ01EX1VTRVJfT05MSU5F", + "TElTVBCIJxISCg1DTURfVVNFUl9KT0lOEKcnEhMKDkNNRF9VU0VSX0xFQVZF", + "EKgnEhoKFUNNRF9VU0VSX1NUQVRFX1VQREFURRCpJxIYChNDTURfVENQVFVO", + "TkVMX0hFTExPEIknEhUKEENNRF9UQ1BUVU5ORUxfRE8QiicSFQoQQ01EX1RD", + "UF9QMlBfQ0hBVBCRTio+CglFcnJvckNvZGUSEAoMRVJST1JfREVGQVVMEAAS", + "DAoIRVJST1JfT0sQARIRCg1FUlJPUl9OT1RGSU5EEGQqPgoJTG9naW5UeXBl", + "Eg8KC0Jhc2VEZWZhdWx0EAASDgoKSGFvWXVlQXV0aBABEgcKA0JGMxADEgcK", + "A0JGNBAEKksKCkRldmljZVR5cGUSFgoSRGV2aWNlVHlwZV9EZWZhdWx0EAAS", + "BgoCUEMQARILCgdBbmRyb2lkEAISBwoDSU9TEAMSBwoDUFNWEAQqTgoRTG9n", + "aW5SZXN1bHRTdGF0dXMSIQodTG9naW5SZXN1bHRTdGF0dXNfQmFzZURlZmF1", + "bHQQABIGCgJPSxABEg4KCkFjY291bnRFcnIQAkICSAFiBnByb3RvMw==")); descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData, 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(typeof(global::AxibugProtobuf.Protobuf_Login), global::AxibugProtobuf.Protobuf_Login.Parser, new[]{ "LoginType", "DeviceType", "Account", "Password" }, null, null, null, null), - new pbr::GeneratedClrTypeInfo(typeof(global::AxibugProtobuf.Protobuf_Login_RESP), global::AxibugProtobuf.Protobuf_Login_RESP.Parser, new[]{ "Token", "LastLoginDate", "RegDate", "Status" }, null, null, null, null), + new pbr::GeneratedClrTypeInfo(typeof(global::AxibugProtobuf.Protobuf_Login_RESP), global::AxibugProtobuf.Protobuf_Login_RESP.Parser, new[]{ "Token", "LastLoginDate", "RegDate", "Status", "UID", "NickName" }, null, null, null, null), new pbr::GeneratedClrTypeInfo(typeof(global::AxibugProtobuf.Protobuf_ChatMsg), global::AxibugProtobuf.Protobuf_ChatMsg.Parser, new[]{ "ChatMsg" }, null, null, null, null), new pbr::GeneratedClrTypeInfo(typeof(global::AxibugProtobuf.Protobuf_ChatMsg_RESP), global::AxibugProtobuf.Protobuf_ChatMsg_RESP.Parser, new[]{ "NickName", "ChatMsg", "Date" }, null, null, null, null) })); @@ -95,6 +96,10 @@ namespace AxibugProtobuf { ///TCP打洞请求 下行 对应 Protobuf_TcpTunnel_DoTunnel | Protobuf_TcpTunnel_DoTunnel_RESP /// [pbr::OriginalName("CMD_TCPTUNNEL_DO")] CmdTcptunnelDo = 5002, + /// + ///TCPP2P聊天 Protobuf_TcpP2P_Chat + /// + [pbr::OriginalName("CMD_TCP_P2P_CHAT")] CmdTcpP2PChat = 10001, } public enum ErrorCode { @@ -109,7 +114,7 @@ namespace AxibugProtobuf { /// ///用户不存在 /// - [pbr::OriginalName("ERROR_NOTFAND")] ErrorNotfand = 100, + [pbr::OriginalName("ERROR_NOTFIND")] ErrorNotfind = 100, } public enum LoginType { @@ -476,6 +481,8 @@ namespace AxibugProtobuf { lastLoginDate_ = other.lastLoginDate_; regDate_ = other.regDate_; status_ = other.status_; + uID_ = other.uID_; + nickName_ = other.nickName_; _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); } @@ -540,6 +547,34 @@ namespace AxibugProtobuf { } } + /// Field number for the "UID" field. + public const int UIDFieldNumber = 5; + private long uID_; + /// + ///UID + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public long UID { + get { return uID_; } + set { + uID_ = value; + } + } + + /// Field number for the "NickName" field. + public const int NickNameFieldNumber = 6; + private string nickName_ = ""; + /// + ///昵称 + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public string NickName { + get { return nickName_; } + set { + nickName_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public override bool Equals(object other) { return Equals(other as Protobuf_Login_RESP); @@ -557,6 +592,8 @@ namespace AxibugProtobuf { if (LastLoginDate != other.LastLoginDate) return false; if (RegDate != other.RegDate) return false; if (Status != other.Status) return false; + if (UID != other.UID) return false; + if (NickName != other.NickName) return false; return Equals(_unknownFields, other._unknownFields); } @@ -567,6 +604,8 @@ namespace AxibugProtobuf { if (LastLoginDate.Length != 0) hash ^= LastLoginDate.GetHashCode(); if (RegDate.Length != 0) hash ^= RegDate.GetHashCode(); if (Status != global::AxibugProtobuf.LoginResultStatus.BaseDefault) hash ^= Status.GetHashCode(); + if (UID != 0L) hash ^= UID.GetHashCode(); + if (NickName.Length != 0) hash ^= NickName.GetHashCode(); if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); } @@ -599,6 +638,14 @@ namespace AxibugProtobuf { output.WriteRawTag(32); output.WriteEnum((int) Status); } + if (UID != 0L) { + output.WriteRawTag(40); + output.WriteInt64(UID); + } + if (NickName.Length != 0) { + output.WriteRawTag(50); + output.WriteString(NickName); + } if (_unknownFields != null) { _unknownFields.WriteTo(output); } @@ -624,6 +671,14 @@ namespace AxibugProtobuf { output.WriteRawTag(32); output.WriteEnum((int) Status); } + if (UID != 0L) { + output.WriteRawTag(40); + output.WriteInt64(UID); + } + if (NickName.Length != 0) { + output.WriteRawTag(50); + output.WriteString(NickName); + } if (_unknownFields != null) { _unknownFields.WriteTo(ref output); } @@ -645,6 +700,12 @@ namespace AxibugProtobuf { if (Status != global::AxibugProtobuf.LoginResultStatus.BaseDefault) { size += 1 + pb::CodedOutputStream.ComputeEnumSize((int) Status); } + if (UID != 0L) { + size += 1 + pb::CodedOutputStream.ComputeInt64Size(UID); + } + if (NickName.Length != 0) { + size += 1 + pb::CodedOutputStream.ComputeStringSize(NickName); + } if (_unknownFields != null) { size += _unknownFields.CalculateSize(); } @@ -668,6 +729,12 @@ namespace AxibugProtobuf { if (other.Status != global::AxibugProtobuf.LoginResultStatus.BaseDefault) { Status = other.Status; } + if (other.UID != 0L) { + UID = other.UID; + } + if (other.NickName.Length != 0) { + NickName = other.NickName; + } _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); } @@ -698,6 +765,14 @@ namespace AxibugProtobuf { Status = (global::AxibugProtobuf.LoginResultStatus) input.ReadEnum(); break; } + case 40: { + UID = input.ReadInt64(); + break; + } + case 50: { + NickName = input.ReadString(); + break; + } } } #endif @@ -728,6 +803,14 @@ namespace AxibugProtobuf { Status = (global::AxibugProtobuf.LoginResultStatus) input.ReadEnum(); break; } + case 40: { + UID = input.ReadInt64(); + break; + } + case 50: { + NickName = input.ReadString(); + break; + } } } } diff --git a/ProtobufCore/out/ProtobufTcpTunnel.cs b/ProtobufCore/out/ProtobufTcpTunnel.cs index 3c26d84..bb80caa 100644 --- a/ProtobufCore/out/ProtobufTcpTunnel.cs +++ b/ProtobufCore/out/ProtobufTcpTunnel.cs @@ -30,15 +30,17 @@ namespace AxibugProtobuf { "Zl9UY3BUdW5uZWxfRG9UdW5uZWwSCwoDVUlEGAEgASgDEhEKCXRhcmdldFVJ", "RBgCIAEoAyJ3CiBQcm90b2J1Zl9UY3BUdW5uZWxfRG9UdW5uZWxfUkVTUBIR", "Cgl0YXJnZXRVSUQYASABKAMSDAoEbXlJUBgCIAEoCRIOCgZteVBvcnQYAyAB", - "KAUSDwoHb3RoZXJJUBgEIAEoCRIRCglvdGhlclBvcnQYBSABKAVCAkgBYgZw", - "cm90bzM=")); + "KAUSDwoHb3RoZXJJUBgEIAEoCRIRCglvdGhlclBvcnQYBSABKAUiJwoUUHJv", + "dG9idWZfVGNwUDJQX0NoYXQSDwoHQ2hhdE1zZxgBIAEoCUICSAFiBnByb3Rv", + "Mw==")); descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData, new pbr::FileDescriptor[] { }, new pbr::GeneratedClrTypeInfo(null, null, new pbr::GeneratedClrTypeInfo[] { new pbr::GeneratedClrTypeInfo(typeof(global::AxibugProtobuf.Protobuf_TcpTunnel_HellToSev), global::AxibugProtobuf.Protobuf_TcpTunnel_HellToSev.Parser, new[]{ "UID" }, null, null, null, null), new pbr::GeneratedClrTypeInfo(typeof(global::AxibugProtobuf.Protobuf_TcpTunnel_HellToSev_RESP), global::AxibugProtobuf.Protobuf_TcpTunnel_HellToSev_RESP.Parser, null, null, null, null, null), new pbr::GeneratedClrTypeInfo(typeof(global::AxibugProtobuf.Protobuf_TcpTunnel_DoTunnel), global::AxibugProtobuf.Protobuf_TcpTunnel_DoTunnel.Parser, new[]{ "UID", "TargetUID" }, null, null, null, null), - new pbr::GeneratedClrTypeInfo(typeof(global::AxibugProtobuf.Protobuf_TcpTunnel_DoTunnel_RESP), global::AxibugProtobuf.Protobuf_TcpTunnel_DoTunnel_RESP.Parser, new[]{ "TargetUID", "MyIP", "MyPort", "OtherIP", "OtherPort" }, null, null, null, null) + new pbr::GeneratedClrTypeInfo(typeof(global::AxibugProtobuf.Protobuf_TcpTunnel_DoTunnel_RESP), global::AxibugProtobuf.Protobuf_TcpTunnel_DoTunnel_RESP.Parser, new[]{ "TargetUID", "MyIP", "MyPort", "OtherIP", "OtherPort" }, null, null, null, null), + new pbr::GeneratedClrTypeInfo(typeof(global::AxibugProtobuf.Protobuf_TcpP2P_Chat), global::AxibugProtobuf.Protobuf_TcpP2P_Chat.Parser, new[]{ "ChatMsg" }, null, null, null, null) })); } #endregion @@ -913,6 +915,184 @@ namespace AxibugProtobuf { } + /// + ///TCPP2P聊天 + /// + public sealed partial class Protobuf_TcpP2P_Chat : pb::IMessage + #if !GOOGLE_PROTOBUF_REFSTRUCT_COMPATIBILITY_MODE + , pb::IBufferMessage + #endif + { + private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new Protobuf_TcpP2P_Chat()); + private pb::UnknownFieldSet _unknownFields; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pb::MessageParser Parser { get { return _parser; } } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pbr::MessageDescriptor Descriptor { + get { return global::AxibugProtobuf.ProtobufTcpTunnelReflection.Descriptor.MessageTypes[4]; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + pbr::MessageDescriptor pb::IMessage.Descriptor { + get { return Descriptor; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public Protobuf_TcpP2P_Chat() { + OnConstruction(); + } + + partial void OnConstruction(); + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public Protobuf_TcpP2P_Chat(Protobuf_TcpP2P_Chat other) : this() { + chatMsg_ = other.chatMsg_; + _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public Protobuf_TcpP2P_Chat Clone() { + return new Protobuf_TcpP2P_Chat(this); + } + + /// Field number for the "ChatMsg" field. + public const int ChatMsgFieldNumber = 1; + private string chatMsg_ = ""; + /// + ///消息 + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public string ChatMsg { + get { return chatMsg_; } + set { + chatMsg_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override bool Equals(object other) { + return Equals(other as Protobuf_TcpP2P_Chat); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool Equals(Protobuf_TcpP2P_Chat other) { + if (ReferenceEquals(other, null)) { + return false; + } + if (ReferenceEquals(other, this)) { + return true; + } + if (ChatMsg != other.ChatMsg) return false; + return Equals(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override int GetHashCode() { + int hash = 1; + if (ChatMsg.Length != 0) hash ^= ChatMsg.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 (ChatMsg.Length != 0) { + output.WriteRawTag(10); + output.WriteString(ChatMsg); + } + 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 (ChatMsg.Length != 0) { + output.WriteRawTag(10); + output.WriteString(ChatMsg); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(ref output); + } + } + #endif + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public int CalculateSize() { + int size = 0; + if (ChatMsg.Length != 0) { + size += 1 + pb::CodedOutputStream.ComputeStringSize(ChatMsg); + } + if (_unknownFields != null) { + size += _unknownFields.CalculateSize(); + } + return size; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(Protobuf_TcpP2P_Chat other) { + if (other == null) { + return; + } + if (other.ChatMsg.Length != 0) { + ChatMsg = other.ChatMsg; + } + _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 10: { + ChatMsg = input.ReadString(); + 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 10: { + ChatMsg = input.ReadString(); + break; + } + } + } + } + #endif + + } + #endregion } diff --git a/ProtobufCore/proto/protobuf_Auth.proto b/ProtobufCore/proto/protobuf_Auth.proto index d9dda24..a2835f4 100644 --- a/ProtobufCore/proto/protobuf_Auth.proto +++ b/ProtobufCore/proto/protobuf_Auth.proto @@ -17,6 +17,8 @@ enum CommandID CMD_TCPTUNNEL_HELLO = 5001; //TCP打洞请求 上行 | 下行 对应 Protobuf_TcpTunnel_HellToSev | Protobuf_TcpTunnel_HellToSev_RESP CMD_TCPTUNNEL_DO = 5002; //TCP打洞请求 下行 对应 Protobuf_TcpTunnel_DoTunnel | Protobuf_TcpTunnel_DoTunnel_RESP + + CMD_TCP_P2P_CHAT = 10001; //TCPP2P聊天 Protobuf_TcpP2P_Chat } enum ErrorCode @@ -66,6 +68,8 @@ message Protobuf_Login_RESP string LastLoginDate = 2;//上次登录时间(只用于呈现的字符串,若界面需求需要) string RegDate = 3;//注册时间(只用于呈现的字符串,若界面需求需要) LoginResultStatus Status = 4;//账号状态 (预留) [1]正常[0]被禁封 + int64 UID = 5;//UID + string NickName = 6;//昵称 } diff --git a/ProtobufCore/proto/protobuf_TcpTunnel.proto b/ProtobufCore/proto/protobuf_TcpTunnel.proto index bf0aff8..fcf042c 100644 --- a/ProtobufCore/proto/protobuf_TcpTunnel.proto +++ b/ProtobufCore/proto/protobuf_TcpTunnel.proto @@ -30,3 +30,13 @@ message Protobuf_TcpTunnel_DoTunnel_RESP string otherIP = 4;//对方的IP int32 otherPort = 5;//对方的Port } + + +////////////////////////////TCP P2P聊天////////////////// + +//TCPP2P聊天 +message Protobuf_TcpP2P_Chat +{ + string ChatMsg = 1;//消息 +} + diff --git a/Server/Program.cs b/Server/Program.cs index 56b243f..9b06c5d 100644 --- a/Server/Program.cs +++ b/Server/Program.cs @@ -1,5 +1,6 @@ using ServerCore.Manager; +Console.ForegroundColor = ConsoleColor.Green; ServerManager.InitServer(23846, 23847); while (true) @@ -12,6 +13,9 @@ while (true) case "list": Console.WriteLine("当前在线:" + ServerManager.g_ClientMgr.GetOnlineClientCount()); break; + case "tlist": + Console.WriteLine("当前TcpTunnel在线:" + ServerManager.g_TcpTunnelMgr.GetOnlineClientCount()); + break; default: Console.WriteLine("未知命令" + CommandStr); break; diff --git a/ServerCore/Common/Enum/CommEnum.cs b/ServerCore/Common/Enum/CommEnum.cs new file mode 100644 index 0000000..9b14ae6 --- /dev/null +++ b/ServerCore/Common/Enum/CommEnum.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ServerCore.Common.Enum +{ + public enum ServerType + { + MainServer, + TcpTunnelServer + } +} diff --git a/ServerCore/Event/EEvent.cs b/ServerCore/Event/EEvent.cs index a2d126e..8e126e8 100644 --- a/ServerCore/Event/EEvent.cs +++ b/ServerCore/Event/EEvent.cs @@ -10,6 +10,10 @@ namespace ServerCore.Event { // 添加你自己需要的事件类型 OnUserJoin, - OnUserLeave + OnUserLeave, + + + //连接管理 + OnSocketDisconnect, } } diff --git a/ServerCore/Manager/ClientManager.cs b/ServerCore/Manager/ClientManager.cs index eeaf3a1..f3a8556 100644 --- a/ServerCore/Manager/ClientManager.cs +++ b/ServerCore/Manager/ClientManager.cs @@ -1,4 +1,5 @@ using AxibugProtobuf; +using ServerCore.Common.Enum; using ServerCore.Event; using System.Net.Sockets; using System.Timers; @@ -26,40 +27,51 @@ namespace ServerCore.Manager private long _RemoveOfflineCacheMin; + public ClientManager() + { + //事件 + EventSystem.Instance.RegisterEvent(EEvent.OnSocketDisconnect, OnSocketDisconnect); + } + #region 事件 + void OnSocketDisconnect(ServerType serverType, Socket socket) + { + if (serverType != ServerType.MainServer) + return; - + RemoveClientBySocket(socket); + } #endregion - public void Init(long ticktime, long RemoveOfflineCacheMin) - { - //换算成毫秒 - _RemoveOfflineCacheMin = RemoveOfflineCacheMin * 1000; - _ClientCheckTimer = new System.Timers.Timer(); - _ClientCheckTimer.Interval = ticktime; - _ClientCheckTimer.AutoReset = true; - _ClientCheckTimer.Elapsed += new ElapsedEventHandler(ClientCheckClearOffline_Elapsed); - _ClientCheckTimer.Enabled = true; - } + //public void Init(long ticktime, long RemoveOfflineCacheMin) + //{ + // //换算成毫秒 + // _RemoveOfflineCacheMin = RemoveOfflineCacheMin * 1000; + // _ClientCheckTimer = new System.Timers.Timer(); + // _ClientCheckTimer.Interval = ticktime; + // _ClientCheckTimer.AutoReset = true; + // _ClientCheckTimer.Elapsed += new ElapsedEventHandler(ClientCheckClearOffline_Elapsed); + // _ClientCheckTimer.Enabled = true; + //} public long GetNextUID() { return ++TestUIDSeed; } - private void ClientCheckClearOffline_Elapsed(object sender, ElapsedEventArgs e) - { - DateTime CheckDT = DateTime.Now.AddMinutes(-1 * _RemoveOfflineCacheMin); - ClientInfo[] OfflineClientlist = ClientList.Where(w => w.IsOffline == true && w.LogOutDT < CheckDT).ToArray(); + //private void ClientCheckClearOffline_Elapsed(object sender, ElapsedEventArgs e) + //{ + // DateTime CheckDT = DateTime.Now.AddMinutes(-1 * _RemoveOfflineCacheMin); + // ClientInfo[] OfflineClientlist = ClientList.Where(w => w.IsOffline == true && w.LogOutDT < CheckDT).ToArray(); - Console.WriteLine("开始清理离线过久的玩家的缓存"); - for (int i = 0; i < OfflineClientlist.Length; i++) - { - //to do 掉线处理 - RemoveClient(OfflineClientlist[i]); - } - GC.Collect(); - } + // Console.WriteLine("开始清理离线过久的玩家的缓存"); + // for (int i = 0; i < OfflineClientlist.Length; i++) + // { + // //to do 掉线处理 + // RemoveClient(OfflineClientlist[i]); + // } + // GC.Collect(); + //} //通用处理 @@ -118,6 +130,8 @@ namespace ServerCore.Manager /// public void RemoveClient(ClientInfo client) { + EventSystem.Instance.PostEvent(EEvent.OnUserLeave, client.UID); + lock (ClientList) { if (_DictUIDClient.ContainsKey(client.UID)) @@ -150,22 +164,21 @@ namespace ServerCore.Manager } - /// - /// 设置玩家离线 - /// - /// - public void SetClientOfflineForSocket(Socket sk) - { - if (!_DictSocketClient.ContainsKey(sk)) - return; + ///// + ///// 设置玩家离线 + ///// + ///// + //public void SetClientOfflineForSocket(Socket sk) + //{ + // if (!_DictSocketClient.ContainsKey(sk)) + // return; + // Console.WriteLine("标记玩家UID" + _DictSocketClient[sk].UID + "为离线"); + // _DictSocketClient[sk].IsOffline = true; + // _DictSocketClient[sk].LogOutDT = DateTime.Now; + // EventSystem.Instance.PostEvent(EEvent.OnUserLeave, _DictSocketClient[sk].UID); + //} - Console.WriteLine("标记玩家UID" + _DictSocketClient[sk].UID + "为离线"); - _DictSocketClient[sk].IsOffline = true; - _DictSocketClient[sk].LogOutDT = DateTime.Now; - EventSystem.Instance.PostEvent(EEvent.OnUserLeave, _DictSocketClient[sk].UID); - } - - public void RemoveClientForSocket(Socket sk) + public void RemoveClientBySocket(Socket sk) { if (!_DictSocketClient.ContainsKey(sk)) return; diff --git a/ServerCore/Manager/LoginManager.cs b/ServerCore/Manager/LoginManager.cs index 05d39b8..3792baa 100644 --- a/ServerCore/Manager/LoginManager.cs +++ b/ServerCore/Manager/LoginManager.cs @@ -23,7 +23,9 @@ namespace ServerCore.Manager Status = LoginResultStatus.Ok, RegDate = "", LastLoginDate = "", - Token = "" + Token = "", + UID = cinfo.UID, + NickName= cinfo.NickName, }); ServerManager.g_ClientMgr.ClientSend(cinfo, (int)CommandID.CmdLogin, (int)ErrorCode.ErrorOk, respData); diff --git a/ServerCore/Manager/ServerManager.cs b/ServerCore/Manager/ServerManager.cs index a3183b6..a7430cf 100644 --- a/ServerCore/Manager/ServerManager.cs +++ b/ServerCore/Manager/ServerManager.cs @@ -10,7 +10,7 @@ namespace ServerCore.Manager public static LogManager g_Log; public static LoginManager g_Login; public static ChatManager g_Chat; - public static P2PUserManager g_P2PMgr; + public static UserManager g_UserMgr; public static TcpTunnelClientManager g_TcpTunnelMgr; public static IOCPNetWork g_SocketMgr; public static IOCPNetWork g_SocketTcpTunnelMgr; @@ -18,16 +18,17 @@ namespace ServerCore.Manager public static void InitServer(int port, int tcptunnelport) { g_ClientMgr = new ClientManager(); + //g_ClientMgr.Init(10000, 10000); g_Log = new LogManager(); g_Login = new LoginManager(); g_Chat = new ChatManager(); - g_P2PMgr = new P2PUserManager(); + g_UserMgr = new UserManager(); g_TcpTunnelMgr = new TcpTunnelClientManager(); - g_SocketMgr = new IOCPNetWork(1024, 1024); + g_SocketMgr = new IOCPNetWork(1024, 1024,Common.Enum.ServerType.MainServer); g_SocketMgr.Init(); Console.WriteLine("监听:" + port); g_SocketMgr.Start(new IPEndPoint(IPAddress.Any.Address, port)); - g_SocketTcpTunnelMgr = new IOCPNetWork(1024, 1024); + g_SocketTcpTunnelMgr = new IOCPNetWork(1024, 1024, Common.Enum.ServerType.TcpTunnelServer); g_SocketTcpTunnelMgr.Init(); g_SocketTcpTunnelMgr.Start(new IPEndPoint(IPAddress.Any.Address, tcptunnelport)); Console.WriteLine("监听:" + tcptunnelport); diff --git a/ServerCore/Manager/TcpTunnelClientManager.cs b/ServerCore/Manager/TcpTunnelClientManager.cs index 7b97fbc..9e47a99 100644 --- a/ServerCore/Manager/TcpTunnelClientManager.cs +++ b/ServerCore/Manager/TcpTunnelClientManager.cs @@ -1,5 +1,6 @@ using AxibugProtobuf; using ServerCore.Common; +using ServerCore.Common.Enum; using ServerCore.Event; using ServerCore.NetWork; using System.Collections.Generic; @@ -22,15 +23,29 @@ namespace ServerCore.Manager public class TcpTunnelClientManager { + private System.Timers.Timer _ClientCheckTimer; + private long _RemoveOfflineCacheMin; public TcpTunnelClientManager() { + //消息注册 NetMsg.Instance.RegNetMsgEvent((int)CommandID.CmdTcptunnelHello, TcpTunnelHello); NetMsg.Instance.RegNetMsgEvent((int)CommandID.CmdTcptunnelDo, TcptunnelDo); + //事件注册 + EventSystem.Instance.RegisterEvent(EEvent.OnSocketDisconnect, OnSocketDisconnect); } private Dictionary _DictUID2Client = new Dictionary(); private Dictionary _DictScoket2Client = new Dictionary(); + #region 事件 + void OnSocketDisconnect(ServerType serverType, Socket socket) + { + if (serverType != ServerType.TcpTunnelServer) + return; + + RemoveClientBySocket(socket); + } + #endregion void AddClient(long UID,Socket _socket) { IPEndPoint ipEndPoint = (IPEndPoint)_socket.RemoteEndPoint; @@ -44,6 +59,7 @@ namespace ServerCore.Manager _Socket = _socket }; _DictScoket2Client[_socket] = cinfo; + _DictUID2Client[UID] = cinfo; } else { @@ -69,8 +85,7 @@ namespace ServerCore.Manager { if (_DictScoket2Client.ContainsKey(_socket)) { - _DictUID2Client.Remove(_DictScoket2Client[_socket].UID); - _DictScoket2Client.Remove(_socket); + RemoveClient(_DictScoket2Client[_socket].UID); } } @@ -98,13 +113,15 @@ namespace ServerCore.Manager ServerManager.g_Log.Debug("收到TcpTunnel 打洞端口Hello"); Protobuf_TcpTunnel_DoTunnel msg = ProtoBufHelper.DeSerizlize(reqData); TCPTunnelClientInfo Other = GetClient(msg.TargetUID); - if (Other == null) + + if (Other == null || msg.UID == msg.TargetUID) { Protobuf_TcpTunnel_DoTunnel_RESP respToErr = new Protobuf_TcpTunnel_DoTunnel_RESP(); - ClientSend(msg.UID, (int)CommandID.CmdTcptunnelDo, (int)ErrorCode.ErrorNotfand, ProtoBufHelper.Serizlize(respToErr)); + ClientSend(msg.UID, (int)CommandID.CmdTcptunnelDo, (int)ErrorCode.ErrorNotfind, ProtoBufHelper.Serizlize(respToErr)); return; } + //发给自己 TCPTunnelClientInfo mine = GetClient(msg.UID); Protobuf_TcpTunnel_DoTunnel_RESP respToMine = new Protobuf_TcpTunnel_DoTunnel_RESP() { @@ -114,9 +131,9 @@ namespace ServerCore.Manager OtherPort= Other.Port, TargetUID = msg.TargetUID, }; - ClientSend(msg.UID, (int)CommandID.CmdTcptunnelHello, (int)ErrorCode.ErrorOk, ProtoBufHelper.Serizlize(respToMine)); - + ClientSend(msg.UID, (int)CommandID.CmdTcptunnelDo, (int)ErrorCode.ErrorOk, ProtoBufHelper.Serizlize(respToMine)); + //发给对方 Protobuf_TcpTunnel_DoTunnel_RESP respToOther = new Protobuf_TcpTunnel_DoTunnel_RESP() { MyIP = Other.IP, @@ -125,11 +142,18 @@ namespace ServerCore.Manager OtherPort = mine.Port, TargetUID = msg.UID, }; - ClientSend(msg.TargetUID, (int)CommandID.CmdTcptunnelHello, (int)ErrorCode.ErrorOk, ProtoBufHelper.Serizlize(respToOther)); + ClientSend(msg.TargetUID, (int)CommandID.CmdTcptunnelDo, (int)ErrorCode.ErrorOk, ProtoBufHelper.Serizlize(respToOther)); + + //TODO 暂时服务器不断开,交由客户端收到后主动断开 + + //断开两边 + //mine._Socket.Close(); + //TCPTunnelClientInfo other = GetClient(msg.TargetUID); + //other._Socket.Close(); } /// - /// 错误 + /// /// /// /// @@ -142,5 +166,10 @@ namespace ServerCore.Manager ServerManager.g_SocketTcpTunnelMgr.SendToSocket(_DictUID2Client[UID]._Socket, CMDID, ERRCODE, data); } } + + public int GetOnlineClientCount() + { + return _DictUID2Client.Count(); + } } } diff --git a/ServerCore/Manager/P2PUserManager.cs b/ServerCore/Manager/UserManager.cs similarity index 97% rename from ServerCore/Manager/P2PUserManager.cs rename to ServerCore/Manager/UserManager.cs index 8152373..b4eb80d 100644 --- a/ServerCore/Manager/P2PUserManager.cs +++ b/ServerCore/Manager/UserManager.cs @@ -9,9 +9,9 @@ using System.Timers; namespace ServerCore.Manager { - public class P2PUserManager + public class UserManager { - public P2PUserManager() + public UserManager() { NetMsg.Instance.RegNetMsgEvent((int)CommandID.CmdUserOnlinelist, RecvGetUserList); @@ -21,7 +21,7 @@ namespace ServerCore.Manager } - #region + #region 事件 void OnUserJoin(long UID) { ServerManager.g_Log.Debug($"P2PUserManager->OnUserJoin UID->{UID}"); diff --git a/ServerCore/NetWork/IOCPNetWork.cs b/ServerCore/NetWork/IOCPNetWork.cs index be41f65..b45e8fb 100644 --- a/ServerCore/NetWork/IOCPNetWork.cs +++ b/ServerCore/NetWork/IOCPNetWork.cs @@ -1,15 +1,21 @@ using AxibugProtobuf; using HaoYueNet.ServerNetwork; +using ServerCore.Common.Enum; +using ServerCore.Event; using ServerCore.Manager; +using System.Net; using System.Net.Sockets; namespace ServerCore.NetWork { public class IOCPNetWork : SocketManager { - public IOCPNetWork(int numConnections, int receiveBufferSize) + ServerType mServerType; + public IOCPNetWork(int numConnections, int receiveBufferSize, ServerType serverType) : base(numConnections, receiveBufferSize) { + mServerType = serverType; + m_clientCount = 0; m_maxConnectNum = numConnections; m_revBufferSize = receiveBufferSize; @@ -38,22 +44,25 @@ namespace ServerCore.NetWork /// 业务数据 public override void DataCallBack(AsyncUserToken token, int CMDID, byte[] data) { - DataCallBackToOld(token.Socket, CMDID, data); + //DataCallBackToOld(token.Socket, CMDID, data); + ServerManager.g_Log.Debug("收到消息 CMDID =>" + CMDID + " 数据长度=>" + data.Length); + //抛出网络数据 + NetMsg.Instance.PostNetMsgEvent(CMDID, token.Socket, data); } - public void DataCallBackToOld(Socket sk, int CMDID, byte[] data) - { - ServerManager.g_Log.Debug("收到消息 CMDID =>" + CMDID + " 数据长度=>" + data.Length); - try - { - //抛出网络数据 - NetMsg.Instance.PostNetMsgEvent(CMDID, sk, data); - } - catch (Exception ex) - { - Console.WriteLine("逻辑处理错误:" + ex.ToString()); - } - } + //public void DataCallBackToOld(Socket sk, int CMDID, byte[] data) + //{ + // ServerManager.g_Log.Debug("收到消息 CMDID =>" + CMDID + " 数据长度=>" + data.Length); + // try + // { + // //抛出网络数据 + // NetMsg.Instance.PostNetMsgEvent(CMDID, sk, data); + // } + // catch (Exception ex) + // { + // Console.WriteLine("逻辑处理错误:" + ex.ToString()); + // } + //} /// /// 断开连接 @@ -61,10 +70,10 @@ namespace ServerCore.NetWork /// public override void OnClose(AsyncUserToken token) { - Console.WriteLine("断开连接"); + ServerManager.g_Log.Debug($"断开连接,ServerType->{mServerType} | {((IPEndPoint)token.Socket.LocalEndPoint).Address}"); + //ServerManager.g_ClientMgr.SetClientOfflineForSocket(token.Socket); //TODO 要删除不同的 - ServerManager.g_ClientMgr.SetClientOfflineForSocket(token.Socket); - s + EventSystem.Instance.PostEvent(EEvent.OnSocketDisconnect, mServerType, token.Socket); } } } diff --git a/ServerCore/NetWork/NetMsg.cs b/ServerCore/NetWork/NetMsg.cs index 39acb0f..be4eb1f 100644 --- a/ServerCore/NetWork/NetMsg.cs +++ b/ServerCore/NetWork/NetMsg.cs @@ -65,18 +65,19 @@ namespace ServerCore.NetWork public void PostNetMsgEvent(int cmd, Socket arg1, byte[] arg2) { List eventList = GetNetEventDicList(cmd); - if (eventList != null) + if (eventList == null) + return; + + for (int i = 0; i < eventList.Count; i++) { - foreach (Delegate callback in eventList) + Delegate callback = eventList[i]; + try { - try - { - ((Action)callback)(arg1, arg2); - } - catch (Exception e) - { - ServerManager.g_Log.Error(e.Message); - } + ((Action)callback)(arg1, arg2); + } + catch (Exception e) + { + ServerManager.g_Log.Error(e.Message); } } }