summary refs log tree commit diff stats
path: root/src/main/java/ganarchy/friendcode/sam/I2PSamStateMachine.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/ganarchy/friendcode/sam/I2PSamStateMachine.java')
-rw-r--r--src/main/java/ganarchy/friendcode/sam/I2PSamStateMachine.java22
1 files changed, 18 insertions, 4 deletions
diff --git a/src/main/java/ganarchy/friendcode/sam/I2PSamStateMachine.java b/src/main/java/ganarchy/friendcode/sam/I2PSamStateMachine.java
index 57424dd..37deda3 100644
--- a/src/main/java/ganarchy/friendcode/sam/I2PSamStateMachine.java
+++ b/src/main/java/ganarchy/friendcode/sam/I2PSamStateMachine.java
@@ -2,6 +2,7 @@ package ganarchy.friendcode.sam;
 
 import com.google.common.collect.ImmutableMap;
 import ganarchy.friendcode.FriendCode;
+import ganarchy.friendcode.util.ConfigUtil;
 import net.minecraft.util.Util;
 
 import java.io.*;
@@ -68,7 +69,18 @@ public abstract class I2PSamStateMachine implements Closeable {
                     "PASSWORD", auth.password()
                 )
             ));
-            return "OK".equals(this.getCommand("HELLO", "REPLY").parameters().get("RESULT"));
+            var replyParams = this.getCommand("HELLO", "REPLY").parameters();
+            if ("I2P_ERROR".equals(replyParams.get("RESULT"))) {
+                var msg = replyParams.getOrDefault("MESSAGE", "");
+                FriendCode.LOGGER.error("Couldn't connect to I2P: {}", msg);
+                FriendCode.LOGGER.error(
+                    "If the above error is about authorization,"
+                        + " please create the relevant file at {} and provide"
+                        + " i2p.sam.username and i2p.sam.password.",
+                    ConfigUtil.getGlobalConfigFilePath()
+                );
+            }
+            return "OK".equals(replyParams.get("RESULT"));
         } catch (IOException e) {
             return false;
         }
@@ -76,7 +88,7 @@ public abstract class I2PSamStateMachine implements Closeable {
 
     /**
      * Attempts to step the SAM session.
-     *
+     * <p>
      * This will generally not block, unless something went wrong.
      */
     public void tryStep() {
@@ -143,7 +155,7 @@ public abstract class I2PSamStateMachine implements Closeable {
     /**
      * Reads a name from the SAM session.
      *
-     * @param name The command name.
+     * @param name   The command name.
      * @param opcode The subcommand name.
      * @return The name line, or null if something went wrong.
      * @throws IOException If an I/O error occurs.
@@ -190,6 +202,7 @@ public abstract class I2PSamStateMachine implements Closeable {
 
     /**
      * Returns the SAM bridge address.
+     *
      * @return The SAM bridge address.
      */
     protected SocketAddress getSamBridgeAddress() {
@@ -201,12 +214,13 @@ public abstract class I2PSamStateMachine implements Closeable {
 
     /**
      * Closes this connection.
+     *
      * @throws IOException As per {@link Socket#close()}.
      */
     public void close() throws IOException {
         if (this.connected) {
             this.samSocket.close();
-	}
+        }
     }
 
     protected Socket unwrap() {