mirror of
https://github.com/Leahnaya/UBFunkeysServer.git
synced 2026-04-08 01:44:58 -05:00
Implement u_ccs and fix potential issue with ConnectionIds
- Needs Testing
This commit is contained in:
parent
2fe09b3116
commit
660fdc3182
|
|
@ -77,6 +77,9 @@ public class ArkOneController implements TcpHandler {
|
|||
case "u_gbl":
|
||||
responses.add(userPlugin.GetBuddyList(commandInfo));
|
||||
break;
|
||||
case "u_ccs":
|
||||
responses.add(userPlugin.ChangeChatStatus(commandInfo));
|
||||
break;
|
||||
case "p":
|
||||
responses.add(userPlugin.Ping());
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ import javax.xml.parsers.ParserConfigurationException;
|
|||
import javax.xml.transform.TransformerException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
|
||||
@Service
|
||||
public class UserPlugin {
|
||||
|
|
@ -111,7 +111,7 @@ public class UserPlugin {
|
|||
if (buddyUser == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
//TODO: VERIFY THIS BUILDS THE XML AS EXPECTED
|
||||
// Get information off their data to build a xml tag
|
||||
Element buddyElement = doc.createElement("buddy");
|
||||
buddyElement.setAttribute("id", String.valueOf(buddyUser.getUUID()));
|
||||
|
|
@ -128,6 +128,7 @@ public class UserPlugin {
|
|||
user.setIsOnline(1);
|
||||
userService.save(user);
|
||||
|
||||
// Let all your buddies know you are online
|
||||
if (buddyList.size() > 0) {
|
||||
arkOneSender.SendStatusUpdate("u_cos", "o",
|
||||
String.valueOf(user.getIsOnline()), user.getUUID());
|
||||
|
|
@ -136,6 +137,30 @@ public class UserPlugin {
|
|||
return ArkOneParser.RemoveXMLTag(doc);
|
||||
}
|
||||
|
||||
public String ChangeChatStatus(Element element) throws ParserConfigurationException, TransformerException {
|
||||
//TODO: VERIFY THE ATTRIBUTE NAME
|
||||
User user = userService.findByUUID(Integer.valueOf(element.getAttribute("id"))).orElse(null);
|
||||
|
||||
//TODO: VERIFY THE ATTRIBUTE NAME
|
||||
// Update that user's chat status
|
||||
user.setChatStatus(Integer.valueOf(element.getAttribute("s")));
|
||||
userService.save(user);
|
||||
|
||||
// Build the response
|
||||
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
|
||||
Document doc = dBuilder.newDocument();
|
||||
Element rootElement = doc.createElement("u_ccs");
|
||||
rootElement.setAttribute("s", String.valueOf(user.getChatStatus()));
|
||||
rootElement.setAttribute("id", String.valueOf(user.getUUID()));
|
||||
doc.appendChild(rootElement);
|
||||
|
||||
// Announce to friends
|
||||
arkOneSender.SendStatusUpdate("u_ccs", "s", String.valueOf(user.getChatStatus()), user.getUUID());
|
||||
|
||||
return ArkOneParser.RemoveXMLTag(doc);
|
||||
}
|
||||
|
||||
public String Ping() {
|
||||
return "<p t=\"30\" />";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -89,11 +89,13 @@ public class TcpServer implements Server, Connection.Listener {
|
|||
public void connected(Connection connection)
|
||||
throws InvocationTargetException, IllegalAccessException {
|
||||
logger.info("New connection! Ip: " + connection.getAddress().getCanonicalHostName() + ".");
|
||||
connections.add(connection);
|
||||
|
||||
// Generate a UUID for this connection
|
||||
connection.setClientIdentifier(UUID.randomUUID());
|
||||
|
||||
// Save it to all connections
|
||||
connections.add(connection);
|
||||
|
||||
logger.info("Current connections count: " + connections.size());
|
||||
for (Connection.Listener listener : listeners) {
|
||||
listener.connected(connection);
|
||||
|
|
@ -104,11 +106,13 @@ public class TcpServer implements Server, Connection.Listener {
|
|||
public void disconnected(Connection connection)
|
||||
throws InvocationTargetException, IllegalAccessException {
|
||||
logger.info("Disconnect! Ip: " + connection.getAddress().getCanonicalHostName() + ".");
|
||||
connections.remove(connection);
|
||||
|
||||
// Remove the UUID
|
||||
connection.setClientIdentifier(null);
|
||||
|
||||
// Remove it from all connections
|
||||
connections.remove(connection);
|
||||
|
||||
logger.info("Current connections count: " + connections.size());
|
||||
for (Connection.Listener listener : listeners) {
|
||||
listener.disconnected(connection);
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user