public List <string> GetGroupMembers(string groupID) { SortedArray <string> ary = this.SafeGetGroupMembers(groupID); if (ary == null) { return(null); } return(ary.GetAll()); }
public List<string> GetGroupmates(string userID) { SortedArray<string> array = new SortedArray<string>(); foreach (SortedArray<string> group in this.manager.GetAll()) { if (group.Contains(userID)) { array.Add(group.GetAll()); } } return array.GetAll(); }
public List <string> GetGroupmates(string userID) { SortedArray <string> array = new SortedArray <string>(); foreach (SortedArray <string> group in this.manager.GetAll()) { if (group.Contains(userID)) { array.Add(group.GetAll()); } } return(array.GetAll()); }
public void Broadcast(string groupID, int broadcastType, byte[] broadcastContent, ActionTypeOnChannelIsBusy action, BroadcastChannelMode broadcastChannelMode) { if (broadcastChannelMode == BroadcastChannelMode.AllTransferByServer) { this.BroadcastByServer(groupID, broadcastType, broadcastContent, action); return; } if (broadcastChannelMode == BroadcastChannelMode.AllByP2PChannel) { this.BroadcastByP2PChannel(groupID, broadcastType, broadcastContent, action); return; } BroadcastContract contract = new BroadcastContract(this.currentUserID, groupID, broadcastType, broadcastContent, action); byte[] info = CompactPropertySerializer.Default.Serialize(contract); SortedArray <string> passiveGroupmates = this.SafeGetGroupMembers(groupID); if (passiveGroupmates == null) { return; } bool allP2P = true; foreach (string memberID in passiveGroupmates.GetAll()) { if (memberID == this.currentUserID) { continue; } if (this.rapidPassiveEngine.P2PController.IsP2PChannelExist(memberID)) { this.rapidPassiveEngine.CustomizeOutter.SendByP2PChannel(memberID, this.groupInfoTypes.Broadcast, info, ActionTypeOnNoP2PChannel.Discard, true, action); } else { allP2P = false; } } if (!allP2P) //如果有一个在线用户没有P2P,则经过服务器中转。 { this.rapidPassiveEngine.CustomizeOutter.Send(null, this.groupInfoTypes.Broadcast, info, true, action); } }
private void BroadcastByP2PChannel(string groupID, int broadcastType, byte[] broadcastContent, ActionTypeOnChannelIsBusy action) { BroadcastContract contract = new BroadcastContract(this.currentUserID, groupID, broadcastType, broadcastContent, action); byte[] info = CompactPropertySerializer.Default.Serialize(contract); SortedArray <string> ary = this.SafeGetGroupMembers(groupID); foreach (string memberID in ary.GetAll()) { if (memberID == this.currentUserID) { continue; } if (this.rapidPassiveEngine.P2PController.IsP2PChannelExist(memberID)) { this.rapidPassiveEngine.CustomizeOutter.SendByP2PChannel(memberID, this.groupInfoTypes.Broadcast, info, ActionTypeOnNoP2PChannel.Discard, true, action); } } }
public void Offline(string userID) { SortedArray <string> array = new SortedArray <string>(); lock (this.locker) { foreach (SortedArray <string> group in this.manager.GetAll()) { if (group.Contains(userID)) { array.Add(group.GetAll()); group.Remove(userID); } } } if (this.GroupmateOffline != null) { this.GroupmateOffline(userID, array.GetAll()); } }
public void Offline(string userID) { SortedArray<string> array = new SortedArray<string>(); lock (this.locker) { foreach (SortedArray<string> group in this.manager.GetAll()) { if (group.Contains(userID)) { array.Add(group.GetAll()); group.Remove(userID); } } } if (this.GroupmateOffline != null) { this.GroupmateOffline(userID, array.GetAll()); } }
public void BroadcastBlob(string groupID, int broadcastType, byte[] blobInfo, int fragmentSize, BroadcastChannelMode broadcastChannelMode) { if (blobInfo == null || blobInfo.Length == 0) { return; } if (fragmentSize == 0) { throw new ArgumentException("Value of fragmentSize must be greater than 0."); } if (blobInfo.Length <= fragmentSize) { this.Broadcast(groupID, broadcastType, blobInfo, ActionTypeOnChannelIsBusy.Continue, broadcastChannelMode); return; } int messageType = broadcastChannelMode == BroadcastChannelMode.AllTransferByServer ? this.groupInfoTypes.BroadcastBlobByServer : this.groupInfoTypes.BroadcastBlob; int blobID = System.Threading.Interlocked.Increment(ref this.maxBlobID); int count = blobInfo.Length / fragmentSize; if (blobInfo.Length % fragmentSize > 0) { count += 1; } if (broadcastChannelMode == BroadcastChannelMode.AllTransferByServer) { #region AllTransferByServer for (int i = 0; i < count; i++) { byte[] fragment = null; if (i < count - 1) { fragment = new byte[fragmentSize]; } else { fragment = new byte[blobInfo.Length - i * fragmentSize]; } Buffer.BlockCopy(blobInfo, i * fragmentSize, fragment, 0, fragment.Length); BlobFragmentContract contract = new BlobFragmentContract(this.currentUserID, blobID, broadcastType, i, fragment, i == count - 1, groupID); byte[] info = CompactPropertySerializer.Default.Serialize(contract); this.rapidPassiveEngine.CustomizeOutter.Send(null, messageType, info, true, ActionTypeOnChannelIsBusy.Continue); } #endregion } else if (broadcastChannelMode == BroadcastChannelMode.P2PChannelFirst) { #region P2PChannelFirst SortedArray <string> passiveGroupmates = this.SafeGetGroupMembers(groupID); if (passiveGroupmates == null) { return; } for (int i = 0; i < count; i++) { bool allP2P = true; byte[] fragment = null; if (i < count - 1) { fragment = new byte[fragmentSize]; } else { fragment = new byte[blobInfo.Length - i * fragmentSize]; } Buffer.BlockCopy(blobInfo, i * fragmentSize, fragment, 0, fragment.Length); BlobFragmentContract contract = new BlobFragmentContract(this.currentUserID, blobID, broadcastType, i, fragment, i == count - 1, groupID); byte[] info = CompactPropertySerializer.Default.Serialize(contract); foreach (string memberID in passiveGroupmates.GetAll()) { if (memberID == this.currentUserID) { continue; } if (this.rapidPassiveEngine.P2PController.IsP2PChannelExist(memberID)) { this.rapidPassiveEngine.CustomizeOutter.SendByP2PChannel(memberID, messageType, info, ActionTypeOnNoP2PChannel.Discard, true, ActionTypeOnChannelIsBusy.Continue); } else { allP2P = false; } } if (!allP2P) //如果有一个在线用户没有P2P,则经过服务器中转。 { this.rapidPassiveEngine.CustomizeOutter.Send(null, messageType, info, true, ActionTypeOnChannelIsBusy.Continue); } } #endregion } else //AllByP2PChannel { #region AllByP2PChannel SortedArray <string> passiveGroupmates = this.SafeGetGroupMembers(groupID); if (passiveGroupmates == null) { return; } for (int i = 0; i < count; i++) { byte[] fragment = null; if (i < count - 1) { fragment = new byte[fragmentSize]; } else { fragment = new byte[blobInfo.Length - i * fragmentSize]; } Buffer.BlockCopy(blobInfo, i * fragmentSize, fragment, 0, fragment.Length); BlobFragmentContract contract = new BlobFragmentContract(this.currentUserID, blobID, broadcastType, i, fragment, i == count - 1, groupID); byte[] info = CompactPropertySerializer.Default.Serialize(contract); foreach (string memberID in passiveGroupmates.GetAll()) { if (memberID == this.currentUserID) { continue; } if (this.rapidPassiveEngine.P2PController.IsP2PChannelExist(memberID)) { this.rapidPassiveEngine.CustomizeOutter.SendByP2PChannel(memberID, messageType, info, ActionTypeOnNoP2PChannel.Discard, true, ActionTypeOnChannelIsBusy.Continue); } } } #endregion } }