Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Sorry I'm invading Buildism to ask this but...
#1
I really need help on understanding why this code will not work...

Code:
package org.opencraft.server.net.packet.handler.impl;

/*
* OpenCraft License
*
* Copyright (c) 2009 Graham Edgecombe, S�ren Enevoldsen and Brett Russell.
* All rights reserved.
*
* Distribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
*     * Distributions of source code must retain the above copyright notice,
*       this list of conditions and the following disclaimer.
*      
*     * Distributions in binary form must reproduce the above copyright
*       notice, this list of conditions and the following disclaimer in the
*       documentation and/or other materials provided with the distribution.
*      
*     * Neither the name of the OpenCraft nor the names of its
*       contributors may be used to endorse or promote products derived from
*       this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/

import org.opencraft.server.game.impl.CTFGameMode;
import org.opencraft.server.model.Player;
import org.opencraft.server.model.PlayerUntagger;
import org.opencraft.server.model.Position;
import org.opencraft.server.model.Rotation;
import org.opencraft.server.model.World;
import org.opencraft.server.net.MinecraftSession;
import org.opencraft.server.net.packet.Packet;
import org.opencraft.server.net.packet.handler.PacketHandler;

/**
* A packet handler which handles movement packets.
* @author Graham Edgecombe
*/
public class MovementPacketHandler implements PacketHandler<MinecraftSession> {
   Position lastPosition = null;
        long lastMoveTime = 0;
   @Override
   public void handlePacket(MinecraftSession session, Packet packet) {
      if (!session.isAuthenticated()) {
         return;
      }
      final Player player = session.getPlayer();
                Position oldPosition = player.getPosition();
                Rotation oldRotation = player.getOldRotation();
                final int oldX = oldPosition.getX();
                final int oldY = oldPosition.getY();
                final int oldZ = oldPosition.getZ();
      final int x = packet.getNumericField("x").intValue();
      final int y = packet.getNumericField("y").intValue();
      final int z = packet.getNumericField("z").intValue();
                Position blockPosition = new Position((x - 16)/32, (y - 16)/32, (z - 16)/32);
                if(lastPosition == null || (Math.abs(blockPosition.getX() - lastPosition.getX()) > 2 || Math.abs(blockPosition.getY() - lastPosition.getY()) > 2 || Math.abs(blockPosition.getZ() - lastPosition.getZ()) > 2))
                {
                    lastPosition = blockPosition;
                    lastMoveTime = System.currentTimeMillis();
                }
                else if(System.currentTimeMillis() - lastMoveTime > 300000)
                {
                    player.getActionSender().sendLoginFailure("You were kicked for being AFK!");
                    World.getWorld().broadcast("- "+player.parseName()+" was kicked for being AFK!");
                }
                int dx = Math.abs(x - oldX);
                int dy = Math.abs(y - oldY);
                int dz = Math.abs(z - oldZ);
                if((dx > 500 || dy > 500 || dz > 500))
                {
                    int divider = World.getWorld().getLevel().divider;
                    if(player.team == 0 && blockPosition.getX() > divider)
                    {
                        player.sendToTeamSpawn();
                        player.getActionSender().sendChatMessage("- &eYou may not respawn on the other team's side!");
                    }
                    else if(player.team == 1 && blockPosition.getX() < divider)
                    {
                        player.sendToTeamSpawn();
                        player.getActionSender().sendChatMessage("- &eYou may not respawn on the other team's side!");
                    }
                    if(player.hasFlag)
                    {
                        CTFGameMode ctf = (CTFGameMode) World.getWorld().getGameMode();
                        if(player.team == 0)
                        {
                            ctf.blueFlagTaken = false;
                            ctf.placeBlueFlag();
                        }
                        else
                        {
                            ctf.redFlagTaken = false;
                            ctf.placeRedFlag();
                        }
                        ctf.antiStalemate = false;
                        player.hasFlag = false;
                        World.getWorld().broadcast("- "+player.parseName()+" dropped the flag due to respawning!");
                    }
                }
                if((z - 16)/32 < World.getWorld().getLevel().floor && !player.safe)
                {
                    player.safe = true;
                    new Thread(new PlayerUntagger(player)).start();
                    World.getWorld().broadcast("- "+player.parseName()+" died!");
                    player.sendToTeamSpawn();
                    if(player.hasFlag)
                    {
                        CTFGameMode ctf = (CTFGameMode) World.getWorld().getGameMode();
                        if(player.team == 0)
                        {
                            ctf.blueFlagTaken = false;
                            ctf.placeBlueFlag();
                        }
                        else
                        {
                            ctf.redFlagTaken = false;
                            ctf.placeRedFlag();
                        }
                        ctf.antiStalemate = false;
                        player.hasFlag = false;
                        World.getWorld().broadcast("- "+player.parseName()+" dropped the flag!");
                    }
                }
      final int rotation = packet.getNumericField("rotation").intValue();
      final int look = packet.getNumericField("look").intValue();
      player.setPosition(new Position(x, y, z));
      player.setRotation(new Rotation(rotation, look));
   }
  
}

Also, how can I make it so chat messages can be longer? Would it be using this code?

Code:
public void sendChatMessage(int id, String message) {
      PacketBuilder bldr = new PacketBuilder(PersistingPacketManager.getPacketManager().getOutgoingPacket(13));
                String message2 = "";
                if(message.length() > 64)
                {
                    message2 = message.substring(64);
                    int idx = message.lastIndexOf("&");
                    if(idx != -1)
                        message2 = "&"+message.charAt(idx + 1)+message2;
                    message = message.substring(0, 64);
                }
                bldr.putByte("id", id);
      bldr.putString("message", message);
                session.send(bldr.toPacket());
                if(!message2.equals(""))
                    sendChatMessage(id, "> "+message2);
   }

I thought I could get a quicker response if I caught you on Buildism... Smile I thought I had an account here, but I didn't, so now I do. Big Grin haha.

Thanks. Big Grin
Reply
#2
What's wrong with the first piece of code? Does it not compile at all, or just not do what it's supposed to do?

And the Minecraft Classic network protocol only allows strings to be 64 characters long, so there's no way to send longer messages without splitting them up.
Reply
#3
The first code just doesn't do what it's supposed to do. It compiles fine, and it's in the current server code, but it's not kicking people that don't move for 3 minutes. :/
Reply
#4
(07-18-2011, 12:50 AM)Komain72 Wrote: The first code just doesn't do what it's supposed to do. It compiles fine, and it's in the current server code, but it's not kicking people that don't move for 3 minutes. :/

The limit is 5 minutes, not 3.

I tested it with a shorter time limit before I gave it to you, and it worked. If the map changes it will reset the timer, so that could be causing a problem.

I think 3 minutes would work better though, or maybe even 2.
Reply
#5
(07-18-2011, 01:17 AM)Jacob_ Wrote:
(07-18-2011, 12:50 AM)Komain72 Wrote: The first code just doesn't do what it's supposed to do. It compiles fine, and it's in the current server code, but it's not kicking people that don't move for 3 minutes. :/

The limit is 5 minutes, not 3.

I tested it with a shorter time limit before I gave it to you, and it worked. If the map changes it will reset the timer, so that could be causing a problem.

I think 3 minutes would work better though, or maybe even 2.

I know, but I had it with 5 minutes and with 3 minutes and neither worked. But I will change it to 3 * 60 * 1000 and see what happens.

If it doesn't work, would something else in my version of the server code be causing the problem?
Reply
#6
(07-18-2011, 01:38 AM)Komain72 Wrote:
(07-18-2011, 01:17 AM)Jacob_ Wrote:
(07-18-2011, 12:50 AM)Komain72 Wrote: The first code just doesn't do what it's supposed to do. It compiles fine, and it's in the current server code, but it's not kicking people that don't move for 3 minutes. :/

The limit is 5 minutes, not 3.

I tested it with a shorter time limit before I gave it to you, and it worked. If the map changes it will reset the timer, so that could be causing a problem.

I think 3 minutes would work better though, or maybe even 2.

I know, but I had it with 5 minutes and with 3 minutes and neither worked. But I will change it to 3 * 60 * 1000 and see what happens.

If it doesn't work, would something else in my version of the server code be causing the problem?

Probably not. This is the code that processes movement packets from clients, so nothing else should affect it.
Reply
#7
> Sees how inefficient the Minecraft network protocol is
<_<


Why is Java big-endian anyway?
Reply
#8
Nope, not a thing happened. D:
Reply
#9
(07-18-2011, 04:07 PM)Komain72 Wrote: Nope, not a thing happened. D:

I just tested it again on an empty server with a 2 minute time limit, and it works.

It could be that other players are pushing around the AFK people, so try changing the 2s on line 68 to a higher number (it's the number of blocks someone has to move for it to be counted.)
Reply
#10
(07-18-2011, 04:20 PM)Jacob_ Wrote:
(07-18-2011, 04:07 PM)Komain72 Wrote: Nope, not a thing happened. D:

I just tested it again on an empty server with a 2 minute time limit, and it works.

It could be that other players are pushing around the AFK people, so try changing the 2s on line 68 to a higher number (it's the number of blocks someone has to move for it to be counted.)


Ok. I will do that then. Thanks! I'll post if it works or not later on. Big Grin
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)