mirror of
https://github.com/2006-Scape/2006Scape.git
synced 2026-07-03 08:39:04 +00:00
Cleanup part 1 (#213)
* Clean up part 1 - Removed lots of dead code - Removed unncessary files not in use - Cleaned up small bits of code - Removed a few warnings - Server.java ---> GameEngine.java - Constants.java ---> GameConstants.java * Cape Dye Rewrote cape dying * Packaging - redone ----> com.rebotted * PacketSender/clean up - ActionSender ---> PacketSender - Moved many more packets to packetsender - Cleaned up more dead code * Merge Client/Player - Merged Client.java with Player.java (both were doing same thing so redundant to have both) - Removed some more dead code - Tidy a few small things up * Quests/more clean up - Removed more dead code - Made quests static in order to clean them up a bit * More cleanup - Removed some more of the dead quest code - Correcting naming of some of the shop variables
This commit is contained in:
committed by
Daniel Ginovker
parent
3d1ae1b288
commit
d876a923b9
@@ -0,0 +1,315 @@
|
||||
package com.rebotted;
|
||||
|
||||
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 com.rebotted.game.players.Player;
|
||||
|
||||
/**
|
||||
* 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>();
|
||||
|
||||
/**
|
||||
* Adds the banned usernames and ips from the text file to the ban list
|
||||
**/
|
||||
public static void initialize() {
|
||||
banUsers();
|
||||
banIps();
|
||||
muteUsers();
|
||||
muteIps();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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(Player player) {
|
||||
return mutedNames.contains(player.playerName.toLowerCase()) || mutedIps.contains(player.connectedFrom);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user