summaryrefslogtreecommitdiff
path: root/NET/worlds/console/VoiceChat.java
diff options
context:
space:
mode:
authorFuwn <[email protected]>2021-05-03 16:38:41 -0700
committerFuwn <[email protected]>2021-05-03 16:38:41 -0700
commite1e781bb2135ef78592226f1a3eaba4925702f1f (patch)
tree8a5b590463ed413e1c6eabb719130e701b95ca63 /NET/worlds/console/VoiceChat.java
downloadworlds.jar-e1e781bb2135ef78592226f1a3eaba4925702f1f.tar.xz
worlds.jar-e1e781bb2135ef78592226f1a3eaba4925702f1f.zip
:star:HEADmain
Diffstat (limited to 'NET/worlds/console/VoiceChat.java')
-rw-r--r--NET/worlds/console/VoiceChat.java669
1 files changed, 669 insertions, 0 deletions
diff --git a/NET/worlds/console/VoiceChat.java b/NET/worlds/console/VoiceChat.java
new file mode 100644
index 0000000..3c2cc20
--- /dev/null
+++ b/NET/worlds/console/VoiceChat.java
@@ -0,0 +1,669 @@
+/* */ package NET.worlds.console;
+/* */
+/* */ import NET.worlds.core.IniFile;
+/* */ import NET.worlds.network.URL;
+/* */ import NET.worlds.network.WorldServer;
+/* */ import NET.worlds.scape.CDAudio;
+/* */ import NET.worlds.scape.Pilot;
+/* */ import NET.worlds.scape.WavSoundPlayer;
+/* */ import java.io.File;
+/* */ import java.io.IOException;
+/* */ import java.net.InetAddress;
+/* */ import java.text.MessageFormat;
+/* */ import java.util.Vector;
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */ public class VoiceChat
+/* */ implements DialogReceiver
+/* */ {
+/* */ private static final String SPEAKFREELY = "sfmain.exe";
+/* */ private static final int INITIAL_STATE = 0;
+/* */ private static final int BEGINNING_CONNECTION = 1;
+/* */ private static final int REQUESTING_CONNECTION = 2;
+/* */ private static final int ATTEMPTING_CONNECTION = 3;
+/* */ private static final int SUCCESSFULLY_CONNECTED = 4;
+/* */ private static final int CONNECTION_FAILED_RESETTING = 5;
+/* */ private static final int CLOSING_CONNECTION = 6;
+/* */ private static final int CONNECTION_CLOSED_RESETTING = 7;
+/* 110 */ private static final String[] _stateStrs = { "Initial State",
+/* 111 */ "Beginning Connection", "Attempting Connection",
+/* 112 */ "Successfully Connected", "Resetting (Connection Failed)",
+/* 113 */ "Closing Connection", "Resetting (Connection Closed)" };
+/* */
+/* */
+/* 116 */ private int _state = 0;
+/* */
+/* */ public int getState() {
+/* 119 */ return this._state;
+/* */ }
+/* */
+/* */ public String getStateString() {
+/* 123 */ return _stateStrs[this._state];
+/* */ }
+/* */
+/* */
+/* 127 */ private String _error = "";
+/* */
+/* */ public String getLastError() {
+/* 130 */ return this._error;
+/* */ }
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* 142 */ private static boolean _selfWhisper = false;
+/* */
+/* */ public static void activateSelfWhisper() {
+/* 145 */ _selfWhisper = true;
+/* 146 */ Console.println(Console.message("Selfwhisper-on"));
+/* */ }
+/* */
+/* */ public static void deactivateSelfWhisper() {
+/* 150 */ _selfWhisper = false;
+/* 151 */ Console.println(Console.message("Selfwhisper-off"));
+/* */ }
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* 161 */ public static String VCdebugCommand = "&|+debug>VCcommand=";
+/* 162 */ public static String VCdebugCommandReset = "&|+debug>VCcommandReset=";
+/* */
+/* 164 */ private static String _extraCommand = "";
+/* */
+/* */ public static void setExtra(String text) {
+/* 167 */ int start = text.indexOf('"') + 1;
+/* 168 */ int end = text.lastIndexOf('"');
+/* 169 */ _extraCommand = text.substring(start, end);
+/* 170 */ Object[] arguments = { new String(_extraCommand) };
+/* 171 */ Console.println(MessageFormat.format(Console.message("Add-VoiceChat"),
+/* 172 */ arguments));
+/* */ }
+/* */
+/* */ public static void resetExtra() {
+/* 176 */ _extraCommand = "";
+/* 177 */ Console.println(Console.message("VoiceChat-reset"));
+/* */ }
+/* */
+/* */
+/* */
+/* 182 */ private static GammaPhoneMonitor chatMonitor = null;
+/* */
+/* */
+/* 185 */ private String _who = null;
+/* */ public static UpdateableDialog voiceChatDialog;
+/* */
+/* 188 */ public String who() { return this._who; }
+/* */
+/* */
+/* */
+/* */ private static UpdateableDialog voiceChatQueryDialog;
+/* */
+/* */
+/* */ private static String voiceChatQueryIP;
+/* */
+/* */
+/* */ private static String voiceChatQueryWho;
+/* */
+/* */
+/* 201 */ public static boolean voiceChatEnabled = IniFile.gamma().getIniInt(
+/* 202 */ "VoiceChat", voiceChatAvailable() ? 1 : 0) != 0;
+/* */
+/* */ public static void setVoiceChatEnabled(boolean f) {
+/* 205 */ if (!voiceChatAvailable())
+/* 206 */ f = false;
+/* 207 */ voiceChatEnabled = f;
+/* 208 */ IniFile.gamma().setIniInt("VoiceChat", f ? 1 : 0);
+/* */ }
+/* */
+/* 211 */ private static boolean voiceChatExeChecked = false;
+/* 212 */ private static boolean voiceChatExists = false;
+/* */
+/* */ public static boolean voiceChatAvailable() {
+/* 215 */ if (voiceChatExeChecked) {
+/* 216 */ return voiceChatExists;
+/* */ }
+/* 218 */ URL vcexe = URL.make("home:sfmain.exe");
+/* 219 */ String fname = vcexe.unalias();
+/* 220 */ File f = new File(fname);
+/* 221 */ voiceChatExists = f.exists();
+/* 222 */ voiceChatExeChecked = true;
+/* 223 */ return voiceChatExists;
+/* */ }
+/* */
+/* 226 */ private int _gammaphoneWindow = 0;
+/* */
+/* */ public void registerProcess(int id) {
+/* 229 */ this._gammaphoneWindow = id;
+/* */ }
+/* */
+/* 232 */ DefaultConsole _console = null;
+/* */
+/* 234 */ VCTimerThread _vtimer = null;
+/* */ private static final String voiceChatQuery = "&|+voicechat?";
+/* */ private static final String voiceChatAccept = "&|+voicechat>accept";
+/* */ private static final String voiceChatReject = "&|+voicechat>reject";
+/* */ private static final String voiceChatBusy = "&|+voicechat>busy";
+/* */ private static final String voiceChatNotVIP = "&|+voicechat>notvip";
+/* */ private static final String voiceChatDisabled = "&|+voicechat>disabled";
+/* */
+/* */ public void beginChat(String friendName, DefaultConsole console) {
+/* 243 */ this._state = 1;
+/* 244 */ this._console = console;
+/* */
+/* 246 */ if (!console.getVIP()) {
+/* 247 */ resetConnection(Console.message("must-be-VIP"));
+/* */ } else {
+/* 249 */ String ip = null;
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */ try
+/* */ {
+/* 262 */ InetAddress localAddr = console.getServerNew()
+/* 263 */ .getLocalAddress();
+/* 264 */ ip = localAddr != null ? localAddr.toString() : null;
+/* */
+/* 266 */ ip = ip.substring(ip.indexOf('/') + 1);
+/* */ }
+/* */ catch (SecurityException e)
+/* */ {
+/* 270 */ resetConnection(Console.message("sec-violation"));
+/* */ }
+/* */
+/* 273 */ if (ip == null) {
+/* 274 */ resetConnection(Console.message("cant-determine-IP"));
+/* */ } else {
+/* 276 */ if (voiceChatDialog != null) {
+/* 277 */ if (friendName.equals(this._who)) {
+/* 278 */ Object[] arguments = { new String(this._who) };
+/* 279 */ Console.println(MessageFormat.format(
+/* 280 */ Console.message("already-VoiceChat"), arguments));
+/* 281 */ return;
+/* */ }
+/* 283 */ resetConnection(Console.message("chat-ended"));
+/* */ }
+/* */
+/* 286 */ if ((voiceChatQueryDialog != null) &&
+/* 287 */ (voiceChatQueryWho.equals(friendName))) {
+/* 288 */ arguments = new Object[] { new String(friendName) };
+/* 289 */ Console.println(MessageFormat.format(
+/* 290 */ Console.message("already-calling"), arguments));
+/* 291 */ return;
+/* */ }
+/* */
+/* */
+/* */
+/* */
+/* */
+/* 298 */ while (ConnectionRecord.checkList(this._who)) { Object[] arguments;
+/* 299 */ Object[] arguments = { new String(this._who) };
+/* 300 */ Console.println(MessageFormat.format(
+/* 301 */ Console.message("wait-a-few"), arguments));
+/* */ try {
+/* 303 */ Thread.sleep(2000L);
+/* */ }
+/* */ catch (InterruptedException localInterruptedException) {}
+/* */ }
+/* */
+/* */
+/* 309 */ if (initiateVoiceChat(friendName, null)) {
+/* 310 */ Object[] arguments = { new String(friendName),
+/* 311 */ new String(ip) };
+/* 312 */ Console.println(MessageFormat.format(
+/* 313 */ Console.message("Asking-to-call"), arguments));
+/* 314 */ this._state = 2;
+/* 315 */ sendWhisper(friendName, "&|+voicechat?" + ip);
+/* */
+/* 317 */ this._vtimer = new VCTimerThread(this, 30000L);
+/* 318 */ this._vtimer.start();
+/* */ }
+/* */ }
+/* */ }
+/* */ }
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */ private static native void terminateVC(int paramInt);
+/* */
+/* */
+/* */
+/* */
+/* */ private boolean initiateVoiceChat(String friendName, String ip)
+/* */ {
+/* 335 */ this._who = friendName;
+/* 336 */ int hWnd = Window.getHWnd();
+/* */
+/* 338 */ String startString = URL.make("home:sfmain.exe" + (
+/* 339 */ ip == null ? " -a " : new StringBuilder(" -c ").append(ip).toString()) + " -g " + hWnd +
+/* 340 */ " -p " + Window.getGammaProcessID() + " " + _extraCommand +
+/* 341 */ " ").unalias();
+/* */
+/* */
+/* */
+/* */
+/* */
+/* 347 */ WavSoundPlayer.pauseSystem();
+/* 348 */ CDAudio.get().setEnabled(false);
+/* */
+/* 350 */ if (tryToRun(startString)) {
+/* 351 */ Object[] arguments = { new String(this._who) };
+/* 352 */ voiceChatDialog = new UpdateableDialog(Console.getFrame(), this,
+/* 353 */ Console.message("Voice-connect"), null,
+/* 354 */ Console.message("Terminate"), MessageFormat.format(
+/* 355 */ Console.message("end-VoiceChat"), arguments), false);
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* 363 */ if (chatMonitor == null) {
+/* 364 */ chatMonitor = new GammaPhoneMonitor(this);
+/* 365 */ chatMonitor.start();
+/* */ }
+/* */
+/* */
+/* */
+/* */
+/* */
+/* 372 */ return true;
+/* */ }
+/* 374 */ WavSoundPlayer.resumeSystem();
+/* 375 */ CDAudio.get().setEnabled(true);
+/* */
+/* 377 */ Object[] arguments = { new String(this._who), new String(startString) };
+/* 378 */ voiceChatDialog = new UpdateableDialog(Console.getFrame(), this,
+/* 379 */ Console.message("Voice-Chat-199"), null,
+/* 380 */ Console.message("Continue"), MessageFormat.format(
+/* 381 */ Console.message("Unable-to-chat"), arguments), false);
+/* 382 */ return false;
+/* */ }
+/* */
+/* */
+/* */ public void inform(int msgid, String msg)
+/* */ {
+/* 388 */ if (msgid >= 900) {
+/* 389 */ if (voiceChatDialog == null)
+/* */ {
+/* */
+/* 392 */ return;
+/* */ }
+/* */
+/* 395 */ voiceChatDialog.setTitle(Console.message("VoiceChat-Connected"));
+/* 396 */ this._state = 4;
+/* */ } else {
+/* 398 */ resetConnection(msg);
+/* */ }
+/* */ }
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */ public boolean handleChatRequest(String user, String text, DefaultConsole console)
+/* */ {
+/* 418 */ Object[] arguments = { new String(user) };
+/* 419 */ if (!console.getVIP()) {
+/* 420 */ Console.println(MessageFormat.format(
+/* 421 */ Console.message("reject-chat"), arguments));
+/* 422 */ sendWhisper(user, "&|+voicechat>notvip");
+/* 423 */ } else if (!voiceChatEnabled) {
+/* 424 */ Console.println(MessageFormat.format(
+/* 425 */ Console.message("chat-disabled"), arguments));
+/* 426 */ sendWhisper(user, "&|+voicechat>disabled");
+/* 427 */ } else if (voiceChatQueryDialog != null) {
+/* 428 */ sendWhisper(user, "&|+voicechat>busy");
+/* */ } else {
+/* 430 */ voiceChatQueryIP = text.substring("&|+voicechat?".length());
+/* 431 */ voiceChatQueryWho = user;
+/* */
+/* 433 */ voiceChatQueryDialog = new UpdateableDialog(Console.getFrame(),
+/* 434 */ this, Console.message("Accept-voice"),
+/* 435 */ Console.message("Reject"), Console.message("Accept"),
+/* 436 */ MessageFormat.format(Console.message("do-you-voice"),
+/* 437 */ arguments), false);
+/* */ }
+/* 439 */ return true;
+/* */ }
+/* */
+/* */ public boolean handleChatWhisper(String user, String whisper, DefaultConsole console)
+/* */ {
+/* 444 */ Object[] arguments = { new String(user) };
+/* 445 */ if (whisper.startsWith("&|+voicechat?")) {
+/* 446 */ handleChatRequest(user, whisper, console);
+/* 447 */ return true;
+/* */ }
+/* */
+/* */
+/* 451 */ if (whisper.startsWith("&|+voicechat>accept"))
+/* */ {
+/* */
+/* */
+/* 455 */ if (this._state != 2) {
+/* 456 */ sendWhisper(user, "&|+voicechat>reject");
+/* 457 */ return false;
+/* */ }
+/* */
+/* 460 */ Console.println(MessageFormat.format(
+/* 461 */ Console.message("chat-accepted"), arguments));
+/* */
+/* 463 */ synchronized (this._vtimer) {
+/* 464 */ this._vtimer._vc = null;
+/* */ }
+/* 466 */ this._vtimer = null;
+/* */
+/* 468 */ this._state = 3;
+/* 469 */ this._vtimer = new VCTimerThread(this, 15000L);
+/* 470 */ this._vtimer.start();
+/* */
+/* */ }
+/* 473 */ else if (whisper.startsWith("&|+voicechat>notvip")) {
+/* 474 */ if ((voiceChatDialog != null) && (this._who.equals(user))) {
+/* 475 */ resetConnection(MessageFormat.format(
+/* 476 */ Console.message("cannot-voice"), arguments));
+/* */ }
+/* */
+/* */
+/* */ }
+/* 481 */ else if (whisper.startsWith("&|+voicechat>disabled")) {
+/* 482 */ if ((voiceChatDialog != null) && (this._who.equals(user))) {
+/* 483 */ resetConnection(MessageFormat.format(
+/* 484 */ Console.message("user-voice-dis"), arguments));
+/* */ }
+/* */
+/* */
+/* */ }
+/* 489 */ else if (whisper.startsWith("&|+voicechat>busy")) {
+/* 490 */ if ((voiceChatDialog != null) && (this._who.equals(user))) {
+/* 491 */ resetConnection(MessageFormat.format(
+/* 492 */ Console.message("receiving-Voice"), arguments));
+/* */ }
+/* */
+/* */
+/* */ }
+/* 497 */ else if (whisper.startsWith("&|+voicechat>reject"))
+/* */ {
+/* 499 */ if ((voiceChatDialog != null) && (this._who.equals(user))) {
+/* 500 */ resetConnection(MessageFormat.format(
+/* 501 */ Console.message("Voice-terminated"), arguments));
+/* */ }
+/* 503 */ if ((voiceChatQueryDialog != null) && (voiceChatQueryWho != null) &&
+/* 504 */ (voiceChatQueryWho.equals(user))) {
+/* 505 */ voiceChatQueryDialog.closeIt(false);
+/* */
+/* */
+/* 508 */ voiceChatQueryWho = null;
+/* 509 */ resetConnection(MessageFormat.format(
+/* 510 */ Console.message("Voice-terminated"), arguments));
+/* */ }
+/* */ }
+/* 513 */ return false;
+/* */ }
+/* */
+/* */ public static boolean tryToRun(String s) {
+/* */ try {
+/* 518 */ Runtime.getRuntime().exec(s);
+/* 519 */ return true;
+/* */ } catch (IOException e) {}
+/* 521 */ return false;
+/* */ }
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */ public void checkConnected()
+/* */ {
+/* 531 */ if (getState() == 2) {
+/* 532 */ resetConnection(Console.message("never-answered"));
+/* 533 */ sendWhisper(who(), "&|+voicechat>reject");
+/* 534 */ return;
+/* */ }
+/* */
+/* 537 */ if (getState() != 4) {
+/* 538 */ resetConnection(Console.message("VoiceChat-failed"));
+/* */ }
+/* */ }
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */ public void resetConnection(String err)
+/* */ {
+/* 557 */ this._error = err;
+/* 558 */ if (err != null) {
+/* 559 */ this._state = 5;
+/* 560 */ Console.println(this._error);
+/* */ }
+/* */
+/* 563 */ if (voiceChatDialog != null) {
+/* 564 */ voiceChatDialog.closeIt(true);
+/* */ }
+/* */ }
+/* */
+/* */
+/* */ public void terminate()
+/* */ {
+/* 571 */ if (this._vtimer != null)
+/* */ {
+/* 573 */ synchronized (this._vtimer) {
+/* 574 */ this._vtimer._vc = null;
+/* */ }
+/* */
+/* 577 */ this._vtimer = null;
+/* */ }
+/* */
+/* */
+/* */
+/* */
+/* */
+/* 584 */ CDAudio.get().setEnabled(true);
+/* */
+/* */
+/* */
+/* */
+/* 589 */ ConnectionRecord.getList().addElement(new ConnectionRecord(who()));
+/* */
+/* 591 */ this._state = 0;
+/* */ }
+/* */
+/* */ public void release() {
+/* 595 */ if (chatMonitor != null) {
+/* 596 */ chatMonitor.stop();
+/* 597 */ chatMonitor = null;
+/* */ }
+/* */ }
+/* */
+/* */
+/* */
+/* */
+/* */ public synchronized void dialogDone(Object who, boolean confirmed)
+/* */ {
+/* 606 */ if (who == voiceChatQueryDialog) {
+/* 607 */ voiceChatQueryDialog = null;
+/* 608 */ if (confirmed) {
+/* 609 */ sendWhisper(voiceChatQueryWho, "&|+voicechat>accept");
+/* 610 */ initiateVoiceChat(voiceChatQueryWho, voiceChatQueryIP);
+/* */
+/* */
+/* */
+/* */ }
+/* 615 */ else if (voiceChatQueryWho != null) {
+/* 616 */ sendWhisper(voiceChatQueryWho, "&|+voicechat>reject");
+/* */ }
+/* 618 */ } else if (who == voiceChatDialog) {
+/* 619 */ this._state = 6;
+/* 620 */ String stopString = URL.make("home:sfmain.exe -q")
+/* 621 */ .unalias();
+/* */
+/* */
+/* */
+/* 625 */ tryToRun(stopString);
+/* */
+/* */
+/* 628 */ voiceChatDialog = null;
+/* 629 */ sendWhisper(this._who, "&|+voicechat>reject");
+/* 630 */ terminate();
+/* */
+/* */
+/* */
+/* */ }
+/* */ else
+/* */ {
+/* */
+/* */
+/* */
+/* 640 */ String stopString = URL.make("home:sfmain.exe -q")
+/* 641 */ .unalias();
+/* */
+/* */
+/* 644 */ tryToRun(stopString);
+/* */ }
+/* */ }
+/* */
+/* */
+/* */
+/* */
+/* */
+/* */ private void sendWhisper(String destination, String text)
+/* */ {
+/* 654 */ Pilot.sendText(destination, text);
+/* */
+/* */
+/* */
+/* */
+/* 659 */ if (_selfWhisper) {
+/* 660 */ handleChatWhisper(destination, text, this._console);
+/* */ }
+/* */ }
+/* */ }
+
+
+/* Location: C:\Program Files (x86)\Worlds Inc\WorldsPlayer - Win7\lib\worlds.jar!\NET\worlds\console\VoiceChat.class
+ * Java compiler version: 6 (50.0)
+ * JD-Core Version: 0.7.1
+ */ \ No newline at end of file