Search in sources :

Example 1 with MessageClientSkinPart

use of riskyken.armourersWorkshop.common.network.messages.client.MessageClientSkinPart in project Armourers-Workshop by RiskyKen.

the class SkinUploadHelper method uploadSkinToServer.

public static void uploadSkinToServer(Skin skin) {
    if (!ConfigHandler.allowClientsToUploadSkins) {
        return;
    }
    skin.requestId = new SkinIdentifier(skin);
    ModLogger.log("Uploading skin to server: " + skin);
    byte[] skinData = ByteBufHelper.convertSkinToByteArray(skin);
    ArrayList<MessageClientSkinPart> packetQueue = new ArrayList<MessageClientSkinPart>();
    int packetsNeeded = (int) Math.ceil((double) skinData.length / (double) MAX_PACKET_SIZE);
    int bytesLeftToSend = skinData.length;
    int bytesSent = 0;
    for (int i = 0; i < packetsNeeded; i++) {
        boolean lastPacket = i == packetsNeeded - 1;
        byte[] messageData;
        if (lastPacket) {
            messageData = new byte[bytesLeftToSend];
        } else {
            messageData = new byte[MAX_PACKET_SIZE];
        }
        System.arraycopy(skinData, bytesSent, messageData, 0, messageData.length);
        MessageClientSkinPart skinMessage = new MessageClientSkinPart(skin.lightHash(), (byte) i, messageData);
        packetQueue.add(skinMessage);
        bytesLeftToSend -= messageData.length;
        bytesSent += messageData.length;
    }
    for (int i = 0; i < packetQueue.size(); i++) {
        PacketHandler.networkWrapper.sendToServer(packetQueue.get(i));
    }
}
Also used : MessageClientSkinPart(riskyken.armourersWorkshop.common.network.messages.client.MessageClientSkinPart) ArrayList(java.util.ArrayList) SkinIdentifier(riskyken.armourersWorkshop.common.skin.data.SkinIdentifier)

Aggregations

ArrayList (java.util.ArrayList)1 MessageClientSkinPart (riskyken.armourersWorkshop.common.network.messages.client.MessageClientSkinPart)1 SkinIdentifier (riskyken.armourersWorkshop.common.skin.data.SkinIdentifier)1