!unban <Alternative> <Unbans Macs and IP Address Also>

Junior Spellweaver
Joined
Feb 23, 2008
Messages
111
Reaction score
1
Hi, I was about 50% finished making this !unban command when I notice someone released one. However, I notice that the current one doesn't unban macs and ip addresses, and mine does, so I decided I'd finish mine and release it.


Here's the code for CommandProcessor.java:

Code:
else if(splitted[0].equals("!unban"))
            {
                String playerName = splitted[1];
                
                Connection con = DatabaseConnection.getConnection();
                PreparedStatement ps;
                
                int accountid = 0;
                
                try
                {
                    //get points according to town
                    ps = con.prepareStatement("SELECT accountid FROM characters WHERE name = ?");
                    ps.setString(1, playerName);
                    ResultSet rs = ps.executeQuery();
                    if (!rs.next())
                    {
                        ps.close();
                    }
                    accountid = rs.getInt("accountid");
                    ps.close();
                }
                catch (SQLException e) {System.out.println("SQL Exception: " + e);}
                
                String banString = "";
                String macsOrig = "";
                
                try
                {
                    ps = con.prepareStatement("SELECT banreason, macs FROM accounts WHERE id = " + accountid);
                    ResultSet rs = ps.executeQuery();
                    if (!rs.next())
                    {
                        ps.close();
                    }
                    banString = rs.getString("banreason");
                    macsOrig = rs.getString("macs");
                    ps.close();
                }
                catch (SQLException e) {System.out.println("SQL Exception: " + e);}
                
                if(macsOrig != null)
                {
                    int occurs = 0;
                 
                    for(int i = 0; i < macsOrig.length(); i++)
                    {
                        
                          char next = macsOrig.charAt(i);
                          
                          if(next == ',')
                          {
                               occurs++;
                          }
                    }
                    
                    String macs[] = new String[occurs + 1];
                    
                    System.out.println("Creating macs array...");
                    for(int i = 0; i <= occurs; i++)
                    {
                        int offset = 0;
                        
                        if(i > 0)
                            offset = 2;
                        
                        macs[i] = macsOrig.substring((i * 17) + offset, (i * 17) + 17);
                        System.out.println(macs[i]);
                    }
                    
                    for(int i = 0; i < macs.length; i++)
                    {
                        try
                        {
                            ps = con.prepareStatement("DELETE FROM macbans WHERE mac = ?");
                            ps.setString(1, macs[i]);
                            ps.executeUpdate();
                            ps.close();
                        }
                        catch (SQLException e) {System.out.println("SQL Exception: " + e);}
                    }
                    mc.dropMessage("Macs Unbanned");
                }    
                
                if(banString.indexOf("IP: /") != -1)
                {
                    String ip = banString.substring(banString.indexOf("IP: /") + 5, banString.length() - 1);
                    try
                    {
                        ps = con.prepareStatement("DELETE FROM ipbans WHERE ip = ?");
                        ps.setString(1, ip);
                        ps.executeUpdate();
                        ps.close();
                        mc.dropMessage("IP Address Unbanned");
                    }
                    catch (SQLException e) {System.out.println("SQL Exception: " + e);}
                }
                
                
                try
                {
                    ps = con.prepareStatement("UPDATE accounts SET banned = -1, banreason = null WHERE id = " + accountid);
                    ps.executeUpdate();
                    ps.close();
                    mc.dropMessage("Account Unbanned");
                }
                catch (SQLException e) {System.out.println("SQL Exception: " + e);}
                
                
            }



And you'll need to execute this query in your database.
REMEMBER: Always make backups of your database before making any changes

Code:
ALTER TABLE `accounts` MODIFY COLUMN `banreason` VARCHAR(500) CHARACTER SET latin1 COLLATE latin1_swedish_ci;
 
Re: [RELEASE] !unban <Alternative> <Unbans Macs and IP Address Also>

Mine sets banned to -1, unbanning the ip and mac *sigh

But its a good alternative anyway.

I know, I'm not trying to compete or anything, but like I said, I had already started and didn't want what I'd done to go to waste, so I finished it.
 
Re: [RELEASE] !unban <Alternative> <Unbans Macs and IP Address Also>

lol, i already use'd zero's >.<

Oh well, they essentially do the same thing right?
 
Re: [RELEASE] !unban <Alternative> <Unbans Macs and IP Address Also>

Sathon said:
However, I notice that the current one doesn't unban macs and ip addresses, and mine does, so I decided I'd finish mine and release it.

I'm not competing either, more like asking why you included that.
 
Re: [RELEASE] !unban <Alternative> <Unbans Macs and IP Address Also>

I'm not competing either, more like asking why you included that.

This actually removes the ip and mac bans, which insures that they are completely unbanned if, say, they have another account or something, or they have family members that play on the same computer/ip address.
 
Re: [RELEASE] !unban <Alternative> <Unbans Macs and IP Address Also>

Kk, I tested on one of my Gm's and it works just fine..=D
Ty Sathon!
 
Re: [RELEASE] !unban <Alternative> <Unbans Macs and IP Address Also>

i add it to the java file and when i type it in game it dont work
 
Re: [RELEASE] !unban <Alternative> <Unbans Macs and IP Address Also>

How to add it to the .java file??

Just copy Paste it at the end? :S

I don't understand it..

I pasted it in the .java file, but it doesn't work for me..
 
Re: [RELEASE] !unban <Alternative> <Unbans Macs and IP Address Also>

xDutch be sure to paste the .java in jre_6_0 blablabla too ...
 
Re: [RELEASE] !unban <Alternative> <Unbans Macs and IP Address Also>

i add it to the java file and when i type it in game it dont work

Did you make sure you compiled and replace your source code first?

How to add it to the .java file??

Just copy Paste it at the end? :S

I don't understand it..

I pasted it in the .java file, but it doesn't work for me..

Go ahead and paste it all UNDER ALL of this code:
Code:
else if (splitted[0].equals("!ban")) {
				if (splitted.length < 3) {
					new ServernoticeMapleClientMessageCallback(2, c).dropMessage("Syntaxhelper : Syntax: !ban charname reason");
					return true;
                                       
				}
				String originalReason = StringUtil.joinStringFrom(splitted, 2);
				String reason = c.getPlayer().getName() + " banned " + splitted[1] + ": " +
				originalReason;
				MapleCharacter target = cserv.getPlayerStorage().getCharacterByName(splitted[1]);
				if (target != null) {
					String readableTargetName = MapleCharacterUtil.makeMapleReadable(target.getName());
					String ip = target.getClient().getSession().getRemoteAddress().toString().split(":")[0];
					reason += " (IP: " + ip + ")";
                                        String gmsname = player.getName();
					target.ban(reason);
                                        c.getPlayer().getMap().broadcastMessage(MaplePacketCreator.serverNotice(6, "" +  splitted[1] + "  got pwned REAL bad by " + gmsname + " for " + originalReason));
                                      
				} else {
					if (MapleCharacter.ban(splitted[1], reason, false)) {
						mc.dropMessage("Offline Banned " + splitted[1]);
					} else {
						mc.dropMessage("Failed to ban " + splitted[1]);
					}
                                }
			}
 
Re: [RELEASE] !unban <Alternative> <Unbans Macs and IP Address Also>

ps = con.prepareStatement("UPDATE accounts SET banned = -1, banreason = null WHERE id = " + accountid);


Shouldnt it be banned = 0 ?
 
Re: [RELEASE] !unban <Alternative> <Unbans Macs and IP Address Also>

ps = con.prepareStatement("UPDATE accounts SET banned = -1, banreason = null WHERE id = " + accountid);


Shouldnt it be banned = 0 ?

That would work too, I guess the best way to describe it is that -1 is like a "stronger" unban, it really ensures that they get unbanned.
 
Re: [RELEASE] !unban <Alternative> <Unbans Macs and IP Address Also>

So does this work?

Yes, this will unban the banned IP address and the user's Macs as well as their account as opposed to just their account.

The usage is !unban <character name>
 
Back