Ejemplo n.º 1
0
        private static void ReadMovement(Client client, PacketReader reader)
        {
            MovePacket mp = new MovePacket();
            mp.Read(reader);

            if (!reader.Failed)
            {
                Client.HandleMovePacket(client, mp);
            }
        }
Ejemplo n.º 2
0
        public static void ReadHandshake(Client client, PacketReader reader)
        {
            HandshakePacket hp = new HandshakePacket();
            hp.Read(reader);

            if (!reader.Failed)
            {
                client.HandleHandshake(hp);
            }
        }
Ejemplo n.º 3
0
        public static void ReadKeepAlive(Client client, PacketReader reader)
        {
            KeepAlivePacket ap = new KeepAlivePacket();
            ap.Read(reader);

            if (!reader.Failed)
            {
                Client.HandleKeepAlive(client, ap);
            }
        }
Ejemplo n.º 4
0
 public static void HandleKeepAlive(Client client, KeepAlivePacket ap)
 {
     if (ap.TimeStamp + 3000 > DateTime.Now.Ticks)
     {
         //TODO: Client Timeout. Disconnect Player
     }
     else
     {
         //Keep Alive Response came within time
         Console.WriteLine("Timeout Check is okey.");
     }
 }
Ejemplo n.º 5
0
 public ServerPlayer getForClient(Client client)
 {
     return getForClient(client.ClientId);
 }
Ejemplo n.º 6
0
 public static void HandleMovePacket(Client client, MovePacket mp)
 {
     client.Player.PrepareToMove(mp.Direction, mp.Speed);
 }
Ejemplo n.º 7
0
 private void AddClient(Client c)
 {
     Clients.TryAdd(c.ClientId, c);
     Interlocked.Increment(ref _clientDictChanges);
 }
Ejemplo n.º 8
0
        private static byte[] GetBufferToBeRead(ByteQueue processedBuffer, Client client, int length)
        {
            int availableData = client.FragPackets.Size + processedBuffer.Size;

            if (length > availableData)
                return null;

            int fromFrag;

            byte[] data = new byte[length];

            if (length >= client.FragPackets.Size)
                fromFrag = client.FragPackets.Size;
            else
                fromFrag = length;

            client.FragPackets.Dequeue(data, 0, fromFrag);

            int fromProcessed = length - fromFrag;

            processedBuffer.Dequeue(data, fromFrag, fromProcessed);

            return data;
        }
Ejemplo n.º 9
0
        private void AcceptProcess(SocketAsyncEventArgs e)
        {
            if (OnBeforeAccept(e.AcceptSocket))
            {
                Console.WriteLine("Incoming Connection");
                int clientId = Interlocked.Increment(ref _nextClientId);
                // FIXME: client muss noch aus datenbank geladen werden
                Client c = new Client(clientId, clientId, this, e.AcceptSocket);

                c.Start();

                AddClient(c);
            }
            else
            {
                if (e.AcceptSocket.Connected)
                {
                    e.AcceptSocket.Shutdown(SocketShutdown.Both);
                }
                e.AcceptSocket.Close();
            }

            _acceptEventArgs.AcceptSocket = null;
            Interlocked.Exchange(ref _asyncAccepts, 0);
            NetworkSignal.Set();
        }
Ejemplo n.º 10
0
 private static void EnqueueFragment(Client client, byte[] data)
 {
     int fragPacketWaiting = client.FragPackets.Length;
     // We are waiting for more data than an uncompressed chunk, it's not possible
     if (fragPacketWaiting > 81920)
     {
         //client.Kick("Too much pending data to be read");
     }
     else
     {
         client.FragPackets.Enqueue(data, 0, data.Length);
     }
 }
Ejemplo n.º 11
0
        internal void SendPacketToNearbyPlayers(WorldPosition pos, Packet packet, Client excludedClient = null)
        {
            Client[] nearbyClients = GetNearbyPlayers(pos).ToArray();

            if (nearbyClients.Length == 0)
                return;

            packet.SetShared(nearbyClients.Length);

            Parallel.ForEach(nearbyClients, client =>
                {
                    if (excludedClient != client)
                    {
                        client.SendPacket(packet);
                    }
                    else
                    {
                        packet.Release();
                    }
                });
        }
Ejemplo n.º 12
0
        internal void SendPacketToClientList(Packet packet, Client[] targetList, Client excludedClient = null)
        {
            if (targetList.Length == 0)
                return;

            if (targetList.Length == 1)
            {
                if (targetList[0] == excludedClient)
                    return;
                targetList[0].SendPacket(packet);
            }
            else
            {
                packet.SetShared(targetList.Length);

                Parallel.ForEach(targetList, client =>
                    {
                        if (excludedClient != client)
                        {
                            client.SendPacket(packet);
                        }
                        else
                        {
                            packet.Release();
                        }
                    });
            }
        }
Ejemplo n.º 13
0
 public void RemoveClient(Client c)
 {
     Clients.TryRemove(c.ClientId, out c);
     Interlocked.Increment(ref _clientDictChanges);
 }
Ejemplo n.º 14
0
 internal void UninfomClient(Client client)
 {
     if (client != this)
     {
         EntityDespawnPacket dp = new EntityDespawnPacket {
             EntityId = client.ClientId
         };
         dp.Write();
         client.SendSync(dp);
     }
     byte dummy;
     _awareCloseClients.TryRemove(client, out dummy);
 }