public static void Handshake(RemoteClient client, MinecraftServer server, IPacket _packet) { var packet = (HandshakePacket)_packet; if (packet.ProtocolVersion < PacketReader.ProtocolVersion) { client.SendPacket(new DisconnectPacket("Outdated client!")); return; } if (packet.ProtocolVersion > PacketReader.ProtocolVersion) { client.SendPacket(new DisconnectPacket("Outdated server!")); return; } if (server.Clients.Any(c => c.Username == packet.Username)) { client.SendPacket(new DisconnectPacket("")); return; } client.Username = packet.Username; client.Hostname = packet.ServerHostname + ":" + packet.ServerPort; if (server.Settings.OnlineMode) client.AuthenticationHash = CreateHash(); else client.AuthenticationHash = "-"; if (server.Settings.EnableEncryption) client.SendPacket(CreateEncryptionRequest(client, server)); else server.LogInPlayer(client); }
public static void RightClick(RemoteClient client, MinecraftServer server, IPacket _packet) { var packet = (RightClickPacket)_packet; var slot = client.Entity.Inventory[client.Entity.SelectedSlot]; var position = new Coordinates3D(packet.X, packet.Y, packet.Z); var cursorPosition = new Coordinates3D(packet.CursorX, packet.CursorY, packet.CursorZ); BlockInfo?block = null; if (position != -Coordinates3D.One) { if (position.DistanceTo((Coordinates3D)client.Entity.Position) > client.Reach) { return; } block = client.World.GetBlockInfo(position); } bool use = true; if (block != null) { use = client.World.RightClickBlock(position, packet.Face, cursorPosition, slot.AsItem()); } if (!slot.Empty) { var item = slot.AsItem(); if (use) { if (block != null) { client.World.UseItemOnBlock(position, packet.Face, cursorPosition, item.Value); if (item.Value.ItemId < 0x100) { client.SendPacket(new SoundEffectPacket(Block.GetPlacementSoundEffect(item.Value.ItemId), position.X, position.Y, position.Z, SoundEffectPacket.DefaultVolume, SoundEffectPacket.DefaultPitch)); } if (client.GameMode != GameMode.Creative) { slot.Count--; // TODO: This is probably a bad place to put this code if (slot.Count == 0) { client.Entity.Inventory[client.Entity.SelectedSlot] = ItemStack.EmptyStack; } else { client.Entity.Inventory[client.Entity.SelectedSlot] = slot; } } } else { client.World.UseItemOnBlock(position, packet.Face, cursorPosition, item.Value); if (item.Value.ItemId < 0x100) { client.SendPacket(new SoundEffectPacket(Block.GetPlacementSoundEffect(item.Value.ItemId), position.X, position.Y, position.Z, SoundEffectPacket.DefaultVolume, SoundEffectPacket.DefaultPitch)); } } } } }
public static void Handshake(RemoteClient client, MinecraftServer server, IPacket _packet) { var packet = (HandshakePacket)_packet; if (packet.ProtocolVersion < NetworkManager.ProtocolVersion) { client.SendPacket(new DisconnectPacket("Outdated client!")); return; } if (packet.ProtocolVersion > NetworkManager.ProtocolVersion) { client.SendPacket(new DisconnectPacket("Outdated server!")); return; } client.Hostname = packet.ServerHostname + ":" + packet.ServerPort; }
public static void LoginStart(RemoteClient client, MinecraftServer server, IPacket _packet) { var packet = (LoginStartPacket)_packet; if (server.Clients.Any(c => c.IsLoggedIn && c.Username == packet.Username)) { client.Disconnect("You're already on this server!"); } else { client.Username = packet.Username; if (server.Settings.OnlineMode) { client.ServerId = CreateId(); } else { client.ServerId = CreateId(); client.UUID = Guid.NewGuid().ToJavaUUID(); } if (server.Settings.EnableEncryption) { client.SendPacket(CreateEncryptionRequest(client, server)); } else { server.LogInPlayer(client); } } }
public static void Handshake(RemoteClient client, Proxy proxy, IPacket _packet) { var packet = (HandshakePacket)_packet; if (packet.ProtocolVersion < PacketReader.ProtocolVersion) { client.SendPacket(new DisconnectPacket("Outdated client!")); return; } if (packet.ProtocolVersion > PacketReader.ProtocolVersion) { client.SendPacket(new DisconnectPacket("Outdated server!")); return; } client.AuthenticationHash = "-"; client.Username = packet.Username; client.SendPacket(CreateEncryptionRequest(client, proxy)); }
public static void ClientStatus(RemoteClient client, Proxy proxy, IPacket _packet) { var packet = (ClientStatusPacket)_packet; if (packet.Status == ClientStatusPacket.ClientStatus.InitialSpawn) { // Throw them into an empty world and inform them that we'll be connecting them shortly. client.SendPacket(new LoginRequestPacket(1, "FLAT", GameMode.Creative, Dimension.Overworld, Difficulty.Normal, 100)); client.SendPacket(new PlayerAbilitiesPacket(0, 0.05f, 0.1f)); client.SendPacket(new EntityPropertiesPacket(1, new[] { new EntityProperty("generic.movementSpeed", 0.05f) })); client.SendPacket(new PlayerPositionAndLookPacket(0, 1.72, 0, 0.1, 0, 0, false)); client.SendChat(ChatColors.Yellow + "Connecting to the classic server, please wait."); proxy.Connect(client); } else if (packet.Status == ClientStatusPacket.ClientStatus.Respawn) { // TODO } }
public static void ClientStatus(RemoteClient client, MinecraftServer server, IPacket _packet) { var packet = (ClientStatusPacket)_packet; if (packet.Change == ClientStatusPacket.StatusChange.Respawn) { var world = client.Entity.World; client.Entity.Position = new Vector3( client.Entity.SpawnPoint.X, // FIXME: This seems to drop the player camera from half the height of a login spawn client.Entity.SpawnPoint.Y, client.Entity.SpawnPoint.Z); client.Entity.Health = client.Entity.MaxHealth; client.Entity.Food = 20; client.Entity.FoodSaturation = 20; server.EntityManager.SpawnEntity(world, client.Entity); client.SendPacket(new UpdateHealthPacket(client.Entity.Health, client.Entity.Food, client.Entity.FoodSaturation)); client.SendPacket(new RespawnPacket(Dimension.Overworld, server.Settings.Difficulty, client.GameMode, world.WorldGenerator.GeneratorName)); client.SendPacket(new PlayerPositionAndLookPacket(client.Entity.Position.X, client.Entity.Position.Y, client.Entity.Position.Z, client.Entity.Position.Y + PlayerEntity.Height, client.Entity.Yaw, client.Entity.Pitch, true)); } }
public static void EncryptionKeyResponse(RemoteClient client, MinecraftServer server, IPacket _packet) { var packet = (EncryptionKeyResponsePacket)_packet; var decryptedToken = server.CryptoServiceProvider.Decrypt(packet.VerificationToken, false); for (int i = 0; i < decryptedToken.Length; i++) { if (decryptedToken[i] != client.VerificationToken[i]) { client.Disconnect("Unable to authenticate."); return; } } client.SharedKey = server.CryptoServiceProvider.Decrypt(packet.SharedSecret, false); client.SendPacket(new EncryptionKeyResponsePacket(new byte[0], new byte[0])); }
public static void SpawnPlayer(RemoteClient client, Proxy proxy, IPacket _packet) { var packet = (SpawnPlayerPacket)_packet; if (packet.PlayerID < 0) { client.Position = new Vector3(packet.X / 32.0, packet.Y / 32.0, packet.Z / 32.0); client.Yaw = packet.Yaw; client.Pitch = packet.Pitch; client.SendPacket(new Modern.PlayerPositionAndLookPacket( client.Position.X, client.Position.Y + 1.72, client.Position.Z, client.Position.Y + 0.1, 0, 0, false)); } else { var dictionary = new MetadataDictionary(); dictionary[0] = new MetadataByte(0); dictionary[1] = new MetadataShort(300); client.SendPacket(new Modern.SpawnPlayerPacket(packet.PlayerID, packet.Username, MathHelper.CreateAbsoluteInt(packet.X / 32.0), MathHelper.CreateAbsoluteInt(packet.Y / 32.0), MathHelper.CreateAbsoluteInt(packet.Z / 32.0), packet.Yaw, packet.Pitch, 0, dictionary)); } client.SendPacket(new Modern.PlayerListItemPacket(packet.Username, true, 0)); }
public static void PositionAndOrientation(RemoteClient client, Proxy proxy, IPacket _packet) { var packet = (PositionAndOrientationPacket)_packet; if (packet.PlayerID < 0) { client.Position = new Vector3(packet.X / 32, packet.Y / 32, packet.Z / 32); client.Yaw = packet.Yaw; client.Pitch = packet.Pitch; client.SendPacket(new Modern.PlayerPositionAndLookPacket( client.Position.X, client.Position.Y + 1.72, client.Position.Z, client.Position.Y + 0.1, 0, 0, false)); } else { } }
public static void EncryptionKeyResponse(RemoteClient client, Proxy proxy, IPacket _packet) { var packet = (EncryptionKeyResponsePacket)_packet; var decryptedToken = proxy.CryptoServiceProvider.Decrypt(packet.VerificationToken, false); for (int i = 0; i < decryptedToken.Length; i++) { if (decryptedToken[i] != client.VerificationToken[i]) { client.Disconnect("Unable to authenticate."); return; } } client.SharedKey = proxy.CryptoServiceProvider.Decrypt(packet.SharedSecret, false); client.SendPacket(new EncryptionKeyResponsePacket(new byte[0], new byte[0])); }
public void Login(string sessionToken, RegionType region, string version, string hash, Guid installationId) { _api.Logger.Debug($"Sending login packet"); var authPacket = new NoS0577Packet { ClientId = installationId, ClientVersion = version, Md5String = hash, RegionType = region, AuthToken = sessionToken, UnknownConstant = 0, UnknownYet = "003662BF" }; string packet = _serializer.Serialize(authPacket); _client.SendPacket(packet); }
public static void LoginStart(RemoteClient client, MinecraftServer server, IPacket _packet) { var packet = (LoginStartPacket)_packet; if (server.Clients.Any(c => c.IsLoggedIn && c.Username == packet.Username)) client.Disconnect("You're already on this server!"); else { client.Username = packet.Username; if (server.Settings.OnlineMode) client.ServerId = CreateId(); else { client.ServerId = CreateId(); client.UUID = Guid.NewGuid().ToJavaUUID(); } if (server.Settings.EnableEncryption) client.SendPacket(CreateEncryptionRequest(client, server)); else server.LogInPlayer(client); } }
public static void ClientStatus(RemoteClient client, MinecraftServer server, IPacket _packet) { var packet = (ClientStatusPacket)_packet; if (packet.Status == ClientStatusPacket.ClientStatus.InitialSpawn) { // Create a hash for session verification AsnKeyBuilder.AsnMessage encodedKey = AsnKeyBuilder.PublicKeyToX509(server.ServerKey); byte[] shaData = Encoding.UTF8.GetBytes(client.AuthenticationHash) .Concat(client.SharedKey) .Concat(encodedKey.GetBytes()).ToArray(); string hash = Cryptography.JavaHexDigest(shaData); // Talk to session.minecraft.net if (server.Settings.OnlineMode) { var webClient = new WebClient(); var webReader = new StreamReader(webClient.OpenRead( new Uri(string.Format(sessionCheckUri, client.Username, hash)))); string response = webReader.ReadToEnd(); webReader.Close(); if (response != "YES") { client.Disconnect("Failed to verify username!"); return; } } var eventArgs = new ConnectionEstablishedEventArgs(client); server.OnConnectionEstablished(eventArgs); if (eventArgs.PermitConnection) server.LogInPlayer(client); else client.Disconnect(eventArgs.DisconnectReason); } else if (packet.Status == ClientStatusPacket.ClientStatus.Respawn) { var world = client.Entity.World; client.Entity.Position = new Vector3( client.Entity.SpawnPoint.X, // FIXME: This seems to drop the player camera from half the height of a login spawn client.Entity.SpawnPoint.Y, client.Entity.SpawnPoint.Z); client.Entity.Health = client.Entity.MaxHealth; client.Entity.Food = 20; client.Entity.FoodSaturation = 20; server.EntityManager.SpawnEntity(world, client.Entity); client.SendPacket(new UpdateHealthPacket(client.Entity.Health, client.Entity.Food, client.Entity.FoodSaturation)); client.SendPacket(new RespawnPacket(Dimension.Overworld, server.Settings.Difficulty, client.GameMode, World.Height, world.WorldGenerator.GeneratorName)); client.SendPacket(new PlayerPositionAndLookPacket(client.Entity.Position.X, client.Entity.Position.Y, client.Entity.Position.Z, client.Entity.Position.Y + PlayerEntity.Height, client.Entity.Yaw, client.Entity.Pitch, true)); } }
public static void RightClick(RemoteClient client, MinecraftServer server, IPacket _packet) { var packet = (RightClickPacket)_packet; var slot = client.Entity.Inventory[client.Entity.SelectedSlot]; var position = new Coordinates3D(packet.X, packet.Y, packet.Z); var cursorPosition = new Coordinates3D(packet.CursorX, packet.CursorY, packet.CursorZ); BlockInfo? block = null; if (position != -Coordinates3D.One) { if (position.DistanceTo((Coordinates3D)client.Entity.Position) > client.Reach) return; block = client.World.GetBlockInfo(position); } bool use = true; if (block != null) use = client.World.RightClickBlock(position, packet.Face, cursorPosition, slot.AsItem()); if (!slot.Empty) { var item = slot.AsItem(); if (use) { if (block != null) { client.World.UseItemOnBlock(position, packet.Face, cursorPosition, item.Value); if (item.Value.ItemId < 0x100) { client.SendPacket(new SoundEffectPacket(Block.GetPlacementSoundEffect(item.Value.ItemId), position.X, position.Y, position.Z, SoundEffectPacket.DefaultVolume, SoundEffectPacket.DefaultPitch)); } if (client.GameMode != GameMode.Creative) { slot.Count--; // TODO: This is probably a bad place to put this code if (slot.Count == 0) client.Entity.Inventory[client.Entity.SelectedSlot] = ItemStack.EmptyStack; else client.Entity.Inventory[client.Entity.SelectedSlot] = slot; } } else { client.World.UseItemOnBlock(position, packet.Face, cursorPosition, item.Value); if (item.Value.ItemId < 0x100) { client.SendPacket(new SoundEffectPacket(Block.GetPlacementSoundEffect(item.Value.ItemId), position.X, position.Y, position.Z, SoundEffectPacket.DefaultVolume, SoundEffectPacket.DefaultPitch)); } } } } }
public static void ServerListPing(RemoteClient client, Proxy proxy, IPacket _packet) { client.SendPacket(new DisconnectPacket(GetPingValue(proxy))); }
public static void StatusRequest(RemoteClient client, MinecraftServer server, IPacket _packet) { client.SendPacket(new StatusResponsePacket(GetServerStatus(server))); }
public static void StatusPing(RemoteClient client, MinecraftServer server, IPacket _packet) { client.SendPacket(_packet); }
public static void ServerListPing(RemoteClient client, MinecraftServer server, IPacket _packet) { client.SendPacket(new DisconnectPacket(GetPingValue(server))); }