summaryrefslogtreecommitdiff
path: root/NET/worlds/console/MuteListPart.java
diff options
context:
space:
mode:
authorFuwn <[email protected]>2026-02-12 22:33:32 -0800
committerFuwn <[email protected]>2026-02-12 22:33:32 -0800
commitc7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9 (patch)
treedf9f48bf128a6c0186a8e91857d6ff30fe0e9f18 /NET/worlds/console/MuteListPart.java
downloadworldsplayer-c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9.tar.xz
worldsplayer-c7a9d4a6bd53ed7d61731770f2f10e8b9fd435f9.zip
Initial commit
Diffstat (limited to 'NET/worlds/console/MuteListPart.java')
-rw-r--r--NET/worlds/console/MuteListPart.java254
1 files changed, 254 insertions, 0 deletions
diff --git a/NET/worlds/console/MuteListPart.java b/NET/worlds/console/MuteListPart.java
new file mode 100644
index 0000000..9692966
--- /dev/null
+++ b/NET/worlds/console/MuteListPart.java
@@ -0,0 +1,254 @@
+package NET.worlds.console;
+
+import NET.worlds.core.IniFile;
+import NET.worlds.network.Galaxy;
+import NET.worlds.network.NetworkObject;
+import NET.worlds.network.ObjID;
+import NET.worlds.network.WorldServer;
+import NET.worlds.scape.Drone;
+import NET.worlds.scape.FrameEvent;
+import java.awt.Container;
+import java.awt.Event;
+import java.awt.MenuItem;
+import java.text.MessageFormat;
+import java.util.Enumeration;
+import java.util.StringTokenizer;
+import java.util.Vector;
+
+public class MuteListPart implements FramePart, NameListOwner {
+ private static final String oldIniItemName = "Mutes";
+ private static final String iniItemName = "Mute";
+ private static final int maxMutes = 50;
+ private static final String separator = ";";
+ private static MuteListPart active;
+ private Vector<String> mutes;
+ private Vector<String> syncMutes = new Vector<String>();
+ private MenuItem editItem;
+ private MenuItem disableWhisperItem;
+ private boolean rejectWhispers;
+ private DefaultConsole console;
+ private Galaxy galaxy;
+ private IniFile serverSection;
+ private Object mutesMutex = new Object();
+ private Vector<String> updates = new Vector<String>();
+
+ private void loadMutes() {
+ this.mutes = new Vector<String>();
+
+ for (int i = 0; i < 50; i++) {
+ String name = this.serverSection.getIniString("Mute" + i, "");
+ if (name.length() == 0) {
+ break;
+ }
+
+ if (FriendsListPart.isValidUserName(name) && !FriendsListPart.icontains(this.mutes, name)) {
+ this.mutes.addElement(name);
+ }
+ }
+
+ if (this.mutes.size() == 0) {
+ String mutesStr = this.serverSection.getIniString("Mutes", "");
+ StringTokenizer tokens = new StringTokenizer(mutesStr, ";");
+
+ while (tokens.hasMoreTokens() && this.mutes.size() < 50) {
+ String namex = tokens.nextToken();
+ if (FriendsListPart.isValidUserName(namex) && !FriendsListPart.icontains(this.mutes, namex)) {
+ this.mutes.addElement(namex);
+ }
+ }
+
+ if (this.mutes.size() != 0) {
+ this.saveMutes();
+ this.serverSection.setIniString("Mutes", "");
+ }
+ }
+ }
+
+ void saveMutes() {
+ int count = this.mutes.size();
+
+ for (int i = 0; i < count; i++) {
+ this.serverSection.setIniString("Mute" + i, this.mutes.elementAt(i));
+ }
+
+ this.serverSection.setIniString("Mute" + count, "");
+ }
+
+ private void setDisableWhisper() {
+ this.rejectWhispers = IniFile.gamma().getIniInt("RejectWhispers", 0) == 1;
+ if (this.rejectWhispers) {
+ this.disableWhisperItem.setLabel(Console.message("Accept-Whispers"));
+ } else {
+ this.disableWhisperItem.setLabel(Console.message("Reject-Whispers"));
+ }
+ }
+
+ @Override
+ public void activate(Console c, Container f, Console prev) {
+ active = this;
+ this.console = (DefaultConsole)c;
+ this.editItem = c.addMenuItem(Console.message("Edit-Mute-List"), "Options");
+ this.editItem.setEnabled(this.mutes != null);
+ this.disableWhisperItem = c.addMenuItem(Console.message("Reject-Whispers"), "Options");
+ this.setDisableWhisper();
+ }
+
+ @Override
+ public void deactivate() {
+ active = null;
+ this.editItem = null;
+ }
+
+ @Override
+ public boolean action(Event event, Object what) {
+ if (event.target == this.editItem) {
+ new EditNamesDialog(this, Console.message("Edit-Mute-List"), Console.message("Add-Mute-List"));
+ return true;
+ } else {
+ if (event.target == this.disableWhisperItem) {
+ IniFile.gamma().setIniInt("RejectWhispers", this.rejectWhispers ? 0 : 1);
+ this.setDisableWhisper();
+ }
+
+ return false;
+ }
+ }
+
+ @Override
+ public boolean handle(FrameEvent f) {
+ synchronized (this.mutesMutex) {
+ int count = this.updates.size();
+ if (count != 0) {
+ WorldServer server = this.console.getServerNew();
+ if (server != null) {
+ for (int i = 0; i < count; i++) {
+ String name = this.updates.elementAt(i);
+ boolean muted = this.mutes.contains(name);
+ NetworkObject obj = server.getObject(new ObjID(name));
+ if (obj instanceof Drone) {
+ Drone d = (Drone)obj;
+ d.muteStateChanged();
+ }
+
+ this.console.getFriends().changeMuteState(name, muted);
+ }
+
+ this.updates.removeAllElements();
+ this.syncMutes = (Vector<String>)this.mutes.clone();
+ }
+ }
+
+ return true;
+ }
+ }
+
+ public void setServer(WorldServer server, IniFile serverSection) {
+ this.serverSection = serverSection;
+ this.galaxy = server.getGalaxy();
+ this.loadMutes();
+ if (this.editItem != null) {
+ this.editItem.setEnabled(true);
+ }
+ }
+
+ public static boolean isMuted(WorldServer server, String name) {
+ if (server != null && name != null) {
+ Galaxy g = server.getGalaxy();
+ Enumeration<NetworkObject> consoleList = g.getConsoles();
+
+ while (consoleList.hasMoreElements()) {
+ Object c = consoleList.nextElement();
+ if (c instanceof DefaultConsole) {
+ MuteListPart target = ((DefaultConsole)c).getMutes();
+ if (target.mutes != null) {
+ return FriendsListPart.icontains(target.mutes, name);
+ }
+ }
+ }
+ }
+
+ return false;
+ }
+
+ public static boolean isRejecting(WorldServer server) {
+ if (server != null) {
+ Galaxy g = server.getGalaxy();
+ Enumeration<NetworkObject> consoleList = g.getConsoles();
+
+ while (consoleList.hasMoreElements()) {
+ Object c = consoleList.nextElement();
+ if (c instanceof DefaultConsole) {
+ MuteListPart target = ((DefaultConsole)c).getMutes();
+ if (target.rejectWhispers) {
+ return true;
+ }
+ }
+ }
+ }
+
+ return false;
+ }
+
+ @Override
+ public int getNameListCount() {
+ return this.mutes.size();
+ }
+
+ @Override
+ public String getNameListName(int index) {
+ return this.mutes.elementAt(index);
+ }
+
+ @Override
+ public void removeNameListName(int index) {
+ synchronized (this.mutesMutex) {
+ String name = this.mutes.elementAt(index);
+ this.mutes.removeElementAt(index);
+ this.saveMutes();
+ if (!this.updates.contains(name)) {
+ this.updates.addElement(name);
+ }
+ }
+ }
+
+ @Override
+ public boolean mayAddNameListName(java.awt.Window currentWindow) {
+ if (this.mutes.size() < 50) {
+ return true;
+ } else {
+ Object[] arguments = new Object[]{new String("50")};
+ new OkCancelDialog(
+ currentWindow,
+ null,
+ Console.message("Too-many-names"),
+ null,
+ Console.message("OK"),
+ MessageFormat.format(Console.message("You-are-limitedM"), arguments),
+ true
+ );
+ return false;
+ }
+ }
+
+ @Override
+ public int addNameListName(String name) {
+ synchronized (this.mutesMutex) {
+ if (name.toLowerCase().startsWith("host")) {
+ return -1;
+ } else {
+ int index = FriendsListPart.iindexOf(this.mutes, name);
+ if (index != -1) {
+ return index;
+ } else {
+ this.mutes.addElement(name);
+ this.saveMutes();
+ if (!this.updates.contains(name)) {
+ this.updates.addElement(name);
+ }
+
+ return this.mutes.size() - 1;
+ }
+ }
+ }
+ }
+}