首 页 >> 传世技术 >> 在0.2里增加GM命令方法
在0.2里增加GM命令方法
时间:2008-6-25 来源: 99945 发表讨论

今日新开服 明日新开服 昨日新开服 网通传奇私服 英雄合击私服 变态私服 仿盛大私服

在0.2里增加GM命令方法


在0.2里增加GM命令(example: .level ,.buy etc)……
文件: L2_Gameserver\ java\net\sf\l2j\gameserv\clientpacket\ Say2.java

/*
* $Header: /cvsroot/l2j/L2_Gameserver/java/net/sf/l2j/gameserver/
clientpackets/Say2.java,v 1.4 2004/07/04 11:09:02 l2chef Exp $
*
* $Author: l2chef $
* $Date: 2004/07/04 11:09:02 $
* $Revision: 1.4 $
* $Log: Say2.java,v $
* Revision 1.4 2004/07/04 11:09:02 l2chef
* commands removed.
* say is now only local
* shout and trade is global
*
* Revision 1.3 2004/06/29 22:55:35 l2chef
* tell and say works now. say is actually a server broadcast now
*
* Revision 1.2 2004/06/27 08:51:42 jeichhorn
* Added copyright notice
*
*
* 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. 

*/
package net.sf.l2j.gameserver.clientpackets;

import java.io.IOException;
import java.util.Iterator;
import java.util.List;
import java.util.logging.Logger;
import java.util.StringTokenizer;

import net.sf.l2j.gameserver.ClientThread;
import net.sf.l2j.gameserver.Connection;
import net.sf.l2j.gameserver.model.L2PcInstance;
import net.sf.l2j.gameserver.model.L2World;
import net.sf.l2j.gameserver.serverpackets.CreatureSay;
import net.sf.l2j.gameserver.serverpackets.TeleportToLocation;
import net.sf.l2j.gameserver.IdFactory;
import net.sf.l2j.gameserver.NpcTable;
import net.sf.l2j.gameserver.TradeController;
import net.sf.l2j.gameserver.model.L2BuyList;
import net.sf.l2j.gameserver.model.L2DoorInstance;
import net.sf.l2j.gameserver.model.L2NpcInstance;
import net.sf.l2j.gameserver.model.L2Object;
import net.sf.l2j.gameserver.serverpackets.BuyList;
import net.sf.l2j.gameserver.serverpackets.DoorInfo;
import net.sf.l2j.gameserver.serverpackets.DoorStatusUpdate;
import net.sf.l2j.gameserver.serverpackets.ItemList;
import net.sf.l2j.gameserver.serverpackets.NpcHtmlMessage;
import net.sf.l2j.gameserver.serverpackets.NpcInfo;
import net.sf.l2j.gameserver.serverpackets.StatusUpdate;
import net.sf.l2j.gameserver.serverpackets.UserInfo;
import net.sf.l2j.gameserver.templates.L2Npc;
/**
* This class ...
*
* @version $Revision: 1.4 $ $Date: 2004/07/04 11:09:02 $
*/
public class Say2 extends ClientBasePacket
{
private static final String _C__38_SAY2 = "[C] 38 Say2";
private static Logger _log = Logger.getLogger(Say2.class.getName()); 

public final static int ALL = 0;
public final static int SHOUT = 1;
public final static int TELL = 2;
public final static int PARTY = 3;
public final static int CLAN = 4;
public final static int PRIVATE_CHAT_PLAYER = 6; // used for petition
public final static int PRIVATE_CHAT_GM = 7; // used for petition
public final static int TRADE = 8;
public final static int GM_MESSAGE = 9;

/**
* packet type id 0x38
* format: cSd (S)
* @param decrypt
*/
public Say2(byte[] decrypt, ClientThread client) throws IOException
{
super(decrypt);
String text = readS();
int type = readD();
String target = null;
if (type == TELL)
{
target = readS();
}

_log.fine("Say type:"+type);

L2PcInstance activeChar = client.getActiveChar();
Connection con = client.getConnection();

try{ //if is not special command,it will be catch (to be a normal talk)
if (text.equals(".help"))
{
NpcHtmlMessage adminCommands = new NpcHtmlMessage(5);
StringBuffer html1 = new StringBuffer("<html><title>AdminCommands</title>");
html1.append("<body>");
html1.append("<br><a action=\"bypass -h spawn_monster\">spawn monster</a>");
// -> causes a 0x21 packet
html1.append("<br><a action=\"bypass -h come_here\">force target to move here</a>");
html1.append("<br><a action=\"bypass -h attack_me\">force target to attack</a>");
html1.append("<br><a action=\"bypass -h stats\">show statistics</a>");
html1.append("</body></html>");

adminCommands.setHtml(html1.toString());
con.sendPacket(adminCommands);
}
else if(text.startsWith(".teleport"))
{
StringTokenizer st = new StringTokenizer(text);
st.nextToken();// skip command
String x1 = st.nextToken();
int x = Integer.parseInt(x1);
String y1 = st.nextToken();
int y = Integer.parseInt(y1);
String z1 = st.nextToken();
int z = Integer.parseInt(z1);

CreatureSay cs = new CreatureSay(activeChar.getObjectId(), type,
activeChar.getName(), "teleporting to "+ x + " " + y + " "+z);
con.sendPacket(cs);

TeleportToLocation tele = new TeleportToLocation(activeChar, x,y,z);
con.sendPacket(tele);
activeChar.setX(x);
activeChar.setY(y);
activeChar.setZ(z);
}
else if (text.startsWith(".buy"))
{
int listId = 0;
listId = Integer.parseInt(text.substring(4));

L2BuyList list = TradeController.getInstance().getBuyList(listId);

if (list != null)
{
BuyList bl = new BuyList(list, activeChar.getAdena());
con.sendPacket(bl);
}
else
{
System.out.println("no buylist with id:" +listId);
}
}
else if (text.equals(".money"))
{
activeChar.addAdena(100000);
ItemList il = new ItemList(activeChar, true);
con.sendPacket(il);
}
else if (text.equals(".mob"))
{
L2Npc goblin = NpcTable.getInstance().getTemplate(3);
L2NpcInstance mob = new L2NpcInstance(goblin);
mob.setObjectId(IdFactory.getInstance().getNextId());
mob.setX(activeChar.getX());
mob.setY(activeChar.getY());
mob.setZ(activeChar.getZ());
mob.setCurrentHp(80);
mob.setMaxHp(198);
mob.setHeading(activeChar.getHeading());
mob.setUnknown1(1.08);
mob.setUnknown2(0.9983664);
NpcInfo ni = new NpcInfo(mob);
con.sendPacket(ni);

L2World.getInstance().storeObject(mob); // this is just a hack
to make the id globally known
}
else if (text.startsWith(".movehere"))
{
L2Object target1 = activeChar.getTarget();
if (target1 instanceof L2NpcInstance)
{
L2NpcInstance temp = (L2NpcInstance) target1;
temp.moveTo(activeChar.getX(), activeChar.getY(), activeChar.getZ(),0);
}
}
else if (text.startsWith(".sethere"))
{
L2Object target1 = activeChar.getTarget();
if (target1 instanceof L2NpcInstance)
{
L2NpcInstance temp = (L2NpcInstance) target1;
temp.setTo(activeChar.getX(), activeChar.getY(), activeChar.getZ(),
activeChar.getHeading());
}
}
else if (text.startsWith(".stopmove"))
{
L2Object target1 = activeChar.getTarget();
if (target1 instanceof L2NpcInstance)
{
L2NpcInstance temp = (L2NpcInstance) target1;
temp.stopMove();
}
}
else if (text.startsWith(".stat"))
{
int val = Integer.parseInt(text.substring(5));
System.out.println("changing stat: "+val);
StatusUpdate su = new StatusUpdate(activeChar.getObjectId());
su.addAttribute(val, 234);
con.sendPacket(su);
}
else if (text.startsWith(".exp"))
{
int val = Integer.parseInt(text.substring(5));
System.out.println("setting exp t "+val);
activeChar.setExp(val);
UserInfo ui = new UserInfo(activeChar);
con.sendPacket(ui);
}
else if (text.startsWith(".level"))
{
int val = Integer.parseInt(text.substring(7));
System.out.println("setting level t "+val);
activeChar.setLevel(val);
UserInfo ui = new UserInfo(activeChar);
con.sendPacket(ui);
}
else if (text.startsWith(".doorinfo"))
{
System.out.println("creating door ");
L2DoorInstance door = new L2DoorInstance();
door.setObjectId(0x48302222);
door.setX(activeChar.getX());
door.setY(activeChar.getY());
door.setZ(activeChar.getZ());

DoorInfo di = new DoorInfo(door);
con.sendPacket(di);

DoorStatusUpdate ds = new DoorStatusUpdate(door);
con.sendPacket(ds);
}
else
{
talk(activeChar, type, text,target);
}
}
catch(Exception e)//if command is input error format , the client will not be crash
{
talk(activeChar, type, text,target);
}
}

/* (non-Javadoc)
* @see net.sf.l2j.gameserver.clientpackets.ClientBasePacket#getType()
*/
public String getType()
{
return _C__38_SAY2;
}

/* (non-Javadoc)
* @function normal talk(not specal command)
*/
private void talk(L2PcInstance activeChar,int type,String text,String target)
{
CreatureSay cs = new CreatureSay(activeChar.getObjectId(), type, activeChar.getName(), text);

if (type == TELL)
{
L2PcInstance receiver = L2World.getInstance().getPlayer(target);
if (receiver != null)
{
receiver.sendPacket(cs);
activeChar.sendPacket(cs);
}
else
{
cs = new CreatureSay(activeChar.getObjectId(), type, activeChar.getName(),
"Player '"+target+"' is not online");
activeChar.sendPacket(cs);
}
}
else if (type == SHOUT || type == TRADE)
{
L2PcInstance[] players = L2World.getInstance().getAllPlayers();
for (int i = 0; i < players.length; i++)
{
players[i].sendPacket(cs);
}
}
else if (type == ALL)
{
List players = activeChar.getKnownPlayers();
for (Iterator iter = players.iterator(); iter.hasNext();)
{
L2PcInstance player = (L2PcInstance) iter.next();
player.sendPacket(cs);
}
activeChar.sendPacket(cs);

[全文完]

99945文章和资讯源于互联网,版权属于作者,如涉及版权问题请来信告之,谢谢!
鄂ICP备05017171号 违法不良信息举报中心