예제 #1
0
        /// <summary>
        /// The callback from Terraria.Netplay.Initialize
        /// </summary>
        public static bool Initialise()
        {
            #if Full_API
            if (Terraria.Main.dedServ)
            {
                var ctx = new HookContext()
                {
                    Sender = HookContext.ConsoleSender
                };
                var args = new HookArgs.ServerStateChange()
                {
                    ServerChangeState = ServerState.Starting
                };
                HookPoints.ServerStateChange.Invoke(ref ctx, ref args);

                return ctx.Result != HookResult.IGNORE;
            }
            #endif

            return true; //Allow continue
        }
        /// <summary>
        /// The call from the end of Terraria.WorldFile.loadWorld
        /// </summary>
        public static void WorldLoadEnd()
        {
            //Since this is hook is at the end of the world loading then we can clear the new progress loading
            #if Full_API
            Terraria.Main.statusText = String.Empty;
            #endif

            var ctx = new HookContext()
            {
                Sender = HookContext.ConsoleSender
            };
            var args = new HookArgs.ServerStateChange()
            {
                ServerChangeState = (Globals.CurrentState = ServerState.WorldLoaded)
            };
            HookPoints.ServerStateChange.Invoke(ref ctx, ref args);
        }
        /// <summary>
        /// The call from the start of Terraria.WorldGen.generateWorld
        /// </summary>
        public static void WorldGenerateBegin()
        {
            MainCallback.ResetTileArray(8400, 2400); //You make me sad Terraria.WorldGen

            #if Full_API
            Terraria.Main.statusText = String.Empty;
            #endif

            var ctx = new HookContext()
            {
                Sender = HookContext.ConsoleSender
            };
            var args = new HookArgs.ServerStateChange()
            {
                ServerChangeState = (Globals.CurrentState = ServerState.WorldGenerating)
            };
            HookPoints.ServerStateChange.Invoke(ref ctx, ref args);
        }
        /// <summary>
        /// The callback from vanilla code to start shutting down
        /// </summary>
        public static void OnProgramFinished()
        {
            while (NAT.ShuttingDown)
            {
                System.Threading.Thread.Sleep(50);
            }

            var ctx = new HookContext()
            {
                Sender = HookContext.ConsoleSender
            };
            var args = new HookArgs.ServerStateChange()
            {
                ServerChangeState = (Globals.CurrentState = ServerState.Stopping)
            };
            HookPoints.ServerStateChange.Invoke(ref ctx, ref args);

            PluginManager.DisablePlugins();

            //Close the logging if set
            ProgramLog.Close();
            //            if (Tools.WriteClose != null)
            //                Tools.WriteClose.Invoke();
        }
 /// <summary>
 /// The call from the XNA Game initialise
 /// </summary>
 /// <remarks>This could have been in the XNA shims, but the client uses FNA/XNA and if our client is to work they require CIL modifications</remarks>
 public static void Initialise()
 {
     #if Full_API
     if (Terraria.Main.dedServ)
     {
         var ctx = new HookContext()
         {
             Sender = HookContext.ConsoleSender
         };
         var args = new HookArgs.ServerStateChange()
         {
             ServerChangeState = (Globals.CurrentState = ServerState.Initialising)
         };
         HookPoints.ServerStateChange.Invoke(ref ctx, ref args);
     }
     #endif
 }
예제 #6
0
        /// <summary>
        /// When vanilla requests to start the server, this method is called.
        /// </summary>
        /// <param name="state">State.</param>
        public static void StartServer(object state)
        {
            #if Full_API
            var ctx = new HookContext()
            {
                Sender = HookContext.ConsoleSender
            };
            var args = new HookArgs.ServerStateChange()
            {
                ServerChangeState = (Globals.CurrentState = ServerState.Starting)
            };
            HookPoints.ServerStateChange.Invoke(ref ctx, ref args);

            if (ctx.Result != HookResult.IGNORE)
            {
                ProgramLog.Console.Print("Starting server...");
                ThreadPool.QueueUserWorkItem(new WaitCallback(Terraria.Netplay.ServerLoop), 1);
                ProgramLog.Console.Print("Ok");
            }
            #endif
        }