Beispiel #1
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))
            });
        }
Beispiel #2
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))
            });
        }
Beispiel #3
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;
            }
        }