public static Packet ReadPacket(Stream stream) { var packetType = stream.ReadByte(); Packet packet = null; switch (packetType) { case 1: packet = new QueueInteractionPacket(); packet.ReadPacketData(stream); return packet; case 2: packet = new QueueStatusUpdatePacket(); packet.ReadPacketData(stream); return packet; case 3: packet = new QueueFinishedPacket(); packet.ReadPacketData(stream); return packet; case 4: packet = new GameServerConnectPacket(); packet.ReadPacketData(stream); return packet; case 7: packet = new GameStatePacket(); return packet; case 8: packet = new InputPacket(); packet.ReadPacketData(stream); return packet; default: throw new Exception("Unrecognized Packet Type"); } }
private void SendStatePacket(bool guaranteed = false) { var pack = new GameStatePacket() { //Blackholes = gravityObjects.OfType<Blackhole>().ToList(), //Planets = gravityObjects.OfType<Spheroid>().ToList() }; var dat = new List<byte>(); pack.WritePacketData(dat); if (guaranteed) { PacketQueue.Instance.AddPacket(pack); } else { client3.Send(dat.ToArray(), dat.Count, new IPEndPoint(new IPAddress(ClientIP.Split('.').Select(byte.Parse).ToArray()), port3)); } }