private void TcpClient_PacketReceive(object sender, EventArgs <ArraySegment <byte> > e) { Packet packet = new Packet(e.Value); switch (VirtualPacketFlag.GetMessage(packet.InstanceId)) { case TransrouterMessage.ClientConnect: this.AddVirtualClient(VirtualPacketFlag.GetTargetID(packet.InstanceId), BitConverter.ToInt32(packet.Array, packet.Offset + packet.BodyOffset), BitConverter.ToInt32(packet.Array, packet.Offset + packet.BodyOffset + 4)); return; case TransrouterMessage.ClientDisconnect: this.RemoveVirtualClient(VirtualPacketFlag.GetTargetID(packet.InstanceId)); return; case TransrouterMessage.SingleTransferMessage: this.TransferMessage(VirtualPacketFlag.GetTargetID(packet.InstanceId), e); return; default: return; } }
private void TcpClient_PacketReceive(object sender, EventArgs <ArraySegment <byte> > e) { Packet packet = new Packet(e.Value); switch (VirtualPacketFlag.GetMessage(packet.InstanceId)) { case TransrouterMessage.SingleTransferMessage: { int targetID = VirtualPacketFlag.GetTargetID(packet.InstanceId); packet.InstanceId = (long)VirtualPacketFlag.GenerateClientFlag(this.id); this.bridge.SendToClient(targetID, packet); return; } case TransrouterMessage.GroupTransferMessage: { int secondaryTargetID = VirtualPacketFlag.GetSecondaryTargetID(packet); packet.InstanceId = (long)VirtualPacketFlag.GenerateClientFlag(this.id); foreach (int num in this.clientGroup[secondaryTargetID].Keys) { if (!this.bridge.SendToClient(num, packet)) { this.removeList.Add(num); } } for (int i = 0; i < this.removeList.Count; i++) { this.clientGroup[secondaryTargetID].Remove(this.removeList[i]); } this.removeList.Clear(); return; } case TransrouterMessage.CreateClientGroup: { int secondaryTargetID = VirtualPacketFlag.GetSecondaryTargetID(packet); this.clientGroup.Add(secondaryTargetID, new SortedDictionary <int, int>()); return; } case TransrouterMessage.DestroyClientGroup: { int secondaryTargetID = VirtualPacketFlag.GetSecondaryTargetID(packet); this.clientGroup.Remove(secondaryTargetID); return; } case TransrouterMessage.AddClientGroupMember: { int targetID = VirtualPacketFlag.GetTargetID(packet.InstanceId); int secondaryTargetID = VirtualPacketFlag.GetSecondaryTargetID(packet); this.clientGroup[secondaryTargetID][targetID] = 0; return; } case TransrouterMessage.RemoveClientGroupMember: { int targetID = VirtualPacketFlag.GetTargetID(packet.InstanceId); int secondaryTargetID = VirtualPacketFlag.GetSecondaryTargetID(packet); this.clientGroup[secondaryTargetID].Remove(targetID); return; } case TransrouterMessage.ConnectClient: { int targetID = VirtualPacketFlag.GetTargetID(packet.InstanceId); this.bridge.Open(this.id, targetID); return; } case TransrouterMessage.DisconnectClient: { int targetID = VirtualPacketFlag.GetTargetID(packet.InstanceId); this.bridge.Close(this.id, targetID); return; } default: return; } }