package NET.worlds.network; import NET.worlds.console.ConfirmDialog; import NET.worlds.console.Console; import NET.worlds.console.DialogReceiver; import NET.worlds.core.RegKey; import NET.worlds.core.RegKeyNotFoundException; import java.io.IOException; import java.net.InetAddress; import java.net.UnknownHostException; import java.text.MessageFormat; public class IPhone implements DialogReceiver { private static String _IPhoneProgPath = null; private static ConfirmDialog _dlg = null; private String _name; private String _ip; private IPhone(String name, String ip) { this._name = name; this._ip = ip; } public static synchronized boolean placeCall(String name, String text) { if (_dlg != null) { return false; } else { String s = text.trim(); if (s.startsWith("[TALK:") && s.endsWith("]")) { s = s.substring(6, s.length() - 1); IPhone fone = new IPhone(name, s); _dlg = new ConfirmDialog( Console.getFrame(), fone, "Internet Phone Request", name + " has requested an Internet Phone call. " + "Do you want to call them?" ); return true; } else { return false; } } } public static boolean isCall(String text) { String s = text.trim().toUpperCase(); return s.startsWith("[TALK") && s.endsWith("]"); } public static String initiateCall(String text) { if (_IPhoneProgPath == null) { getRegEntry(); } if (_IPhoneProgPath.equals("")) { return "Can't initiate call -- no Internet Telephone Application found."; } else { String ret = "[BAD REMOTE HOST ADDRESS]"; try { String s = InetAddress.getLocalHost().toString(); s = s.substring(s.indexOf(47) + 1); ret = "[TALK:" + s + "]"; Runtime.getRuntime().exec(_IPhoneProgPath); } catch (SecurityException var3) { ret = "Can't initiate call -- couldn't start Internet Telephone Application."; } catch (UnknownHostException var4) { var4.printStackTrace(); } catch (IOException var5) { var5.printStackTrace(); } return ret; } } private static void getRegEntry() { try { RegKey root = RegKey.getRootKey(2); RegKey key = new RegKey(root, "SOFTWARE\\Classes\\InternetPhoneUser\\shell\\open\\command", 0); _IPhoneProgPath = key.getStringValue(""); key.close(); int idx = _IPhoneProgPath.indexOf(34); if (idx == 0) { _IPhoneProgPath = _IPhoneProgPath.substring(1, _IPhoneProgPath.indexOf(34, 1)); } else { _IPhoneProgPath = _IPhoneProgPath.substring(0, idx); } } catch (RegKeyNotFoundException var3) { _IPhoneProgPath = ""; } } private void talkToPhoneService() { DDEMLClass ddeml = new DDEMLClass("InternetPhone", "CallIP"); ddeml.Request("," + this._ip); ddeml.destroy(); ddeml = new DDEMLClass("InternetPhone", "Show"); ddeml.Request("2"); ddeml.destroy(); } @Override public void dialogDone(Object who, boolean confirmed) { if (confirmed) { Object[] arguments = new Object[]{new String(this._name), new String(this._ip)}; Console.println(MessageFormat.format(Console.message("Calling-IP"), arguments)); if (_IPhoneProgPath == null) { getRegEntry(); } try { Runtime.getRuntime().exec(_IPhoneProgPath); this.talkToPhoneService(); } catch (SecurityException var5) { Console.println(Console.message("Call-failed")); } catch (Exception var6) { var6.printStackTrace(); } } _dlg = null; } }