Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
272e7cf8dc | ||
|
|
69d31175d4 | ||
|
|
16f5c063ce | ||
|
|
2f1e03d7a2 | ||
|
|
32f65a506e | ||
|
|
703c69b055 | ||
|
|
15faff3dd4 | ||
|
|
dc8e49f643 | ||
|
|
2380c42089 | ||
|
|
02b700b07f | ||
|
|
87cb4d8929 |
4
.travis.yml
Normal file
4
.travis.yml
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
sudo: false
|
||||||
|
language: java
|
||||||
|
jdk:
|
||||||
|
- oraclejdk8
|
||||||
@@ -1,4 +1,6 @@
|
|||||||
Bukkit-SSHD
|
Bukkit-SSHD
|
||||||
===========
|
===========
|
||||||
|
|
||||||
|
[](https://travis-ci.org/rmichela/Bukkit-SSHD)
|
||||||
|
|
||||||
An SSHD daemon embedded in a Bukkit plugin.
|
An SSHD daemon embedded in a Bukkit plugin.
|
||||||
|
|||||||
74
pom.xml
74
pom.xml
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
<groupId>com.ryanmichela</groupId>
|
<groupId>com.ryanmichela</groupId>
|
||||||
<artifactId>SSHD</artifactId>
|
<artifactId>SSHD</artifactId>
|
||||||
<version>1.3.2</version>
|
<version>1.3.4</version>
|
||||||
<url>http://dev.bukkit.org/server-mods/sshd/</url>
|
<url>http://dev.bukkit.org/server-mods/sshd/</url>
|
||||||
|
|
||||||
<!-- Repositories -->
|
<!-- Repositories -->
|
||||||
@@ -29,11 +29,8 @@
|
|||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.bukkit</groupId>
|
<groupId>org.bukkit</groupId>
|
||||||
<artifactId>craftbukkit</artifactId>
|
<artifactId>bukkit</artifactId>
|
||||||
<version>1.12.2-R0.1-SNAPSHOT</version>
|
<version>1.12.2-R0.1-SNAPSHOT</version>
|
||||||
<scope>system</scope>
|
|
||||||
<type>jar</type>
|
|
||||||
<systemPath>${basedir}/bukkit-build/bukkit.jar</systemPath>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
@@ -68,13 +65,46 @@
|
|||||||
<version>2.12.1</version>
|
<version>2.12.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
<dependency>
|
||||||
|
<groupId>org.apache.logging.log4j</groupId>
|
||||||
|
<artifactId>log4j-core</artifactId>
|
||||||
|
<version>2.0</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.logging.log4j</groupId>
|
||||||
|
<artifactId>log4j-api</artifactId>
|
||||||
|
<version>2.1</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>commons-codec</groupId>
|
||||||
|
<artifactId>commons-codec</artifactId>
|
||||||
|
<version>1.10</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
<!-- Build -->
|
<!-- Build -->
|
||||||
<build>
|
<build>
|
||||||
|
<resources>
|
||||||
|
<resource>
|
||||||
|
<targetPath>.</targetPath>
|
||||||
|
<filtering>true</filtering>
|
||||||
|
<directory>${basedir}/src/main/resources</directory>
|
||||||
|
<includes>
|
||||||
|
<include>plugin.yml</include>
|
||||||
|
<include>config.yml</include>
|
||||||
|
</includes>
|
||||||
|
</resource>
|
||||||
|
</resources>
|
||||||
|
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
<artifactId>maven-assembly-plugin</artifactId>
|
<artifactId>maven-assembly-plugin</artifactId>
|
||||||
|
<version>3.1.0</version>
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<phase>package</phase>
|
<phase>package</phase>
|
||||||
@@ -84,45 +114,19 @@
|
|||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
<configuration>
|
<configuration>
|
||||||
|
<finalName>${project.name}-${project.version}</finalName>
|
||||||
|
<appendAssemblyId>false</appendAssemblyId>
|
||||||
<descriptorRefs>
|
<descriptorRefs>
|
||||||
<descriptorRef>jar-with-dependencies</descriptorRef>
|
<descriptorRef>jar-with-dependencies</descriptorRef>
|
||||||
</descriptorRefs>
|
</descriptorRefs>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
|
||||||
<!-- Shade plugin -->
|
|
||||||
<!-- <plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-shade-plugin</artifactId>
|
|
||||||
<version>1.7</version>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<phase>package</phase>
|
|
||||||
<goals>
|
|
||||||
<goal>shade</goal>
|
|
||||||
</goals>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
<configuration>
|
|
||||||
<filters>
|
|
||||||
<filter>
|
|
||||||
<artifact>*:*</artifact>
|
|
||||||
<excludes>
|
|
||||||
<exclude>META-INF/*.SF</exclude>
|
|
||||||
<exclude>META-INF/*.DSA</exclude>
|
|
||||||
<exclude>META-INF/*.RSA</exclude>
|
|
||||||
</excludes>
|
|
||||||
</filter>
|
|
||||||
</filters>
|
|
||||||
<minimizeJar>true</minimizeJar>
|
|
||||||
</configuration>
|
|
||||||
</plugin> -->
|
|
||||||
|
|
||||||
<!-- Compile plugin -->
|
<!-- Compile plugin -->
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
<version>3.0</version>
|
<version>3.5.1</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<source>1.8</source>
|
<source>1.8</source>
|
||||||
<target>1.8</target>
|
<target>1.8</target>
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.ryanmichela.sshd;
|
package com.ryanmichela.sshd;
|
||||||
|
|
||||||
|
import com.ryanmichela.sshd.implementations.SSHDCommandSender;
|
||||||
import jline.console.ConsoleReader;
|
import jline.console.ConsoleReader;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.core.Logger;
|
import org.apache.logging.log4j.core.Logger;
|
||||||
@@ -12,9 +13,13 @@ import org.bukkit.Bukkit;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
|
import java.util.logging.Level;
|
||||||
import java.util.logging.StreamHandler;
|
import java.util.logging.StreamHandler;
|
||||||
|
|
||||||
public class ConsoleShellFactory implements Factory<Command> {
|
public class ConsoleShellFactory implements Factory<Command> {
|
||||||
|
|
||||||
|
static SSHDCommandSender sshdCommandSender = new SSHDCommandSender();
|
||||||
|
|
||||||
public Command get() {
|
public Command get() {
|
||||||
return this.create();
|
return this.create();
|
||||||
}
|
}
|
||||||
@@ -24,7 +29,6 @@ public class ConsoleShellFactory implements Factory<Command> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static class ConsoleShell implements Command, Runnable {
|
public static class ConsoleShell implements Command, Runnable {
|
||||||
|
|
||||||
private InputStream in;
|
private InputStream in;
|
||||||
private OutputStream out;
|
private OutputStream out;
|
||||||
private OutputStream err;
|
private OutputStream err;
|
||||||
@@ -33,7 +37,7 @@ public class ConsoleShellFactory implements Factory<Command> {
|
|||||||
private Thread thread;
|
private Thread thread;
|
||||||
|
|
||||||
StreamHandlerAppender streamHandlerAppender;
|
StreamHandlerAppender streamHandlerAppender;
|
||||||
ConsoleReader consoleReader;
|
public static ConsoleReader consoleReader;
|
||||||
|
|
||||||
public InputStream getIn() {
|
public InputStream getIn() {
|
||||||
return in;
|
return in;
|
||||||
@@ -68,7 +72,6 @@ public class ConsoleShellFactory implements Factory<Command> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void start(Environment env) throws IOException {
|
public void start(Environment env) throws IOException {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
consoleReader = new ConsoleReader(in, new FlushyOutputStream(out), new SshTerminal());
|
consoleReader = new ConsoleReader(in, new FlushyOutputStream(out), new SshTerminal());
|
||||||
consoleReader.setExpandEvents(true);
|
consoleReader.setExpandEvents(true);
|
||||||
@@ -93,38 +96,42 @@ public class ConsoleShellFactory implements Factory<Command> {
|
|||||||
|
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
printPreamble(consoleReader);
|
if (!SshdPlugin.instance.getConfig().getString("mode").equals("RPC"))
|
||||||
|
printPreamble(consoleReader);
|
||||||
while (true) {
|
while (true) {
|
||||||
String command = consoleReader.readLine("\r>", null);
|
String command = consoleReader.readLine("\r>", null);
|
||||||
if (command != null) {
|
if (command == null) continue;
|
||||||
if (command.equals("exit")) {
|
if (command.equals("exit")) break;
|
||||||
break;
|
Bukkit.getScheduler().runTask(SshdPlugin.instance, () -> {
|
||||||
}
|
if (SshdPlugin.instance.getConfig().getString("mode").equals("RPC") && command.startsWith("rpc")) {
|
||||||
SshdPlugin.instance.getLogger().info("<" + environment.getEnv().get(Environment.ENV_USER) + "> " + command);
|
//NO ECHO NO PREAMBLE AND SHIT
|
||||||
Bukkit.getScheduler().runTask(SshdPlugin.instance, () -> {
|
String cmd = command.substring("rpc".length() + 1, command.length());
|
||||||
|
Bukkit.dispatchCommand(sshdCommandSender, cmd);
|
||||||
|
} else {
|
||||||
|
SshdPlugin.instance.getLogger().info("<" + environment.getEnv().get(Environment.ENV_USER) + "> " + command);
|
||||||
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command);
|
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command);
|
||||||
});
|
}
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
SshdPlugin.instance.getLogger().severe("Error processing command from SSH");
|
SshdPlugin.instance.getLogger().log(Level.SEVERE, "Error processing command from SSH", e);
|
||||||
} finally {
|
} finally {
|
||||||
callback.onExit(0);
|
callback.onExit(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void printPreamble(ConsoleReader consoleReader) throws IOException {
|
private void printPreamble(ConsoleReader consoleReader) throws IOException {
|
||||||
consoleReader.println(" _____ _____ _ _ _____");
|
consoleReader.println(" _____ _____ _ _ _____" + "\r");
|
||||||
consoleReader.println(" / ____/ ____| | | | __ \\");
|
consoleReader.println(" / ____/ ____| | | | __ \\" + "\r");
|
||||||
consoleReader.println("| (___| (___ | |__| | | | |");
|
consoleReader.println("| (___| (___ | |__| | | | |" + "\r");
|
||||||
consoleReader.println(" \\___ \\\\___ \\| __ | | | |");
|
consoleReader.println(" \\___ \\\\___ \\| __ | | | |" + "\r");
|
||||||
consoleReader.println(" ____) |___) | | | | |__| |");
|
consoleReader.println(" ____) |___) | | | | |__| |" + "\r");
|
||||||
consoleReader.println("|_____/_____/|_| |_|_____/");
|
consoleReader.println("|_____/_____/|_| |_|_____/" + "\r");
|
||||||
consoleReader.println("Connected to: " + Bukkit.getServer().getName());
|
consoleReader.println("Connected to: " + Bukkit.getServer().getName() + "\r");
|
||||||
consoleReader.println("- " + Bukkit.getServer().getMotd());
|
consoleReader.println("- " + Bukkit.getServer().getMotd() + "\r");
|
||||||
consoleReader.println();
|
consoleReader.println("\r");
|
||||||
consoleReader.println("Type 'exit' to exit the shell.");
|
consoleReader.println("Type 'exit' to exit the shell." + "\r");
|
||||||
consoleReader.println("===============================================");
|
consoleReader.println("===============================================" + "\r");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -8,6 +8,7 @@ import java.io.OutputStream;
|
|||||||
*/
|
*/
|
||||||
public class FlushyOutputStream extends OutputStream {
|
public class FlushyOutputStream extends OutputStream {
|
||||||
private OutputStream base;
|
private OutputStream base;
|
||||||
|
private boolean isClosed = false;
|
||||||
|
|
||||||
public FlushyOutputStream(OutputStream base) {
|
public FlushyOutputStream(OutputStream base) {
|
||||||
this.base = base;
|
this.base = base;
|
||||||
@@ -15,19 +16,27 @@ public class FlushyOutputStream extends OutputStream {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(int b) throws IOException {
|
public void write(int b) throws IOException {
|
||||||
|
if(isClosed) return;
|
||||||
base.write(b);
|
base.write(b);
|
||||||
base.flush();
|
base.flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(byte[] b) throws IOException {
|
public void write(byte[] b) throws IOException {
|
||||||
|
if(isClosed) return;
|
||||||
base.write(b);
|
base.write(b);
|
||||||
base.flush();
|
base.flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(byte[] b, int off, int len) throws IOException {
|
public void write(byte[] b, int off, int len) throws IOException {
|
||||||
|
if(isClosed) return;
|
||||||
base.write(b, off, len);
|
base.write(b, off, len);
|
||||||
base.flush();
|
base.flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void close() {
|
||||||
|
isClosed = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,15 @@
|
|||||||
package com.ryanmichela.sshd;
|
package com.ryanmichela.sshd;
|
||||||
|
|
||||||
|
import org.apache.sshd.common.file.virtualfs.VirtualFileSystemFactory;
|
||||||
import org.apache.sshd.server.SshServer;
|
import org.apache.sshd.server.SshServer;
|
||||||
import org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider;
|
import org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider;
|
||||||
|
import org.apache.sshd.server.subsystem.sftp.SftpSubsystemFactory;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.nio.file.FileSystems;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -45,11 +49,21 @@ public class SshdPlugin extends JavaPlugin {
|
|||||||
sshd.setShellFactory(new ConsoleShellFactory());
|
sshd.setShellFactory(new ConsoleShellFactory());
|
||||||
sshd.setPasswordAuthenticator(new ConfigPasswordAuthenticator());
|
sshd.setPasswordAuthenticator(new ConfigPasswordAuthenticator());
|
||||||
sshd.setPublickeyAuthenticator(new PublicKeyAuthenticator(authorizedKeys));
|
sshd.setPublickeyAuthenticator(new PublicKeyAuthenticator(authorizedKeys));
|
||||||
|
|
||||||
|
if (getConfig().getBoolean("enableSFTP")) {
|
||||||
|
sshd.setSubsystemFactories(Collections.singletonList(new SftpSubsystemFactory()));
|
||||||
|
sshd.setFileSystemFactory(new VirtualFileSystemFactory(
|
||||||
|
FileSystems.getDefault().getPath(
|
||||||
|
getDataFolder().getAbsolutePath()
|
||||||
|
).getParent().getParent()
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
sshd.setCommandFactory(new ConsoleCommandFactory());
|
sshd.setCommandFactory(new ConsoleCommandFactory());
|
||||||
try {
|
try {
|
||||||
sshd.start();
|
sshd.start();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
getLogger().severe("Failed to start SSH server! " + e.getMessage());
|
getLogger().log(Level.SEVERE, "Failed to start SSH server! ", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -69,16 +69,6 @@ public class StreamHandlerAppender implements Appender {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public State getState() {
|
|
||||||
return State.INITIALIZED;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void initialize() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void start() {
|
public void start() {
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,130 @@
|
|||||||
|
package com.ryanmichela.sshd.implementations;
|
||||||
|
|
||||||
|
import com.ryanmichela.sshd.ConsoleShellFactory;
|
||||||
|
import com.ryanmichela.sshd.SshdPlugin;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.Server;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.command.ConsoleCommandSender;
|
||||||
|
import org.bukkit.conversations.Conversation;
|
||||||
|
import org.bukkit.conversations.ConversationAbandonedEvent;
|
||||||
|
import org.bukkit.conversations.ManuallyAbandonedConversationCanceller;
|
||||||
|
import org.bukkit.permissions.PermissibleBase;
|
||||||
|
import org.bukkit.permissions.Permission;
|
||||||
|
import org.bukkit.permissions.PermissionAttachment;
|
||||||
|
import org.bukkit.permissions.PermissionAttachmentInfo;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
public class SSHDCommandSender implements ConsoleCommandSender, CommandSender {
|
||||||
|
|
||||||
|
private final PermissibleBase perm = new PermissibleBase(this);
|
||||||
|
private final SSHDConversationTracker conversationTracker = new SSHDConversationTracker();
|
||||||
|
|
||||||
|
public void sendMessage(String message) {
|
||||||
|
this.sendRawMessage(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendRawMessage(String message) {
|
||||||
|
if(ConsoleShellFactory.ConsoleShell.consoleReader == null) return;
|
||||||
|
try {
|
||||||
|
ConsoleShellFactory.ConsoleShell.consoleReader.println(ChatColor.stripColor(message));
|
||||||
|
} catch (IOException e) {
|
||||||
|
SshdPlugin.instance.getLogger().log(Level.SEVERE, "Error sending message to SSHDCommandSender", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendMessage(String[] messages) {
|
||||||
|
Arrays.asList(messages).forEach(this::sendMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return "SSHD CONSOLE";
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isOp() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOp(boolean value) {
|
||||||
|
throw new UnsupportedOperationException("Cannot change operator status of server console");
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean beginConversation(Conversation conversation) {
|
||||||
|
return this.conversationTracker.beginConversation(conversation);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void abandonConversation(Conversation conversation) {
|
||||||
|
this.conversationTracker.abandonConversation(conversation, new ConversationAbandonedEvent(conversation, new ManuallyAbandonedConversationCanceller()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void abandonConversation(Conversation conversation, ConversationAbandonedEvent details) {
|
||||||
|
this.conversationTracker.abandonConversation(conversation, details);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void acceptConversationInput(String input) {
|
||||||
|
this.conversationTracker.acceptConversationInput(input);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isConversing() {
|
||||||
|
return this.conversationTracker.isConversing();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isPermissionSet(String name) {
|
||||||
|
return this.perm.isPermissionSet(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isPermissionSet(Permission perm) {
|
||||||
|
return this.perm.isPermissionSet(perm);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasPermission(String name) {
|
||||||
|
return this.perm.hasPermission(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasPermission(Permission perm) {
|
||||||
|
return this.perm.hasPermission(perm);
|
||||||
|
}
|
||||||
|
|
||||||
|
public PermissionAttachment addAttachment(Plugin plugin, String name, boolean value) {
|
||||||
|
return this.perm.addAttachment(plugin, name, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public PermissionAttachment addAttachment(Plugin plugin) {
|
||||||
|
return this.perm.addAttachment(plugin);
|
||||||
|
}
|
||||||
|
|
||||||
|
public PermissionAttachment addAttachment(Plugin plugin, String name, boolean value, int ticks) {
|
||||||
|
return this.perm.addAttachment(plugin, name, value, ticks);
|
||||||
|
}
|
||||||
|
|
||||||
|
public PermissionAttachment addAttachment(Plugin plugin, int ticks) {
|
||||||
|
return this.perm.addAttachment(plugin, ticks);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeAttachment(PermissionAttachment attachment) {
|
||||||
|
this.perm.removeAttachment(attachment);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void recalculatePermissions() {
|
||||||
|
this.perm.recalculatePermissions();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Set<PermissionAttachmentInfo> getEffectivePermissions() {
|
||||||
|
return this.perm.getEffectivePermissions();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isPlayer() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Server getServer() {
|
||||||
|
return Bukkit.getServer();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,78 @@
|
|||||||
|
package com.ryanmichela.sshd.implementations;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.conversations.Conversation;
|
||||||
|
import org.bukkit.conversations.ConversationAbandonedEvent;
|
||||||
|
import org.bukkit.conversations.ManuallyAbandonedConversationCanceller;
|
||||||
|
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
public class SSHDConversationTracker {
|
||||||
|
private LinkedList<Conversation> conversationQueue = new LinkedList<>();
|
||||||
|
|
||||||
|
synchronized boolean beginConversation(Conversation conversation) {
|
||||||
|
if (!this.conversationQueue.contains(conversation)) {
|
||||||
|
this.conversationQueue.addLast(conversation);
|
||||||
|
if (this.conversationQueue.getFirst() == conversation) {
|
||||||
|
conversation.begin();
|
||||||
|
conversation.outputNextPrompt();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
synchronized void abandonConversation(Conversation conversation, ConversationAbandonedEvent details) {
|
||||||
|
if (!this.conversationQueue.isEmpty()) {
|
||||||
|
if (this.conversationQueue.getFirst() == conversation) {
|
||||||
|
conversation.abandon(details);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.conversationQueue.contains(conversation)) {
|
||||||
|
this.conversationQueue.remove(conversation);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!this.conversationQueue.isEmpty()) {
|
||||||
|
this.conversationQueue.getFirst().outputNextPrompt();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized void abandonAllConversations() {
|
||||||
|
LinkedList<Conversation> oldQueue = this.conversationQueue;
|
||||||
|
this.conversationQueue = new LinkedList<>();
|
||||||
|
|
||||||
|
for (Conversation conversation : oldQueue) {
|
||||||
|
try {
|
||||||
|
conversation.abandon(new ConversationAbandonedEvent(conversation, new ManuallyAbandonedConversationCanceller()));
|
||||||
|
} catch (Throwable var5) {
|
||||||
|
Bukkit.getLogger().log(Level.SEVERE, "Unexpected exception while abandoning a conversation", var5);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
synchronized void acceptConversationInput(String input) {
|
||||||
|
if (this.isConversing()) {
|
||||||
|
Conversation conversation = this.conversationQueue.getFirst();
|
||||||
|
|
||||||
|
try {
|
||||||
|
conversation.acceptInput(input);
|
||||||
|
} catch (Throwable var4) {
|
||||||
|
conversation.getContext().getPlugin().getLogger().log(Level.WARNING, String.format("Plugin %s generated an exception whilst handling conversation input", conversation.getContext().getPlugin().getDescription().getFullName()), var4);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
synchronized boolean isConversing() {
|
||||||
|
return !this.conversationQueue.isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized boolean isConversingModaly() {
|
||||||
|
return this.isConversing() && this.conversationQueue.getFirst().isModal();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,6 +4,13 @@ listenAddress: all
|
|||||||
# The port the SSH server will listen on.
|
# The port the SSH server will listen on.
|
||||||
port: 22
|
port: 22
|
||||||
|
|
||||||
|
# Operational mode. Don't touch if you don't know what you're doing. Can be either DEFAULT or RPC
|
||||||
|
mode: DEFAULT
|
||||||
|
|
||||||
|
# Enable built-in SFTP server or not. You'll be able to connect and upload/download files via SFTP protocol.
|
||||||
|
# Might be useful for testing purposes as well , i. e. docker containers.
|
||||||
|
enableSFTP: true
|
||||||
|
|
||||||
# By default, only public key authentication is enabled. This is the most secure mode.
|
# By default, only public key authentication is enabled. This is the most secure mode.
|
||||||
# To authorize a user to log in with public key authentication, install their public
|
# To authorize a user to log in with public key authentication, install their public
|
||||||
# PEM certificate in the authorized_users directory. Name the key file with user's user
|
# PEM certificate in the authorized_users directory. Name the key file with user's user
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
name: SSHD
|
name: SSHD
|
||||||
version: "1.2"
|
version: ${project.version}
|
||||||
author: Ryan Michela
|
author: Ryan Michela, Haarolean, toxuin
|
||||||
main: com.ryanmichela.sshd.SshdPlugin
|
main: com.ryanmichela.sshd.SshdPlugin
|
||||||
Reference in New Issue
Block a user