2019-08-03 06:51:05 +00:00
|
|
|
/*
|
2021-01-01 15:10:36 +00:00
|
|
|
* Copyright (c) 2019-2021 GeyserMC. http://geysermc.org
|
2019-08-03 06:51:05 +00:00
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*
|
|
|
|
* @author GeyserMC
|
|
|
|
* @link https://github.com/GeyserMC/Geyser
|
|
|
|
*/
|
|
|
|
|
2021-11-20 23:29:46 +00:00
|
|
|
package org.geysermc.geyser.translator.protocol.bedrock;
|
2019-08-03 06:51:05 +00:00
|
|
|
|
2021-11-13 03:44:15 +00:00
|
|
|
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.ServerboundKeepAlivePacket;
|
2021-07-08 02:44:53 +00:00
|
|
|
import com.nukkitx.protocol.bedrock.data.AttributeData;
|
2020-09-29 18:15:11 +00:00
|
|
|
import com.nukkitx.protocol.bedrock.packet.NetworkStackLatencyPacket;
|
2020-11-26 22:00:43 +00:00
|
|
|
import com.nukkitx.protocol.bedrock.packet.UpdateAttributesPacket;
|
2021-11-20 21:34:30 +00:00
|
|
|
import org.geysermc.geyser.entity.attribute.GeyserAttributeType;
|
2021-11-21 18:36:42 +00:00
|
|
|
import org.geysermc.geyser.session.GeyserSessionImpl;
|
2021-11-20 23:29:46 +00:00
|
|
|
import org.geysermc.geyser.translator.protocol.PacketTranslator;
|
|
|
|
import org.geysermc.geyser.translator.protocol.Translator;
|
2020-12-15 21:06:59 +00:00
|
|
|
import org.geysermc.floodgate.util.DeviceOs;
|
2020-11-26 22:00:43 +00:00
|
|
|
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.concurrent.TimeUnit;
|
2019-08-03 06:51:05 +00:00
|
|
|
|
2020-09-29 18:15:11 +00:00
|
|
|
/**
|
2021-02-10 17:18:31 +00:00
|
|
|
* Used to send the forwarded keep alive packet back to the server
|
2020-09-29 18:15:11 +00:00
|
|
|
*/
|
|
|
|
@Translator(packet = NetworkStackLatencyPacket.class)
|
|
|
|
public class BedrockNetworkStackLatencyTranslator extends PacketTranslator<NetworkStackLatencyPacket> {
|
2019-08-03 06:51:05 +00:00
|
|
|
|
2020-09-29 18:15:11 +00:00
|
|
|
@Override
|
2021-11-21 18:36:42 +00:00
|
|
|
public void translate(GeyserSessionImpl session, NetworkStackLatencyPacket packet) {
|
2020-12-14 20:47:17 +00:00
|
|
|
long pingId;
|
|
|
|
// so apparently, as of 1.16.200
|
|
|
|
// PS4 divides the network stack latency timestamp FOR US!!!
|
|
|
|
// WTF
|
2020-12-15 21:06:59 +00:00
|
|
|
if (session.getClientData().getDeviceOs().equals(DeviceOs.PS4)) {
|
2020-12-14 20:47:17 +00:00
|
|
|
pingId = packet.getTimestamp();
|
|
|
|
} else {
|
|
|
|
pingId = packet.getTimestamp() / 1000;
|
|
|
|
}
|
2020-12-15 21:06:59 +00:00
|
|
|
|
|
|
|
// negative timestamps are used as hack to fix the url image loading bug
|
2020-11-26 22:00:43 +00:00
|
|
|
if (packet.getTimestamp() > 0) {
|
2021-11-20 21:34:30 +00:00
|
|
|
if (session.getGeyser().getConfig().isForwardPlayerPing()) {
|
2021-11-13 03:44:15 +00:00
|
|
|
ServerboundKeepAlivePacket keepAlivePacket = new ServerboundKeepAlivePacket(pingId);
|
2021-02-25 01:28:48 +00:00
|
|
|
session.sendDownstreamPacket(keepAlivePacket);
|
2021-02-10 17:18:31 +00:00
|
|
|
}
|
2020-11-26 22:00:43 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Hack to fix the url image loading bug
|
|
|
|
UpdateAttributesPacket attributesPacket = new UpdateAttributesPacket();
|
|
|
|
attributesPacket.setRuntimeEntityId(session.getPlayerEntity().getGeyserId());
|
|
|
|
|
2021-07-08 02:44:53 +00:00
|
|
|
AttributeData attribute = session.getPlayerEntity().getAttributes().get(GeyserAttributeType.EXPERIENCE_LEVEL);
|
2020-11-26 22:00:43 +00:00
|
|
|
if (attribute != null) {
|
2021-07-08 02:44:53 +00:00
|
|
|
attributesPacket.setAttributes(Collections.singletonList(attribute));
|
2020-11-26 22:00:43 +00:00
|
|
|
} else {
|
2021-07-08 02:44:53 +00:00
|
|
|
attributesPacket.setAttributes(Collections.singletonList(GeyserAttributeType.EXPERIENCE_LEVEL.getAttribute(0)));
|
2020-11-26 22:00:43 +00:00
|
|
|
}
|
|
|
|
|
2021-11-13 16:03:55 +00:00
|
|
|
session.scheduleInEventLoop(() -> session.sendUpstreamPacket(attributesPacket),
|
2020-11-26 22:00:43 +00:00
|
|
|
500, TimeUnit.MILLISECONDS);
|
2020-09-29 18:15:11 +00:00
|
|
|
}
|
2019-08-03 06:51:05 +00:00
|
|
|
}
|