Begin the port to BungeeCord

This commit is contained in:
Justin Crawford 2019-10-07 23:31:20 -07:00
parent e986cacc50
commit 96bb1a5fa8
No known key found for this signature in database
GPG Key ID: 0D84DEDBB8EF259C
6 changed files with 81 additions and 124 deletions

View File

@ -1,5 +1,5 @@
--- ---
#BasedOnStyle: WebKit Language: 'Java'
TabWidth: '4' TabWidth: '4'
IndentWidth: '4' IndentWidth: '4'
UseTab: 'Always' UseTab: 'Always'
@ -7,6 +7,7 @@ AlignOperands: 'true'
AlignAfterOpenBracket: 'Align' AlignAfterOpenBracket: 'Align'
AlignConsecutiveAssignments: 'true' AlignConsecutiveAssignments: 'true'
AlignConsecutiveDeclarations: 'true' AlignConsecutiveDeclarations: 'true'
AlignConsecutiveMacros: 'true'
AlignEscapedNewlines: 'Left' AlignEscapedNewlines: 'Left'
AlignTrailingComments: 'true' AlignTrailingComments: 'true'
AllowAllParametersOfDeclarationOnNextLine: 'true' AllowAllParametersOfDeclarationOnNextLine: 'true'
@ -20,35 +21,20 @@ AlwaysBreakTemplateDeclarations: 'true'
AlwaysBreakBeforeMultilineStrings: 'false' AlwaysBreakBeforeMultilineStrings: 'false'
BinPackArguments: 'false' BinPackArguments: 'false'
BinPackParameters: 'false' BinPackParameters: 'false'
BreakBeforeBraces: 'Custom' BreakBeforeBraces: 'Allman'
BraceWrapping:
AfterEnum: 'true'
AfterClass: 'true'
AfterControlStatement: 'true'
AfterStruct: 'true'
AfterFunction: 'true'
AfterNamespace: 'true'
AfterUnion: 'true'
AfterExternBlock: 'true'
BeforeCatch: 'true'
BeforeElse: 'true'
SplitEmptyRecord: 'false'
SplitEmptyNamespace: 'false'
SplitEmptyFunction: 'false'
BreakBeforeBinaryOperators: 'true' BreakBeforeBinaryOperators: 'true'
BreakBeforeTernaryOperators: 'false' BreakBeforeTernaryOperators: 'false'
BreakConstructorInitializersBeforeComma: 'false' BreakConstructorInitializers: 'AfterColon'
BreakBeforeInheritanceComma: 'false' BreakBeforeInheritanceComma: 'false'
BreakAfterJavaFieldAnnotations: 'true'
BreakStringLiterals: 'true' BreakStringLiterals: 'true'
ColumnLimit: '140' ColumnLimit: '140'
CompactNamespaces: 'false' CompactNamespaces: 'false'
Cpp11BracedListStyle: 'true'
ConstructorInitializerAllOnOneLineOrOnePerLine: 'false' ConstructorInitializerAllOnOneLineOrOnePerLine: 'false'
DerivePointerAlignment: 'false' DerivePointerAlignment: 'false'
IndentCaseLabels: 'true' IndentCaseLabels: 'true'
IndentPPDirectives: 'AfterHash' IndentPPDirectives: 'AfterHash'
KeepEmptyLinesAtTheStartOfBlocks: 'true' KeepEmptyLinesAtTheStartOfBlocks: 'true'
Language: 'Java'
NamespaceIndentation: 'All' NamespaceIndentation: 'All'
PointerAlignment: 'Right' PointerAlignment: 'Right'
ReflowComments: 'true' ReflowComments: 'true'

View File

@ -33,9 +33,10 @@
<!-- Dependencies --> <!-- Dependencies -->
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>org.bukkit</groupId> <groupId>net.md-5</groupId>
<artifactId>bukkit</artifactId> <artifactId>bungeecord-api</artifactId>
<version>1.14.4-R0.1-SNAPSHOT</version> <version>1.14-SNAPSHOT</version>
<scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>

View File

@ -5,7 +5,7 @@ import org.apache.sshd.server.command.CommandFactory;
import org.apache.sshd.server.channel.ChannelSession; import org.apache.sshd.server.channel.ChannelSession;
import org.apache.sshd.server.Environment; import org.apache.sshd.server.Environment;
import org.apache.sshd.server.ExitCallback; import org.apache.sshd.server.ExitCallback;
import org.bukkit.Bukkit;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
@ -55,7 +55,9 @@ public class ConsoleCommandFactory implements CommandFactory {
try { try {
SshdPlugin.instance.getLogger() SshdPlugin.instance.getLogger()
.info("[U: " + environment.getEnv().get(Environment.ENV_USER) + "] " + command); .info("[U: " + environment.getEnv().get(Environment.ENV_USER) + "] " + command);
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command);
SshdPlugin.instance.getProxy().getPluginManager().dispatchCommand(SshdPlugin.instance.getProxy().getConsoleSender().getInstance(), command);
//Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command);
} catch (Exception e) { } catch (Exception e) {
SshdPlugin.instance.getLogger().severe("Error processing command from SSH -" + e.getMessage()); SshdPlugin.instance.getLogger().severe("Error processing command from SSH -" + e.getMessage());
} finally { } finally {

View File

@ -148,14 +148,16 @@ public class ConsoleShellFactory implements ShellFactory {
{ {
// NO ECHO NO PREAMBLE AND SHIT // NO ECHO NO PREAMBLE AND SHIT
String cmd = command.substring("rpc".length() + 1, command.length()); String cmd = command.substring("rpc".length() + 1, command.length());
Bukkit.dispatchCommand(this.SshdCommandSender, cmd); SshdPlugin.instance.getProxy().getPluginManager().dispatchCommand(this.SshdCommandSender, cmd);
//Bukkit.dispatchCommand(this.SshdCommandSender, cmd);
} }
else else
{ {
if (!mkpasswd) if (!mkpasswd)
SshdPlugin.instance.getLogger().info("<" + this.Username + "> " + command); SshdPlugin.instance.getLogger().info("<" + this.Username + "> " + command);
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command); SshdPlugin.instance.getProxy().getPluginManager().dispatchCommand(SshdPlugin.instance.getProxy().getConsoleSender().getInstance(), command);
//Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command);
} }
}); });
} }
@ -190,8 +192,8 @@ public class ConsoleShellFactory implements ShellFactory {
// Doesn't really guarantee our actual system hostname but // Doesn't really guarantee our actual system hostname but
// it's better than not having one at all. // it's better than not having one at all.
cr.println("Connected to: " + InetAddress.getLocalHost().getHostName() + " (" + Bukkit.getServer().getName() + ")\r"); cr.println("Connected to: " + InetAddress.getLocalHost().getHostName() + " (BungeeCord)\r");
cr.println(ConsoleLogFormatter.ColorizeString(Bukkit.getServer().getMotd()).replaceAll("\n", "\r\n")); cr.println(ConsoleLogFormatter.ColorizeString(DO SOMETHING HERE).replaceAll("\n", "\r\n"));
cr.println("\r"); cr.println("\r");
cr.println("Type 'exit' to exit the shell." + "\r"); cr.println("Type 'exit' to exit the shell." + "\r");
cr.println("===============================================" + "\r"); cr.println("===============================================" + "\r");

View File

@ -4,7 +4,8 @@ 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.apache.sshd.server.subsystem.sftp.SftpSubsystemFactory;
import org.bukkit.plugin.java.JavaPlugin; import net.md_5.bungee.api.plugin.Plugin;
import net.md_5.bungee.config.Configuration;
import com.ryanmichela.sshd.ConsoleShellFactory; import com.ryanmichela.sshd.ConsoleShellFactory;
import com.ryanmichela.sshd.MkpasswdCommand; import com.ryanmichela.sshd.MkpasswdCommand;
@ -20,8 +21,7 @@ import java.util.logging.Level;
/** /**
* Copyright 2013 Ryan Michela * Copyright 2013 Ryan Michela
*/ */
public public final class SshdPlugin extends Plugin
class SshdPlugin extends JavaPlugin
{ {
private SshServer sshd; private SshServer sshd;

View File

@ -1,6 +1,12 @@
package com.ryanmichela.sshd.implementations; package com.ryanmichela.sshd.implementations;
import com.ryanmichela.sshd.SshdPlugin; import com.ryanmichela.sshd.SshdPlugin;
import net.md_5.bungee.command.ConsoleCommandSender;
import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.ProxyServer;
/*
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Server; import org.bukkit.Server;
@ -14,6 +20,7 @@ import org.bukkit.permissions.Permission;
import org.bukkit.permissions.PermissionAttachment; import org.bukkit.permissions.PermissionAttachment;
import org.bukkit.permissions.PermissionAttachmentInfo; import org.bukkit.permissions.PermissionAttachmentInfo;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
*/
import com.ryanmichela.sshd.ConsoleShellFactory; import com.ryanmichela.sshd.ConsoleShellFactory;
@ -22,118 +29,77 @@ import java.util.Arrays;
import java.util.Set; import java.util.Set;
import java.util.logging.Level; import java.util.logging.Level;
public class SSHDCommandSender implements ConsoleCommandSender, CommandSender { @NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class SSHDConsoleCommandSender implements CommandSender
private final PermissibleBase perm = new PermissibleBase(this); {
private final SSHDConversationTracker conversationTracker = new SSHDConversationTracker(); @Getter
// Set by the upstream allocating function private static final SSHDConsoleCommandSender instance = new SSHDConsoleCommandSender();
public ConsoleShellFactory.ConsoleShell console;
@Override
public void sendMessage(String message) { public void sendMessage(String message) {
this.sendRawMessage(message); ProxyServer.getInstance().getLogger().info(message);
} }
public void sendRawMessage(String message) public void sendRawMessage(String message) {
{ // What the fuck does this code even do? Are we sending to one client or all of
// What the fuck does this code even do? Are we sending to one client or all of them? // them?
if (this.console.ConsoleReader == null) if (this.console.ConsoleReader == null)
return; return;
try try {
{ ProxyServer.getInstance().getLogger().info(message);
this.console.ConsoleReader.println(ChatColor.stripColor(message)); this.console.ConsoleReader.println(ChatColor.stripColor(message));
} } catch (IOException e) {
catch (IOException e)
{
SshdPlugin.instance.getLogger().log(Level.SEVERE, "Error sending message to SSHDCommandSender", e); SshdPlugin.instance.getLogger().log(Level.SEVERE, "Error sending message to SSHDCommandSender", e);
} }
} }
public void sendMessage(String[] messages) { @Override
public void sendMessages(String... messages) {
Arrays.asList(messages).forEach(this::sendMessage); Arrays.asList(messages).forEach(this::sendMessage);
} }
public String getName() { @Override
return "SSHD Console"; public void sendMessage(BaseComponent... message) {
sendMessage(BaseComponent.toLegacyText(message));
} }
public boolean isOp() { @Override
public void sendMessage(BaseComponent message) {
sendMessage(message.toLegacyText());
}
@Override
public String getName() {
return "CONSOLE";
}
@Override
public Collection<String> getGroups() {
return Collections.emptySet();
}
@Override
public void addGroups(String... groups) {
throw new UnsupportedOperationException("Console may not have groups");
}
@Override
public void removeGroups(String... groups) {
throw new UnsupportedOperationException("Console may not have groups");
}
@Override
public boolean hasPermission(String permission) {
return true; return true;
} }
public void setOp(boolean value) { @Override
throw new UnsupportedOperationException("Cannot change operator status of server console"); public void setPermission(String permission, boolean value) {
throw new UnsupportedOperationException("Console has all permissions");
} }
public boolean beginConversation(Conversation conversation) { @Override
return this.conversationTracker.beginConversation(conversation); public Collection<String> getPermissions() {
return Collections.emptySet();
} }
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();
}
} }