Beispiel #1
0
		/// <summary>
		/// Initialize all script components
		/// </summary>
		/// <returns>true if successfull, false if not</returns>
		protected bool StartScriptComponents()
		{
			try
			{
				//---------------------------------------------------------------
				//Create the server rules
				m_serverRules = ScriptMgr.CreateServerRules(Configuration.ServerType);
				if (log.IsInfoEnabled)
					log.Info("Server rules: true");

				//---------------------------------------------------------------
				//Load the skills
				SkillBase.LoadSkills();
				if (log.IsInfoEnabled)
					log.Info("Loading skills: true");

				//---------------------------------------------------------------
				//Register all event handlers
				var scripts = new ArrayList(ScriptMgr.Scripts);
				scripts.Insert(0, typeof (GameServer).Assembly);
				foreach (Assembly asm in scripts)
				{
					GameEventMgr.RegisterGlobalEvents(asm, typeof (GameServerStartedEventAttribute), GameServerEvent.Started);
					GameEventMgr.RegisterGlobalEvents(asm, typeof (GameServerStoppedEventAttribute), GameServerEvent.Stopped);
					GameEventMgr.RegisterGlobalEvents(asm, typeof (ScriptLoadedEventAttribute), ScriptEvent.Loaded);
					GameEventMgr.RegisterGlobalEvents(asm, typeof (ScriptUnloadedEventAttribute), ScriptEvent.Unloaded);
				}
				if (log.IsInfoEnabled)
					log.Info("Registering global event handlers: true");
			}
			catch (Exception e)
			{
				if (log.IsErrorEnabled)
					log.Error("StartScriptComponents", e);
				return false;
			}
			//---------------------------------------------------------------
			return true;
		}
Beispiel #2
0
		/// <summary>
		/// Stops the server, disconnects all clients, and writes the database to disk
		/// </summary>
		public override void Stop()
		{
			//Stop new clients from logging in
			m_status = eGameServerStatus.GSS_Closed;

			log.Info("GameServer.Stop() - enter method");

			if (log.IsWarnEnabled)
			{
				string stacks = PacketProcessor.GetConnectionThreadpoolStacks();
				if (stacks.Length > 0)
				{
					log.Warn("Packet processor thread stacks:");
					log.Warn(stacks);
				}
			}

			//Notify our scripthandlers
			GameEventMgr.Notify(ScriptEvent.Unloaded);

			//Notify of the global server stop event
			//We notify before we shutdown the database
			//so that event handlers can use the datbase too
			GameEventMgr.Notify(GameServerEvent.Stopped, this);
			GameEventMgr.RemoveAllHandlers(true);

			//Stop the World Save timer
			if (m_timer != null)
			{
				m_timer.Change(Timeout.Infinite, Timeout.Infinite);
				m_timer.Dispose();
				m_timer = null;
			}

			//Stop the base server
			base.Stop();

			//Close the UDP connection
			if (m_udpListen != null)
			{
				m_udpListen.Close();
				m_udpListen = null;
			}
			if (m_udpOutSocket != null)
			{
				m_udpOutSocket.Close();
				m_udpOutSocket = null;
			}

			//Stop all mobMgrs
			WorldMgr.StopRegionMgrs();

			//unload all weatherMgr
			WeatherMgr.Unload();

			//Stop the WorldMgr, save all players
			//WorldMgr.SaveToDatabase();
			SaveTimerProc(null);

			WorldMgr.Exit();


			//Save the database
			// 2008-01-29 Kakuri - Obsolete
			/*if ( m_database != null )
				{
					m_database.WriteDatabaseTables();
				}*/

			m_serverRules = null;

			Thread.CurrentThread.Priority = ThreadPriority.BelowNormal;

			if (log.IsInfoEnabled)
				log.Info("Server Stopped");

			LogManager.Shutdown();
		}
Beispiel #3
0
        /// <summary>
        /// Create server rules handler for specified server type
        /// </summary>
        /// <param name="serverType">server type used to look for rules handler</param>
        /// <returns>server rules handler or normal server type handler if errors</returns>
        public static IServerRules CreateServerRules(eGameServerType serverType)
        {
            Type rules = null;

            // first search in scripts
            foreach (Assembly script in Scripts)
            {
                foreach (Type type in script.GetTypes())
                {
                    if (type.IsClass == false)
                    {
                        continue;
                    }
                    if (type.GetInterface("DOL.GS.ServerRules.IServerRules") == null)
                    {
                        continue;
                    }

                    // look for attribute
                    try
                    {
                        object[] objs = type.GetCustomAttributes(typeof(ServerRulesAttribute), false);
                        if (objs.Length == 0)
                        {
                            continue;
                        }

                        foreach (ServerRulesAttribute attrib in objs)
                        {
                            if (attrib.ServerType == serverType)
                            {
                                rules = type;
                                break;
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        if (log.IsErrorEnabled)
                        {
                            log.Error("CreateServerRules", e);
                        }
                    }
                    if (rules != null)
                    {
                        break;
                    }
                }
            }

            if (rules == null)
            {
                // second search in gameserver
                foreach (Type type in Assembly.GetAssembly(typeof(GameServer)).GetTypes())
                {
                    if (type.IsClass == false)
                    {
                        continue;
                    }
                    if (type.GetInterface("DOL.GS.ServerRules.IServerRules") == null)
                    {
                        continue;
                    }

                    // look for attribute
                    try
                    {
                        object[] objs = type.GetCustomAttributes(typeof(ServerRulesAttribute), false);
                        if (objs.Length == 0)
                        {
                            continue;
                        }

                        foreach (ServerRulesAttribute attrib in objs)
                        {
                            if (attrib.ServerType == serverType)
                            {
                                rules = type;
                                break;
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        if (log.IsErrorEnabled)
                        {
                            log.Error("CreateServerRules", e);
                        }
                    }
                    if (rules != null)
                    {
                        break;
                    }
                }
            }

            if (rules != null)
            {
                try
                {
                    IServerRules rls = (IServerRules)Activator.CreateInstance(rules, null);
                    if (log.IsInfoEnabled)
                    {
                        log.Info("Found server rules for " + serverType + " server type (" + rls.RulesDescription() + ").");
                    }
                    return(rls);
                }
                catch (Exception e)
                {
                    if (log.IsErrorEnabled)
                    {
                        log.Error("CreateServerRules", e);
                    }
                }
            }
            if (log.IsWarnEnabled)
            {
                log.Warn("Rules for " + serverType + " server type not found, using \"normal\" server type rules.");
            }
            return(new NormalServerRules());
        }