public override void AddSpectator(SkyPlayer player) { player.IsGameSpectator = true; //Set an invisibily effect on top of the scale to completely 'remove' the player player.SetEffect(new Invisibility { Duration = int.MaxValue, Particles = false }); player.SetNameTagVisibility(false); McpeSetEntityData mcpeSetEntityData = McpeSetEntityData.CreateObject(); mcpeSetEntityData.runtimeEntityId = player.EntityId; mcpeSetEntityData.metadata = player.GetMetadata(); mcpeSetEntityData.metadata[(int)Entity.MetadataFlags.Scale] = new MetadataFloat(0.5f); // Scale //Avoid changing the local player's scale foreach (SkyPlayer gamePlayer in GetAllPlayers()) { if (gamePlayer == player) { continue; } gamePlayer.SendPackage(mcpeSetEntityData); } //Update slot held for other players player.Inventory.SetHeldItemSlot(player.Inventory.InHandSlot, false); }
public virtual void SpawnEntity() { Level.AddEntity(this); var addEntity = McpeAddEntity.CreateObject(); addEntity.entityType = EntityTypeId; addEntity.entityId = EntityId; addEntity.x = KnownPosition.X; addEntity.y = KnownPosition.Y; addEntity.z = KnownPosition.Z; addEntity.yaw = KnownPosition.Yaw; addEntity.pitch = KnownPosition.Pitch; addEntity.metadata = GetMetadata(); addEntity.speedX = (float)Velocity.X; addEntity.speedY = (float)Velocity.Y; addEntity.speedZ = (float)Velocity.Z; Level.RelayBroadcast(addEntity); IsSpawned = true; McpeSetEntityData mcpeSetEntityData = McpeSetEntityData.CreateObject(); mcpeSetEntityData.entityId = EntityId; mcpeSetEntityData.metadata = GetMetadata(); Level.RelayBroadcast(mcpeSetEntityData); }
public override void OnTick(Entity[] entities) { Fuse--; if (Fuse == 0) { DespawnEntity(); Explode(); } else { PositionCheck(); if (KnownPosition.Y > -1 && _checkPosition) { Velocity -= new Vector3(0, (float)Gravity, 0); Velocity *= (float)(1.0f - Drag); } var entityData = McpeSetEntityData.CreateObject(); entityData.runtimeEntityId = EntityId; entityData.metadata = GetMetadata(); Level.RelayBroadcast(entityData); } }
public virtual void BroadcastSetEntityData() { McpeSetEntityData mcpeSetEntityData = McpeSetEntityData.CreateObject(); mcpeSetEntityData.entityId = EntityId; mcpeSetEntityData.metadata = GetMetadata(); Level.RelayBroadcast(this, mcpeSetEntityData); }
public virtual void BroadcastSetEntityData(MetadataDictionary metadata) { McpeSetEntityData mcpeSetEntityData = McpeSetEntityData.CreateObject(); mcpeSetEntityData.runtimeEntityId = EntityId; mcpeSetEntityData.metadata = metadata; Level?.RelayBroadcast(mcpeSetEntityData); }
private Packet CreatePe(byte messageId, ReadOnlyMemory <byte> buffer) { Packet packet = null; try { switch (messageId) { case 111: //Fixes entity delta packet = new EntityDelta(); break; //The following are only here so we can join. case 49: packet = new InventoryContent(); break; case 31: packet = new MobEquipment(); break; case 122: packet = new BiomeDefinitionList(); break; case 119: packet = new AvailableEntityIdentifiers(); break; case 32: packet = new MobArmorEquipment(); break; case 50: packet = new InventorySlot(); break; case 7: packet = new McpeResourcePackStack(); break; case 39: packet = new McpeSetEntityData(); break; } packet?.Decode(buffer); } catch (Exception ex) { if (messageId != 39) { // Log.Error(ex, $"Processing error: {ex.ToString()}"); } } return(packet); }
public void SendName(Player player, string Name) { MetadataDictionary metadata = GetMetadata(); metadata[(int)MetadataFlags.NameTag] = Name; McpeSetEntityData mcpeSetEntityData = McpeSetEntityData.CreateObject(); mcpeSetEntityData.runtimeEntityId = EntityId; mcpeSetEntityData.metadata = metadata; player.SendPackage(mcpeSetEntityData); }
public void SendName(Level level, string Name) { MetadataDictionary metadata = GetMetadata(); metadata[(int)MetadataFlags.NameTag] = Name; McpeSetEntityData mcpeSetEntityData = McpeSetEntityData.CreateObject(); mcpeSetEntityData.runtimeEntityId = EntityId; mcpeSetEntityData.metadata = metadata; //player.SendPackage(mcpeSetEntityData); level.RelayBroadcast(mcpeSetEntityData); }
private static void OnMcpeSetEntityData(Package message) { McpeSetEntityData msg = (McpeSetEntityData)message; Log.DebugFormat("Entity ID: {0}", msg.entityId); MetadataDictionary metadata = msg.metadata; if (metadata.Contains(17)) { Log.DebugFormat("Metadata: {0}", metadata.ToString()); } }
public override void OnTick() { Fuse--; if (Fuse == 0) { DespawnEntity(); Explode(); } else { var entityData = McpeSetEntityData.CreateObject(); entityData.entityId = EntityId; entityData.metadata = GetMetadata(); Level.RelayBroadcast(entityData); if (CheckPosition) { PositionCheck(); } } }
public virtual void SpawnToPlayer(Player player) { var addEntity = McpeAddEntity.CreateObject(); addEntity.entityType = EntityTypeId; addEntity.entityId = EntityId; addEntity.x = KnownPosition.X; addEntity.y = KnownPosition.Y; addEntity.z = KnownPosition.Z; addEntity.yaw = KnownPosition.Yaw; addEntity.pitch = KnownPosition.Pitch; addEntity.metadata = GetMetadata(); addEntity.speedX = (float)Velocity.X; addEntity.speedY = (float)Velocity.Y; addEntity.speedZ = (float)Velocity.Z; player.SendPackage(addEntity); McpeSetEntityData mcpeSetEntityData = McpeSetEntityData.CreateObject(); mcpeSetEntityData.entityId = EntityId; mcpeSetEntityData.metadata = GetMetadata(); player.SendPackage(mcpeSetEntityData); }
/// <summary> /// Handles the specified package. /// </summary> /// <param name="message">The package.</param> /// <param name="senderEndpoint">The sender's endpoint.</param> private void HandlePackage(Package message, IPEndPoint senderEndpoint) { if (typeof(McpeBatch) == message.GetType()) { McpeBatch batch = (McpeBatch)message; var messages = new List <Package>(); // Get bytes byte[] payload = batch.payload; // Decompress bytes MemoryStream stream = new MemoryStream(payload); if (stream.ReadByte() != 0x78) { throw new InvalidDataException("Incorrect ZLib header. Expected 0x78 0x9C"); } stream.ReadByte(); using (var defStream2 = new DeflateStream(stream, CompressionMode.Decompress, false)) { // Get actual package out of bytes MemoryStream destination = new MemoryStream(); defStream2.CopyTo(destination); byte[] internalBuffer = destination.ToArray(); messages.Add(PackageFactory.CreatePackage(internalBuffer[0], internalBuffer) ?? new UnknownPackage(internalBuffer[0], internalBuffer)); } foreach (var msg in messages) { HandlePackage(msg, senderEndpoint); } return; } TraceReceive(message); if (typeof(UnknownPackage) == message.GetType()) { return; } if (typeof(McpeDisconnect) == message.GetType()) { McpeDisconnect msg = (McpeDisconnect)message; Log.Debug(msg.message); StopServer(); return; } if (typeof(ConnectedPing) == message.GetType()) { ConnectedPing msg = (ConnectedPing)message; SendConnectedPong(msg.sendpingtime); return; } if (typeof(McpeFullChunkData) == message.GetType()) { McpeFullChunkData msg = (McpeFullChunkData)message; ChunkColumn chunk = ClientUtils.DecocedChunkColumn(msg.chunkData); if (chunk != null) { Log.DebugFormat("Chunk X={0}", chunk.x); Log.DebugFormat("Chunk Z={0}", chunk.z); ClientUtils.SaveChunkToAnvil(chunk); } return; } if (typeof(ConnectionRequestAccepted) == message.GetType()) { Thread.Sleep(50); SendNewIncomingConnection(); var t1 = new Timer(state => SendConnectedPing(), null, 2000, 5000); Thread.Sleep(50); SendLogin("Client12"); return; } if (typeof(McpeSetSpawnPosition) == message.GetType()) { McpeSetSpawnPosition msg = (McpeSetSpawnPosition)message; _spawn = new Vector3(msg.x, msg.y, msg.z); _level.SpawnX = (int)_spawn.X; _level.SpawnY = (int)_spawn.Y; _level.SpawnZ = (int)_spawn.Z; return; } if (typeof(McpeStartGame) == message.GetType()) { McpeStartGame msg = (McpeStartGame)message; _entityId = msg.entityId; _spawn = new Vector3(msg.x, msg.y, msg.z); _level.LevelName = "Default"; _level.Version = 19133; _level.GameType = msg.gamemode; ClientUtils.SaveLevel(_level); return; } if (typeof(McpeTileEvent) == message.GetType()) { McpeTileEvent msg = (McpeTileEvent)message; Log.DebugFormat("X: {0}", msg.x); Log.DebugFormat("Y: {0}", msg.y); Log.DebugFormat("Z: {0}", msg.z); Log.DebugFormat("Case 1: {0}", msg.case1); Log.DebugFormat("Case 2: {0}", msg.case2); return; } if (typeof(McpeAddEntity) == message.GetType()) { McpeAddEntity msg = (McpeAddEntity)message; Log.DebugFormat("Entity ID: {0}", msg.entityId); Log.DebugFormat("Entity Type: {0}", msg.entityType); Log.DebugFormat("X: {0}", msg.x); Log.DebugFormat("Y: {0}", msg.y); Log.DebugFormat("Z: {0}", msg.z); Log.DebugFormat("Yaw: {0}", msg.yaw); Log.DebugFormat("Pitch: {0}", msg.pitch); Log.DebugFormat("Velocity X: {0}", msg.speedX); Log.DebugFormat("Velocity Y: {0}", msg.speedY); Log.DebugFormat("Velocity Z: {0}", msg.speedZ); Log.DebugFormat("Metadata: {0}", msg.metadata.ToString()); Log.DebugFormat("Links count: {0}", msg.links); return; } if (typeof(McpeSetEntityData) == message.GetType()) { McpeSetEntityData msg = (McpeSetEntityData)message; Log.DebugFormat("Entity ID: {0}", msg.entityId); MetadataDictionary metadata = msg.metadata; Log.DebugFormat("Metadata: {0}", metadata.ToString()); return; } if (typeof(McpeMovePlayer) == message.GetType()) { McpeMovePlayer msg = (McpeMovePlayer)message; Log.DebugFormat("Entity ID: {0}", msg.entityId); _currentLocation = new PlayerLocation(msg.x, msg.y + 10, msg.z); SendMcpeMovePlayer(); return; } if (typeof(McpeUpdateBlock) == message.GetType()) { McpeUpdateBlock msg = (McpeUpdateBlock)message; Log.DebugFormat("No of Blocks: {0}", msg.blocks.Count); return; } if (typeof(McpeLevelEvent) == message.GetType()) { McpeLevelEvent msg = (McpeLevelEvent)message; Log.DebugFormat("Event ID: {0}", msg.eventId); Log.DebugFormat("X: {0}", msg.x); Log.DebugFormat("Y: {0}", msg.y); Log.DebugFormat("Z: {0}", msg.z); Log.DebugFormat("Data: {0}", msg.data); return; } }
public override void HandleMcpeSetEntityData(McpeSetEntityData message) { }
public override void SpawnEntity() { lock (_spawnSync) { if (IsSpawned) { throw new Exception("Invalid state. Tried to spawn projectile more than one time."); } Level.AddEntity(this); IsSpawned = true; if (Shooter == null) { var addEntity = McpeAddEntity.CreateObject(); addEntity.entityType = EntityTypeId; addEntity.entityId = EntityId; addEntity.x = KnownPosition.X; addEntity.y = KnownPosition.Y; addEntity.z = KnownPosition.Z; addEntity.yaw = KnownPosition.Yaw; addEntity.pitch = KnownPosition.Pitch; addEntity.metadata = GetMetadata(); addEntity.speedX = (float)Velocity.X; addEntity.speedY = (float)Velocity.Y; addEntity.speedZ = (float)Velocity.Z; Level.RelayBroadcast(addEntity); McpeSetEntityData mcpeSetEntityData = McpeSetEntityData.CreateObject(); mcpeSetEntityData.entityId = EntityId; mcpeSetEntityData.metadata = GetMetadata(); Level.RelayBroadcast(mcpeSetEntityData); } else { { var addEntity = McpeAddEntity.CreateObject(); addEntity.entityType = EntityTypeId; addEntity.entityId = EntityId; addEntity.x = KnownPosition.X; addEntity.y = KnownPosition.Y; addEntity.z = KnownPosition.Z; addEntity.yaw = KnownPosition.Yaw; addEntity.pitch = KnownPosition.Pitch; addEntity.metadata = GetMetadata(); addEntity.speedX = (float)Velocity.X; addEntity.speedY = (float)Velocity.Y; addEntity.speedZ = (float)Velocity.Z; Level.RelayBroadcast(Shooter, addEntity); McpeSetEntityData mcpeSetEntityData = McpeSetEntityData.CreateObject(); mcpeSetEntityData.entityId = EntityId; mcpeSetEntityData.metadata = GetMetadata(); Level.RelayBroadcast(Shooter, mcpeSetEntityData); } { MetadataDictionary metadata = GetMetadata(); metadata[17] = new MetadataLong(0); var addEntity = McpeAddEntity.CreateObject(); addEntity.entityType = EntityTypeId; addEntity.entityId = EntityId; addEntity.x = KnownPosition.X; addEntity.y = KnownPosition.Y; addEntity.z = KnownPosition.Z; addEntity.yaw = KnownPosition.Yaw; addEntity.pitch = KnownPosition.Pitch; addEntity.metadata = metadata; addEntity.speedX = (float)Velocity.X; addEntity.speedY = (float)Velocity.Y; addEntity.speedZ = (float)Velocity.Z; Shooter.SendPackage(addEntity); McpeSetEntityData mcpeSetEntityData = McpeSetEntityData.CreateObject(); mcpeSetEntityData.entityId = EntityId; mcpeSetEntityData.metadata = metadata; Shooter.SendPackage(mcpeSetEntityData); } } } }
public override void SpawnToPlayers(Player[] players) { { var fake = new Player(null, null) { ClientUuid = ClientUuid, EntityId = EntityId, NameTag = NameTag, DisplayName = NameTag, Username = NameTag, Skin = Skin, PlayerInfo = new PlayerInfo { DeviceOS = 7, PlatformChatId = NameTag, } }; var playerList = McpePlayerList.CreateObject(); playerList.records = new PlayerAddRecords { fake }; Level.RelayBroadcast(players, Level.CreateMcpeBatch(playerList.Encode())); playerList.records = null; playerList.PutPool(); } { var message = McpeAddPlayer.CreateObject(); message.uuid = ClientUuid; message.username = NameTag; message.entityIdSelf = EntityId; message.runtimeEntityId = EntityId; message.x = KnownPosition.X; message.y = KnownPosition.Y; message.z = KnownPosition.Z; message.yaw = KnownPosition.Yaw; message.headYaw = KnownPosition.HeadYaw; message.pitch = KnownPosition.Pitch; message.metadata = GetMetadata(); message.userId = -1; Level.RelayBroadcast(players, message); } { var message = McpeMobEquipment.CreateObject(); message.runtimeEntityId = EntityId; message.item = ItemInHand; message.slot = 0; Level.RelayBroadcast(players, message); } { var armorEquipment = McpeMobArmorEquipment.CreateObject(); armorEquipment.runtimeEntityId = EntityId; armorEquipment.helmet = Helmet; armorEquipment.chestplate = Chest; armorEquipment.leggings = Leggings; armorEquipment.boots = Boots; Level.RelayBroadcast(players, armorEquipment); } { var fake = new Player(null, null) { ClientUuid = ClientUuid, EntityId = EntityId, NameTag = NameTag, Skin = Skin }; var playerList = McpePlayerList.CreateObject(); playerList.records = new PlayerRemoveRecords { fake }; Level.RelayBroadcast(players, Level.CreateMcpeBatch(playerList.Encode())); playerList.records = null; playerList.PutPool(); } { var setEntityData = McpeSetEntityData.CreateObject(); setEntityData.runtimeEntityId = EntityId; setEntityData.metadata = GetMetadata(); Level?.RelayBroadcast(players, setEntityData); } }
public virtual void HandleMcpeSetEntityData(McpeSetEntityData message) { }
public override void SpawnToPlayers(Player[] players) { { Player fake = new Player(null, null) { ClientUuid = Uuid, EntityId = EntityId, NameTag = NameTag, Skin = Skin }; McpePlayerList playerList = McpePlayerList.CreateObject(); playerList.records = new PlayerAddRecords { fake }; Level.RelayBroadcast(players, Level.CreateMcpeBatch(playerList.Encode())); playerList.records = null; playerList.PutPool(); } { McpeAddPlayer message = McpeAddPlayer.CreateObject(); message.uuid = Uuid; message.username = NameTag; message.entityIdSelf = EntityId; message.runtimeEntityId = EntityId; message.x = KnownPosition.X; message.y = KnownPosition.Y; message.z = KnownPosition.Z; message.yaw = KnownPosition.Yaw; message.headYaw = KnownPosition.HeadYaw; message.pitch = KnownPosition.Pitch; message.metadata = GetMetadata(); Level.RelayBroadcast(players, message); } { McpeMobEquipment message = McpeMobEquipment.CreateObject(); message.runtimeEntityId = EntityId; message.item = ItemInHand; message.slot = 0; Level.RelayBroadcast(players, message); } { McpeMobArmorEquipment armorEquipment = McpeMobArmorEquipment.CreateObject(); armorEquipment.runtimeEntityId = EntityId; armorEquipment.helmet = ItemFactory.GetItem(Helmet); armorEquipment.chestplate = ItemFactory.GetItem(Chest); armorEquipment.leggings = ItemFactory.GetItem(Leggings); armorEquipment.boots = ItemFactory.GetItem(Boots); Level.RelayBroadcast(players, armorEquipment); } //{ // Player fake = new Player(null, null) // { // ClientUuid = Uuid, // EntityId = EntityId, // NameTag = NameTag, // Skin = Skin // }; // McpePlayerList playerList = McpePlayerList.CreateObject(); // playerList.records = new PlayerRemoveRecords {fake}; // Level.RelayBroadcast(players, Level.CreateMcpeBatch(playerList.Encode())); // playerList.records = null; // playerList.PutPool(); //} { McpeSetEntityData setEntityData = McpeSetEntityData.CreateObject(); setEntityData.runtimeEntityId = EntityId; setEntityData.metadata = GetMetadata(); Level?.RelayBroadcast(players, setEntityData); } }
public override void HandleMcpeSetEntityData(McpeSetEntityData message) { UnhandledPackage(message); }
public override void SpawnEntity() { Level.AddEntity(this); if (Shooter == null) { var addEntity = McpeAddEntity.CreateObject(); addEntity.entityType = EntityTypeId; addEntity.entityId = EntityId; addEntity.x = KnownPosition.X; addEntity.y = KnownPosition.Y; addEntity.z = KnownPosition.Z; addEntity.yaw = KnownPosition.Yaw; addEntity.pitch = KnownPosition.Pitch; //addEntity.metadata = GetMetadata(); addEntity.speedX = (float)Velocity.X; addEntity.speedY = (float)Velocity.Y; addEntity.speedZ = (float)Velocity.Z; Level.RelayBroadcast(addEntity); IsSpawned = true; McpeSetEntityData mcpeSetEntityData = McpeSetEntityData.CreateObject(); mcpeSetEntityData.entityId = EntityId; mcpeSetEntityData.metadata = GetMetadata(); Level.RelayBroadcast(mcpeSetEntityData); } else { { var addEntity = McpeAddEntity.CreateObject(); addEntity.entityType = EntityTypeId; addEntity.entityId = EntityId; addEntity.x = KnownPosition.X; addEntity.y = KnownPosition.Y; addEntity.z = KnownPosition.Z; addEntity.yaw = KnownPosition.Yaw; addEntity.pitch = KnownPosition.Pitch; //addEntity.metadata = GetMetadata(); addEntity.speedX = (float)Velocity.X; addEntity.speedY = (float)Velocity.Y; addEntity.speedZ = (float)Velocity.Z; Level.RelayBroadcast(Shooter, addEntity); McpeSetEntityData mcpeSetEntityData = McpeSetEntityData.CreateObject(); mcpeSetEntityData.entityId = EntityId; mcpeSetEntityData.metadata = GetMetadata(); Level.RelayBroadcast(Shooter, mcpeSetEntityData); } { MetadataDictionary metadata = GetMetadata(); metadata[17] = new MetadataLong(0); var addEntity = McpeAddEntity.CreateObject(); addEntity.entityType = EntityTypeId; addEntity.entityId = EntityId; addEntity.x = KnownPosition.X; addEntity.y = KnownPosition.Y; addEntity.z = KnownPosition.Z; addEntity.yaw = KnownPosition.Yaw; addEntity.pitch = KnownPosition.Pitch; //addEntity.metadata = metadata; addEntity.speedX = (float)Velocity.X; addEntity.speedY = (float)Velocity.Y; addEntity.speedZ = (float)Velocity.Z; Shooter.SendPackage(addEntity); McpeSetEntityData mcpeSetEntityData = McpeSetEntityData.CreateObject(); mcpeSetEntityData.entityId = EntityId; mcpeSetEntityData.metadata = metadata; Shooter.SendPackage(mcpeSetEntityData); } } }
private static void OnMcpeSetEntityData(Package message) { McpeSetEntityData msg = (McpeSetEntityData)message; Log.DebugFormat("McpeSetEntityData Entity ID: {0}, Metadata: {1}", msg.entityId, msg.metadata); }
public abstract void HandleMcpeSetEntityData(McpeSetEntityData message);
public override void HandleMcpeSetEntityData(McpeSetEntityData message) { Log.DebugFormat("McpeSetEntityData Entity ID: {0}, Metadata: {1}", message.runtimeEntityId, Client.MetadataToCode(message.metadata)); }
/// <summary> /// Handles the specified package. /// </summary> /// <param name="message">The package.</param> /// <param name="senderEndpoint">The sender's endpoint.</param> private void HandlePackage(Package message, IPEndPoint senderEndpoint) { if (typeof(McpeBatch) == message.GetType()) { Log.Debug("Processing Batch package"); McpeBatch batch = (McpeBatch)message; var messages = new List <Package>(); // Get bytes byte[] payload = batch.payload; // Decompress bytes MemoryStream stream = new MemoryStream(payload); if (stream.ReadByte() != 0x78) { throw new InvalidDataException("Incorrect ZLib header. Expected 0x78"); } stream.ReadByte(); using (var defStream2 = new DeflateStream(stream, CompressionMode.Decompress, false)) { // Get actual package out of bytes MemoryStream destination = new MemoryStream(); defStream2.CopyTo(destination); destination.Position = 0; NbtBinaryReader reader = new NbtBinaryReader(destination, true); do { int len = reader.ReadInt32(); byte[] internalBuffer = reader.ReadBytes(len); messages.Add(PackageFactory.CreatePackage(internalBuffer[0], internalBuffer) ?? new UnknownPackage(internalBuffer[0], internalBuffer)); } while (destination.Position < destination.Length); // throw new Exception("Have more data"); } foreach (var msg in messages) { HandlePackage(msg, senderEndpoint); msg.PutPool(); } return; } TraceReceive(message); if (typeof(UnknownPackage) == message.GetType()) { return; } if (typeof(McpeDisconnect) == message.GetType()) { McpeDisconnect msg = (McpeDisconnect)message; Log.InfoFormat("Disconnect {1}: {0}", msg.message, Username); SendDisconnectionNotification(); StopClient(); return; } if (typeof(ConnectedPing) == message.GetType()) { ConnectedPing msg = (ConnectedPing)message; SendConnectedPong(msg.sendpingtime); return; } if (typeof(McpeFullChunkData) == message.GetType()) { //McpeFullChunkData msg = (McpeFullChunkData) message; //ChunkColumn chunk = ClientUtils.DecocedChunkColumn(msg.chunkData); //if (chunk != null) //{ // Log.DebugFormat("Chunk X={0}", chunk.x); // Log.DebugFormat("Chunk Z={0}", chunk.z); // //ClientUtils.SaveChunkToAnvil(chunk); //} return; } if (typeof(ConnectionRequestAccepted) == message.GetType()) { Thread.Sleep(50); SendNewIncomingConnection(); //_connectedPingTimer = new Timer(state => SendConnectedPing(), null, 1000, 1000); Thread.Sleep(50); SendLogin(Username); return; } if (typeof(McpeSetSpawnPosition) == message.GetType()) { McpeSetSpawnPosition msg = (McpeSetSpawnPosition)message; _spawn = new Vector3(msg.x, msg.y, msg.z); _level.SpawnX = (int)_spawn.X; _level.SpawnY = (int)_spawn.Y; _level.SpawnZ = (int)_spawn.Z; return; } if (typeof(McpeStartGame) == message.GetType()) { McpeStartGame msg = (McpeStartGame)message; _entityId = msg.entityId; _spawn = new Vector3(msg.x, msg.y, msg.z); _level.LevelName = "Default"; _level.Version = 19133; _level.GameType = msg.gamemode; //ClientUtils.SaveLevel(_level); return; } if (typeof(McpeTileEvent) == message.GetType()) { McpeTileEvent msg = (McpeTileEvent)message; Log.DebugFormat("X: {0}", msg.x); Log.DebugFormat("Y: {0}", msg.y); Log.DebugFormat("Z: {0}", msg.z); Log.DebugFormat("Case 1: {0}", msg.case1); Log.DebugFormat("Case 2: {0}", msg.case2); return; } if (typeof(McpeAddEntity) == message.GetType()) { McpeAddEntity msg = (McpeAddEntity)message; Log.DebugFormat("Entity ID: {0}", msg.entityId); Log.DebugFormat("Entity Type: {0}", msg.entityType); Log.DebugFormat("X: {0}", msg.x); Log.DebugFormat("Y: {0}", msg.y); Log.DebugFormat("Z: {0}", msg.z); Log.DebugFormat("Yaw: {0}", msg.yaw); Log.DebugFormat("Pitch: {0}", msg.pitch); Log.DebugFormat("Velocity X: {0}", msg.speedX); Log.DebugFormat("Velocity Y: {0}", msg.speedY); Log.DebugFormat("Velocity Z: {0}", msg.speedZ); //Log.DebugFormat("Metadata: {0}", msg.metadata.ToString()); //Log.DebugFormat("Links count: {0}", msg.links); return; } if (typeof(McpeSetEntityData) == message.GetType()) { McpeSetEntityData msg = (McpeSetEntityData)message; Log.DebugFormat("Entity ID: {0}", msg.entityId); MetadataDictionary metadata = msg.metadata; Log.DebugFormat("Metadata: {0}", metadata.ToString()); return; } if (typeof(McpeMovePlayer) == message.GetType()) { //McpeMovePlayer msg = (McpeMovePlayer) message; //Log.DebugFormat("Entity ID: {0}", msg.entityId); //CurrentLocation = new PlayerLocation(msg.x, msg.y + 10, msg.z); //SendMcpeMovePlayer(); return; } if (typeof(McpeUpdateBlock) == message.GetType()) { McpeUpdateBlock msg = (McpeUpdateBlock)message; Log.DebugFormat("No of Blocks: {0}", msg.blocks.Count); return; } if (typeof(McpeLevelEvent) == message.GetType()) { McpeLevelEvent msg = (McpeLevelEvent)message; Log.DebugFormat("Event ID: {0}", msg.eventId); Log.DebugFormat("X: {0}", msg.x); Log.DebugFormat("Y: {0}", msg.y); Log.DebugFormat("Z: {0}", msg.z); Log.DebugFormat("Data: {0}", msg.data); return; } if (typeof(McpeContainerSetContent) == message.GetType()) { McpeContainerSetContent msg = (McpeContainerSetContent)message; Log.DebugFormat("Window ID: 0x{0:x2}, Count: {1}", msg.windowId, msg.slotData.Count); var slots = msg.slotData.GetValues(); foreach (var entry in slots) { MetadataSlot slot = (MetadataSlot)entry; //Log.DebugFormat(" - Id: {0}, Metadata: {1}, Count: {2}", slot.Value.Item.Id, slot.Value.Item.Metadata, slot.Value.Count); } return; } if (typeof(McpeCraftingData) == message.GetType()) { string fileName = Path.GetTempPath() + "Recipes_" + Guid.NewGuid() + ".txt"; Log.Info("Writing recipes to filename: " + fileName); FileStream file = File.OpenWrite(fileName); McpeCraftingData msg = (McpeCraftingData)message; IndentedTextWriter writer = new IndentedTextWriter(new StreamWriter(file)); writer.WriteLine("static RecipeManager()"); writer.WriteLine("{"); writer.Indent++; writer.WriteLine("Recipes = new Recipes"); writer.WriteLine("{"); writer.Indent++; foreach (Recipe recipe in msg.recipes) { ShapelessRecipe shapelessRecipe = recipe as ShapelessRecipe; if (shapelessRecipe != null) { writer.WriteLine(string.Format("new ShapelessRecipe(new ItemStack(ItemFactory.GetItem({0}, {1}), {2}),", shapelessRecipe.Result.Id, shapelessRecipe.Result.Metadata, shapelessRecipe.Result.Count)); writer.Indent++; writer.WriteLine("new List<ItemStack>"); writer.WriteLine("{"); writer.Indent++; foreach (var itemStack in shapelessRecipe.Input) { writer.WriteLine(string.Format("new ItemStack(ItemFactory.GetItem({0}, {1}), {2}),", itemStack.Id, itemStack.Metadata, itemStack.Count)); } writer.Indent--; writer.WriteLine("}),"); writer.Indent--; continue; } ShapedRecipe shapedRecipe = recipe as ShapedRecipe; if (shapedRecipe != null) { writer.WriteLine(string.Format("new ShapedRecipe({0}, {1}, new ItemStack(ItemFactory.GetItem({2}, {3}), {4}),", shapedRecipe.Width, shapedRecipe.Height, shapedRecipe.Result.Id, shapedRecipe.Result.Metadata, shapedRecipe.Result.Count)); writer.Indent++; writer.WriteLine("new Item[]"); writer.WriteLine("{"); writer.Indent++; foreach (Item item in shapedRecipe.Input) { writer.WriteLine(string.Format("ItemFactory.GetItem({0}, {1}),", item.Id, item.Metadata)); } writer.Indent--; writer.WriteLine("}),"); writer.Indent--; continue; } } writer.WriteLine("};"); writer.Indent--; writer.WriteLine("}"); writer.Indent--; writer.Flush(); file.Close(); Environment.Exit(0); return; } }