protected override bool DoSuccess(int userId, out IUser user) { user = null; var cache = new MemoryCacheStruct <ChatUser>(); ChatUser chatUser = cache.Find(t => t.UserName == _userName); if (chatUser != null) { user = chatUser; return(true); } return(false); }
protected override void OnDisconnected(GameSession session) { var user = session.User as SessionUser; if (user != null) { var cache = new MemoryCacheStruct <ChatUser>(); ChatUser chatUser = cache.Find(t => t.UserId == user.UserId); if (chatUser != null && session.SessionId == chatUser.SessionId) { cache.TryRemove(user.UserId.ToString()); } } base.OnDisconnected(session); }
public bool CheckLogin() { var cache = new MemoryCacheStruct<ChatUser>(); ChatUser chatUser = cache.Find(t => t.UserName == PassportID); if (chatUser != null) { UserID = chatUser.UserId.ToString(); return true; } //not user create it. chatUser = new ChatUser() { UserId = (int)RedisConnectionPool.GetNextNo(typeof(ChatUser).FullName), UserName = PassportID, AccessTime = DateTime.Now }; if (cache.TryAdd(chatUser.UserId.ToString(), chatUser)) { UserID = chatUser.UserId.ToString(); return true; } return false; }
public override bool TakeAction() { SessionUser user = null; try { var cache = new MemoryCacheStruct <ChatUser>(); ChatUser chatUser = cache.Find(t => t.UserId == _userId); if (chatUser == null) { chatUser = new ChatUser() { UserId = _userId, SessionId = Current.SessionId, GuildID = string.Empty }; cache.TryAdd(_userId.ToString(), chatUser); } user = new SessionUser() { PassportId = _userId.ToString(), UserId = _userId }; Current.Bind(user); return(true); } catch (Exception ex) { SaveLog(ex); ErrorCode = Language.Instance.ErrorCode; ErrorInfo = Language.Instance.ValidateError; return(false); } }
public bool CheckLogin() { var cache = new MemoryCacheStruct <ChatUser>(); ChatUser chatUser = cache.Find(t => t.UserName == PassportID); if (chatUser != null) { UserID = chatUser.UserId.ToString(); return(true); } //not user create it. chatUser = new ChatUser() { UserId = (int)RedisConnectionPool.GetNextNo(typeof(ChatUser).FullName), UserName = PassportID, AccessTime = DateTime.Now }; if (cache.TryAdd(chatUser.UserId.ToString(), chatUser)) { UserID = chatUser.UserId.ToString(); return(true); } return(false); }
protected override void TakeRemote() { var session = paramGetter.GetSession(); if (session == null) { ErrorCode = 10000; ErrorInfo = "Sessin is null."; return; } var cache = new MemoryCacheStruct <ChatUser>(); ChatUser chatUser = cache.Find(t => t.UserId == _userId); if (chatUser != null) { chatUser.UserName = _userName; chatUser.VipLv = _vipLv; chatUser.Profession = _profession; chatUser.AvatarUrl = _avatarUrl; chatUser.ServerID = _serverID; chatUser.GuildID = _guildID; } }
protected override void TakeRemote() { var remoteSession = paramGetter.GetSession(); if (remoteSession == null) { ErrorCode = 10000; ErrorInfo = "RemoteSession is null."; return; } switch (_chatType) { case ChatType.AllService: { var cache = new MemoryCacheStruct <ChatUser>(); var Sender = cache.Find(t => (t.UserId == _sender)); if (Sender != null) { var sessionlist = GameSession.GetAll(); foreach (var on in sessionlist) { if (on.Connected && !on.IsRemote) { MsgData data = new MsgData(); data.Type = MsgType.Chat; data.UserId = on.UserId; var parameters = new Parameters(); parameters["Type"] = ChatType.AllService; parameters["Sender"] = _sender; parameters["SenderName"] = Sender.UserName; parameters["SenderVipLv"] = Sender.VipLv; parameters["SenderProfession"] = Sender.Profession; parameters["SenderAvatarUrl"] = Sender.AvatarUrl; parameters["ServerID"] = _serverID; parameters["SendDate"] = _sendDate; parameters["Content"] = _content; data.Param = parameters; MsgDispatcher.Push(data); } } } } break; case ChatType.World: { var cache = new MemoryCacheStruct <ChatUser>(); var Sender = cache.Find(t => (t.UserId == _sender)); if (Sender != null) { var list = cache.FindAll(t => t.ServerID == Sender.ServerID); foreach (var v in list) { var session = GameSession.Get(v.UserId); if (session != null && session.Connected && !session.IsRemote) { MsgData data = new MsgData(); data.Type = MsgType.Chat; data.UserId = v.UserId; var parameters = new Parameters(); parameters["Type"] = ChatType.World; parameters["Sender"] = _sender; parameters["SenderName"] = Sender.UserName; parameters["SenderVipLv"] = Sender.VipLv; parameters["SenderProfession"] = Sender.Profession; parameters["SenderAvatarUrl"] = Sender.AvatarUrl; parameters["ServerID"] = _serverID; parameters["SendDate"] = _sendDate; parameters["Content"] = _content; data.Param = parameters; MsgDispatcher.Push(data); } } } } break; case ChatType.Whisper: { var cache = new MemoryCacheStruct <ChatUser>(); var Sender = cache.Find(t => (t.UserId == _sender)); var Receiver = cache.Find(t => (t.UserId == _reveiver)); if (Sender != null && Receiver != null) { var session = GameSession.Get(_reveiver); if (session != null && session.Connected && !session.IsRemote) { MsgData data = new MsgData(); data.Type = MsgType.Chat; data.UserId = _reveiver; var parameters = new Parameters(); parameters["Type"] = ChatType.Whisper; parameters["Sender"] = _sender; parameters["SenderName"] = Sender.UserName; parameters["SenderVipLv"] = Sender.VipLv; parameters["SenderProfession"] = Sender.Profession; parameters["SenderAvatarUrl"] = Sender.AvatarUrl; parameters["ServerID"] = _serverID; parameters["SendDate"] = _sendDate; parameters["Content"] = _content; data.Param = parameters; MsgDispatcher.Push(data); } } } break; case ChatType.Guild: { var cache = new MemoryCacheStruct <ChatUser>(); var Sender = cache.Find(t => (t.UserId == _sender)); if (Sender != null) { if (Sender.GuildID.IsEmpty()) { return; } var list = cache.FindAll(t => t.GuildID == Sender.GuildID); foreach (var v in list) { var session = GameSession.Get(v.UserId); if (session != null && session.Connected && !session.IsRemote) { MsgData data = new MsgData(); data.Type = MsgType.Chat; data.UserId = v.UserId; var parameters = new Parameters(); parameters["Type"] = ChatType.Guild; parameters["Sender"] = _sender; parameters["SenderName"] = Sender.UserName; parameters["SenderVipLv"] = Sender.VipLv; parameters["SenderProfession"] = Sender.Profession; parameters["SenderAvatarUrl"] = Sender.AvatarUrl; parameters["ServerID"] = _serverID; parameters["SendDate"] = _sendDate; parameters["Content"] = _content; data.Param = parameters; MsgDispatcher.Push(data); } } } } break; case ChatType.System: { var cache = new MemoryCacheStruct <ChatUser>(); var Receiver = cache.Find(t => (t.UserId == _reveiver)); if (Receiver != null) { var session = GameSession.Get(_reveiver); if (session != null && session.Connected && !session.IsRemote) { MsgData data = new MsgData(); data.Type = MsgType.Chat; data.UserId = _reveiver; var parameters = new Parameters(); parameters["Type"] = ChatType.System; parameters["Sender"] = 0; parameters["SenderName"] = "系统"; parameters["SenderVipLv"] = 0; parameters["SenderProfession"] = 0; parameters["SenderAvatarUrl"] = string.Empty; parameters["ServerID"] = _serverID; parameters["SendDate"] = _sendDate; parameters["Content"] = _content; data.Param = parameters; MsgDispatcher.Push(data); } } } break; } }
public T GetData(Predicate <T> match) { return(m_Table.Find(match)); }
protected override bool DoSuccess(int userId, out IUser user) { user = null; var cache = new MemoryCacheStruct<ChatUser>(); ChatUser chatUser = cache.Find(t => t.UserName == _userName); if (chatUser != null) { user = chatUser; return true; } return false; }