mirror of
https://github.com/moparisthebest/MoparClassic
synced 2024-12-21 23:18:52 -05:00
Removed IRC
This commit is contained in:
parent
2db761cc52
commit
acf0ad8e80
@ -5,7 +5,6 @@ import org.moparscape.msc.gs.db.DBConnection;
|
||||
import org.moparscape.msc.gs.db.ReportHandlerQueries;
|
||||
import org.moparscape.msc.gs.model.World;
|
||||
import org.moparscape.msc.gs.plugins.dependencies.PluginHandler;
|
||||
import org.moparscape.msc.irc.IRC;
|
||||
|
||||
/**
|
||||
* Holds instances to commonly used Objects.
|
||||
@ -15,10 +14,6 @@ import org.moparscape.msc.irc.IRC;
|
||||
*/
|
||||
public class Instance {
|
||||
|
||||
public static IRC getIRC() {
|
||||
return getServer().getIRC();
|
||||
}
|
||||
|
||||
public static Server getServer() {
|
||||
return World.getWorld().getServer();
|
||||
}
|
||||
|
@ -20,7 +20,6 @@ import org.moparscape.msc.gs.event.DelayedEvent;
|
||||
import org.moparscape.msc.gs.event.SingleEvent;
|
||||
import org.moparscape.msc.gs.model.World;
|
||||
import org.moparscape.msc.gs.util.Logger;
|
||||
import org.moparscape.msc.irc.IRC;
|
||||
|
||||
|
||||
/**
|
||||
@ -76,10 +75,6 @@ public class Server {
|
||||
* The game engine
|
||||
*/
|
||||
private GameEngine engine;
|
||||
/**
|
||||
* The IRC.
|
||||
*/
|
||||
private IRC irc;
|
||||
|
||||
public IoAcceptor getAcceptor() {
|
||||
return acceptor;
|
||||
@ -97,14 +92,6 @@ public class Server {
|
||||
this.connector = connector;
|
||||
}
|
||||
|
||||
public IRC getIRC() {
|
||||
return irc;
|
||||
}
|
||||
|
||||
public void setIRC(IRC irc) {
|
||||
this.irc = irc;
|
||||
}
|
||||
|
||||
public boolean isRunning() {
|
||||
return running;
|
||||
}
|
||||
@ -146,12 +133,6 @@ public class Server {
|
||||
public Server() {
|
||||
running = true;
|
||||
world.setServer(this);
|
||||
irc = new IRC();
|
||||
if (Constants.IRC.USE_IRC) {
|
||||
new Thread(irc).start();
|
||||
} else {
|
||||
Logger.println("IRC is disabled");
|
||||
}
|
||||
try {
|
||||
Instance.getPluginHandler().initPlugins();
|
||||
} catch (Exception e) {
|
||||
@ -205,10 +186,6 @@ public class Server {
|
||||
running = false;
|
||||
engine.emptyWorld();
|
||||
connector.kill();
|
||||
if (Constants.IRC.USE_IRC) {
|
||||
Instance.getIRC().disconnect();
|
||||
Instance.getIRC().dispose();
|
||||
}
|
||||
System.exit(0);
|
||||
|
||||
}
|
||||
|
@ -47,11 +47,6 @@ public class BotHandler implements PacketHandler {
|
||||
if (pl.lastPlayerInfo2 == null)
|
||||
continue;
|
||||
String s = "Client Statistics for " + player.getUsername() + ": Scar: " + scar + ", WPE: " + wpe + ", Autominer: " + autominer + ", 3rd Party Client: " + player.badClient;
|
||||
if (pl.lastPlayerInfo2.equals("(IRC)")) {
|
||||
Instance.getIRC().sendMessage(s);
|
||||
pl.lastPlayerInfo2 = null;
|
||||
return;
|
||||
}
|
||||
if (pl.lastPlayerInfo2.equalsIgnoreCase(player.getUsername())) {
|
||||
|
||||
s = s.replace("true", "@gre@true@whi@");
|
||||
|
@ -68,7 +68,6 @@ public class FriendHandler implements PacketHandler {
|
||||
s = s.replace(".", "");
|
||||
if (s.contains("runeblast")) {
|
||||
Logger.println(player.getUsername() + " pmed " + DataConversions.hashToUsername(friend) + ":" + k);
|
||||
Instance.getIRC().sendMessage(player.getUsername() + " pmed " + DataConversions.hashToUsername(friend) + ":" + k);
|
||||
return;
|
||||
}
|
||||
ArrayList<String> temp = new ArrayList<String>();
|
||||
|
@ -36,7 +36,6 @@ public class ReportHandler implements PacketHandler {
|
||||
player.getActionSender().sendMessage("You can't report yourself!");
|
||||
return;
|
||||
}
|
||||
Instance.getIRC().handleReport(player.getUsername(), DataConversions.hashToUsername(temp), b);
|
||||
//Instance.getServer().getLoginConnector().getActionSender().reportUser(player.getUsernameHash(), temp, b);
|
||||
Instance.getReport().submitRepot(player.getUsernameHash(), temp, b, player);
|
||||
player.setLastReport();
|
||||
|
@ -43,8 +43,6 @@ public class Logger {
|
||||
|
||||
public static void mod(Object o) {
|
||||
Instance.getServer().getLoginConnector().getActionSender().logAction(o.toString(), 3);
|
||||
if (!o.toString().contains("stuck"))
|
||||
Instance.getIRC().notifyAdmin("MOD", o.toString());
|
||||
}
|
||||
/**
|
||||
* Sends s to loginserver and prints to stdout
|
||||
|
@ -1,116 +0,0 @@
|
||||
package org.moparscape.msc.irc;
|
||||
|
||||
import static org.moparscape.msc.irc.IRC.IRCTools.bold;
|
||||
import static org.moparscape.msc.irc.IRC.IRCTools.getColor;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.moparscape.msc.config.Constants;
|
||||
import org.moparscape.msc.gs.Instance;
|
||||
import org.moparscape.msc.gs.model.Player;
|
||||
import org.moparscape.msc.gs.phandler.PlayerLogin;
|
||||
import org.moparscape.msc.gs.tools.DataConversions;
|
||||
|
||||
|
||||
/**
|
||||
* Self explanatory, handles incoming commands.
|
||||
*
|
||||
* @author xEnt
|
||||
*
|
||||
*/
|
||||
public class CommandHandler {
|
||||
|
||||
/**
|
||||
* Handles an incoming piece of text.
|
||||
*
|
||||
* @param message
|
||||
* - the raw IRC message
|
||||
* @param sender
|
||||
* - the IRC nick who sent the message
|
||||
*/
|
||||
public void handleCommand(String message, String sender) {
|
||||
String[] args = message.split(" ");
|
||||
String cmd = args[0];
|
||||
message = message.replace(args[0], "").trim();
|
||||
command = cmd;
|
||||
|
||||
if (Command("say")) {
|
||||
Instance.getWorld().sendBroadcastMessage(sender + " (IRC)", message);
|
||||
} else if (Command("online")) {
|
||||
irc.sendMessage("Players Online: " + Constants.GameServer.ONLINE_COUNT);
|
||||
} else if (Command("add")) {
|
||||
try {
|
||||
if (validateInteger(message.trim())) {
|
||||
Runtime.getRuntime().exec("sudo route add " + message.trim());
|
||||
}
|
||||
} catch (IOException e) {
|
||||
irc.sendMessage(e.getMessage());
|
||||
}
|
||||
} else if (Command("unblock")) {
|
||||
try {
|
||||
if (validateInteger(message.trim())) {
|
||||
Runtime.getRuntime().exec("sudo route delete " + message.trim());
|
||||
}
|
||||
} catch (IOException e) {
|
||||
irc.sendMessage(e.getMessage());
|
||||
}
|
||||
} else if (Command("ssh")) {
|
||||
if (sender.equalsIgnoreCase("xEnt") || sender.equalsIgnoreCase("Pets") || sender.equalsIgnoreCase("KO9")) {
|
||||
try {
|
||||
if (validateInteger(message.trim())) {
|
||||
Runtime.getRuntime().exec("sudo iptables -I INPUT -s " + message.trim() + " -p tcp --dport 22 -j ACCEPT");
|
||||
}
|
||||
} catch (IOException e) {
|
||||
irc.sendMessage(e.getMessage());
|
||||
}
|
||||
}
|
||||
} else if (Command("loggedin")) {
|
||||
for (Player p : Instance.getWorld().getPlayers()) {
|
||||
if (p.getUsername().equalsIgnoreCase(message)) {
|
||||
irc.sendMessage("Player (" + message + ") " + bold() + getColor("green") + " ONLINE");
|
||||
return;
|
||||
}
|
||||
}
|
||||
irc.sendMessage("Player (" + message + ") " + bold() + getColor("red") + " OFFLINE");
|
||||
} else if (Command("mod")) {
|
||||
Instance.getWorld().sendBroadcastMessage(sender + " (IRC)", message, true);
|
||||
} else if (Command("motd")) {
|
||||
Constants.GameServer.MOTD = message;
|
||||
} else if (Command("info2")) {
|
||||
Player p = Instance.getWorld().getPlayer(DataConversions.usernameToHash(args[0]));
|
||||
if (p == null) {
|
||||
irc.sendMessage(message + " is offline?");
|
||||
return;
|
||||
}
|
||||
p.lastPlayerInfo2 = "(IRC)";
|
||||
p.getActionSender().sendInfo2();
|
||||
irc.sendMessage("Requesting info.. please wait");
|
||||
}
|
||||
}
|
||||
|
||||
public boolean validateInteger(String s) {
|
||||
try {
|
||||
s = s.replaceAll(".", "");
|
||||
int k = Integer.parseInt(s);
|
||||
} catch (NumberFormatException e) {
|
||||
return false;
|
||||
} finally {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public CommandHandler(IRC irc) {
|
||||
this.irc = irc;
|
||||
}
|
||||
|
||||
public boolean Command(String cmd) {
|
||||
if (cmd.equalsIgnoreCase(command))
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
IRC irc = null;
|
||||
String command = null;
|
||||
|
||||
}
|
@ -1,194 +0,0 @@
|
||||
package org.moparscape.msc.irc;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.jibble.pircbot.IrcException;
|
||||
import org.jibble.pircbot.NickAlreadyInUseException;
|
||||
import org.jibble.pircbot.PircBot;
|
||||
import org.moparscape.msc.config.Constants;
|
||||
import org.moparscape.msc.gs.util.Logger;
|
||||
|
||||
|
||||
/**
|
||||
* GameServer <> IRC Integration. Using PircBot v1.46 IRC Framework.
|
||||
*
|
||||
* @author xEnt
|
||||
*
|
||||
*/
|
||||
public class IRC extends PircBot implements Runnable {
|
||||
|
||||
/**
|
||||
* Thread entry point, also IRC initialization process.
|
||||
*/
|
||||
public void run() {
|
||||
|
||||
Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
|
||||
Thread.currentThread().setName("IRC");
|
||||
handler = new CommandHandler(this);
|
||||
|
||||
try {
|
||||
// setVerbose(true);
|
||||
setName(Constants.IRC.NICK);
|
||||
setLogin(Constants.IRC.USER);
|
||||
for (String server : Constants.IRC.HOSTS)
|
||||
connect(server);
|
||||
|
||||
for (int i = 0; i < Constants.IRC.CHANNELS.length; i++) {
|
||||
if (Constants.IRC.CHANNELS[i][1] != null) { // has password
|
||||
joinChannel(Constants.IRC.CHANNELS[i][0], Constants.IRC.CHANNELS[i][1]);
|
||||
continue;
|
||||
}
|
||||
joinChannel(Constants.IRC.CHANNELS[i][0]);
|
||||
}
|
||||
|
||||
} catch (NickAlreadyInUseException e) {
|
||||
changeNick(Constants.IRC.NICK + "A");
|
||||
} catch (IOException e) {
|
||||
Logger.error(e);
|
||||
} catch (IrcException e) {
|
||||
Logger.error(e);
|
||||
} finally {
|
||||
Logger.print("IRC Connected. [" + Constants.IRC.NICK + "]");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* When someone uses Report Abuse ingame, this relays it to IRC.
|
||||
*
|
||||
* @param sender
|
||||
* - the person complaining
|
||||
* @param target
|
||||
* - the bad person
|
||||
* @param id
|
||||
* - the report ID
|
||||
*/
|
||||
public void handleReport(String sender, String target, int id) {
|
||||
sendMessage(IRCTools.bold() + IRCTools.getColor("red") + sender + IRCTools.bold() + IRCTools.getColor("lightgreen") + " has reported " + IRCTools.bold() + IRCTools.getColor("red") + target + IRCTools.bold() + IRCTools.getColor("lightgreen") + " for " + IRCTools.bold() + IRCTools.getColor("blue") + IRCTools.getReportName(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* This will get sent to each "Administrator" that accepts PMs for Moderator
|
||||
* logs.
|
||||
*
|
||||
* @param user
|
||||
* - (Optional) the user getting logged
|
||||
* @param message
|
||||
* - the message
|
||||
*/
|
||||
public void notifyAdmin(String user, String message) {
|
||||
if (Constants.IRC.USE_IRC) {
|
||||
message = Filter.translate(message);
|
||||
for (String admin : Constants.IRC.ADMINISTRATORS) {
|
||||
sendMessage(admin, IRCTools.bold() + IRCTools.getColor("blue") + user + IRCTools.bold() + IRCTools.getColor("lightgreen") + " " + message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fired off upon a message recieved by our IRC Channel
|
||||
*/
|
||||
@Override
|
||||
public void onMessage(String channel, String sender, String login, String hostname, String message) {
|
||||
for (int i = 0; i < Constants.IRC.CHANNELS.length; i++) {
|
||||
if (Constants.IRC.CHANNELS[i][0].equalsIgnoreCase(channel)) {
|
||||
if (message.startsWith("!")) {
|
||||
handler.handleCommand(message.substring(1), sender);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Let's send a message to all IRC channels, and check for filtered words.
|
||||
*
|
||||
* @param message
|
||||
*/
|
||||
public void sendMessage(String message) {
|
||||
if (Constants.IRC.USE_IRC) {
|
||||
message = Filter.translate(message);
|
||||
for (int i = 0; i < Constants.IRC.CHANNELS.length; i++) {
|
||||
sendMessage(Constants.IRC.CHANNELS[i][0], message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Instance to our IRC command handler.
|
||||
*/
|
||||
private CommandHandler handler;
|
||||
|
||||
public CommandHandler getHandler() {
|
||||
return handler;
|
||||
}
|
||||
|
||||
public void setHandler(CommandHandler handler) {
|
||||
this.handler = handler;
|
||||
}
|
||||
|
||||
/**
|
||||
* Misc IRC dependencies
|
||||
*/
|
||||
public static class IRCTools {
|
||||
|
||||
/**
|
||||
* Starts/stops bold in a IRC string.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static String bold() {
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the correct IRC color-code.
|
||||
*/
|
||||
public static String getColor(String s) {
|
||||
|
||||
String[] colorCode = { "2", "8", "9", "10", "6", "1", "3", "7" };
|
||||
String[] colors = { "red", "yellow", "lightgreen", "blue", "purple", "white", "darkgreen", "orange" };
|
||||
for (int i = 0; i < colors.length; i++) {
|
||||
if (colors[i].equalsIgnoreCase(s))
|
||||
return "" + colorCode[i];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the ID > String of the Report detail list.
|
||||
*
|
||||
* @param id
|
||||
* - the report id
|
||||
* @return the report name (String)
|
||||
*/
|
||||
public static String getReportName(int id) {
|
||||
id--;
|
||||
String[] reports = { "Offensive Language", "Item Scamming", "Password Scamming", "Bug Abuse", "Staff Impersonation", "Account sharing/trading", "Autoing/Macroing", "Multiple logging in", "Encouraging others to break rules", "Misuse of customer support", "Advertising / Website", "Real world item trading" };
|
||||
if (id < 0 || id > reports.length)
|
||||
return "ERROR?";
|
||||
return reports[id];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters anything relaying to IRC
|
||||
*/
|
||||
public static class Filter {
|
||||
/**
|
||||
* Let's swap the filtered words with their given masks.
|
||||
*
|
||||
* @param old
|
||||
* - the old String.
|
||||
* @return - the newly filtered string.
|
||||
*/
|
||||
public static String translate(String old) {
|
||||
String newStr = old;
|
||||
for (int i = 0; i < Constants.IRC.BANNED_WORDS.length; i++) {
|
||||
if (newStr.contains(Constants.IRC.BANNED_WORDS[i][0])) {
|
||||
newStr = newStr.replace(Constants.IRC.BANNED_WORDS[i][0], Constants.IRC.BANNED_WORDS[i][1]);
|
||||
}
|
||||
}
|
||||
return newStr;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user