Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[1.11.2 - SOLVED] Networking issues


Franckyi
 Share

Recommended Posts

Hi !

I'm using SimpleImpl to send data from the server to the client.

I have to send 2 different messages (in fact, the same message containing different informations) approximatively at the same time to all players.

But players receive two times the same message.

If I pause the server thread after the first message is sent, both messages are correctly received. So I conclude that there's not enough time between the moments where messages are sent.
Do you know how can I fix that ?

Edited by Franckyi
Link to comment
Share on other sites

My source code is available here : https://github.com/Franckyi/Wireless-Switch-Control/tree/1.11.2-update-networking

Network issues are occuring at blocks.BlockRedstoneSwitch::breakBlock and blocks.BlockRedstoneController::breakBlock.

In both cases, I'm sending messages to all players in a loop. But, for example, if I send 1, then 2, then 3; I'll recieve 3, 3, 3.

Edited by Franckyi
Link to comment
Share on other sites

One solution could be to change the message to send a set of data instead of only one data per message. If someone has a better solution, please tell me.

And also, that's strange that I can't send two messages in a too short period of time.

[EDIT] My solution works.

Edited by Franckyi
Link to comment
Share on other sites

I haven't really checked if it was correct or not, but with my new message it works.

How do I send a message to the players tracking the chunk ?

And also, if player 1 goes far away (not tracking the chunk), then player 2 updates the block, then player 1 comes back, is the data sent automatically to player 1 when he loads the chunk ? Or I have to detect and send the data to the client ?

 

Edited by Franckyi
Link to comment
Share on other sites

1 hour ago, Franckyi said:

How do I send a message to the players tracking the chunk ?

WorldServer::getPlayerChunkMap().getEntry(chunkX, chunkZ).players

 

1 hour ago, Franckyi said:

And also, if player 1 goes far away (not tracking the chunk), then player 2 updates the block, then player 1 comes back, is the data sent automatically to player 1 when he loads the chunk ? Or I have to detect and send the data to the client ?

You would need to use ChunkWatchEvent to detect this.

Edited by diesieben07
Link to comment
Share on other sites

Thanks !
So this should work ?


BlockRedstoneController::breakBlock (everything is called server side)

WorldServer worldServer = (WorldServer) world;
for (EntityPlayer player : worldServer.playerEntities) {
	EntityPlayerMP playerMP = (EntityPlayerMP) player;
	if (worldServer.getPlayerChunkMap() {
		.getEntry(world.getChunkFromBlockCoords(pos).x, world.getChunkFromBlockCoords(pos).z)
		.containsPlayer(playerMP))
			PacketHandler.INSTANCE.sendTo(new UpdateRedstoneControllerMessage(updateControllers), playerMP);
    }
}

(and the same for BlockRedstoneSwitch)

 

EventHandler (I don't know if this event is fired on the server, on client or on both)

@SubscribeEvent
public void onChunkWatch(ChunkWatchEvent.Watch event) {
	WorldServer world = event.getPlayer().getServerWorld();
	if (!world.isRemote) {
		for (TileEntity te : world.loadedTileEntityList) {
			if (event.getChunk().equals(world.getChunkFromBlockCoords(te.getPos()).getPos())) {
				if (te instanceof TileEntityRedstoneSwitch) {
					PacketHandler.INSTANCE.sendTo(new UpdateRedstoneSwitchMessage(te.getPos(),
							te.getCapability(RedstoneSwitchProvider.SWITCH_CAP, null).getSwitch()), event.getPlayer());
				} else if (te instanceof TileEntityRedstoneController) {
					PacketHandler.INSTANCE.sendTo(new UpdateRedstoneControllerMessage(te.getPos(),
							te.getCapability(RedstoneControllerProvider.CONTROLLER_CAP, null).getController()), event.getPlayer());
				}
			}
		}
	}
}

 

 

 

Edited by Franckyi
Link to comment
Share on other sites

Okay so everything seems to be fine. But I have another problem also linked to networking : my mod can't run on the server.

Crash Report

It fails when it registers a message that is handled on the client side. But I must register it on both sides anyway, right ?

I really don't know where does it try to load the WorldClient class.

Is it linked to my special PacketHandler class ?

 

public class PacketHandler {

	public static abstract class ClientHandler<REQ extends IMessage> extends CommonHandler<REQ> {

		@Override
		public IMessage onMessage(REQ message, MessageContext ctx) {
			super.onMessage(message, ctx);
			this.world = Minecraft.getMinecraft().world;
			this.mainThread = Minecraft.getMinecraft();
			this.mainThread.addScheduledTask(this);
			return null;
		}

	}

	public static abstract class CommonHandler<REQ extends IMessage>
			implements IMessageHandler<REQ, IMessage>, Runnable {

		protected World world;
		protected IThreadListener mainThread;
		protected REQ message;
		protected MessageContext ctx;

		@Override
		public IMessage onMessage(REQ message, MessageContext ctx) {
			this.message = message;
			this.ctx = ctx;
			return null;
		}

	}

	public static abstract class ServerHandler<REQ extends IMessage> extends CommonHandler<REQ> {

		@Override
		public IMessage onMessage(REQ message, MessageContext ctx) {
			super.onMessage(message, ctx);
			this.world = ctx.getServerHandler().player.world;
			this.mainThread = (WorldServer) this.world;
			this.mainThread.addScheduledTask(this);
			return null;
		}

	}

	public static final SimpleNetworkWrapper INSTANCE = NetworkRegistry.INSTANCE.newSimpleChannel(ModReference.MODID);

}

 

Client-side Message Handlers extends PacketHandler.ClientHandler whereas Server-side Message Handlers extends PacketHandler.ServerHandler.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • I do not know how to check the sites certificate on my phone
    • Oh ok, thank you. Should I uninstall java 17 and get java 8, or have both?
    • I have installed a forge server, and tried launching it. It launches as a vanilla server if I run the file called "minecraft_server.1.16.5.jar" If i run the file called "forge-1.16.5-36.2.23.jar", nothing at all happens, it just creates a log with these 2 lines: [19Jan2022 16:08:29.340] [main/INFO] [cpw.mods.modlauncher.Launcher/MODLAUNCHER]: ModLauncher running: args [--gameDir, ., --launchTarget, fmlserver, --fml.forgeVersion, 36.2.23, --fml.mcpVersion, 20210115.111550, --fml.mcVersion, 1.16.5, --fml.forgeGroup, net.minecraftforge] [19Jan2022 16:08:29.345] [main/INFO] [cpw.mods.modlauncher.Launcher/MODLAUNCHER]: ModLauncher 8.0.9+86+master.3cf110c starting: java version 17.0.1 by Oracle Corporation I have also tried running both files (since I don't know which one I'm supposed to use) using the command line like this: java -Xmx6000M -Xms6000M -jar {serverName}.jar nogui pause If I run the the server file, i get a vanilla server as well. If i run the forge file, the log file looks the same as before, and I get this result in the terminal: D:\MCS\VH>java -Xmx6000M -Xms6000M -jar forge-1.16.5-36.2.23.jar nogui 2022-01-19 16:16:32,476 main WARN Advanced terminal features are not available in this environment [16:16:32] [main/INFO] [cp.mo.mo.Launcher/MODLAUNCHER]: ModLauncher running: args [--gameDir, ., --launchTarget, fmlserver, --fml.forgeVersion, 36.2.23, --fml.mcpVersion, 20210115.111550, --fml.mcVersion, 1.16.5, --fml.forgeGroup, net.minecraftforge, nogui] [16:16:32] [main/INFO] [cp.mo.mo.Launcher/MODLAUNCHER]: ModLauncher 8.0.9+86+master.3cf110c starting: java version 17.0.1 by Oracle Corporation Exception in thread "main" java.lang.IllegalAccessError: class cpw.mods.modlauncher.SecureJarHandler (in unnamed module @0xadd0edd) cannot access class sun.security.util.ManifestEntryVerifier (in module java.base) because module java.base does not export sun.security.util to unnamed module @0xadd0edd at cpw.mods.modlauncher.SecureJarHandler.lambda$static$1(SecureJarHandler.java:41) at cpw.mods.modlauncher.api.LamdbaExceptionUtils.uncheck(LamdbaExceptionUtils.java:95) at cpw.mods.modlauncher.SecureJarHandler.<clinit>(SecureJarHandler.java:41) at cpw.mods.modlauncher.Launcher.lambda$new$6(Launcher.java:55) at java.base/java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1708) at cpw.mods.modlauncher.api.TypesafeMap.computeIfAbsent(TypesafeMap.java:52) at cpw.mods.modlauncher.api.TypesafeMap.computeIfAbsent(TypesafeMap.java:47) at cpw.mods.modlauncher.Environment.computePropertyIfAbsent(Environment.java:62) at cpw.mods.modlauncher.Launcher.<init>(Launcher.java:55) at cpw.mods.modlauncher.Launcher.main(Launcher.java:66) at net.minecraftforge.server.ServerMain$Runner.runLauncher(ServerMain.java:63) at net.minecraftforge.server.ServerMain$Runner.access$100(ServerMain.java:60) at net.minecraftforge.server.ServerMain.main(ServerMain.java:57) D:\MCS\VH>pause Press any key to continue . . . I have also tried launching old servers that I had on SkyFactory 3 that worked fine before, but they have stopped working too. When I launch them I get this result: Starting Sky Factory 3 Server... A problem occurred running the Server launcher.java.lang.reflect.InvocationTargetException at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:568) at net.minecraftforge.fml.relauncher.ServerLaunchWrapper.run(ServerLaunchWrapper.java:62) at net.minecraftforge.fml.relauncher.ServerLaunchWrapper.main(ServerLaunchWrapper.java:31) Caused by: java.lang.ClassCastException: class jdk.internal.loader.ClassLoaders$AppClassLoader cannot be cast to class java.net.URLClassLoader (jdk.internal.loader.ClassLoaders$AppClassLoader and java.net.URLClassLoader are in module java.base of loader 'bootstrap') at net.minecraft.launchwrapper.Launch.<init>(Launch.java:34) at net.minecraft.launchwrapper.Launch.main(Launch.java:28) ... 6 more Press any key to continue . . . I assume this means that something has changed on my pc, causing forge servers not to run correctly, but I cannot imagine what that could be. I hope this is enough information to be able to help
    • Check it out, you won't regret https://shrinke.me/I0iwHJ3
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.