Thread: Trey's 525 Banning system

Results 1 to 10 of 10
  1. #1 Trey's 525 Banning system 
    Banned
    Join Date
    Mar 2010
    Posts
    56
    Thanks given
    4
    Thanks received
    1
    Rep Power
    0
    Before you start: this is for real 525's not z525 or 508's with 525 cache. Also not sure if this still works a user here found it on a diffrent site but it was hard to read so i rewrite it.


    Alright lets start. save this as

    punishHandler.java
    Put punishHandler class in Server525\src\com\rs2hd\model

    Code:
    package com.rs2hd.model;
    
    import java.util.*;
    import java.io.*;
    
    import org.apache.mina.common.IoSession;
    
    import com.rs2hd.io.XStreamPlayerLoader;
    
    public class punishHandler
    {
    public static List<String> banned = new ArrayList<String>();
    public static List<String> muted = new ArrayList<String>();
    public static List<String> ipbanned = new ArrayList<String>();
    public static List<String> ipmuted = new ArrayList<String>();
    
    public punishHandler()
    {
    updateAll();
    }
    
    public static void updateAll()
    {
    banUpdate();
    ipbanUpdate();
    muteUpdate();
    ipmuteUpdate();
    }
    
    public static void banUpdate()
        {
            banned.clear();
            try
            {        
                BufferedReader in = new BufferedReader(new FileReader("data/text/bans.txt"));
                String inFile;
                while ((inFile = in.readLine()) != null)
                {
                    banned.add(inFile);
                }
            } catch (Exception e) {}
        }
    
    public static void ipmuteUpdate()
        {
            ipmuted.clear();
            try
            {        
                BufferedReader in = new BufferedReader(new FileReader("data/text/ipmutes.txt"));
                String inFile;
                while ((inFile = in.readLine()) != null)
                {
                    ipmuted.add(inFile);
                }
            } catch (Exception e) {}
        }
    
    public static void muteUpdate()
        {
            muted.clear();
            try
            {        
                BufferedReader in = new BufferedReader(new FileReader("data/text/mutes.txt"));
                String inFile;
                while ((inFile = in.readLine()) != null)
                {
                    muted.add(inFile);
                }
            } catch (Exception e) {}
        }
    
    public static void ipbanUpdate()
        {
            ipbanned.clear();
            try
            {        
                BufferedReader in = new BufferedReader(new FileReader("data/text/ipbans.txt"));
                String inFile;
                while ((inFile = in.readLine()) != null)
                {
                    ipbanned.add(inFile);
                }
            } catch (Exception e) {}
        }
    
    public void writeTo(String name, String path)
        {
            BufferedWriter bw = null;
            try
            {
                bw = new BufferedWriter(new FileWriter(path +".txt", true));
                bw.write(name);
                bw.newLine();
                bw.flush();
            }
    catch (IOException ioe)
    {
                ioe.printStackTrace();
            }
    finally
    {
                if (bw != null)
    {
                    try
                    {
                        bw.close();
                    } catch (IOException ioe2) {
                        System.out.println("Error writing system log.");
                        ioe2.printStackTrace();
                    }
    }
            }
            updateAll();
        }
    
    public void deleteFrom(String name, String path)
        {
            if (name != null)
            {
                File file = new File(path + ".txt");
                if (file.exists())
                {    
                    try
                    {
                        BufferedReader in = new BufferedReader(new FileReader(file));
                        BufferedWriter out = new BufferedWriter(new FileWriter(file));
                        String inFile;
                        while ((inFile = in.readLine()) != null)
                        {
                            if (inFile.equalsIgnoreCase(name))
                                out.write(inFile);
                        }
                    } catch (Exception e) {}
                }
            }
            updateAll();
        }
    
    public boolean isBanned(String name)
        {
            updateAll();
            if (banned.contains(name))
                return true;
            return false;
        }
    
    public boolean isIpBanned(IoSession session)
        {
            String ip = session.getRemoteAddress().toString();
            updateAll();
            if (ipbanned.contains(ip))
                return true;
            return false;
        }
    
    public boolean isIpMuted(IoSession session)
        {
            String ip = session.getRemoteAddress().toString();
            updateAll();
            if (ipmuted.contains(ip))
                return true;
            return false;
        }
    
    public boolean isMuted(String name)
        {
            updateAll();
            if (muted.contains(name))
                return true;
            return false;
        }
    
    }
    Now download this folder it has two .java files in it put it in your util folder located:

    Server525\src\com\rs2hd\util

    Link: [Only registered and activated users can see links. ]

    Banned.java
    Put Banned class in Server525\src\com\rs2hd\model

    Code:
    package com.rs2hd.model;
    
    import java.util.*;
    import java.io.*;
    
    import com.rs2hd.io.XStreamPlayerLoader;
    import com.rs2hd.model.Player;
    
    public class Banned
    {
    public static List<String> banned = new ArrayList<String>();
    
    public void banUser(String name) 
    {
    BufferedWriter bw = null;
    try 
    {
    bw = new BufferedWriter(new FileWriter("data/bans.txt", true));
    bw.write(name);
    bw.newLine();
    bw.flush();
    } catch (IOException ioe) {
    ioe.printStackTrace();
    } finally {
    if (bw != null)
    try 
    {
    bw.close();
    } catch (IOException ioe2) {
    System.out.println("Error writing system log.");
    ioe2.printStackTrace();
    }
    }
    update();
    }
    
    public boolean isBanned(String name)
    {
    update();
    if (banned.contains(name)) 
    return true;
    return false;
    }
    
    public void unBan(String name)
    {
    if (name != null)
    {
    File file = new File("data/bans.txt");
    if (file.exists()) 
    {    
    try 
    {
    BufferedReader in = new BufferedReader(new FileReader(file));
    BufferedWriter out = new BufferedWriter(new FileWriter(file));
    String inFile;
    while ((inFile = in.readLine()) != null) 
    {
    if (inFile.equalsIgnoreCase(name)) {} 
    else 
    out.write(inFile);
    }
    } catch (Exception e) {}
    } 
    }
    update();
    }
    
    public static void update()
    {
    banned.clear();
    try
    {    
    BufferedReader in = new BufferedReader(new FileReader("data/bans.txt"));
    String inFile;
    while ((inFile = in.readLine()) != null)
    {
    banned.add(inFile);
    }
    } catch (Exception e) {}
    }
    
    public Banned()
    {
    update();
    }
    }
    Now add these commands located in: Server525\src\com\rs2hd\packethandler\commands

    banuser.java

    Code:
    package com.rs2hd.packethandler.commands;
    
    import com.rs2hd.model.Player;
    import com.rs2hd.io.XStreamPlayerLoader;
    import com.rs2hd.Constants;
    import com.rs2hd.model.*;
    import com.rs2hd.net.Packet;
    
    public class banuser implements Command
    {
    @Override
    public void execute(Player player, String command)
    {
    String ban = command.substring(;
    XStreamPlayerLoader.punish.writeTo(ban, "/data/text/bans");
    player.sm((new StringBuilder()).append("You have banned ").append(ban).toString());
    for(Player p : World.getInstance().getPlayerList())
    {
    if(p.getUsername().equalsIgnoreCase(ban))
    {
    p.getActionSender().logout();
    }
    }
    }
    
    @Override
    public int getRights()
    {
    return 2;
    }
    }
    ipban.java

    Code:
    package com.rs2hd.packethandler.commands;
    
    import com.rs2hd.model.Player;
    import com.rs2hd.io.XStreamPlayerLoader;
    import com.rs2hd.Constants;
    import com.rs2hd.model.*;
    import com.rs2hd.net.Packet;
    
    public class ipban implements Command
    {
    @Override
    public void execute(Player player, String command)
    {
    String ban = command.substring(6);
    XStreamPlayerLoader.punish.writeTo(ban, "/data/text/ipbans");
    player.sm((new StringBuilder()).append("You have ipbanned ").append(ban).toString());
    for(Player p : World.getInstance().getPlayerList())
    {
    if(p.getUsername().equalsIgnoreCase(ban))
    {
    p.getActionSender().logout();
    }
    }
    }
    
    @Override
    public int getRights()
    {
    return 2;
    }
    }
    ipmute.java

    Code:
    package com.rs2hd.packethandler.commands;
    
    import com.rs2hd.model.Player;
    import com.rs2hd.io.XStreamPlayerLoader;
    import com.rs2hd.Constants;
    import com.rs2hd.model.*;
    import com.rs2hd.net.Packet;
    
    public class ipmute implements Command
    {
    @Override
    public void execute(Player player, String command)
    {
    String ban = command.substring(7);
    XStreamPlayerLoader.punish.writeTo(ban, "/data/text/ipmutes");
    player.sm((new StringBuilder()).append("You have ipmuted ").append(ban).toString());
    for(Player p : World.getInstance().getPlayerList())
    {
    if(p.getUsername().equalsIgnoreCase(ban))
    {
    p.getActionSender().logout();
    }
    }
    }
    
    @Override
    public int getRights()
    {
    return 2;
    }
    }
    mute.java

    Code:
    package com.rs2hd.packethandler.commands;
    
    import com.rs2hd.model.Player;
    import com.rs2hd.io.XStreamPlayerLoader;
    
    public class mute implements Command
    {
    @Override
    public void execute(Player player, String command)
    {
    String mute = command.substring(6);
    XStreamPlayerLoader.punish.writeTo(mute, "/data/text/mutes");
    player.sm((new StringBuilder()).append("You have muted ").append(mute).toString());
    }
    
    @Override
    public int getRights()
    {
    return 1;
    }
    }
    unban.java

    Code:
    package com.rs2hd.packethandler.commands;
    
    import com.rs2hd.model.Player;
    import com.rs2hd.io.XStreamPlayerLoader;
    
    public class unban implements Command
    {
    @Override
    public void execute(Player player, String command)
    {
    String ban = command.substring(6);
    XStreamPlayerLoader.punish.deleteFrom(ban, "/data/text/mutes");
    player.sm((new StringBuilder()).append("You have unbanned ").append(ban).toString());
    }
    
    @Override
    public int getRights()
    {
    return 2;
    }
    }
    unmute.java

    Code:
    package com.rs2hd.packethandler.commands;
    
    import com.rs2hd.model.Player;
    import com.rs2hd.io.XStreamPlayerLoader;
    
    public class unmute implements Command
    {
    @Override
    public void execute(Player player, String command)
    {
    String mute = command.substring(7);
    XStreamPlayerLoader.punish.deleteFrom(mute, "/data/text/mutes");
    player.sm((new StringBuilder()).append("You have unmuted ").append(mute).toString());
    }
    
    @Override
    public int getRights()
    {
    return 1;
    }
    }
    Alright now add these to your commmandmanager class file
    Code:
    commandMap.put("banuser", new banuser());
    commandMap.put("unban", new unban());
    commandMap.put("mute", new mute());
    commandMap.put("unmute", new unmute());
    commandMap.put("ipban", new ipban());
    Alright now we need to modify XStreamPlayerLoader class
    Add these imports
    Code:
    import org.apache.mina.common.IoSession;
    import com.rs2hd.model.punishHandler;
    import com.rs2hd.Main;
    import java.util.*;
    Now add this instance
    Code:
    public static punishHandler punish = new punishHandler();
    Now replace PlayerLoadResult constructor with this

    Code:
    public PlayerLoadResult load(PlayerDetails p)
    {
    XStream xstream = XStreamUtil.getXStream();
    PlayerLoadResult result = new PlayerLoadResult();
    result.returnCode = Constants.ReturnCodes.INVALID_PASSWORD;
    try
    {
    Player player = (Player) xstream.fromXML(new FileInputStream("data/savedgames/"+p.getUsername()+".xml"));
    player.getPlayerDetails().setSession(p.getSession());
    if(punish.isIpMuted(player.getSession()))
    punish.writeTo(player.getUsername(), "/data/text/mutes");
    if(punish.isBanned(player.getUsername()))
    result.returnCode = Constants.ReturnCodes.BANNED;
    else
    {
    if(!player.getPlayerDetails().getPassword().equals(p.getPassword()))
    result.returnCode = Constants.ReturnCodes.INVALID_PASSWORD;
    else
    {
    if(World.getInstance().isOnline(p.getUsername())) {
    result.returnCode = Constants.ReturnCodes.ALREADY_ONLINE;
    }
    else
    {
    result.player = player;
    result.returnCode = Constants.ReturnCodes.LOGIN_OK;
    Main.frame.updateList();
    }
    }
    }
    }
    catch (FileNotFoundException e)
    {
    result.returnCode = Constants.ReturnCodes.LOGIN_OK;
    result.player = new Player(p);
    result.player = (Player) result.player.readResolve();
    }
    return result;
    }
    Add this import then replace isConnectedOk method with this below (ConnectionThrottleFilter)
    Code:
    import com.rs2hd.io.XStreamPlayerLoader;
    Code:
    public boolean isConnectionOk(IoSession session)
    {
    InetAddress addr = getAddress(session);
    long now = System.currentTimeMillis();
    if (XStreamPlayerLoader.punish.isIpBanned(session))
    return false;
    if (clients.containsKey(addr))
    {
    long lastConnTime = clients.get(addr);
    if (now - lastConnTime < allowedInterval)
    {
    int c = 0;
    if(!counts.containsKey(addr))
    counts.put(addr, 0);
    else
    c = counts.get(addr) + 1;
    if(c >= 350)
    c = 0;
    counts.put(addr, c);
    return false;
    }
    else
    {
    clients.put(addr, now);
    return true;
    }
    }
    else
    {
    clients.put(addr, now);
    return true;
    }
    }
    Now go to communications class and add this import
    Code:
    import com.rs2hd.io.XStreamPlayerLoader;
    now replace handlePublicChat method with this
    Code:
    private void handlePublicChat(Player player, Packet packet)
    {
    if (!XStreamPlayerLoader.punish.isMuted(player.getUsername()))
    {
    try
    {
    int colour = packet.readByte();
    int effects  = packet.readByte();
    int numChars = packet.readByte();
    String text  = Misc.decryptPlayerChat(packet, numChars);
    player.setLastChatMessage(new ChatMessage(colour, numChars, text));
    player.getUpdateFlags().setChatTextUpdateRequired(true);
    }
    catch (Exception e) {}
    }
    else
                    {
    player.sm("You are muted!");
                    }
    }
    }
    now in main class add this instance of the frame class
    Code:
    public static Frame frame = new Frame("Trey's 525 GUI");
    Then add this imports to the same class

    Code:
    import com.rs2hd.util.gui.Frame;
    import com.rs2hd.util.gui.Console;
    now download this and add it to your "Data" folder

    Link: [Only registered and activated users can see links. ]

    Now in ActionSender replace your logout method with this
    Code:
    public void logout() {
    player.getSession().write(new StaticPacketBuilder().setId(102).toPacket()).addListener(new IoFutureListener() {
    @Override
    public void operationComplete(IoFuture arg0) {
    arg0.getSession().close();
    }
    });
    Main.frame.updateList();
    }
    Congratz! you have completed the tutorial

    Picture of GUI:



    If you get errors feel free to post i can try to help you also don't post saying leech.. cause theres credits..

    Credits:
    `Tray | Making most of it (99.9%)
    Lolpl0xme | Making thread and writing it all (0.01%)

    Errors you may/will get
    Code:
    src\com\rs2hd\net\ActionSender.java:249: package Main does not exist
    Main.frame.updateList();
        ^
    1 error
    im not sure what package you need to link... so yeah if you know please post thanks.
    Reply With Quote  
     

  2. #2  
    RuneCasino


    Join Date
    Jul 2007
    Posts
    1,618
    Thanks given
    170
    Thanks received
    228
    Rep Power
    326
    This is w00tsc4p3's gui, you have no business reposting it for free rep.
    Reply With Quote  
     

  3. #3  
    Banned
    Join Date
    Mar 2010
    Posts
    56
    Thanks given
    4
    Thanks received
    1
    Rep Power
    0
    Lmao... you didn't make this `trey did all you did was give him a picture..

    [Only registered and activated users can see links. ]

    also you should learn to read... "i didnt ask for rep i don't give a shit about rep idc if i dont get any from this" i did it to help others."...
    Reply With Quote  
     

  4. #4  
    RuneCasino


    Join Date
    Jul 2007
    Posts
    1,618
    Thanks given
    170
    Thanks received
    228
    Rep Power
    326
    Quote Originally Posted by lolpl0xme View Post
    Lmao... you didn't make this `trey did all you did was give him a picture..

    [Only registered and activated users can see links. ]

    also you should learn to read... "i didnt ask for rep i don't give a shit about rep idc if i dont get any from this" i did it to help others."...
    Look at the date of it. You obviously were desperate for a banning system now after looking for hours you feel like you accomplished something so you released it for credit.

    Me and Trey made up and he deleted his thread. Don't judge over a illogical thread made 2 years ago. I didn't say say I made this, so YOU learn to read.
    Reply With Quote  
     

  5. #5  
    Banned
    Join Date
    Mar 2010
    Posts
    56
    Thanks given
    4
    Thanks received
    1
    Rep Power
    0
    Lol, how would i be desperate. i found it and thought it could be useful.
    Reply With Quote  
     

  6. #6  
    Registered Member
    AndyJay's Avatar
    Join Date
    Jun 2008
    Posts
    1,285
    Thanks given
    38
    Thanks received
    48
    Rep Power
    84
    Either way it looks quite long for something simple like a ban system. This could be done with just a few lines of code instead of like 7 new classes or however many there are I cba counting.

    If it works then good job to whoever created, I wont be using it though. It would also look nicer with proper conventions etc, maybe you should re-write again and clean it up a bit.
    [Only registered and activated users can see links. ]

    Reply With Quote  
     

  7. #7  
    Registered Member
    Join Date
    Aug 2007
    Posts
    453
    Thanks given
    82
    Thanks received
    27
    Rep Power
    53
    Quote Originally Posted by AndyJay123 View Post
    Either way it looks quite long for something simple like a ban system. This could be done with just a few lines of code instead of like 7 new classes or however many there are I cba counting.

    If it works then good job to whoever created, I wont be using it though. It would also look nicer with proper conventions etc, maybe you should re-write again and clean it up a bit.
    I agree, this can be written way easier; but still it's a start.
    Reply With Quote  
     

  8. #8  
    Hi.

    'Mystic Flow's Avatar
    Join Date
    Nov 2007
    Posts
    7,141
    Thanks given
    256
    Thanks received
    1,247
    Rep Power
    3636
    Quote Originally Posted by 1024 View Post
    This is w00tsc4p3's gui, you have no business reposting it for free rep.
    I don't recall you being the one who made that gui???

    [Only registered and activated users can see links. ]

    Reply With Quote  
     

  9. #9  
    RuneCasino


    Join Date
    Jul 2007
    Posts
    1,618
    Thanks given
    170
    Thanks received
    228
    Rep Power
    326
    Quote Originally Posted by 'Mystic Flow View Post
    I don't recall you being the one who made that gui???
    I helped with it... Trey gave it to me.
    Reply With Quote  
     

  10. #10  
    Registered Member
    Join Date
    Jul 2010
    Posts
    154
    Thanks given
    15
    Thanks received
    8
    Rep Power
    1
    yEAH!! REAL 525's FTW!
    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. 525 Banning system?
    By lolpl0xme in forum Help
    Replies: 4
    Last Post: 03-23-2011, 02:38 PM
  2. ip banning
    By mrprostat in forum Help
    Replies: 1
    Last Post: 02-04-2009, 07:51 PM
  3. Replies: 36
    Last Post: 10-09-2008, 12:30 AM
  4. Decent Banning System
    By Daniel in forum Tutorials
    Replies: 9
    Last Post: 09-20-2008, 10:54 AM
  5. TgProtect banning system
    By Cascade in forum Tutorials
    Replies: 15
    Last Post: 05-31-2008, 08:02 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
  •