1 parent
44858ccb98
commit
312596b2dd
4 files changed
+22
-9
No files matched your search
@@ -33,10 +33,11 @@ public class ChangePasswordCommand implements CommandManager.CommandRegistry {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
MQTTClient.getInstance().subscribe("loon/auth/register/+/response", (topic, message) -> {
|
String uuid = player.uuid.toString();
|
||||||
String[] parts = topic.split("/");
|
String responseTopic = "loon/auth/change_password/" + uuid + "/response";
|
||||||
|
|
||||||
String playerUuid = parts[3];
|
MQTTClient.getInstance().subscribe(responseTopic, (topic, message) -> {
|
||||||
|
MQTTClient.getInstance().unsubscribe(responseTopic);
|
||||||
|
|
||||||
ObjectMapper objectMapper = new ObjectMapper();
|
ObjectMapper objectMapper = new ObjectMapper();
|
||||||
RegisterResponse response = objectMapper.readValue(
|
RegisterResponse response = objectMapper.readValue(
|
||||||
@@ -61,7 +62,7 @@ public class ChangePasswordCommand implements CommandManager.CommandRegistry {
|
|||||||
|
|
||||||
String hashedPassword = PasswordHasher.hash(password);
|
String hashedPassword = PasswordHasher.hash(password);
|
||||||
|
|
||||||
ChangePasswordPayload payload = new ChangePasswordPayload(player.uuid.toString(), hashedPassword);
|
ChangePasswordPayload payload = new ChangePasswordPayload(uuid, hashedPassword);
|
||||||
|
|
||||||
MQTTClient.getInstance().publish(payload.topics().get(0), payload.toJson());
|
MQTTClient.getInstance().publish(payload.topics().get(0), payload.toJson());
|
||||||
|
|
||||||
|
|||||||
@@ -35,10 +35,11 @@ public class RegisterCommand implements CommandManager.CommandRegistry {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
MQTTClient.getInstance().subscribe("loon/auth/register/+/response", (topic, message) -> {
|
String uuid = player.uuid.toString();
|
||||||
String[] parts = topic.split("/");
|
String responseTopic = "loon/auth/register/" + uuid + "/response";
|
||||||
|
|
||||||
String playerUuid = parts[3];
|
MQTTClient.getInstance().subscribe(responseTopic, (topic, message) -> {
|
||||||
|
MQTTClient.getInstance().unsubscribe(responseTopic);
|
||||||
|
|
||||||
ObjectMapper objectMapper = new ObjectMapper();
|
ObjectMapper objectMapper = new ObjectMapper();
|
||||||
RegisterResponse response = objectMapper.readValue(
|
RegisterResponse response = objectMapper.readValue(
|
||||||
@@ -64,7 +65,7 @@ public class RegisterCommand implements CommandManager.CommandRegistry {
|
|||||||
|
|
||||||
String hashedPassword = PasswordHasher.hash(password);
|
String hashedPassword = PasswordHasher.hash(password);
|
||||||
|
|
||||||
RegisterPayload payload = new RegisterPayload(player.uuid.toString(), hashedPassword, internalUsername);
|
RegisterPayload payload = new RegisterPayload(uuid, hashedPassword, internalUsername);
|
||||||
|
|
||||||
MQTTClient.getInstance().publish(payload.topics().get(0), payload.toJson());
|
MQTTClient.getInstance().publish(payload.topics().get(0), payload.toJson());
|
||||||
|
|
||||||
|
|||||||
@@ -28,8 +28,11 @@ public class WebUsernameCommand implements CommandManager.CommandRegistry {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String uuid = player.uuid.toString();
|
String uuid = player.uuid.toString();
|
||||||
|
String responseTopic = "loon/auth/show_username/" + uuid + "/response";
|
||||||
|
|
||||||
|
MQTTClient.getInstance().subscribe(responseTopic, (topic, message) -> {
|
||||||
|
MQTTClient.getInstance().unsubscribe(responseTopic);
|
||||||
|
|
||||||
MQTTClient.getInstance().subscribe("loon/auth/show_username/" + uuid + "/response", (topic, message) -> {
|
|
||||||
ObjectMapper objectMapper = new ObjectMapper();
|
ObjectMapper objectMapper = new ObjectMapper();
|
||||||
ShowUsernameResponse response = objectMapper.readValue(
|
ShowUsernameResponse response = objectMapper.readValue(
|
||||||
message.getPayload(),
|
message.getPayload(),
|
||||||
|
|||||||
@@ -33,6 +33,14 @@ public class MQTTClient {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void unsubscribe(String topicFilter) {
|
||||||
|
try {
|
||||||
|
client.unsubscribe(topicFilter);
|
||||||
|
} catch (MqttException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void publish(String topic, String message, int qos) {
|
public void publish(String topic, String message, int qos) {
|
||||||
MqttMessage mqttMessage = new MqttMessage(message.getBytes());
|
MqttMessage mqttMessage = new MqttMessage(message.getBytes());
|
||||||
mqttMessage.setQos(qos);
|
mqttMessage.setQos(qos);
|
||||||
|
|||||||
Reference in new issue
Block a user