Sending and Receiving an ES3File In Multiplayer

Discussion and help for Easy Save 3
Post Reply
User avatar
frezno
Posts: 10
Joined: Mon Nov 13, 2017 8:53 pm

Sending and Receiving an ES3File In Multiplayer

Post by frezno »

Hello!

I just wanted to see if I'm on the right track of what I'm trying to do. Essentially I have an ES3File that will contain a bunch of various data that belongs to the player. I would like to send this file to all players in the room so that the users can load this players data without actually having to be sent the file physically.

In networking, the general rule is that sending Bytes it better than sending raw data and since ES3File has LoadRaw, would it be wise to essentially do something like the code below? I have tested it, and everything seemed fine, but I just wanted to make sure I'm doing this correctly or see if there is a better way to do it.

Thanks!

Code: Select all

    public void SendPlayerData(string playerDataFile)
    {
        //Load physical file into ES3File
        var pData = new ES3File(playerDataFile);

        //Convert player data to bytes
        var bytesToSend = pData.LoadRawBytes();

        this.RPC("SendBytes", All, bytesToSend);
    }

    public void ReceivePlayerData(byte[] receivedBytes)
    {
        var rData = new ES3File(receivedBytes);

        rData.LoadInto("playerSetupData", NetPlayer[thisPlayer.index].Components.PlayerData);
    }
cloudweight
User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

Re: Sending and Receiving an ES3File In Multiplayer

Post by Joel »

Hi there,

This is indeed the best and most efficient way of doing what you want.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
Post Reply