jjohnsnaill / SubworldLibrary

Dimensions in Terraria, made easy.
44 stars 24 forks source link

Invalid operation at this state #12

Closed ThuverX closed 1 year ago

ThuverX commented 1 year ago

I've been trying to get this mod working with Stars Above (With limited C# and IL knowledge). One of the issues I was having was already described in #10. For the issue in the title I will try to describe the things I've observed:

Steps to recreate

  1. Start two game clients
  2. Have Stars Above and Subworld Library installed on both
  3. Start a server on one of the client, connect with the other.
  4. On the connected client (So not the host), go to a subworld
  5. Quickly after (And before the other is done), do the same on the host.

The host will be disconnected with the message: "Invalid operation at this state."

Things I've found myself

Again keep in mind, I have limited knowledge of Terraria modding, and C# for that matter. This message can only come from 3 different places, all of them located in Terraria.MessageBuffer.cs:

[107] if (Main.netMode == 2) {
[108]   if (Netplay.Clients[whoAmI].State < 10 && b > 12 && b != 93 && b != 16 && b != 42 && b != 50 && b != 38 && b != 68)
[109]     NetMessage.BootPlayer(whoAmI, Lang.mp[2].ToNetworkText());
[111] if (Netplay.Clients[whoAmI].State == 0 && b != 1)
[112]   NetMessage.BootPlayer(whoAmI, Lang.mp[2].ToNetworkText());
[3384] default:
[3385]   if (Netplay.Clients[whoAmI].State == 0)
[3386]     NetMessage.BootPlayer(whoAmI, Lang.mp[2].ToNetworkText());
[3387]   break;

(Lang.mp[2] being "Invalid operation at this state." (From Terraria.Lang.cs:330))

A part of the server.log (With my own logging for every function in Subworld Library, might not be relevant)

[20:42:55.466] [Main Thread/WARN] [SubworldLibrary]: static bool LoadIntoSubworld()
[20:42:55.477] [Main Thread/WARN] [SubworldLibrary]: static void LoadWorld()
[20:42:55.478] [Main Thread/WARN] [SubworldLibrary]: static void LoadSubworld(string path, bool cloud)
[20:42:55.495] [Main Thread/WARN] [SubworldLibrary]: static void ReadCopiedMainWorldData()
[20:42:55.498] [Main Thread/WARN] [SubworldLibrary]: static void ReadCopiedDowned()
[20:42:56.601] [23/WARN] [SubworldLibrary]: static void SubserverCallBack(object pipeObject)
[20:42:56.779] [Main Thread/INFO] [Terraria]: 0.0.0.0:0 was booted: Invalid operation at this state.

Now I don't know if its just as easy as "don't try to start another server when one is already starting" or that changing the client.State is causing the issue.

Anyway I hope this helps, and this issue can be fixed!

jjohnsnaill commented 1 year ago

The initiative is appreciated! This is happening because packets are being sent to and/or received by the subserver out of order, for reasons that I hope aren't out of SubLib's control.

jjohnsnaill commented 1 year ago

Presumably fixed in 2.2.0.1. Please reopen the issue if this isn't the case.