Rizlaaa Posted May 20, 2012 Posted May 20, 2012 Credits iRat Read this before please I was chating with a friend in MSN and he requested this. In the beggining i told him it was a bad idea and useless but then i thought better and i changed opinion. Full Description You know all(specially if you are member in Maxcheaters lol :P) that there is Maintenance mode in forums.So that's I did, a maintenance mode in Lineage. Admin can start the maintenance by pressing //start_maintenance. A new panel opens and has opinion to start maintenance , clear maintenance messages and add a new maintenance. He first adds a new maintenance method somehow like that: Then after he adds as many messages he wants he press Main Menu to come to the starting page. And then he press Do Maintenance and players are informed. After 30 seconds all players are teleporting somewhere(default Jail), they informed with the reasons of maintenance and there they can't attack,etc , using unstuck ,blabla till maintenance mode finish. While maintenance mode admin can also add new messages pressing //add_reason and players will be informed by each message he adds automatically. Players who were offline , while server is in maintenance mod they will informed when they log in and they will also get teleported in the maintenance place.And finally he can press //end_maintenance to finish the maintenance mode and players continue playing :D Why it can be usefull 1)Players are bored to enter at server's site. 2)It's cool to have a maintenance mode in L2 and not in the site 3)Many players will leave if they see Down server status , believe me they will. And this you can fix some things and players get instant informed about your actions. ### Eclipse Workspace Patch 1.0 #P Chr.6GMS Index: java/net/sf/l2j/gameserver/handler/usercommandhandlers/Escape.java =================================================================== --- java/net/sf/l2j/gameserver/handler/usercommandhandlers/Escape.java (revision 5263) +++ java/net/sf/l2j/gameserver/handler/usercommandhandlers/Escape.java (working copy) @@ -24,6 +24,7 @@ import net.sf.l2j.gameserver.ai.CtrlIntention; import net.sf.l2j.gameserver.datatables.MapRegionTable; import net.sf.l2j.gameserver.handler.IUserCommandHandler; +import net.sf.l2j.gameserver.model.Maintenance; import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance; import net.sf.l2j.gameserver.model.entity.TvTEvent; import net.sf.l2j.gameserver.network.SystemMessageId; @@ -67,6 +68,9 @@ activeChar.sendMessage("You may not use an escape command in a festival."); return false; } + + if(Maintenance.isMaintenance()) + return false; // Check to see if player is in jail if (activeChar.isInJail()) Index: java/net/sf/l2j/gameserver/clientpackets/EnterWorld.java =================================================================== --- java/net/sf/l2j/gameserver/clientpackets/EnterWorld.java (revision 5263) +++ java/net/sf/l2j/gameserver/clientpackets/EnterWorld.java (working copy) @@ -46,6 +46,7 @@ import net.sf.l2j.gameserver.model.L2Effect; import net.sf.l2j.gameserver.model.L2ItemInstance; import net.sf.l2j.gameserver.model.L2World; +import net.sf.l2j.gameserver.model.Maintenance; import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance; import net.sf.l2j.gameserver.model.entity.ClanHall; import net.sf.l2j.gameserver.model.entity.Couple; @@ -254,6 +255,15 @@ Quest.playerEnter(activeChar); activeChar.sendPacket(new QuestList()); + + if(Maintenance.isMaintenance()){ + Maintenance.informPlayer(activeChar); + if(!activeChar.isInJail()) + activeChar.teleToLocation(Maintenance.x, Maintenance.y, Maintenance.z); + } + else if(Maintenance.isMaintenance() == false) + if(activeChar.isInJail()) + activeChar.teleToLocation(Maintenance.giranX, Maintenance.giranY, Maintenance.giranZ); if (Config.SERVER_NEWS) { Index: java/net/sf/l2j/gameserver/model/Maintenance.java =================================================================== --- java/net/sf/l2j/gameserver/model/Maintenance.java (revision 0) +++ java/net/sf/l2j/gameserver/model/Maintenance.java (revision 0) @@ -0,0 +1,192 @@ + +package net.sf.l2j.gameserver.model; + +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.IOException; +import java.io.LineNumberReader; +import java.util.StringTokenizer; +import java.util.logging.Logger; + +import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance; +import net.sf.l2j.gameserver.serverpackets.NpcHtmlMessage; + +import javolution.text.TextBuilder; +import javolution.util.FastList; + + + +/** + * + * @author iRat + */ +public class Maintenance +{ + private static Logger _log = Logger.getLogger(Maintenance.class.getName()); + + public static int giranX = 0, giranY = 0, giranZ = 0; + public static int x = -114462,y = -249619,z = -2986; + private static boolean maintenance = false; + private static FastList<String> maintenanceMessages = new FastList<String>(); + + public static void addMessage(String reason) + { + maintenanceMessages.add(reason); + } + + public static void clearAllMessages(){ + maintenanceMessages.clear(); + } + + public static FastList<String> getReasons() + { + return maintenanceMessages; + } + + public static boolean isMaintenance() + { + return maintenance; + } + + public static void setMaintenance(boolean _maintenance){ + setMaintenanceInDisk(_maintenance); + maintenance = _maintenance; + } + + private static void setMaintenanceInDisk(boolean Maintenance){ + String mode = ""; + if(Maintenance) + mode = "true"; + else + mode = "false"; + + File file = new File("data/maintenance.txt"); + FileWriter save = null; + + try + { + save = new FileWriter(file); + save.write(mode); + save.flush(); + save.close(); + save = null; + } + catch (IOException e) + { + _log.warning("Error saving maintenance value " + e); + } + } + + public static void serverStartMaintenance() + { + File file = new File("data/maintenance.txt"); + LineNumberReader lnr = null; + try + { + String line = null; + lnr = new LineNumberReader(new FileReader(file)); + if ( (line = lnr.readLine()) != null) + { + StringTokenizer st = new StringTokenizer(line); + + if (st.hasMoreTokens()) + { + String mode = st.nextToken(); + + if(mode.equals("true")) + maintenance = true; + else if(mode.equals("false")) + maintenance = false; + else + maintenance = false; + } + } + } + catch (IOException e) + { + _log.warning("Error reading maintenance mode: "+e); + } + finally + { + try + { + lnr.close(); + } + catch (Exception e1) + {} + } + } + + public static void sendHtmlAddMessagePage(L2PcInstance player) + { + TextBuilder tb = new TextBuilder(); + NpcHtmlMessage html = new NpcHtmlMessage(1); + + tb.append("<html><head>"); + tb.append("<title>Manage Maintenance Mode</title>"); + tb.append("</head><body>"); + tb.append("<center>Here you can add new maintenance messages "+player.getName()+"</center>"); + tb.append("<br><br>"); + tb.append("<multiedit var=\"newmain\" width=240 height=30><br>"); + tb.append("<center><button value=\"Add\" action=\"bypass -h setAddMain $newmain\" width=60 height=15 back=\"sek.cbui94\" fore=\"sek.cbui92\"></center>"); + tb.append("<center><button value=\"Main Menu\" action=\"bypass -h mainMain\" width=60 height=15 back=\"sek.cbui94\" fore=\"sek.cbui92\"></center>"); + tb.append("</body></html>"); + + html.setHtml(tb.toString()); + player.sendPacket(html); + } + + public static void informPlayers() + { + TextBuilder tb = new TextBuilder(); + NpcHtmlMessage html = new NpcHtmlMessage(1); + + tb.append("<html><head>"); + tb.append("<title>Maintenance Mode</title>"); + tb.append("</head><body>"); + tb.append("<br><br>"); + int i = 1; + if(getReasons().isEmpty() == false) + for(String message : getReasons()) + { + tb.append(i+":"+message+"<br>"); + i++; + } + tb.append("</body></html>"); + + html.setHtml(tb.toString()); + + for(L2PcInstance player : L2World.getInstance().getAllPlayers()){ + if(player == null) + continue; + player.sendPacket(html); + + } + } + + public static void informPlayer(L2PcInstance player) + { + TextBuilder tb = new TextBuilder(); + NpcHtmlMessage html = new NpcHtmlMessage(1); + + tb.append("<html><head>"); + tb.append("<title>Maintenance Mode</title>"); + tb.append("</head><body>"); + tb.append("<br><br>"); + int i = 1; + if(getReasons().isEmpty() == false) + for(String message : getReasons()) + { + tb.append(i+":"+message+"<br>"); + i++; + } + tb.append("</body></html>"); + + html.setHtml(tb.toString()); + player.sendPacket(html); + + } + } + +} Index: java/net/sf/l2j/gameserver/model/actor/instance/L2PcInstance.java =================================================================== --- java/net/sf/l2j/gameserver/model/actor/instance/L2PcInstance.java (revision 5263) +++ java/net/sf/l2j/gameserver/model/actor/instance/L2PcInstance.java (working copy) @@ -106,6 +106,7 @@ import net.sf.l2j.gameserver.model.L2Summon; import net.sf.l2j.gameserver.model.L2World; import net.sf.l2j.gameserver.model.MacroList; +import net.sf.l2j.gameserver.model.Maintenance; import net.sf.l2j.gameserver.model.PcFreight; import net.sf.l2j.gameserver.model.PcInventory; import net.sf.l2j.gameserver.model.PcWarehouse; @@ -271,6 +272,8 @@ @Override public void doAttack(L2Character target) { + if(Maintenance.isMaintenance()) + return; super.doAttack(target); // cancel the recent fake-death protection instantly if the player attacks or casts spells @@ -283,6 +286,8 @@ @Override public void doCast(L2Skill skill) { + if(Maintenance.isMaintenance()) + return; super.doCast(skill); // cancel the recent fake-death protection instantly if the player attacks or casts spells Index: java/net/sf/l2j/gameserver/clientpackets/RequestBypassToServer.java =================================================================== --- java/net/sf/l2j/gameserver/clientpackets/RequestBypassToServer.java (revision 5263) +++ java/net/sf/l2j/gameserver/clientpackets/RequestBypassToServer.java (working copy) @@ -22,13 +22,17 @@ import java.util.logging.Logger; import net.sf.l2j.Config; +import net.sf.l2j.gameserver.Announcements; +import net.sf.l2j.gameserver.ThreadPoolManager; import net.sf.l2j.gameserver.ai.CtrlIntention; import net.sf.l2j.gameserver.communitybbs.CommunityBoard; import net.sf.l2j.gameserver.handler.AdminCommandHandler; import net.sf.l2j.gameserver.handler.IAdminCommandHandler; +import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminMaintenance; import net.sf.l2j.gameserver.model.L2CharPosition; import net.sf.l2j.gameserver.model.L2Object; import net.sf.l2j.gameserver.model.L2World; +import net.sf.l2j.gameserver.model.Maintenance; import net.sf.l2j.gameserver.model.actor.instance.L2NpcInstance; import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance; import net.sf.l2j.gameserver.model.entity.L2Event; @@ -56,6 +60,22 @@ { _command = readS(); } + + private class LockAll implements Runnable{ + public void run() + { + for(L2PcInstance player : L2World.getInstance().getAllPlayers()){ + if(player == null) + continue; + + player.teleToLocation(Maintenance.x, Maintenance.y, Maintenance.z); + + } + Maintenance.informPlayers(); + } + + } + @Override protected void runImpl() @@ -81,6 +101,51 @@ else _log.warning("No handler registered for bypass '"+_command+"'"); } + else if(_command.equals("newMessage")){ + Maintenance.sendHtmlAddMessagePage(activeChar); + } + else if(_command.startsWith("setAddMain")){ + String maintenanceMessage = _command.substring(11); + + if(maintenanceMessage == "" || maintenanceMessage == null){ + Maintenance.sendHtmlAddMessagePage(activeChar); + activeChar.sendMessage("You can't add null messages"); + return; + } + + else if(maintenanceMessage.length() >= 100){ + Maintenance.sendHtmlAddMessagePage(activeChar); + activeChar.sendMessage("You can't add too big message"); + return; + } + + else + { + Maintenance.addMessage(maintenanceMessage); + if(Maintenance.isMaintenance()) + Maintenance.informPlayers(); + activeChar.sendMessage("Your maintenance message added."); + Maintenance.sendHtmlAddMessagePage(activeChar); + } + } + else if(_command.equals("mainMain")){ + + AdminMaintenance.sendHtmlToAddReasons(activeChar); + } + else if(_command.equals("clearMessage")){ + if(!Maintenance.getReasons().isEmpty()) + Maintenance.clearAllMessages(); + activeChar.sendMessage("All your maintenance messages cleared"); + + AdminMaintenance.sendHtmlToAddReasons(activeChar); + } + else if(_command.equals("doMain")){ + Maintenance.setMaintenance(true); + Announcements.getInstance().announceToAll("Server is in Maintenance Mode now , read the reasons."); + Announcements.getInstance().announceToAll("You will be locked in 30 seconds"); + + ThreadPoolManager.getInstance().scheduleGeneral(new LockAll(), 30000); + } else if (_command.equals("come_here") && activeChar.getAccessLevel() >= Config.GM_ACCESSLEVEL) { comeHere(activeChar); Index: java/net/sf/l2j/gameserver/handler/admincommandhandlers/AdminMaintenance.java =================================================================== --- java/net/sf/l2j/gameserver/handler/admincommandhandlers/AdminMaintenance.java (revision 0) +++ java/net/sf/l2j/gameserver/handler/admincommandhandlers/AdminMaintenance.java (revision 0) @@ -0,0 +1,76 @@ + +package net.sf.l2j.gameserver.handler.admincommandhandlers; + +import javolution.text.TextBuilder; +import net.sf.l2j.gameserver.Announcements; +import net.sf.l2j.gameserver.handler.IAdminCommandHandler; +import net.sf.l2j.gameserver.model.L2World; +import net.sf.l2j.gameserver.model.Maintenance; +import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance; +import net.sf.l2j.gameserver.serverpackets.NpcHtmlMessage; + +/** + * + * @author iRat + */ +public class AdminMaintenance implements IAdminCommandHandler +{ + + private final String[] commands = {"admin_start_maintenance","admin_end_maintenance","admin_add_reason"}; + + public boolean useAdminCommand(String command, L2PcInstance activeChar) + { + if(activeChar == null) return false; + + if(command.equalsIgnoreCase("admin_start_maintenance")) + { + sendHtmlToAddReasons(activeChar); + } + else if(command.equalsIgnoreCase("admin_add_reason")) + { + Maintenance.sendHtmlAddMessagePage(activeChar); + } + else if(command.equalsIgnoreCase("admin_end_maintenance")) + { + Maintenance.setMaintenance(false); + Maintenance.clearAllMessages(); + for(L2PcInstance player : L2World.getInstance().getAllPlayers()){ + if(player == null) + continue; + + player.sendMessage("Maintenance Mode finished, you telepored in giran"); + player.teleToLocation(Maintenance.giranX, Maintenance.giranZ, Maintenance.giranY); + } + Announcements.getInstance().announceToAll("Maintenance Mode finished, have a nice game"); + } + return true; + } + + public static void sendHtmlToAddReasons(L2PcInstance activeChar) + { + //no need null check since added in useAdminCommand() + + TextBuilder tb = new TextBuilder(); + NpcHtmlMessage html = new NpcHtmlMessage(1); + + tb.append("<html><head>"); + tb.append("<title>Manage Maintenance Mode</title>"); + tb.append("</head><body>"); + tb.append("<center>Here you can manage the maintenance mode "+activeChar.getName()+"</center>"); + tb.append("<br><br>"); + tb.append("Select if you want to add a new reason or you want to remove.<br>"); + tb.append("<button value=\"Add Message\" action=\"bypass -h newMessage\" width=65 height=19>"); + tb.append("<button value=\"Clear Messages\" action=\"bypass -h clearMessage\" width=65 height=19><br><br>"); + tb.append("<center><button value=\"Do Maintenance\" action=\"bypass -h doMain\" width=65 height=19></center>"); + tb.append("</body></html>"); + + html.setHtml(tb.toString()); + activeChar.sendPacket(html); + } + + public String[] getAdminCommandList() + { + return commands; + } + +} Index: java/net/sf/l2j/gameserver/GameServer.java =================================================================== --- java/net/sf/l2j/gameserver/GameServer.java (revision 5263) +++ java/net/sf/l2j/gameserver/GameServer.java (working copy) @@ -97,6 +97,7 @@ import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminKill; import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminLevel; import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminLogin; +import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminMaintenance; import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminMammon; import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminManor; import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminMenu; @@ -221,6 +222,7 @@ import net.sf.l2j.gameserver.model.L2Manor; import net.sf.l2j.gameserver.model.L2PetDataTable; import net.sf.l2j.gameserver.model.L2World; +import net.sf.l2j.gameserver.model.Maintenance; import net.sf.l2j.gameserver.model.entity.Hero; import net.sf.l2j.gameserver.model.entity.TvTManager; import net.sf.l2j.gameserver.network.L2GameClient; @@ -351,6 +353,7 @@ NobleSkillTable.getInstance(); HeroSkillTable.getInstance(); + Maintenance.serverStartMaintenance(); //Call to load caches HtmCache.getInstance(); CrestCache.getInstance(); @@ -518,6 +521,7 @@ _adminCommandHandler = AdminCommandHandler.getInstance(); _adminCommandHandler.registerAdminCommandHandler(new AdminAdmin()); + _adminCommandHandler.registerAdminCommandHandler(new AdminMaintenance()); _adminCommandHandler.registerAdminCommandHandler(new AdminInvul()); _adminCommandHandler.registerAdminCommandHandler(new AdminDelete()); _adminCommandHandler.registerAdminCommandHandler(new AdminKill());
Fizo Posted May 21, 2012 Posted May 21, 2012 Great share for sure it's hard to use it cause u can fix them without move player's or stop them from xp and etC ! but it's seems great ! good work keep it like this we want to see Mods like that ! thanks from me for sure i will try it and then i will post again
Fanky Posted May 21, 2012 Posted May 21, 2012 Ι believe that its useless ;p I cant get how this can help your server..but still you did a great job.
An4rchy Posted May 21, 2012 Posted May 21, 2012 Eh, good job, but the admin commands should be handled by admin command handlers. Check another example how it works, like //item_create.
Rizlaaa Posted May 21, 2012 Author Posted May 21, 2012 Eh, good job, but the admin commands should be handled by admin command handlers. Check another example how it works, like //item_create. What exactly you mean? :P
An4rchy Posted May 21, 2012 Posted May 21, 2012 What exactly you mean? :P That you handle the admin command handlers with normal bypasses. I mean these: + else if(_command.equals("newMessage")){ + Maintenance.sendHtmlAddMessagePage(activeChar); + } + else if(_command.startsWith("setAddMain")){ + String maintenanceMessage = _command.substring(11); + + if(maintenanceMessage == "" || maintenanceMessage == null){ + Maintenance.sendHtmlAddMessagePage(activeChar); + activeChar.sendMessage("You can't add null messages"); + return; + } + + else if(maintenanceMessage.length() >= 100){ + Maintenance.sendHtmlAddMessagePage(activeChar); + activeChar.sendMessage("You can't add too big message"); + return; + } + + else + { + Maintenance.addMessage(maintenanceMessage); + if(Maintenance.isMaintenance()) + Maintenance.informPlayers(); + activeChar.sendMessage("Your maintenance message added."); + Maintenance.sendHtmlAddMessagePage(activeChar); + } + } + else if(_command.equals("mainMain")){ + + AdminMaintenance.sendHtmlToAddReasons(activeChar); + } + else if(_command.equals("clearMessage")){ + if(!Maintenance.getReasons().isEmpty()) + Maintenance.clearAllMessages(); + activeChar.sendMessage("All your maintenance messages cleared"); + + AdminMaintenance.sendHtmlToAddReasons(activeChar); + } + else if(_command.equals("doMain")){ + Maintenance.setMaintenance(true); + Announcements.getInstance().announceToAll("Server is in Maintenance Mode now , read the reasons."); + Announcements.getInstance().announceToAll("You will be locked in 30 seconds"); + + ThreadPoolManager.getInstance().scheduleGeneral(new LockAll(), 30000); + } should have been coded in AdminMaintenance.java.
Rizlaaa Posted May 21, 2012 Author Posted May 21, 2012 That you handle the admin command handlers with normal bypasses. I mean these: + else if(_command.equals("newMessage")){ + Maintenance.sendHtmlAddMessagePage(activeChar); + } + else if(_command.startsWith("setAddMain")){ + String maintenanceMessage = _command.substring(11); + + if(maintenanceMessage == "" || maintenanceMessage == null){ + Maintenance.sendHtmlAddMessagePage(activeChar); + activeChar.sendMessage("You can't add null messages"); + return; + } + + else if(maintenanceMessage.length() >= 100){ + Maintenance.sendHtmlAddMessagePage(activeChar); + activeChar.sendMessage("You can't add too big message"); + return; + } + + else + { + Maintenance.addMessage(maintenanceMessage); + if(Maintenance.isMaintenance()) + Maintenance.informPlayers(); + activeChar.sendMessage("Your maintenance message added."); + Maintenance.sendHtmlAddMessagePage(activeChar); + } + } + else if(_command.equals("mainMain")){ + + AdminMaintenance.sendHtmlToAddReasons(activeChar); + } + else if(_command.equals("clearMessage")){ + if(!Maintenance.getReasons().isEmpty()) + Maintenance.clearAllMessages(); + activeChar.sendMessage("All your maintenance messages cleared"); + + AdminMaintenance.sendHtmlToAddReasons(activeChar); + } + else if(_command.equals("doMain")){ + Maintenance.setMaintenance(true); + Announcements.getInstance().announceToAll("Server is in Maintenance Mode now , read the reasons."); + Announcements.getInstance().announceToAll("You will be locked in 30 seconds"); + + ThreadPoolManager.getInstance().scheduleGeneral(new LockAll(), 30000); + } should have been coded in AdminMaintenance.java. Aha , actually i didn't know that can bypassing in admin commands classes. Anyway i don't think it's so important since it doesn't take more memory or have problems to work :P but yes it would be better like that.
An4rchy Posted May 21, 2012 Posted May 21, 2012 Aha , actually i didn't know that can bypassing in admin commands classes. Anyway i don't think it's so important since it doesn't take more memory or have problems to work :P but yes it would be better like that. Yeah, it works just fine like this too. It's just for order and cleaner coding ;)
32start Posted May 21, 2012 Posted May 21, 2012 better way is just to shutdown server and boot it in gm only mode. noob players could just login and start shouting 'wtf is happening at this bugland' (worst scenario). mine verdict: useless.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now