Jump to content

[1.11.2 - SOLVED] Networking issues


Franckyi

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

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
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
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.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.