Handler created for IgnoreMsg

This commit is contained in:
2024-03-29 06:08:04 -04:00
parent 7b9d9d64bb
commit fbec206389
4 changed files with 114 additions and 82 deletions
+1 -78
View File
@@ -10,23 +10,17 @@
package engine.net.client.msg;
import engine.gameManager.ChatManager;
import engine.gameManager.DbManager;
import engine.gameManager.SessionManager;
import engine.net.AbstractConnection;
import engine.net.ByteBufferReader;
import engine.net.ByteBufferWriter;
import engine.net.client.ClientConnection;
import engine.net.client.Protocol;
import engine.objects.Account;
import engine.objects.PlayerCharacter;
public class IgnoreMsg extends ClientNetMsg {
private int unknown1;
private int unknown2;
private String nameToIgnore;
public String nameToIgnore;
/**
* This is the general purpose constructor.
@@ -65,77 +59,6 @@ public class IgnoreMsg extends ClientNetMsg {
nameToIgnore = reader.getUnicodeString();
}
public void handleRequest(ClientConnection origin) {
PlayerCharacter pcSource = SessionManager.getPlayerCharacter(origin);
if (nameToIgnore.isEmpty()) { // list ignored players
String[] ignoredPlayers = pcSource.getIgnoredPlayerNames();
String crlf = "\r\n";
String out = "Ignored players (" + ignoredPlayers.length + "):";
for (String name : ignoredPlayers) {
out += crlf + name;
}
ChatManager.chatSystemInfo(pcSource, out);
return;
}
//FIX THIS, USE OUR CACHE!
PlayerCharacter pcToIgnore = PlayerCharacter.getByFirstName(nameToIgnore);
if (pcSource == null) {
return;
}
if (pcToIgnore == null || pcToIgnore.getAccount() == null) {
ChatManager.chatSystemError(pcSource, "Character name " + nameToIgnore + " does not exist and cannot be ignored.");
return;
}
if (pcToIgnore.getObjectUUID() == pcSource.getObjectUUID()) {
ChatManager.chatSystemError(pcSource, "Try as you might, you are unable to ignore yourself!");
return;
}
String fn = pcToIgnore.getFirstName();
Account ac = pcSource.getAccount();
if (ac == null)
return;
if (pcSource.isIgnoringPlayer(pcToIgnore)) {
if (ac != null) {
if (!DbManager.PlayerCharacterQueries.SET_IGNORE_LIST(ac.getObjectUUID(), pcToIgnore.getObjectUUID(), false, pcToIgnore.getFirstName())) {
ChatManager.chatSystemError(pcSource, "Unable to update database ignore list.");
}
} else {
ChatManager.chatSystemError(pcSource, "Unable to update database ignore list.");
}
pcSource.removeIgnoredPlayer(pcToIgnore.getAccount());
ChatManager.chatSystemInfo(pcSource, "Character " + fn + " is no longer ignored.");
} else {
if (!PlayerCharacter.isIgnorable()) {
ChatManager.chatSystemError(pcSource, "This character cannot be ignored.");
return;
}
if (PlayerCharacter.isIgnoreListFull()) {
ChatManager.chatSystemError(pcSource, "Your ignore list is already full.");
return;
}
if (ac != null) {
if (!DbManager.PlayerCharacterQueries.SET_IGNORE_LIST(ac.getObjectUUID(), pcToIgnore.getObjectUUID(), true, pcToIgnore.getFirstName())) {
ChatManager.chatSystemError(pcSource, "Unable to update database ignore list. This ignore will not persist past server down.");
}
} else {
ChatManager.chatSystemError(pcSource, "Unable to update database ignore list.");
}
pcSource.addIgnoredPlayer(pcToIgnore.getAccount(), pcToIgnore.getFirstName());
ChatManager.chatSystemInfo(pcSource, "Character " + fn + " is now being ignored.");
}
}
/**
* @return the unknown1
*/