コード例 #1
0
ファイル: AddUserForm.cs プロジェクト: liweizl/GGTalk-1
        private void btnClose_Click(object sender, EventArgs e)
        {
            this.userID = this.skinTextBox_id.SkinTxt.Text.Trim();
            if (userID.Length == 0)
            {
                MessageBoxEx.Show("成员帐号不能为空!");
                this.DialogResult = System.Windows.Forms.DialogResult.None;
                return;
            }

            //try
            //{
            if (this.ggSupporter.MemberList.Contains(this.userID))
            {
                MessageBoxEx.Show("已经是该群的成员了!");
                this.DialogResult = System.Windows.Forms.DialogResult.None;
                return;
            }

            byte[]          bRes = this.rapidPassiveEngine.CustomizeOutter.Query(InformationTypes.AddMember, System.Text.Encoding.UTF8.GetBytes(ggSupporter.ID + "|" + userID));
            AddMemberResult res  = (AddMemberResult)BitConverter.ToInt32(bRes, 0);

            if (res == AddMemberResult.MemberNotExist)
            {
                MessageBoxEx.Show("成员不存在!");
                this.DialogResult = System.Windows.Forms.DialogResult.None;
                return;
            }

            this.DialogResult = System.Windows.Forms.DialogResult.OK;
            //}
            //catch (Exception ee)
            //{
            //    MessageBoxEx.Show("加入群失败!" + ee.Message);
            //    this.DialogResult = System.Windows.Forms.DialogResult.None;
            //}
        }
コード例 #2
0
        /// <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.AddMember)
            {
                string          groupID = System.Text.Encoding.UTF8.GetString(info).Split('|')[0];
                string          UserID  = System.Text.Encoding.UTF8.GetString(info).Split('|')[1];
                AddMemberResult res     = this.globalCache.AddMember(UserID, groupID);
                if (res == AddMemberResult.Succeed)
                {
                    //通知其它组成员
                    this.rapidServerEngine.ContactsController.Broadcast(groupID, BroadcastTypes.SomeoneAddGroup, System.Text.Encoding.UTF8.GetBytes(UserID), null, ESFramework.ActionTypeOnChannelIsBusy.Continue);
                    //通知对方
                    this.rapidServerEngine.CustomizeController.Send(UserID, InformationTypes.AddMember, info, true, 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, sourceUserID, "");
                return(BitConverter.GetBytes((int)res));
            }


            //上传群文件
            if (informationType == InformationTypes.SendGroupFile)
            {
                SendGroupFileContract contract = CompactPropertySerializer.Default.Deserialize <SendGroupFileContract>(info, 0);
                SendGroupFileResult   res      = this.globalCache.SendGroupFile(contract.SID, contract.FileName, contract.FileLength, contract.SenderID, contract.SenderName, contract.SendDate, contract.GroupID);
                return(BitConverter.GetBytes((int)res));
            }

            //删除群文件
            if (informationType == InformationTypes.DeleteGroupFile)
            {
                string fileID             = System.Text.Encoding.UTF8.GetString(info).Split('|')[0];
                string groupID            = System.Text.Encoding.UTF8.GetString(info).Split('|')[1];
                DeleteGroupFileResult res = this.globalCache.DeleteGroupFile(fileID, groupID);
                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);
        }