Esempio n. 1
0
    private void OnAssetUpdatedByClient(NetMessagePlayerAssets netMessage, INetworkInterfaceConnection source)
    {
        if (netMessage.Assets == null || netMessage.Assets.Length == 0)
        {
            return;
        }

        UpdateOrCreateLocalAssets(netMessage);

        List <PlayerAsset> assetsToSend = new List <PlayerAsset>(netMessage.Assets.Length);

        for (int i = 0; i < netMessage.Assets.Length; i++)
        {
            PlayerAsset playerAsset = GetAsset(netMessage.Assets[i].Guid);
            if (playerAsset != null)
            {
                assetsToSend.Add(playerAsset);
            }
        }

        List <INetworkInterfaceConnection> clientsToSendTo = _session.Connections.ToList();

        clientsToSendTo.Remove(source);

        SendPlayerAssetsToClients(assetsToSend.ToArray(), clientsToSendTo.ToArray());
    }
Esempio n. 2
0
    private void SendPlayerAssetsToClients(PlayerAsset[] playerAssets, INetworkInterfaceConnection[] clients)
    {
        NetMessagePlayerAssets.Data[] datas = new NetMessagePlayerAssets.Data[playerAssets.Length];
        for (int i = 0; i < playerAssets.Length; i++)
        {
            datas[i] = new NetMessagePlayerAssets.Data(playerAssets[i]);
        }

        NetMessagePlayerAssets netMessage = new NetMessagePlayerAssets()
        {
            Assets = datas
        };

        // send message
        foreach (var client in clients)
        {
            _session.BeginLargeDataTransfer(netMessage, client, "Doodles");
        }
    }
Esempio n. 3
0
    protected void UpdateOrCreateLocalAssets(NetMessagePlayerAssets netMessage)
    {
        foreach (var item in netMessage.Assets)
        {
            if (item.Type == PlayerAssetType.Invalid)
            {
                logDiscardReason($"Invalid asset type");
                continue;
            }

            if (item.Guid == Guid.Empty)
            {
                logDiscardReason($"Invalid guid");
                continue;
            }

            if (item.AssetData == null)
            {
                logDiscardReason($"Null asset data");
                continue;
            }

            PlayerAsset asset = GetAsset(item.Guid);
            if (asset == null)
            {
                asset = CreateAssetInternal(item.Guid, item.Type);
            }

            asset.Author          = item.Author;
            asset.UtcCreationTime = item.UtcCreationTime;
            asset.Load(item.AssetData);
        }

        void logDiscardReason(string reason)
        {
            Log.Warning($"{reason} in {nameof(NetMessagePlayerAssets)}. Discarding asset.");
        }
    }
Esempio n. 4
0
 private void OnAssetUpdatedByServer(NetMessagePlayerAssets netMessage, INetworkInterfaceConnection source)
 {
     UpdateOrCreateLocalAssets(netMessage);
 }