Search in sources :

Example 11 with PlayerIdentifier

use of com.mraof.minestuck.util.IdentifierHandler.PlayerIdentifier in project Minestuck by mraof.

the class SessionHandler method getServerList.

static List<Object> getServerList(PlayerIdentifier client) {
    ArrayList<Object> list = new ArrayList<Object>();
    for (PlayerIdentifier server : SkaianetHandler.serversOpen.keySet()) {
        if (canConnect(client, server)) {
            list.add(server.getId());
            list.add(server.getUsername());
        }
    }
    return list;
}
Also used : PlayerIdentifier(com.mraof.minestuck.util.IdentifierHandler.PlayerIdentifier)

Example 12 with PlayerIdentifier

use of com.mraof.minestuck.util.IdentifierHandler.PlayerIdentifier in project Minestuck by mraof.

the class SkaianetHandler method playerConnected.

/**
 * Note that this is when a player logs in to the server.
 * @param player
 */
public static void playerConnected(EntityPlayer player) {
    PlayerIdentifier identifier = IdentifierHandler.encode(player);
    PlayerIdentifier[] s = new PlayerIdentifier[5];
    s[0] = identifier;
    infoToSend.put(identifier, s);
    updatePlayer(identifier);
}
Also used : PlayerIdentifier(com.mraof.minestuck.util.IdentifierHandler.PlayerIdentifier)

Example 13 with PlayerIdentifier

use of com.mraof.minestuck.util.IdentifierHandler.PlayerIdentifier in project Minestuck by mraof.

the class SkaianetHandler method updatePlayer.

private static void updatePlayer(PlayerIdentifier player) {
    PlayerIdentifier[] iden = infoToSend.get(player);
    EntityPlayerMP playerMP = player.getPlayer();
    if (// If the player disconnected
    iden == null || playerMP == null)
        return;
    for (SburbConnection c : connections) if (c.isActive && (c.getClientIdentifier().equals(player) || c.getServerIdentifier().equals(player))) {
        // playerMP.addStat(MinestuckAchievementHandler.setupConnection);
        break;
    }
    for (PlayerIdentifier i : iden) if (i != null) {
        MinestuckPacket packet = MinestuckPacket.makePacket(Type.SBURB_INFO, generateClientInfo(i));
        MinestuckChannelHandler.sendToPlayer(packet, playerMP);
    }
}
Also used : EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) PlayerIdentifier(com.mraof.minestuck.util.IdentifierHandler.PlayerIdentifier) MinestuckPacket(com.mraof.minestuck.network.MinestuckPacket)

Example 14 with PlayerIdentifier

use of com.mraof.minestuck.util.IdentifierHandler.PlayerIdentifier in project Minestuck by mraof.

the class SkaianetHandler method checkData.

private static void checkData() {
    Iterator<PlayerIdentifier> iter0 = infoToSend.keySet().iterator();
    while (iter0.hasNext()) if (iter0.next().getPlayer() == null) {
        // Debug.print("[SKAIANET] Player disconnected, removing data.");
        iter0.remove();
    }
    @SuppressWarnings("unchecked") Iterator<ComputerData>[] iter1 = new Iterator[] { serversOpen.values().iterator(), resumingClients.values().iterator(), resumingServers.values().iterator() };
    for (Iterator<ComputerData> i : iter1) while (i.hasNext()) {
        ComputerData data = i.next();
        if (getComputer(data) == null || data.dimension == -1 || !getComputer(data).owner.equals(data.owner) || !(i == iter1[1] && getComputer(data).getData(0).getBoolean("isResuming") || i != iter1[1] && getComputer(data).getData(1).getBoolean("isOpen"))) {
            Debug.warn("[SKAIANET] Invalid computer in waiting list!");
            i.remove();
        }
    }
    Iterator<SburbConnection> iter2 = connections.iterator();
    while (iter2.hasNext()) {
        SburbConnection c = iter2.next();
        if (c.getClientIdentifier() == null || c.getServerIdentifier() == null) {
            Debug.warn("Found a broken connection with the client \"" + c.getClientIdentifier() + "\" and server \"" + c.getServerIdentifier() + ". If this message continues to show up, something isn't working as it should.");
            iter2.remove();
            continue;
        }
        if (c.isActive) {
            TileEntityComputer cc = getComputer(c.client), sc = getComputer(c.server);
            if (cc == null || sc == null || c.client.dimension == -1 || c.server.dimension == -1 || !c.getClientIdentifier().equals(cc.owner) || !c.getServerIdentifier().equals(sc.owner) || !cc.getData(0).getBoolean("connectedToServer")) {
                Debug.warnf("[SKAIANET] Invalid computer in connection between %s and %s.", c.getClientIdentifier(), c.getServerIdentifier());
                if (!c.isMain)
                    iter2.remove();
                else
                    c.isActive = false;
                SessionHandler.onConnectionClosed(c, true);
                ServerEditHandler.onDisconnect(c);
                if (cc != null) {
                    cc.getData(0).setBoolean("connectedToServer", false);
                    cc.latestmessage.put(0, "computer.messageClosed");
                    cc.markBlockForUpdate();
                } else if (sc != null) {
                    sc.latestmessage.put(1, "computer.messageClosed");
                    sc.markBlockForUpdate();
                }
            }
            if (// If the center location isn't defined
            cc != null && c.enteredGame && c.inventory == null && c.centerX == 0 && c.centerZ == 0) {
                c.centerX = cc.getPos().getX();
                c.centerZ = cc.getPos().getZ();
                c.inventory = new NBTTagList();
            }
            if (cc != null && c.enteredGame && !MinestuckDimensionHandler.isLandDimension(c.clientHomeLand))
                c.clientHomeLand = c.client.dimension;
        }
        if (c.enteredGame && !MinestuckDimensionHandler.isLandDimension(c.clientHomeLand)) {
            EntityPlayerMP player = c.getClientIdentifier().getPlayer();
            if (player != null) {
                c.clientHomeLand = player.dimension;
                if (!MinestuckDimensionHandler.isLandDimension(c.clientHomeLand)) {
                    iter2.remove();
                    SessionHandler.onConnectionClosed(c, false);
                    if (c.isActive) {
                        TileEntityComputer cc = getComputer(c.client), sc = getComputer(c.server);
                        cc.getData(0).setBoolean("connectedToServer", false);
                        cc.latestmessage.put(0, "computer.messageClosed");
                        cc.markBlockForUpdate();
                        sc.getData(1).setString("connectedClient", "");
                        sc.latestmessage.put(1, "computer.messageClosed");
                        sc.markBlockForUpdate();
                    }
                }
            }
        }
    }
    if (MinestuckConfig.privateComputers) {
        for (Entry<PlayerIdentifier, PlayerIdentifier[]> entry : infoToSend.entrySet()) {
            EntityPlayerMP player = entry.getKey().getPlayer();
            UserListOpsEntry opsEntry = player == null ? null : player.getServer().getPlayerList().getOppedPlayers().getEntry(player.getGameProfile());
            if (opsEntry != null && opsEntry.getPermissionLevel() >= 2)
                continue;
            for (int i = 0; i < entry.getValue().length; i++) if (entry.getValue()[i] != null && !entry.getValue()[i].equals(entry.getKey()))
                entry.getValue()[i] = null;
        }
    }
}
Also used : TileEntityComputer(com.mraof.minestuck.tileentity.TileEntityComputer) PlayerIdentifier(com.mraof.minestuck.util.IdentifierHandler.PlayerIdentifier) NBTTagList(net.minecraft.nbt.NBTTagList) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) UserListOpsEntry(net.minecraft.server.management.UserListOpsEntry)

Example 15 with PlayerIdentifier

use of com.mraof.minestuck.util.IdentifierHandler.PlayerIdentifier in project Minestuck by mraof.

the class SkaianetHandler method enterMedium.

public static int enterMedium(EntityPlayerMP player, int dimensionId) {
    PlayerIdentifier username = IdentifierHandler.encode(player);
    SburbConnection c = getMainConnection(username, true);
    if (c == null) {
        c = getClientConnection(username);
        if (c == null) {
            Debug.infof("Player %s entered without connection. Creating connection... ", player.getName());
            c = new SburbConnection();
            c.isActive = false;
            c.isMain = true;
            c.clientIdentifier = username;
            c.serverIdentifier = IdentifierHandler.nullIdentifier;
            String s = SessionHandler.onConnectionCreated(c);
            if (s == null) {
                SburbHandler.onFirstItemGiven(c);
                connections.add(c);
            } else if (SessionHandler.singleSession) {
                Debug.warnf("Failed to create connection: %s. Trying again with global session disabled for this world...", s);
                SessionHandler.singleSession = false;
                SessionHandler.split();
                s = SessionHandler.onConnectionCreated(c);
                if (s == null) {
                    SburbHandler.onFirstItemGiven(c);
                    connections.add(c);
                } else {
                    Debug.errorf("Couldn't create a connection for %s: %s. Stopping entry.", player.getName(), s);
                    return -1;
                }
            } else {
                Debug.errorf("Couldn't create a connection for %s: %s. Stopping entry.", player.getName(), s);
                return -1;
            }
        } else
            giveItems(username);
    } else if (c.enteredGame)
        return c.clientHomeLand;
    c.clientHomeLand = dimensionId;
    c.enteredGame = true;
    SburbHandler.onGameEntered(c);
    c.centerX = (int) player.posX;
    c.centerZ = (int) player.posZ;
    updateAll();
    return dimensionId;
}
Also used : TextComponentString(net.minecraft.util.text.TextComponentString) PlayerIdentifier(com.mraof.minestuck.util.IdentifierHandler.PlayerIdentifier)

Aggregations

PlayerIdentifier (com.mraof.minestuck.util.IdentifierHandler.PlayerIdentifier)27 TextComponentString (net.minecraft.util.text.TextComponentString)7 CommandException (net.minecraft.command.CommandException)6 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)4 MinestuckPacket (com.mraof.minestuck.network.MinestuckPacket)3 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)3 NBTTagList (net.minecraft.nbt.NBTTagList)3 Style (net.minecraft.util.text.Style)3 SburbConnection (com.mraof.minestuck.network.skaianet.SburbConnection)2 TileEntityComputer (com.mraof.minestuck.tileentity.TileEntityComputer)2 Title (com.mraof.minestuck.util.Title)2 ChunkProviderLands (com.mraof.minestuck.world.lands.gen.ChunkProviderLands)2 WrongUsageException (net.minecraft.command.WrongUsageException)2 UserListOpsEntry (net.minecraft.server.management.UserListOpsEntry)2 Vec3d (net.minecraft.util.math.Vec3d)2 TextComponentTranslation (net.minecraft.util.text.TextComponentTranslation)2 Modus (com.mraof.minestuck.inventory.captchalouge.Modus)1 Echeladder (com.mraof.minestuck.util.Echeladder)1 WorldProviderLands (com.mraof.minestuck.world.WorldProviderLands)1 LandAspectRegistry (com.mraof.minestuck.world.lands.LandAspectRegistry)1