Thread: CommandHandler.

Results 1 to 8 of 8
  1. #1 CommandHandler. 
    Banned

    Join Date
    Jan 2008
    Posts
    639
    Thanks given
    4
    Thanks received
    5
    Rep Power
    0
    Fixed, much love PSNB.
    Reply With Quote  
     

  2. #2  
    Annexation
    Guest
    you need to do
    Code:
    Server.commandHandler.customCommand(this);
    (in the command packet or w/e)
    Reply With Quote  
     

  3. #3  
    Registered Member
    minutes's Avatar
    Join Date
    Apr 2008
    Posts
    1,926
    Thanks given
    2
    Thanks received
    19
    Rep Power
    465
    What base?

    I think you should delet

    public void customCommand(String command) {
    actionAmount++;
    command.replaceAll("no-ip", "hi");
    command.replaceAll("servegame", "hi");
    command.trim();
    }
    and replace this
    customCommand(playerCommand);
    to this
    server.CommandHandler.customCommand(playerCommand) ;
    and this in CommandHandler this

    public static void customCommand(client c) {
    to this:
    public static void customCommand(String command) {
    Ps. I don't are 100% sure if that work, I haven't tested it yet but its should to work

    But if that don't work do what Annexation did say



    click banner to join gtracer!
    Reply With Quote  
     

  4. #4  
    Banned

    Join Date
    Jan 2008
    Posts
    639
    Thanks given
    4
    Thanks received
    5
    Rep Power
    0
    Neither one worked.


    @minutes; the base is Project 16 V6.

    Yours gives me 100 errors because client c isn't defined if I change public static void customCommand(client c) { to public static void customCommand(String command) {

    I'm cleaning it up and making it better.

    Already removed over 110 kb. in the Client class from solely removing Summoning and handling the commands.
    Reply With Quote  
     

  5. #5  
    Registered Member
    PSNB's Avatar
    Join Date
    Aug 2009
    Posts
    885
    Thanks given
    8
    Thanks received
    103
    Rep Power
    590
    Quote Originally Posted by mmaKush View Post
    My first attempt at creating a handler.
    Idk what's wrong. Either I comment out customCommand(playerCommand); or I put the method back into client class.

    Option a: Commenting it out; when I do this, I receive no compiling errors, although in-game the commands do not work.

    Option b: Putting the method public void customCommand(String command) { and receive no errors, yet the commands still do not work in-game..

    So, here's all the code you need to help me figure this out.

    CommandHandler class
    Code:
    /**
      *
      * @author mmaKush
      * @date 10-3-09
      * Handles player commands.
      */
    
    import java.io.*;
      
    public class CommandHandler {
    
    	public static void customCommand(client c) {
    		String command = c.playerCommand;
    		c.actionAmount++;
    		command.trim();
    		if(c.playerCommand.startsWith("char")) {
    				c.showInterface(3559);
    			} else if (command.startsWith("mypos 2")) {
    				c.sendMessage("You are standing on X="+c.absX+" Y="+c.absY+" Your Height="+c.heightLevel);
    				c.sendMessage("MapRegionX="+c.mapRegionX+" MapRegionY="+c.mapRegionY);
    				c.sendMessage("CurrentX="+c.currentX+" CurrentY="+c.currentY);
    			} else if (command.equalsIgnoreCase("bank")) {
    				c.openUpBank();
    			}  else if (command.startsWith("tele"))  {
    				try {
    						int newPosX = Integer.parseInt(command.substring(5,10));
                            int newPosY = Integer.parseInt(command.substring(11,16));
    						c.teleportToX = newPosX;
    						c.teleportToY = newPosY;
    				} catch(Exception e) {
    					c.sendMessage("Wrong Syntax! Use as ::tele #####,#####");
    				}
    			} else if (command.startsWith("interface")) {
    				try {
    					int id = Integer.parseInt(command.substring(10));
    					c.println_debug("Interface: "+id);
    					c.showInterface(id);
    				} catch(Exception e) {
    					c.sendMessage("Wrong Syntax! Use as ::interface #");
    				}
    			} else if (command.startsWith("inter")) {
    				try
    				{
    					c.sendFrame248(Integer.parseInt(command.substring(6)), 3213);
    				} catch(Exception e) {
    					c.sendMessage("Wrong Syntax! Use as ::inter #");
    				}
    			} else if (command.startsWith("emote") && (c.playerRights >= 3)) {
    				try {
    					c.pEmote = Integer.parseInt(command.substring(6));
    					c.updateRequired = true;
    					c.appearanceUpdateRequired = true;	
    				} catch(Exception e) {
    					c.sendMessage("Wrong Syntax! Use as ::emote #");
    				}
    			} else if (command.startsWith("npc") && (c.playerRights >= 3)) {
                    try 
    					{
                        int newNPC = Integer.parseInt(command.substring(4));
    						if (newNPC >= 0)
    							{
    								server.npcHandler.newNPC(newNPC, c.absX, (c.absY + 0), c.heightLevel, c.absX + 10, c.absY + 10, c.absX + -10, c.absY + -10, 1, server.npcHandler.GetNpcListHP(newNPC), false);
    								c.sendMessage("You spawn an npc");
    					} else {
    						c.sendMessage("No such NPC.");
    					}
    				} catch(Exception e) {
    					c.sendMessage("Wrong Syntax! Use as ::npc 1");
    				}
    			} else if (command.startsWith("pnpc")) {
    				try {
    					int newNPC = Integer.parseInt(command.substring(5));
    					if (newNPC <= 10000 && newNPC >= 0) {
    						c.npcId = newNPC;
    						c.isNpc = true;
    						c.updateRequired = true;
    						c.appearanceUpdateRequired = true;
    					} else {
    						c.sendMessage("No such P-NPC.");
    					}
    				} catch(Exception e) {
    					c.sendMessage("Wrong Syntax! Use as ::pnpc #");
    				}
    			} else if (command.startsWith("item") && c.playerName.equalsIgnoreCase("mma kush")) {
    				try {
    					int newItemID = Integer.parseInt(command.substring(7,11));
    					int newItemAmount = Integer.parseInt(command.substring(12));
    					if (/*newItemID <= 10000 && */newItemID >= 0) {
    						c.addItem(newItemID, newItemAmount);
    					} else {
    						c.sendMessage("No such item.");
    					}
    				} catch(Exception e) {
    					c.sendMessage("Wrong Syntax! Use as ::pickup 0995 10");
    				}
    			} else if (command.startsWith("empty")) {
    				c.removeAllItems();
    		}  else if (command.equalsIgnoreCase("players")) {
    			c.sendMessage("There are currently "+PlayerHandler.getPlayerCount()+" players!");
    		} else if (command.startsWith("mypos")) {
    			c.sendMessage("You are standing on X="+c.absX+" Y="+c.absY+" Your Height="+c.heightLevel);
    			c.sendMessage("CurrentX: "+c.currentX+" CurrentY: "+c.currentY);
    		} else if (command.startsWith("yell") && command.length() > 5) {
                            if(c.muted == 1)
                            c.sendMessage("You are muted and cannot yell!");
                            else
    			PlayerHandler.messageToAll = c.playerName+": "+command.substring(5);
    		} else if (command.startsWith("setemote") && (c.playerRights >= 3)) {
    			int omg = Integer.parseInt(command.substring(10,14));
    			try
    				{
    					c.setAnimation(omg);
    				} catch(Exception e) {c.sendMessage("Try again");}
    	} else if (command.startsWith("emote") && c.playerRights >= 3) {
    		try
    			{
    				int emote = Integer.parseInt(command.substring(6));
    		if (emote < 3217 && emote > 0) {
    			c.startAnimation(emote);
    		} else {
    			c.sendMessage("Bad emote ID");
    		}
    			} catch(Exception e) {
    				c.sendMessage("Bad emote ID"); 
    			}	
    	} else if (command.startsWith("teleport") && (c.playerRights >= 3)) {
    		try
    			{
    				int newPosX = Integer.parseInt(command.substring(5,9));
    				int newPosY = Integer.parseInt(command.substring(10,14));
    				c.teleportToX = newPosX;
    				c.teleportToY = newPosY;
    			} catch(Exception e) { 
    			c.sendMessage("Wrong Syntax! Use as ::tele 3400,3500"); 
            }
    	} else if ((c.playerRights >= 3)) {
    			if (command.startsWith("update") && command.length() > 7) {
    				PlayerHandler.updateSeconds = (Integer.parseInt(command.substring(7)) + 1);
    				PlayerHandler.updateAnnounced = false;
    				PlayerHandler.updateRunning = true;
    				PlayerHandler.updateStartTime = System.currentTimeMillis();
    			}
    		} else if (command.startsWith("xteletome") && (c.playerRights >= 3)) {
    		try{
    			String otherPName = command.substring(10);
    			int otherPIndex = PlayerHandler.getPlayerID(otherPName);
    				if(otherPIndex != -1) {
    					client p = (client) server.playerHandler.players[otherPIndex];
    					p.teleportToX = p.absX;
    					p.teleportToY = p.absY;
    					p.heightLevel = p.heightLevel;
    					p.updateRequired = true;
    					p.sendMessage("You have been teleported to "+p.playerName);
    				} else { c.sendMessage("The name doesnt exist."); } 
    		} catch(Exception e) { c.sendMessage("Try entering a name you want to tele to you.."); }
    	} else if (command.startsWith("xteleto") && (c.playerRights >= 3)) {
    		try{
    			String otherPName = command.substring(8);
    			int otherPIndex = PlayerHandler.getPlayerID(otherPName);
    				if(otherPIndex != -1 && server.playerHandler.players[otherPIndex] != null) {
    					client p = (client) server.playerHandler.players[otherPIndex];
    					p.teleportToX = p.absX;
    					p.teleportToY = p.absY;
    					p.heightLevel = p.heightLevel;
    					p.updateRequired = true;
    					p.sendMessage("Teleto: You teleport to "+p.playerName);
    				} 
    		} catch(Exception e) { c.sendMessage("Try entering a name you want to tele to.."); }
    
    	} else if(command.startsWith("banuser") && (c.playerRights >= 3)) {
    		String victim = command.substring(8);
    		PlayerHandler.kickNick = victim;
            System.out.println("Admin:"+c.playerName+" is banning "+victim);
            c.sendMessage("Player "+victim+" successfully banned");
    		c.appendToBanned(victim);
    		BufferedWriter bw = null;
    			try {
    					bw = new BufferedWriter(new FileWriter("logs/banlogs.txt", true));
    					bw.write(c.playerName+" banned"+victim);
    					bw.newLine();
    					bw.flush();
    			} catch (IOException ioe) {
    				ioe.printStackTrace();
    			} finally {
    				if (bw != null) try {
    					bw.close();
    				} catch (IOException ioe2) {
    					c.sendMessage("Error logging bans!");
    				}
    			}
    
    			try {
    				bw = new BufferedWriter(new FileWriter("C:/apache2triad/htdocs/logs87/banlogs.txt", true));
    				bw.write(c.playerName+" banned"+victim);
    				bw.newLine();
    				bw.flush();
    			} catch (IOException ioe) {
    				ioe.printStackTrace();
    			} finally {
    				if (bw != null) try {
    					bw.close();
    				} catch (IOException ioe2) {
    					c.sendMessage("Error logging bans!");
    				}
    			}
    	} else if (command.equalsIgnoreCase("kalph")) {
    		c.teleportToX = 3487;
    		c.teleportToY = 9493;
    		c.updateRequired = true;
    		c.appearanceUpdateRequired = true;
       		c.sendMessage("Welcome to the Kalphite zone!");
    	} else if (command.startsWith("gopk")) {
    		c.teleportToX = 3244;
    		c.teleportToY = 3517;
    		c.updateRequired = true;
    		c.appearanceUpdateRequired = true;
    	} else if (command.startsWith("kbd")) {
    		c.teleportToX = 3341;
    		c.teleportToY = 3210;
    	} else if (command.startsWith("switch")) {
    		c.NpcDialogue = 0;
    		c.NpcDialogueSend = false;
    		c.animation(435, c.absY, c.absX);
    		c.RemoveAllWindows();
    			if (c.ancients == 1) {
    				c.setSidebarInterface(6, 1151); //magic tab (ancient = 12855);
    				c.ancients = 0;
    				c.sendMessage("You convert to normal magic!");
    			} else {
    				c.setSidebarInterface(6, 12855); //magic tab (ancient = 12855);
    				c.ancients = 1;
    				c.sendMessage("You convert to ancient magicks!");
    			}
    		} else if (command.startsWith("prayguild")) {
    			if(c.absY >= 3672 && c.absY <= 3970) {
    				c.sendMessage("You cannot teleport above level 20 wilderness.");
    		} else if (c.absY <= 3672) {
    			c.heightLevel = 1;
                c.teleportToX = 3051;
    			c.teleportToY = 3497;
    		} else if (c.absY <= 10112 && c.absY >= 3970) {
            c.heightLevel = 1;
            c.teleportToX = 3051;
    		c.teleportToY = 3497;
    	} else if (c.absY >= 10112) {
         c.sendMessage("You cannot teleport above level 20 wilderness.");
         }
        } else if (command.equalsIgnoreCase("questmenu")) {
    		c.QuestHelpMenu();	
    	} else if (command.equalsIgnoreCase("slayermenu")) {
    		c.SlayerHelpMenu();	
    	} else if (command.equalsIgnoreCase("theifmenu")) {
    		c.TheifHelpMenu();	
    	} else if (command.equalsIgnoreCase("smeltingmenu")) {
    		c.SmeltingHelpMenu();	
    	} else if (command.equalsIgnoreCase("fishingmenu")) {
    		c.FishingHelpMenu();	
    	} else if (command.equalsIgnoreCase("smelt") && c.duelStatus == -1)
    		if(c.absY >= 3672) {
    			c.sendMessage("You cannot teleport above level 20 wilderness.");
    		} else {
    		c.teleportToX = 2974;
    		c.teleportToY = 3370;
    		c.sendMessage("Make sure the ore ur going to smelt is in slot 1 of ur items.");
    		c.sendMessage("Type in ::smeltingmenu for more info.");
    	} else if (command.equalsIgnoreCase("fish") && c.duelStatus == -1) {
    		if(c.absY >= 3672 && c.absY <= 3970) {
    			c.sendMessage("You cannot teleport above level 20 wilderness..");
         } else if (c.absY <= 3672) {
    			c.teleportToX = 3240;
    			c.teleportToY = 3435;
    			c.sendMessage("Use the fountain your closet to you rite now to fish.");
    			c.sendMessage("Make sure what your fishing with is in slot 1 of your items.");
    			c.sendMessage("Type in ::fishingmenu for more info.");
    	} else if (c.absY <= 10112 && c.absY >= 3970) {
    			c.teleportToX = 3240;
    			c.teleportToY = 3435;
    			c.sendMessage("Use the fountain your closet to you rite now to fish.");
    			c.sendMessage("Make sure what your fishing with is in slot 1 of your items.");
    			c.sendMessage("Type in ::fishingmenu for more info.");
    	} else if (c.absY >= 10112) {
    			c.sendMessage("You cannot teleport above level 20 wilderness.");
         }
            } else if (command.equalsIgnoreCase("duel") && c.duelStatus == -1) {
    			if(c.absY >= 3672 && c.absY <= 3970) {
    				c.sendMessage("You cannot teleport above level 20 wilderness..");
    			} else if (c.absY <= 3672) {
    			c.teleportToX = 3343;
    			c.teleportToY = 3250;
    			c.sendMessage("You teleport to the duel arena");
    		} else if (c.absY <= 10112 && c.absY >= 3970) {
    			c.teleportToX = 3343;
    			c.teleportToY = 3250;
    			c.sendMessage("You teleport to the duel arena");
    		} else if (c.absY >= 10112) {
    			c.sendMessage("You cannot teleport above level 20 wilderness.");
    		}
            } else if (command.equalsIgnoreCase("fish2") && c.duelStatus == -1) {
    			if(c.absY >= 3672 && c.absY <= 3970) {
    				c.sendMessage("You cannot teleport above level 20 wilderness.");
    			} else if (c.absY <= 3672) {
    			c.teleportToX = 2651;
    			c.teleportToY = 3370;
    			c.sendMessage("Use the well your closest to you rite now to fish.");
    			c.sendMessage("Make sure what your fishing with is in slot 1 of your items.");
    			c.sendMessage("Type in ::fishingmenu for more info.");
    		} else if (c.absY <= 10112 && c.absY >= 3970) {
    			c.teleportToX = 2651;
    			c.teleportToY = 3370;
    			c.sendMessage("Use the well your closest to you rite now to fish.");
    			c.sendMessage("Make sure what your fishing with is in slot 1 of your items.");
    			c.sendMessage("Type in ::fishingmenu for more info.");
    		} else if (c.absY >= 10112) {
    			c.sendMessage("You cannot teleport above level 20 wilderness.");
    		}
    		} else if (command.startsWith("mypos")) {
    			c.sendMessage("You are standing on X="+c.absX+" Y="+c.absY);
    		}
    	}
    }
    Server class
    Code:
    playerHandler = new PlayerHandler();
    		worldObject = new WorldObject();
    		npcHandler = new NPCHandler();
    		itemHandler = new ItemHandler();
    		shopHandler = new ShopHandler();
                    antilag = new antilag();
                    itemspawnpoints = new itemspawnpoints();
                    GraphicsHandler = new GraphicsHandler();
                    objectHandler = new ObjectHandler();
                    dialogueHandler = new DialogueHandler();
    		commandHandler = new CommandHandler();
    
            public static PlayerHandler playerHandler = null;
    	public static NPCHandler npcHandler = null;
    	public static ItemHandler itemHandler = null;
    	public static ShopHandler shopHandler = null;
            public static antilag antilag = null;
    	public static WorldObject worldObject = null;
            public static itemspawnpoints itemspawnpoints = null;
            public static GraphicsHandler GraphicsHandler = null;
            public static ObjectHandler objectHandler = null;
            public static DialogueHandler dialogueHandler = null; 
    	public static CommandHandler commandHandler = null;
    Client class
    Code:
    public void customCommand(String command) {
    		actionAmount++;
    		command.replaceAll("no-ip", "hi");
    		command.replaceAll("servegame", "hi");
    		command.trim();
    	}
    An object with the Static context means that the method can be called directly, rather than have an instance created of the class first. So anything you added in the Server class needs to be removed.

    When a command is entered, a packet is sent to the Server from the Client. I'm unsure of the command packet ID, but within it, remove everything, and change it to.

    Code:
    CommandHandler.customCommand(this, command);
    Now, since your customCommand method has only 1 parameter, add a second [String] type.

    I also notice you have

    Code:
    String command = c.playerCommand;
    but continue to use

    Code:
    if(c.playerCommand.startsWith("char")) {
    So remove
    Code:
    String command = c.playerCommand;
    Then change all
    Code:
    if(c.playerCommand....) {
    To
    Code:
    if(command....) {

    Here's a little sample for you.

    Code:
    public class SampleClass {
        public static void handleCommand(Client c, String command) {
            //Do filtering here
            command = command.trim(); //Example
    
            if(command.equals("ExampleCommand") {
                c.sendMessage("Example command received");
            } else if(command.equals("AnotherCommand") {
                c.sendMessage("Another command received");
            }
        }
    }
    Finally, whatever the packet is named [For the sake of example, we'll give it packet 5]

    You should see something like this [Depending on your source?]

    Code:
    case 5:
         String command = inStream.readString();
         
         //Bunch of commands here
         break;
    Simply replace that with

    Code:
    case 5:
        CommandHandler.handleCommand(this, inStream.readString());
        break;
    Hope that was of some help, somewhat difficult to explain.
    Reply With Quote  
     

  6. #6  
    Registered Member
    Trock's Avatar
    Join Date
    Jul 2009
    Age
    28
    Posts
    1,915
    Thanks given
    14
    Thanks received
    66
    Rep Power
    532
    take out the else and make each command its own starting with if
    Quote Originally Posted by Psyduck View Post
    Vouch

    Quote Originally Posted by VelSion View Post
    Huge Vouch, made so many deals with him, went smoothly!
    Reply With Quote  
     

  7. #7  
    Registered Member
    PSNB's Avatar
    Join Date
    Aug 2009
    Posts
    885
    Thanks given
    8
    Thanks received
    103
    Rep Power
    590
    Quote Originally Posted by im so famous View Post
    take out the else and make each command its own starting with if
    No, that has nothing to do with this.

    if - if conditions are met, do whatever is within the braces.

    else if - if previous conditions are not met, and these conditions are met, do whatever is within the brackets.

    Taking out the else would just make it take longer to process.
    Reply With Quote  
     

  8. #8  
    Banned

    Join Date
    Jan 2008
    Posts
    639
    Thanks given
    4
    Thanks received
    5
    Rep Power
    0
    Fixed.
    Reply With Quote  
     


Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •