-
Notifications
You must be signed in to change notification settings - Fork 99
Networking and packets OLD
Our story begins with a player, who presses the Play button...
but this is not important now.
But keep in mind that the Fabric server and Bukkit server does the exact same, just the implementation is different
After the success handshaking and logging in into the server (server-client) both sides open all the channels:
emotecraft:discovery : Discovery channel
emotecraft:playemote : Emote streaming.
emotecraft:stopemote : Stopping emotes.
All types of packages are serializable with the Default Java 8 and emotecraftCommon packages.
DiscoveryPacket is for Emotecraft version (and in the close future config) exchange.
Emotecraft supports version discovery so it is possible to join a server with an older version of Emotecraft
StopPacket is for sending when someone stops playing an emote before its end.
It will be sent by the client, when the main player starts to move, or by the server for an invalid emotePlay as a response.
EmotePacket
This is for streaming EmoteData objects. It includes a version number, so the other side can know, what is this packet's version.
Version exchanging: same both sides
When the other side opens the discovery channel, a Discovery packet will be sent.
When receiving a DiscoveryPacket it registers that the other side has *** networking version.
Playing an emote:
The client start creates a new EmotePacket, and using it, it writes a byte array with the minimum of the client and the server's version
PacketByteBuf buf = new PacketByteBuf(Unpooled.buffer());
EmotePacket emotePacket = new EmotePacket(emote, player.getUuid());
emotePacket.write(buf, Math.min(serverEmotecraftVersion, clientEmotecraftVersion));
ClientPlayNetworking.send(MainNetwork.EMOTE_PLAY_NETWORK_PACKET_ID, buf);
The Server will deserialize it for anti-cheat and serialize it back for everyone with the other player's emotecraftVersion
EmotePacket packet = new EmotePacket();
if(!packet.read(Unpooled.wrappedBuffer(message), (float) this.config.getDouble("validThreshold")) && validate){
getLogger().info("Player: " + player.getName() + " is playing an invalid emote");
ByteBuf buf = Unpooled.buffer();
StopPacket stopPacket = new StopPacket(player.getUniqueId());
stopPacket.write(buf);
player.sendPluginMessage(this, Stoppacket, buf.array()); //send the invalid info back to the sender
return;
}
for(Player otherPlayer:getServer().getOnlinePlayers()){
if(otherPlayer != player && otherPlayer.canSee(player)){
ByteBuf buf = Unpooled.buffer();
packet.write(buf, player_database.get(otherPlayer.getUniqueId()));
otherPlayer.sendPluginMessage(this, Emotepacket, buf.array());
}
}
StopPacket is only streaming (currently)