public void _RegSession(ZYNetServer Server, ReadBytes read, ZYNetSession session) { RegSession regSession; if (read.ReadObject <RegSession>(out regSession)) { session.LANIP = regSession.LocalHost; session.Group = regSession.Group; if (!Server.SessionDiy.ContainsKey(session.Id)) { regSession.Id = session.Id; regSession.IsSuccess = true; regSession.Port = Server.RegPort; Server.SessionDiy.AddOrUpdate(session.Id, session, (a, b) => session); Server.Send(session, BufferFormat.FormatFCA(regSession)); AddSession add = new AddSession() { Id = regSession.Id }; Server.SendAll(BufferFormat.FormatFCA(add)); } else { regSession.IsSuccess = false; regSession.Msg = "User Id Is Have"; Server.Send(session, BufferFormat.FormatFCA(regSession)); Server.Service.Disconnect(session.Asyn.AcceptSocket); } } }
public void _SetGroup(ZYNetServer Server, ReadBytes read, ZYNetSession session) { int group; if (read.ReadInt32(out group)) { session.Group = group; } }
public static ZYNetServer GetInstance() { lock (lockthis) { if (_My == null) { _My = new ZYNetServer(); } } return(_My); }
public void _LEFTConnect(ZYNetServer Server, ReadBytes read, ZYNetSession session) { long ToId; if (read.ReadInt64(out ToId)) { if (Server.SessionDiy.ContainsKey(ToId) && !string.IsNullOrEmpty(session.WANIP) && session.WANPort != 0) { ZYNetSession toUser = Server.SessionDiy[ToId]; if (toUser.Group != session.Group) { return; } if (!session.WANIP.Equals(toUser.WANIP)) //如果不再一个局域网内 { LEFTConnect tmp = new LEFTConnect() { Id = session.Id, Host = session.WANIP, Port = session.WANPort, IsSuccess = true }; Server.Send(toUser, BufferFormat.FormatFCA(tmp)); } else //同局域网内 { LEFTConnect tmp = new LEFTConnect() { Id = session.Id, Host = session.LANIP, Port = session.NatNextPort, IsSuccess = true }; Server.Send(toUser, BufferFormat.FormatFCA(tmp)); } } } }
public void _GetAllSession(ZYNetServer Server, ReadBytes read, ZYNetSession session) { GetAllSession pack; if (read.ReadObject <GetAllSession>(out pack)) { var userlist = Server.SessionDiy.Values.Where(p => p.Group == session.Group && p.Id != session.Id); pack.UserIds = new List <long>(); foreach (var item in userlist) { pack.UserIds.Add(item.Id); } pack.IsSuccess = true; Server.Send(session, BufferFormat.FormatFCA(pack)); } }