1
0
mirror of https://github.com/Rogiel/l2jserver2 synced 2025-12-10 09:22:49 +00:00

Teleporter implementation

Signed-off-by: Rogiel <rogiel@rogiel.com>
This commit is contained in:
2011-05-22 02:04:35 -03:00
parent b3ff0795ec
commit 87ce7bb987
31 changed files with 900 additions and 31 deletions

View File

@@ -27,10 +27,14 @@ import com.google.inject.Inject;
import com.google.inject.Injector;
import com.l2jserver.game.net.Lineage2Connection;
import com.l2jserver.game.net.packet.ClientPacket;
import com.l2jserver.game.net.packet.client.AdminCommandPacket;
import com.l2jserver.game.net.packet.client.AuthLoginPacket;
import com.l2jserver.game.net.packet.client.CharacterActionPacket;
import com.l2jserver.game.net.packet.client.CharacterAppearingPacket;
import com.l2jserver.game.net.packet.client.CharacterChatMessagePacket;
import com.l2jserver.game.net.packet.client.CharacterCreatePacket;
import com.l2jserver.game.net.packet.client.CharacterRequestActionUse;
import com.l2jserver.game.net.packet.client.CharacterRequestBypass;
import com.l2jserver.game.net.packet.client.CharacterRequestInventoryPacket;
import com.l2jserver.game.net.packet.client.CharacterRequestMovePacket;
import com.l2jserver.game.net.packet.client.CharacterSelectPacket;
@@ -166,6 +170,14 @@ public class Lineage2PacketReader extends OneToOneDecoder {
return CharacterActionPacket.class;
case CharacterRequestInventoryPacket.OPCODE:
return CharacterRequestInventoryPacket.class;
case AdminCommandPacket.OPCODE:
return AdminCommandPacket.class;
case CharacterRequestBypass.OPCODE:
return CharacterRequestBypass.class;
case CharacterAppearingPacket.OPCODE:
return CharacterAppearingPacket.class;
case CharacterRequestActionUse.OPCODE:
return CharacterRequestActionUse.class;
default:
logger.warn("Unknown opcode: 0x{}", Integer.toHexString(opcode));
break;

View File

@@ -0,0 +1,84 @@
/*
* This file is part of l2jserver <l2jserver.com>.
*
* l2jserver 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.
*
* l2jserver 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 l2jserver. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jserver.game.net.packet.client;
import java.util.StringTokenizer;
import org.jboss.netty.buffer.ChannelBuffer;
import com.google.inject.Inject;
import com.l2jserver.game.net.Lineage2Connection;
import com.l2jserver.game.net.packet.AbstractClientPacket;
import com.l2jserver.service.admin.AdministratorService;
import com.l2jserver.service.game.spawn.NotSpawnedServiceException;
import com.l2jserver.service.game.spawn.SpawnService;
import com.l2jserver.util.BufferUtils;
import com.l2jserver.util.dimensional.Coordinate;
/**
* Executes an administrator action
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class AdminCommandPacket extends AbstractClientPacket {
/**
* The packet OPCODE
*/
public static final int OPCODE = 0x74;
/**
* The admin service
*/
private final AdministratorService adminService;
private final SpawnService spawnService;
/**
* The command
*/
private String command;
@Inject
public AdminCommandPacket(AdministratorService adminService,
SpawnService spawnService) {
this.adminService = adminService;
this.spawnService = spawnService;
}
@Override
public void read(Lineage2Connection conn, ChannelBuffer buffer) {
command = BufferUtils.readString(buffer).trim();
}
@Override
public void process(final Lineage2Connection conn) {
final StringTokenizer tokenizer = new StringTokenizer(command, " ");
final String cmd = tokenizer.nextToken();
if (cmd.equals("tele")) {
Coordinate coord = Coordinate.fromXYZ(
Integer.parseInt(tokenizer.nextToken()),
Integer.parseInt(tokenizer.nextToken()),
Integer.parseInt(tokenizer.nextToken()));
try {
spawnService.teleport(conn.getCharacter(), coord);
} catch (NotSpawnedServiceException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
// TODO implement admin commands
}
}

View File

@@ -0,0 +1,56 @@
/*
* This file is part of l2jserver <l2jserver.com>.
*
* l2jserver 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.
*
* l2jserver 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 l2jserver. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jserver.game.net.packet.client;
import org.jboss.netty.buffer.ChannelBuffer;
import com.google.inject.Inject;
import com.l2jserver.game.net.Lineage2Connection;
import com.l2jserver.game.net.packet.AbstractClientPacket;
import com.l2jserver.service.game.character.CharacterService;
/**
* Completes the creation of an character. Creates the object, inserts into the
* database and notifies the client about the status of the operation.
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class CharacterAppearingPacket extends AbstractClientPacket {
/**
* The packet OPCODE
*/
public static final int OPCODE = 0x3a;
/**
* The {@link CharacterService}
*/
private final CharacterService charService;
@Inject
public CharacterAppearingPacket(CharacterService charService) {
this.charService = charService;
}
@Override
public void read(Lineage2Connection conn, ChannelBuffer buffer) {
}
@Override
public void process(final Lineage2Connection conn) {
charService.appearing(conn.getCharacter());
}
}

View File

@@ -0,0 +1,103 @@
/*
* This file is part of l2jserver <l2jserver.com>.
*
* l2jserver 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.
*
* l2jserver 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 l2jserver. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jserver.game.net.packet.client;
import java.util.StringTokenizer;
import org.jboss.netty.buffer.ChannelBuffer;
import com.google.inject.Inject;
import com.l2jserver.game.net.Lineage2Connection;
import com.l2jserver.game.net.packet.AbstractClientPacket;
import com.l2jserver.model.id.ObjectID;
import com.l2jserver.model.id.object.NPCID;
import com.l2jserver.model.id.object.provider.ObjectIDResolver;
import com.l2jserver.model.world.NPC;
import com.l2jserver.service.game.npc.ActionServiceException;
import com.l2jserver.service.game.npc.NPCService;
import com.l2jserver.util.BufferUtils;
/**
* Executes an bypass command
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class CharacterRequestBypass extends AbstractClientPacket {
/**
* The packet OPCODE
*/
public static final int OPCODE = 0x23;
/**
* The {@link ObjectID} resolver
*/
private final ObjectIDResolver idResolver;
/**
* The {@link NPC} service
*/
private final NPCService npcService;
/**
* The bypass command
*/
private String command;
@Inject
public CharacterRequestBypass(ObjectIDResolver idResolver,
NPCService npcService) {
this.idResolver = idResolver;
this.npcService = npcService;
}
@Override
public void read(Lineage2Connection conn, ChannelBuffer buffer) {
this.command = BufferUtils.readString(buffer);
}
@Override
public void process(final Lineage2Connection conn) {
// parse command
final StringTokenizer tokenizer = new StringTokenizer(command, "_ ");
final String type = tokenizer.nextToken();
if (type.equals("npc")) {
final int objectId = Integer.parseInt(tokenizer.nextToken());
final ObjectID<NPC> id = idResolver.resolve(objectId);
if (!(id instanceof NPCID)) {
conn.sendActionFailed();
return;
}
final NPC npc = id.getObject();
try {
npcService.action(npc, conn.getCharacter(),
createArgumentArray(tokenizer));
} catch (ActionServiceException e) {
conn.sendActionFailed();
}
}
}
private String[] createArgumentArray(StringTokenizer tokenizer) {
if (!tokenizer.hasMoreTokens())
return new String[0];
final String[] args = new String[tokenizer.countTokens()];
int i = 0;
while (tokenizer.hasMoreTokens()) {
args[i++] = tokenizer.nextToken();
}
return args;
}
}

View File

@@ -0,0 +1,52 @@
/*
* This file is part of l2jserver <l2jserver.com>.
*
* l2jserver 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.
*
* l2jserver 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 l2jserver. If not, see <http://www.gnu.org/licenses/>.
*/
package com.l2jserver.game.net.packet.server;
import org.jboss.netty.buffer.ChannelBuffer;
import com.l2jserver.game.net.Lineage2Connection;
import com.l2jserver.game.net.packet.AbstractServerPacket;
import com.l2jserver.model.world.L2Character;
/**
* This is an message informing the client of extra informations from a player
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class CharacterInformationExtraPacket extends AbstractServerPacket {
/**
* The packet OPCODE
*/
public static final int OPCODE = 0xfe;
/**
* The character
*/
private L2Character character;
public CharacterInformationExtraPacket(L2Character character) {
super(OPCODE);
this.character = character;
}
@Override
public void write(Lineage2Connection conn, ChannelBuffer buffer) {
buffer.writeShort(0xcf); // opcode2
buffer.writeInt(character.getID().getID()); // object ID of Player
buffer.writeInt(0x00); // event effect id
}
}

View File

@@ -239,7 +239,7 @@ public class CharacterInformationPacket extends AbstractServerPacket {
buffer.writeInt(character.getAppearance().getHairStyle().option);
buffer.writeInt(character.getAppearance().getHairColor().option);
buffer.writeInt(character.getAppearance().getFace().option);
buffer.writeInt(0x00); // is gm
buffer.writeInt(0x01); // is gm
String title = "Testing"; // title
BufferUtils.writeString(buffer, title);