Thread: [317 Pi] Ban Command, Unban, Givemod, giveadmin, giveowner, givedonor only kicks!

Results 1 to 5 of 5
  1. #1 [317 Pi] Ban Command, Unban, Givemod, giveadmin, giveowner, givedonor only kicks! 
    Registered Member
    Join Date
    Apr 2013
    Posts
    3
    Thanks given
    0
    Thanks received
    0
    Rep Power
    0
    I'm using Trisidiax V3 source, when I try to ban a player, it only disconnects them and they can log straight back in.
    Same with givemod, admin owner etc.

    Spoiler for Commands.java:
    if (playerCommand.startsWith("ban")) {
    try {
    String playerToBan = playerCommand.substring(4);
    Connection.addNameToBanList(playerToBan);
    for(int i = 0; i < Config.MAX_PLAYERS; i++) {
    if(Server.playerHandler.players[i] != null) {
    if(Server.playerHandler.players[i].playerName.equalsIgnoreCase(playerToBan)) {
    }
    }
    }
    } catch(Exception e) {
    //c.sendMessage("Player Must Be Offline.");
    }
    }



    Spoiler for Connection.java:
    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() {
    appendStarters();
    appendStarters2();
    banUsers();
    banIps();
    muteUsers();
    muteIps();
    }

    /***
    *This was used for TrisidiaX source
    *Property Of Trisidia
    */
    public static void appendStarters() {
    try {
    BufferedReader in = new BufferedReader(new FileReader("./Data/1.)TrisidiaX Player/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/1.)TrisidiaX Player/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/1.)TrisidiaX Player/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/1.)TrisidiaX Player/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;
    }
    /**
    * 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/1.)TrisidiaX Player/Player Punishments/UsersMuted.txt", name);
    }

    public static void unIPMuteUser(String name) {
    mutedIps.remove(name);
    deleteFromFile("./Data/1.)TrisidiaX Player/Player Punishments/IpsMuted.txt", name);
    }
    public static void unIPBanUser(String IP) {
    bannedIps.remove(IP);
    deleteFromFile("./Data/1.)TrisidiaX Player/Player Punishments/IpsBanned.txt", IP);
    }

    /**
    * 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/1.)TrisidiaX Player/Player Punishments/UsersBanned.txt", name);
    }

    public static void removeNameFromMuteList(String name) {
    bannedNames.remove(name.toLowerCase());
    deleteFromFile("./Data/1.)TrisidiaX Player/Player Punishments/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;
    }


    /**
    * 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/1.)TrisidiaX Player/Player Punishments/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/1.)TrisidiaX Player/Player Punishments/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/1.)TrisidiaX Player/Player Punishments/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/1.)TrisidiaX Player/Player Punishments/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/1.)TrisidiaX Player/Player Punishments/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/1.)TrisidiaX Player/Player Punishments/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/1.)TrisidiaX Player/Player Punishments/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/1.)TrisidiaX Player/Player Punishments/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;
    }
    }


    Please reply ASAP, thank you.
    -Holy Sin.
    Reply With Quote  
     

  2. #2  
    Donator
    Darkness's Avatar
    Join Date
    Nov 2012
    Age
    26
    Posts
    876
    Thanks given
    121
    Thanks received
    75
    Rep Power
    47
    Too lazy to check anything into your own code so here's the one in my source >.< if that might help, it's probably universal ahahaha if it doesn't, reply and i'll get to check, or if doesn't help at all and you really want yours fixed, then tell me. Please use something like notepad++ to put your things in code forms ( with tabs etc)

    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(PlayerHandler.players[i] != null) {
    						if(PlayerHandler.players[i].playerName.equalsIgnoreCase(playerToBan)) {
    							PlayerHandler.players[i].disconnected = true;
    							Client c2 = (Client)PlayerHandler.players[i];
    							c2.sendMessage(" " +c2.playerName+ " Got Banned By " + c.playerName+ ".");
    						} 
    					}
    				}
    			} catch(Exception e) {
    				c.sendMessage("Player Must Be Offline.");
    			}
    		}
    Connections

    Code:
    	public static void addNameToBanList(String name) {
    		bannedNames.add(name.toLowerCase());
    	}
    Code:
    	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();
    		}
    	}
    Code:
    	public static boolean isNamedBanned(String name) {
    		if(bannedNames.contains(name.toLowerCase())) {
    			return true;
    		}
    		return false;
    	}
    Attached image
    Reply With Quote  
     

  3. #3  
    Registered Member
    Join Date
    Apr 2013
    Posts
    3
    Thanks given
    0
    Thanks received
    0
    Rep Power
    0
    Just tried it, no errors when compiling but still disconnects instead of bans.

    Also I changed "BufferedReader in = new BufferedReader(new FileReader("./Data/bans/UsersBanned.txt"));"
    to "BufferedReader in = new BufferedReader(new FileReader("./Data/1.)TrisidiaX Player/Player Punishments/UsersBanned.txt"));"

    Because that is the file folders.
    Reply With Quote  
     

  4. #4  
    Server Developer
    Argyros's Avatar
    Join Date
    Apr 2011
    Posts
    498
    Thanks given
    25
    Thanks received
    31
    Rep Power
    23
    Then it seems that your server is not saving any of the bans in the file?
    open up: connection.java and find
    Code:
    public static void banUsers() {
    in there you should see something like this
    Code:
    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();
    		}
    	}
    Make sure this is correct:
    BufferedReader in = new BufferedReader(new FileReader("./Data/bans/UsersBanned.txt"));

    That is where all your user who get banned are written to.
    Reply With Quote  
     

  5. #5  
    Registered Member
    Join Date
    Apr 2013
    Posts
    3
    Thanks given
    0
    Thanks received
    0
    Rep Power
    0
    Quote Originally Posted by Evolution0521 View Post
    Then it seems that your server is not saving any of the bans in the file?
    open up: connection.java and find
    Code:
    public static void banUsers() {
    in there you should see something like this
    Code:
    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();
    		}
    	}
    Make sure this is correct:
    BufferedReader in = new BufferedReader(new FileReader("./Data/bans/UsersBanned.txt"));

    That is where all your user who get banned are written to.
    Tried this, still only kicks :/
    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. Replies: 2
    Last Post: 12-19-2012, 05:51 PM
  2. 317 PI how to unban anyone
    By Cody289 in forum Tutorials
    Replies: 12
    Last Post: 06-24-2012, 04:08 PM
  3. 317 Pi couple commands.
    By walex80 in forum Help
    Replies: 3
    Last Post: 11-21-2011, 11:38 PM
  4. 317 pi backup command
    By walex80 in forum Help
    Replies: 5
    Last Post: 11-20-2011, 10:41 PM
  5. giveadmin,givemod,demote,giveowner commands
    By Icy Whip in forum Tutorials
    Replies: 16
    Last Post: 11-29-2007, 02:00 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
  •