1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
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;
}
}
}
}
}
|