Esempio n. 1
0
        /// <summary>
        /// 获取某个用户的所有联系人(组友,好友)。
        /// 建议:由于该方法经常被调用,可将组友关系缓存在内存中,而非每次都遍历计算一遍。
        /// </summary>
        public List <string> GetAllContacts(string userID)
        {
            List <string> contacts = new List <string>();
            GGUser        user     = this.userCache.Get(userID);

            if (user == null)
            {
                return(contacts);
            }

            contacts = user.GetAllFriendList();
            foreach (string groupID in user.GroupList)
            {
                GGGroup g = this.groupCache.Get(groupID);
                if (g != null)
                {
                    foreach (string memberID in g.MemberList)
                    {
                        if (memberID != userID && !contacts.Contains(memberID))
                        {
                            contacts.Add(memberID);
                        }
                    }
                }
            }

            return(contacts);
        }
Esempio n. 2
0
        private void btnClose_Click(object sender, EventArgs e)
        {
            string groupID = this.skinTextBox_id.SkinTxt.Text.Trim();
            if (groupID.Length == 0)
            {
                MessageBoxEx.Show("群帐号不能为空!");
                this.DialogResult = System.Windows.Forms.DialogResult.None;
                return;
            }

            try
            {
                CreateGroupContract contract = new CreateGroupContract(groupID, this.skinTextBox_name.SkinTxt.Text.Trim() ,this.skinTextBox_announce.SkinTxt.Text);
                byte[] bRes = this.rapidPassiveEngine.CustomizeOutter.Query(InformationTypes.CreateGroup, CompactPropertySerializer.Default.Serialize(contract));
                CreateGroupResult res = (CreateGroupResult)BitConverter.ToInt32(bRes, 0);
                if (res == CreateGroupResult.GroupExisted)
                {
                    MessageBoxEx.Show("同ID的群已经存在!");
                    this.DialogResult = System.Windows.Forms.DialogResult.None;
                    return;
                }

                this.group = new GGGroup(groupID, contract.Name,this.rapidPassiveEngine.CurrentUserID,"",this.rapidPassiveEngine.CurrentUserID);
                this.DialogResult = System.Windows.Forms.DialogResult.OK;
            }
            catch (Exception ee)
            {
                MessageBoxEx.Show("创建群失败!" + ee.Message);
                this.DialogResult = System.Windows.Forms.DialogResult.None;
            }
        }
Esempio n. 3
0
        /// <summary>
        /// 加入某个组。
        /// </summary>
        public JoinGroupResult JoinGroup(string userID, string groupID)
        {
            GGGroup group = this.groupCache.Get(groupID);

            if (group == null)
            {
                return(JoinGroupResult.GroupNotExist);
            }

            GGUser user = this.userCache.Get(userID);

            if (!user.GroupList.Contains(groupID))
            {
                user.JoinGroup(groupID);
                this.dbPersister.ChangeUserGroups(user.UserID, user.Groups);
            }

            if (!group.MemberList.Contains(userID))
            {
                group.AddMember(userID);
                this.dbPersister.UpdateGroup(group);
            }

            return(JoinGroupResult.Succeed);
        }
Esempio n. 4
0
        /// <summary>
        /// 添加好友
        /// </summary>
        /// <param name="userId"></param>
        /// <returns></returns>
        public static bool AddFriend(GGGroup defaultGroup, int friendAutoId)
        {
            string members = defaultGroup.members + "," + friendAutoId;
            string sql     = string.Format("UPDATE [dbo].[{0}] SET [members] = '{1}' WHERE groupAutoId={2}", DBTUtils.DBT_GGGroup, members, defaultGroup.groupAutoId);
            int    row     = DBHelper.Excute(sql);

            return(row > 0 ? true : false);
        }
Esempio n. 5
0
        /// <summary>
        /// 删除好友
        /// </summary>
        /// <param name="group"></param>
        /// <param name="friendAutoId"></param>
        /// <returns></returns>
        public static bool DelFriend(GGGroup group, string friendAutoId)
        {
            string members = group.members.Replace("," + friendAutoId, "");
            string sql     = string.Format("UPDATE [dbo].[{0}] SET [members] = '{1}' WHERE groupAutoId={2}", DBTUtils.DBT_GGGroup, members, group.groupAutoId);
            int    row     = DBHelper.Excute(sql);

            return(row > 0 ? true : false);
        }
Esempio n. 6
0
 public void UpdateGroup(GGGroup t)
 {
     using (var scope = _transactionScopeFactory.NewTransactionScope())
     {
         var accessor = scope.NewOrmAccesser <GGGroup>();
         accessor.Update(t);
         scope.Commit();
     }
 }
Esempio n. 7
0
 public void InsertGroup(GGGroup t)
 {
     using (TransactionScope scope = this.transactionScopeFactory.NewTransactionScope())
     {
         IOrmAccesser <GGGroup> accesser = scope.NewOrmAccesser <GGGroup>();
         accesser.Insert(t);
         scope.Commit();
     }
 }
Esempio n. 8
0
        /// <summary>
        /// 检查是否存在默认分组,不存在则添加
        /// </summary>
        /// <param name="fromInfo"></param>
        private static void CheckDefaultGroup(MessageInfo fromInfo)
        {
            GGUserInfo tmpUser      = ChatDBUtils.GetPerInfoByUserId(fromInfo.fromId);
            GGGroup    defaultGroup = ChatDBUtils.GetDefaultGroup(tmpUser.userId);

            if (defaultGroup == null)
            {
                ChatDBUtils.CreateGroup(tmpUser, "我的好友", true);
            }
        }
Esempio n. 9
0
 public void UpdateGroup(GGGroup t)
 {
     using (TransactionScope scope = this.transactionScopeFactory.NewTransactionScope())
     {
         IOrmAccesser <GGGroup> accesser = scope.NewOrmAccesser <GGGroup>();
         t.Version += 1;  //2018.09.25
         accesser.Update(t);
         scope.Commit();
     }
 }
        public List <string> GetGroupMemberList(string groupID)
        {
            GGGroup group = this.globalCache.GetGroup(groupID);

            if (group == null)
            {
                return(new List <string>());
            }

            return(group.MemberList);
        }
Esempio n. 11
0
        public GGGroup GetGroup(string groupID)
        {
            GGGroup group = null;

            using (TransactionScope scope = this.transactionScopeFactory.NewTransactionScope())
            {
                IOrmAccesser <GGGroup> accesser = scope.NewOrmAccesser <GGGroup>();
                group = accesser.GetOne(groupID);
                scope.Commit();
            }
            return(group);
        }
Esempio n. 12
0
        /// <summary>
        /// 解除禁止发言
        /// </summary>
        public void SetAllowSpeakGroup(string userID, string groupID)
        {
            GGGroup group = this.groupCache.Get(groupID);

            if (group != null)
            {
                group.RemoveNoSpeak(userID);
            }
            this.dbPersister.UpdateGroup(group);

            // GGUser user = this.userCache.Get(userID);
            // user.QuitGroup(groupID);
            this.dbPersister.ChangeUserGroups(userID, groupID);
        }
Esempio n. 13
0
        /// <summary>
        /// 添加管理员
        /// </summary>
        public void AddManagerGroup(string userID, string groupID)
        {
            GGGroup group = this.groupCache.Get(groupID);

            if (group != null)
            {
                group.AddManager(userID);
            }
            this.dbPersister.UpdateGroup(group);

            // GGUser user = this.userCache.Get(userID);
            // user.QuitGroup(groupID);
            this.dbPersister.ChangeUserGroups(userID, groupID);
        }
Esempio n. 14
0
        /// <summary>
        /// 踢人
        /// </summary>
        public void RemoveMemberGroup(string userID, string groupID)
        {
            GGGroup group = this.groupCache.Get(groupID);

            if (group != null)
            {
                group.RemoveMember(userID);
            }
            this.dbPersister.UpdateGroup(group);

            GGUser user = this.userCache.Get(userID);

            user.QuitGroup(groupID);
            this.dbPersister.ChangeUserGroups(userID, groupID);
        }
Esempio n. 15
0
        public void UpdateGroup(GGGroup group)
        {
            GGGroup old = this.groupCache.Get(group.ID);

            if (old == null)
            {
                return;
            }

            //user.Friends = old.Friends;       //0922
            //user.Groups = old.Groups;  //0922

            group.Version = old.Version + 1;
            this.groupCache.Add(group.ID, group);

            this.dbPersister.UpdateGroup(group);
        }
Esempio n. 16
0
        /// <summary>
        /// 创建组
        /// </summary>
        public CreateGroupResult CreateGroup(string creatorID, string groupID, string groupName, string announce, string admin, string noSpeak)
        {
            if (this.groupCache.Contains(groupID))
            {
                return(CreateGroupResult.GroupExisted);
            }

            GGGroup group = new GGGroup(groupID, groupName, creatorID, announce, creatorID, admin, noSpeak);

            this.groupCache.Add(groupID, group);
            this.dbPersister.InsertGroup(group);

            GGUser user = this.userCache.Get(creatorID);

            user.JoinGroup(groupID);
            this.dbPersister.ChangeUserGroups(user.UserID, user.Groups);
            return(CreateGroupResult.Succeed);
        }
Esempio n. 17
0
        public void DeleteGroup(string groupID)
        {
            GGGroup group = this.groupCache.Get(groupID);

            if (group == null)
            {
                return;
            }
            foreach (string userID in group.MemberList)
            {
                GGUser user = this.userCache.Get(userID);
                if (user != null)
                {
                    user.QuitGroup(groupID);
                    this.dbPersister.ChangeUserGroups(user.UserID, user.Groups);
                }
            }
            this.dbPersister.DeleteGroup(groupID);
        }
Esempio n. 18
0
        public Dictionary <string, int> GetMyGroupVersions(string userID)
        {
            Dictionary <string, int> dic = new Dictionary <string, int>();
            GGUser user = this.userCache.Get(userID);

            if (user == null)
            {
                return(dic);
            }

            foreach (string groupID in user.GroupList)
            {
                GGGroup g = this.groupCache.Get(groupID);
                if (g != null)
                {
                    dic.Add(groupID, g.Version);
                }
            }
            return(dic);
        }
Esempio n. 19
0
        /// <summary>
        /// 获取某用户所在的所有组列表。
        /// 建议:可将某个用户所在的组ID列表挂接在用户资料的某个字段上,以避免遍历计算。
        /// </summary>
        public List <GGGroup> GetMyGroups(string userID)
        {
            List <GGGroup> groups = new List <GGGroup>();
            GGUser         user   = this.userCache.Get(userID);

            if (user == null)
            {
                return(groups);
            }

            foreach (string groupID in user.GroupList)
            {
                GGGroup g = this.groupCache.Get(groupID);
                if (g != null)
                {
                    groups.Add(g);
                }
            }
            return(groups);
        }
Esempio n. 20
0
        void do_globalUserCache_GroupInfoChanged(GGGroup group, GroupChangedType type, string userID)
        {
            this.groupListBox.GroupInfoChanged(group, type, userID);

            if (type == GroupChangedType.GroupDeleted)
            {
                GroupChatForm form = this.groupChatFormManager.GetForm(group.ID);
                if (form != null)
                {
                    form.Close();
                }

                if (userID != null) //为null 表示更改了自己的部门资料
                {
                    MessageBoxEx.Show(string.Format("群{0}({1})已经被解散。", group.ID, group.Name));
                }
                return;
            }

            GroupChatForm form2 = this.groupChatFormManager.GetForm(group.ID);
            if (form2 != null)
            {
                form2.OnGroupInfoChanged(type, userID);
            }
        }
        /// <summary>
        /// 处理来自客户端的消息。
        /// </summary>
        public void HandleInformation(string sourceUserID, int informationType, byte[] info)
        {
            if (informationType == InformationTypes.AddFriendCatalog)
            {
                string catalogName = System.Text.Encoding.UTF8.GetString(info);
                this.globalCache.AddFriendCatalog(sourceUserID, catalogName);
                return;
            }

            if (informationType == InformationTypes.RemoveFriendCatalog)
            {
                string catalogName = System.Text.Encoding.UTF8.GetString(info);
                this.globalCache.RemoveFriendCatalog(sourceUserID, catalogName);
                return;
            }

            if (informationType == InformationTypes.ChangeFriendCatalogName)
            {
                ChangeCatalogContract contract = CompactPropertySerializer.Default.Deserialize <ChangeCatalogContract>(info, 0);
                this.globalCache.ChangeFriendCatalogName(sourceUserID, contract.OldName, contract.NewName);
                return;
            }

            if (informationType == InformationTypes.MoveFriendToOtherCatalog)
            {
                MoveFriendToOtherCatalogContract contract = CompactPropertySerializer.Default.Deserialize <MoveFriendToOtherCatalogContract>(info, 0);
                this.globalCache.MoveFriend(sourceUserID, contract.FriendID, contract.OldCatalog, contract.NewCatalog);
                return;
            }

            if (informationType == InformationTypes.GetOfflineMessage)
            {
                this.SendOfflineMessage(sourceUserID);
                return;
            }

            if (informationType == InformationTypes.GetOfflineFile)
            {
                this.offlineFileController.SendOfflineFile(sourceUserID);
                return;
            }

            if (informationType == InformationTypes.QuitGroup)
            {
                string groupID = System.Text.Encoding.UTF8.GetString(info);
                this.globalCache.QuitGroup(sourceUserID, groupID);
                //通知其它组成员
                this.rapidServerEngine.ContactsController.Broadcast(groupID, BroadcastTypes.SomeoneQuitGroup, System.Text.Encoding.UTF8.GetBytes(sourceUserID), null, ESFramework.ActionTypeOnChannelIsBusy.Continue);

                return;
            }

            if (informationType == InformationTypes.DeleteGroup)
            {
                string groupID = System.Text.Encoding.UTF8.GetString(info);
                //通知其它组成员
                this.rapidServerEngine.ContactsController.Broadcast(groupID, BroadcastTypes.GroupDeleted, System.Text.Encoding.UTF8.GetBytes(sourceUserID), null, ESFramework.ActionTypeOnChannelIsBusy.Continue);
                this.globalCache.DeleteGroup(groupID);
                return;
            }

            if (informationType == InformationTypes.RemoveFriend)
            {
                string friendID = System.Text.Encoding.UTF8.GetString(info);
                this.globalCache.RemoveFriend(sourceUserID, friendID);
                //通知好友
                this.rapidServerEngine.CustomizeController.Send(friendID, InformationTypes.FriendRemovedNotify, System.Text.Encoding.UTF8.GetBytes(sourceUserID));
                return;
            }

            if (informationType == InformationTypes.ChangeStatus)
            {
                GGUser user      = this.globalCache.GetUser(sourceUserID);
                int    newStatus = BitConverter.ToInt32(info, 0);
                user.UserStatus = (UserStatus)newStatus;
                List <string>             contacts = this.globalCache.GetAllContacts(sourceUserID);
                UserStatusChangedContract contract = new UserStatusChangedContract(sourceUserID, newStatus);
                byte[] msg = ESPlus.Serialization.CompactPropertySerializer.Default.Serialize(contract);
                foreach (string friendID in contacts)
                {
                    this.rapidServerEngine.CustomizeController.Send(friendID, InformationTypes.UserStatusChanged, msg);
                }
                return;
            }

            if (informationType == InformationTypes.SystemNotify4AllOnline)
            {
                foreach (string userID in this.rapidServerEngine.UserManager.GetOnlineUserList())
                {
                    this.rapidServerEngine.CustomizeController.Send(userID, InformationTypes.SystemNotify4AllOnline, info);
                }
                return;
            }

            if (informationType == InformationTypes.SystemNotify4Group)
            {
                SystemNotifyContract contract = CompactPropertySerializer.Default.Deserialize <SystemNotifyContract>(info, 0);
                GGGroup group = this.globalCache.GetGroup(contract.GroupID);
                if (group != null)
                {
                    foreach (string userID in group.MemberList)
                    {
                        this.rapidServerEngine.CustomizeController.Send(userID, InformationTypes.SystemNotify4Group, info);
                    }
                }
                return;
            }
        }
        /// <summary>
        /// 处理来自客户端的同步调用请求。
        /// </summary>
        public byte[] HandleQuery(string sourceUserID, int informationType, byte[] info)
        {
            if (informationType == InformationTypes.GetFriendIDList)
            {
                List <string> friendIDs = this.globalCache.GetFriends(sourceUserID);
                return(CompactPropertySerializer.Default.Serialize <List <string> >(friendIDs));
            }

            if (informationType == InformationTypes.AddFriend)
            {
                AddFriendContract contract = CompactPropertySerializer.Default.Deserialize <AddFriendContract>(info, 0);
                bool isExist = this.globalCache.IsUserExist(contract.FriendID);
                if (!isExist)
                {
                    return(BitConverter.GetBytes((int)AddFriendResult.FriendNotExist));
                }
                this.globalCache.AddFriend(sourceUserID, contract.FriendID, contract.CatalogName);

                //0922
                GGUser owner     = this.globalCache.GetUser(sourceUserID);
                byte[] ownerBuff = CompactPropertySerializer.Default.Serialize <GGUser>(owner);

                //通知对方
                this.rapidServerEngine.CustomizeController.Send(contract.FriendID, InformationTypes.FriendAddedNotify, ownerBuff, true, ESFramework.ActionTypeOnChannelIsBusy.Continue);
                return(BitConverter.GetBytes((int)AddFriendResult.Succeed));
            }

            if (informationType == InformationTypes.GetAllContacts)
            {
                List <string> contacts = this.globalCache.GetAllContacts(sourceUserID);
                Dictionary <string, GGUser> contactDic = new Dictionary <string, GGUser>();
                foreach (string friendID in contacts)
                {
                    if (!contactDic.ContainsKey(friendID))
                    {
                        GGUser friend = this.globalCache.GetUser(friendID);
                        if (friend != null)
                        {
                            contactDic.Add(friendID, friend);
                        }
                    }
                }

                return(CompactPropertySerializer.Default.Serialize <List <GGUser> >(new List <GGUser>(contactDic.Values)));
            }

            if (informationType == InformationTypes.GetSomeUsers)
            {
                List <string> friendIDs = CompactPropertySerializer.Default.Deserialize <List <string> >(info, 0);
                List <GGUser> friends   = new List <GGUser>();
                foreach (string friendID in friendIDs)
                {
                    GGUser friend = this.globalCache.GetUser(friendID);
                    if (friend != null)
                    {
                        friends.Add(friend);
                    }
                }

                return(CompactPropertySerializer.Default.Serialize <List <GGUser> >(friends));
            }

            if (informationType == InformationTypes.GetContactsRTData)
            {
                List <string> contacts = this.globalCache.GetAllContacts(sourceUserID);
                Dictionary <string, UserRTData> dic = new Dictionary <string, UserRTData>();
                foreach (string friendID in contacts)
                {
                    if (!dic.ContainsKey(friendID))
                    {
                        GGUser data = this.globalCache.GetUser(friendID);
                        if (data != null)
                        {
                            UserRTData rtData = new UserRTData(data.UserStatus, data.Version);
                            dic.Add(friendID, rtData);
                        }
                    }
                }
                Dictionary <string, int> groupVerDic = this.globalCache.GetMyGroupVersions(sourceUserID);
                ContactsRTDataContract   contract    = new ContactsRTDataContract(dic, groupVerDic);
                return(CompactPropertySerializer.Default.Serialize(contract));
            }

            if (informationType == InformationTypes.GetUserInfo)
            {
                string target = System.Text.Encoding.UTF8.GetString(info);
                GGUser user   = this.globalCache.GetUser(target);
                if (user == null)
                {
                    return(null);
                }
                if (sourceUserID != target)  //0922
                {
                    user = user.PartialCopy;
                }
                return(CompactPropertySerializer.Default.Serialize <GGUser>(user));
            }

            if (informationType == InformationTypes.GetMyGroups)
            {
                List <GGGroup> myGroups = this.globalCache.GetMyGroups(sourceUserID);
                return(CompactPropertySerializer.Default.Serialize(myGroups));
            }

            if (informationType == InformationTypes.GetSomeGroups)
            {
                List <string>  groups   = ESPlus.Serialization.CompactPropertySerializer.Default.Deserialize <List <string> >(info, 0);
                List <GGGroup> myGroups = new List <GGGroup>();
                foreach (string groupID in groups)
                {
                    GGGroup group = this.globalCache.GetGroup(groupID);
                    if (group != null)
                    {
                        myGroups.Add(group);
                    }
                }

                return(CompactPropertySerializer.Default.Serialize(myGroups));
            }

            if (informationType == InformationTypes.JoinGroup)
            {
                string          groupID = System.Text.Encoding.UTF8.GetString(info);
                JoinGroupResult res     = this.globalCache.JoinGroup(sourceUserID, groupID);
                if (res == JoinGroupResult.Succeed)
                {
                    //通知其它组成员
                    this.rapidServerEngine.ContactsController.Broadcast(groupID, BroadcastTypes.SomeoneJoinGroup, System.Text.Encoding.UTF8.GetBytes(sourceUserID), null, ESFramework.ActionTypeOnChannelIsBusy.Continue);
                }
                return(BitConverter.GetBytes((int)res));
            }

            if (informationType == InformationTypes.CreateGroup)
            {
                CreateGroupContract contract = CompactPropertySerializer.Default.Deserialize <CreateGroupContract>(info, 0);
                CreateGroupResult   res      = this.globalCache.CreateGroup(sourceUserID, contract.ID, contract.Name, contract.Announce);
                return(BitConverter.GetBytes((int)res));
            }

            if (informationType == InformationTypes.GetGroup)
            {
                string  groupID = System.Text.Encoding.UTF8.GetString(info);
                GGGroup group   = this.globalCache.GetGroup(groupID);
                return(CompactPropertySerializer.Default.Serialize(group));
            }

            if (informationType == InformationTypes.ChangePassword)
            {
                ChangePasswordContract contract = CompactPropertySerializer.Default.Deserialize <ChangePasswordContract>(info, 0);
                ChangePasswordResult   res      = this.globalCache.ChangePassword(sourceUserID, contract.OldPasswordMD5, contract.NewPasswordMD5);
                return(BitConverter.GetBytes((int)res));
            }
            return(null);
        }
Esempio n. 23
0
 public void InsertGroup(GGGroup t)
 {
 }
Esempio n. 24
0
 public void UpdateGroup(GGGroup t)
 {
 }
Esempio n. 25
0
 public void UpdateGroup(GGGroup t)
 {
     using (TransactionScope scope = this.transactionScopeFactory.NewTransactionScope())
     {
         IOrmAccesser<GGGroup> accesser = scope.NewOrmAccesser<GGGroup>();
         accesser.Update(t);
         scope.Commit();
     }
 }
Esempio n. 26
0
 public void UpdateGroupInfo(GGGroup t)
 {
     this.UpdateGroup(t);
 }
Esempio n. 27
0
        /// <summary>
        /// 服务器获取客户端发来的信息
        /// </summary>
        public void GetClientMsg()
        {
            while (true)
            {
                try
                {
                    if (!this.currentUser.socket.Connected)
                    {
                        toInfo.msgType = MsgType.系统消息;
                        //信息显示到服务器
                        toInfo.content = GGUserUtils.ShowNickAndId(this.currentUser) + " 客户端失去连接";
                        ChatUtils.AppendMsgToServerChatList(this.serverChatRecords, toInfo);
                        SoundUtils.playSound(toInfo.content, EndPointEnum.务器);
                        break;
                    }

                    string      json     = ToolUtils.GetString(this.currentUser.socket);
                    MessageInfo fromInfo = SerializerUtil.JsonToObject <MessageInfo>(json);

                    if (fromInfo == null)
                    {
                        //信息显示到服务器
                        MessageInfo tmpInfo = new MessageInfo();
                        tmpInfo.msgType = MsgType.异常报告;
                        tmpInfo.content = GGUserUtils.ShowNickAndId(this.currentUser) + " 未获取到信息";
                        ChatUtils.AppendMsgToServerChatList(this.serverChatRecords, tmpInfo);
                        SoundUtils.playSound(toInfo.content, EndPointEnum.务器);
                        break;
                    }

                    toInfo = new MessageInfo()
                    {
                        msgType  = fromInfo.msgType,
                        socket   = this.currentUser.socket,
                        content  = fromInfo.content,
                        fromId   = fromInfo.fromId,
                        toId     = fromInfo.toId,
                        fromUser = fromInfo.fromUser,
                        toUser   = fromInfo.toUser,
                        dateTime = DateTime.Now
                    };


                    if (!string.IsNullOrEmpty(fromInfo.toId) && OnlineUserUtils.CheckClientIsOnline(fromInfo.toId) && true)
                    {
                        toInfo.socket = OnlineUserUtils.GetSingleOnlineClient(fromInfo.toId).socket;
                    }
                    if (fromInfo.msgType == MsgType.移动好友)
                    {
                        int        oldGroupAutoId = Convert.ToInt32(fromInfo.oldGroupAutoId);
                        int        newGroupAutoId = Convert.ToInt32(fromInfo.newGroupAutoId);
                        int        friendAutoId   = Convert.ToInt32(fromInfo.toId);
                        GGGroup    oldGroupInfo   = ChatDBUtils.GetSingeGroupByAutoId(oldGroupAutoId);
                        GGGroup    newGroupInfo   = ChatDBUtils.GetSingeGroupByAutoId(newGroupAutoId);
                        GGUserInfo userInfo       = ChatDBUtils.GetPerInfoByAutoId(friendAutoId);
                        ChatDBUtils.MoveGroup(oldGroupAutoId, newGroupAutoId, friendAutoId);
                        toInfo.content = "成功将好友" + GGUserUtils.ShowNickAndId(userInfo) + "从[ " + oldGroupInfo.groupName + " ] 移动到 [ " + newGroupInfo.groupName + " ]";
                        SocketUtils.SendToSingleClient(toInfo);
                    }
                    else if (fromInfo.msgType == MsgType.私发红包)
                    {
                        if (OnlineUserUtils.CheckClientIsOnline(fromInfo.toId))
                        {
                            SocketUtils.SendToSingleClient(toInfo);
                        }
                        toInfo.content = GGUserUtils.ShowNickAndId(fromInfo.fromUser) + "给" + GGUserUtils.ShowNickAndId(fromInfo.toUser) + "发了" + fromInfo.content + "元的红包";
                    }
                    else if (fromInfo.msgType == MsgType.私聊)
                    {
                        if (OnlineUserUtils.CheckClientIsOnline(fromInfo.toId))
                        {
                            //信息转发给指定客户端
                            SocketUtils.SendToSingleClient(toInfo);
                            //添加聊天记录
                            ChatDBUtils.AddRecords(fromInfo);
                        }
                        else
                        {
                            //添加离线信息到数据库
                            ChatDBUtils.AddOfflineMsgToClient(fromInfo);
                        }
                    }
                    else if (fromInfo.msgType == MsgType.用户注册)
                    {
                        GGUserInfo user  = SerializerUtil.JsonToObject <GGUserInfo>(json);
                        bool       isSuc = ChatDBUtils.RegisterUser(user);

                        if (isSuc)
                        {
                            toInfo.content = GGUserUtils.ShowNickAndId(user) + "注册成功";
                        }
                        else
                        {
                            toInfo.content = GGUserUtils.ShowNickAndId(user) + "注册失败";
                        }
                        SocketUtils.SendToSingleClient(toInfo);
                    }
                    else if (fromInfo.msgType == MsgType.创建分组)
                    {
                        GGGroup tmpGroup = ChatDBUtils.GetGroupByName(fromInfo.content);
                        if (tmpGroup != null)
                        {
                            toInfo.content = "分组[" + fromInfo.content + "]已存在,请重新命名";
                            SocketUtils.SendToSingleClient(toInfo);
                        }
                        else
                        {
                            ChatDBUtils.CreateGroup(fromInfo.fromUser, fromInfo.content);
                            toInfo.content = "分组[" + fromInfo.content + "]创建成功";
                            SocketUtils.SendToSingleClient(toInfo);
                        }
                    }
                    else if (fromInfo.msgType == MsgType.除分组)
                    {
                        string groupAutoId = fromInfo.content;
                        ChatDBUtils.DelGroup(groupAutoId);
                        toInfo.content = "分组[" + fromInfo.content + "]删除成功";
                        SocketUtils.SendToSingleClient(toInfo);
                    }
                    else if (fromInfo.msgType == MsgType.修改分组)
                    {
                        string[] arr         = fromInfo.content.Split('|');
                        string   groupAutoId = arr[0];
                        string   groupName   = arr[1];
                        ChatDBUtils.UpdateGroup(groupAutoId, groupName);
                        toInfo.content = "分组[" + fromInfo.content + "]修改为[" + groupName + "]";
                        SocketUtils.SendToSingleClient(toInfo);
                    }
                    else if (fromInfo.msgType == MsgType.除好友)
                    {
                        string  friendAutoId = fromInfo.toId;
                        int     groupAutoId  = Convert.ToInt32(fromInfo.content);
                        GGGroup defaultGroup = ChatDBUtils.GetSingeGroupByAutoId(groupAutoId);
                        bool    isSuc        = ChatDBUtils.DelFriend(defaultGroup, friendAutoId);
                        //信息转发给指定客户端
                        toInfo.content = "成功删除好友" + GGUserUtils.ShowNickAndId(fromInfo.toUser);
                        SocketUtils.SendToSingleClient(toInfo);
                    }
                    else if (fromInfo.msgType == MsgType.添加好友)
                    {
                        //检查默认分组
                        CheckDefaultGroup(fromInfo);

                        GGUserInfo user         = ChatDBUtils.GetPerInfoByUserId(fromInfo.toId);
                        GGGroup    defaultGroup = ChatDBUtils.GetDefaultGroup(fromInfo.fromId);
                        bool       isSuc        = ChatDBUtils.AddFriend(defaultGroup, user.userAutoid);
                        //信息转发给指定客户端
                        toInfo.content = "成功添加" + GGUserUtils.ShowNickAndId(fromInfo.toUser) + "为好友";
                        SocketUtils.SendToSingleClient(toInfo);
                    }
                    else if (fromInfo.msgType == MsgType.获取好友信息)
                    {
                        List <GGGroup> groupList = ChatDBUtils.GetGroupFriendsInfo(fromInfo.fromId);
                        toInfo.content = SerializerUtil.ObjectToJson <List <GGGroup> >(groupList);
                        //将好友信息发送给制定客户端,刷新好友在线情况
                        SocketUtils.SendToSingleClient(toInfo);
                        toInfo.content = GGUserUtils.ShowNickAndId(fromInfo.fromUser) + "的好友情况如下:" + ChatDBUtils.GetPerOnlineGroupFriendsStr(fromInfo.fromId);
                    }
                    else if (fromInfo.msgType == MsgType.群发抖动)
                    {
                        //信息分发给其他客户端
                        SocketUtils.SendToMultiClients(OnlineUserUtils.GetAllOnlineClients(), fromInfo);
                    }
                    else if (fromInfo.msgType == MsgType.私发抖动)
                    {
                        toInfo.fromUser = OnlineUserUtils.GetSingleOnlineClient(fromInfo.fromId);
                        if (OnlineUserUtils.CheckClientIsOnline(fromInfo.toId))
                        {
                            toInfo.toUser  = OnlineUserUtils.GetSingleOnlineClient(fromInfo.toId);
                            toInfo.content = GGUserUtils.ShowNickAndId(toInfo.fromUser) + " 给你发了一个抖动";
                            toInfo.socket  = toInfo.toUser.socket;
                            SocketUtils.SendToSingleClient(toInfo);
                        }
                        toInfo.content = GGUserUtils.ShowNickAndId(fromInfo.fromUser) + " 给" + GGUserUtils.ShowNickAndId(fromInfo.toUser) + "发了一个抖动";
                    }
                    else if (fromInfo.msgType == MsgType.退出聊天室)
                    {
                        SocketUtils.SendToMultiClients(OnlineUserUtils.GetAllOnlineClients(), toInfo);
                    }
                    else if (fromInfo.msgType == MsgType.群发红包)
                    {
                        //信息分发给其他客户端
                        SocketUtils.SendToMultiClients(OnlineUserUtils.GetAllOnlineClients(), toInfo);
                    }
                    else if (fromInfo.msgType == MsgType.线)
                    {
                        string     userId = fromInfo.fromId;
                        GGUserInfo user   = OnlineUserUtils.GetSingleOnlineClient(userId);
                        toInfo.content = GGUserUtils.ShowNickAndId(user) + " 下线了";
                        //user.socket.Close();
                        //下线客户端
                        OnlineUserUtils.RemoveOnlineClient(userId);
                    }
                    else if (fromInfo.msgType == MsgType.线)
                    {
                        //信息分发给其他客户端
                        SocketUtils.SendToMultiClients(OnlineUserUtils.GetAllOnlineClients(), toInfo);
                    }
                    else if (fromInfo.msgType == MsgType.群聊)
                    {
                        //信息分发给其他客户端
                        SocketUtils.SendToMultiClients(OnlineUserUtils.GetAllOnlineClients(), toInfo);
                    }
                    else
                    {
                        toInfo.content = "未知信息:[ " + fromInfo.msgType + " ]  " + fromInfo.content;
                    }
                    //信息显示到服务器
                    ChatUtils.AppendMsgToServerChatList(this.serverChatRecords, toInfo);
                }
                catch (Exception ex)
                {
                    MessageInfo toInfo = new MessageInfo();
                    toInfo.msgType = MsgType.异常报告;
                    toInfo.content = GGUserUtils.ShowNickAndId(currentUser) + "被强制下线,服务器读取信息时异常:" + ex.Message;
                    //信息显示到服务器
                    ChatUtils.AppendMsgToServerChatList(this.serverChatRecords, toInfo);
                    //关闭连接并下线客户端
                    //userInfo.UserSocket1.Close();
                    OnlineUserUtils.RemoveOnlineClient(currentUser.userId);
                    //currentUser.socket.Close();
                    SoundUtils.playSound(toInfo.msgType + toInfo.content, EndPointEnum.务器);
                }
            }
        }
Esempio n. 28
0
 void globalUserCache_GroupInfoChanged(GGGroup group, GroupChangedType type, string userID)
 {
     GlobalResourceManager.UiSafeInvoker.ActionOnUI<GGGroup, GroupChangedType, string>(this.do_globalUserCache_GroupInfoChanged, group, type, userID);
 }
Esempio n. 29
0
 public void UpdateGroupInfo(GGGroup t)
 {
     this.UpdateGroup(t);
 }
        /// <summary>
        /// 创建组
        /// </summary>       
        public CreateGroupResult CreateGroup(string creatorID, string groupID, string groupName, string announce)
        {
            if (this.groupCache.Contains(groupID))
            {
                return CreateGroupResult.GroupExisted;
            }

            GGGroup group = new GGGroup(groupID, groupName, creatorID, announce, creatorID);            
            this.groupCache.Add(groupID, group);
            this.dbPersister.InsertGroup(group);

            GGUser user = this.userCache.Get(creatorID);          
            user.JoinGroup(groupID);
            this.dbPersister.ChangeUserGroups(user.UserID, user.Groups);
            return CreateGroupResult.Succeed;
        }
Esempio n. 31
0
        void rapidServerEngine_MessageReceived(string sourceUserID, int informationType, byte[] info, string tag)
        {
            if (informationType == InformationTypes.Chat)
            {
                string destID = tag;
                if (this.rapidServerEngine.UserManager.IsUserOnLine(destID))
                {
                    this.rapidServerEngine.SendMessage(destID, informationType, info, sourceUserID, 2048);
                }
                else
                {
                    OfflineMessage msg = new OfflineMessage(sourceUserID, destID, informationType, info);
                    this.globalCache.StoreOfflineMessage(msg);
                }
                this.globalCache.StoreChatRecord(sourceUserID, destID, info);
                return;
            }

            if (informationType == InformationTypes.UpdateUserInfo)
            {
                GGUser user = ESPlus.Serialization.CompactPropertySerializer.Default.Deserialize <GGUser>(info, 0);
                GGUser old  = this.globalCache.GetUser(user.UserID);
                this.globalCache.UpdateUser(user);
                List <string> friendIDs = this.globalCache.GetFriends(sourceUserID);
                byte[]        subData   = ESPlus.Serialization.CompactPropertySerializer.Default.Serialize <GGUser>(user.PartialCopy); //0922
                foreach (string friendID in friendIDs)
                {
                    if (friendID != sourceUserID)
                    {
                        //可能要分块发送
                        this.rapidServerEngine.CustomizeController.Send(friendID, InformationTypes.UserInforChanged, subData, true, ActionTypeOnChannelIsBusy.Continue);
                    }
                }
                return;
            }


            if (informationType == InformationTypes.UpdateGroupInfo)
            {
                GGGroup group = ESPlus.Serialization.CompactPropertySerializer.Default.Deserialize <GGGroup>(info, 0);
                GGGroup old   = this.globalCache.GetGroup(group.ID);
                this.globalCache.UpdateGroup(group);



                List <string> Members = old.MemberList;



                byte[] subData = ESPlus.Serialization.CompactPropertySerializer.Default.Serialize <GGGroup>(group); //0922
                foreach (string MemberID in Members)
                {
                    if (MemberID != sourceUserID)
                    {
                        //可能要分块发送
                        this.rapidServerEngine.CustomizeController.Send(MemberID, InformationTypes.UpdateGroupInfo, subData, true, ActionTypeOnChannelIsBusy.Continue);
                    }
                }
                return;
            }
        }