Fix u_cph | Modify ArkOneSender

- Needs testing to verify fixed and if Sender works
This commit is contained in:
Julia Butenhoff 2022-07-19 07:54:11 -05:00 committed by Julia Butenhoff
parent f1b11c0247
commit e40677bfdd
3 changed files with 17 additions and 22 deletions

View File

@ -81,7 +81,7 @@ public class ArkOneController implements TcpHandler {
responses.add(userPlugin.ChangeChatStatus(commandInfo, connection));
break;
case "u_cph":
responses.add(userPlugin.ChangePhoneStatus(commandInfo));
responses.add(userPlugin.ChangePhoneStatus(commandInfo, connection));
break;
case "p":
responses.add(userPlugin.Ping());

View File

@ -62,25 +62,21 @@ public class ArkOneSender {
}
public void SendToUser(UUID clientId, String message) {
Connection connection = null;
for (Connection conn : server.getConnections()) {
if (conn.getClientIdentifier() == clientId) {
connection = conn;
}
}
try {
// Append a 0x00 to the end of the response
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
outputStream.write(message.getBytes());
outputStream.write((byte)0x00);
if (connection != null) {
try {
// Append a 0x00 to the end of the response
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
outputStream.write(message.getBytes());
outputStream.write((byte)0x00);
conn.send(outputStream.toByteArray());
connection.send(outputStream.toByteArray());
} catch (IOException e) {
System.out.println("[ArkOne][ERROR] Failed to send message to user [" + clientId + "]: " + message);
e.printStackTrace();
return;
} catch (IOException e) {
System.out.println("[ArkOne][ERROR] Failed to send message to user [" + clientId + "]: " + message);
e.printStackTrace();
}
}
}
}

View File

@ -144,6 +144,7 @@ public class UserPlugin {
public String ChangeChatStatus(Element element, Connection connection) throws ParserConfigurationException, TransformerException {
User user = server.getConnectedUsers().get(connection.getClientIdentifier());
// Update the chat status
user.setChatStatus(Integer.valueOf(element.getAttribute("s")));
userService.updateUserOnServer(connection, user);
@ -162,14 +163,12 @@ public class UserPlugin {
return ArkOneParser.RemoveXMLTag(doc);
}
public String ChangePhoneStatus(Element element) throws ParserConfigurationException, TransformerException {
//TODO: VERIFY THE ATTRIBUTE NAME
User user = userService.findByUUID(Integer.valueOf(element.getAttribute("id"))).orElse(null);
public String ChangePhoneStatus(Element element, Connection connection) throws ParserConfigurationException, TransformerException {
User user = server.getConnectedUsers().get(connection.getClientIdentifier());
//TODO: VERIFY THE ATTRIBUTE NAME
// Update that user's chat status
// Update the phone status
user.setPhoneStatus(Integer.valueOf(element.getAttribute("ph")));
userService.save(user);
userService.updateUserOnServer(connection, user);
// Build the response
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();