Jump to content
  • 0

Question

Posted (edited)

Hello,

I have problem while setting aio for player. Today is 30th month day and if  I set aio for 1 day some how end date is december 31(i think it is because november does not have 31 day). But if I set aio for 2 days its end time is december 1. How I can fix it? l2jfrozen rev 1132.

P.S. when it was november 25 and I set aio for 1 day it worked perfectly.

Adding code:

/*
 * L2jFrozen Project - www.l2jfrozen.com 
 * 
 * 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 2, 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, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 * 02111-1307, USA.
 *
 * http://www.gnu.org/copyleft/gpl.html
 */
package com.l2jfrozen.gameserver.handler.admincommandhandlers;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.util.StringTokenizer;

import org.apache.log4j.Logger;

import com.l2jfrozen.Config;
import com.l2jfrozen.gameserver.datatables.GmListTable;
import com.l2jfrozen.gameserver.handler.IAdminCommandHandler;
import com.l2jfrozen.gameserver.model.L2World;
import com.l2jfrozen.gameserver.model.actor.instance.L2PcInstance;
import com.l2jfrozen.gameserver.network.serverpackets.EtcStatusUpdate;
import com.l2jfrozen.util.CloseUtil;
import com.l2jfrozen.util.database.DatabaseUtils;
import com.l2jfrozen.util.database.L2DatabaseFactory;

/**
 * Give / Take Status Aio to Player Changes name color and title color if enabled Uses: setaio [<player_name>] [<time_duration in days>] removeaio [<player_name>] If <player_name> is not specified, the current target player is used.
 * @author KhayrusS
 */
public class AdminAio implements IAdminCommandHandler
{
	private final static Logger LOGGER = Logger.getLogger(AdminAio.class);
	
	private static String[] _adminCommands =
	{
		"admin_setaio",
		"admin_removeaio"
	};
	
	private enum CommandEnum
	{
		admin_setaio,
		admin_removeaio
	}
	
	@Override
	public boolean useAdminCommand(final String command, final L2PcInstance activeChar)
	{
		/*
		 * if(!AdminCommandAccessRights.getInstance().hasAccess(command, activeChar.getAccessLevel())){ return false; } if(Config.GMAUDIT) { Logger _logAudit = Logger.getLogger("gmaudit"); LogRecord record = new LogRecord(Level.INFO, command); record.setParameters(new Object[] { "GM: " +
		 * activeChar.getName(), " to target [" + activeChar.getTarget() + "] " }); _logAudit.LOGGER(record); }
		 */
		
		final StringTokenizer st = new StringTokenizer(command);
		
		final CommandEnum comm = CommandEnum.valueOf(st.nextToken());
		
		if (comm == null)
			return false;
		
		switch (comm)
		{
			case admin_setaio:
			{
				
				boolean no_token = false;
				
				if (st.hasMoreTokens())
				{ // char_name not specified
				
					final String char_name = st.nextToken();
					
					final L2PcInstance player = L2World.getInstance().getPlayer(char_name);
					
					if (player != null)
					{
						
						if (st.hasMoreTokens()) // time
						{
							final String time = st.nextToken();
							
							try
							{
								final int value = Integer.parseInt(time);
								
								if (value > 0)
								{
									
									doAio(activeChar, player, char_name, time);
									
									if (player.isAio())
										return true;
									
								}
								else
								{
									activeChar.sendMessage("Time must be bigger then 0!");
									return false;
								}
								
							}
							catch (final NumberFormatException e)
							{
								activeChar.sendMessage("Time must be a number!");
								return false;
							}
							
						}
						else
						{
							no_token = true;
						}
						
					}
					else
					{
						activeChar.sendMessage("Player must be online to set AIO status");
						no_token = true;
					}
					
				}
				else
				{
					
					no_token = true;
					
				}
				
				if (no_token)
				{
					activeChar.sendMessage("Usage: //setaio <char_name> [time](in days)");
					return false;
				}
				
			}
			case admin_removeaio:
			{
				
				boolean no_token = false;
				
				if (st.hasMoreTokens())
				{ // char_name
				
					final String char_name = st.nextToken();
					
					final L2PcInstance player = L2World.getInstance().getPlayer(char_name);
					
					if (player != null)
					{
						
						removeAio(activeChar, player, char_name);
						
						if (!player.isAio())
							return true;
						
					}
					else
					{
						
						activeChar.sendMessage("Player must be online to remove AIO status");
						no_token = true;
					}
					
				}
				else
				{
					no_token = true;
				}
				
				if (no_token)
				{
					activeChar.sendMessage("Usage: //removeaio <char_name>");
					return false;
				}
				
			}
		}
		
		return true;
		
	}
	
	public void doAio(final L2PcInstance activeChar, final L2PcInstance _player, final String _playername, final String _time)
	{
		final int days = Integer.parseInt(_time);
		if (_player == null)
		{
			activeChar.sendMessage("not found char" + _playername);
			return;
		}
		
		if (days > 0)
		{
			_player.setAio(true);
			_player.setEndTime("aio", days);
			_player.getStat().addExp(_player.getStat().getExpForLevel(81));
			
			Connection connection = null;
			try
			{
				connection = L2DatabaseFactory.getInstance().getConnection(false);
				
				final PreparedStatement statement = connection.prepareStatement("UPDATE characters SET aio=1, aio_end=? WHERE obj_id=?");
				statement.setLong(1, _player.getAioEndTime());
				statement.setInt(2, _player.getObjectId());
				statement.execute();
				DatabaseUtils.close(statement);
				connection.close();
				
				if (Config.ALLOW_AIO_NCOLOR && activeChar.isAio())
					_player.getAppearance().setNameColor(Config.AIO_NCOLOR);
				
				if (Config.ALLOW_AIO_TCOLOR && activeChar.isAio())
					_player.getAppearance().setTitleColor(Config.AIO_TCOLOR);
				
				_player.rewardAioSkills();
				_player.broadcastUserInfo();
				_player.sendPacket(new EtcStatusUpdate(_player));
				_player.sendSkillList();
				GmListTable.broadcastMessageToGMs("GM " + activeChar.getName() + " set Aio stat for player " + _playername + " for " + _time + " day(s)");
				_player.sendMessage("You are now an Aio, Congratulations!");
				_player.broadcastUserInfo();
			}
			catch (final Exception e)
			{
				if (Config.DEBUG)
					e.printStackTrace();
				
				LOGGER.warn("could not set Aio stats to char:", e);
			}
			finally
			{
				CloseUtil.close(connection);
			}
		}
		else
		{
			removeAio(activeChar, _player, _playername);
		}
	}
	
	public void removeAio(final L2PcInstance activeChar, final L2PcInstance _player, final String _playername)
	{
		_player.setAio(false);
		_player.setAioEndTime(0);
		
		Connection connection = null;
		try
		{
			connection = L2DatabaseFactory.getInstance().getConnection(false);
			
			final PreparedStatement statement = connection.prepareStatement("UPDATE characters SET Aio=0, Aio_end=0 WHERE obj_id=?");
			statement.setInt(1, _player.getObjectId());
			statement.execute();
			DatabaseUtils.close(statement);
			connection.close();
			
			_player.lostAioSkills();
			_player.getAppearance().setNameColor(0xFFFFFF);
			_player.getAppearance().setTitleColor(0xFFFFFF);
			_player.broadcastUserInfo();
			_player.sendPacket(new EtcStatusUpdate(_player));
			_player.sendSkillList();
			GmListTable.broadcastMessageToGMs("GM " + activeChar.getName() + " remove Aio stat of player " + _playername);
			_player.sendMessage("Now You are not an Aio..");
			_player.broadcastUserInfo();
		}
		catch (final Exception e)
		{
			if (Config.DEBUG)
				e.printStackTrace();
			
			LOGGER.warn("could not remove Aio stats of char:", e);
		}
		finally
		{
			CloseUtil.close(connection);
		}
	}
	
	@Override
	public String[] getAdminCommandList()
	{
		return _adminCommands;
	}
}

EDIT adding aioendtime code:

public void setEndTime(final String process, int val)
	{
		if (val > 0)
		{
			long end_day;
			final Calendar calendar = Calendar.getInstance();
			if (val >= 30)
			{
				while (val >= 30)
				{
					if (calendar.get(Calendar.MONTH) == 11)
						calendar.roll(Calendar.YEAR, true);
					calendar.roll(Calendar.MONTH, true);
					val -= 30;
				}
			}
			if (val < 30 && val > 0)
			{
				while (val > 0)
				{
					if (calendar.get(Calendar.DATE) == 28 && calendar.get(Calendar.MONTH) == 1)
						calendar.roll(Calendar.MONTH, true);
					if (calendar.get(Calendar.DATE) == 30)
					{
						if (calendar.get(Calendar.MONTH) == 11)
							calendar.roll(Calendar.YEAR, true);
						calendar.roll(Calendar.MONTH, true);
						
					}
					calendar.roll(Calendar.DATE, true);
					val--;
				}
			}
			
			end_day = calendar.getTimeInMillis();
			if (process.equals("aio"))
				_aio_endTime = end_day;
			
			else
			{
				LOGGER.info("process " + process + "no Known while try set end date");
				return;
			}
			final Date dt = new Date(end_day);
			LOGGER.info("" + process + " end time for player " + getName() + " is " + dt);
		}
		else
		{
			if (process.equals("aio"))
				_aio_endTime = 0;
			
			else
			{
				LOGGER.info("process " + process + "no Known while try set end date");
				return;
			}
		}
	}
	
	/**
	 * Gets the aio end time.
	 * @return the aio end time
	 */
	public long getAioEndTime()
	{
		return _aio_endTime;
	}
Edited by Helperis

2 answers to this question

Recommended Posts

  • 0
Posted

Why not do it this way?

 

long endDateMillis = System.currentTimeMillis() + TimeUnit.DAYS.toMillis(val);

this. Millisecond can be translated into anything since is static time. If you get current millisecond and the day is about to change in 1 minute and you add 3600000 ms this will just go to the next day. 

This setEndTime is the most fucked up thing i ever seen in my life... delete it and recycle the whole code is 2 lines

 

long endDateMillis = System.currentTimeMillis() + TimeUnit.DAYS.toMillis(val); (As guy said)

player.setPremiumTime(endDateMillis)  <-- example.

 

or make a direct method to update base on Days

long premtime = 0;

public void setPremiumTime(int days)
{
   premTime = System.currentTimeMillis() + TimeUnit.DAYS.toMillis(days)
}
  • 0
Posted

Why not do it this way?

 

long endDateMillis = System.currentTimeMillis() + TimeUnit.DAYS.toMillis(val);

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 account

Sign in

Already have an account? Sign in here.

Sign In Now


  • Posts

    • You make me laugh... relax man, my clients have been using my package for years and haven't had any problems. Cheers!  
    • yes travor? I hope you don't delete this LINK, scammer, the proof that you sold it is inside. HASH MD5: F1B3722977A7E3720DC91D56203D4E39 https://www.mediafire.com/file/rma1p98juce3ust/travor-source.rar/file   I'm uploading it again because I'm sure you'll delete it. https://www.mediafire.com/file/h51kz9vlbj9tk8a/travor-source.rar/file L2Ext.vcproj.DESKTOP-I4LDE28.Mariano.user in ext2025-main.zip Modified 2025-07-15 L2Ext.vcproj.DESKTOP-I4LDE28.Mariano.user in  travor-source.rar Modified 2026-03-09 Explain this to the community, you damn scammer! YOUR PC IS: DESKTOP-I4LDE28 VERIFY: HASH CRC32 in two files. GG. <?xml version="1.0" encoding="windows-1250"?> <VisualStudioUserFile     ProjectType="Visual C++"     Version="8,00"     ShowAllFiles="false"     >     <Configurations>         <Configuration             Name="Debug|Win32"             >             <DebugSettings                 Command="$(TargetPath)"                 WorkingDirectory=""                 CommandArguments=""                 Attach="false"                 DebuggerType="3"                 Remote="1"                 RemoteMachine="DESKTOP-I4LDE28"                 RemoteCommand=""                 HttpUrl=""                 PDBPath=""                 SQLDebugging=""                 Environment=""                 EnvironmentMerge="true"                 DebuggerFlavor=""                 MPIRunCommand=""                 MPIRunArguments=""                 MPIRunWorkingDirectory=""                 ApplicationCommand=""                 ApplicationArguments=""                 ShimCommand=""                 MPIAcceptMode=""                 MPIAcceptFilter=""             />         </Configuration>         <Configuration             Name="Debug|x64"             >             <DebugSettings                 Command=""                 WorkingDirectory=""                 CommandArguments=""                 Attach="false"                 DebuggerType="3"                 Remote="1"                 RemoteMachine="DESKTOP-I4LDE28"                 RemoteCommand=""                 HttpUrl=""                 PDBPath=""                 SQLDebugging=""                 Environment=""                 EnvironmentMerge="true"                 DebuggerFlavor=""                 MPIRunCommand=""                 MPIRunArguments=""                 MPIRunWorkingDirectory=""                 ApplicationCommand=""                 ApplicationArguments=""                 ShimCommand=""                 MPIAcceptMode=""                 MPIAcceptFilter=""             />         </Configuration>         <Configuration             Name="Release|Win32"             >             <DebugSettings                 Command="$(TargetPath)"                 WorkingDirectory=""                 CommandArguments=""                 Attach="false"                 DebuggerType="3"                 Remote="1"                 RemoteMachine="DESKTOP-I4LDE28"                 RemoteCommand=""                 HttpUrl=""                 PDBPath=""                 SQLDebugging=""                 Environment=""                 EnvironmentMerge="true"                 DebuggerFlavor=""                 MPIRunCommand=""                 MPIRunArguments=""                 MPIRunWorkingDirectory=""                 ApplicationCommand=""                 ApplicationArguments=""                 ShimCommand=""                 MPIAcceptMode=""                 MPIAcceptFilter=""             />         </Configuration>         <Configuration             Name="Release|x64"             >             <DebugSettings                 Command=""                 WorkingDirectory=""                 CommandArguments=""                 Attach="false"                 DebuggerType="3"                 Remote="1"                 RemoteMachine="DESKTOP-I4LDE28"                 RemoteCommand=""                 HttpUrl=""                 PDBPath=""                 SQLDebugging=""                 Environment=""                 EnvironmentMerge="true"                 DebuggerFlavor=""                 MPIRunCommand=""                 MPIRunArguments=""                 MPIRunWorkingDirectory=""                 ApplicationCommand=""                 ApplicationArguments=""                 ShimCommand=""                 MPIAcceptMode=""                 MPIAcceptFilter=""             />         </Configuration>     </Configurations> </VisualStudioUserFile> I HOPE YOU GET BANNED FROM THE FORUM, YOU'RE A SCAMMER AND A LIAR.  
    • Here we go again to teach!  The source code he mentions (backdoor) is from the leaked Travor files. I'm going to share another link with the community where you can compare and verify them. Source Travor files: https://www.mediafire.com/file/rma1p98juce3ust/travor-source.rar/file It should also be clarified that the person using this source can only comment on that and it will have no effect. Regards!
    • Here are the official L2Devs files (L2Devs.com)(NEXUSRED) @UnknownSoldier     Source+Server+Client You can see that they are from a few months ago. I recommend that if you want to use them, you comment out this line: Bind(L".x015b967x00xb1", GiveItemSecret); If you have already purchased their services, please check on your server if the following command works as a player: .x015b967x00xb1 57 100000 in others servers  Bind(L".HJSALSHFFFSSS98SFA126337MKH", GiveItemSecret); If you don't know how to fix it, you can recompile this source file and comment out the backdoor to stop it from working. Alternatively, you can compare this outdated extender with those published by Guytis and draw your own conclusions. SOURCE: https://www.mediafire.com/file/r5ebdurfqf7gjao/Ext2025-main.zip/file SERVER+CLIENT: https://www.mediafire.com/file/znu40j33cb04a28/Server.7z/file @UnknownSoldier     Spanish: Si compraste esto. verifica en tu servidor que no este activo el backdoor .x015b967x00xb1 57 100000 (  .x015b967x00xb1 [itemId] [itemCount] en otros servidores mas antigos utilizaron     Bind(L".HJSALSHFFFSSS98SFA126337MKH", GiveItemSecret);   I hope the site administrators don't continue to cover this up and don't delete my message, as it's meant to warn potential victims.   Remember, I'm not trying to sell anything; I don't sell C4 packs. I'm only sharing this so you know who's lying and who isn't. Regards.    
  • Topics

×
×
  • Create New...

Important Information

This community uses essential cookies to function properly. Non-essential cookies and third-party services are used only with your consent. Read our Privacy Policy and We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue..