^Wyatt Posted August 22, 2013 Posted August 22, 2013 Well this code is so simple to understand... with this code you can use admin commands through e-mails. You must choose a password that will be the subject of the email; without this password if someone knows the commands and the e-mail you use as "receptor", he won't be able to use it. You can also specify an e-mail sender that will be used to send you back a feedback email with the players on-line, but it's not necessary, you can use it from any e-mail. This feature should be only used if the admin is being, for example, on holidays, so remember to "Enabled = False" if you are at home, to feel safer. I don't really know if this needs more explanation, but here you have and old video. P.S: I know some guys can think that it's not so safe to enable this, OK I know it, I don't need replies 'bout that, if you don't feel safe using it, just don't even look at the topic. Credits: Mhoska & Wyatt Index: dist/game/config/MailController.properties =================================================================== --- dist/game/config/MailController.properties (revision 0) +++ dist/game/config/MailController.properties (revision 0) @@ -0,0 +1,43 @@ +# ----------------------------------------------------------------------------------------------------------- +# MailController +# Developed by Mhoska & Wyatt +# ----------------------------------------------------------------------------------------------------------- +# This tool it's used to land admin commands via e-mail +# ----------------------------------------------------------------------------------------------------------- +# Available commands Information Target Status +# ----------------------------------------------------------------------------------------------------------- +# Restart 120 Restart Time - +# Shutdown 120 Shutdown Time - +# Kick Wyatt Kick PlayerName - +# Ban_Char Wyatt Ban_Char PlayerName Both +# Ban_Acc L2jHidden Ban_Acc PlayerName Both +# Unban_Char Wyatt Unban_Char PlayerName - +# Unban_Acc L2jHidden Unban_Acc PlayerName - +# Jail Wyatt 60 Jail PlayerName Time Both +# UnJail Wyatt UnJail PlayerName Both +# Announce blablabla Announce Text Text... - +# Repair Wyatt Repair PlayerName Must be Offline +# GiveItem Wyatt 57 10 GiveItem PlayerName ItemId ItemCount Must be Online +# GiveItemAll 57 10 GiveItemAll ItemId ItemCount Must be Online +# GetOnlineCount (Gives you a feedback of online players) - +# ----------------------------------------------------------------------------------------------------------- +# Configs +# Note: Recommended to se a new e-mail that will only be used for this script. +# ----------------------------------------------------------------------------------------------------------- +# Enable/Disable the system. +Enabled = True + +# Here you must especify your GMAIL e-mail. +Email = 123456@gmail.com + +# Here you must especify your GMAIL e-mail password. +EmailPassword = 123456 + +# IMPORTANT: Here you must especify your personal password that you'll have to put as Subject +# in every e-mail that you send. +SystemPassword = DumbHoe + +# Here you must especify your personal e-mail that will get a feedback after some commands use. +# Just to get the feedback, you can use commands no matter which email you use. +EmailSender = 654321@gmail.com Index: java/com/l2jserver/gameserver/model/email/Logger.java =================================================================== --- java/com/l2jserver/gameserver/model/email/Logger.java (revision 0) +++ java/com/l2jserver/gameserver/model/email/Logger.java (revision 0) @@ -0,0 +1,118 @@ +/* + * This program is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation, either version 3 of the License, or (at your option) any later + * version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see <http://www.gnu.org/licenses/>. + */ +package com.l2jserver.gameserver.model.email; + +import java.io.*; +import java.util.*; +import javax.mail.*; +import javax.mail.Flags.Flag; +import javax.mail.search.AndTerm; +import javax.mail.search.FlagTerm; +import javax.mail.search.SearchTerm; +import javax.mail.search.SubjectTerm; +import com.sun.mail.imap.IMAPFolder; + +/** + * + * @author Mhoska + * @rework Wyatt + * + */ + +public class Logger +{ + public static String emailpass = ""; + public static String email = ""; + public static String pass = ""; + public static String content = ""; + public static String to = ""; + public static boolean enabled = false; + + public static void main(String[] args) throws MessagingException, IOException + { + IMAPFolder folder = null; + Store store = null; + @SuppressWarnings("unused") + String subject = null; + @SuppressWarnings("unused") + Flag flag = null; + @SuppressWarnings("unused") + String nonsense = "restart"; + + try + { + content = ""; + Properties props = System.getProperties(); + props.setProperty("mail.store.protocol", "imaps"); + Session session = Session.getDefaultInstance(props, null); + store = session.getStore("imaps"); + store.connect("imap.googlemail.com", email, emailpass); + folder = (IMAPFolder) store.getFolder("INBOX"); // This works for the whole inbox + + if(!folder.isOpen()) + { + folder.open(Folder.READ_WRITE); + } + Flags seen = new Flags(Flags.Flag.SEEN); + FlagTerm unseenFlagTerm = new FlagTerm(seen, false); + Flags recent = new Flags(Flags.Flag.RECENT); + @SuppressWarnings("unused") + FlagTerm recentFlagTerm = new FlagTerm(recent, true); + SearchTerm dumb = new SubjectTerm(pass); + SearchTerm searchTerm = new AndTerm(unseenFlagTerm, dumb); + Message[] messages = folder.search(searchTerm); + + for (int i=0; i < messages.length;i++) + { + Message msg = messages[i]; + content = ""+msg.getContent(); + } + } + finally + { + if (folder != null && folder.isOpen()) + { + folder.close(true); + } + if (store != null) + { + store.close(); + } + } + + if (!content.equals("")) + { + Log.Load(content); + } + } + + public static void loadConfigs() + { + try + { + Properties prop = new Properties(); + prop.load(new FileInputStream(new File("./config/MailController.properties"))); + to = prop.getProperty("EmailSender", "123456@gmail.com"); + emailpass = prop.getProperty("EmailPassword", "123456"); + email = prop.getProperty("Email", "123456@gmail.com"); + pass = prop.getProperty("SystemPassword", "DumbHoe"); + enabled = Boolean.parseBoolean(prop.getProperty("Enabled", "True")); + } + catch(Exception e) + { + e.printStackTrace(); + } + } +} \ No newline at end of file Index: java/com/l2jserver/gameserver/GameServer.java =================================================================== --- java/com/l2jserver/gameserver/GameServer.java (revision 5822) +++ java/com/l2jserver/gameserver/GameServer.java (working copy) @@ -117,8 +117,10 @@ import com.l2jserver.gameserver.model.L2World; import com.l2jserver.gameserver.model.PartyMatchRoomList; import com.l2jserver.gameserver.model.PartyMatchWaitingList; +import com.l2jserver.gameserver.model.email.Log; import com.l2jserver.gameserver.model.entity.Hero; import com.l2jserver.gameserver.model.entity.TvTManager; @@ -306,11 +308,13 @@ CursedWeaponsManager.getInstance(); printSection("Scripts"); + Log.getInstance(); QuestManager.getInstance(); TransformationManager.getInstance(); BoatManager.getInstance(); Index: java/com/l2jserver/gameserver/model/email/Packet.java =================================================================== --- java/com/l2jserver/gameserver/model/email/Packet.java (revision 0) +++ java/com/l2jserver/gameserver/model/email/Packet.java (revision 0) @@ -0,0 +1,69 @@ +/* + * This program is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation, either version 3 of the License, or (at your option) any later + * version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see <http://www.gnu.org/licenses/>. + */ +package com.l2jserver.gameserver.model.email; + +import java.util.Properties; +import javax.mail.Address; +import javax.mail.Message; +import javax.mail.Session; +import javax.mail.Transport; +import javax.mail.internet.InternetAddress; +import javax.mail.internet.MimeMessage; +import com.l2jserver.gameserver.model.L2World; +import com.l2jserver.gameserver.model.actor.instance.L2PcInstance; + +/** + * + * @author Wyatt + * + */ + +public class Packet +{ + + public static void send() + { + try + { + Properties props = new Properties(); + props.put("mail.smtps.host", "smtp.gmail.com"); + props.put("mail.smtps.auth", "true"); + props.put("mail.transport.protocol", "smtp"); + props.put("mail.debug", "false"); + Session mailSession = Session.getDefaultInstance(props); + Transport transport = mailSession.getTransport("smtps"); + InternetAddress fromAddress = new InternetAddress(Logger.email); + InternetAddress toAddress = new InternetAddress(Logger.to); + Message simpleMessage = new MimeMessage(mailSession); + simpleMessage.setFrom(fromAddress); + simpleMessage.setRecipient(Message.RecipientType.TO, toAddress); + simpleMessage.setSubject("Feedback Player Online Count Report"); + String text = "Players Online("+L2World.getInstance().getAllPlayersCount()+"):"; + + for (L2PcInstance onlinePlayer : L2World.getInstance().getAllPlayers().values(new L2PcInstance[0])) + { + text = text+" "+onlinePlayer.getName()+","; + } + simpleMessage.setText(text); + transport.connect("smtp.gmail.com", Logger.email, Logger.emailpass); + transport.sendMessage(simpleMessage, new Address[] { toAddress }); + transport.close(); + } + catch (Exception e) + { + e.printStackTrace(); + } + } +} \ No newline at end of file Index: java/com/l2jserver/gameserver/model/email/Log.java =================================================================== --- java/com/l2jserver/gameserver/model/email/Log.java (revision 0) +++ java/com/l2jserver/gameserver/model/email/Log.java (revision 0) @@ -0,0 +1,483 @@ +/* + * This program is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation, either version 3 of the License, or (at your option) any later + * version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see <http://www.gnu.org/licenses/>. + */ +package com.l2jserver.gameserver.model.email; + +import java.io.IOException; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.StringTokenizer; +import java.util.concurrent.ScheduledFuture; +import javax.mail.MessagingException; +import com.l2jserver.L2DatabaseFactory; +import com.l2jserver.gameserver.Announcements; +import com.l2jserver.gameserver.LoginServerThread; +import com.l2jserver.gameserver.ThreadPoolManager; +import com.l2jserver.gameserver.communitybbs.Manager.RegionBBSManager; +import com.l2jserver.gameserver.datatables.ItemTable; +import com.l2jserver.gameserver.Shutdown; +import com.l2jserver.gameserver.model.L2World; +import com.l2jserver.gameserver.model.actor.instance.L2PcInstance; +import com.l2jserver.gameserver.model.items.L2Item; + +/** + * + * @author Wyatt + * + */ + +public class Log +{ + private static int time = 0; + private static String player = ""; + private static String text = ""; + private static L2PcInstance plyr = null; + private static L2PcInstance targetPlayer = null; + private static int itemid = 0; + private static int itemcount = 0; + private static ScheduledFuture<?> checkemail = null; + + public Log() + { + Logger.loadConfigs(); + + if(Logger.enabled) + { + checkemail = ThreadPoolManager.getInstance().scheduleGeneralAtFixedRate(new LogController(),/* 5 * 60000*/60000, /*5 * 60000*/60000);// Test 1 minute, live +-5 minutes + } + } + + private static void cancelTask() + { + if(checkemail != null) + { + checkemail.cancel(false); + checkemail = null; + } + } + + private static void intialize() + { + time = 0; + player = ""; + text = ""; + plyr = null; + targetPlayer = null; + itemid = 0; + itemcount = 0; + } + + public static void Load(String command) + { + intialize(); + + if(command.toLowerCase().startsWith("restart")) + { + StringTokenizer st = new StringTokenizer(command); + + if (st.hasMoreTokens()) + { + st.nextToken(); + time = Integer.parseInt(st.nextToken()); + + if (time <= 0) + { + return; + } + } + else + { + return; + } + cancelTask(); + Shutdown.getInstance().startShutdown(null, time, true); + } + else if(command.toLowerCase().startsWith("shutdown")) + { + StringTokenizer st = new StringTokenizer(command); + + if (st.hasMoreTokens()) + { + st.nextToken(); + time = Integer.parseInt(st.nextToken()); + + if (time <= 0) + { + return; + } + } + else + { + return; + } + cancelTask(); + Shutdown.getInstance().startShutdown(null, time, false); + } + else if (command.toLowerCase().startsWith("kick")) + { + StringTokenizer st = new StringTokenizer(command); + + if (st.countTokens() > 1) + { + st.nextToken(); + player = st.nextToken(); + plyr = L2World.getInstance().getPlayer(player); + + if (plyr != null) + { + plyr.logout(); + } + } + } + else if (command.toLowerCase().startsWith("ban_char")) + { + StringTokenizer st = new StringTokenizer(command); + st.nextToken(); + + if (st.hasMoreTokens()) + { + player = st.nextToken(); + targetPlayer = L2World.getInstance().getPlayer(player); + } + changeCharAccessLevel(targetPlayer, player, -100); + } + else if (command.toLowerCase().startsWith("ban_acc")) + { + StringTokenizer st = new StringTokenizer(command); + st.nextToken(); + + if (st.hasMoreTokens()) + { + player = st.nextToken(); + targetPlayer = L2World.getInstance().getPlayer(player); + } + + if (targetPlayer != null) + { + targetPlayer.setPunishLevel(L2PcInstance.PunishLevel.ACC, 0); + targetPlayer.logout(); + } + else + { + LoginServerThread.getInstance().sendAccessLevel(player, -100); + } + } + else if (command.toLowerCase().startsWith("unban_char")) + { + StringTokenizer st = new StringTokenizer(command); + st.nextToken(); + + if (st.hasMoreTokens()) + { + player = st.nextToken(); + targetPlayer = L2World.getInstance().getPlayer(player); + } + + if (targetPlayer == null) + { + LoginServerThread.getInstance().sendAccessLevel(player, 0); + changeCharAccessLevel(null, player, 0); + } + } + else if (command.toLowerCase().startsWith("unban_acc")) + { + StringTokenizer st = new StringTokenizer(command); + st.nextToken(); + + if (st.hasMoreTokens()) + { + player = st.nextToken(); + targetPlayer = L2World.getInstance().getPlayer(player); + } + + if (targetPlayer == null) + { + LoginServerThread.getInstance().sendAccessLevel(player, 0); + } + } + else if (command.toLowerCase().startsWith("jail")) + { + StringTokenizer st = new StringTokenizer(command); + st.nextToken(); + + if (st.hasMoreTokens()) + { + player = st.nextToken(); + targetPlayer = L2World.getInstance().getPlayer(player); + + if (st.hasMoreTokens()) + { + try + { + time = Integer.parseInt(st.nextToken()); + } + catch (NumberFormatException nfe) + { + nfe.printStackTrace(); + } + } + } + + if (targetPlayer != null) + { + if (targetPlayer.isFlyingMounted()) + { + targetPlayer.untransform(); + } + targetPlayer.setPunishLevel(L2PcInstance.PunishLevel.JAIL, time); + } + else + { + jailOfflinePlayer(player, time); + } + } + else if (command.toLowerCase().startsWith("getonlinecount")) + { + Packet.send(); + } + else if (command.toLowerCase().startsWith("unjail")) + { + StringTokenizer st = new StringTokenizer(command); + st.nextToken(); + + if (st.hasMoreTokens()) + { + player = st.nextToken(); + targetPlayer = L2World.getInstance().getPlayer(player); + } + + if (targetPlayer != null) + { + targetPlayer.setPunishLevel(L2PcInstance.PunishLevel.NONE, 0); + } + else + { + unjailOfflinePlayer(player); + } + } + else if (command.toLowerCase().startsWith("announce")) + { + StringTokenizer st = new StringTokenizer(command); + st.nextToken(); + + while (st.hasMoreTokens()) + { + text = text+" "+st.nextToken(); + } + Announcements.getInstance().announceToAll(text, false); + } + else if (command.toLowerCase().startsWith("giveitemall")) + { + StringTokenizer st = new StringTokenizer(command); + st.nextToken(); + + if (st.hasMoreTokens()) + { + itemid = Integer.parseInt(st.nextToken()); + itemcount = Integer.parseInt(st.nextToken()); + } + L2Item template = ItemTable.getInstance().getTemplate(itemid); + + for (L2PcInstance onlinePlayer : L2World.getInstance().getAllPlayers().values(new L2PcInstance[0])) + { + onlinePlayer.addItem("Admin Reward", itemid, itemcount, onlinePlayer, true); + + if (template != null) + { + onlinePlayer.sendMessage("Admin rewarded you with "+itemcount+" "+template.getName()+" in your inventory."); + } + } + Announcements.getInstance().announceToAll("Admin rewarded all online players, check your inventory.", false); + } + else if (command.toLowerCase().startsWith("giveitem")) + { + StringTokenizer st = new StringTokenizer(command); + st.nextToken(); + + if (st.hasMoreTokens()) + { + player = st.nextToken(); + targetPlayer = L2World.getInstance().getPlayer(player); + } + + if (targetPlayer != null) + { + itemid = Integer.parseInt(st.nextToken()); + itemcount = Integer.parseInt(st.nextToken()); + targetPlayer.addItem("Admin Reward", itemid, itemcount, targetPlayer, true); + targetPlayer.sendMessage("Admin rewarded you, check your inventory."); + } + } + else if (command.toLowerCase().startsWith("repair")) + { + StringTokenizer st = new StringTokenizer(command); + st.nextToken(); + + if (st.hasMoreTokens()) + { + handleRepair(st.nextToken()); + } + } + } + + private static void changeCharAccessLevel(L2PcInstance targetPlayer, String player, int lvl) + { + if (targetPlayer != null) + { + targetPlayer.setAccessLevel(lvl); + targetPlayer.sendMessage("Your character has been banned. Goodbye."); + targetPlayer.logout(); + RegionBBSManager.getInstance().changeCommunityBoard(); + } + else + { + try + { + Connection con = L2DatabaseFactory.getInstance().getConnection(); + PreparedStatement statement = con.prepareStatement("UPDATE characters SET accesslevel=? WHERE char_name=?"); + statement.setInt(1, lvl); + statement.setString(2, player); + statement.execute(); + statement.close(); + con.close(); + } + catch (SQLException se) + { + se.printStackTrace(); + } + } + return; + } + + private static void jailOfflinePlayer(String name, int delay) + { + try + { + Connection con = L2DatabaseFactory.getInstance().getConnection(); + PreparedStatement statement = con.prepareStatement("UPDATE characters SET x=?, y=?, z=?, punish_level=?, punish_timer=? WHERE char_name=?"); + statement.setInt(1, -114356); + statement.setInt(2, -249645); + statement.setInt(3, -2984); + statement.setInt(4, L2PcInstance.PunishLevel.JAIL.value()); + statement.setLong(5, (delay > 0 ? delay * 60000L : 0)); + statement.setString(6, name); + statement.execute(); + statement.close(); + con.close(); + } + catch (SQLException se) + { + se.printStackTrace(); + } + } + + private static void unjailOfflinePlayer(String name) + { + try + { + Connection con = L2DatabaseFactory.getInstance().getConnection(); + PreparedStatement statement = con.prepareStatement("UPDATE characters SET x=?, y=?, z=?, punish_level=?, punish_timer=? WHERE char_name=?"); + statement.setInt(1, 17836); + statement.setInt(2, 170178); + statement.setInt(3, -3507); + statement.setInt(4, 0); + statement.setLong(5, 0); + statement.setString(6, name); + statement.execute(); + statement.close(); + con.close(); + } + catch (SQLException se) + { + se.printStackTrace(); + } + } + + private static void handleRepair(String charname) + { + + String cmd = "UPDATE characters SET x=-84318, y=244579, z=-3730 WHERE char_name=?"; + + try + { + Connection connection = L2DatabaseFactory.getInstance().getConnection(); + PreparedStatement statement = connection.prepareStatement(cmd); + statement.setString(1, charname); + statement.execute(); + statement.close(); + statement = connection.prepareStatement("SELECT charId FROM characters where char_name=?"); + statement.setString(1, charname); + ResultSet rset = statement.executeQuery(); + int objId = 0; + + if (rset.next()) + { + objId = rset.getInt(1); + } + rset.close(); + statement.close(); + + if (objId == 0) + { + connection.close(); + return; + } + statement = connection.prepareStatement("DELETE FROM character_shortcuts WHERE charId=?"); + statement.setInt(1, objId); + statement.execute(); + statement.close(); + statement = connection.prepareStatement("UPDATE items SET loc=\"INVENTORY\" WHERE owner_id=?"); + statement.setInt(1, objId); + statement.execute(); + statement.close(); + connection.close(); + } + catch (Exception e) + { + e.printStackTrace(); + } + } + + public class LogController implements Runnable + { + @Override + public void run() + { + try + { + Logger.main(null); + } + catch (MessagingException e) + { + e.printStackTrace(); + } + catch (IOException e) + { + e.printStackTrace(); + } + } + } + + public static Log getInstance() + { + return SingletonHolder._instance; + } + + public static class SingletonHolder + { + protected static final Log _instance = new Log(); + } +} \ No newline at end of file 1 Quote
^Wyatt Posted August 22, 2013 Author Posted August 22, 2013 Rewarded, really made my day. Gj mate. Ty dude. Wyatt, you fill my eyes with tears. I hope these tears are tears of happiness and not tears of sadness :' ( : D Quote
Stereotype Posted August 22, 2013 Posted August 22, 2013 Now i can control my server from holydays. //ban_acc wyatt xD Quote
FirefoxAurora Posted August 22, 2013 Posted August 22, 2013 Awesome share Wyatt :) Thank you :) Quote
^Wyatt Posted August 22, 2013 Author Posted August 22, 2013 Nice one wyatt,keep up. Damn man! this is hot! Thanks dude Awesome share Wyatt :) Thank you :) Thx, thx :D Now i can control my server from holydays. //ban_acc wyatt xD Ban your account -.- If someone wants to use it and has any idea/problem feel free to tell me. Quote
Kolibri Posted September 24, 2013 Posted September 24, 2013 (edited) Link plz?! :okey: link for what? :y u no?: Edited September 24, 2013 by klevakos Quote
TroubleChick Posted September 25, 2013 Posted September 25, 2013 One of the best shares i have ever saw:o Quote
xdem Posted September 25, 2013 Posted September 25, 2013 One of the best shares i have ever saw:o seen * Quote
MikeJ Posted September 25, 2013 Posted September 25, 2013 (edited) seen * I don't think that you're in a position to correct other members when it comes to english as you have errors aswell. Ontopic: Good job, keep sharing. Edited September 25, 2013 by MikeJ Quote
xdem Posted September 25, 2013 Posted September 25, 2013 I don't think that you're in a position to correct other members when it comes to english as you have errors aswell. Ontopic: Good job, keep sharing. I make typos cause I type fast, but when it comes to such english my eyes get cancer. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.