Thread: Replace old bans with one spreadsheet (Also has 3 day & 7 day temp ban)

Page 1 of 2 12 LastLast
Results 1 to 10 of 14
  1. #1 Replace old bans with one spreadsheet (Also has 3 day & 7 day temp ban) 
    Banned

    Join Date
    Mar 2008
    Posts
    2,595
    Thanks given
    128
    Thanks received
    191
    Rep Power
    0
    NOTE: I heard using apache poi is better than jxl, so I'll be posting a tut on that eventually.

    Purpose: Replace bans with excel spreadsheets. Handles:
    - ip ban
    - Permaban
    - Temp ban (3 days)
    - Temp ban (7 days)
    - Mute
    - No ban

    Difficulty: 4/10
    Tested On: Devolution v7

    YOU MIGHT WANT TO READ THE WHOLE GUIDE IF YOU AREN'T USING DEVOLUTION V7 INSTEAD OF DOING IT FIRST. MAKE A BACKUP TOO.

    Step 1: Make backup. Delete anything to do with old bans.

    Step 2: Download jxl.jar at [Only registered and activated users can see links. ]

    Extract 'jxl.jar' to your java path, for example:

    C:\Program Files\Java\jdk1.6.0_03\bin\

    I would extract there, because I use jdk 1.6.3

    Step 3: Replace compiler w/

    Code:
    @echo off
    title Compiler - By Filth
    "C:\Program Files\Java\jdk1.6.0_03\bin\javac.exe" -classpath "C:\Program Files\Java\jdk1.6.0_03\bin\jxl.jar" *.java
    
    pause
    NOTE: Change the paths! Btw, if you set environmental variables, you can use javac instead of that long thing in beginning.

    Step 4: Add this new class (heavily commented, read it! EXTREMELY EASY TO LEARN SOMETHING NEW)

    Code:
    /*
    	This was made by filth jr, kthx respect.
    
    	Please read the comments so you learn something.
    
    */
    import java.io.File;
    import java.io.IOException;
    import jxl.*;
    import jxl.write.*;
    import jxl.read.biff.BiffException;
    import java.util.Calendar;
    import java.text.SimpleDateFormat;
    
    public class BanHandler {
    
    	public String Date = "None";
    	public boolean muted = false;
    	public int Punishment = 0;
    
    	private String getDate(int days) {
    		SimpleDateFormat sdf = new SimpleDateFormat("M/d/yyyy");
    		Calendar cal = Calendar.getInstance();
    		cal.add(Calendar.DATE, days);
    	return sdf.format(cal.getTime());
    	}
    
    	public boolean bannedHost(String host) {
    		if (Punishment == 5) {
    			return (host.equals(getHost(host))) ? true : false;
    		}
    	return false;
    	}
    
    	public boolean bannedName(String name, String host) {
    		if (name.equals(getName(name))) {
    			if (Punishment == 4) {
    				return true;
    			} else if (Punishment == 1) {
    				muted = true;
    				return false;
    			} else if (Punishment == 2 || Punishment == 3) {
    				String sep[] = Date.split("/");
    				int day = Integer.parseInt(sep[0]);
    				int month = Integer.parseInt(sep[1]);
    				int year = Integer.parseInt(sep[2]);
    				Calendar cal = Calendar.getInstance();
    				cal.set(year, month, day);
    				Calendar cal2 = Calendar.getInstance();
    				int month2 = cal2.get(Calendar.MONTH);
    				int day2 = cal2.get(Calendar.DATE);
    				int year2 = cal2.get(Calendar.YEAR);
    				cal2.set(year2, month2 + 1, day2); // Calendar is different -.- I have to add a month.
    				if (cal.before(cal2)) { // If the date the ban is lifted on is before
    					// the current date, you will be unbanned.
    					writeSheet(name, host, 0);
    					return false;
    				} else {
    					return true;
    				}
    			} else if (Punishment == 0) {
    				return false;
    			} else if (Punishment == 5) {
    				writeSheet("", host, -1); // This fucker came back with a different IP.
    				// Too bad they didn't change accounts :3 BAN THEIR IP AGAIN!
    				return false;
    			}
    		}
    		return false;
    	}
    
    	public String getName(String name) {
    		return readSheet(0, name, null);
    	}
    
    	public String getHost(String host) {
    		return readSheet(1, null, host);
    	}
    
    	/*
    	int banType
    	0 = No ban
    	1 = Mute
    	2 = Temp Ban 3 Days
    	3 = Temp Ban 7 Days
    	4 = Permanent Ban
    	5 = Host Ban
    	*/
    	public void ban(String playerName, String host, int banType) {
    		if (!playerName.equals(null) || !host.equals(null) || banType > -1) {
    			writeSheet(playerName, host, banType);
    		} else {
    			System.out.println("Null error");
    		}
    	}
    
    	public String readSheet(int read, String playerName, String host) { // This method will return a value from a spreadsheet based on the int 'read'
    		try {
    			try {
    				Workbook workbook = Workbook.getWorkbook(new File("config\\ban.xls"));  // Accesses your spread sheet
    				// NOTE: If you are going to do any manual editing to your sheet, make sure that you save it as a
    				// Windows 97-2003 worksheet (in Save As) if you have Excel 2007. It has the extension '.xls'
    
    
    				Sheet sheet = workbook.getSheet(0); // Now we are accessing the sheets in the excel file. We are accessing
    				// Sheet '0', which is the first sheet.
    
    				String valueFound = null; // the value we will be returning at end of String
    
    
    				// Now using a for each loop to, in the end, get the contents of each cell
    				for (int row = 0; row < sheet.getRows(); row++) {
    					boolean vars = false;
    					// Now, the int read comes in. NOTE: The Date and Punishment are ALWAYS read
    						if (read == 0) { // If read == 0, this method will return the player name
    							if (sheet.getCell(0, row).getContents().trim().equals(playerName)) {
    							// If we found the row the player's data is on...
    								valueFound = sheet.getCell(0, row).getContents().trim();
    								vars = true;
    								// DO NOT RETURN HERE. You want to close the workbook first!
    							}
    						} else if (read == 1) { // If read == 1, this method will return the player's host
    							if (sheet.getCell(2, row).getContents().trim().equals(host)) {
    							// If we found the row the player's data is on...
    								valueFound = sheet.getCell(2, row).getContents().trim();
    								vars = true;
    							}
    						}
    					if (vars) { // If we set these values on the wrong row, we will get an error
    					// so this boolean is just a catch.
    						NumberCell nc = (NumberCell) sheet.getCell(1, row);
    						Punishment = (int) nc.getValue();
    						Date = sheet.getCell(3, row).getContents().trim();
    					}
    				}
    
    				workbook.close(); // Don't forget to close the workbook to free some memory.
    				return valueFound;
    			} catch(BiffException ex) {
    				ex.printStackTrace();
    				return null;
    			}
    		}catch(IOException ex2) {
    			ex2.printStackTrace();
    			return null;
    		}
    	}
    
    	public void writeSheet(String playerName, String host, int offense) {
    		try {
    			try {
    				try {
    					boolean WriteOffense = true;
    					if (offense < 0) {
    						WriteOffense = false;
    					}
    					Workbook workbook = Workbook.getWorkbook(new File("config\\ban.xls"));
    					// The reason we are loading the 'reading' workbook is so that we can copy it.
    
    					WritableWorkbook workbookWrite = Workbook.createWorkbook(new File("config\\ban.xls"), workbook);
    					// This is the 'writing' workbook. It has copied all the values of the reading workbook.
    
    					Sheet sheetRead = workbook.getSheet(0); // Sheet used for reading
    
    					WritableSheet sheet = workbookWrite.getSheet(0); // Sheet used for writing
    
    					Label label; // This will later become the value of a cell as a STRING
    					jxl.write.Number number; // This will later become the value of a cell as a NUMBER (holds ints, longs, doubles, etc)
    
    					int row = sheetRead.getRows(); // Finds the first cell without a value
    					// So that you can place data in it.
    
    					int permrow = -1; // IF PLAYER ALREADY LOGGED, DON'T MAKE NEW ENTRY FOR THEM :)
    
    					for (int x = 0; x < row; x++) { // Gets first free spot incase you fuck up your file, and it skips empty spaces (LOLIDIDNTDOTHAT)
    						if (sheetRead.getCell(0, x).getContents().trim().equals(playerName) && playerName.length() > 0) {
    							permrow = x;
    						}
    						if (sheetRead.getCell(0, x).getContents().length() < 1) {
    							row = x;
    							break;
    						}
    					}
    
    					if (permrow > -1) { // if player has already been logged..
    						String loadhost = sheetRead.getCell(2, permrow).getContents().trim();
    						// Loading that player's host...
    
    						if (host != loadhost && host != null && !WriteOffense) { // If they have a new IP...
    							label = new Label(2, row, host); // BAN IT! HAHAHHAA.
    							sheet.addCell(label);
    						}
    					}
    
    					// Writes all new data to empty cells unless a player data is being overwritten
    					label = new Label(2, (permrow > -1) ? permrow : row, host);
    					sheet.addCell(label);
    					if (WriteOffense) { // if you're writing more than a host...
    						if (offense == 2 || offense == 3) { // Adds time to see when ban will be lifed, tempban
    							label = new Label(3, (permrow > -1) ? permrow : row, getDate((offense == 2) ? 3 : 7).trim());
    							sheet.addCell(label);
    						} else { // Does not add time, permaban, mute
    							label = new Label(3, (permrow > -1) ? permrow : row, getDate(0).trim());
    							sheet.addCell(label);
    						}
    						label = new Label(0, (permrow > -1) ? permrow : row, playerName); // Make new label
    						sheet.addCell(label); // Add label
    						number = new jxl.write.Number(1, (permrow > -1) ? permrow : row, offense);
    						sheet.addCell(number);
    					}
    
    					workbookWrite.write(); // Write stuff to workbook.
    					workbook.close();
    					workbookWrite.close(); // Don't forget to close the workbook to free some memory.
    				} catch(BiffException ex) {  // All the exceptions that need to be caught LOL.
    					ex.printStackTrace();
    					return;
    				}
    			} catch(WriteException ex2) {
    				ex2.printStackTrace();
    				return;
    			}
    		}catch(IOException ex3) {
    			ex3.printStackTrace();
    		}
    	}
    }
    Step 5: In your config folder add this file (its the spreadsheet, I made it for you so you don't screw up lol):

    [Only registered and activated users can see links. ]

    Delete all your other ban/mute files in your config folder.

    Step 6: In server.java add this to the boolean 'checkHost'

    Code:
    		if (ban.bannedHost(host)) {
    			return false;
    		}
    		return true;
    and don't forget to declare:

    Code:
    	public static BanHandler ban = new BanHandler();
    Step 7: In client.java add this in the method 'run'

    NOTE: ITS PLACING IS CRUCIAL, LOOK WHERE SIMILAR THINGS ARE POSTED! DO NOT JUST POST IT IN THE BEGINNING OR END OF THE METHOD, OR ANY RANDOM PLACE!!!!!!

    Code:
    			if (server.ban.bannedName(playerName, connectedFrom)) {
    				returnCode = 4;
    				disconnected = true;
    				return;
    			}
    Step 8: Replace your runserver.bat with:

    Code:
    @echo off
    title Running Server
    
    java -classpath "C:\Program Files\Java\jdk1.6.0_03\bin\jxl.jar";. server
    
    pause
    Step 9:

    Don't try to add bans manually until you learn how they work >.<

    this is how you would add a temp ban (3 days):

    Code:
    writeSheet(playerName, connectedFrom, 2);

    NOTE: If you need commands to use this, request and I will post. Although you should be able to add yourself.

    Credits:
    - Me
    - [Only registered and activated users can see links. ]
    - [Only registered and activated users can see links. ]
    Reply With Quote  
     

  2. #2  
    Registered Member Tx-Sec's Avatar
    Join Date
    Jan 2008
    Age
    27
    Posts
    521
    Thanks given
    34
    Thanks received
    15
    Rep Power
    68
    Very nice man. maybe i use lol.
    Reply With Quote  
     

  3. #3  
    Banned

    Join Date
    May 2008
    Posts
    2,327
    Thanks given
    55
    Thanks received
    67
    Rep Power
    0
    Quote Originally Posted by filth jr View Post
    NOTE: If you need commands to use this, request and I will post. Although you should be able to add yourself.
    lol make some commands for it

    also, maybe a way so they can view how many days there banned for left?
    Reply With Quote  
     

  4. #4  
    Banned

    Join Date
    Mar 2008
    Posts
    2,595
    Thanks given
    128
    Thanks received
    191
    Rep Power
    0
    Quote Originally Posted by silabgarza View Post
    lol make some commands for it

    also, maybe a way so they can view how many days there banned for left?
    Tommorow, I cba nao I'm going to bed soon.
    Reply With Quote  
     

  5. #5  
    Banned

    Join Date
    Jul 2008
    Age
    26
    Posts
    5,826
    Thanks given
    1,301
    Thanks received
    197
    Rep Power
    0
    Good except you make it read from a file every time someone tries to connct. Mass connections = epic fail. Lists pl0x. Theres to many methods in there. Shorten it down to one method to check if someone is banned. No use for all of those. Plus your thread accepting connections should be do ing only that. The thing checking for ip banned users inn the serevrs thread is going to lagg all of the incoming connections epicly.
    Reply With Quote  
     

  6. #6  
    Banned

    Join Date
    Mar 2008
    Posts
    2,595
    Thanks given
    128
    Thanks received
    191
    Rep Power
    0
    Nou.

    And it loads fast. Besides, what was your old method doing anyways (reading on connection).

    ---------- Post added at 03:13 PM ---------- Previous post was at 03:02 PM ----------

    I'll change it to make it load on server start and give it up an update method so it can still ban people without restarting server.

    ---------- Post added at 03:46 PM ---------- Previous post was at 03:13 PM ----------

    Ok I made new version I will post laterrrr
    Reply With Quote  
     

  7. #7  
    Austin_
    Guest
    mmm sorta nice =P
    Reply With Quote  
     

  8. #8  
    Registered Member

    Join Date
    Jun 2007
    Posts
    2,237
    Thanks given
    267
    Thanks received
    411
    Rep Power
    1283
    public boolean bannedHost(String host) {
    if (Punishment == 5) {
    return (host.equals(getHost(host))) ? true : false;
    }
    return false;
    }
    Can be simpily done as
    Code:
    public boolean bannedHost(String host) {
    	if (Punishment == 5) {
    		return host.equals(getHost(host));
    	}
    	return false;
    }
    And for the writeSheet method, you can only have one try statement
    instead of
    Code:
    try	{
    		try	{
    			try	{
    			} catch(BiffException ex) { 
    				ex.printStackTrace();
    				return;
    			}
    		} catch(WriteException ex2) {
    			ex2.printStackTrace();
    			return;
    		}
    	} catch(IOException ex3) {
    		ex3.printStackTrace();
    	}
    You can do
    Code:
    try	{
    	} catch(BiffException ex) { 
    		ex.printStackTrace();
    		return;			
    	} catch(WriteException ex2) {
    		ex2.printStackTrace();
    		return;		
    	} catch(IOException ex3) {
    		ex3.printStackTrace();
    	}
    Don't worry, Be happy.
    Reply With Quote  
     

  9. #9  
    Registered Member
    The Myth's Avatar
    Join Date
    Oct 2008
    Posts
    751
    Thanks given
    5
    Thanks received
    9
    Rep Power
    105
    Niceeee man repped , I modded it quite alot to reduce lagg but now my modorater 48 mute option in report abuse is at 100%! =D + ive got the message saying when yours muted and how long your muted for , exactly like runescape. Ty man =D
    Funny how when one person talks to an invisible man and commits acts in their name it's called schizophrenia, but when 1.166 billion people do it simultaneously it's called religion.

    Reply With Quote  
     

  10. #10  
    Banned

    Join Date
    Mar 2008
    Posts
    2,595
    Thanks given
    128
    Thanks received
    191
    Rep Power
    0
    On second thought, I cba to change because I'm working on a better version (apache poi) anyways, so you guys are smart, you can figure it out.
    Reply With Quote  
     

Page 1 of 2 12 LastLast

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
  •