/// <summary> /// 处理来自客户端的同步调用请求。 /// </summary> public byte[] HandleQuery(string sourceUserID, int informationType, byte[] info) { if (informationType == InformationTypes.GetFriendIDList) { var friendIDs = this.globalCache.GetFriends(sourceUserID); return(CompactPropertySerializer.Default.Serialize <List <string> >(friendIDs)); } if (informationType == InformationTypes.AddFriend) { var contract = CompactPropertySerializer.Default.Deserialize <AddFriendContract>(info, 0); var isExist = this.globalCache.IsUserExist(contract.FriendID); if (!isExist) { return(BitConverter.GetBytes((int)AddFriendResult.FriendNotExist)); } this.globalCache.AddFriend(sourceUserID, contract.FriendID, contract.CatalogName); //0922 var owner = this.globalCache.GetUser(sourceUserID); var 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) { var contacts = this.globalCache.GetAllContacts(sourceUserID); var contactDic = new Dictionary <string, GGUser>(); foreach (var friendID in contacts) { if (!contactDic.ContainsKey(friendID)) { var 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) { var friendIDs = CompactPropertySerializer.Default.Deserialize <List <string> >(info, 0); var friends = new List <GGUser>(); foreach (var friendID in friendIDs) { var friend = this.globalCache.GetUser(friendID); if (friend != null) { friends.Add(friend); } } return(CompactPropertySerializer.Default.Serialize <List <GGUser> >(friends)); } if (informationType == InformationTypes.GetContactsRTData) { var contacts = this.globalCache.GetAllContacts(sourceUserID); var dic = new Dictionary <string, UserRTData>(); foreach (var friendID in contacts) { if (!dic.ContainsKey(friendID)) { var data = this.globalCache.GetUser(friendID); if (data != null) { var rtData = new UserRTData(data.UserStatus, data.Version); dic.Add(friendID, rtData); } } } var groupVerDic = this.globalCache.GetMyGroupVersions(sourceUserID); var contract = new ContactsRTDataContract(dic, groupVerDic); return(CompactPropertySerializer.Default.Serialize(contract)); } if (informationType == InformationTypes.GetUserInfo) { var target = System.Text.Encoding.UTF8.GetString(info); var 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) { var myGroups = this.globalCache.GetMyGroups(sourceUserID); return(CompactPropertySerializer.Default.Serialize(myGroups)); } if (informationType == InformationTypes.GetSomeGroups) { var groups = ESPlus.Serialization.CompactPropertySerializer.Default.Deserialize <List <string> >(info, 0); var myGroups = new List <GGGroup>(); foreach (var groupID in groups) { var group = this.globalCache.GetGroup(groupID); if (group != null) { myGroups.Add(group); } } return(CompactPropertySerializer.Default.Serialize(myGroups)); } if (informationType == InformationTypes.JoinGroup) { var groupID = System.Text.Encoding.UTF8.GetString(info); var 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) { var contract = CompactPropertySerializer.Default.Deserialize <CreateGroupContract>(info, 0); var res = this.globalCache.CreateGroup(sourceUserID, contract.ID, contract.Name, contract.Announce); return(BitConverter.GetBytes((int)res)); } if (informationType == InformationTypes.GetGroup) { var groupID = System.Text.Encoding.UTF8.GetString(info); var group = this.globalCache.GetGroup(groupID); return(CompactPropertySerializer.Default.Serialize(group)); } if (informationType == InformationTypes.ChangePassword) { var contract = CompactPropertySerializer.Default.Deserialize <ChangePasswordContract>(info, 0); var res = this.globalCache.ChangePassword(sourceUserID, contract.OldPasswordMD5, contract.NewPasswordMD5); return(BitConverter.GetBytes((int)res)); } return(null); }
/// <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); }