private static void ServerConnectionOnPacketReceived(object sender, Packet rawPacket) { Packet?handledPacket = null; serverProxyLatencyMeter.Measure(rawPacket, () => { try { handledPacket = serverPacketHandler.HandlePacket(rawPacket); } catch (PacketMaterializationException ex) { // just log exception and continue, do not interrupt proxy Console.Error(ex.ToString()); DumpPacketLog(); } catch (Exception ex) { // just log exception and continue, do not interrupt proxy Console.Error(ex.ToString()); } }); if (handledPacket != null) { SendToClient(handledPacket.Value); } }
private void ServerConnectionOnPacketReceived(object sender, Packet rawPacket) { try { var handledPacket = serverPacketHandler.HandlePacket(rawPacket); if (transmitClientPackets && handledPacket.HasValue) { SendToClient(handledPacket.Value); } } catch (PacketMaterializationException ex) { // just log exception and continue, do not interrupt proxy console.Error(ex.ToString()); } catch (Exception ex) { // just log exception and continue, do not interrupt proxy console.Debug(ex.ToString()); } }
private void OnReceive(IAsyncResult result) { Socket socket = (Socket)result.AsyncState; try { int received = socket.EndReceive(result); if (received <= 0) { CloseClient(index); } else { byte[] dataBuffer = new byte[received]; Array.Copy(_buffer, dataBuffer, received); packetHandler.HandlePacket(index, dataBuffer); socket.BeginReceive(_buffer, 0, _buffer.Length, SocketFlags.None, new AsyncCallback(OnReceive), socket); } } catch { CloseClient(index); } }
private void Recieve() { byte[] _sizeInfo = new byte[4]; int totalRead = 0; int currentRead = 0; try { if (closing) { return; } if (!socket.Connected) { closing = true; return; } currentRead = totalRead = socket.Receive(_sizeInfo); Debug.Log("Sizeinfo: " + _sizeInfo.Length); if (totalRead <= 0) { return; } else { // Read message size info while (totalRead < _sizeInfo.Length && currentRead > 0) { currentRead = socket.Receive(_sizeInfo, totalRead, _sizeInfo.Length - totalRead, SocketFlags.None); totalRead += currentRead; } int messagesize = 0; messagesize |= _sizeInfo[0]; messagesize |= (_sizeInfo[1] << 8); messagesize |= (_sizeInfo[2] << 16); messagesize |= (_sizeInfo[3] << 24); // Read message data byte[] data = new byte[messagesize]; totalRead = 0; currentRead = totalRead = socket.Receive(data, totalRead, data.Length - totalRead, SocketFlags.None); while (totalRead < messagesize && currentRead > 0) { currentRead = socket.Receive(data, totalRead, data.Length - totalRead, SocketFlags.None); totalRead += currentRead; } // Handle the received packet.. Debug.Log("Received " + data.Length + " bytes from client " + index); packetHandler.HandlePacket(index, data); } } catch (Exception ex) { Logger.Log("You are not connected to the server: " + ex.Message); CloseClient(index); } }
public Packet?PacketReceivedFromServer(byte[] payload) => ServerPacketHandler.HandlePacket(new Packet(payload[0], payload));
public Packet?PacketReceivedFromServer(Packet packet) => ServerPacketHandler.HandlePacket(packet);