Beispiel #1
0
        /// <summary>
        /// Sets the NetworkConfig data with that from a base64 encoded version
        /// </summary>
        /// <param name="base64">The base64 encoded version</param>
        /// <param name="createDummyObject">Wheter or not to create dummy objects for NetworkedPrefabs</param>
        public void FromBase64(string base64, bool createDummyObject = false)
        {
            NetworkConfig config = this;

            byte[] binary = Convert.FromBase64String(base64);
            using (BitReader reader = BitReader.Get(binary))
            {
                config.ProtocolVersion = reader.ReadUShort();
                config.Transport       = (DefaultTransport)reader.ReadBits(5);

                ushort channelCount = reader.ReadUShort();
                config.Channels.Clear();
                for (int i = 0; i < channelCount; i++)
                {
                    Channel channel = new Channel()
                    {
                        Name      = reader.ReadString(),
                        Encrypted = reader.ReadBool(),
                        Type      = (ChannelType)reader.ReadBits(5)
                    };
                    config.Channels.Add(channel);
                }

                ushort messageTypeCount = reader.ReadUShort();
                config.MessageTypes.Clear();
                for (int i = 0; i < messageTypeCount; i++)
                {
                    MessageType messageType = new MessageType()
                    {
                        Name        = reader.ReadString(),
                        Passthrough = reader.ReadBool()
                    };
                    config.MessageTypes.Add(messageType);
                }

                ushort sceneCount = reader.ReadUShort();
                config.RegisteredScenes.Clear();
                for (int i = 0; i < sceneCount; i++)
                {
                    config.RegisteredScenes.Add(reader.ReadString());
                }

                ushort networkedPrefabsCount = reader.ReadUShort();
                config.NetworkedPrefabs.Clear();
                GameObject root = createDummyObject ? new GameObject("MLAPI: Dummy prefabs") : null;
                for (int i = 0; i < networkedPrefabsCount; i++)
                {
                    bool       playerPrefab = reader.ReadBool();
                    string     prefabName   = reader.ReadString();
                    GameObject dummyPrefab  = createDummyObject ? new GameObject("REPLACEME: " + prefabName + "(Dummy prefab)", typeof(NetworkedObject)) : null;
                    if (dummyPrefab != null)
                    {
                        dummyPrefab.GetComponent <NetworkedObject>().NetworkedPrefabName = prefabName;
                        dummyPrefab.transform.SetParent(root.transform); //This is just here to not ruin your hierarchy
                    }
                    NetworkedPrefab networkedPrefab = new NetworkedPrefab()
                    {
                        playerPrefab = playerPrefab,
                        prefab       = dummyPrefab
                    };
                    config.NetworkedPrefabs.Add(networkedPrefab);
                }

                config.MessageBufferSize           = reader.ReadInt();
                config.ReceiveTickrate             = reader.ReadInt();
                config.MaxReceiveEventsPerTickRate = reader.ReadInt();
                config.SendTickrate   = reader.ReadInt();
                config.EventTickrate  = reader.ReadInt();
                config.MaxConnections = reader.ReadInt();
                config.ConnectPort    = reader.ReadInt();
                config.ConnectAddress = reader.ReadString();
                config.ClientConnectionBufferTimeout = reader.ReadInt();
                config.ConnectionApproval            = reader.ReadBool();
                config.SecondsHistory           = reader.ReadInt();
                config.HandleObjectSpawning     = reader.ReadBool();
                config.EnableEncryption         = reader.ReadBool();
                config.SignKeyExchange          = reader.ReadBool();
                config.AllowPassthroughMessages = reader.ReadBool();
                config.EnableSceneSwitching     = reader.ReadBool();
                config.EnableTimeResync         = reader.ReadBool();
                config.AttributeMessageMode     = (AttributeMessageMode)reader.ReadBits(3);
            }
        }