예제 #1
0
        // public method
        // data initialize
        public void DataInitialize()
        {
            // allocate queue
            receiveQueue     = new PacketQueue();
            sendQueue        = new PacketQueue();
            indexClientQueue = new Queue <Socket>();

            // allocate buffer
            receiveBuffer = new byte[bufferSize];
            sendBuffer    = new byte[bufferSize];

            // set network processor
            networkProcessor             = new NetworkProcessor();
            networkProcessor.OnReceived += OnReceivePacketFromClient;

            // set data processor
            dataProcessor = new DataProcessor(networkProcessor);

            // set receive notifier
            RegisterServerReceivePacket((int)ClientToServerPacket.JoinRequest, ReceiveJoinRequest);
            RegisterServerReceivePacket((int)ClientToServerPacket.LoginRequest, ReceiveLoginRequest);
            RegisterServerReceivePacket((int)ClientToServerPacket.GameDataRequest, ReceiveGameDataRequest);
            RegisterServerReceivePacket((int)ClientToServerPacket.StoreCreateRequest, ReceiveStoreCreateRequest);
            RegisterServerReceivePacket((int)ClientToServerPacket.ItemCreateRequest, ReceiveItemCreateRequest);
            RegisterServerReceivePacket((int)ClientToServerPacket.ItemAcquireRequest, ReceiveItemCreateRequest);
            RegisterServerReceivePacket((int)ClientToServerPacket.ItemSellRequest, ReceiveItemSellRequest);
        }
예제 #2
0
            /// <summary>
            /// new
            /// </summary>
            /// <param name="connectionID"></param>
            /// <param name="socket"></param>
            /// <param name="host"></param>
            /// <exception cref="ArgumentNullException">socket is null</exception>
            /// <exception cref="ArgumentNullException">host is null</exception>
            public DefaultConnection(long connectionID, Socket socket, BaseHost host)
            {
                if (socket == null)
                {
                    throw new ArgumentNullException("socket");
                }
                if (host == null)
                {
                    throw new ArgumentNullException("host");
                }

                this.ConnectionID       = connectionID;
                this._socket            = socket;
                this._messageBufferSize = host.MessageBufferSize;
                this._host = host;

                try
                {
                    this.LocalEndPoint  = (IPEndPoint)socket.LocalEndPoint;
                    this.RemoteEndPoint = (IPEndPoint)socket.RemoteEndPoint;
                }
                catch (Exception ex) { Log.Trace.Error("get socket endPoint error.", ex); }

                //init send socketAsyncEventArgs
                this._saeSend = new SocketAsyncEventArgs();
                this._saeSend.SetBuffer(new byte[host.MessageBufferSize], 0, host.MessageBufferSize);
                this._saeSend.Completed += new EventHandler <SocketAsyncEventArgs>(this.SendAsyncCompleted);
                this._packetQueue        = new PacketQueue(this.SendPacketInternal);

                //init receive socketAsyncEventArgs
                this._saeReceive = new SocketAsyncEventArgs();
                this._saeReceive.SetBuffer(new byte[host.MessageBufferSize], 0, host.MessageBufferSize);
                this._saeReceive.Completed += new EventHandler <SocketAsyncEventArgs>(this.ReceiveAsyncCompleted);
            }
예제 #3
0
        void ProcessPackets()
        {
            while (IsConnected)
            {
                try {
                    MCForge.Networking.Packet packet = PacketQueue.InQueue.Dequeue();
                    // PacketEventArgs args = new PacketEventArgs(packet.WritePacket(), true, )

                    switch (packet.PacketID)
                    {
                    case PacketIDs.Identification:
                        ProcessLogin(packet as PacketIdentification);
                        break;

                    case PacketIDs.PlayerSetBlock:
                        ProcessBlockChange(packet as PacketPlayerSetBlock);
                        break;

                    case PacketIDs.PosAndRot:
                        ProcessPosAndRot(packet as PacketPositionAndOrientation);
                        break;

                    case PacketIDs.Message:
                        ProcessMessage(packet as PacketMessage);
                        break;
                    }
                }
                catch {
                    break;
                }
            }

            PacketQueue.CloseConnection();
        }
예제 #4
0
 // Use this for initialization
 void Start()
 {
     // 송수신 버퍼를 만듭니다.
     m_sendQueue = new PacketQueue();
     m_recvQueue = new PacketQueue();
     DontDestroyOnLoad(this);
 }
예제 #5
0
        public void OnData()
        {
            try
            {
                PacketReader packet = null;
                if (PacketQueue.Count > 0)
                {
                    packet = (PacketReader)PacketQueue.Dequeue();
                }
                else
                {
                    packet = new PacketReader(ReceiveBuffer);
                }

                PacketLog.WritePacket(clientSocket.RemoteEndPoint.ToString(), null, packet);

                if (Enum.IsDefined(typeof(Opcodes), packet.Opcode))
                {
                    PacketManager.InvokeHandler(ref packet, this, (Opcodes)packet.Opcode);
                }
                else
                {
                    Log.outDebug("Received unknown opcode 0x{0:X} ({0}) from AcountId:{1}", (ushort)packet.Opcode, GetAccountId());
                }
            }
            catch (Exception ex)
            {
                Log.outException(ex);
            }
        }
예제 #6
0
        public void TestGetRequestPacketExists()
        {
            PacketQueue queue = new PacketQueue();
            IPacketWrapper packetRequest = new MockPacket() {
                Packet = {
                    Origin = PacketOrigin.Client,
                    Type = PacketType.Request,
                    RequestId = 1
                }
            };

            IPacketWrapper packetResponse = new MockPacket() {
                Packet = {
                    Origin = PacketOrigin.Client,
                    Type = PacketType.Response,
                    RequestId = 1
                }
            };

            queue.PacketSend(packetRequest);
            Assert.AreEqual(1, queue.OutgoingPackets.Count);

            IPacketWrapper fetchedRequestPacket = queue.GetRequestPacket(packetResponse);

            Assert.AreEqual(packetRequest, fetchedRequestPacket);
        }
예제 #7
0
        /// <summary>
        /// //Tells a client where all the other players are in the world so they can be spawned in before they can enter the world
        /// </summary>
        /// <param name="ClientID">NetworkID for target client</param>
        public static void SendActivePlayerList(int ClientID)
        {
            CommunicationLog.LogOut(ClientID + " active player list");

            //Create a new NetworkPacket object to store the data for this active player list
            NetworkPacket Packet = new NetworkPacket();

            //Grab the list of all the other active game clients
            List <ClientConnection> OtherClients = ClientSubsetFinder.GetInGameClientsExceptFor(ClientID);

            //Write the relevant data values into the packet data
            Packet.WriteType(ServerPacketType.ActivePlayerList);
            Packet.WriteInt(OtherClients.Count);

            //Loop through the list of other clients and write each of their information into the packet data
            foreach (ClientConnection OtherClient in OtherClients)
            {
                //Write each characters name, and current location and rotation values
                Packet.WriteString(OtherClient.Character.Name);
                Packet.WriteBool(OtherClient.Character.IsAlive);
                Packet.WriteVector3(OtherClient.Character.Position);
                Packet.WriteQuaternion(OtherClient.Character.Rotation);
                Packet.WriteInt(OtherClient.Character.CurrentHealth);
                Packet.WriteInt(OtherClient.Character.MaxHealth);
            }

            //Add this packet to the target clients outgoing packet queue
            PacketQueue.QueuePacket(ClientID, Packet);
        }
예제 #8
0
        /// <summary>
        /// //Tells a client all the items currently socketed into their ability bar to be loaded in before they can enter into the game world
        /// </summary>
        /// <param name="ClientID">NetworkID of target client</param>
        /// <param name="CharacterName">Name of character who's socketed abilities are being sent</param>
        public static void SendSocketedAbilities(int ClientID, string CharacterName)
        {
            CommunicationLog.LogOut(ClientID + " socketed abilities");

            //Create a new NetworkPacket object to store the data for this socketed abilities request
            NetworkPacket Packet = new NetworkPacket();

            //Grab the list of all the items currently socketed into the characters action bar
            List <ItemData> SocketedAbilities = ActionBarsDatabase.GetEveryActionBarItem(CharacterName);

            //Write the relevant data values into the packet data
            Packet.WriteType(ServerPacketType.SocketedAbilities);

            Packet.WriteInt(0);
            PacketQueue.QueuePacket(ClientID, Packet);

            //Packet.WriteInt(SocketedAbilities.Count);

            ////Loop through the list and write in each items information into the packet data
            //foreach(ItemData Ability in SocketedAbilities)
            //{
            //    Packet.WriteInt(Ability.ItemNumber);
            //    Packet.WriteInt(Ability.ItemID);
            //}

            ////Add this packet to the target clients outgoing packet queue
            //PacketQueue.QueuePacket(ClientID, Packet);
        }
예제 #9
0
        /// <summary>
        /// //Tells a client where all the active entities are in the world to have them spawned in before they can enter the game world
        /// </summary>
        /// <param name="ClientID">NetworkID for target client</param>
        public static void SendActiveEntityList(int ClientID)
        {
            CommunicationLog.LogOut(ClientID + " active entity list");

            //Create a new NetworkPacket object to store the data for this active entity list
            NetworkPacket Packet = new NetworkPacket();

            //Grab the list of all the entities currently active in the game world
            List <BaseEntity> ActiveEntities = EntityManager.ActiveEntities;

            //Write the relevant data values into the packet data
            Packet.WriteType(ServerPacketType.ActiveEntityList);
            Packet.WriteInt(ActiveEntities.Count);

            //Loop through the list of active entities and write each of their information into the packet data
            foreach (BaseEntity ActiveEntity in ActiveEntities)
            {
                Packet.WriteString(ActiveEntity.Type);
                Packet.WriteString(ActiveEntity.ID);
                Packet.WriteVector3(VectorTranslate.ConvertVector(ActiveEntity.Location));
                Packet.WriteInt(ActiveEntity.HealthPoints);
            }

            //Add this packet to the target clients outgoing packet queue
            PacketQueue.QueuePacket(ClientID, Packet);
        }
예제 #10
0
        /// <summary>
        /// //Tells a client where all the active items are in the world to have them spawned in before they can start playing
        /// </summary>
        /// <param name="ClientID">NetworkID for target client</param>
        public static void SendActiveItemList(int ClientID)
        {
            CommunicationLog.LogOut(ClientID + " active item list");

            //Create a new NetworkPacket object to store the data for this active item list
            NetworkPacket Packet = new NetworkPacket();

            //Grab the list of all the active item pickups currently in the game world
            List <GameItem> ItemPickups = ItemManager.GetActiveItemList();

            //Write the relevant data values into the packet data
            Packet.WriteType(ServerPacketType.ActiveItemList);
            Packet.WriteInt(ItemPickups.Count);

            //Loop through the list of item pickups and write each of their information into the packet data
            foreach (GameItem ItemPickup in ItemPickups)
            {
                Packet.WriteInt(ItemPickup.ItemNumber);
                Packet.WriteInt(ItemPickup.ItemID);
                Packet.WriteVector3(VectorTranslate.ConvertVector(ItemPickup.ItemPosition));
            }

            //Add this packet to the target clients outgoing packet queue
            PacketQueue.QueuePacket(ClientID, Packet);
        }
예제 #11
0
        static int packet_queue_put_private(PacketQueue q, Native <AV.AVPacket> pkt)
        {
            MyAVPacketList pkt1 = new MyAVPacketList();

            if (q.abort_request != 0)
            {
                return(-1);
            }

            pkt1.pkt  = pkt;
            pkt1.next = null;
            if (pkt.P == flush_pkt.P)
            {
                q.serial++;
            }
            pkt1.serial = q.serial;

            if (q.last_pkt == null)
            {
                q.first_pkt = pkt1;
            }
            else
            {
                q.last_pkt.next = pkt1;
            }
            q.last_pkt = pkt1;
            q.nb_packets++;
            q.size += pkt1.pkt.O.size + Marshal.SizeOf(pkt.O) + 12;
            /* XXX: should duplicate packet data in DV case */
            SDL.SDL_CondSignal(q.cond);
            return(0);
        }
예제 #12
0
        /// <summary>
        /// //Tells a client all the items currently equipped on their chosen character to be loaded in before they enter into the game world
        /// </summary>
        /// <param name="ClientID">NetworkID of target client</param>
        /// <param name="CharacterName">Name of character who's equipped items are being sent</param>
        public static void SendEquippedItems(int ClientID, string CharacterName)
        {
            CommunicationLog.LogOut(ClientID + " equipped items");

            //Create a new NetworkPacket object to store the data for this equipped items request
            NetworkPacket Packet = new NetworkPacket();

            //Grab the list of all the items currently equipped on the character
            List <ItemData> EquippedItems = EquipmentsDatabase.GetAllEquipmentSlots(CharacterName);

            //Write the relevant data values into the packet data
            Packet.WriteType(ServerPacketType.EquippedItems);

            Packet.WriteInt(0);
            PacketQueue.QueuePacket(ClientID, Packet);

            //Packet.WriteInt(EquippedItems.Count);

            ////Loop through the list and write in each items information into the packet data
            //foreach(ItemData Item in EquippedItems)
            //{
            //    Packet.WriteInt((int)Item.ItemEquipmentSlot);
            //    Packet.WriteInt(Item.ItemNumber);
            //    Packet.WriteInt(Item.ItemID);
            //}

            ////Add this packet to the target clients outgoing packet queue
            //PacketQueue.QueuePacket(ClientID, Packet);
        }
예제 #13
0
        /// <summary>
        /// //Sends a message to a client (immediately) letting them know they have been kicked from the game
        /// </summary>
        /// <param name="ClientID">NetworkID of the target client</param>
        /// <param name="Reason">Reason this client is being kicked from the server</param>
        public static void SendKickedFromServer(int ClientID, string Reason = "No reason given")
        {
            //Get the client who we are kicking from the server
            ClientConnection TargetClient = ConnectionManager.GetClient(ClientID);

            //Make sure we were actually able to find this client
            if (TargetClient == null)
            {
                MessageLog.Print("ERROR: Cant kick client #" + ClientID + " as they could not be found in the connections");
                return;
            }

            //Log what is happening here
            MessageLog.Print("Kicking " + TargetClient.ClientID + " from the server...");

            //Create a new packet to send letting them know they have been kicked
            NetworkPacket Packet = new NetworkPacket();

            //Give it the next packet number they are expecting, then write the identifying packet type
            Packet.WriteInt(TargetClient.GetNextOrderNumber());
            Packet.WriteType(ServerPacketType.KickedFromServer);
            Packet.WriteString(Reason);

            //Send this packet off to them immediately to ensure its sent to them before we clean up their network connection ourselves
            PacketQueue.QueuePacket(ClientID, Packet);
        }
예제 #14
0
	// Use this for initialization
	void Start ()
    {

        // 송수신 버퍼를 만듭니다.
        m_sendQueue = new PacketQueue();
        m_recvQueue = new PacketQueue();	
	}
예제 #15
0
 static void packet_queue_start(PacketQueue q)
 {
     SDL.SDL_LockMutex(q.mutex);
     q.abort_request = 0;
     packet_queue_put_private(q, flush_pkt);
     SDL.SDL_UnlockMutex(q.mutex);
 }
예제 #16
0
    void Update()
    {
        // 서버로부터 받기
        if (m_pcFromServer.GetPacketCount() > 0)
        {
            PacketQueue queue = m_pcFromServer.GetBuffer();
            Socket      sock;
            int         count = queue.Count;
            for (int i = 0; i < count; i++)
            {
                queue.Dequeue(out sock, ref m_recvBuffer, m_recvBuffer.Length);
                ReceivePacket(m_notiServer, sock, m_recvBuffer);
            }
        }

        // 게스트(또는 호스트)로부터 받기
        if (m_pcFromP2P.GetPacketCount() > 0)
        {
            PacketQueue queue = m_pcFromP2P.GetBuffer();
            Socket      sock;
            int         count = queue.Count;
            for (int i = 0; i < count; i++)
            {
                queue.Dequeue(out sock, ref m_recvBuffer, m_recvBuffer.Length);
                ReceivePacket(m_notiP2P, sock, m_recvBuffer);
            }
        }
    }
예제 #17
0
 public void EnqueueSend(params ServerPacket[] packets)
 {
     foreach (var packet in packets)
     {
         PacketQueue.Enqueue(packet);
     }
 }
예제 #18
0
        private void Send()
        {
            try
            {
                while (Socket.Connected)
                {
                    if (this.clientAbort.WaitOne(10) || Worker.Singleton.ServerShutdown.WaitOne(10))
                    {
                        return;
                    }

                    while (PacketQueue.Count > 0)
                    {
                        var p = PacketQueue.Dequeue();
                        using (var ms = new MemoryStream())
                        {
                            using (var bw = new BinaryWriter(ms))
                            {
                                p.WriteTo(bw);
                                Logging.Debug(ms.ToArray().Hexdump());
                                Socket.Send(ms.ToArray());
                            }
                        }
                    }
                }
            }
            catch
            {
                // nevermind
            }

            this.clientAbort.Set();
        }
예제 #19
0
    void Awake()
    {
        DontDestroyOnLoad(this.gameObject);

        m_sendQueue = new PacketQueue();
        m_recvQueue = new PacketQueue();
    }
예제 #20
0
        public void UpdateWorld(float DeltaTime)
        {
            //Poll User Input from the server window
            ProcessInput(ApplicationWindow.Focused, DeltaTime);

            //Manage all client connections and their player characters
            ConnectionManager.CheckClients(DeltaTime);
            ConnectionManager.CleanDeadClients(World);
            ConnectionManager.AddNewClients(World);
            ConnectionManager.UpdateClientPositions(World);
            ConnectionManager.RespawnDeadPlayers(World);

            //Track current inhabitants of the PVP Battle Arena, then process the players PVP attacks
            List <CharacterData> InGameCharacters = ClientSubsetFinder.GetInGameCharacters();

            PVPBattleArena.UpdateArenaInhabitants(InGameCharacters);
            PVPBattleArena.AlertTravellers();
            ConnectionManager.PerformPlayerAttacks(World);

            //Update the packet queue, transmitting all messages to the client connections
            PacketQueue.UpdateQueue(DeltaTime, TransmitPackets);

            //Update the physics simulation
            World.Timestep(DeltaTime, ThreadDispatcher);
            TimeSamples.RecordFrame(World);
        }
        public byte[] CharaWorkExp(Socket sender)
        {
            if (PacketQueue == null || PacketQueue.Count == 0)
            {
                Inventory.Update(sender);

                Queue <short> jobLevel    = new Queue <short>();
                Queue <short> jobLevelCap = new Queue <short>();
                int           count       = 0;

                foreach (var item in Jobs)
                {
                    count++;
                    if (count > 52)
                    {
                        break;
                    }
                    Job job = item.Value;
                    jobLevel.Enqueue(job.Level);
                    jobLevelCap.Enqueue(job.LevelCap);
                }

                WorkProperties property = new WorkProperties(sender, Id, @"charaWork/exp");
                property.Add("charaWork.battleSave.skillLevel", jobLevel);
                property.Add("charaWork.battleSave.skillLevelCap", jobLevelCap, true);
                PacketQueue = property.PacketQueue;
            }

            return(PacketQueue.Dequeue());
        }
예제 #22
0
        public void TestPackagingOneTypeMessages()
        {
            var packetQueue = new PacketQueue(100, ConsoleLogger);

            packetQueue.Count.Should().Be(0);

            packetQueue.Enqueue(new DeliveryOptions(false, false), new Payload(new byte[] { 1 }, 0, 1));
            packetQueue.Count.Should().Be(1);
            packetQueue.Enqueue(new DeliveryOptions(false, false), new Payload(new byte[] { 1 }, 0, 1));
            packetQueue.Count.Should().Be(1);
            packetQueue.Enqueue(new DeliveryOptions(false, false), new Payload(new byte[] { 1 }, 0, 1));
            packetQueue.Count.Should().Be(1);
            packetQueue.Enqueue(new DeliveryOptions(true, false), new Payload(new byte[] { 1 }, 0, 1));
            packetQueue.Count.Should().Be(2);
            packetQueue.Enqueue(new DeliveryOptions(true, false), new Payload(new byte[] { 1 }, 0, 1));
            packetQueue.Count.Should().Be(2);
            packetQueue.Enqueue(new DeliveryOptions(true, true), new Payload(new byte[] { 1 }, 0, 1));
            packetQueue.Count.Should().Be(3);
            packetQueue.Enqueue(new DeliveryOptions(true, true), new Payload(new byte[] { 1 }, 0, 1));
            packetQueue.Count.Should().Be(3);
            packetQueue.Enqueue(new DeliveryOptions(false, true), new Payload(new byte[] { 1 }, 0, 1));
            packetQueue.Count.Should().Be(4);
            packetQueue.Enqueue(new DeliveryOptions(false, true), new Payload(new byte[] { 1 }, 0, 1));
            packetQueue.Count.Should().Be(4);

            foreach (var packet in packetQueue)
            {
                packet.Length.Should().BeGreaterThan(1);
            }

            foreach (var packet in (IEnumerable)packetQueue)
            {
                packet.Should().BeOfType <PacketInfo>();
            }
        }
예제 #23
0
 // Use this for initialization
 void Start()
 {
     // 송수신 버퍼를 작성합니다.
     _sendQueue        = new PacketQueue();
     _recvQueue        = new PacketQueue();
     _garbagecollector = new Thread(new ThreadStart(Observing));
 }
예제 #24
0
 public void PacketProcess(Packet iPacket)
 {
     lock (PacketQueue)
     {
         PacketQueue.Enqueue(iPacket);
     }
 }
예제 #25
0
        /// <summary>
        /// //Tells a clients all the contents of their chosen characters inventory to be loaded in before they enter into the game world
        /// </summary>
        /// <param name="ClientID">NetworkID of target client</param>
        /// <param name="CharacterName">Name of character who's inventory contents are being sent</param>
        public static void SendInventoryContents(int ClientID, string CharacterName)
        {
            CommunicationLog.LogOut(ClientID + " inventory contents");

            //Create a new NetworkPacket object to store the data for this inventory contents request
            NetworkPacket Packet = new NetworkPacket();

            //Grab the list of all the items currently in the characters inventory
            List <ItemData> InventoryContents = InventoriesDatabase.GetAllInventorySlots(CharacterName);

            //Write the relevant data values into the packet data
            Packet.WriteType(ServerPacketType.InventoryContents);

            Packet.WriteInt(0);
            PacketQueue.QueuePacket(ClientID, Packet);

            //Packet.WriteInt(InventoryContents.Count);

            ////Loop through the list of items in the players inventory and write all of their information into the packet data
            //foreach(ItemData Item in InventoryContents)
            //{
            //    Packet.WriteInt(Item.ItemNumber);
            //    Packet.WriteInt(Item.ItemID);
            //}

            ////Add this packet to the target clients outgoing packet queue
            //PacketQueue.QueuePacket(ClientID, Packet);
        }
예제 #26
0
            /// <summary>
            /// new
            /// </summary>
            /// <param name="connectionID"></param>
            /// <param name="socket"></param>
            /// <param name="host"></param>
            /// <exception cref="ArgumentNullException">socket is null</exception>
            /// <exception cref="ArgumentNullException">host is null</exception>
            public DefaultConnection(long connectionID, Socket socket, BaseHost host)
            {
                if (socket == null)
                {
                    throw new ArgumentNullException("socket");
                }
                if (host == null)
                {
                    throw new ArgumentNullException("host");
                }

                this.ConnectionID       = connectionID;
                this._socket            = socket;
                this._messageBufferSize = host.MessageBufferSize;
                this._host = host;

                try
                {
                    this.LocalEndPoint  = (IPEndPoint)socket.LocalEndPoint;
                    this.RemoteEndPoint = (IPEndPoint)socket.RemoteEndPoint;
                }
                catch (Exception ex) { Log.Trace.Error("get socket endPoint error.", ex); }

                //init send
                this._saeSend            = host._saePool.Acquire();
                this._saeSend.Completed += this.SendAsyncCompleted;
                this._packetQueue        = new PacketQueue(this.SendPacketInternal);

                //init receive
                this._saeReceive            = host._saePool.Acquire();
                this._saeReceive.Completed += this.ReceiveAsyncCompleted;
            }
예제 #27
0
        private void FlushPackets()
        {
            while (PacketQueue.Count > 0)
            {
                ServerPacket packet;
                if (PacketQueue.TryDequeue(out packet))
                {
                    if (packet.Header.HasFlag(PacketHeaderFlags.EncryptedChecksum) && ConnectionData.PacketSequence < 2)
                    {
                        ConnectionData.PacketSequence = 2;
                    }

                    packet.Header.Sequence = ConnectionData.PacketSequence++;
                    packet.Header.Id       = 0x0B; // This value is currently the hard coded Server ID. It can be something different...
                    packet.Header.Table    = 0x14;
                    packet.Header.Time     = (ushort)ConnectionData.ServerTime;

                    if (packet.Header.Sequence >= 2u)
                    {
                        CachedPackets.TryAdd(packet.Header.Sequence, packet);
                    }

                    SendPacket(packet);
                }
            }
        }
예제 #28
0
        private void FlushPackets()
        {
            while (PacketQueue.Count > 0)
            {
                ServerPacket packet;
                if (PacketQueue.TryDequeue(out packet))
                {
                    if (packet.Header.HasFlag(PacketHeaderFlags.EncryptedChecksum) && ConnectionData.PacketSequence < 2)
                    {
                        ConnectionData.PacketSequence = 2;
                    }

                    packet.Header.Sequence = ConnectionData.PacketSequence++;
                    packet.Header.Id       = (ushort)(connectionType == ConnectionType.Login ? 0x0B : 0x18);
                    packet.Header.Table    = 0x14;
                    packet.Header.Time     = (ushort)ConnectionData.ServerTime;

                    if (packet.Header.Sequence >= 2u)
                    {
                        CachedPackets.TryAdd(packet.Header.Sequence, packet);
                    }

                    SendPacket(packet);
                }
            }
        }
예제 #29
0
        /// <summary>
        /// //Asks a client if they are still connected, requesting for them to immediately reply to us letting us know
        /// </summary>
        /// <param name="ClientID">NetworkID of the target client</param>
        public static void SendStillConnectedCheck(int ClientID)
        {
            CommunicationLog.LogOut(ClientID + " still alive request");
            NetworkPacket Packet = new NetworkPacket();

            Packet.WriteType(ServerPacketType.StillConnectedCheck);
            PacketQueue.QueuePacket(ClientID, Packet);
        }
예제 #30
0
 public WebSocketProtocol(WebSocket socket)
 {
     this.socket      = socket;
     pinnedForSending = new PacketQueue(async(data, end) => await socket.SendAsync(new ArraySegment <byte>(data),
                                                                                   WebSocketMessageType.Binary,
                                                                                   end,
                                                                                   CancellationToken.None));
 }
예제 #31
0
        public int InsertPacketQueue(PacketQueue packetqueue)
        {
            int rs = 0;

            ctx.PacketQueues.Add(packetqueue);
            rs = ctx.SaveChanges();
            return(rs);
        }
예제 #32
0
    public void CreateRyu()
    {
        mServerIPAddress = "192.168.0.21";
        mPort            = 50765;

        mSendQueue = new PacketQueue();
        mRecvQueue = new PacketQueue();
    }
예제 #33
0
 static void packet_queue_destroy(PacketQueue q)
 {
     packet_queue_flush(q);
     SDL.SDL_DestroyMutex(q.mutex);
     SDL.SDL_DestroyCond(q.cond);
 }
예제 #34
0
        public void TestPacketReceivedRemoveFromOutgoing()
        {
            PacketQueue queue = new PacketQueue();

            IPacketWrapper sentPacket = new MockPacket() {
                Packet = {
                    Origin = PacketOrigin.Client,
                    Type = PacketType.Request,
                    RequestId = 1
                }
            };

            IPacketWrapper recievedPacket = new MockPacket() {
                Packet = {
                    Origin = PacketOrigin.Client,
                    Type = PacketType.Response,
                    RequestId = 1
                }
            };

            IPacketWrapper poppedPacket = queue.PacketSend(sentPacket);

            // Client would send to the server.

            Assert.AreEqual(sentPacket, poppedPacket);
            Assert.AreEqual(1, queue.OutgoingPackets.Count);
            Assert.AreEqual(0, queue.QueuedPackets.Count);

            poppedPacket = queue.PacketReceived(recievedPacket);

            Assert.IsNull(poppedPacket);
            Assert.AreEqual(0, queue.OutgoingPackets.Count);
            Assert.AreEqual(0, queue.QueuedPackets.Count);
        }
예제 #35
0
        public void TestPacketSendImmediate()
        {
            PacketQueue queue = new PacketQueue();
            IPacketWrapper packet = new MockPacket() {
                Packet = {
                    Origin = PacketOrigin.Client,
                    Type = PacketType.Request,
                    RequestId = 1
                }
            };

            IPacketWrapper poppedPacket = queue.PacketSend(packet);

            // Client would send to the server.

            Assert.AreEqual(packet, poppedPacket);
            Assert.AreEqual(1, queue.OutgoingPackets.Count);
            Assert.AreEqual(0, queue.QueuedPackets.Count);
        }
예제 #36
0
        public void TestRestartConnectionOnQueueFailureFalsey()
        {
            PacketQueue queue = new PacketQueue();
            IPacketWrapper packet = new MockPacket() {
                Packet = {
                    Origin = PacketOrigin.Client,
                    Type = PacketType.Request,
                    RequestId = 1
                }
            };

            IPacketWrapper poppedPacket = queue.PacketSend(packet);

            Assert.AreEqual(packet, poppedPacket);
            Assert.AreEqual(1, queue.OutgoingPackets.Count);

            Assert.IsFalse(queue.RestartConnectionOnQueueFailure());
        }
예제 #37
0
        public void TestPacketSendQueued()
        {
            PacketQueue queue = new PacketQueue();
            IPacketWrapper firstPacket = new MockPacket() {
                Packet = {
                    Origin = PacketOrigin.Client,
                    Type = PacketType.Request,
                    RequestId = 1
                }
            };

            IPacketWrapper poppedPacket = queue.PacketSend(firstPacket);

            // Client would send to the server.

            Assert.AreEqual(firstPacket, poppedPacket);
            Assert.AreEqual(1, queue.OutgoingPackets.Count);

            IPacketWrapper secondPacket = new MockPacket() {
                Packet = {
                    Origin = PacketOrigin.Client,
                    Type = PacketType.Request,
                    RequestId = 1
                }
            };

            poppedPacket = queue.PacketSend(secondPacket);

            // Popped packet is null, client would essentially ignore it until later.

            Assert.IsNull(poppedPacket);
            Assert.AreEqual(1, queue.OutgoingPackets.Count);
            Assert.AreEqual(1, queue.QueuedPackets.Count);
        }
예제 #38
0
        public void TestPacketReceivedRemovedAndPopped()
        {
            PacketQueue queue = new PacketQueue();

            IPacketWrapper firstPacketRequest = new MockPacket() {
                Packet = {
                    Origin = PacketOrigin.Client,
                    Type = PacketType.Request,
                    RequestId = 1
                }
            };

            IPacketWrapper secondPacketRequest = new MockPacket() {
                Packet = {
                    Origin = PacketOrigin.Client,
                    Type = PacketType.Request,
                    RequestId = 2
                }
            };

            IPacketWrapper firstPacketResponse = new MockPacket() {
                Packet = {
                    Origin = PacketOrigin.Client,
                    Type = PacketType.Response,
                    RequestId = 1
                }
            };

            queue.PacketSend(firstPacketRequest);
            queue.PacketSend(secondPacketRequest);
            Assert.AreEqual(1, queue.OutgoingPackets.Count);
            Assert.AreEqual(1, queue.QueuedPackets.Count);

            IPacketWrapper poppedPacket = queue.PacketReceived(firstPacketResponse);
            Assert.AreEqual(secondPacketRequest, poppedPacket);

            queue.PacketSend(poppedPacket);

            Assert.AreEqual(1, queue.OutgoingPackets.Count);
            Assert.AreEqual(0, queue.QueuedPackets.Count);
        }
예제 #39
0
        public void TestRestartConnectionOnQueueFailureTruey()
        {
            PacketQueue queue = new PacketQueue();
            IPacketWrapper packet = new MockPacket() {
                Packet = {
                    Origin = PacketOrigin.Client,
                    Type = PacketType.Request,
                    RequestId = 1,
                    Stamp = DateTime.Now.AddMinutes(-5)
                }
            };

            IPacketWrapper poppedPacket = queue.PacketSend(packet);

            Assert.AreEqual(packet, poppedPacket);
            Assert.AreEqual(1, queue.OutgoingPackets.Count);

            Assert.IsTrue(queue.RestartConnectionOnQueueFailure());
        }
예제 #40
0
        static int packet_queue_put(PacketQueue q, Native<AV.AVPacket> pkt)
        {
            int ret;

            /* duplicate the packet */
            if (pkt.P != flush_pkt.P && AV.av_dup_packet(pkt.P) < 0)
                return -1;

            SDL.SDL_LockMutex(q.mutex);
            ret = packet_queue_put_private(q, pkt);
            SDL.SDL_UnlockMutex(q.mutex);

            if (pkt.P != flush_pkt.P && ret < 0)
                AV.av_free_packet(pkt.P);

            return ret;
        }
예제 #41
0
        static int packet_queue_put_private(PacketQueue q, Native<AV.AVPacket> pkt)
        {
            MyAVPacketList pkt1 = new MyAVPacketList();

            if (q.abort_request != 0)
                return -1;

            pkt1.pkt = pkt;
            pkt1.next = null;
            if (pkt.P == flush_pkt.P)
                q.serial++;
            pkt1.serial = q.serial;

            if (q.last_pkt == null)
                q.first_pkt = pkt1;
            else
                q.last_pkt.next = pkt1;
            q.last_pkt = pkt1;
            q.nb_packets++;
            q.size += pkt1.pkt.O.size + Marshal.SizeOf(pkt.O) + 12;
            /* XXX: should duplicate packet data in DV case */
            SDL.SDL_CondSignal(q.cond);
            return 0;
        }
예제 #42
0
 static int packet_queue_put_nullpacket(PacketQueue q, int stream_index)
 {
     Native<AV.AVPacket> pkt1 = new Native<AV.AVPacket>(new AV.AVPacket());
     Native<AV.AVPacket> pkt = new Native<AV.AVPacket>(pkt1.P);
     AV.av_init_packet(pkt.P);
     var O = pkt.O;
     O.data = IntPtr.Zero;
     O.size = 0;
     O.stream_index = stream_index;
     pkt.O = O;
     return packet_queue_put(q, pkt);
 }
예제 #43
0
 /* packet queue handling */
 static void packet_queue_init(PacketQueue q)
 {
     q.mutex = SDL.SDL_CreateMutex();
     q.cond = SDL.SDL_CreateCond();
     q.abort_request = 1;
 }
예제 #44
0
 //-------------------------------
 // LifeCycle
 //-------------------------------
 void Start()
 {
     sendQueue = new PacketQueue();
     recvQueue = new PacketQueue();
 }
예제 #45
0
 static void packet_queue_start(PacketQueue q)
 {
     SDL.SDL_LockMutex(q.mutex);
     q.abort_request = 0;
     packet_queue_put_private(q, flush_pkt);
     SDL.SDL_UnlockMutex(q.mutex);
 }
예제 #46
0
        /* return < 0 if aborted, 0 if no packet and > 0 if packet.  */
        static int packet_queue_get(PacketQueue q, out Native<AV.AVPacket> pkt, int block, out int serial)
        {
            MyAVPacketList pkt1;
            int ret;

            pkt = null;
            serial = 0;

            SDL.SDL_LockMutex(q.mutex);

            for (; ; )
            {
                if (q.abort_request != 0)
                {
                    ret = -1;
                    break;
                }

                pkt1 = q.first_pkt;
                if (pkt1 != null)
                {
                    q.first_pkt = pkt1.next;
                    if (q.first_pkt == null)
                        q.last_pkt = null;
                    q.nb_packets--;
                    q.size -= pkt1.pkt.O.size + Marshal.SizeOf(pkt1.pkt.O) + 12;
                    pkt = pkt1.pkt;
                    //if (serial != 0)
                        serial = pkt1.serial;
                    //AV.av_free(pkt1);
                    ret = 1;
                    break;
                }
                else if (block == 0)
                {
                    ret = 0;
                    break;
                }
                else
                {
                    SDL.SDL_CondWait(q.cond, q.mutex);
                }
            }
            SDL.SDL_UnlockMutex(q.mutex);
            return ret;
        }
예제 #47
0
        static void packet_queue_flush(PacketQueue q)
        {
            MyAVPacketList pkt, pkt1;

            SDL.SDL_LockMutex(q.mutex);
            for (pkt = q.first_pkt; pkt != null; pkt = pkt1)
            {
                pkt1 = pkt.next;
                AV.av_free_packet(pkt.pkt.P);
                //AV.av_freep(pkt);
            }
            q.last_pkt = null;
            q.first_pkt = null;
            q.nb_packets = 0;
            q.size = 0;
            SDL.SDL_UnlockMutex(q.mutex);
        }
예제 #48
0
        static void packet_queue_abort(PacketQueue q)
        {
            SDL.SDL_LockMutex(q.mutex);

            q.abort_request = 1;

            SDL.SDL_CondSignal(q.cond);

            SDL.SDL_UnlockMutex(q.mutex);
        }