Browse Source

Make it work better

master
Colin Reeder 2 years ago
parent
commit
b63034dcd5
2 changed files with 12 additions and 5 deletions
  1. +10
    -5
      src/main/java/click/vpzom/mods/mcmatrix/MatrixServiceThread.java
  2. +2
    -0
      src/main/java/click/vpzom/mods/mcmatrix/McMatrix.java

+ 10
- 5
src/main/java/click/vpzom/mods/mcmatrix/MatrixServiceThread.java View File

@@ -67,7 +67,13 @@ public class MatrixServiceThread implements Runnable {
System.out.println("m.room.message!!");
String room = evt.get("room_id").getAsString();
if(mod.cfgRoom.equals(room)) {
sendMessageToPlayers(((JsonObject)evt.get("content")).get("body").getAsString(), evt.get("sender").getAsString());
String sender = evt.get("sender").getAsString();
if(sender.startsWith("@" + mod.cfgPrefix) && sender.endsWith(":" + mod.cfgDomain)) {
// sent by server, ignore
}
else {
sendMessageToPlayers(((JsonObject)evt.get("content")).get("body").getAsString(), sender);
}
}
}
}
@@ -99,7 +105,7 @@ public class MatrixServiceThread implements Runnable {
private void joinRoom(String roomID, String userID) {
System.out.println("joining room " + roomID);
try {
URLConnection conn = new URL(mod.cfgMatrixHost + "_matrix/client/r0/join/" + roomID + (userID == null ? "" : ("?user_id=@" + userID + ":localhost:8448"))).openConnection();
URLConnection conn = new URL(mod.cfgMatrixHost + "_matrix/client/r0/join/" + roomID + (userID == null ? "" : ("?user_id=@" + userID + ":" + mod.cfgDomain))).openConnection();
((HttpURLConnection) conn).setRequestMethod("POST");
conn.setRequestProperty("Authorization", "Bearer " + mod.cfgAccessToken);

@@ -116,8 +122,7 @@ public class MatrixServiceThread implements Runnable {
registerMatrixUser(name);
String userID = getMatrixUID(name);
String txnID = new Random().nextInt() + "t";
URLConnection conn = new URL(mod.cfgMatrixHost + "_matrix/client/r0/rooms/" + mod.cfgRoom + "/send/m.room.message/" + txnID + "?user_id=@" + userID + ":localhost:8448").openConnection();
// TODO not that
URLConnection conn = new URL(mod.cfgMatrixHost + "_matrix/client/r0/rooms/" + mod.cfgRoom + "/send/m.room.message/" + txnID + "?user_id=@" + userID + ":" + mod.cfgDomain).openConnection();
((HttpURLConnection) conn).setRequestMethod("PUT");
conn.setRequestProperty("Authorization", "Bearer " + mod.cfgAccessToken);
conn.setRequestProperty("Content-Type", "application/json");
@@ -165,7 +170,7 @@ public class MatrixServiceThread implements Runnable {
int status = ((HttpURLConnection)conn).getResponseCode();
System.out.println("result: " + status);

inviteToRoom("@" + userID + ":localhost:8448");
inviteToRoom("@" + userID + ":" + mod.cfgDomain);
joinRoom(mod.cfgRoom, userID);
}



+ 2
- 0
src/main/java/click/vpzom/mods/mcmatrix/McMatrix.java View File

@@ -20,6 +20,7 @@ public class McMatrix {
protected String cfgAccessToken;
protected String cfgRoom;
protected String cfgPrefix;
protected String cfgDomain;

private MatrixServiceThread serviceThread;

@@ -34,6 +35,7 @@ public class McMatrix {
cfgAccessToken = config.get(Configuration.CATEGORY_GENERAL, "accessToken", "").getString();
cfgRoom = config.get(Configuration.CATEGORY_GENERAL, "room", "").getString();
cfgPrefix = config.get(Configuration.CATEGORY_GENERAL, "userPrefix", "mc_").getString();
cfgDomain = config.get(Configuration.CATEGORY_GENERAL, "domain", "localhost").getString();
config.save();

MinecraftForge.EVENT_BUS.register(this);


Loading…
Cancel
Save