테스트

aion-server 4.8

Gitteol
최고관리자 · 1 · 💬 0 클론/새로받기
 4.8 61f661d · 1 commits 새로받기(Pull)
game-server/data/handlers/admincommands/Send.java
package admincommands;

import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;

import javax.xml.bind.annotation.*;

import com.aionemu.gameserver.model.gameobjects.player.Player;
import com.aionemu.gameserver.network.aion.serverpackets.SM_CUSTOM_PACKET;
import com.aionemu.gameserver.network.aion.serverpackets.SM_CUSTOM_PACKET.PacketElementType;
import com.aionemu.gameserver.utils.PacketSendUtility;
import com.aionemu.gameserver.utils.ThreadPoolManager;
import com.aionemu.gameserver.utils.chathandlers.AdminCommand;
import com.aionemu.gameserver.utils.xml.JAXBUtil;

/**
 * This admin command is used for sending custom packets from server to client.
 * <p/>
 * Sends packets based on xml mappings in folder "./data/packets".<br />
 * Command details: "//send [1]<br />
 * * 1 - packet mappings name.<br />
 * * - 'demo' for file './data/packets/demo.xml'<br />
 * * - 'test' for file './data/packets/test.xml'<br />
 * <p/>
 * Created on: 14.07.2009 13:54:46
 * 
 * @author Aquanox, Neon
 */
public class Send extends AdminCommand {

	private static final String FOLDER = "./data/packets/";
	private static final String SCHEMAFILE = FOLDER + "packets.xsd";

	public Send() {
		super("send", "Sends custom packets.");

		setSyntaxInfo("<file> - Sends packets to your client, based on the ./data/packets/<file>.xml template.");
	}

	@Override
	public void execute(Player admin, String... params) {
		if (params.length == 0) {
			sendInfo(admin);
			return;
		}

		String fileName = params[0] + ".xml";
		File file = new File(FOLDER + fileName);

		if (!file.isFile()) {
			sendInfo(admin, "File " + fileName + " not found");
			return;
		}

		Packets packetsTemplate = JAXBUtil.deserialize(file, Packets.class, SCHEMAFILE);
		send(admin, packetsTemplate);
	}

	private void send(Player player, Packets packets) {
		String senderObjectId = String.valueOf(player.getObjectId());
		String targetObjectId = player.getTarget() != null ? String.valueOf(player.getTarget().getObjectId()) : "0";
		long delay = 0;
		for (Packet packetTemplate : packets) {
			SM_CUSTOM_PACKET packet = new SM_CUSTOM_PACKET(packetTemplate.getOpcode());

			for (Part part : packetTemplate.getParts()) {
				PacketElementType byCode = PacketElementType.getByCode(part.getType());

				String value = part.getValue();

				if (value.contains("${objectId}"))
					value = value.replace("${objectId}", senderObjectId);
				if (value.contains("${targetObjectId}"))
					value = value.replace("${targetObjectId}", targetObjectId);

				for (int i = 0; i < part.getRepeatCount(); i++)
					packet.addElement(byCode, value);
			}

			delay += packetTemplate.getDelay();

			ThreadPoolManager.getInstance().schedule(() -> PacketSendUtility.sendPacket(player, packet), delay);

			delay += packets.getDelay();
		}
	}

	@XmlAccessorType(XmlAccessType.FIELD)
	@XmlRootElement(name = "packets")
	private static class Packets implements Iterable<Packet> {

		@XmlElement(name = "packet")
		private List<Packet> packets;

		@XmlAttribute(name = "delay")
		private long delay = -1;

		public long getDelay() {
			return delay;
		}

		@Override
		public Iterator<Packet> iterator() {
			return packets.iterator();
		}

		@Override
		public String toString() {
			return "Packets" + "{delay=" + delay + ", packets=" + packets + '}';
		}
	}

	@XmlAccessorType(XmlAccessType.FIELD)
	@XmlRootElement(name = "packet")
	private static class Packet {

		@XmlElement(name = "part")
		private Collection<Part> parts = new ArrayList<>();

		@XmlAttribute(name = "opcode")
		private String opcode = "-1";

		@XmlAttribute(name = "delay")
		private long delay = 0;

		public int getOpcode() {
			return Integer.decode(opcode);
		}

		public Collection<Part> getParts() {
			return parts;
		}

		public long getDelay() {
			return delay;
		}

		@Override
		public String toString() {
			return "Packet" + "{opcode=" + opcode + ", parts=" + parts + '}';
		}
	}

	@XmlAccessorType(XmlAccessType.FIELD)
	@XmlRootElement(name = "part")
	private static class Part {

		@XmlAttribute(name = "type", required = true)
		private String type = null;

		@XmlAttribute(name = "value", required = true)
		private String value = null;

		@XmlAttribute(name = "repeat", required = true)
		private int repeatCount = 1;

		public char getType() {
			return type.charAt(0);
		}

		public String getValue() {
			return value;
		}

		public int getRepeatCount() {
			return repeatCount;
		}

		@Override
		public String toString() {
			return "Part" + "{type='" + type + '\'' + ", value='" + value + '\'' + ", repeatCount=" + repeatCount + '}';
		}
	}
}

📎 첨부파일

댓글 작성 권한이 없습니다.
🏆 포인트 랭킹 TOP 10
순위 닉네임 포인트
1 no_profile 타키야겐지쪽지보내기 자기소개 아이디로 검색 전체게시물 100,792
2 no_profile 동가리쪽지보내기 자기소개 아이디로 검색 전체게시물 58,079
3 no_profile 라프텔쪽지보내기 자기소개 아이디로 검색 전체게시물 51,771
4 no_profile 불멸의행복쪽지보내기 자기소개 아이디로 검색 전체게시물 36,923
5 서번트쪽지보내기 자기소개 아이디로 검색 전체게시물 35,011
6 no_profile 보거스쪽지보내기 자기소개 아이디로 검색 전체게시물 29,969
7 no_profile 닥터스쪽지보내기 자기소개 아이디로 검색 전체게시물 29,470
8 no_profile 검은고양이쪽지보내기 자기소개 아이디로 검색 전체게시물 29,077
9 no_profile Revolution쪽지보내기 자기소개 아이디로 검색 전체게시물 28,199
10 no_profile 호롤롤로쪽지보내기 자기소개 아이디로 검색 전체게시물 17,020
알림 0