Пример #1
0
        public void Disconnect()
        {
            Packet packet = new Packet(0);

            packet.InstanceId = (long)VirtualPacketFlag.GenerateFlag(TransrouterMessage.DisconnectClient, this.id);
            this.virtualServer.Transmit(packet);
        }
Пример #2
0
        public VirtualClient LinkVirtualClient(int id, int ip, int port)
        {
            Packet packet = new Packet(0);

            packet.InstanceId = (long)VirtualPacketFlag.GenerateFlag(TransrouterMessage.ConnectClient, id);
            this.tcpClient.Transmit(packet);
            return(this.AddVirtualClient(id, ip, port));
        }
Пример #3
0
        internal void DestroyVirtualClientGroup(VirtualClientGroup vcGroup)
        {
            Packet packet = new Packet(0)
            {
                InstanceId = (long)VirtualPacketFlag.GenerateFlag(TransrouterMessage.DestroyClientGroup, 0)
            };

            VirtualPacketFlag.SetSecondaryTargetID(packet, vcGroup.ID);
            this.tcpClient.Transmit(packet);
        }
Пример #4
0
        private void Disable()
        {
            this.connectedServer = null;
            Packet packet = new Packet(0);

            packet.InstanceId = (long)VirtualPacketFlag.GenerateFlag(TransrouterMessage.ClientDisconnect, this.id);
            for (int i = 0; i < this.connectedServerIndexList.Count; i++)
            {
                this.bridge.SendToServer(this.connectedServerIndexList[i], packet);
            }
            this.connectedServerIndexList.Clear();
        }
Пример #5
0
        public VirtualClientGroup CreateVirtualClientGroup()
        {
            int    num    = Interlocked.Increment(ref this.nextGroupID);
            Packet packet = new Packet(0)
            {
                InstanceId = (long)VirtualPacketFlag.GenerateFlag(TransrouterMessage.CreateClientGroup, 0)
            };

            VirtualPacketFlag.SetSecondaryTargetID(packet, num);
            this.tcpClient.Transmit(packet);
            return(new VirtualClientGroup(this, num));
        }
Пример #6
0
        public void Remove(VirtualClient virtualClient)
        {
            if (virtualClient.Server != this.server)
            {
                throw new ArgumentException("Different virtual server.");
            }
            Packet packet = new Packet(0)
            {
                InstanceId = (long)VirtualPacketFlag.GenerateFlag(TransrouterMessage.RemoveClientGroupMember, virtualClient.ID)
            };

            VirtualPacketFlag.SetSecondaryTargetID(packet, this.id);
            this.server.Transmit(packet);
        }
Пример #7
0
        public void OpenServer(int serverID)
        {
            this.connectedServer[serverID] = true;
            this.connectedServerIndexList.Add(serverID);
            Packet packet = new Packet(8);

            packet.InstanceId = (long)VirtualPacketFlag.GenerateFlag(TransrouterMessage.ClientConnect, this.id);
            Buffer.BlockCopy(this.client.RemoteEndPoint.Address.GetAddressBytes(), 0, packet.Array, packet.Offset + packet.BodyOffset, 4);
            Buffer.BlockCopy(BitConverter.GetBytes(this.client.RemoteEndPoint.Port), 0, packet.Array, packet.Offset + packet.BodyOffset + 4, 4);
            this.bridge.SendToServer(serverID, packet);
            this.Transmit(new Packet
            {
                InstanceId = (long)(256 | VirtualPacketFlag.GenerateClientFlag(serverID))
            });
        }
Пример #8
0
        private void Client_PacketReceive(object sender, EventArgs <ArraySegment <byte> > e)
        {
            Packet packet = new Packet(e.Value);

            if ((packet.InstanceId & -65536L) != -1068630016L)
            {
                throw new ArgumentException("Invalid client packet header.");
            }
            int  num        = (int)((byte)packet.InstanceId);
            long instanceId = packet.InstanceId;

            if (this.connectedServer[num])
            {
                packet.InstanceId = (long)VirtualPacketFlag.GenerateFlag(TransrouterMessage.SingleTransferMessage, this.id);
                this.bridge.SendToServer(num, packet);
            }
        }
Пример #9
0
        public void CloseServer(int serverID)
        {
            if (this.connectedServer == null)
            {
                return;
            }
            this.connectedServer[serverID] = false;
            int index  = this.connectedServerIndexList.IndexOf(serverID);
            int index2 = this.connectedServerIndexList.Count - 1;

            this.connectedServerIndexList[index] = this.connectedServerIndexList[index2];
            this.connectedServerIndexList.RemoveAt(index2);
            Packet packet = new Packet(0);

            packet.InstanceId = (long)VirtualPacketFlag.GenerateFlag(TransrouterMessage.ClientDisconnect, this.id);
            this.bridge.SendToServer(serverID, packet);
            this.Transmit(new Packet(0)
            {
                InstanceId = (long)(512 | VirtualPacketFlag.GenerateClientFlag(serverID))
            });
        }
Пример #10
0
        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;
            }
        }
Пример #11
0
        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;
            }
        }
Пример #12
0
 public void Transmit(IEnumerable <Packet> packets)
 {
     this.virtualServer.Transmit(EnumerablePacketFlagModifier.Convert(packets, VirtualPacketFlag.GenerateFlag(TransrouterMessage.SingleTransferMessage, this.id)));
 }
Пример #13
0
 public void Transmit(Packet packet)
 {
     packet.InstanceId = (long)VirtualPacketFlag.GenerateFlag(TransrouterMessage.SingleTransferMessage, this.id);
     this.virtualServer.Transmit(packet);
 }