Example #1
0
 public PersistAttribute(Type SerializerType = null)
 {
     if (SerializerType != null)
     {
         Serializer = Activator.CreateInstance(SerializerType) as PersistentValueSerializer;
     }
 }
Example #2
0
        public static Object _ReadValue(Type ValueType, JsonReader Reader, MudObject Owner)
        {
            Object r = null;

            if (Reader.TokenType == JsonToken.String)
            {
                r = Reader.Value.ToString(); Reader.Read();
            }
            else if (Reader.TokenType == JsonToken.Integer)
            {
                r = Convert.ToInt32(Reader.Value.ToString()); Reader.Read();
            }
            else if (Reader.TokenType == JsonToken.Boolean)
            {
                r = Convert.ToBoolean(Reader.Value.ToString()); Reader.Read();
            }
            else
            {
                PersistentValueSerializer serializer = null;
                if (ValueType != null && PersistentValueSerializer.GlobalSerializers.TryGetValue(ValueType.Name, out serializer))
                {
                    return(serializer.ReadValue(ValueType, Reader, Owner));
                }
                else if (Reader.TokenType == JsonToken.StartObject)
                {
                    Reader.Read();
                    if (Reader.TokenType != JsonToken.PropertyName || Reader.Value.ToString() != "$type")
                    {
                        throw new InvalidOperationException();
                    }
                    Reader.Read();
                    if (!PersistentValueSerializer.GlobalSerializers.TryGetValue(Reader.Value.ToString(), out serializer))
                    {
                        throw new InvalidOperationException();
                    }
                    Reader.Read();
                    Reader.Read();
                    r = serializer.ReadValue(ValueType, Reader, Owner);
                    Reader.Read();
                }
                else
                {
                    throw new InvalidOperationException();
                }
            }
            return(r);
        }
Example #3
0
        public static void _WriteValue(Object Value, JsonWriter Writer, MudObject Owner)
        {
            var name = Value.GetType().Name;
            PersistentValueSerializer serializer = null;

            if (PersistentValueSerializer.GlobalSerializers.TryGetValue(name, out serializer))
            {
                Writer.WriteStartObject();
                Writer.WritePropertyName("$type");
                Writer.WriteValue(name);
                Writer.WritePropertyName("$value");
                serializer.WriteValue(Value, Writer, Owner);
                Writer.WriteEndObject();
            }
            else
            {
                Writer.WriteValue(Value);  //Hope...
            }
        }
Example #4
0
 public PersistAttribute(Type SerializerType = null)
 {
     if (SerializerType != null)
         Serializer = Activator.CreateInstance(SerializerType) as PersistentValueSerializer;
 }
 public static void AddGlobalSerializer(PersistentValueSerializer Serializer)
 {
     GlobalSerializers.Upsert(Serializer.TargetType.Name, Serializer);
 }
Example #6
0
        /// <summary>
        /// Start the mud engine.
        /// </summary>
        /// <param name="Flags">Flags control engine functions</param>
        /// <param name="Database"></param>
        /// <param name="Assemblies">Modules to integrate</param>
        /// <returns></returns>
        public static bool Start(StartupFlags Flags, WorldDataService Database, params ModuleAssembly[] Assemblies)
        {
            ShuttingDown = false;
            Core.Flags   = Flags;

            try
            {
                // Setup the rule engine and some basic rules.
                GlobalRules = new RuleEngine(NewRuleQueueingMode.QueueNewRules);
                GlobalRules.DeclarePerformRuleBook("at startup", "[] : Considered when the engine is started.");
                GlobalRules.DeclarePerformRuleBook <MudObject>("singleplayer game started", "Considered when a single player game is begun");

                // Integrate modules. The Core assembly is always integrated.
                IntegratedModules.Add(new ModuleAssembly(Assembly.GetExecutingAssembly(), new ModuleInfo {
                    Author = "Blecki", Description = "RMUD Core", BaseNameSpace = "RMUD"
                }, "Core.dll"));
                IntegratedModules.AddRange(Assemblies);

                if ((Flags & StartupFlags.SearchDirectory) == StartupFlags.SearchDirectory)
                {
                    foreach (var file in System.IO.Directory.EnumerateFiles(System.IO.Directory.GetCurrentDirectory()).Where(p => System.IO.Path.GetExtension(p) == ".dll"))
                    {
                        var assembly = System.Reflection.Assembly.LoadFrom(file);

                        var infoType = assembly.GetTypes().FirstOrDefault(t => t.IsSubclassOf(typeof(ModuleInfo)));
                        if (infoType != null)
                        {
                            IntegratedModules.Add(new ModuleAssembly(assembly, file));
                            if ((Flags & StartupFlags.Silent) == 0)
                            {
                                Console.WriteLine("Discovered module: " + file);
                            }
                        }
                    }
                }

                foreach (var startupAssembly in IntegratedModules)
                {
                    IntegrateModule(startupAssembly);
                }

                PersistentValueSerializer.AddGlobalSerializer(new BitArraySerializer());

                InitializeCommandProcessor();

                GlobalRules.FinalizeNewRules();

                Core.Database = Database;
                Database.Initialize();

                GlobalRules.ConsiderPerformRule("at startup");

                if ((Flags & StartupFlags.SingleThreaded) == 0)
                {
                    StartThreadedCommandProcesor();
                }
            }
            catch (Exception e)
            {
                LogError("Failed to start mud engine.");
                LogError(e.Message);
                LogError(e.StackTrace);
                throw;
            }
            return(true);
        }
Example #7
0
 public static void AddGlobalSerializer(PersistentValueSerializer Serializer)
 {
     GlobalSerializers.Upsert(Serializer.TargetType.Name, Serializer);
 }