mirror of
https://github.com/Rogiel/l2jserver2
synced 2025-12-07 07:52:57 +00:00
Gatekeeper complete implementation
Signed-off-by: Rogiel <rogiel@rogiel.com>
This commit is contained in:
@@ -100,29 +100,33 @@ public class Lineage2PacketHandler extends SimpleChannelHandler {
|
||||
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent event)
|
||||
throws Exception {
|
||||
final Throwable e = event.getCause();
|
||||
if (e instanceof ChannelException)
|
||||
return;
|
||||
if (e instanceof IOException)
|
||||
return;
|
||||
if (!connection.isConnected())
|
||||
// no point sending error messages if the client is disconnected
|
||||
return;
|
||||
|
||||
// TODO only send exception stack trace in development mode!
|
||||
final String exception = Throwables.getStackTraceAsString(e)
|
||||
.replaceAll("\n", "<br>").replace(" ", "");
|
||||
final HtmlTemplate template = new HtmlTemplate("Java Exception") {
|
||||
@Override
|
||||
public void build(MarkupTag body) {
|
||||
body.text(exception);
|
||||
try {
|
||||
if (e instanceof ChannelException)
|
||||
return;
|
||||
if (e instanceof IOException)
|
||||
return;
|
||||
if (!connection.isConnected())
|
||||
// no point sending error messages if the client is disconnected
|
||||
return;
|
||||
|
||||
// TODO only send exception stack trace in development mode!
|
||||
final String exception = Throwables.getStackTraceAsString(e)
|
||||
.replaceAll("\n", "<br>").replace(" ", "");
|
||||
final HtmlTemplate template = new HtmlTemplate("Java Exception") {
|
||||
@Override
|
||||
public void build(MarkupTag body) {
|
||||
body.text(exception);
|
||||
}
|
||||
};
|
||||
connection.write(new NPCHtmlMessagePacket(null, template));
|
||||
connection.sendActionFailed(); // order client not to wait any packet
|
||||
|
||||
final String[] lines = Throwables.getStackTraceAsString(e).split("\n");
|
||||
for(final String line : lines) {
|
||||
connection.sendMessage(line);
|
||||
}
|
||||
};
|
||||
connection.write(new NPCHtmlMessagePacket(null, template));
|
||||
connection.sendActionFailed(); // order client not to wait any packet
|
||||
|
||||
final String[] lines = Throwables.getStackTraceAsString(e).split("\n");
|
||||
for(final String line : lines) {
|
||||
connection.sendMessage(line);
|
||||
} finally {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,14 +33,14 @@ import com.l2jserver.util.jaxb.TeleportationTemplateIDAdapter;
|
||||
*/
|
||||
@XmlJavaTypeAdapter(TeleportationTemplateIDAdapter.class)
|
||||
public class TeleportationTemplateID extends
|
||||
TemplateID<TeleportationTemplate, String> {
|
||||
TemplateID<TeleportationTemplate, Integer> {
|
||||
/**
|
||||
* The template service
|
||||
*/
|
||||
private final TemplateService templateService;
|
||||
|
||||
@Inject
|
||||
public TeleportationTemplateID(@Assisted String id,
|
||||
public TeleportationTemplateID(@Assisted int id,
|
||||
TemplateService templateService) {
|
||||
super(id);
|
||||
this.templateService = templateService;
|
||||
|
||||
@@ -25,5 +25,5 @@ import com.l2jserver.model.id.template.TeleportationTemplateID;
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public interface TeleportationTemplateIDProvider extends
|
||||
TemplateIDProvider<String, TeleportationTemplateID> {
|
||||
TemplateIDProvider<Integer, TeleportationTemplateID> {
|
||||
}
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
*/
|
||||
package com.l2jserver.model.template;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
@@ -33,19 +32,16 @@ import org.eclipse.persistence.oxm.annotations.XmlCDATA;
|
||||
|
||||
import com.l2jserver.model.id.template.ItemTemplateID;
|
||||
import com.l2jserver.model.id.template.NPCTemplateID;
|
||||
import com.l2jserver.model.id.template.TeleportationTemplateID;
|
||||
import com.l2jserver.model.template.NPCTemplate.TeleporterMetadata.TeleporterTeleportMetadata;
|
||||
import com.l2jserver.model.world.Actor.ActorSex;
|
||||
import com.l2jserver.model.world.NPC;
|
||||
import com.l2jserver.util.jaxb.ItemTemplateIDAdapter;
|
||||
import com.l2jserver.util.jaxb.NPCTemplateIDAdapter;
|
||||
import com.l2jserver.util.jaxb.TeleportationTemplateIDAdapter;
|
||||
|
||||
/**
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
@XmlRootElement(name = "npc")
|
||||
@XmlType(namespace = "npc")
|
||||
@XmlType(namespace = "npc", name = "npc")
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
public class NPCTemplate extends ActorTemplate<NPC> {
|
||||
@XmlAttribute(name = "id")
|
||||
@@ -226,60 +222,6 @@ public class NPCTemplate extends ActorTemplate<NPC> {
|
||||
protected String script = null;
|
||||
}
|
||||
|
||||
@XmlElement(name = "teleporter")
|
||||
protected TeleporterMetadata teleporter = null;
|
||||
|
||||
@XmlType(namespace = "npc")
|
||||
protected static class TeleporterMetadata {
|
||||
@XmlAttribute(name = "default")
|
||||
protected String defaultTeleport = null;
|
||||
@XmlElement(name = "teleport")
|
||||
protected List<TeleporterTeleportMetadata> teleports = null;
|
||||
|
||||
@XmlType(namespace = "npc")
|
||||
protected static class TeleporterTeleportMetadata {
|
||||
@XmlAttribute(name = "id")
|
||||
protected String id;
|
||||
@XmlElement(name = "region")
|
||||
protected List<TeleportRegion> regions = null;
|
||||
}
|
||||
}
|
||||
|
||||
@XmlType(namespace = "npc")
|
||||
public static class TeleportRegion {
|
||||
@XmlAttribute(name = "id")
|
||||
@XmlJavaTypeAdapter(value = TeleportationTemplateIDAdapter.class)
|
||||
protected TeleportationTemplateID id;
|
||||
@XmlAttribute(name = "price")
|
||||
protected int price = 0;
|
||||
@XmlAttribute(name = "item")
|
||||
@XmlJavaTypeAdapter(ItemTemplateIDAdapter.class)
|
||||
protected ItemTemplateID item;
|
||||
|
||||
/**
|
||||
* @return the id
|
||||
*/
|
||||
public TeleportationTemplateID getID() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the price
|
||||
*/
|
||||
public int getPrice() {
|
||||
return price;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the item
|
||||
*/
|
||||
public ItemTemplateID getItem() {
|
||||
return item;
|
||||
}
|
||||
|
||||
// TODO implement conditions
|
||||
}
|
||||
|
||||
@XmlElement(name = "talk")
|
||||
protected TalkMetadata talk = null;
|
||||
|
||||
@@ -746,28 +688,6 @@ public class NPCTemplate extends ActorTemplate<NPC> {
|
||||
return ai.script;
|
||||
}
|
||||
|
||||
public List<TeleportRegion> getTeleportRegions(String id) {
|
||||
if (teleporter == null)
|
||||
return Collections.emptyList();
|
||||
for (final TeleporterTeleportMetadata teleport : teleporter.teleports) {
|
||||
if (teleport.id.equals(id)) {
|
||||
return Collections.unmodifiableList(teleport.regions);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<TeleportRegion> getTeleportRegions() {
|
||||
if (teleporter == null)
|
||||
return Collections.emptyList();
|
||||
for (final TeleporterTeleportMetadata teleport : teleporter.teleports) {
|
||||
if (teleport.id.equals(teleporter.defaultTeleport)) {
|
||||
return Collections.unmodifiableList(teleport.regions);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getHTML(String id) {
|
||||
if (talk == null)
|
||||
return null;
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
*/
|
||||
package com.l2jserver.model.template;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import javax.xml.bind.annotation.XmlAttribute;
|
||||
@@ -24,9 +26,11 @@ import javax.xml.bind.annotation.XmlRootElement;
|
||||
import javax.xml.bind.annotation.XmlType;
|
||||
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
|
||||
|
||||
import com.l2jserver.model.id.template.ItemTemplateID;
|
||||
import com.l2jserver.model.id.template.TeleportationTemplateID;
|
||||
import com.l2jserver.util.dimensional.Coordinate;
|
||||
import com.l2jserver.util.jaxb.CoordinateAdapter;
|
||||
import com.l2jserver.util.jaxb.ItemTemplateIDAdapter;
|
||||
import com.l2jserver.util.jaxb.TeleportationTemplateIDAdapter;
|
||||
|
||||
/**
|
||||
@@ -40,12 +44,25 @@ import com.l2jserver.util.jaxb.TeleportationTemplateIDAdapter;
|
||||
public class TeleportationTemplate extends AbstractTemplate<Coordinate> {
|
||||
@XmlAttribute(name = "id")
|
||||
@XmlJavaTypeAdapter(TeleportationTemplateIDAdapter.class)
|
||||
private TeleportationTemplateID id;
|
||||
@XmlElement(name = "name")
|
||||
private String name;
|
||||
@XmlElement(name = "coordinate")
|
||||
protected TeleportationTemplateID id;
|
||||
@XmlAttribute(name = "name")
|
||||
protected String name;
|
||||
|
||||
@XmlAttribute(name = "item")
|
||||
@XmlJavaTypeAdapter(ItemTemplateIDAdapter.class)
|
||||
protected ItemTemplateID itemTemplateID;
|
||||
@XmlAttribute(name = "price")
|
||||
protected int price;
|
||||
|
||||
@XmlElement(name = "point")
|
||||
@XmlJavaTypeAdapter(CoordinateAdapter.class)
|
||||
private Coordinate coordinate;
|
||||
protected Coordinate coordinate;
|
||||
|
||||
protected List<TeleportRestriction> restrictions;
|
||||
|
||||
public enum TeleportRestriction {
|
||||
NOBLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Coordinate create() {
|
||||
@@ -59,6 +76,27 @@ public class TeleportationTemplate extends AbstractTemplate<Coordinate> {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the id
|
||||
*/
|
||||
public TeleportationTemplateID getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the itemTemplateID
|
||||
*/
|
||||
public ItemTemplateID getItemTemplateID() {
|
||||
return itemTemplateID;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the price
|
||||
*/
|
||||
public int getPrice() {
|
||||
return price;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the coordinate
|
||||
*/
|
||||
|
||||
@@ -16,20 +16,14 @@
|
||||
*/
|
||||
package com.l2jserver.model.world.npc.controller;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.l2jserver.game.net.Lineage2Connection;
|
||||
import com.l2jserver.game.net.packet.server.NPCHtmlMessagePacket;
|
||||
import com.l2jserver.model.id.template.provider.TeleportationTemplateIDProvider;
|
||||
import com.l2jserver.model.template.NPCTemplate.TeleportRegion;
|
||||
import com.l2jserver.model.template.TeleportationTemplate;
|
||||
import com.l2jserver.model.world.L2Character;
|
||||
import com.l2jserver.model.world.NPC;
|
||||
import com.l2jserver.service.game.spawn.SpawnService;
|
||||
import com.l2jserver.util.exception.L2Exception;
|
||||
import com.l2jserver.util.html.markup.HtmlTemplate;
|
||||
import com.l2jserver.util.html.markup.MarkupTag;
|
||||
|
||||
/**
|
||||
* This controller is used to control teleporters (e.g. gatekeepers)
|
||||
@@ -49,29 +43,9 @@ public class TeleporterController extends AbstractNPCController {
|
||||
public void action(NPC npc, Lineage2Connection conn, L2Character character,
|
||||
String... args) throws L2Exception {
|
||||
if (args.length >= 2) {
|
||||
if (args[0].equals("TeleportList")) {
|
||||
final List<TeleportRegion> regions = getTeleportRegions(npc,
|
||||
args[1]);
|
||||
final HtmlTemplate template = new HtmlTemplate() {
|
||||
@Override
|
||||
protected void build(MarkupTag body) {
|
||||
body.textcode(556);
|
||||
for (final TeleportRegion region : regions) {
|
||||
body.addLink(
|
||||
region.getID().getTemplate().getName()
|
||||
+ " - "
|
||||
+ region.getPrice()
|
||||
+ " "
|
||||
+ region.getItem().getTemplate()
|
||||
.getName(),
|
||||
"Teleport " + region.getID().getID()).br();
|
||||
}
|
||||
}
|
||||
};
|
||||
conn.write(new NPCHtmlMessagePacket(npc, template));
|
||||
} else if (args[0].equals("Teleport")) {
|
||||
if (args[0].equals("goto")) {
|
||||
final TeleportationTemplate tele = teleportationIdProvider
|
||||
.createID(args[1]).getTemplate();
|
||||
.createID(Integer.parseInt(args[1])).getTemplate();
|
||||
if (tele == null) {
|
||||
// TODO chat
|
||||
conn.sendActionFailed();
|
||||
@@ -83,8 +57,4 @@ public class TeleporterController extends AbstractNPCController {
|
||||
}
|
||||
super.action(npc, conn, character, args);
|
||||
}
|
||||
|
||||
protected List<TeleportRegion> getTeleportRegions(NPC npc, String id) {
|
||||
return npc.getTemplate().getTeleportRegions(id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,7 +53,11 @@ public class NPCServiceImpl extends AbstractService implements NPCService {
|
||||
*/
|
||||
private final NPCDAO npcDao;
|
||||
|
||||
private final TeleporterController controller = new TeleporterController();
|
||||
/**
|
||||
* Temporary only
|
||||
*/
|
||||
@Inject
|
||||
private TeleporterController controller;
|
||||
|
||||
@Inject
|
||||
public NPCServiceImpl(SpawnService spawnService,
|
||||
|
||||
@@ -163,6 +163,6 @@ public class XMLTemplateService extends AbstractService implements
|
||||
@XmlType(namespace = "teleports")
|
||||
public static class TeleportationTemplateContainer {
|
||||
@XmlElement(name = "teleport")
|
||||
private List<TeleportationTemplate> templates;
|
||||
public List<TeleportationTemplate> templates;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ import com.l2jserver.model.id.template.provider.TeleportationTemplateIDProvider;
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public class TeleportationTemplateIDAdapter extends
|
||||
XmlAdapter<String, TeleportationTemplateID> {
|
||||
XmlAdapter<Integer, TeleportationTemplateID> {
|
||||
private final TeleportationTemplateIDProvider provider;
|
||||
|
||||
public TeleportationTemplateIDAdapter() {
|
||||
@@ -43,7 +43,7 @@ public class TeleportationTemplateIDAdapter extends
|
||||
}
|
||||
|
||||
@Override
|
||||
public TeleportationTemplateID unmarshal(String v) throws Exception {
|
||||
public TeleportationTemplateID unmarshal(Integer v) throws Exception {
|
||||
if (v == null)
|
||||
return null;
|
||||
if (provider == null)
|
||||
@@ -52,7 +52,7 @@ public class TeleportationTemplateIDAdapter extends
|
||||
}
|
||||
|
||||
@Override
|
||||
public String marshal(TeleportationTemplateID v) throws Exception {
|
||||
public Integer marshal(TeleportationTemplateID v) throws Exception {
|
||||
if (v == null)
|
||||
return null;
|
||||
return v.getID();
|
||||
|
||||
Reference in New Issue
Block a user