Example #1
0
        public static void ServerInit(IServerInitInterfaces initInterfaces)
        {
            MefServer.Init(Assembly.GetExecutingAssembly());
            MefServer.AddType <IGameInfo>(new GameInfo(true));

            LoadMefTypes <IServerInitInterfaces>(initInterfaces, typeof(MefServer));

            MefServer.GetExportedValue <IEntityManager>().GenerateServerClasses();


            var consoleManager = MefServer.GetExportedValue <NI_ConsoleManager>();

            foreach (var conCommand in MefServer.GetExportedValues <IConCommand>())
            {
                consoleManager.Register(conCommand);
            }

            foreach (var conVar in MefServer.GetExportedValues <IConVariable>())
            {
                consoleManager.Register(conVar);
            }


            initInterfaces.ServerGameDll     = MefServer.GetExportedValue <M_IServerGameDll>();
            initInterfaces.ServerGameClients = MefServer.GetExportedValue <M_IServerGameClients>();
            initInterfaces.ServerGameEnts    = MefServer.GetExportedValue <M_IServerGameEnts>();
        }
        public BaseEntityClient CreateEntity(String className)
        {
            BaseEntityClient ent = null;

            try
            {
                ent           = MefServer.GetExportedValue <BaseEntityClient>(className);
                ent.ClassName = className;
            }
            catch (Exception e)
            {
                _ConsoleManager.WriteLine(Color.Red, String.Format("Failed to create entity {0}: {1}", className, e.Message));
                return(null);
            }

            _EntityList.Add(ent);
            return(ent);
        }
Example #3
0
        private BaseEntityServer CreateEntity(String className, IEdict edict, int index = -1)
        {
            BaseEntityServer ent = null;

            try
            {
                ent           = MefServer.GetExportedValue <BaseEntityServer>(className);
                ent.ClassName = className;
            }
            catch (Exception e)
            {
                _ConsoleManager.WriteLine(Color.Red, String.Format("Failed to create entity {0}: {1}", className, e.Message));
                return(null);
            }

            if (edict == null)
            {
                _EngineServer.CreateEdict(ent, index);
            }
            else
            {
                ent.Edict = edict;
            }

            _EntityList.Add(ent);

            ent.PostCreate();

            if (ent.IsServerOnly)
            {
                Debug.Assert(false); //todo fix to work
                ent.Edict.SetSlotAndSerial(1, -1);
            }
            else
            {
                int slot = _EngineServer.IndexOfEdict(ent.Edict);
                ent.Edict.SetSlotAndSerial(slot, _EntSerials[slot]);
            }

            return(ent);
        }