Browse Source

Handler created for IgnoreMsg

combat-2
MagicBot 8 months ago
parent
commit
fbec206389
  1. 3
      src/engine/net/client/ClientMessagePump.java
  2. 2
      src/engine/net/client/Protocol.java
  3. 112
      src/engine/net/client/handlers/IgnoreMsgHandler.java
  4. 79
      src/engine/net/client/msg/IgnoreMsg.java

3
src/engine/net/client/ClientMessagePump.java

@ -337,9 +337,6 @@ public class ClientMessagePump implements NetMsgHandler { @@ -337,9 +337,6 @@ public class ClientMessagePump implements NetMsgHandler {
break;
case OPENVAULT:
break;
case IGNORE:
((IgnoreMsg) msg).handleRequest(origin);
break;
case VIEWRESOURCES:
ViewResourcesMessage((ViewResourcesMessage) msg, origin);
break;

2
src/engine/net/client/Protocol.java

@ -110,7 +110,7 @@ public enum Protocol { @@ -110,7 +110,7 @@ public enum Protocol {
GUILDRANKCHANGE(0x0DEFB21F, ChangeRankMsg.class, ChangeRankHandler.class), // Change Rank
GUILDTREESTATUS(0x4B95FB85, GuildTreeStatusMsg.class, GuildTreeStatusMsgHandler.class),
HIRELINGSERVICE(0xD3D93322, HirelingServiceMsg.class, HirelingServiceMsgHandler.class),
IGNORE(0xBD8881EE, IgnoreMsg.class, null), //client sent /ignore command
IGNORE(0xBD8881EE, IgnoreMsg.class, IgnoreMsgHandler.class), //client sent /ignore command
INITIATETRADEHUDS(0x667D29D8, OpenTradeWindowMsg.class, null), // Open Trade Window
INVITEGROUP(0x004A2012, GroupInviteMsg.class, GroupInviteHandler.class), // Send/Receive/Deny Group Invite
INVITEGUILDFEALTY(0x0274D612, InviteToSubMsg.class, InviteToSubHandler.class), // Invite Guild to Swear

112
src/engine/net/client/handlers/IgnoreMsgHandler.java

@ -0,0 +1,112 @@ @@ -0,0 +1,112 @@
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
// Magicbane Emulator Project © 2013 - 2022
// www.magicbane.com
package engine.net.client.handlers;
import engine.exception.MsgSendException;
import engine.gameManager.ChatManager;
import engine.gameManager.DbManager;
import engine.net.client.ClientConnection;
import engine.net.client.msg.ClientNetMsg;
import engine.net.client.msg.IgnoreMsg;
import engine.objects.Account;
import engine.objects.PlayerCharacter;
public class IgnoreMsgHandler extends AbstractClientMsgHandler {
public IgnoreMsgHandler() {
super(IgnoreMsg.class);
}
@Override
protected boolean _handleNetMsg(ClientNetMsg baseMsg, ClientConnection origin) throws MsgSendException {
PlayerCharacter playerCharacter = origin.getPlayerCharacter();
// Member variable declaration
IgnoreMsg msg;
// Member variable assignment
msg = (IgnoreMsg) baseMsg;
if (msg.nameToIgnore.isEmpty()) { // list ignored players
String[] ignoredPlayers = playerCharacter.getIgnoredPlayerNames();
String crlf = "\r\n";
String out = "Ignored players (" + ignoredPlayers.length + "):";
for (String name : ignoredPlayers)
out += crlf + name;
ChatManager.chatSystemInfo(playerCharacter, out);
return true;
}
//FIX THIS, USE OUR CACHE!
PlayerCharacter pcToIgnore = PlayerCharacter.getByFirstName(msg.nameToIgnore);
if (playerCharacter == null)
return true;
if (pcToIgnore == null || pcToIgnore.getAccount() == null) {
ChatManager.chatSystemError(playerCharacter, "Character name " + msg.nameToIgnore + " does not exist and cannot be ignored.");
return true;
}
if (pcToIgnore.getObjectUUID() == playerCharacter.getObjectUUID()) {
ChatManager.chatSystemError(playerCharacter, "Try as you might, you are unable to ignore yourself!");
return true;
}
String firstName = pcToIgnore.getFirstName();
Account account = playerCharacter.getAccount();
if (account == null)
return true;
if (playerCharacter.isIgnoringPlayer(pcToIgnore)) {
if (account != null) {
if (!DbManager.PlayerCharacterQueries.SET_IGNORE_LIST(account.getObjectUUID(), pcToIgnore.getObjectUUID(), false, pcToIgnore.getFirstName())) {
ChatManager.chatSystemError(playerCharacter, "Unable to update database ignore list.");
}
} else {
ChatManager.chatSystemError(playerCharacter, "Unable to update database ignore list.");
}
playerCharacter.removeIgnoredPlayer(pcToIgnore.getAccount());
ChatManager.chatSystemInfo(playerCharacter, "Character " + firstName + " is no longer ignored.");
} else {
if (!PlayerCharacter.isIgnorable()) {
ChatManager.chatSystemError(playerCharacter, "This character cannot be ignored.");
return true;
}
if (PlayerCharacter.isIgnoreListFull()) {
ChatManager.chatSystemError(playerCharacter, "Your ignore list is already full.");
return true;
}
if (account != null) {
if (!DbManager.PlayerCharacterQueries.SET_IGNORE_LIST(account.getObjectUUID(), pcToIgnore.getObjectUUID(), true, pcToIgnore.getFirstName())) {
ChatManager.chatSystemError(playerCharacter, "Unable to update database ignore list. This ignore will not persist past server down.");
}
} else {
ChatManager.chatSystemError(playerCharacter, "Unable to update database ignore list.");
}
playerCharacter.addIgnoredPlayer(pcToIgnore.getAccount(), pcToIgnore.getFirstName());
ChatManager.chatSystemInfo(playerCharacter, "Character " + firstName + " is now being ignored.");
}
return true;
}
}

79
src/engine/net/client/msg/IgnoreMsg.java

@ -10,23 +10,17 @@ @@ -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 { @@ -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
*/

Loading…
Cancel
Save