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;
}
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);
}
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);
}
}
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;
}
}
}
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;
}
Aggregations