use of org.terasology.engine.network.ClientComponent in project Terasology by MovingBlocks.
the class PermissionCommands method usePermissionKey.
@Command(shortDescription = "Use an one time key to get all permissions", helpText = "The config file contains a one time key which can be used to get all permissions.", runOnServer = true, requiredPermission = PermissionManager.NO_PERMISSION)
public String usePermissionKey(@CommandParam("key") String key, @Sender EntityRef client) {
PermissionConfig permissionConfig = config.getPermission();
String expectedKey = permissionConfig.getOneTimeAuthorizationKey();
if (expectedKey != null && !expectedKey.equals("") && key.equals(expectedKey)) {
permissionConfig.setOneTimeAuthorizationKey("");
ClientComponent clientComponent = client.getComponent(ClientComponent.class);
EntityRef clientInfo = clientComponent.clientInfo;
for (String permission : findAllPermissions()) {
permissionManager.addPermission(clientInfo, permission);
}
PermissionSetComponent permissionSetComp = clientInfo.getComponent(PermissionSetComponent.class);
return "Permission key used: You have now the following permissions: " + permissionSetComp.permissions;
} else {
return "Key invalid or used";
}
}
use of org.terasology.engine.network.ClientComponent in project Terasology by MovingBlocks.
the class PermissionCommands method listPermissions.
@Command(shortDescription = "Lists all permission the specified player has", helpText = "Lists all permission the specified player has", runOnServer = true, requiredPermission = PermissionManager.USER_MANAGEMENT_PERMISSION)
public String listPermissions(@CommandParam(value = "player", suggester = UsernameSuggester.class) String player) {
for (EntityRef client : entityManager.getEntitiesWith(ClientComponent.class)) {
ClientComponent clientComponent = client.getComponent(ClientComponent.class);
if (clientHasName(clientComponent, player)) {
EntityRef clientInfo = clientComponent.clientInfo;
PermissionSetComponent permissionSetComp = clientInfo.getComponent(PermissionSetComponent.class);
return Objects.toString(permissionSetComp.permissions);
}
}
return "Player not found";
}
use of org.terasology.engine.network.ClientComponent in project Terasology by MovingBlocks.
the class PermissionCommands method removePermission.
@Command(shortDescription = "Removes specified permission from player", helpText = "Removes specified permission from player", runOnServer = true, requiredPermission = PermissionManager.USER_MANAGEMENT_PERMISSION)
public String removePermission(@CommandParam(value = "player", suggester = UsernameSuggester.class) String player, @CommandParam("permission") String permission, @Sender EntityRef requester) {
boolean permissionGiven = false;
ClientComponent requesterClientComponent = requester.getComponent(ClientComponent.class);
EntityRef requesterClientInfo = requesterClientComponent.clientInfo;
if (!permissionManager.hasPermission(requesterClientInfo, permission)) {
return String.format("You can't remove the permission %s because you don't have it yourself", permission);
}
for (EntityRef client : entityManager.getEntitiesWith(ClientComponent.class)) {
ClientComponent clientComponent = client.getComponent(ClientComponent.class);
if (clientHasName(clientComponent, player)) {
permissionManager.removePermission(clientComponent.clientInfo, permission);
permissionGiven = true;
}
}
if (permissionGiven) {
return "Permission " + permission + " removed from player " + player;
} else {
return "Unable to find player " + player;
}
}
use of org.terasology.engine.network.ClientComponent in project Terasology by MovingBlocks.
the class OnlinePlayersOverlay method determinePlayerListText.
private String determinePlayerListText() {
Iterable<EntityRef> allClients = entityManager.getEntitiesWith(ClientComponent.class);
StringBuilder sb = new StringBuilder();
boolean first = true;
for (EntityRef clientEntity : allClients) {
if (!first) {
sb.append("\n");
}
ClientComponent clientComp = clientEntity.getComponent(ClientComponent.class);
sb.append(PlayerUtil.getColoredPlayerName(clientComp.clientInfo));
first = false;
}
return sb.toString();
}
use of org.terasology.engine.network.ClientComponent in project Terasology by MovingBlocks.
the class StorageManagerTest method createClientEntity.
private EntityRef createClientEntity(EntityRef charac) {
ClientComponent clientComponent = new ClientComponent();
clientComponent.local = true;
clientComponent.character = charac;
EntityRef clientEntity = entityManager.create(clientComponent);
return clientEntity;
}
Aggregations