midspace / Space-Engineers-Admin-script-mod

Modding script for Space Engineers with dozens of Admin commands for creating game scenarios or supporting servers.
44 stars 13 forks source link

/collectobjects crashes the server #132

Closed Spcemarine closed 9 years ago

Spcemarine commented 9 years ago

/collectobjects throws an exception on servers and crashes it:

Exception occured: System.NullReferenceException: Object reference not set to an instance of an object.
   at midspace.adminscripts.ConnectionHelper.SendMessageToAll(MessageBase message)
   at midspace.adminscripts.CommandObjectsCollect.<>c__DisplayClass7.<CollectObjects>b__2()
   at Sandbox.MySandboxGame.ProcessInvoke()
   at Sandbox.MySandboxGame.Update()
   at Sandbox.Engine.Platform.Game.UpdateInternal()
   at Sandbox.Engine.Platform.FixedLoop.<>c__DisplayClass2.<Run>b__1()
   at Sandbox.Engine.Platform.GenericLoop.Run(VoidAction tickCallback)
   at Sandbox.Engine.Platform.Game.RunLoop()
   at Sandbox.MySandboxGame.Run(Boolean customRenderLoop, Action disposeSplashScreen)
   at VRage.Dedicated.DedicatedServer.RunInternal()
   at VRage.Dedicated.DedicatedServer.RunMain(String instanceName, String customPath, Boolean isService, Boolean showConsole)
   at VRage.Dedicated.DedicatedServer.ProcessArgs(String[] args)
   at VRage.Dedicated.DedicatedServer.Run[T](String[] args)
   at SpaceEngineersDedicated.MyProgram.Main(String[] args)
CheeseJedi commented 9 years ago

I can confirm this. Just crashed my DS twice in a row :/

2015-11-20 00:12:55.801 - Thread:   1 ->  Exception occured: System.NullReferenceException: Object reference not set to an instance of an object.
   at midspace.adminscripts.ConnectionHelper.SendMessageToAll(MessageBase message)
   at midspace.adminscripts.CommandObjectsCollect.<>c__DisplayClass7.<CollectObjects>b__2()
   at Sandbox.MySandboxGame.ProcessInvoke()
   at Sandbox.MySandboxGame.Update()
   at Sandbox.Engine.Platform.Game.UpdateInternal()
   at Sandbox.Engine.Platform.FixedLoop.<>c__DisplayClass2.<Run>b__1()
   at Sandbox.Engine.Platform.GenericLoop.Run(VoidAction tickCallback)
   at Sandbox.Engine.Platform.Game.RunLoop()
   at Sandbox.MySandboxGame.Run(Boolean customRenderLoop, Action disposeSplashScreen)
   at VRage.Dedicated.DedicatedServer.RunInternal()
   at VRage.Dedicated.DedicatedServer.RunMain(String instanceName, String customPath, Boolean isService, Boolean showConsole)
   at VRage.Dedicated.DedicatedServer.ProcessArgs(String[] args)
   at VRage.Dedicated.DedicatedServer.Run[T](String[] args)
   at SpaceEngineersDedicated.MyProgram.Main(String[] args)
midspace commented 9 years ago

I can try and patch it, but I can't test it currently.

Need to change SendMessageToAll to ignore Player if it's not defined, and force message to servers even if is the server.

public static void SendMessageToAll(MessageBase message, bool syncAll = true)
        {
            if (MyAPIGateway.Session.Player != null)
                message.SenderSteamId = MyAPIGateway.Session.Player.SteamUserId;

            if (!MyAPIGateway.Multiplayer.IsServer || syncAll)
                SendMessageToServer(message);
            SendMessageToAllPlayers(message);
        }