1
0
mirror of https://github.com/Rogiel/l2jserver2 synced 2025-12-06 07:32:46 +00:00

Minor improvements

Signed-off-by: Rogiel <rogiel@rogiel.com>
This commit is contained in:
2011-06-05 13:04:34 -03:00
parent 5990a97dfd
commit 0146d1aa82
21 changed files with 226 additions and 68 deletions

View File

@@ -31,10 +31,6 @@ import com.l2jserver.service.network.NetworkService;
import com.l2jserver.service.network.keygen.BlowfishKeygenService;
public class L2JGameServerMain {
/**
* @param args
* @throws InterruptedException
*/
public static void main(String[] args) throws InterruptedException {
final L2JGameServer server = new L2JGameServer();
try {

View File

@@ -27,6 +27,8 @@ import com.l2jserver.game.net.codec.Lineage2PacketReader;
import com.l2jserver.game.net.codec.Lineage2PacketWriter;
import com.l2jserver.game.net.packet.ServerPacket;
import com.l2jserver.game.net.packet.server.SM_ACTION_FAILED;
import com.l2jserver.game.net.packet.server.SM_COMMUNITY_HTML;
import com.l2jserver.game.net.packet.server.SM_HTML;
import com.l2jserver.game.net.packet.server.SM_SYSTEM_MESSAGE;
import com.l2jserver.model.id.object.CharacterID;
import com.l2jserver.model.template.ItemTemplate;
@@ -36,6 +38,7 @@ import com.l2jserver.service.game.world.WorldService;
import com.l2jserver.service.game.world.filter.impl.CharacterBroadcastFilter;
import com.l2jserver.service.network.NetworkService;
import com.l2jserver.util.factory.CollectionFactory;
import com.l2jserver.util.html.markup.HtmlTemplate;
/**
* This object connects the model (structure objects normally stored in the
@@ -311,6 +314,39 @@ public class Lineage2Connection {
return write(SM_ACTION_FAILED.SHARED_INSTANCE);
}
/**
* Sends a {@link SM_HTML} packet to the client. In the packet, the NPC will
* be null. If you wish to send the HTML with an NPC, you should send the
* packet directly.
* <p>
* This is an convenience method for <blockquote><code>
* conn.write(new SM_HTML(null, template));</code></blockquote>
*
* @param template
* the HTML template to be sent
* @return the {@link ChannelFuture} that will be notified once the packet
* has been written.
*/
public ChannelFuture sendHTML(HtmlTemplate template) {
return write(new SM_HTML(null, template));
}
/**
* Sends a {@link SM_COMMUNITY_HTML} packet to the client. HTML code is not
* displayed in the regular chat window, they will appear in a large one.
* <p>
* This is an convenience method for <blockquote><code>
* conn.write(new SM_COMMUNITY_HTML(template));</code></blockquote>
*
* @param template
* the HTML template to be sent
* @return the {@link ChannelFuture} that will be notified once the packet
* has been written.
*/
public ChannelFuture sendCommunityHTML(HtmlTemplate template) {
return write(new SM_COMMUNITY_HTML(template));
}
/**
* Broadcast a packet to all characters in this character knownlist.
* <p>

View File

@@ -28,7 +28,6 @@ import org.jboss.netty.channel.SimpleChannelHandler;
import com.google.common.base.Throwables;
import com.l2jserver.game.net.Lineage2Connection;
import com.l2jserver.game.net.packet.ClientPacket;
import com.l2jserver.game.net.packet.server.SM_HTML;
import com.l2jserver.service.game.world.WorldService;
import com.l2jserver.service.network.NettyNetworkService;
import com.l2jserver.util.html.markup.HtmlTemplate;
@@ -108,7 +107,7 @@ public class Lineage2PacketHandler extends SimpleChannelHandler {
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(" ", "");
@@ -118,11 +117,13 @@ public class Lineage2PacketHandler extends SimpleChannelHandler {
body.text(exception);
}
};
connection.write(new SM_HTML(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.sendCommunityHTML(template);
// order client not to wait any packet
connection.sendActionFailed();
final String[] lines = Throwables.getStackTraceAsString(e).split(
"\n");
for (final String line : lines) {
connection.sendMessage(line);
}
} finally {

View File

@@ -16,18 +16,13 @@
*/
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.game.spawn.CharacterAlreadyTeleportingServiceException;
import com.l2jserver.service.game.spawn.NotSpawnedServiceException;
import com.l2jserver.service.game.spawn.SpawnService;
import com.l2jserver.service.game.admin.AdministratorService;
import com.l2jserver.util.BufferUtils;
import com.l2jserver.util.geometry.Coordinate;
/**
* Executes an administrator action
@@ -43,8 +38,7 @@ public class CM_ADMIN_COMMAND extends AbstractClientPacket {
/**
* The admin service
*/
// private final AdministratorService adminService;
private final SpawnService spawnService;
private final AdministratorService adminService;
/**
* The command
@@ -52,10 +46,8 @@ public class CM_ADMIN_COMMAND extends AbstractClientPacket {
private String command;
@Inject
public CM_ADMIN_COMMAND(/* AdministratorService adminService, */
SpawnService spawnService) {
// this.adminService = adminService;
this.spawnService = spawnService;
public CM_ADMIN_COMMAND(AdministratorService adminService) {
this.adminService = adminService;
}
@Override
@@ -65,21 +57,23 @@ public class CM_ADMIN_COMMAND extends AbstractClientPacket {
@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) {
conn.sendActionFailed();
} catch (CharacterAlreadyTeleportingServiceException e) {
conn.sendActionFailed();
}
}
// 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) {
// conn.sendActionFailed();
// } catch (CharacterAlreadyTeleportingServiceException e) {
// conn.sendActionFailed();
// }
// }
adminService.command(conn, conn.getCharacter(), "", new String[] {});
// TODO implement admin commands
}
}

View File

@@ -19,6 +19,8 @@ package com.l2jserver.game.net.packet.client;
import java.util.StringTokenizer;
import org.jboss.netty.buffer.ChannelBuffer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.inject.Inject;
import com.l2jserver.game.net.Lineage2Connection;
@@ -38,6 +40,8 @@ import com.l2jserver.util.BufferUtils;
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class CM_BYPASS extends AbstractClientPacket {
private final Logger log = LoggerFactory.getLogger(this.getClass());
/**
* The packet OPCODE
*/
@@ -90,6 +94,8 @@ public class CM_BYPASS extends AbstractClientPacket {
} catch (CannotSetTargetServiceException e) {
conn.sendActionFailed();
}
} else {
log.warn("Client requested an bypass not supported by server");
}
}

View File

@@ -20,7 +20,6 @@ import org.jboss.netty.buffer.ChannelBuffer;
import com.l2jserver.game.net.Lineage2Connection;
import com.l2jserver.game.net.packet.AbstractServerPacket;
import com.l2jserver.game.net.packet.server.SM_CHAR_CREATE_FAIL.Reason;
import com.l2jserver.model.world.Actor;
/**
@@ -28,7 +27,6 @@ import com.l2jserver.model.world.Actor;
* successfully selected.
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
* @see Reason
*/
public class SM_ACTOR_POSITION extends AbstractServerPacket {
/**

View File

@@ -20,7 +20,6 @@ import org.jboss.netty.buffer.ChannelBuffer;
import com.l2jserver.game.net.Lineage2Connection;
import com.l2jserver.game.net.packet.AbstractServerPacket;
import com.l2jserver.game.net.packet.server.SM_CHAR_CREATE_FAIL.Reason;
import com.l2jserver.model.world.L2Character;
import com.l2jserver.model.world.actor.ActorExperience;
import com.l2jserver.util.BufferUtils;
@@ -30,7 +29,6 @@ import com.l2jserver.util.BufferUtils;
* successfully selected.
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
* @see Reason
*/
public class SM_CHAR_SELECTED extends AbstractServerPacket {
/**

View File

@@ -20,7 +20,6 @@ import org.jboss.netty.buffer.ChannelBuffer;
import com.l2jserver.game.net.Lineage2Connection;
import com.l2jserver.game.net.packet.AbstractServerPacket;
import com.l2jserver.game.net.packet.server.SM_CHAR_CREATE_FAIL.Reason;
import com.l2jserver.model.world.Actor;
import com.l2jserver.model.world.L2Character;
import com.l2jserver.service.game.chat.ChatMessageDestination;
@@ -31,7 +30,6 @@ import com.l2jserver.util.BufferUtils;
* successfully selected.
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
* @see Reason
*/
public class SM_CHAT extends AbstractServerPacket {
/**
@@ -56,16 +54,16 @@ public class SM_CHAT extends AbstractServerPacket {
*/
private int messageID = 0;
public SM_CHAT(Actor character,
ChatMessageDestination destination, String message) {
public SM_CHAT(Actor character, ChatMessageDestination destination,
String message) {
super(OPCODE);
this.actor = character;
this.destination = destination;
this.message = message;
}
public SM_CHAT(Actor actor,
ChatMessageDestination destination, int messageID) {
public SM_CHAT(Actor actor, ChatMessageDestination destination,
int messageID) {
super(OPCODE);
this.actor = actor;
this.destination = destination;

View File

@@ -0,0 +1,64 @@
/*
* 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.htmlparser.tags.Html;
import org.jboss.netty.buffer.ChannelBuffer;
import com.l2jserver.game.net.Lineage2Connection;
import com.l2jserver.game.net.packet.AbstractServerPacket;
import com.l2jserver.util.BufferUtils;
import com.l2jserver.util.html.markup.HtmlTemplate;
/**
* This packet sends an HTML message to be displayed in the client. As opposed
* to {@link SM_HTML}, this one displays it in the community board window.
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class SM_COMMUNITY_HTML extends AbstractServerPacket {
/**
* The packet OPCODE
*/
public static final int OPCODE = 0x7b;
/**
* The HTML contents
*/
private final String html;
public SM_COMMUNITY_HTML(String html) {
super(OPCODE);
this.html = html;
}
public SM_COMMUNITY_HTML(Html html) {
super(OPCODE);
this.html = html.toHtml();
}
public SM_COMMUNITY_HTML(HtmlTemplate template) {
super(OPCODE);
this.html = template.toHtmlString();
}
@Override
public void write(Lineage2Connection conn, ChannelBuffer buffer) {
buffer.writeByte(0x01); // display or hide
BufferUtils.writeString(buffer, html);
}
}

View File

@@ -20,14 +20,12 @@ import org.jboss.netty.buffer.ChannelBuffer;
import com.l2jserver.game.net.Lineage2Connection;
import com.l2jserver.game.net.packet.AbstractServerPacket;
import com.l2jserver.game.net.packet.server.SM_CHAR_CREATE_FAIL.Reason;
import com.l2jserver.model.world.L2Character;
/**
* This packet updates the movement type
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
* @see Reason
*/
public class SM_MOVE_TYPE extends AbstractServerPacket {
/**

View File

@@ -23,7 +23,6 @@ import org.jboss.netty.buffer.ChannelBuffer;
import com.l2jserver.game.net.Lineage2Connection;
import com.l2jserver.game.net.packet.AbstractServerPacket;
import com.l2jserver.game.net.packet.server.SM_CHAR_CREATE_FAIL.Reason;
import com.l2jserver.model.world.Actor;
import com.l2jserver.util.factory.CollectionFactory;
@@ -32,7 +31,6 @@ import com.l2jserver.util.factory.CollectionFactory;
* successfully selected.
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
* @see Reason
*/
public class SM_STATUS_UPDATE extends AbstractServerPacket {
/**

View File

@@ -20,7 +20,6 @@ import org.jboss.netty.buffer.ChannelBuffer;
import com.l2jserver.game.net.Lineage2Connection;
import com.l2jserver.game.net.packet.AbstractServerPacket;
import com.l2jserver.game.net.packet.server.SM_CHAR_CREATE_FAIL.Reason;
import com.l2jserver.model.world.Actor;
/**
@@ -28,7 +27,6 @@ import com.l2jserver.model.world.Actor;
* successfully selected.
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
* @see Reason
*/
public class SM_TARGET extends AbstractServerPacket {
/**

View File

@@ -20,7 +20,6 @@ import org.jboss.netty.buffer.ChannelBuffer;
import com.l2jserver.game.net.Lineage2Connection;
import com.l2jserver.game.net.packet.AbstractServerPacket;
import com.l2jserver.game.net.packet.server.SM_CHAR_CREATE_FAIL.Reason;
import com.l2jserver.model.world.L2Character;
import com.l2jserver.util.geometry.Point3D;
@@ -29,7 +28,6 @@ import com.l2jserver.util.geometry.Point3D;
* successfully selected.
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
* @see Reason
*/
public class SM_TELEPORT extends AbstractServerPacket {
/**

View File

@@ -16,7 +16,6 @@
*/
package com.l2jserver.model.server.attack;
import com.l2jserver.model.template.ItemTemplate;
import com.l2jserver.model.world.Actor;
/**

View File

@@ -33,6 +33,8 @@ import com.l2jserver.service.database.DatabaseService;
import com.l2jserver.service.database.JDBCDatabaseService;
import com.l2jserver.service.game.AttackService;
import com.l2jserver.service.game.AttackServiceImpl;
import com.l2jserver.service.game.admin.AdministratorService;
import com.l2jserver.service.game.admin.AdministratorServiceImpl;
import com.l2jserver.service.game.character.CharacterService;
import com.l2jserver.service.game.character.CharacterServiceImpl;
import com.l2jserver.service.game.chat.ChatService;
@@ -102,6 +104,8 @@ public class ServiceModule extends AbstractModule {
bind(ChatService.class).to(SimpleChatService.class)
.in(Scopes.SINGLETON);
bind(AdministratorService.class).to(AdministratorServiceImpl.class).in(
Scopes.SINGLETON);
bind(SpawnService.class).to(SpawnServiceImpl.class)
.in(Scopes.SINGLETON);
bind(BroadcastService.class).to(BroadcastServiceImpl.class).in(

View File

@@ -14,8 +14,9 @@
* 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.service.admin;
package com.l2jserver.service.game.admin;
import com.l2jserver.game.net.Lineage2Connection;
import com.l2jserver.model.world.L2Character;
import com.l2jserver.service.Service;
@@ -28,6 +29,8 @@ public interface AdministratorService extends Service {
/**
* Executes an command
*
* @param conn
* the lineage 2 connection
* @param character
* the admin character
* @param command
@@ -35,7 +38,8 @@ public interface AdministratorService extends Service {
* @param args
* the arguments
*/
void command(L2Character character, String command, String... args);
void command(Lineage2Connection conn, L2Character character,
String command, String... args);
/**
* The base interface for Administrator commands

View File

@@ -14,13 +14,15 @@
* 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.service.admin;
package com.l2jserver.service.game.admin;
import java.util.List;
import com.l2jserver.game.net.Lineage2Connection;
import com.l2jserver.model.id.object.CharacterID;
import com.l2jserver.model.world.L2Character;
import com.l2jserver.service.AbstractService;
import com.l2jserver.service.game.admin.panel.AdminHomeTemplate;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>
@@ -30,13 +32,10 @@ public class AdministratorServiceImpl extends AbstractService implements
AdministratorService {
@SuppressWarnings("unused")
private List<CharacterID> online;
@Override
public void command(L2Character character, String command, String... args) {
if(command.equals("log")) {
if(args.length == 2) {
}
}
public void command(Lineage2Connection conn, L2Character character,
String command, String... args) {
conn.sendCommunityHTML(new AdminHomeTemplate());
}
}

View File

@@ -14,7 +14,7 @@
* 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.service.admin;
package com.l2jserver.service.game.admin;
import com.l2jserver.model.world.L2Character;
import com.l2jserver.service.Service;

View File

@@ -0,0 +1,32 @@
/*
* 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.service.game.admin.panel;
import com.l2jserver.util.html.markup.HtmlTemplate;
import com.l2jserver.util.html.markup.MarkupTag;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class AdminHomeTemplate extends HtmlTemplate {
@Override
protected void build(MarkupTag body) {
body.text("Welcome to l2jserver2 administration panel.").br();
body.addLink("Teleport", "admin teleport").br();
body.addLink("Online characters", "admin online").br();
}
}

View File

@@ -0,0 +1,33 @@
/*
* 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.service.game.admin.panel;
import com.l2jserver.util.html.markup.HtmlTemplate;
import com.l2jserver.util.html.markup.MarkupTag;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>
*
*/
public class TeleportTemplate extends HtmlTemplate {
@Override
protected void build(MarkupTag body) {
body.text("You can teleport to the following places:").br();
body.addLink("Aden", "admin teleport aden");
body.addLink("Giran", "admin teleport giran");
}
}

View File

@@ -29,6 +29,7 @@ import com.l2jserver.GameServerModule;
import com.l2jserver.model.template.CharacterTemplate;
import com.l2jserver.model.template.NPCTemplate;
import com.l2jserver.model.template.TeleportationTemplate;
import com.l2jserver.service.game.admin.panel.AdminHomeTemplate;
import com.l2jserver.util.jaxb.CharacterTemplateIDAdapter;
import com.l2jserver.util.jaxb.ItemTemplateIDAdapter;
import com.l2jserver.util.jaxb.NPCTemplateIDAdapter;
@@ -47,6 +48,9 @@ public class XMLMappingTest {
public static void main(String[] args) throws JAXBException, IOException {
// final List<NPCTemplate> templates = CollectionFactory.newList();
System.out.println(new AdminHomeTemplate().toHtmlString());
System.exit(0);
final JAXBContext c = JAXBContext.newInstance(CharacterTemplate.class,
NPCTemplate.class, TeleportationTemplate.class);
final Unmarshaller u = c.createUnmarshaller();