Jump to content

problems with server/client communication


Torojima

Recommended Posts

I have a IPacketHandler responsible for receiving packets from server to client and the other way round (thus only one packet handler and not two).

 

The packets I'm using are Packet250CustomPayload packets. First entry is a custom packet id so the packet handler can recognise what to do with them.

 

Now since the last update all routines working by sending packets from the client to the server do not work any more, while all routines working by sending packets form the server to the clients are working fine.

 

I have no idea where to look for clues how to fix this. Does anybody have any pointers for me where I can start looking for faults?

 

ChocoboPacketHandler.java

 

// <copyright file="ChocoboPacketHandler.java">
// Copyright (c) 2012 All Right Reserved, http://chococraft.arno-saxena.de/
//
// THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY 
// KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// </copyright>
// <author>Arno Saxena</author>
// <email>[email protected]</email>
// <date>2012-10-25</date>
// <summary>receiving and distributing network communication packets intended for the ChocoCraft mod.</summary>

package chococraft.common.network;

import java.io.ByteArrayInputStream;
import java.io.DataInputStream;

import chococraft.debugger.DebugFileWriter;

import net.minecraft.src.INetworkManager;
import net.minecraft.src.Packet250CustomPayload;
import cpw.mods.fml.common.network.IPacketHandler;
import cpw.mods.fml.common.network.Player;

public class ChocoboPacketHandler implements IPacketHandler
{    
public ChocoboPacketHandler()
{
}

@Override
public void onPacketData(INetworkManager manager, Packet250CustomPayload packet, Player player)
{

	DataInputStream data = new DataInputStream(new ByteArrayInputStream(packet.data));
	try {
		int packetId = data.readInt();

		DebugFileWriter.instance().writeLine("ChPaHa", "received packet: " + packetId);

		if(packetId == PacketChocobo.PID_HEALTH)
		{
			PacketChocoboHealth.handleUpdate(data, player);
		}
		else if(packetId == PacketChocobo.PID_MOUNT)
		{
			PacketChocoboMount.handleUpdate(data, player);
		}
		else if(packetId == PacketChocobo.PID_TAMED)
		{
			PacketChocoboTamed.handleUpdate(data, player);
		}
		else if(packetId == PacketChocobo.PID_ATTRIBUTE)
		{
			PacketChocoboAttribute.handleUpdate(data, player);
		}
		else if(packetId == PacketChocobo.PID_RIDERJUMP)
		{
			PacketChocoboRiderJump.handleUpdate(data, player);
		}
		else if(packetId == PacketChocobo.PID_DROPSADDLE)
		{
			PacketChocoboDropGear.handleUpdate(data, player);
		}
		else if(packetId == PacketChocobo.PID_CHIGROWUP)
		{
			PacketChicoboCanGrowUp.handleUpdate(data, player);
		}
	}
	catch (Exception ex)
	{
		ex.printStackTrace();
	}
}
}

 

 

abstract PacketChocobo.java

 

// <copyright file="PacketChocobo.java">
// Copyright (c) 2012 All Right Reserved, http://chococraft.arno-saxena.de/
//
// THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY 
// KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// </copyright>
// <author>Arno Saxena</author>
// <email>[email protected]</email>
// <date>2012-10-25</date>
// <summary>abstract class for all ChocoCraft wrapper network packets</summary>

package chococraft.common.network;

import chococraft.common.Constants;
import net.minecraft.src.Packet250CustomPayload;

public abstract class PacketChocobo
{
public static int PID_ATTRIBUTE  = 0;
public static int PID_DROPSADDLE = 1;
public static int PID_HEALTH     = 2;
public static int PID_MOUNT      = 3;
public static int PID_RIDERJUMP  = 4;
public static int PID_TAMED      = 5;
public static int PID_CHIGROWUP  = 6;

protected Packet250CustomPayload packet = null;

public PacketChocobo()
{
	this.packet = new Packet250CustomPayload();
	this.packet.channel = Constants.PCHAN_CHOCOBO;
}

public Packet250CustomPayload getPacket()
{
	return this.packet;
}
}

 

 

example concrete PacketChocobo class PacketChocoboAttribute.java

 

// <copyright file="PacketChocoboAttribute.java">
// Copyright (c) 2012 All Right Reserved, http://chococraft.arno-saxena.de/
//
// THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY 
// KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// </copyright>
// <author>Arno Saxena</author>
// <email>[email protected]</email>
// <date>2012-10-25</date>
// <summary>Network Packet wrapper for sending Chocobo Entity attribute information</summary>

package chococraft.common.network;

import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;

import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.Side;
import cpw.mods.fml.common.network.Player;

import chococraft.common.entities.EntityAnimalChocobo;
import chococraft.common.helper.ChocoboClientHelper;

public class PacketChocoboAttribute extends PacketChocobo
{
public PacketChocoboAttribute(EntityAnimalChocobo chocobo)
{
	super();
	ByteArrayOutputStream bos = new ByteArrayOutputStream(;
	DataOutputStream outputStream = new DataOutputStream(bos);
	try
	{
		outputStream.writeInt(PID_ATTRIBUTE);
		outputStream.writeInt(chocobo.entityId);
		outputStream.writeUTF(chocobo.getName());
		outputStream.writeBoolean(chocobo.isHidename());
		outputStream.writeBoolean(chocobo.isFollowing());
		outputStream.writeBoolean(chocobo.isWander());
		outputStream.writeInt(chocobo.worldObj.getWorldInfo().getDimension());
	}
	catch (Exception ex)
	{
		ex.printStackTrace();
	}		

	this.packet.data = bos.toByteArray();
	this.packet.length = bos.size();
}

public static void handleUpdate(DataInputStream inputStream, Player player)
{
	if (Side.SERVER == FMLCommonHandler.instance().getEffectiveSide())
	{
		try
		{
			int chocoboId = inputStream.readInt();
			String chocoboName = inputStream.readUTF();
			boolean hidename = inputStream.readBoolean();
			boolean following = inputStream.readBoolean();
			boolean wander = inputStream.readBoolean();
			int dimension = inputStream.readInt();
			EntityAnimalChocobo chocobo = ChocoboClientHelper.getChocoboByID(chocoboId, dimension);
			if(null != chocobo)
			{
				chocobo.setName(chocoboName);
				chocobo.setHidename(hidename);
				chocobo.setFollowing(following);
				chocobo.setWander(wander);
			}
		}
		catch(IOException e)
		{
			e.printStackTrace();
			return;
		}
	}
}
}

 

 

call of send method in entity class

 

protected void sendAttributeUpdate()
{
if (Side.CLIENT == FMLCommonHandler.instance().getEffectiveSide())
{
	PacketChocoboAttribute packet = new PacketChocoboAttribute(this);
	PacketDispatcher.sendPacketToServer(packet.getPacket());
}
}

 

running minecraft on Mac OS X - Sierra --- creating code since 1986 ... --- मेरा दिल भारतवासी है!

width=289 height=100http://www.arno-saxena.de/pictures/chococraft/banner_signature.png[/img]

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.