/// <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), 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), 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 void HandleInformation(string sourceUserID, int informationType, byte[] info) { if (informationType == InformationTypes.AddFriendCatalog) { var catalogName = System.Text.Encoding.UTF8.GetString(info); this.globalCache.AddFriendCatalog(sourceUserID, catalogName); return; } if (informationType == InformationTypes.RemoveFriendCatalog) { var catalogName = System.Text.Encoding.UTF8.GetString(info); this.globalCache.RemoveFriendCatalog(sourceUserID, catalogName); return; } if (informationType == InformationTypes.ChangeFriendCatalogName) { var contract = CompactPropertySerializer.Default.Deserialize <ChangeCatalogContract>(info, 0); this.globalCache.ChangeFriendCatalogName(sourceUserID, contract.OldName, contract.NewName); return; } if (informationType == InformationTypes.MoveFriendToOtherCatalog) { var 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) { var 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) { var 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) { var 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) { var user = this.globalCache.GetUser(sourceUserID); var newStatus = BitConverter.ToInt32(info, 0); user.UserStatus = (UserStatus)newStatus; var contacts = this.globalCache.GetAllContacts(sourceUserID); var contract = new UserStatusChangedContract(sourceUserID, newStatus); var msg = ESPlus.Serialization.CompactPropertySerializer.Default.Serialize(contract); foreach (var friendID in contacts) { this.rapidServerEngine.CustomizeController.Send(friendID, InformationTypes.UserStatusChanged, msg); } return; } if (informationType == InformationTypes.SystemNotify4AllOnline) { foreach (var userID in this.rapidServerEngine.UserManager.GetOnlineUserList()) { this.rapidServerEngine.CustomizeController.Send(userID, InformationTypes.SystemNotify4AllOnline, info); } return; } if (informationType == InformationTypes.SystemNotify4Group) { var contract = CompactPropertySerializer.Default.Deserialize <SystemNotifyContract>(info, 0); var group = this.globalCache.GetGroup(contract.GroupID); if (group != null) { foreach (var userID in group.MemberList) { this.rapidServerEngine.CustomizeController.Send(userID, InformationTypes.SystemNotify4Group, info); } } return; } }
/// <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.SetNoSpeak) { string groupID = System.Text.Encoding.UTF8.GetString(info).Split('|')[0]; string UserID = System.Text.Encoding.UTF8.GetString(info).Split('|')[1]; this.globalCache.SetNoSpeakGroup(UserID, groupID); //通知其它组成员 this.rapidServerEngine.ContactsController.Broadcast(groupID, BroadcastTypes.SomeoneNoSpeakGroup, System.Text.Encoding.UTF8.GetBytes(UserID), null, ESFramework.ActionTypeOnChannelIsBusy.Continue); return; } //解除禁止发言 if (informationType == InformationTypes.SetAllowSpeak) { string groupID = System.Text.Encoding.UTF8.GetString(info).Split('|')[0]; string UserID = System.Text.Encoding.UTF8.GetString(info).Split('|')[1]; this.globalCache.SetAllowSpeakGroup(UserID, groupID); //通知其它组成员 this.rapidServerEngine.ContactsController.Broadcast(groupID, BroadcastTypes.SomeoneAllowSpeakGroup, System.Text.Encoding.UTF8.GetBytes(UserID), null, ESFramework.ActionTypeOnChannelIsBusy.Continue); return; } //踢人 if (informationType == InformationTypes.RemoveMember) { string groupID = System.Text.Encoding.UTF8.GetString(info).Split('|')[0]; string UserID = System.Text.Encoding.UTF8.GetString(info).Split('|')[1]; this.globalCache.RemoveMemberGroup(UserID, groupID); //通知其它组成员 this.rapidServerEngine.ContactsController.Broadcast(groupID, BroadcastTypes.SomeoneRemoveGroup, System.Text.Encoding.UTF8.GetBytes(UserID), null, ESFramework.ActionTypeOnChannelIsBusy.Continue); //通知对方 this.rapidServerEngine.CustomizeController.Send(UserID, InformationTypes.RemoveMember, info, true, ESFramework.ActionTypeOnChannelIsBusy.Continue); return; } if (informationType == InformationTypes.AddMember) { string groupID = System.Text.Encoding.UTF8.GetString(info).Split('|')[0]; string UserID = System.Text.Encoding.UTF8.GetString(info).Split('|')[1]; JoinGroupResult res = this.globalCache.JoinGroup(UserID, groupID); if (res == JoinGroupResult.Succeed) { //通知其它组成员 this.rapidServerEngine.ContactsController.Broadcast(groupID, BroadcastTypes.SomeoneJoinGroup, System.Text.Encoding.UTF8.GetBytes(sourceUserID), null, ESFramework.ActionTypeOnChannelIsBusy.Continue); //通知对方 this.rapidServerEngine.CustomizeController.Send(UserID, InformationTypes.AddMember, info, true, ESFramework.ActionTypeOnChannelIsBusy.Continue); } return; } //解除管理员 if (informationType == InformationTypes.RemoveManager) { string groupID = System.Text.Encoding.UTF8.GetString(info).Split('|')[0]; string UserID = System.Text.Encoding.UTF8.GetString(info).Split('|')[1]; this.globalCache.RemoveManagerGroup(UserID, groupID); //通知其它组成员 this.rapidServerEngine.ContactsController.Broadcast(groupID, BroadcastTypes.SomeoneRemoveManagerGroup, System.Text.Encoding.UTF8.GetBytes(UserID), null, ESFramework.ActionTypeOnChannelIsBusy.Continue); ////通知对方 //this.rapidServerEngine.CustomizeController.Send(UserID, InformationTypes.RemoveManager, info, true, ESFramework.ActionTypeOnChannelIsBusy.Continue); return; } if (informationType == InformationTypes.AddManager) { string groupID = System.Text.Encoding.UTF8.GetString(info).Split('|')[0]; string UserID = System.Text.Encoding.UTF8.GetString(info).Split('|')[1]; this.globalCache.AddManagerGroup(UserID, groupID); this.rapidServerEngine.ContactsController.Broadcast(groupID, BroadcastTypes.SomeoneAddManagerGroup, System.Text.Encoding.UTF8.GetBytes(UserID), null, ESFramework.ActionTypeOnChannelIsBusy.Continue); //通知对方 // this.rapidServerEngine.CustomizeController.Send(UserID, InformationTypes.AddManager, info, true, ESFramework.ActionTypeOnChannelIsBusy.Continue); return; } if (informationType == InformationTypes.BroadcastNotice) { string groupID = System.Text.Encoding.UTF8.GetString(info).Split('|')[0]; string UserID = System.Text.Encoding.UTF8.GetString(info).Split('|')[1]; string content = System.Text.Encoding.UTF8.GetString(info).Split('|')[2]; this.globalCache.StoreGroupNoticeRecord(groupID, UserID, System.Text.Encoding.UTF8.GetBytes(content)); // this.globalCache.StoreGroupChatRecord(groupID, broadcasterID, broadcastContent); this.rapidServerEngine.ContactsController.Broadcast(groupID, BroadcastTypes.BroadcastNotice, System.Text.Encoding.UTF8.GetBytes(UserID + "|" + content), 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; } }