/// <summary>
        ///     Creates the server.
        /// </summary>
        public void Create(NameValueCollection variables)
        {
            if (Server != null)
            {
                throw new InvalidOperationException("The server has already been created! (Is CreateOnEnable enabled?)");
            }

            if (configuration != null)
            {
                //Create spawn data from config
                ServerSpawnData spawnData = ServerSpawnData.CreateFromXml(XDocument.Parse(configuration.text), variables);

                //Inaccessible from xml, set from inspector
                spawnData.EventsFromDispatcher = eventsFromDispatcher;

                //Unity is broken, work around it...
                spawnData.Server.UseFallbackNetworking = true;

                //Add types
                spawnData.PluginSearch.PluginTypes.AddRange(UnityServerHelper.SearchForPlugins());
                spawnData.PluginSearch.PluginTypes.Add(typeof(UnityConsoleWriter));

                //Create server
                Server = new DarkRiftServer(spawnData);
                Server.Start();
            }
            else
            {
                Debug.LogError("No configuration file specified!");
            }
        }
示例#2
0
        /// <summary>
        ///     Creates the server.
        /// </summary>
        public void Create(NameValueCollection variables)
        {
            if (Server != null)
                throw new InvalidOperationException("The server has already been created! (Is CreateOnEnable enabled?)");
            
            if (configuration != null)
            {
                //Create spawn data from config
                ServerSpawnData spawnData = ServerSpawnData.CreateFromXml(XDocument.Parse(configuration.text), variables);

                //Inaccessible from xml, set from inspector
                spawnData.EventsFromDispatcher = eventsFromDispatcher;

                //Unity is broken, work around it...
                //This is an obsolete property but is still used if the user is using obsolete <server> tag properties
#pragma warning disable 0618
                spawnData.Server.UseFallbackNetworking = true;
#pragma warning restore 0618

                //Add types
                spawnData.PluginSearch.PluginTypes.AddRange(UnityServerHelper.SearchForPlugins());
                spawnData.PluginSearch.PluginTypes.Add(typeof(UnityConsoleWriter));

                //Create server
                Server = new DarkRiftServer(spawnData);
                Server.Start();
                enetListener = Server.NetworkListenerManager.GetNetworkListenersByType<EnetListenerPlugin>().First();
            }
            else
                Debug.LogError("No configuration file specified!");
        }
示例#3
0
        public override void OnInspectorGUI()
        {
            serializedObject.Update();

            EditorGUILayout.PropertyField(configuration);

            if (configuration.objectReferenceValue == null)
            {
                EditorGUILayout.HelpBox("There is currently no configuration file assigned for the XmlUnityServer. The server will not be able to start!\n\nConsider adding the ExampleConfiguration.xml file here to get started.", MessageType.Warning);
            }

            EditorGUILayout.PropertyField(createOnEnable);

            //Alert to changes when this is unticked!
            bool old = eventsFromDispatcher.boolValue;

            EditorGUILayout.PropertyField(eventsFromDispatcher);

            if (eventsFromDispatcher.boolValue != old && !eventsFromDispatcher.boolValue)
            {
                eventsFromDispatcher.boolValue = !EditorUtility.DisplayDialog(
                    "Danger!",
                    "Unchecking " + eventsFromDispatcher.displayName + " will cause DarkRift to fire events from the .NET thread pool. unless you are confident using multithreading with Unity you should not disable this.\n\nAre you sure you want to proceed?",
                    "Yes",
                    "No (Save me!)"
                    );
            }

            EditorGUILayout.Separator();

            IEnumerable <Type> pluginTypes = UnityServerHelper.SearchForPlugins();

            if (pluginTypes.Count() > 0)
            {
                string pluginList = pluginTypes.Select(t => "\t\u2022 " + t.Name).Aggregate((a, b) => a + "\n" + b);

                EditorGUILayout.HelpBox("The following plugin types were found and will be loaded into the server:\n" + pluginList, MessageType.Info);
            }
            else
            {
                EditorGUILayout.HelpBox("No plugins were found to load!", MessageType.Info);
            }

            EditorGUILayout.Separator();

            if (GUILayout.Button("Open Configuration"))
            {
                if (configuration != null)
                {
                    AssetDatabase.OpenAsset(configuration.objectReferenceValue);
                }
                else
                {
                    Debug.LogError("No configuration file specified!");
                }
            }
            serializedObject.ApplyModifiedProperties();
        }
示例#4
0
        /// <summary>
        ///     Creates the server.
        /// </summary>
        public void Create(NameValueCollection variables)
        {
            if (Server != null)
            {
                if (Server.Disposed)
                {
                    Server.StartServer();
                }
                else
                {
                    throw new InvalidOperationException("The server has already been created! (Is CreateOnEnable enabled?)");
                }
            }

            if (configuration != null)
            {
                // Create spawn data from config
                ServerSpawnData spawnData = ServerSpawnData.CreateFromXml(XDocument.Parse(configuration.text), variables);
                if (spawnData == null)
                {
                    throw new Exception("SpawnData not defined");
                }

                // Allow only this thread to execute dispatcher tasks to enable deadlock protection
                spawnData.DispatcherExecutorThreadID = Thread.CurrentThread.ManagedThreadId;

                // Inaccessible from XML, set from inspector
                spawnData.EventsFromDispatcher = eventsFromDispatcher;

                // Unity is broken, work around it...
                // This is an obsolete property but is still used if the user is using obsolete <server> tag properties
#pragma warning disable 0618
                spawnData.Server.UseFallbackNetworking = true;
#pragma warning restore 0618

                // Add types
                spawnData.PluginSearch.PluginTypes.AddRange(UnityServerHelper.SearchForPlugins());

                spawnData.Listeners.NetworkListeners[0].Port = port;

                // Create server
                Server = new DarkRiftServer(spawnData);
                Server.StartServer();
            }
            else
            {
                throw new Exception("Configuration file not set");
            }
        }
示例#5
0
        /// <summary>
        ///     Creates the server.
        /// </summary>
        public void Create(NameValueCollection variables)
        {
            if (Server != null)
            {
                throw new InvalidOperationException("The server has already been created! (Is CreateOnEnable enabled?)");
            }

            if (configuration != null)
            {
                // Create spawn data from config
                ServerSpawnData spawnData = ServerSpawnData.CreateFromXml(XDocument.Parse(configuration.text), variables);

                // Allow only this thread to execute dispatcher tasks to enable deadlock protection
                spawnData.DispatcherExecutorThreadID = Thread.CurrentThread.ManagedThreadId;

                // Inaccessible from XML, set from inspector
                spawnData.EventsFromDispatcher = eventsFromDispatcher;

                // Unity is broken, work around it...
                // This is an obsolete property but is still used if the user is using obsolete <server> tag properties
#pragma warning disable 0618
                spawnData.Server.UseFallbackNetworking = true;
#pragma warning restore 0618

                // Add types
                spawnData.PluginSearch.PluginTypes.AddRange(UnityServerHelper.SearchForPlugins());
                spawnData.PluginSearch.PluginTypes.Add(typeof(UnityConsoleWriter));

                // Create server
                Server = new DarkRiftServer(spawnData);
                Server.StartServer();
            }
            else
            {
                Debug.LogError("No configuration file specified! Please ensure there is a configuration file set on the XmlUnityServer component before starting the server.");
            }
        }
示例#6
0
        /// <summary>
        ///     Creates the server.
        /// </summary>
        public void Create()
        {
            if (Server != null)
            {
                throw new InvalidOperationException("The server has already been created! (Is CreateOnEnable enabled?)");
            }

            ServerSpawnData spawnData = new ServerSpawnData(address, port, ipVersion);

            //Server settings
            spawnData.Server.MaxStrikes            = maxStrikes;
            spawnData.Server.UseFallbackNetworking = true;      //Unity is broken, work around it...
            spawnData.EventsFromDispatcher         = eventsFromDispatcher;

            //Plugin search settings
            spawnData.PluginSearch.PluginTypes.AddRange(UnityServerHelper.SearchForPlugins());
            spawnData.PluginSearch.PluginTypes.Add(typeof(UnityConsoleWriter));

            //Data settings
            spawnData.Data.Directory = dataDirectory;

            //Logging settings
            spawnData.Plugins.LoadByDefault = true;

            if (logToFile)
            {
                ServerSpawnData.LoggingSettings.LogWriterSettings fileWriter = new ServerSpawnData.LoggingSettings.LogWriterSettings();
                fileWriter.Name             = "FileWriter1";
                fileWriter.Type             = "FileWriter";
                fileWriter.LogLevels        = new LogType[] { LogType.Trace, LogType.Info, LogType.Warning, LogType.Error, LogType.Fatal };
                fileWriter.Settings["file"] = logFileString;
                spawnData.Logging.LogWriters.Add(fileWriter);
            }

            if (logToUnityConsole)
            {
                ServerSpawnData.LoggingSettings.LogWriterSettings consoleWriter = new ServerSpawnData.LoggingSettings.LogWriterSettings();
                consoleWriter.Name      = "UnityConsoleWriter1";
                consoleWriter.Type      = "UnityConsoleWriter";
                consoleWriter.LogLevels = new LogType[] { LogType.Info, LogType.Warning, LogType.Error, LogType.Fatal };
                spawnData.Logging.LogWriters.Add(consoleWriter);
            }

            if (logToDebug)
            {
                ServerSpawnData.LoggingSettings.LogWriterSettings debugWriter = new ServerSpawnData.LoggingSettings.LogWriterSettings();
                debugWriter.Name      = "DebugWriter1";
                debugWriter.Type      = "DebugWriter";
                debugWriter.LogLevels = new LogType[] { LogType.Warning, LogType.Error, LogType.Fatal };
                spawnData.Logging.LogWriters.Add(debugWriter);
            }

            //Plugins
            spawnData.Plugins.LoadByDefault = loadByDefault;
            spawnData.Plugins.Plugins.AddRange(plugins);

            //Databases
            spawnData.Databases.Databases.AddRange(databases);

            //Cache
            spawnData.Cache.MaxCachedWriters              = MaxCachedWriters;
            spawnData.Cache.MaxCachedReaders              = MaxCachedReaders;
            spawnData.Cache.MaxCachedMessages             = MaxCachedMessages;
            spawnData.Cache.MaxCachedSocketAsyncEventArgs = MaxCachedSocketAsyncEventArgs;
            spawnData.Cache.MaxActionDispatcherTasks      = MaxCachedActionDispatcherTasks;

            Server = new DarkRiftServer(spawnData);
            Server.Start();
        }
示例#7
0
        public override void OnInspectorGUI()
        {
            serializedObject.Update();

            EditorGUILayout.PropertyField(createOnEnable);

            //Alert to changes when this is unticked!
            bool old = eventsFromDispatcher.boolValue;

            EditorGUILayout.PropertyField(eventsFromDispatcher);

            if (eventsFromDispatcher.boolValue != old && !eventsFromDispatcher.boolValue)
            {
                eventsFromDispatcher.boolValue = !EditorUtility.DisplayDialog(
                    "Danger!",
                    "Unchecking " + eventsFromDispatcher.displayName + " will cause DarkRift to fire events from the .NET thread pool, unless you are confident using multithreading with Unity you should not disable this. Are you 100% sure you want to proceed?",
                    "Yes",
                    "No (Save me!)"
                    );
            }

            if (showServer = EditorGUILayout.Foldout(showServer, "Server Setttings"))
            {
                EditorGUI.indentLevel++;

                //Display IP address
                address = EditorGUILayout.TextField(new GUIContent("Address", "The address the client will connect to."), address);

                try
                {
                    server.Address = IPAddress.Parse(address);
                }
                catch (FormatException)
                {
                    EditorGUILayout.HelpBox("Invalid IP address.", MessageType.Error);
                }

                EditorGUILayout.PropertyField(port);

                //Draw IP versions manually else it gets formatted as "Ip Version" and "I Pv4" -_-
                ipVersion.enumValueIndex = EditorGUILayout.Popup(new GUIContent("IP Version", "The IP protocol version the server will listen on."), ipVersion.enumValueIndex, Array.ConvertAll(ipVersion.enumNames, i => new GUIContent(i)));

                EditorGUILayout.PropertyField(maxStrikes);

                EditorGUI.indentLevel--;
            }

            if (showData = EditorGUILayout.Foldout(showData, "Data Setttings"))
            {
                EditorGUI.indentLevel++;

                EditorGUILayout.PropertyField(dataDirectory);

                EditorGUI.indentLevel--;
            }

            if (showLogging = EditorGUILayout.Foldout(showLogging, "Logging Setttings"))
            {
                EditorGUI.indentLevel++;

                EditorGUILayout.PropertyField(logToFile);

                EditorGUI.indentLevel++;
                if (logToFile.boolValue)
                {
                    EditorGUILayout.PropertyField(logFileString);
                }
                EditorGUI.indentLevel--;

                EditorGUILayout.PropertyField(logToUnityConsole);

                EditorGUILayout.PropertyField(logToDebug);

                EditorGUI.indentLevel--;
            }

            //Draw plugins list
            if (showPlugins = EditorGUILayout.Foldout(showPlugins, "Plugin Setttings"))
            {
                EditorGUI.indentLevel++;

                EditorGUILayout.PropertyField(loadByDefault);

                IEnumerable <Type> types = UnityServerHelper.SearchForPlugins();

                foreach (Type type in types)
                {
                    ServerSpawnData.PluginsSettings.PluginSettings plugin = server.Plugins.SingleOrDefault(p => p.Type == type.Name);

                    if (plugin == null)
                    {
                        plugin = new ServerSpawnData.PluginsSettings.PluginSettings
                        {
                            Type = type.Name,
                            Load = true
                        };

                        server.Plugins.Add(plugin);
                    }

                    EditorGUILayout.HelpBox("The following are plugins in your project, tick those to be loaded.", MessageType.Info);

                    plugin.Load = EditorGUILayout.Toggle(type.Name, plugin.Load);

                    EditorGUILayout.Space();
                }

                EditorGUI.indentLevel--;
            }

            //Draw databases manually
            if (showDatabases = EditorGUILayout.Foldout(showDatabases, "Databases"))
            {
                EditorGUI.indentLevel++;
                for (int i = 0; i < server.Databases.Count; i++)
                {
                    ServerSpawnData.DatabaseSettings.DatabaseConnectionData database = server.Databases[i];

                    database.Name = EditorGUILayout.TextField("Name", database.Name);

                    database.ConnectionString = EditorGUILayout.TextField("Connection String", database.ConnectionString);

                    Rect removeRect = EditorGUI.IndentedRect(EditorGUILayout.GetControlRect());        //So indent level affects the button
                    if (GUI.Button(removeRect, "Remove"))
                    {
                        server.Databases.Remove(database);
                        i--;
                    }

                    EditorGUILayout.Space();
                }

                Rect addRect = EditorGUI.IndentedRect(EditorGUILayout.GetControlRect(true));
                if (GUI.Button(addRect, "Add Database"))
                {
                    server.Databases.Add(new ServerSpawnData.DatabaseSettings.DatabaseConnectionData("NewDatabase", "Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword;"));
                }

                EditorGUI.indentLevel--;
            }

            if (showCache = EditorGUILayout.Foldout(showCache, "Cache"))
            {
                EditorGUILayout.PropertyField(maxCachedWriters);
                EditorGUILayout.PropertyField(maxCachedReaders);
                EditorGUILayout.PropertyField(maxCachedMessages);
                EditorGUILayout.PropertyField(maxCachedSocketAsyncEventArgs);
                EditorGUILayout.PropertyField(maxCachedActionDispatcherTasks);
            }

            serializedObject.ApplyModifiedProperties();
        }