Search in sources :

Example 31 with Packet

use of net.minecraft.server.v1_15_R1.Packet in project jop by jop-devel.

the class Ppp method doSend.

void doSend() {
    if (reconnectRequest) {
        // System.out.print("3");
        // start over
        modemHangUp();
        modemInit();
    }
    if (disconnectRequest) {
        // stop the connection
        modemHangUp();
    }
    if (state == CONNECTED) {
        // send waiting ip packets
        if (scnt == 0) {
            // transmit buffer is free
            // use IP timeout
            globTimer = Timer.getTimeoutMs(IP_SEND);
            // 
            // get a ready to send packet with source from this driver.
            // 
            Packet p = PacketPool.getTxPacket(single);
            if (p != null) {
                // send one packet
                sendIp(p);
            }
        } else {
            // check sendTimer;
            if (Timer.timeout(globTimer)) {
                // System.out.print("4");
                // start over
                modemHangUp();
                modemInit();
            }
        }
    } else {
        // do the negotiation stuff
        dropIp();
        if (Timer.timeout(globTimer)) {
            /*
Dbg.intVal(state);
if (lcpAck) Dbg.wr('t'); else Dbg.wr('f');
*/
            if (scnt == 0) {
                // once every three seconds send a REQ
                if (state == MODEM_OK) {
                    makeLCP();
                    state = LCP_SENT;
                } else if (state == LCP_OK && lcpAck) {
                    makePAP();
                    state = PAP_SENT;
                // } else if (state == PAP_OK && ipcpAck) { // wait for remote ipcp and ACK first on Linux
                } else if (state >= PAP_OK && state < CONNECTED) {
                    // ONE
                    makeIPCP();
                    state = IPCP_SENT;
                    // incremenet counter to start over when no respond
                    ++rejCnt;
                }
                // use negotiation timeout
                globTimer = Timer.getTimeoutMs(NEG_SEND);
            }
        }
    }
}
Also used : Packet(ejip123.Packet)

Example 32 with Packet

use of net.minecraft.server.v1_15_R1.Packet in project vespa by vespa-engine.

the class FastSearcher method searchTwoPhase.

private Result searchTwoPhase(FS4Channel channel, Query query, QueryPacket queryPacket, CacheKey cacheKey) throws IOException {
    if (isLoggingFine())
        getLogger().finest("sending query packet");
    try {
        boolean couldSend = channel.sendPacket(queryPacket);
        if (!couldSend)
            return new Result(query, ErrorMessage.createBackendCommunicationError("Could not reach '" + getName() + "'"));
    } catch (InvalidChannelException e) {
        return new Result(query, ErrorMessage.createBackendCommunicationError("Invalid channel " + getName()));
    } catch (IllegalStateException e) {
        return new Result(query, ErrorMessage.createBackendCommunicationError("Illegal state in FS4: " + e.getMessage()));
    }
    BasicPacket[] basicPackets;
    try {
        basicPackets = channel.receivePackets(query.getTimeLeft(), 1);
    } catch (ChannelTimeoutException e) {
        return new Result(query, ErrorMessage.createTimeout("Timeout while waiting for " + getName()));
    } catch (InvalidChannelException e) {
        return new Result(query, ErrorMessage.createBackendCommunicationError("Invalid channel for " + getName()));
    }
    if (basicPackets.length == 0) {
        return new Result(query, ErrorMessage.createBackendCommunicationError(getName() + " got no packets back"));
    }
    if (isLoggingFine())
        getLogger().finest("got packets " + basicPackets.length + " packets");
    ensureInstanceOf(QueryResultPacket.class, basicPackets[0], getName());
    QueryResultPacket resultPacket = (QueryResultPacket) basicPackets[0];
    if (isLoggingFine())
        getLogger().finest("got query packet. " + "docsumClass=" + query.getPresentation().getSummary());
    if (query.getPresentation().getSummary() == null)
        query.getPresentation().setSummary(getDefaultDocsumClass());
    Result result = new Result(query);
    addMetaInfo(query, queryPacket.getQueryPacketData(), resultPacket, result, false);
    addUnfilledHits(result, resultPacket.getDocuments(), false, queryPacket.getQueryPacketData(), cacheKey);
    Packet[] packets;
    PacketWrapper packetWrapper = cacheControl.lookup(cacheKey, query);
    if (packetWrapper != null) {
        cacheControl.updateCacheEntry(cacheKey, query, resultPacket);
    } else {
        if (resultPacket.getCoverageFeature() && !resultPacket.getCoverageFull()) {
        // Don't add error here, it was done in first phase
        // No check if packetWrapper already exists, since incomplete
        // first phase data won't be cached anyway.
        } else {
            packets = new Packet[1];
            packets[0] = resultPacket;
            cacheControl.cache(cacheKey, query, new DocsumPacketKey[0], packets);
        }
    }
    return result;
}
Also used : InvalidChannelException(com.yahoo.fs4.mplex.InvalidChannelException) QueryResultPacket(com.yahoo.fs4.QueryResultPacket) QueryResultPacket(com.yahoo.fs4.QueryResultPacket) QueryPacket(com.yahoo.fs4.QueryPacket) PongPacket(com.yahoo.fs4.PongPacket) BasicPacket(com.yahoo.fs4.BasicPacket) GetDocSumsPacket(com.yahoo.fs4.GetDocSumsPacket) Packet(com.yahoo.fs4.Packet) PingPacket(com.yahoo.fs4.PingPacket) BasicPacket(com.yahoo.fs4.BasicPacket) ChannelTimeoutException(com.yahoo.fs4.ChannelTimeoutException) Result(com.yahoo.search.Result)

Example 33 with Packet

use of net.minecraft.server.v1_15_R1.Packet in project vespa by vespa-engine.

the class FS4Channel method receivePackets.

/**
 * Receives the given number of packets and returns them, OR
 * <ul>
 * <li>Returns a smaller number of packets if an error or eol packet is received
 * <li>Throws a ChannelTimeoutException if timeout occurs before all packets
 * are received. Packets received with the wrong channel id are ignored.
 * </ul>
 *
 * @param timeout the number of ms to attempt to get packets before throwing an exception
 * @param packetCount the number of packets to receive, or -1 to receive any number up to eol/error
 */
public BasicPacket[] receivePackets(long timeout, int packetCount) throws InvalidChannelException, ChannelTimeoutException {
    ensureValid();
    List<BasicPacket> packets = new ArrayList<>(12);
    long startTime = SystemTimer.INSTANCE.milliTime();
    long timeLeft = timeout;
    try {
        while (timeLeft >= 0) {
            BasicPacket p = nextPacket(timeLeft);
            if (p == null)
                throw new ChannelTimeoutException("Timed out");
            if (!isPingChannel && ((Packet) p).getChannel() != getChannelId().intValue()) {
                log.warning("Ignoring received " + p + ", when excepting channel " + getChannelId());
                continue;
            }
            packets.add(p);
            if (isLastPacket(p) || hasEnoughPackets(packetCount, packets)) {
                BasicPacket[] packetArray = new BasicPacket[packets.size()];
                packets.toArray(packetArray);
                return packetArray;
            }
            // doing this last might save us one system call for the last
            // packet.
            timeLeft = timeout - (SystemTimer.INSTANCE.milliTime() - startTime);
        }
    } catch (InvalidChannelException e) {
        // nop.  if we get this we want to return the default
        // zero length packet array indicating that we have no
        // valid response
        log.info("FS4Channel was invalid. timeLeft=" + timeLeft + ", timeout=" + timeout);
    } catch (InterruptedException e) {
        log.info("FS4Channel was interrupted. timeLeft=" + timeLeft + ", timeout=" + timeout);
        Thread.currentThread().interrupt();
    }
    // did not get the end of the packet stream
    throw new ChannelTimeoutException();
}
Also used : BasicPacket(com.yahoo.fs4.BasicPacket) Packet(com.yahoo.fs4.Packet) BasicPacket(com.yahoo.fs4.BasicPacket) ArrayList(java.util.ArrayList) ChannelTimeoutException(com.yahoo.fs4.ChannelTimeoutException)

Example 34 with Packet

use of net.minecraft.server.v1_15_R1.Packet in project solinia3-core by mixxit.

the class EntityUtils method PSetHPChange.

public static void PSetHPChange(LivingEntity targetToDamage, Double hpchange, LivingEntity sourceEntityOfChange, boolean playHurtSound) {
    if (targetToDamage instanceof ArmorStand || sourceEntityOfChange instanceof ArmorStand)
        return;
    if (hpchange == 0)
        return;
    // This will check both their invulnerability from minecraft and godmode from essentials
    if (hpchange < 0 && EntityUtils.IsInvulnerable(targetToDamage))
        return;
    float cur_hp = ((EntityLiving) ((CraftLivingEntity) targetToDamage).getHandle()).getHealth();
    float max_hp = ((EntityLiving) ((CraftLivingEntity) targetToDamage).getHandle()).getMaxHealth();
    float hp = cur_hp + hpchange.floatValue();
    if (hp >= max_hp)
        cur_hp = max_hp;
    else
        cur_hp = hp;
    ((EntityLiving) ((CraftLivingEntity) targetToDamage).getHandle()).setHealth(cur_hp);
    float soundVolume = 1.0F;
    if (hpchange < 0) {
        DamageSource damagesource = net.minecraft.server.v1_15_R1.DamageSource.mobAttack(((EntityLiving) ((CraftLivingEntity) sourceEntityOfChange).getHandle()));
        DamageCause damagecause = DamageCause.ENTITY_ATTACK;
        EntityDamageByEntityEvent event = new EntityDamageByEntityEvent(sourceEntityOfChange, targetToDamage, damagecause, hpchange);
        ((CraftLivingEntity) targetToDamage).setLastDamage(hpchange.doubleValue());
        ((CraftLivingEntity) targetToDamage).setLastDamageCause(event);
        ((CraftLivingEntity) targetToDamage).setNoDamageTicks(20);
        ((EntityLiving) ((CraftLivingEntity) targetToDamage).getHandle()).hurtDuration = 10;
        ((EntityLiving) ((CraftLivingEntity) targetToDamage).getHandle()).hurtTicks = ((EntityLiving) ((CraftLivingEntity) targetToDamage).getHandle()).hurtDuration;
        ((EntityLiving) ((CraftLivingEntity) targetToDamage).getHandle()).getCombatTracker().trackDamage(damagesource, cur_hp, hpchange.floatValue());
        if (((EntityLiving) ((CraftLivingEntity) targetToDamage).getHandle()).getHealth() <= 0.0F) {
            targetToDamage.getWorld().playSound(targetToDamage.getLocation(), Sound.ENTITY_GENERIC_DEATH, soundVolume, GetSoundPitch(((EntityLiving) ((CraftLivingEntity) targetToDamage).getHandle())));
            ((EntityLiving) ((CraftLivingEntity) targetToDamage).getHandle()).die(damagesource);
        } else {
            if (targetToDamage instanceof Player) {
                PacketPlayOutAnimation packet = new PacketPlayOutAnimation(((CraftPlayer) targetToDamage).getHandle(), 1);
                ((CraftPlayer) targetToDamage).getHandle().playerConnection.sendPacket(packet);
            }
            if (playHurtSound)
                targetToDamage.getWorld().playSound(targetToDamage.getLocation(), Sound.ENTITY_GENERIC_HURT, soundVolume, GetSoundPitch(((EntityLiving) ((CraftLivingEntity) targetToDamage).getHandle())));
        }
    }
}
Also used : Player(org.bukkit.entity.Player) CraftPlayer(org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer) EntityPlayer(net.minecraft.server.v1_15_R1.EntityPlayer) ArmorStand(org.bukkit.entity.ArmorStand) EntityLiving(net.minecraft.server.v1_15_R1.EntityLiving) DamageSource(net.minecraft.server.v1_15_R1.DamageSource) EntityDamageByEntityEvent(org.bukkit.event.entity.EntityDamageByEntityEvent) CraftLivingEntity(org.bukkit.craftbukkit.v1_15_R1.entity.CraftLivingEntity) CraftPlayer(org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer) DamageCause(org.bukkit.event.entity.EntityDamageEvent.DamageCause) PacketPlayOutAnimation(net.minecraft.server.v1_15_R1.PacketPlayOutAnimation)

Example 35 with Packet

use of net.minecraft.server.v1_15_R1.Packet in project Citizens2 by CitizensDev.

the class EntityHumanNPC method updatePackets.

private void updatePackets(boolean navigating) {
    updateCounter++;
    boolean itemChanged = false;
    for (EnumItemSlot slot : EnumItemSlot.values()) {
        ItemStack equipment = getEquipment(slot);
        ItemStack cache = equipmentCache.get(slot);
        if (!(cache == null && equipment == null) && (cache == null ^ equipment == null || !ItemStack.equals(cache, equipment))) {
            itemChanged = true;
        }
        equipmentCache.put(slot, equipment);
    }
    if (updateCounter++ <= npc.data().<Integer>get(NPC.Metadata.PACKET_UPDATE_DELAY, Setting.PACKET_UPDATE_DELAY.asInt()) && !itemChanged)
        return;
    updateCounter = 0;
    Location current = getBukkitEntity().getLocation(packetLocationCache);
    Packet<?>[] packets = new Packet[EnumItemSlot.values().length];
    int i = 0;
    for (EnumItemSlot slot : EnumItemSlot.values()) {
        packets[i++] = new PacketPlayOutEntityEquipment(getId(), slot, getEquipment(slot));
    }
    NMSImpl.sendPacketsNearby(getBukkitEntity(), current, packets);
}
Also used : EnumItemSlot(net.minecraft.server.v1_12_R1.EnumItemSlot) Packet(net.minecraft.server.v1_12_R1.Packet) ItemStack(net.minecraft.server.v1_12_R1.ItemStack) PacketPlayOutEntityEquipment(net.minecraft.server.v1_12_R1.PacketPlayOutEntityEquipment) Location(org.bukkit.Location)

Aggregations

CraftPlayer (org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer)12 Player (org.bukkit.entity.Player)11 GameProfile (com.mojang.authlib.GameProfile)10 Location (org.bukkit.Location)10 EntityPlayer (net.minecraft.server.v1_15_R1.EntityPlayer)6 ParallelWorld (thpmc.engine.api.world.parallel.ParallelWorld)5 Packet (com.yahoo.fs4.Packet)4 CraftChunk (org.bukkit.craftbukkit.v1_15_R1.CraftChunk)4 BasicPacket (com.yahoo.fs4.BasicPacket)3 ChannelTimeoutException (com.yahoo.fs4.ChannelTimeoutException)3 QueryPacket (com.yahoo.fs4.QueryPacket)3 Packet (ejip123.Packet)3 BlockPosition (net.minecraft.server.v1_15_R1.BlockPosition)3 PacketPlayOutEntityLook (net.minecraft.server.v1_15_R1.PacketPlayOutEntity.PacketPlayOutEntityLook)3 World (org.bukkit.World)3 ParallelUniverse (thpmc.engine.api.world.parallel.ParallelUniverse)3 GetDocSumsPacket (com.yahoo.fs4.GetDocSumsPacket)2 PingPacket (com.yahoo.fs4.PingPacket)2 PongPacket (com.yahoo.fs4.PongPacket)2 QueryResultPacket (com.yahoo.fs4.QueryResultPacket)2