mirror of
https://github.com/ViaVersion/ViaLegacy.git
synced 2024-12-21 16:28:34 +01:00
Improved classic hack management
This commit is contained in:
parent
55d6ba4dd1
commit
3845d04197
1
.gitignore
vendored
1
.gitignore
vendored
@ -14,3 +14,4 @@ hs_err_pid*
|
||||
/.gradle/
|
||||
/build/
|
||||
/out/
|
||||
/run/
|
||||
|
@ -129,6 +129,7 @@ public class Protocola1_0_15toc0_30 extends AbstractProtocol<ClientboundPacketsc
|
||||
gameEvent.write(Type.BYTE, (byte) 1); // value (creative)
|
||||
gameEvent.send(Protocolb1_8_0_1tob1_7_0_3.class);
|
||||
}
|
||||
wrapper.user().get(ClassicOpLevelStorage.class).updateAbilities();
|
||||
|
||||
wrapper.user().put(new ClassicLevelStorage(wrapper.user()));
|
||||
|
||||
@ -355,8 +356,9 @@ public class Protocola1_0_15toc0_30 extends AbstractProtocol<ClientboundPacketsc
|
||||
public void register() {
|
||||
handler(wrapper -> {
|
||||
wrapper.cancel();
|
||||
final ClassicOpLevelStorage opLevelStorage = wrapper.user().get(ClassicOpLevelStorage.class);
|
||||
final byte opLevel = wrapper.read(Type.BYTE); // op level
|
||||
wrapper.user().get(ClassicOpLevelStorage.class).setOpLevel(opLevel);
|
||||
opLevelStorage.setOpLevel(opLevel);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
@ -19,21 +19,82 @@ package net.raphimc.vialegacy.protocols.classic.protocola1_0_15toc0_28_30.storag
|
||||
|
||||
import com.viaversion.viaversion.api.connection.StoredObject;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import net.raphimc.vialegacy.protocols.alpha.protocola1_0_16_2toa1_0_15.ClientboundPacketsa1_0_15;
|
||||
import net.raphimc.vialegacy.protocols.beta.protocolb1_8_0_1tob1_7_0_3.types.Typesb1_7_0_3;
|
||||
import net.raphimc.vialegacy.protocols.classic.protocola1_0_15toc0_28_30.Protocola1_0_15toc0_30;
|
||||
import net.raphimc.vialegacy.protocols.release.protocol1_2_4_5to1_2_1_3.Protocol1_2_4_5to1_2_1_3;
|
||||
import net.raphimc.vialegacy.protocols.release.protocol1_3_1_2to1_2_4_5.ClientboundPackets1_2_4;
|
||||
|
||||
public class ClassicOpLevelStorage extends StoredObject {
|
||||
|
||||
private byte opLevel;
|
||||
|
||||
private boolean flying = true;
|
||||
private boolean noClip = true;
|
||||
private boolean speed = true;
|
||||
private boolean respawn = true;
|
||||
|
||||
public ClassicOpLevelStorage(final UserConnection user) {
|
||||
super(user);
|
||||
}
|
||||
|
||||
public void setOpLevel(final byte opLevel) {
|
||||
public void updateHax(final boolean flying, final boolean noClip, final boolean speed, final boolean respawn) throws Exception {
|
||||
boolean changed = this.flying != flying;
|
||||
changed |= this.noClip != noClip;
|
||||
changed |= this.speed != speed;
|
||||
changed |= this.respawn != respawn;
|
||||
|
||||
if (this.flying != flying) {
|
||||
this.flying = flying;
|
||||
this.updateAbilities();
|
||||
}
|
||||
|
||||
this.noClip = noClip;
|
||||
this.speed = speed;
|
||||
this.respawn = respawn;
|
||||
|
||||
if (changed) {
|
||||
String statusMessage = "§6Hack control: ";
|
||||
statusMessage += this.flying ? "§aFlying" : "§cFlying";
|
||||
statusMessage += " ";
|
||||
statusMessage += this.noClip ? "§aNoClip" : "§cNoClip";
|
||||
statusMessage += " ";
|
||||
statusMessage += this.speed ? "§aSpeed" : "§cSpeed";
|
||||
statusMessage += " ";
|
||||
statusMessage += this.respawn ? "§aRespawn" : "§cRespawn";
|
||||
|
||||
final PacketWrapper chatMessage = PacketWrapper.create(ClientboundPacketsa1_0_15.CHAT_MESSAGE, this.getUser());
|
||||
chatMessage.write(Typesb1_7_0_3.STRING, statusMessage); // message
|
||||
chatMessage.send(Protocola1_0_15toc0_30.class);
|
||||
}
|
||||
}
|
||||
|
||||
public void setOpLevel(final byte opLevel) throws Exception {
|
||||
final boolean changed = this.opLevel != opLevel;
|
||||
this.opLevel = opLevel;
|
||||
|
||||
final ClassicServerTitleStorage serverTitleStorage = this.getUser().get(ClassicServerTitleStorage.class);
|
||||
this.updateHax(serverTitleStorage.isFlyEffectivelyEnabled(), serverTitleStorage.isNoclipEffectivelyEnabled(), serverTitleStorage.isSpeedEffectivelyEnabled(), serverTitleStorage.isRespawnEffectivelyEnabled());
|
||||
if (changed) {
|
||||
this.updateAbilities();
|
||||
}
|
||||
}
|
||||
|
||||
public byte getOpLevel() {
|
||||
return this.opLevel;
|
||||
}
|
||||
|
||||
public void updateAbilities() throws Exception {
|
||||
if (this.getUser().getProtocolInfo().getPipeline().contains(Protocol1_2_4_5to1_2_1_3.class)) {
|
||||
final PacketWrapper playerAbilities = PacketWrapper.create(ClientboundPackets1_2_4.PLAYER_ABILITIES, this.getUser());
|
||||
playerAbilities.write(Type.BOOLEAN, true); // invulnerable
|
||||
playerAbilities.write(Type.BOOLEAN, false); // flying
|
||||
playerAbilities.write(Type.BOOLEAN, this.flying); // allow flying
|
||||
playerAbilities.write(Type.BOOLEAN, true); // creative mode
|
||||
playerAbilities.send(Protocol1_2_4_5to1_2_1_3.class);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -39,4 +39,68 @@ public class ClassicServerTitleStorage extends StoredObject {
|
||||
return this.motd;
|
||||
}
|
||||
|
||||
public boolean isHaxEnabled() {
|
||||
return this.motd.contains("+hax");
|
||||
}
|
||||
|
||||
public boolean isHaxDisabled() {
|
||||
return this.motd.contains("-hax");
|
||||
}
|
||||
|
||||
public boolean isFlyEnabled() {
|
||||
return this.motd.contains("+fly");
|
||||
}
|
||||
|
||||
public boolean isFlyDisabled() {
|
||||
return this.motd.contains("-fly");
|
||||
}
|
||||
|
||||
public boolean isFlyEffectivelyEnabled() {
|
||||
final boolean isOp = this.getUser().get(ClassicOpLevelStorage.class).getOpLevel() >= 100;
|
||||
return (this.isHaxDisabled() ? this.isFlyEnabled() : !this.isFlyDisabled()) || (isOp && this.isOphaxEnabled());
|
||||
}
|
||||
|
||||
public boolean isNoclipEnabled() {
|
||||
return this.motd.contains("+noclip");
|
||||
}
|
||||
|
||||
public boolean isNoclipDisabled() {
|
||||
return this.motd.contains("-noclip");
|
||||
}
|
||||
|
||||
public boolean isNoclipEffectivelyEnabled() {
|
||||
final boolean isOp = this.getUser().get(ClassicOpLevelStorage.class).getOpLevel() >= 100;
|
||||
return (this.isHaxDisabled() ? this.isNoclipEnabled() : !this.isNoclipDisabled()) || (isOp && this.isOphaxEnabled());
|
||||
}
|
||||
|
||||
public boolean isRespawnEnabled() {
|
||||
return this.motd.contains("+respawn");
|
||||
}
|
||||
|
||||
public boolean isRespawnDisabled() {
|
||||
return this.motd.contains("-respawn");
|
||||
}
|
||||
|
||||
public boolean isRespawnEffectivelyEnabled() {
|
||||
final boolean isOp = this.getUser().get(ClassicOpLevelStorage.class).getOpLevel() >= 100;
|
||||
return (this.isHaxDisabled() ? this.isRespawnEnabled() : !this.isRespawnDisabled()) || (isOp && this.isOphaxEnabled());
|
||||
}
|
||||
|
||||
public boolean isSpeedEnabled() {
|
||||
return this.motd.contains("+speed");
|
||||
}
|
||||
|
||||
public boolean isSpeedDisabled() {
|
||||
return this.motd.contains("-speed");
|
||||
}
|
||||
|
||||
public boolean isSpeedEffectivelyEnabled() {
|
||||
final boolean isOp = this.getUser().get(ClassicOpLevelStorage.class).getOpLevel() >= 100;
|
||||
return (this.isHaxDisabled() ? this.isSpeedEnabled() : !this.isSpeedDisabled()) || (isOp && this.isOphaxEnabled());
|
||||
}
|
||||
|
||||
public boolean isOphaxEnabled() {
|
||||
return this.motd.contains("+ophax");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -42,12 +42,12 @@ import net.raphimc.vialegacy.protocols.classic.protocola1_0_15toc0_28_30.data.Cl
|
||||
import net.raphimc.vialegacy.protocols.classic.protocola1_0_15toc0_28_30.model.ClassicLevel;
|
||||
import net.raphimc.vialegacy.protocols.classic.protocola1_0_15toc0_28_30.storage.ClassicBlockRemapper;
|
||||
import net.raphimc.vialegacy.protocols.classic.protocola1_0_15toc0_28_30.storage.ClassicLevelStorage;
|
||||
import net.raphimc.vialegacy.protocols.classic.protocola1_0_15toc0_28_30.storage.ClassicOpLevelStorage;
|
||||
import net.raphimc.vialegacy.protocols.classic.protocola1_0_15toc0_28_30.storage.ClassicProgressStorage;
|
||||
import net.raphimc.vialegacy.protocols.classic.protocola1_0_15toc0_28_30.types.Typesc0_30;
|
||||
import net.raphimc.vialegacy.protocols.classic.protocolc0_28_30toc0_28_30cpe.data.ClassicProtocolExtension;
|
||||
import net.raphimc.vialegacy.protocols.classic.protocolc0_28_30toc0_28_30cpe.data.ExtendedClassicBlocks;
|
||||
import net.raphimc.vialegacy.protocols.classic.protocolc0_28_30toc0_28_30cpe.storage.ExtBlockPermissionsStorage;
|
||||
import net.raphimc.vialegacy.protocols.classic.protocolc0_28_30toc0_28_30cpe.storage.ExtHackControlStorage;
|
||||
import net.raphimc.vialegacy.protocols.classic.protocolc0_28_30toc0_28_30cpe.storage.ExtensionProtocolMetadataStorage;
|
||||
import net.raphimc.vialegacy.protocols.classic.protocolc0_28_30toc0_28_30cpe.task.ClassicPingTask;
|
||||
import net.raphimc.vialegacy.protocols.release.protocol1_2_1_3to1_1.types.Types1_1;
|
||||
@ -134,15 +134,12 @@ public class Protocolc0_30toc0_30cpe extends AbstractProtocol<ClientboundPackets
|
||||
}
|
||||
}
|
||||
|
||||
if (supportedExtensions.contains(ClassicProtocolExtension.HACK_CONTROL)) {
|
||||
wrapper.user().put(new ExtHackControlStorage(wrapper.user()));
|
||||
}
|
||||
if (supportedExtensions.contains(ClassicProtocolExtension.BLOCK_PERMISSIONS)) {
|
||||
wrapper.user().put(new ExtBlockPermissionsStorage(wrapper.user()));
|
||||
}
|
||||
|
||||
final PacketWrapper extensionProtocolInfo = PacketWrapper.create(ServerboundPacketsc0_30cpe.EXTENSION_PROTOCOL_INFO, wrapper.user());
|
||||
extensionProtocolInfo.write(Typesc0_30.STRING, "ClassiCube 1.3.2"); // app name
|
||||
extensionProtocolInfo.write(Typesc0_30.STRING, "ClassiCube 1.3.5"); // app name
|
||||
extensionProtocolInfo.write(Type.SHORT, (short) supportedExtensions.size()); // extension count
|
||||
extensionProtocolInfo.sendToServer(Protocolc0_30toc0_30cpe.class);
|
||||
|
||||
@ -171,37 +168,20 @@ public class Protocolc0_30toc0_30cpe extends AbstractProtocol<ClientboundPackets
|
||||
});
|
||||
}
|
||||
});
|
||||
this.registerClientbound(ClientboundPacketsc0_30cpe.EXT_HACK_CONTROL, ClientboundPacketsc0_28.CHAT_MESSAGE, new PacketHandlers() {
|
||||
this.registerClientbound(ClientboundPacketsc0_30cpe.EXT_HACK_CONTROL, null, new PacketHandlers() {
|
||||
@Override
|
||||
public void register() {
|
||||
handler(wrapper -> {
|
||||
final ExtHackControlStorage hackControlStorage = wrapper.user().get(ExtHackControlStorage.class);
|
||||
wrapper.cancel();
|
||||
final ClassicOpLevelStorage opLevelStorage = wrapper.user().get(ClassicOpLevelStorage.class);
|
||||
final boolean flying = wrapper.read(Type.BOOLEAN); // flying
|
||||
final boolean noClip = wrapper.read(Type.BOOLEAN); // no clip
|
||||
final boolean speed = wrapper.read(Type.BOOLEAN); // speed
|
||||
final boolean respawn = wrapper.read(Type.BOOLEAN); // respawn key
|
||||
final boolean thirdPerson = wrapper.read(Type.BOOLEAN); // third person view
|
||||
final short jumpHeight = wrapper.read(Type.SHORT); // jump height
|
||||
wrapper.read(Type.BOOLEAN); // third person view
|
||||
wrapper.read(Type.SHORT); // jump height
|
||||
|
||||
if (!hackControlStorage.update(flying, noClip, speed, respawn, thirdPerson, jumpHeight)) {
|
||||
wrapper.cancel();
|
||||
return;
|
||||
}
|
||||
|
||||
String statusMessage = "&6Hack control: ";
|
||||
statusMessage += hackControlStorage.flying ? "&aFlying" : "&cFlying";
|
||||
statusMessage += " ";
|
||||
statusMessage += hackControlStorage.noClip ? "&aNoClip" : "&cNoClip";
|
||||
statusMessage += " ";
|
||||
statusMessage += hackControlStorage.speed ? "&aSpeed" : "&cSpeed";
|
||||
statusMessage += " ";
|
||||
statusMessage += hackControlStorage.respawn ? "&aRespawn" : "&cRespawn";
|
||||
statusMessage += " ";
|
||||
statusMessage += hackControlStorage.thirdPerson ? "&aThird-Person" : "&cThird-Person";
|
||||
statusMessage += " &aJump-Height: " + hackControlStorage.jumpHeight;
|
||||
|
||||
wrapper.write(Type.BYTE, (byte) 0); // sender id
|
||||
wrapper.write(Typesc0_30.STRING, statusMessage); // message
|
||||
opLevelStorage.updateHax(flying, noClip, speed, respawn);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
@ -1,70 +0,0 @@
|
||||
/*
|
||||
* This file is part of ViaLegacy - https://github.com/RaphiMC/ViaLegacy
|
||||
* Copyright (C) 2023 RK_01/RaphiMC and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package net.raphimc.vialegacy.protocols.classic.protocolc0_28_30toc0_28_30cpe.storage;
|
||||
|
||||
import com.viaversion.viaversion.api.connection.StoredObject;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import net.raphimc.vialegacy.protocols.release.protocol1_2_4_5to1_2_1_3.Protocol1_2_4_5to1_2_1_3;
|
||||
import net.raphimc.vialegacy.protocols.release.protocol1_3_1_2to1_2_4_5.ClientboundPackets1_2_4;
|
||||
|
||||
public class ExtHackControlStorage extends StoredObject {
|
||||
|
||||
public boolean flying = true;
|
||||
public boolean noClip = true;
|
||||
public boolean speed = true;
|
||||
public boolean respawn = true;
|
||||
public boolean thirdPerson = true;
|
||||
public float jumpHeight = 1.233F;
|
||||
|
||||
public ExtHackControlStorage(final UserConnection user) {
|
||||
super(user);
|
||||
}
|
||||
|
||||
public boolean update(final boolean flying, final boolean noClip, final boolean speed, final boolean respawn, final boolean thirdPerson, final short jumpHeight) throws Exception {
|
||||
float calculatedJumpHeight = jumpHeight / 32F;
|
||||
if (calculatedJumpHeight <= 0) calculatedJumpHeight = 1.233F;
|
||||
|
||||
if (this.flying != flying && this.getUser().getProtocolInfo().getPipeline().contains(Protocol1_2_4_5to1_2_1_3.class)) {
|
||||
final PacketWrapper playerAbilities = PacketWrapper.create(ClientboundPackets1_2_4.PLAYER_ABILITIES, this.getUser());
|
||||
playerAbilities.write(Type.BOOLEAN, true); // invulnerable
|
||||
playerAbilities.write(Type.BOOLEAN, false); // flying
|
||||
playerAbilities.write(Type.BOOLEAN, flying); // allow flying
|
||||
playerAbilities.write(Type.BOOLEAN, true); // creative mode
|
||||
playerAbilities.send(Protocol1_2_4_5to1_2_1_3.class);
|
||||
}
|
||||
|
||||
boolean changed = this.flying != flying;
|
||||
changed |= this.noClip != noClip;
|
||||
changed |= this.speed != speed;
|
||||
changed |= this.respawn != respawn;
|
||||
changed |= this.thirdPerson != thirdPerson;
|
||||
changed |= this.jumpHeight != calculatedJumpHeight;
|
||||
|
||||
this.flying = flying;
|
||||
this.noClip = noClip;
|
||||
this.speed = speed;
|
||||
this.respawn = respawn;
|
||||
this.thirdPerson = thirdPerson;
|
||||
this.jumpHeight = calculatedJumpHeight;
|
||||
|
||||
return changed;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user