public override bool HandlePacket(NetInboundPacket packet, CustomPacketType type) { if (type == CustomPacketType.Instantiate) { if (HoldInstantiationPackets) { heldInstantiationPackets.Enqueue(packet); } else { HandleInstantiationPacket(packet); } } else if (type == CustomPacketType.Destroy) { if (HoldDestroyPackets) { heldDestroyPackets.Enqueue(packet); } else { HandleDestroyPacket(packet); } } else { return(false); } return(true); }
public void Update(float deltaTime) { // Update internal messenger base.Update(); // Read packets for (int i = 0; i < 1000 && AvailablePackets > 0; i++) { NetInboundPacket packet = ReadPacket(); if (packet.Position >= packet.Length) { DashCMD.WriteError("[AOSServer] Received invalid custom packet from {0}! (bad packet position)", packet.Sender); } else { CustomPacketType type = (CustomPacketType)packet.ReadByte(); // Try and handle the packet if (!HandlePacket(packet, type)) { DashCMD.WriteWarning("[AOSServer] Received unknown custom packet {0}, from {1}", type, packet.Sender); } } } // Update each component foreach (NetComponent c in components.Values) { c.Update(deltaTime); } }
public override bool HandlePacket(NetInboundPacket packet, CustomPacketType type) { if (type == CustomPacketType.Snapshot) { ushort pid = packet.ReadUInt16(); NetConnectionSnapshotState connState; if (ConnectionStates.TryGetValue(packet.Sender, out connState)) { //connState.GotPacket = true; if (connState.MeasuringRTT) { connState.MeasuringRTT = false; connState.RoundTripTime = Interpolation.Linear(connState.RoundTripTime, connState.RTT_TimeSinceLastSend, 0.15f); } ushort ppid = connState.LastInboundSnapshotId; connState.LastInboundSnapshotId = pid; if (pid <= ppid && pid != 0) { DashCMD.WriteWarning("[SnapshotNC] Dropping late client snapshot..."); return(true); } snapshotSystem.OnInbound(packet); charSnapshotSystem.OnServerInbound(packet, connState); } return(true); } else { return(false); } }
bool OnCustomPacket(NetInboundPacket packet, CustomPacketType type) { if (type == CustomPacketType.HandshakeComplete || type == CustomPacketType.WorldSectionAck) { handshakeComponent.OnPacketInbound(packet, type); return(true); } return(false); }
public void OnPacketInbound(NetInboundPacket packet, CustomPacketType type) { if (type == CustomPacketType.HandshakeComplete) { // Were all done here component.HandshakeCompleted(this); } else if (type == CustomPacketType.WorldSectionAck) { SendNextTerrainChunk(); } }
public override bool HandlePacket(NetInboundPacket packet, CustomPacketType type) { if (type == CustomPacketType.Snapshot) { if (measuringRTT) { rtt = Interpolation.Linear(rtt, timeSinceSend, 0.15f); measuringRTT = false; } gotPacket = true; ushort pid = packet.ReadUInt16(); if (pid <= lastServerPId && pid != 0) { DashCMD.WriteWarning("[SnapshotNC] Dropping late server snapshot..."); return(true); } snapshotSystem.OnInbound(packet); ushort snapshotLength = packet.ReadUInt16(); if (WorldSnapshot != null) { // Read the snapshot WorldSnapshot.Deserialize(packet); // Update players charSnapshotSystem.OnClientInbound(WorldSnapshot); // Invoke event if (OnWorldSnapshotInbound != null) { OnWorldSnapshotInbound(this, WorldSnapshot); } } else { packet.Position += snapshotLength; DashCMD.WriteWarning("[SnapshotNC] Received snapshot before worldsnapshot was intialized!"); } lastServerPId = pid; return(true); } else { return(false); } }
public void OnPacketInbound(NetInboundPacket packet, CustomPacketType type) { Handshake h; if (handshakes.TryGetValue(packet.Sender, out h)) { h.OnPacketInbound(packet, type); } else { DashCMD.WriteError("[HS] Received handshake completion packet, but connection {0} is not in a handshake!", packet.Sender); } }
bool OnCustomPacket(NetInboundPacket packet, CustomPacketType type) { if (type == CustomPacketType.HandshakeInitiate) { if (handshake != null) { DashCMD.WriteError("Got handshake initiate packet, but we are already in a handshake!"); return(false); } // Begin the handshake on our end handshake = new Handshake(client, this, packet); loadingBar.SetHandshake(handshake); // We don't want to have the user staring at a blank skybox, // so lets show them pictures :D StaticGui.ShowBackground = true; return(true); } else if (type == CustomPacketType.WorldSection) { if (handshake != null) { // Notify the handshake we have received another // piece of the world data. handshake.OnLevelChunkInbound(packet); } else { DashCMD.WriteError("Got handshake world section packet, but we are not in a handshake!"); // We did acknowledge the packet, // but since we are not in the right state // act as if its unknown (little extra protection // from a rogue server). return(false); } return(true); } return(false); }
bool HandlePacket(NetInboundPacket packet, CustomPacketType type) { // Give each component a chance to try and handle the packet type, // if none process it we've received an unknown packet. foreach (NetComponent c in components.Values) { if (c.HandlePacket(packet, type)) { return(true); } } // Attempt to defer packet to the custom handlers for (int i = 0; i < packetHooks.Count; i++) { if (packetHooks[i](packet, type)) { return(true); } } return(false); }
/// <summary> /// Attempts to process packet with this component. /// Returns true if handled, false is unhandled. /// </summary> /// <returns>true if handled, false is unhandled</returns> public virtual bool HandlePacket(NetInboundPacket packet, CustomPacketType type) { return(false); }