use of ejip123.Packet in project Citizens2 by CitizensDev.
the class EntityHumanNPC method updatePackets.
private void updatePackets(boolean navigating) {
if (updateCounter++ <= Setting.PACKET_UPDATE_DELAY.asInt())
return;
updateCounter = 0;
Location current = getBukkitEntity().getLocation(packetLocationCache);
Packet<?>[] packets = new Packet[navigating ? EnumItemSlot.values().length : EnumItemSlot.values().length + 1];
if (!navigating) {
packets[5] = new PacketPlayOutEntityHeadRotation(this, (byte) MathHelper.d(NMSImpl.getHeadYaw(this) * 256.0F / 360.0F));
}
int i = 0;
for (EnumItemSlot slot : EnumItemSlot.values()) {
packets[i++] = new PacketPlayOutEntityEquipment(getId(), slot, getEquipment(slot));
}
NMSImpl.sendPacketsNearby(getBukkitEntity(), current, packets);
}
use of ejip123.Packet in project Citizens2 by CitizensDev.
the class EntityHumanNPC method updatePackets.
private void updatePackets(boolean navigating) {
if (updateCounter++ <= Setting.PACKET_UPDATE_DELAY.asInt())
return;
updateCounter = 0;
Location current = getBukkitEntity().getLocation(packetLocationCache);
Packet<?>[] packets = new Packet[navigating ? this.inventory.armor.length : this.inventory.armor.length + 1];
if (!navigating) {
packets[this.inventory.armor.length] = new PacketPlayOutEntityHeadRotation(this, (byte) MathHelper.d(NMSImpl.getHeadYaw(this) * 256.0F / 360.0F));
}
for (int i = 0; i < this.inventory.armor.length; i++) {
packets[i] = new PacketPlayOutEntityEquipment(getId(), i, getEquipment(i));
}
NMSImpl.sendPacketsNearby(getBukkitEntity(), current, packets);
}
use of ejip123.Packet in project jop by jop-devel.
the class Server method request.
public void request(Packet receivedPacket, int offset) {
StringBuffer receiveBuffer = new StringBuffer(receivedPacket.len());
int bufferLength = receivedPacket.getData(offset, receiveBuffer);
String buffer = receiveBuffer.toString();
byte[] receivedData = buffer.getBytes();
Call rpcCall = new Call();
rpcCall.read(receivedData);
Handler handler = Handler.create(rpcCall);
Reply reply = handler.read();
StringBuffer portBuffer = new StringBuffer(22);
receivedPacket.getData(0, portBuffer);
int destinationPort = ((int) portBuffer.charAt(20) << 8) | ((int) portBuffer.charAt(21));
destIp = Ip.Ip(192, 168, 1, 1);
srcIp = Ip.Ip(192, 168, 1, 2);
srcPort = 111;
Dbg.wr(rpcCall.toString() + "\nHandler:" + reply.getData().length + "----");
Dbg.lf();
if (reply != null) {
idx = Udp.OFFSET << 2;
p = PacketPool.getFreshPacket();
p.setLen(reply.getWriteOffset() + idx);
byte[] Data = reply.getData();
for (int i = 0; i < reply.getWriteOffset(); i++) {
System.out.println("[" + i + "]=" + Data[i] + "; ");
p.setByte(Data[i] & 0xFF, idx + i);
}
Udp.send(p, srcIp, destIp, srcPort, destinationPort, true);
}
String data;
try {
data = new String(receivedData, 0, bufferLength);
} catch (Exception e) {
data = "null";
}
if (data.startsWith("exit"))
serverRunning = false;
receivedPacket.free();
}
use of ejip123.Packet in project jop by jop-devel.
the class Server method main.
public static void main(String[] args) {
// inits 10 packet buffers with 1500B each
PacketPool.init(10, 1500);
Serial ser;
if (TWO_SERIAL) {
// serial debug output
Dbg.initSer();
// simulator
ser = new Serial(10, 1000, Const.IO_UART_BG_MODEM_BASE);
} else {
// sends debug output over the network to 192.168.2.1:10000 (see init method)
DbgUdp.init();
// one byte every ~400us at 19200 baud
ser = new Serial(10, 1000, Const.IO_UART1_BASE);
}
// initializes a routing table with 3 routes
Router.init(3);
LinkLayer slip = Slip.init(9, 10000, ser, Ip.Ip(192, 168, 1, 2), 1500);
// ip (and therefore icmp and tcp) loop thread: period 50ms
Ip.init(6, 50000);
Router.addRoute(new Route(Ip.Ip(192, 168, 2, 0), Ip.Ip(255, 255, 255, 0), slip));
// where should packets go which are not matched by a route?
Router.setDefaultInterface(slip);
Dbg.wr("Starting Mission");
Dbg.lf();
RtThread.startMission();
Router.print();
Dbg.wr("Starting Server");
Dbg.lf();
Server server = new Server();
server.run();
}
use of ejip123.Packet in project jop by jop-devel.
the class HelloWorldHereIPing method main.
public static void main(String[] args) {
// inits 10 packet buffers with 1500B each
PacketPool.init(10, 1500);
Serial ser;
if (TWO_SERIAL) {
// serial debug output
Dbg.initSer();
// simulator
ser = new Serial(10, 1000, Const.IO_UART_BG_MODEM_BASE);
} else {
// sends debug output over the network to 192.168.2.1:10000 (see init method)
DbgUdp.init();
// one byte every ~400us at 19200 baud
ser = new Serial(10, 1000, Const.IO_UART1_BASE);
}
// initializes a routing table with 3 routes
Router.init(3);
LinkLayer slip = Slip.init(9, 10000, ser, Ip.Ip(192, 168, 1, 2), 1500);
// ip (and therefore icmp and tcp) loop thread: period 50ms
Ip.init(6, 50000);
Router.addRoute(new Route(Ip.Ip(192, 168, 2, 0), Ip.Ip(255, 255, 255, 0), slip));
// where should packets go which are not matched by a route?
Router.setDefaultInterface(slip);
RtThread.startMission();
Router.print();
forever();
}
Aggregations