Thread: My ban command not working

Results 1 to 5 of 5
  1. #1 My ban command not working 
    Registered Member

    Join Date
    Feb 2007
    Age
    28
    Posts
    6,414
    Thanks given
    354
    Thanks received
    323
    Rep Power
    5000
    I don't know, everything seems to be there. Base is PI. The command saves the file into the text file. It just seem to not read when the server is online that a user is banned, it allows the person to play without any problems.

    Rs2loginProtocolDecoder:
    Code:
    		if (Connection.isNamedBanned(cl.playerName)) {
    			returnCode = 4;
    		}
    Code:
    			if (playerCommand.startsWith("ban") && playerCommand.charAt(3) == ' ') {
    				try {	
    					String playerToBan = playerCommand.substring(4);
    					Connection.addNameToBanList(playerToBan);
    					Connection.addNameToFile(playerToBan);
    					for(int i = 0; i < Config.MAX_PLAYERS; i++) {
    						if(Server.playerHandler.players[i] != null) {
    							if(Server.playerHandler.players[i].playerName.equalsIgnoreCase(playerToBan)) {
    								Server.playerHandler.players[i].disconnected = true;
    						Client c2 = (Client)Server.playerHandler.players[i];
    								c2.sendMessage(" " +c2.playerName+ " Got Banned By " + c.playerName+ ".");
    c.getPA().messageStaff(c.playerName, "has banned the user " + c2.playerName, true);
    							} 
    						}
    					}
    				} catch(Exception e) {
    					c.sendMessage("Player Must Be Offline.");
    				}
    				}
    Connection:
    Code:
    package server;
    
    import java.io.BufferedReader;
    import java.io.BufferedWriter;
    import java.io.FileReader;
    import java.io.FileWriter;
    import java.io.IOException;
    import java.util.ArrayList;
    import server.model.players.Client;
    import server.Connection;
    
    /**
     * Connection Check Class
     * 
     * @author Ryan / Lmctruck30
     *
     */
    
    public class Connection {
    
    	public static ArrayList <String>bannedIps = new ArrayList<String> ();
    	public static ArrayList <String>bannedNames = new ArrayList<String> ();
    	public static ArrayList <String>mutedIps = new ArrayList<String> ();
    	public static ArrayList <String>mutedNames = new ArrayList<String> ();
    	public static ArrayList <String>loginLimitExceeded = new ArrayList<String> ();
    	public static ArrayList <String>starterRecieved1 = new ArrayList<String> ();
    	public static ArrayList <String>starterRecieved2 = new ArrayList<String> ();
    	
    	
    	/**
    	* Adds the banned usernames and ips from the text file to the ban list
    	**/
    	public static void initialize() {
    		banUsers();
    		banIps();
    		muteUsers();
    		muteIps();
    		appendStarters();
    		appendStarters2();
    	}	
    	
    	/**
    	 * Adding Name To List
    	 */
    	public static void addIpToLoginList(String IP) {
    		loginLimitExceeded.add(IP);
    	}
    	
    	/**
    	 * Remove Ip From List
    	 */
    	public static void removeIpFromLoginList(String IP) {
    		loginLimitExceeded.remove(IP);
    	}
    	
    	/**
    	 * Clear Name List
    	 */
    	public static void clearLoginList() {
    		loginLimitExceeded.clear();
    	}
    	
    	public static boolean checkLoginList(String IP) {
    		loginLimitExceeded.add(IP);
    		int num = 0;
    		for(String ips : loginLimitExceeded) {
    			if(IP.equals(ips)) {
    				num++;
    			}
    		}
    		if(num > 5) {
    			return true;
    		}
    		return false;
    	}
    	
    	public static void unMuteUser(String name) {
    		mutedNames.remove(name);
    		deleteFromFile("./Data/bans/UsersMuted.txt", name);	
    	}
    	
    	public static void unIPMuteUser(String name) {
    		mutedIps.remove(name);
    		deleteFromFile("./Data/bans/IpsMuted.txt", name);	
    	}
    	
    	/**
    	* Adding Ban IP
    	**/
    	public static void addIpToBanList(String IP) {
    		bannedIps.add(IP);
    	}
    	
    	public static void addIpToMuteList(String IP) {
    		mutedIps.add(IP);
    		addIpToMuteFile(IP);
    	}
    	
    	
    	/**
    	* Removing Ban IP
    	**/
    	public static void removeIpFromBanList(String IP) {
    		bannedIps.remove(IP);
    	}
    	
    	/**
    	* Contains Ban IP
    	**/
    	public static boolean isIpBanned(String IP) {
    		if(bannedIps.contains(IP)) {
    			return true;
    		}
    		return false;
    	}
    	
    
    	/**
    	* Adding banned username
    	**/
    	public static void addNameToBanList(String name) {
    		bannedNames.add(name.toLowerCase());
    	}
    	
    	public static void addNameToMuteList(String name) {
    		mutedNames.add(name.toLowerCase());
    		addUserToFile(name);
    	}
    	
    	
    	/**
    	* Removing banned username
    	**/
    	public static void removeNameFromBanList(String name) {
    		bannedNames.remove(name.toLowerCase());
    		deleteFromFile("./Data/bans/UsersBanned.txt", name);
    	}
    	
    	public static void removeNameFromMuteList(String name) {
    		bannedNames.remove(name.toLowerCase());
    		deleteFromFile("./Data/bans/UsersMuted.txt", name);
    	}
    	
    	public static void deleteFromFile(String file, String name) {
    		try {
    			BufferedReader r = new BufferedReader(new FileReader(file));
    			ArrayList<String> contents = new ArrayList<String>();
    			while(true) {
    				String line = r.readLine();
    				if(line == null) {
    					break;
    				} else {
    					line = line.trim();
    				}
    				if(!line.equalsIgnoreCase(name)) {
    					contents.add(line);
    				}
    			}
    			r.close();
    			BufferedWriter w = new BufferedWriter(new FileWriter(file));
    			for(String line : contents) {
    				w.write(line, 0, line.length());
    				w.newLine();
    			}
    			w.flush();
    			w.close();
    		} catch (Exception e) {}
    	}
    	
    	/**
    	* Contains banned username
    	**/
    	public static boolean isNamedBanned(String name) {
    		if(bannedNames.contains(name.toLowerCase())) {
    			return true;
    		}
    		return false;
    	}
    	public static void appendStarters() {
    		try {
    			BufferedReader in = new BufferedReader(new FileReader("./Data/starters/FirstStarterRecieved.txt"));
    			String data = null;
    			try {
    				while ((data = in.readLine()) != null) {
    					starterRecieved1.add(data);
    				}
    			} finally {
    				in.close();
    			}
    		} catch (IOException e) {
    			e.printStackTrace();
    		}
    	}
    
    	public static void appendStarters2() {
    		try {
    			BufferedReader in = new BufferedReader(new FileReader("./Data/starters/SecondStarterRecieved.txt"));
    			String data = null;
    			try {
    				while ((data = in.readLine()) != null) {
    					starterRecieved2.add(data);
    				}
    			} finally {
    				in.close();
    			}
    		} catch (IOException e) {
    			e.printStackTrace();
    		}
    	}
    
            public static void addIpToStarter1(String IP) {
    		starterRecieved1.add(IP);
    		addIpToStarterList1(IP);
    	}
    
    	public static void addIpToStarter2(String IP) {
    		starterRecieved2.add(IP);
    		addIpToStarterList2(IP);
    	}
    
    	public static void addIpToStarterList1(String Name) {
    		try {
    			BufferedWriter out = new BufferedWriter(new FileWriter("./Data/starters/FirstStarterRecieved.txt", true));
    		    try {
    				out.newLine();
    				out.write(Name);
    		    } finally {
    				out.close();
    		    }
    		} catch (IOException e) {
    			e.printStackTrace();
    		}
    	}
    
    	public static void addIpToStarterList2(String Name) {
    		try {
    			BufferedWriter out = new BufferedWriter(new FileWriter("./Data/starters/SecondStarterRecieved.txt", true));
    		    try {
    				out.newLine();
    				out.write(Name);
    		    } finally {
    				out.close();
    		    }
    		} catch (IOException e) {
    			e.printStackTrace();
    		}
    	}
    
           public static boolean hasRecieved1stStarter(String IP) {
    		if(starterRecieved1.contains(IP)) {
    			return true;
    		}
    		return false;
    	}
    
    	public static boolean hasRecieved2ndStarter(String IP) {
    		if(starterRecieved2.contains(IP)) {
    			return true;
    		}
    		return false;
    	}
    	
    	/**
    	* Reads all usernames from text file then adds them all to the ban list
    	**/
    	public static void banUsers() {
    		try {
    			BufferedReader in = new BufferedReader(new FileReader("./Data/bans/UsersBanned.txt"));
    			String data = null;
    			try {
    				while ((data = in.readLine()) != null) {
    					addNameToBanList(data);
    				}
    			} finally {
    				in.close();
    			}
    		} catch (IOException e) {
    			e.printStackTrace();
    		}
    	}
    	
    	public static void muteUsers() {
    		try {
    			BufferedReader in = new BufferedReader(new FileReader("./Data/bans/UsersMuted.txt"));
    			String data = null;
    			try {
    				while ((data = in.readLine()) != null) {
    					mutedNames.add(data);
    				}
    			} finally {
    				in.close();
    			}
    		} catch (IOException e) {
    			e.printStackTrace();
    		}
    	}
    	/**
    	* Reads all the Ips from text file then adds them all to ban list
    	**/
    	public static void banIps() {
    		try {
    			BufferedReader in = new BufferedReader(new FileReader("./Data/bans/IpsBanned.txt"));
    			String data = null;
    			try {
    				while ((data = in.readLine()) != null) {
    					addIpToBanList(data);
    				}
    			} finally {
    				in.close();
    			}
    		} catch (IOException e) {
    			e.printStackTrace();
    		}
    	}
    	
    	public static void muteIps() {
    		try {
    			BufferedReader in = new BufferedReader(new FileReader("./Data/bans/IpsMuted.txt"));
    			String data = null;
    			try {
    				while ((data = in.readLine()) != null) {
    					mutedIps.add(data);
    				}
    			} finally {
    				in.close();
    			}
    		} catch (IOException e) {
    			e.printStackTrace();
    		}
    	}
    	/**
    	* Writes the username into the text file - when using the ::ban playername command
    	**/
    	public static void addNameToFile(String Name) {
    		try {
    			BufferedWriter out = new BufferedWriter(new FileWriter("./Data/bans/UsersBanned.txt", true));
    		    try {
    				out.newLine();
    				out.write(Name);
    		    } finally {
    				out.close();
    		    }
    		} catch (IOException e) {
    			e.printStackTrace();
    		}
    	}
    	
    	public static void addUserToFile(String Name) {
    		try {
    			BufferedWriter out = new BufferedWriter(new FileWriter("./Data/bans/UsersMuted.txt", true));
    		    try {
    				out.newLine();
    				out.write(Name);
    		    } finally {
    				out.close();
    		    }
    		} catch (IOException e) {
    			e.printStackTrace();
    		}
    	}
    	
    	
    
    	
    	
    	/**
    	* Writes the IP into the text file - use ::ipban username
    	**/
    	public static void addIpToFile(String Name) {
    		try {
    			BufferedWriter out = new BufferedWriter(new FileWriter("./Data/bans/IpsBanned.txt", true));
    		    try {
    				out.newLine();
    				out.write(Name);
    		    } finally {
    				out.close();
    		    }
    		} catch (IOException e) {
    			e.printStackTrace();
    		}
    	}
    	
    	public static void addIpToMuteFile(String Name) {
    		try {
    			BufferedWriter out = new BufferedWriter(new FileWriter("./Data/bans/IpsMuted.txt", true));
    		    try {
    				out.newLine();
    				out.write(Name);
    		    } finally {
    				out.close();
    		    }
    		} catch (IOException e) {
    			e.printStackTrace();
    		}
    	}
    	
    	public static boolean isMuted(Client c) {
    		if (mutedNames.contains(c.playerName.toLowerCase()) || mutedIps.contains(c.connectedFrom))
    			return true;
    		else
    			return false;
    	}
    }


    Menacescape - Runescape Private server
    Come to Menacescape. We've been online for over two years with an active community!
    Reply With Quote  
     

  2. #2  
    Registered Member
    gomomo11's Avatar
    Join Date
    May 2010
    Posts
    2,379
    Thanks given
    268
    Thanks received
    196
    Rep Power
    177
    Linux? If so, then make sure the data folder is case-sensitive. I don't see anything wrong with the code.
    Attached image
    no external links without affiliate
    Reply With Quote  
     

  3. #3  
    Registered Member

    Join Date
    Feb 2007
    Age
    28
    Posts
    6,414
    Thanks given
    354
    Thanks received
    323
    Rep Power
    5000
    Quote Originally Posted by gomomo11 View Post
    Linux? If so, then make sure the data folder is case-sensitive. I don't see anything wrong with the code.
    It is, i don't understand.


    Menacescape - Runescape Private server
    Come to Menacescape. We've been online for over two years with an active community!
    Reply With Quote  
     

  4. #4  
    Registered

    Izumi's Avatar
    Join Date
    Jun 2010
    Posts
    2,458
    Thanks given
    240
    Thanks received
    597
    Rep Power
    2463
    It worked last time I got banned, mate.



    Reply With Quote  
     

  5. #5  
    I'm Baack...


    Join Date
    Mar 2011
    Posts
    1,663
    Thanks given
    281
    Thanks received
    202
    Rep Power
    324
    Have you tried plain replacing yours with someone else's? There may be something that you cant see that they have fixed, and your connection.java is pretty generic.

    Also try comparing all your methods to someone's whose command works properly.
    I'm back
    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

Similar Threads

  1. Command not working? [Rep++]
    By FinalBlitzKen in forum Help
    Replies: 10
    Last Post: 06-22-2012, 08:52 PM
  2. PI Command not working
    By LiilCraZy in forum Help
    Replies: 4
    Last Post: 12-09-2011, 01:15 AM
  3. working ::giveitem command?
    By OodlesOfNoodles in forum Help
    Replies: 8
    Last Post: 05-27-2011, 02:01 AM
  4. [PI] Need help to get command working [PI]
    By My t4rg fail in forum Help
    Replies: 9
    Last Post: 10-11-2010, 10:35 PM
  5. Yell command not working
    By mitch123hoff in forum Help
    Replies: 7
    Last Post: 10-31-2008, 06:42 AM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •