Jump to content

[1.7.2]Dedicated Server Crash[Solved{for now}]


hugo_the_dwarf

Recommended Posts

After working on my mod for almost a month now, using the client to test my changes and work. Anyways my mod is based around PvP so not only is it going to be a solo but a server mod. And running it with the dedicated server is giving me crashes for well client related items, The keybindings where a no brainer moved them into the clientProxy. Crash fixed, next one is crashing at my classResponsePacket because it can't find "EntityClientPlayerMP" and I'm not sure I can just move that into the client proxy because this is something the server needs to send to the player (keeps class values updated for the client to see)

 

 

package ca.grm.rot.comms;

import ca.grm.rot.libs.ExtendPlayer;
import io.netty.buffer.ByteBuf;
import net.minecraft.client.Minecraft;
import cpw.mods.fml.common.network.ByteBufUtils;
import cpw.mods.fml.common.network.simpleimpl.IMessage;
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
import cpw.mods.fml.common.network.simpleimpl.MessageContext;

public class ClassResponsePacket implements IMessage {

public static class ClassResponsePacketHandler implements IMessageHandler<ClassResponsePacket, IMessage> {

	@Override
	public IMessage onMessage(ClassResponsePacket message, MessageContext ctx) {
		System.out.println("got a response about changing to: " + message.className);
		ExtendPlayer.get(Minecraft.getMinecraft().thePlayer).setCurrentClass(
				message.className);
		return null;
	}

}

public String	className;

public ClassResponsePacket() {

}

public ClassResponsePacket(String className) {
	this.className = className;
}

@Override
public void fromBytes(ByteBuf buf) {
	this.className = ByteBufUtils.readUTF8String(buf); // this class is very
														// useful in general
														// for writing more
														// complex objects
}

@Override
public void toBytes(ByteBuf buf) {
	ByteBufUtils.writeUTF8String(buf, this.className);
}

}

 

 

I'm just understanding the proxies, and the packets I have only a limited grasp on. But enough I know how to use them, but that is not the question at hand. I want a dedicated server to run fine just like the client to (even the client server has no issues) but also work as intended.

 

Also here is my repo if there is code you need to see that I haven't posted https://github.com/GRM-Group/Rise-of-Tristram

 

PS. I have only been modding for the same time I started this mod, so if you see things done wrong or could be better, that is my excuse for it.

Link to comment
Share on other sites

You're using the Minecraft class, which is Client only. You need to move your code into your client proxy, so that on message method should like like

 

public IMessage onMessage(SomeMessage message, MessageContext ctx)
{
    return MainMod.proxy.handleSomeMessage(message, ctx);
}

 

And then you create that method in client and server proxy, and just return null and do nothing on the server.

 

Even though the message is sent from the server and only handled on the client, the server still needs to know about this class.

BEFORE ASKING FOR HELP READ THE EAQ!

 

I'll help if I can. Apologies if I do something obviously stupid. :D

 

If you don't know basic Java yet, go and follow these tutorials.

Link to comment
Share on other sites

Ok so that helped that out, Also had to move my FML bus instance into my proxy for keybindings, and it runs (yay) but has some errors when I log in (also had to find where it made my server, good thing it outputs that in the console, to make it offline)

 

But I get this error when I join [spoiler=Stopped my copy paste at where my mod showed up]

java.lang.RuntimeException: Missing

at cpw.mods.fml.server.FMLServerHandler.getClientToServerNetworkManager(FMLServerHandler.java:238) ~[FMLServerHandler.class:?]

at cpw.mods.fml.common.FMLCommonHandler.getClientToServerNetworkManager(FMLCommonHandler.java:529) ~[FMLCommonHandler.class:?]

at cpw.mods.fml.common.network.FMLOutboundHandler$OutboundTarget$8.selectNetworks(FMLOutboundHandler.java:225) ~[FMLOutboundHandler$OutboundTarget$8.class:?]

at cpw.mods.fml.common.network.FMLOutboundHandler.write(FMLOutboundHandler.java:273) ~[FMLOutboundHandler.class:?]

at io.netty.channel.DefaultChannelHandlerContext.invokeWrite(DefaultChannelHandlerContext.java:644) ~[DefaultChannelHandlerContext.class:?]

at io.netty.channel.DefaultChannelHandlerContext.write(DefaultChannelHandlerContext.java:698) ~[DefaultChannelHandlerContext.class:?]

at io.netty.channel.DefaultChannelHandlerContext.write(DefaultChannelHandlerContext.java:637) ~[DefaultChannelHandlerContext.class:?]

at io.netty.handler.codec.MessageToMessageEncoder.write(MessageToMessageEncoder.java:115) ~[MessageToMessageEncoder.class:?]

at io.netty.handler.codec.MessageToMessageCodec.write(MessageToMessageCodec.java:116) ~[MessageToMessageCodec.class:?]

at io.netty.channel.DefaultChannelHandlerContext.invokeWrite(DefaultChannelHandlerContext.java:644) ~[DefaultChannelHandlerContext.class:?]

at io.netty.channel.DefaultChannelHandlerContext.write(DefaultChannelHandlerContext.java:698) ~[DefaultChannelHandlerContext.class:?]

at io.netty.channel.DefaultChannelHandlerContext.writeAndFlush(DefaultChannelHandlerContext.java:688) ~[DefaultChannelHandlerContext.class:?]

at io.netty.channel.DefaultChannelHandlerContext.writeAndFlush(DefaultChannelHandlerContext.java:717) ~[DefaultChannelHandlerContext.class:?]

at io.netty.channel.DefaultChannelPipeline.writeAndFlush(DefaultChannelPipeline.java:893) ~[DefaultChannelPipeline.class:?]

at io.netty.channel.AbstractChannel.writeAndFlush(AbstractChannel.java:239) ~[AbstractChannel.class:?]

at cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper.sendToServer(SimpleNetworkWrapper.java:207) [simpleNetworkWrapper.class:?]

at ca.grm.rot.events.RotEventHandler.onPlayerJoin(RotEventHandler.java:339) [RotEventHandler.class:?]

 

 

[spoiler=Code snippet that that line]

@SubscribeEvent
public void onPlayerJoin(EntityJoinWorldEvent e) {
	if (e.entity instanceof EntityPlayer) {
		Rot.net.sendToServer(new ClassRequestPacket("whatAmI"));
	}
}

 

 

It still worked despite these errors so I tryied changing my class and got a crash on the playerTick event at this line of code:

player.capabilities.setPlayerWalkSpeed(MathHelper.clamp_float(
					0.1F + ((float) props.getAgility() / 142), 0.04f, 0.3f));

The mod lets you move faster or slower based on the agility stat, and the class I picked changes agility.

 

So do I need to move everything that has to do with a player to the clientProxy? Because I'm sure the server needs to know that the player can move faster.

Link to comment
Share on other sites

oh, that makes sense, since events run both server and client (probably wrong as fk with that assumption)

 

So should I more or less have that event get the properties from the player and just send a reponsePacket? Not player send request to server, get response.

 

If so I think sendTo takes EntityPlayerMP and I'm not sure how I get that to use, I think that is why I have the event send the request and response back.

 

But in this case it's "EntityJoinWorldEvent" and I check to see if it is the player... My understanding of this is limited.

 

But at least I know it's server to server that is causing the exception. (Talking to yourself normally causes problems)

 

EDIT:

for the crash this is the error I believe "Caused by: java.lang.NoSuchMethodError: net.minecraft.entity.player.PlayerCapabilities.setPlayerWalkSpeed(F)V"

 

EDIT2:

Also may I request a link to a good or a few good Proxy tutorials, seems like I should get a better understanding of them and when to use them.

Link to comment
Share on other sites

1. Alright, so I guess will have to read each event carefully when I'm using them just to see where each one is called (one side or both)

 

2. I noticed that even when I use NBT to save and load Extended Properties when a client connects all their stuff (except data Watched values) are all reset to the defaults. So I used the "EntityJoinWorldEvent " to have the server update the clients info so both server and client data is sync'd. So I guess really I could have just said "To Sync server and client data"

 

3. Linked to number 2. But still good to know, thank you.

 

4. *facepalm* guess if I hovered over it eclipse could have told me that, as for reflection I'm not that advanced with Java to understand it or use it (have read other topics on here about people using it or being told to use it) so I guess I am stuck with adding speed/slow potion effects? which kinda sucks I liked the setWalkSpeed did what I wanted it to do. Guess will have to scrap Agility stat. (due to lack of understanding and experience)

 

5.Thanks that is a pretty good explanation. Clears up the use there.

 

So I guess the only thing that still needs answering atm is 2. (3 is kind of a child of 2)

How do I properly keep the client sync'd with the server.

Link to comment
Share on other sites

Ok so googled reflection and had a look at it, it does seem rather easy, never used it yet but I get the idea of it and how to use it. I will give it a try, so what do you suggest I do? I'm also looking up how to get and set private fields. So would I simply get Field playerWalkSpeed = capabilities.class.getDeclaredField(walkSpeed)?

 

Probably when I finish reading up on this I'll know how to do it. But is that what I do? use reflection to set the walkSpeed manually because the method is clientonly?

 

As for the syncing would I just check "if (entity instanceof EntityPlayer){

if (!entity.getWorld.isRemote){

EntityPlayerMP player = (EntityPlayerMP)((EntityPlayer)entity);

//Get Values

sendTo(responsePacket(values),player);

}

}

 

Thanks for the help btw, and sorry if this feels like I'm asking for all the help to make this. I really just want to understand the correct way of doing this.

Link to comment
Share on other sites

Alright so following this tutorial http://docs.oracle.com/javase/tutorial/reflect/member/fieldValues.html and I go this code:

if (props.getAgility() != (agiMod - props.getClassModifers()[1])) {
			props.setAgility(agiMod);
			//ExtendPlayer.get(player).updateMoveSpeed();
			/*player.capabilities.setPlayerWalkSpeed(MathHelper.clamp_float(
					0.1F + ((float) props.getAgility() / 142), 0.04f, 0.3f));*/
			Class<?> pc = player.capabilities.getClass();
			try {
			Field walkSpeed = pc.getDeclaredField("walkSpeed");
			walkSpeed.setAccessible(true);

				walkSpeed.set(pc, 6.6f);
			} catch (IllegalArgumentException | IllegalAccessException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (NoSuchFieldException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (SecurityException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}

 

I literally have no idea what I'm doing but this snippet is in my livingUpdateEvent, and works with:

player.capabilities.setPlayerWalkSpeed(MathHelper.clamp_float(0.1F + ((float) props.getAgility() / 142), 0.04f, 0.3f));

 

So I *think* I have the basic understanding on how to use reflection now, just how do I use it properly with MC?

Do I need to do some more sorcery?

 

EDIT:

We are not suppose to post vanilla code right? Would me posting my reflection code be violating this?

 

EDIT2:

Ok I forgot that my code only does any changes if something has changed. So added something that gave me more agi and it works.

So this won't effect *all* players just the one with more or less agility?

 

EDIT3:

yup each player has their own Move Speed, excellent, Also fixed the Server to Server packet sending issue. So no crashes. Thanks for all the help. I have a feeling more will pop up when I test my mod out more with the other features.

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • If you're seeking an unparalleled solution to recover lost or stolen cryptocurrency, let me introduce you to GearHead Engineers Solutions. Their exceptional team of cybersecurity experts doesn't just restore your funds; they restore your peace of mind. With a blend of cutting-edge technology and unparalleled expertise, GearHead Engineers swiftly navigates the intricate web of the digital underworld to reclaim what's rightfully yours. In your moment of distress, they become your steadfast allies, guiding you through the intricate process of recovery with transparency, trustworthiness, and unwavering professionalism. Their team of seasoned web developers and cyber specialists possesses the acumen to dissect the most sophisticated schemes, leaving no stone unturned in their quest for justice. They don't just stop at recovering your assets; they go the extra mile to identify and track down the perpetrators, ensuring they face the consequences of their deceitful actions. What sets  GearHead Engineers apart is not just their technical prowess, but their unwavering commitment to their clients. From the moment you reach out to them, you're met with compassion, understanding, and a resolute determination to right the wrongs inflicted upon you. It's not just about reclaiming lost funds; it's about restoring faith in the digital landscape and empowering individuals to reclaim control over their financial futures. If you find yourself ensnared in the clutches of cybercrime, don't despair. Reach out to GearHead Engineers and let them weave their magic. With their expertise by your side, you can turn the tide against adversity and emerge stronger than ever before. In the realm of cybersecurity, GearHead Engineers reigns supreme. Don't just take my word for it—experience their unparalleled excellence for yourself. Your journey to recovery starts here.
    • Ok so this specific code freezes the game on world creation. This is what gets me so confused, i get that it might not be the best thing, but is it really so generation heavy?
    • Wizard web recovery has exhibited unparalleled strength in the realm of recovery. They stand out as the premier team to collaborate with if you encounter withdrawal difficulties from the platform where you’ve invested. Recently, I engaged with them to recover over a million dollars trapped in an investment platform I’d been involved with for months. I furnished their team with every detail of the investment, including accounts, names, and wallet addresses to which I sent the funds. This decision proved to be the best I’ve made, especially after realizing the company had scammed me.   Wizard web recovery ensures exemplary service delivery and ensures the perpetrators face justice. They employ advanced techniques to ensure you regain access to your funds. Understandably, many individuals who have fallen victim to investment scams may still regret engaging in online services again due to the trauma of being scammed. However, I implore you to take action. Seek assistance from Wizard Web Recovery today and witness their remarkable capabilities. I am grateful that I resisted their enticements, and despite the time it took me to discover Wizard web recovery, they ultimately fulfilled my primary objective. Without wizard web recovery intervention, I would have remained despondent and perplexed indefinitely.
    • I've tested the same code on three different envionrments (Desktop win10, desktop Linux and Laptop Linux) and it kinda blows up all the same. Gonna try this code and see if i can tune it
    • Minecraft version? Mod loader?
  • Topics

×
×
  • Create New...

Important Information

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