private static void ReadMovement(Client client, PacketReader reader) { MovePacket mp = new MovePacket(); mp.Read(reader); if (!reader.Failed) { Client.HandleMovePacket(client, mp); } }
public static void ReadHandshake(Client client, PacketReader reader) { HandshakePacket hp = new HandshakePacket(); hp.Read(reader); if (!reader.Failed) { client.HandleHandshake(hp); } }
public static void ReadKeepAlive(Client client, PacketReader reader) { KeepAlivePacket ap = new KeepAlivePacket(); ap.Read(reader); if (!reader.Failed) { Client.HandleKeepAlive(client, ap); } }
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."); } }
public ServerPlayer getForClient(Client client) { return getForClient(client.ClientId); }
public static void HandleMovePacket(Client client, MovePacket mp) { client.Player.PrepareToMove(mp.Direction, mp.Speed); }
private void AddClient(Client c) { Clients.TryAdd(c.ClientId, c); Interlocked.Increment(ref _clientDictChanges); }
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; }
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(); }
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); } }
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(); } }); }
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(); } }); } }
public void RemoveClient(Client c) { Clients.TryRemove(c.ClientId, out c); Interlocked.Increment(ref _clientDictChanges); }
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); }