本文整理汇总了Java中ethanjones.cubes.networking.packet.Packet类的典型用法代码示例。如果您正苦于以下问题:Java Packet类的具体用法?Java Packet怎么用?Java Packet使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Packet类属于ethanjones.cubes.networking.packet包,在下文中一共展示了Packet类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: runIf1
import ethanjones.cubes.networking.packet.Packet; //导入依赖的package包/类
private void runIf1(Class<? extends Packet> packetClass, boolean compress) {
if (socketMonitor.getPacketIDDatabase().contains(packetClass)) {
if (compress) {
dataOutputStream.writeByte(2);
} else {
dataOutputStream.writeByte(0);
}
dataOutputStream.writeInt(socketMonitor.getPacketIDDatabase().get(packetClass));
} else {
if (compress) {
dataOutputStream.writeByte(3);
} else {
dataOutputStream.writeByte(1);
}
dataOutputStream.writeUTF(packetClass.getName());
if (socketMonitor.getSide() == Side.Server) {
socketMonitor.getPacketIDDatabase().sendID(packetClass, socketMonitor);
}
}
}
示例2: updateIf2
import ethanjones.cubes.networking.packet.Packet; //导入依赖的package包/类
private void updateIf2(boolean compress, Packet packet) {
if (compress) {
// Reset
uncompressedOutput.reset();
compressionOutput.reset();
deflater.reset();
// Write packet
packet.write(uncompressedDataOutput);
// Deflate
deflater.setInput(uncompressedOutput.buffer(), 0, uncompressedOutput.count());
deflater.finish();
int length = deflater.deflate(deflateBuffer, 0, deflateBuffer.length);
while (length > 0) {
compressionOutput.write(deflateBuffer, 0, length);
length = deflater.deflate(deflateBuffer, 0, deflateBuffer.length);
}
// Write to outputstream
dataOutputStream.writeInt(compressionOutput.count());
dataOutputStream.writeInt(uncompressedOutput.count());
dataOutputStream.write(compressionOutput.buffer(), 0, compressionOutput.count());
} else {
packet.write(dataOutputStream);
}
}
示例3: processPackets
import ethanjones.cubes.networking.packet.Packet; //导入依赖的package包/类
@Override
public void processPackets() {
Side side = Side.getSide();
PacketQueue packetQueue;
switch (side) {
case Client:
packetQueue = toClient;
break;
case Server:
packetQueue = toServer;
break;
default:
return;
}
Packet packet = null;
Packet p = packetQueue.get();
while ((packet = p) != null) {
PacketDirection.checkPacketReceive(packet.getClass(), side);
packet.handlePacket();
p=packetQueue.get();
}
}
示例4: processPackets
import ethanjones.cubes.networking.packet.Packet; //导入依赖的package包/类
@Override
public void processPackets() {
Side side = Side.getSide();
PacketQueue packetQueue;
switch (side) {
case Client:
packetQueue = toClient;
break;
case Server:
packetQueue = toServer;
break;
default:
return;
}
Packet packet = null;
while ((packet = packetQueue.get()) != null) {
PacketDirection.checkPacketReceive(packet.getClass(), side);
packet.handlePacket();
}
}
示例5: sendPacketToServer
import ethanjones.cubes.networking.packet.Packet; //导入依赖的package包/类
public static void sendPacketToServer(Packet packet) {
if (clientNetworking != null) {
clientNetworking.sendPacketToServer(packet);
} else {
Log.warning("Cannot send " + packet.toString() + " as networking not set up yet");
}
}
示例6: sendPacketToClient
import ethanjones.cubes.networking.packet.Packet; //导入依赖的package包/类
public static void sendPacketToClient(Packet packet, ClientIdentifier clientIdentifier) {
if (serverNetworking != null) {
serverNetworking.sendPacketToClient(packet, clientIdentifier);
} else {
Log.warning("Cannot send " + packet.toString() + " as networking not set up yet");
}
}
示例7: sendPacketToOtherClients
import ethanjones.cubes.networking.packet.Packet; //导入依赖的package包/类
public static void sendPacketToOtherClients(Packet packet, ClientIdentifier otherThan) {
if (serverNetworking != null && Cubes.getServer() != null) {
for (ClientIdentifier clientIdentifier : Cubes.getServer().getAllClients()) {
if (clientIdentifier != otherThan) serverNetworking.sendPacketToClient(packet, clientIdentifier);
}
} else {
Log.warning("Cannot send " + packet.toString() + " as networking not set up yet");
}
}
示例8: sendPacketToAllClients
import ethanjones.cubes.networking.packet.Packet; //导入依赖的package包/类
public static void sendPacketToAllClients(Packet packet) {
if (serverNetworking != null && Cubes.getServer() != null) {
for (ClientIdentifier clientIdentifier : Cubes.getServer().getAllClients()) {
serverNetworking.sendPacketToClient(packet, clientIdentifier);
}
} else {
Log.warning("Cannot send " + packet.toString() + " as networking not set up yet");
}
}
示例9: copy
import ethanjones.cubes.networking.packet.Packet; //导入依赖的package包/类
@Override
public Packet copy() {
PacketArea p = new PacketArea();
if (Area.isShared()) {
p.area = this.area;
} else {
p.area = new Area(this.area);
}
return p;
}
示例10: sendPacketToServer
import ethanjones.cubes.networking.packet.Packet; //导入依赖的package包/类
@Override
public void sendPacketToServer(Packet packet) {
if (getNetworkingState() != NetworkingState.Running) {
Log.warning("Cannot send " + packet.toString() + " as " + getNetworkingState().name());
return;
}
PacketDirection.checkPacketSend(packet.getClass(), Side.Client);
socketMonitor.getSocketOutput().getPacketQueue().add(packet);
}
示例11: processPackets
import ethanjones.cubes.networking.packet.Packet; //导入依赖的package包/类
public void processPackets() {
Packet packet = null;
PacketQueue packetQueue = socketMonitor.getSocketInput().getPacketQueue();
Packet p = packetQueue.get();
while ((packet = p) != null) {
PacketDirection.checkPacketReceive(packet.getClass(), Side.Client);
packet.handlePacket();
p = packetQueue.get();
}
}
示例12: sendPacketToClient
import ethanjones.cubes.networking.packet.Packet; //导入依赖的package包/类
@Override
public void sendPacketToClient(Packet packet, ClientIdentifier clientIdentifier)
throws UnsupportedOperationException {
if (getNetworkingState() != NetworkingState.Running) {
Log.warning("Cannot send " + packet.toString() + " as " + getNetworkingState().name());
return;
}
PacketDirection.checkPacketSend(packet.getClass(), Side.Server);
clientIdentifier.getSocketMonitor().getSocketOutput().getPacketQueue().add(packet);
}
示例13: processPackets
import ethanjones.cubes.networking.packet.Packet; //导入依赖的package包/类
public void processPackets() {
for (SocketMonitor socketMonitor : sockets) {
Packet packet = null;
PacketQueue packetQueue = socketMonitor.getSocketInput().getPacketQueue();
Packet s = packetQueue.get();
while ((packet = s) != null) {
PacketDirection.checkPacketReceive(packet.getClass(), Side.Server);
packet.handlePacket();
s=packetQueue.get();
}
}
}
示例14: run
import ethanjones.cubes.networking.packet.Packet; //导入依赖的package包/类
@Override
public void run() {
PairedStreams pair = new PairedStreams();
DataOutputStream dataOutputStream = new DataOutputStream(pair.output);
DataInputStream dataInputStream = new DataInputStream(pair.input);
while (running.get()) {
try {
Packet packet = input.waitAndGet();
if (packet == null) continue;
if (!packet.shouldSend()) continue;
Side.setSide(sideOut);
Packet copy = packet.copy();
if (copy == packet) throw new IllegalStateException(packet.getClass().getName());
if (copy == null) {
Side.setSide(sideIn);
pair.reset();
packet.write(dataOutputStream);
Side.setSide(sideOut);
pair.updateInput();
copy = packet.getClass().newInstance();
copy.read(dataInputStream);
}
if (NETWORKING_DEBUG) Log.debug(packet.toString());
output.add(copy);
} catch (Exception e) {
Debug.crash(e);
}
}
}
示例15: copy
import ethanjones.cubes.networking.packet.Packet; //导入依赖的package包/类
@Override
public Packet copy() {
PacketArea p = new PacketArea();
if (Area.isShared()) {
p.area = this.area;
} else {
p.area = new Area(this.area);
}
return p;
}