PageRenderTime 1203ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 1ms

/oculus/WEB-INF/src/oculus/Application.java

http://oculus.googlecode.com/
Java | 1977 lines | 1563 code | 199 blank | 215 comment | 371 complexity | bb55a57606156e474f4317f1b0a58f6d MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  1. package oculus;
  2. import java.io.File;
  3. import java.util.Collection;
  4. import java.util.Set;
  5. import java.util.UUID;
  6. import oculus.commport.AbstractArduinoComm;
  7. import oculus.commport.Discovery;
  8. import oculus.commport.LightsComm;
  9. import org.red5.server.adapter.MultiThreadedApplicationAdapter;
  10. import org.red5.server.api.IConnection;
  11. import org.red5.server.api.Red5;
  12. import org.red5.server.api.service.IServiceCapableConnection;
  13. import org.jasypt.util.password.*;
  14. import org.red5.io.amf3.ByteArray;
  15. import developer.UpdateFTP;
  16. /** red5 application */
  17. public class Application extends MultiThreadedApplicationAdapter {
  18. private static final int STREAM_CONNECT_DELAY = 2000;
  19. private ConfigurablePasswordEncryptor passwordEncryptor = new ConfigurablePasswordEncryptor();
  20. private static String salt;
  21. private IConnection grabber = null;
  22. private IConnection player = null;
  23. private AbstractArduinoComm comport = null;
  24. private LightsComm light = null;
  25. private BatteryLife battery = null;
  26. private Settings settings = new Settings();
  27. private String pendinguserconnected = null;
  28. private String remember = null;
  29. private IConnection pendingplayer = null;
  30. private String httpPort;
  31. private Docker docker = null;
  32. private State state = State.getReference();
  33. private boolean initialstatuscalled = false;
  34. private boolean pendingplayerisnull = true;
  35. private boolean playerstream = false;
  36. private LoginRecords loginRecords = new LoginRecords();
  37. //dev stuff
  38. private developer.CommandServer commandServer = null;
  39. private developer.LogManager moves = new developer.LogManager();
  40. public developer.OpenNIRead openNIRead = null;
  41. // try to make private
  42. public boolean muteROVonMove = false;
  43. public String stream = null;
  44. public Speech speech = new Speech();
  45. //public String os = Settings.os; // "linux" or "windows"
  46. public Application() {
  47. super();
  48. ///if (System.getProperty("os.name").matches("Linux")) { os = "linux"; }
  49. //else { os = "windows"; }
  50. //System.out.println("OCULUS: OS = "+os);
  51. passwordEncryptor.setAlgorithm("SHA-1");
  52. passwordEncryptor.setPlainDigest(true);
  53. FrameGrabHTTP.setApp(this);
  54. RtmpPortRequest.setApp(this);
  55. AuthGrab.setApp(this);
  56. //settings = new Settings(this);
  57. initialize();
  58. }
  59. @Override
  60. public boolean appConnect(IConnection connection, Object[] params) {
  61. String logininfo[] = ((String) params[0]).split(" ");
  62. // always accept local grabber
  63. if ((connection.getRemoteAddress()).equals("127.0.0.1")
  64. && logininfo[0].equals(""))
  65. return true;
  66. if (logininfo.length == 1) { // test for cookie auth
  67. String username = logintest("", logininfo[0]);
  68. if (username != null) {
  69. pendinguserconnected = username;
  70. return true;
  71. }
  72. }
  73. if (logininfo.length > 1) { // test for user/pass/remember
  74. String encryptedPassword = (passwordEncryptor
  75. .encryptPassword(logininfo[0] + salt + logininfo[1])).trim();
  76. if (logintest(logininfo[0], encryptedPassword) != null) {
  77. if (logininfo[2].equals("remember")) {
  78. remember = encryptedPassword;
  79. }
  80. pendinguserconnected = logininfo[0];
  81. return true;
  82. }
  83. }
  84. String str = "login from: " + connection.getRemoteAddress() + " failed";
  85. System.out.println("OCULUS: appConnect(): " + str);
  86. messageGrabber(str, "");
  87. return false;
  88. }
  89. @Override
  90. public void appDisconnect(IConnection connection) {
  91. if (connection.equals(player)) {
  92. String str = state.get(State.user) + " disconnected";
  93. System.out.println("OCULUS: appDisconnect(): " + str);
  94. messageGrabber(str, "connection awaiting connection");
  95. // admin = false;
  96. // TODO: issue 24
  97. loginRecords.signout();
  98. System.out.println("OCULUS: after appDisconnect(): " + loginRecords);
  99. if(settings.getBoolean(Settings.developer))
  100. if(state.get(State.user) == null)
  101. System.out.println("OCULUS: user was logged out correctly...");
  102. player = null;
  103. if (!state.getBoolean(State.autodocking)) {
  104. if (stream != null) {
  105. if (!stream.equals("stop")) {
  106. publish("stop");
  107. }
  108. }
  109. if (light.isConnected()) { // && light.lightLevel != 0) {
  110. if (light.spotLightBrightness() > 0)
  111. light.setSpotLightBrightness(0);
  112. if (light.floodLightOn())
  113. light.floodLight("off");
  114. }
  115. if (comport != null) {
  116. comport.stopGoing();
  117. comport.releaseCameraServo();
  118. }
  119. }
  120. if (playerstream) {
  121. playerstream = false;
  122. grabberPlayPlayer(0);
  123. messageGrabber("playerbroadcast", "0");
  124. }
  125. }
  126. if (connection.equals(grabber)) {
  127. grabber = null;
  128. // log.info("grabber disconnected");
  129. // wait a bit, see if still no grabber, THEN reload
  130. new Thread(new Runnable() {
  131. public void run() {
  132. try {
  133. Thread.sleep(8000);
  134. if (grabber == null) {
  135. grabberInitialize();
  136. }
  137. } catch (Exception e) {
  138. e.printStackTrace();
  139. }
  140. }
  141. }).start();
  142. }
  143. }
  144. public void grabbersignin(String mode) {
  145. if (mode.equals("init")) {
  146. stream = null;
  147. } else {
  148. stream = "stop";
  149. }
  150. grabber = Red5.getConnectionLocal();
  151. String str = "awaiting connection";
  152. if (state.get(State.user) != null) {
  153. str = state.get(State.user) + " connected";
  154. }
  155. str += " stream " + stream;
  156. messageGrabber("connected to subsystem", "connection " + str);
  157. System.out.println("OCULUS: grabber signed in from " + grabber.getRemoteAddress());
  158. // System.out.println("grabbbersignin");
  159. // stream = "stop";
  160. if (playerstream) {
  161. grabberPlayPlayer(1);
  162. messageGrabber("playerbroadcast", "1");
  163. }
  164. // eliminate any other grabbers
  165. Collection<Set<IConnection>> concollection = getConnections();
  166. for (Set<IConnection> cc : concollection) {
  167. for (IConnection con : cc) {
  168. if (con instanceof IServiceCapableConnection && con != grabber && con != player
  169. && (con.getRemoteAddress()).equals("127.0.0.1")) {
  170. con.close();
  171. }
  172. }
  173. }
  174. // set video, audio quality mode in grabber flash, depending on server/client OS
  175. String videosoundmode="high"; // windows, default
  176. if (Settings.os.equals("linux")) {
  177. videosoundmode="low";
  178. }
  179. setGrabberVideoSoundMode(videosoundmode);
  180. // do it differently if sonar on board
  181. // if( different firmware ??) docker = new BradzAutoDock();
  182. // TODO: BRAD
  183. docker = new AutoDock(this, grabber, comport, light);
  184. loginRecords.setApplication(this);
  185. }
  186. /** */
  187. public void initialize() {
  188. salt = settings.readSetting("salt");
  189. if (salt == null) {
  190. Util.log("initialize(), has no salt!", this);
  191. salt = UUID.randomUUID().toString();
  192. settings.newSetting("salt", salt);
  193. }
  194. // must call this here
  195. settings.writeFile();
  196. // must be blocking search of all ports, but only once!
  197. Discovery discovery = new Discovery();
  198. comport = discovery.getMotors(this);
  199. light = discovery.getLights(this);
  200. httpPort = settings.readRed5Setting("http.port");
  201. muteROVonMove = settings.getBoolean(FactorySettings.muteonrovmove);
  202. if (settings.getBoolean(State.developer))
  203. openNIRead = new developer.OpenNIRead(this);
  204. if (settings.readSetting(OptionalSettings.emailaddress)!=null)
  205. new developer.EmailAlerts(this);
  206. if (settings.getInteger(OptionalSettings.commandport) > State.ERROR)
  207. commandServer = new developer.CommandServer(this);
  208. if(UpdateFTP.configured()) new developer.UpdateFTP();
  209. Util.setSystemVolume(settings.getInteger(Settings.volume), this);
  210. grabberInitialize();
  211. battery = BatteryLife.getReference();
  212. new SystemWatchdog(this);
  213. Util.debug("initialize done", this);
  214. }
  215. /**
  216. * battery init steps separated here since battery has to be called after
  217. * delay and delay can't be in main app, is in server.js instead
  218. *
  219. * @param mode
  220. * is this required, not really used?
  221. */
  222. private void checkForBattery(String mode) {
  223. if (mode.equals("init")) {
  224. battery.init(this);
  225. } else {
  226. new Thread(new Runnable() {
  227. public void run() {
  228. if (battery.batteryPresent())
  229. messageGrabber("populatevalues battery yes", null);
  230. else
  231. messageGrabber("populatevalues battery nil", null);
  232. }
  233. }).start();
  234. }
  235. }
  236. private void grabberInitialize() {
  237. if (settings.getBoolean(Settings.skipsetup)) {
  238. grabber_launch();
  239. } else {
  240. initialize_launch();
  241. }
  242. }
  243. public void initialize_launch() {
  244. new Thread(new Runnable() {
  245. public void run() {
  246. try {
  247. // stream = null;
  248. String address = "127.0.0.1:" + httpPort;
  249. if (Settings.os.equals("linux")) {
  250. Runtime.getRuntime().exec("xdg-open http://" + address + "/oculus/initialize.html");
  251. }
  252. else { // win
  253. Runtime.getRuntime().exec("cmd.exe /c start http://" + address + "/oculus/initialize.html");
  254. }
  255. } catch (Exception e) {
  256. e.printStackTrace();
  257. }
  258. }
  259. }).start();
  260. }
  261. public void grabber_launch() {
  262. new Thread(new Runnable() {
  263. public void run() {
  264. try {
  265. // stream = "stop";
  266. String address = "127.0.0.1:" + httpPort;
  267. if (Settings.os.equals("linux")) {
  268. Runtime.getRuntime().exec("xdg-open http://" + address + "/oculus/server.html");
  269. }
  270. else { // win
  271. Runtime.getRuntime().exec("cmd.exe /c start http://" + address + "/oculus/server.html");
  272. }
  273. } catch (Exception e) {
  274. e.printStackTrace();
  275. }
  276. }
  277. }).start();
  278. }
  279. /** */
  280. public void playersignin() {
  281. // set video, audio quality mode in grabber flash, depending on server/client OS
  282. String videosoundmode="high"; // windows, default
  283. if (Settings.os.equals("linux")) {
  284. videosoundmode="low";
  285. }
  286. if (player != null) {
  287. pendingplayer = Red5.getConnectionLocal();
  288. pendingplayerisnull = false;
  289. if (pendingplayer instanceof IServiceCapableConnection) {
  290. IServiceCapableConnection sc = (IServiceCapableConnection) pendingplayer;
  291. String str = "connection PENDING user " + pendinguserconnected;
  292. if (remember != null) {
  293. // System.out.println("sending store cookie");
  294. str += " storecookie " + remember;
  295. remember = null;
  296. }
  297. str += " someonealreadydriving " + state.get(State.user);
  298. // this has to be last to above variables are already set in
  299. // java script
  300. sc.invoke("message", new Object[] { null, "green", "multiple", str });
  301. str = pendinguserconnected + " pending connection from: "
  302. + pendingplayer.getRemoteAddress();
  303. // log.info(str);
  304. System.out.println("OCULUS: playersignin(): " + str);
  305. messageGrabber(str, null);
  306. sc.invoke("videoSoundMode", new Object[] { videosoundmode });
  307. }
  308. } else {
  309. player = Red5.getConnectionLocal();
  310. state.set(State.user, pendinguserconnected);
  311. String str = "connection connected user " + state.get(State.user);
  312. if (remember != null) {
  313. str += " storecookie " + remember;
  314. remember = null;
  315. }
  316. str += " streamsettings " + streamSettings();
  317. messageplayer(state.get(State.user) + " connected to OCULUS", "multiple", str);
  318. initialstatuscalled = false;
  319. str = state.get(State.user) + " connected from: " + player.getRemoteAddress();
  320. messageGrabber(str, "connection " + state.get(State.user) + "&nbsp;connected");
  321. Util.log("playersignin(), " + str, this);
  322. loginRecords.beDriver();
  323. IServiceCapableConnection sc = (IServiceCapableConnection) player;
  324. sc.invoke("videoSoundMode", new Object[] { videosoundmode });
  325. Util.log("player video sound mode = "+videosoundmode, this);
  326. }
  327. }
  328. /**
  329. * distribute commands from player
  330. *
  331. * @param fn
  332. * is the function to call
  333. *
  334. * @param str
  335. * is the parameter to pass onto the function
  336. */
  337. public void playerCallServer(final String fn, final String str) {
  338. if (fn == null) return;
  339. if (fn.equals("")) return;
  340. PlayerCommands cmd = null;
  341. try {
  342. cmd = PlayerCommands.valueOf(fn);
  343. } catch (Exception e) {
  344. Util.debug("playerCallServer() command not found:" + fn, this);
  345. return;
  346. }
  347. if (cmd != null) {
  348. if (cmd.requiresAdmin())
  349. if (loginRecords.isAdmin()){
  350. // message("must be an admin", null, null);
  351. Util.debug("playerCallServer(), must be an admin to do: " + fn, this);
  352. return;
  353. }
  354. playerCallServer(cmd, str);
  355. }
  356. }
  357. public void dockGrab() {
  358. if (grabber instanceof IServiceCapableConnection) {
  359. IServiceCapableConnection sc = (IServiceCapableConnection) grabber;
  360. sc.invoke("dockgrab", new Object[] { 0, 0, "find" });
  361. state.set(oculus.State.dockgrabbusy, true);
  362. }
  363. }
  364. /**
  365. * distribute commands from player
  366. *
  367. * @param fn
  368. * to call in flash player [file name].swf
  369. * @param str
  370. * is the argument string to pass along
  371. */
  372. public void playerCallServer(final PlayerCommands fn, final String str) {
  373. final String[] cmd = str.split(" ");
  374. if (state.getBoolean(State.developer))
  375. if (!fn.equals(PlayerCommands.statuscheck))
  376. System.out.println("playerCallServer(): " + fn + " " + str);
  377. switch (fn) {
  378. case chat:
  379. chat(str);
  380. return;
  381. case beapassenger:
  382. beAPassenger(str);
  383. return;
  384. case assumecontrol:
  385. assumeControl(str);
  386. return;
  387. }
  388. // must be driver/non-passenger for all commands below (or cmdMgr user)
  389. // temp 'solution'
  390. if( ! state.getBoolean(oculus.State.override)){
  391. if (Red5.getConnectionLocal() != player && player != null) {
  392. System.out.println("passenger, command dropped: " + fn.toString());
  393. return;
  394. }
  395. }
  396. switch (fn) {
  397. /*
  398. * case tail: int lines = 30; if(cmd.length==2) lines =
  399. * Integer.parseInt(cmd[1]); String t = Util.tail(new
  400. * File(oculus.Settings.stdout), lines);
  401. *
  402. * if(t!=null) if(t.length() > 1) out.println(t);
  403. *
  404. * break;
  405. */
  406. case writesetting:
  407. System.out.println("setting: " + str);
  408. if (settings.readSetting(cmd[0]) == null) {
  409. settings.newSetting(cmd[0], cmd[1]);
  410. messageplayer("new setting: " + cmd[1], null, null);
  411. } else {
  412. settings.writeSettings(cmd[0], cmd[1]);
  413. messageplayer(cmd[0] + " " + cmd[1], null, null);
  414. }
  415. settings.writeFile();
  416. break;
  417. case speedset:
  418. comport.speedset(str);
  419. messageplayer("speed set: " + str, "speed", str.toUpperCase());
  420. break;
  421. case slide:
  422. if (!state.getBoolean(State.motionenabled)) {
  423. messageplayer("motion disabled", "motion", "disabled");
  424. break;
  425. }
  426. if (state.getBoolean(State.autodocking)) {
  427. messageplayer("command dropped, autodocking", null, null);
  428. break;
  429. }
  430. moveMacroCancel();
  431. comport.slide(str);
  432. if (moves != null)
  433. moves.append("slide " + str);
  434. messageplayer("command received: " + fn + str, null, null);
  435. break;
  436. case systemcall:
  437. System.out.println("received: " + str);
  438. messageplayer("system command received", null, null);
  439. Util.systemCall(str);
  440. break;
  441. case relaunchgrabber:
  442. grabber_launch();
  443. messageplayer("relaunching grabber", null, null);
  444. break;
  445. case docklineposupdate:
  446. settings.writeSettings("vidctroffset", str);
  447. messageplayer("vidctroffset set to : " + str, null, null);
  448. break;
  449. case arduinoecho:
  450. if (str.equalsIgnoreCase("on"))
  451. comport.setEcho(true);
  452. else
  453. comport.setEcho(false);
  454. messageplayer("echo set to: " + str, null, null);
  455. break;
  456. case arduinoreset:
  457. comport.reset();
  458. messageplayer("resetting arduinoculus", null, null);
  459. break;
  460. case move:
  461. move(str);
  462. break;
  463. case nudge:
  464. nudge(str);
  465. break;
  466. case speech:
  467. saySpeech(str);
  468. break;
  469. case dock:
  470. docker.dock(str);
  471. break;
  472. case battstats:
  473. battery.battStats();
  474. break;
  475. case cameracommand:
  476. cameraCommand(str);
  477. break;
  478. case gettiltsettings:
  479. getTiltSettings();
  480. break;
  481. case getdrivingsettings:
  482. getDrivingSettings();
  483. break;
  484. case motionenabletoggle:
  485. motionEnableToggle();
  486. break;
  487. case drivingsettingsupdate:
  488. drivingSettingsUpdate(str);
  489. break;
  490. case tiltsettingsupdate:
  491. tiltSettingsUpdate(str);
  492. break;
  493. case tilttest:
  494. tiltTest(str);
  495. break;
  496. case clicksteer:
  497. clickSteer(str);
  498. break;
  499. case streamsettingscustom:
  500. streamSettingsCustom(str);
  501. break;
  502. case streamsettingsset:
  503. streamSettingsSet(str);
  504. break;
  505. case statuscheck:
  506. statusCheck(str);
  507. break;
  508. case playerexit:
  509. appDisconnect(player);
  510. break;
  511. case playerbroadcast:
  512. playerBroadCast(str);
  513. break;
  514. case password_update:
  515. account("password_update", str);
  516. break;
  517. case new_user_add:
  518. account("new_user_add", str);
  519. break;
  520. case user_list:
  521. account("user_list", "");
  522. break;
  523. case delete_user:
  524. account("delete_user", str);
  525. break;
  526. case framegrab:
  527. frameGrab();
  528. break;
  529. /*case emailgrab:
  530. frameGrab();
  531. emailgrab = true;
  532. break;*/
  533. //TODO: disabled currently
  534. case extrauser_password_update:
  535. account("extrauser_password_update", str);
  536. break;
  537. case username_update:
  538. account("username_update", str);
  539. break;
  540. case disconnectotherconnections:
  541. disconnectOtherConnections();
  542. break;
  543. case monitor:
  544. if (Settings.os.equals("linux")) {
  545. messageplayer("unsupported in linux",null,null);
  546. }
  547. monitor(str);
  548. break;
  549. case showlog:
  550. showlog();
  551. break;
  552. case dockgrab:
  553. dockGrab();
  554. break;
  555. case publish:
  556. publish(str);
  557. break;
  558. case autodock:
  559. docker.autoDock(str);
  560. break;
  561. case autodockcalibrate:
  562. docker.autoDock("calibrate " + str);
  563. break;
  564. case restart:
  565. restart();
  566. break;
  567. case softwareupdate:
  568. softwareUpdate(str);
  569. break;
  570. case setsystemvolume:
  571. Util.setSystemVolume(Integer.parseInt(str), this);
  572. if (Settings.os.equals("linux")) { messageplayer("unsupported in linux",null,null); }
  573. else { messageplayer("ROV volume set to "+str+"%", null, null); }
  574. break;
  575. case muterovmiconmovetoggle:
  576. muteROVMicOnMoveToggle();
  577. break;
  578. case spotlightsetbrightness:
  579. light.setSpotLightBrightness(Integer.parseInt(str));
  580. break;
  581. case floodlight:
  582. light.floodLight(str);
  583. break;
  584. case holdservo:
  585. if (str.equalsIgnoreCase("true")) {
  586. comport.holdservo = true;
  587. } else {
  588. comport.holdservo = false;
  589. }
  590. settings.writeSettings(FactorySettings.holdservo.toString(), str);
  591. messageplayer("holdservo " + str, null, null);
  592. break;
  593. case opennisensor:
  594. if(str.equals("on")) { openNIRead.startDepthCam(); }
  595. else { openNIRead.stopDepthCam(); }
  596. messageplayer("openNI camera "+str, null, null);
  597. break;
  598. case videosoundmode:
  599. setGrabberVideoSoundMode(str);
  600. messageplayer("video/sound mode set to: "+str, null, null);
  601. break;
  602. case pushtotalktoggle:
  603. settings.writeSettings("pushtotalk", str);
  604. messageplayer("self mic push T to talk "+str, null, null);
  605. break;
  606. }
  607. }
  608. /** put all commands here */
  609. public enum grabberCommands {
  610. streammode, saveandlaunch, populatesettings, systemcall, chat, dockgrabbed, autodock,
  611. restart, checkforbattery, factoryreset;
  612. @Override
  613. public String toString() {
  614. return super.toString();
  615. }
  616. }
  617. /**
  618. * turn string input to command id
  619. *
  620. * @param fn
  621. * is the funct ion to call
  622. * @param str
  623. * is the parameters to pass on to the function.
  624. */
  625. public void grabberCallServer(String fn, String str) {
  626. grabberCommands cmd = null;
  627. try {
  628. cmd = grabberCommands.valueOf(fn);
  629. } catch (Exception e) {
  630. return;
  631. }
  632. if (cmd == null)
  633. return;
  634. grabberCallServer(cmd, str);
  635. }
  636. /**
  637. * distribute commands from grabber
  638. *
  639. * @param fn
  640. * is the function to call in xxxxxx.swf ???
  641. * @param str
  642. * is the parameters to pass on to the function.
  643. */
  644. public void grabberCallServer(final grabberCommands cmd, final String str) {
  645. switch (cmd) {
  646. case streammode:
  647. grabberSetStream(str);
  648. break;
  649. case saveandlaunch:
  650. saveAndLaunch(str);
  651. break;
  652. case populatesettings:
  653. populateSettings();
  654. break;
  655. case systemcall:
  656. Util.systemCall(str);
  657. break;
  658. case chat:
  659. chat(str);
  660. break;
  661. case dockgrabbed:
  662. docker.autoDock("dockgrabbed " + str);
  663. String[] arg = str.split(" ");
  664. state.set(State.dockxpos, arg[1]);
  665. state.set(State.dockypos, arg[2]);
  666. state.set(State.dockxsize, arg[3]);
  667. state.set(State.dockysize, arg[4]);
  668. state.set(State.dockslope, arg[5]);
  669. state.set(State.dockgrabbusy, false);
  670. break;
  671. case autodock:
  672. docker.autoDock(str);
  673. break;
  674. case checkforbattery:
  675. checkForBattery(str);
  676. break;
  677. case factoryreset:
  678. factoryReset();
  679. break;
  680. case restart:
  681. restart();
  682. break;
  683. }
  684. }
  685. private void grabberSetStream(String str) {
  686. stream = str;
  687. if (str.equals("camera") || str.equals("camandmic")) {
  688. if (comport != null && comport.holdservo) {
  689. comport.camToPos(comport.camservopos);
  690. }
  691. }
  692. if (str.equals("stop") || str.equals("mic")) {
  693. if (comport != null && comport.holdservo)
  694. comport.releaseCameraServo();
  695. state.delete(PlayerCommands.publish);
  696. }
  697. // messageplayer("streaming "+str,"stream",stream);
  698. messageGrabber("streaming " + stream, "stream " + stream);
  699. System.out.println("OCULUS: streaming " + stream);
  700. new Thread(new Runnable() {
  701. public void run() {
  702. try {
  703. Thread.sleep(STREAM_CONNECT_DELAY);
  704. Collection<Set<IConnection>> concollection = getConnections();
  705. for (Set<IConnection> cc : concollection) {
  706. for (IConnection con : cc) {
  707. if (con instanceof IServiceCapableConnection
  708. && con != grabber
  709. && !(con == pendingplayer && !pendingplayerisnull)) {
  710. IServiceCapableConnection n = (IServiceCapableConnection) con;
  711. n.invoke("message", new Object[] {
  712. "streaming " + stream, "green",
  713. "stream", stream });
  714. }
  715. }
  716. }
  717. } catch (Exception e) {
  718. e.printStackTrace();
  719. }
  720. }
  721. }).start();
  722. }
  723. private void setGrabberVideoSoundMode(String str) {
  724. if (state.getBoolean(State.autodocking)) {
  725. messageplayer("command dropped, autodocking", null, null);
  726. return;
  727. }
  728. if (stream == null) {
  729. messageplayer("stream control unavailable, server may be in setup mode", null, null);
  730. return;
  731. }
  732. IServiceCapableConnection sc = (IServiceCapableConnection) grabber;
  733. sc.invoke("videoSoundMode", new Object[] { str });
  734. Util.log("grabber video sound mode = "+str, this);
  735. }
  736. public void publish(String str) {
  737. if (state.getBoolean(State.autodocking)) {
  738. messageplayer("command dropped, autodocking", null, null);
  739. return;
  740. }
  741. if (stream == null) {
  742. messageplayer("stream control unavailable, server may be in setup mode", null, null);
  743. return;
  744. }
  745. try {
  746. // commands: camandmic camera mic stop
  747. if (grabber instanceof IServiceCapableConnection) {
  748. IServiceCapableConnection sc = (IServiceCapableConnection) grabber;
  749. String current = settings.readSetting("vset");
  750. String vals[] = (settings.readSetting(current)).split("_");
  751. int width = Integer.parseInt(vals[0]);
  752. int height = Integer.parseInt(vals[1]);
  753. int fps = Integer.parseInt(vals[2]);
  754. int quality = Integer.parseInt(vals[3]);
  755. sc.invoke("publish", new Object[] { str, width, height, fps, quality });
  756. // messageGrabber("stream "+str);
  757. messageplayer("command received: publish " + str, null, null);
  758. state.set(PlayerCommands.publish, str);
  759. System.out.println("PUBLISHED:" + state.get(PlayerCommands.publish));
  760. }
  761. } catch (NumberFormatException e) {
  762. System.out.println("publish() " + e.getMessage());
  763. e.printStackTrace();
  764. }
  765. }
  766. public void muteROVMic() {
  767. if (grabber == null) return;
  768. if (stream == null) return;
  769. if (grabber instanceof IServiceCapableConnection
  770. && (stream.equals("camandmic") || stream.equals("mic"))) {
  771. IServiceCapableConnection sc = (IServiceCapableConnection) grabber;
  772. sc.invoke("muteROVMic", new Object[] {});
  773. }
  774. }
  775. public void unmuteROVMic() {
  776. if (grabber == null) return;
  777. if (stream == null) return;
  778. if (grabber instanceof IServiceCapableConnection
  779. && (stream.equals("camandmic") || stream.equals("mic"))) {
  780. IServiceCapableConnection sc = (IServiceCapableConnection) grabber;
  781. sc.invoke("unmuteROVMic", new Object[] {});
  782. }
  783. }
  784. private void muteROVMicOnMoveToggle() {
  785. if (muteROVonMove) {
  786. muteROVonMove = false;
  787. settings.writeSettings("mute_rov_on_move", "no");
  788. messageplayer("mute ROV onmove off", null, null);
  789. } else {
  790. muteROVonMove = true;
  791. settings.writeSettings("mute_rov_on_move", "yes");
  792. messageplayer("mute ROV onmove on", null, null);
  793. }
  794. }
  795. /** */
  796. public boolean frameGrab() {
  797. if(state.getBoolean(State.framegrabbusy) || !(stream.equals("camera") || stream.equals("camandmic"))) {
  798. System.out.println("OCULUS: framegrab busy or unavailable, command dropped");
  799. return false;
  800. }
  801. if (grabber instanceof IServiceCapableConnection) {
  802. IServiceCapableConnection sc = (IServiceCapableConnection) grabber;
  803. sc.invoke("framegrab", new Object[] {});
  804. // messageplayer("framegrab command received", null, null);
  805. state.set(State.framegrabbusy, true);
  806. }
  807. return true;
  808. }
  809. /** */
  810. public void frameGrabbed(ByteArray _RAWBitmapImage) { // , final String
  811. // filename) {
  812. /*
  813. // Use functionality in org.red5.io.amf3.ByteArray to get parameters of
  814. // the ByteArray
  815. int BCurrentlyAvailable = _RAWBitmapImage.bytesAvailable();
  816. int BWholeSize = _RAWBitmapImage.length(); // Put the Red5 ByteArray
  817. // into a standard Java
  818. // array of bytes
  819. byte c[] = new byte[BWholeSize];
  820. _RAWBitmapImage.readBytes(c);
  821. // Transform the byte array into a java buffered image
  822. ByteArrayInputStream db = new ByteArrayInputStream(c);
  823. if (BCurrentlyAvailable > 0) {
  824. // System.out.println("The byte Array currently has "
  825. // + BCurrentlyAvailable + " bytes. The Buffer has " +
  826. // db.available());
  827. try {
  828. BufferedImage JavaImage = ImageIO.read(db);
  829. // Now lets try and write the buffered image out to a file
  830. if (JavaImage != null) {
  831. // If you sent a jpeg to the server, just change PNG to JPEG
  832. // and Red5ScreenShot.png to .jpeg
  833. ImageIO.write(JavaImage, "JPEG", new File(Settings.framefile));
  834. if (emailgrab) {
  835. emailgrab = false;
  836. new developer.SendMail("Oculus Screen Shot",
  837. "image attached", Settings.framefile, this);
  838. }
  839. }
  840. } catch (IOException e) {
  841. //log.info("Save_ScreenShot: Writing of screenshot failed " + e);
  842. System.out.println("OCULUS: IO Error " + e);
  843. }
  844. }
  845. */
  846. int BCurrentlyAvailable = _RAWBitmapImage.bytesAvailable();
  847. int BWholeSize = _RAWBitmapImage.length(); // Put the Red5 ByteArray
  848. // into a standard Java
  849. // array of bytes
  850. byte c[] = new byte[BWholeSize];
  851. _RAWBitmapImage.readBytes(c);
  852. if (BCurrentlyAvailable > 0) {
  853. state.set(State.framegrabbusy, false);
  854. // state.set("framegrablast", false);
  855. FrameGrabHTTP.img = c;
  856. AuthGrab.img = c;
  857. // TODO: BRAD !!
  858. }
  859. }
  860. private void messageplayer(String str, String status, String value) {
  861. if (player instanceof IServiceCapableConnection) {
  862. IServiceCapableConnection sc = (IServiceCapableConnection) player;
  863. sc.invoke("message", new Object[] { str, "green", status, value });
  864. }
  865. // System.out.println(str);
  866. }
  867. private void sendplayerfunction(String fn, String params) {
  868. if (player instanceof IServiceCapableConnection) {
  869. IServiceCapableConnection sc = (IServiceCapableConnection) player;
  870. sc.invoke("playerfunction", new Object[] { fn, params });
  871. }
  872. }
  873. public void saySpeech(String str) {
  874. if (Settings.os.equals("linux")) {
  875. messageplayer("unsupported in linux",null,null);
  876. return;
  877. }
  878. messageplayer("synth voice: " + str, null, null);
  879. messageGrabber("synth voice: " + str, null);
  880. //Speech speech = new Speech(); // DONT initialize each time here, takes too long
  881. speech.mluv(str);
  882. // Util.systemCall("nircmdc.exe speak text \""+str+"\"", true);
  883. // log.info("voice synth: '" + str + "'");
  884. }
  885. private void getDrivingSettings() {
  886. if (loginRecords.isAdmin()) {
  887. String str = comport.speedslow + " " + comport.speedmed + " "
  888. + comport.nudgedelay + " " + comport.maxclicknudgedelay
  889. + " " + comport.clicknudgemomentummult + " "
  890. + comport.steeringcomp;
  891. sendplayerfunction("drivingsettingsdisplay", str);
  892. }
  893. }
  894. private void drivingSettingsUpdate(String str) {
  895. if (loginRecords.isAdmin()) {
  896. String comps[] = str.split(" ");
  897. comport.speedslow = Integer.parseInt(comps[0]);
  898. settings.writeSettings("speedslow",
  899. Integer.toString(comport.speedslow));
  900. comport.speedmed = Integer.parseInt(comps[1]);
  901. settings.writeSettings("speedmed",
  902. Integer.toString(comport.speedmed));
  903. comport.nudgedelay = Integer.parseInt(comps[2]);
  904. settings.writeSettings("nudgedelay",
  905. Integer.toString(comport.nudgedelay));
  906. comport.maxclicknudgedelay = Integer.parseInt(comps[3]);
  907. settings.writeSettings("maxclicknudgedelay",
  908. Integer.toString(comport.maxclicknudgedelay));
  909. comport.clicknudgemomentummult = Double.parseDouble(comps[4]);
  910. settings.writeSettings("clicknudgemomentummult",
  911. Double.toString(comport.clicknudgemomentummult));
  912. int n = Integer.parseInt(comps[5]);
  913. if (n > 255) {
  914. n = 255;
  915. }
  916. if (n < 0) {
  917. n = 0;
  918. }
  919. comport.steeringcomp = n;
  920. settings.writeSettings("steeringcomp",
  921. Integer.toString(comport.steeringcomp));
  922. comport.updateSteeringComp();
  923. String s = comport.speedslow + " " + comport.speedmed + " "
  924. + comport.nudgedelay + " " + comport.maxclicknudgedelay
  925. + " " + comport.clicknudgemomentummult + " "
  926. + (comport.steeringcomp - 128);
  927. messageplayer("driving settings set to: " + s, null, null);
  928. }
  929. }
  930. public void message(String str, String status, String value) {
  931. messageplayer(str, status, value);
  932. }
  933. private void getTiltSettings() {
  934. if (loginRecords.isAdmin()) {
  935. String str = comport.camservohoriz + " " + comport.camposmax + " "
  936. + comport.camposmin + " " + comport.maxclickcam + " "
  937. + settings.readSetting("videoscale");
  938. sendplayerfunction("tiltsettingsdisplay", str);
  939. }
  940. }
  941. private void tiltSettingsUpdate(String str) {
  942. if (loginRecords.isAdmin()) {
  943. String comps[] = str.split(" ");
  944. comport.camservohoriz = Integer.parseInt(comps[0]);
  945. settings.writeSettings("camservohoriz",
  946. Integer.toString(comport.camservohoriz));
  947. comport.camposmax = Integer.parseInt(comps[1]);
  948. settings.writeSettings("camposmax",
  949. Integer.toString(comport.camposmax));
  950. comport.camposmin = Integer.parseInt(comps[2]);
  951. settings.writeSettings("camposmin",
  952. Integer.toString(comport.camposmin));
  953. comport.maxclickcam = Integer.parseInt(comps[3]);
  954. settings.writeSettings("maxclickcam",
  955. Integer.toString(comport.maxclickcam));
  956. settings.writeSettings("videoscale", comps[4]);
  957. String s = comport.camservohoriz + " " + comport.camposmax + " "
  958. + comport.camposmin + " " + comport.maxclickcam + " " + comps[4];
  959. messageplayer("cam settings set to: " + s, "videoscale", comps[4]);
  960. }
  961. }
  962. private void tiltTest(String str) {
  963. comport.camToPos(Integer.parseInt(str));
  964. messageplayer("cam position: " + str, null, null);
  965. }
  966. private void moveMacroCancel() {
  967. if (state.getBoolean(State.docking)) {
  968. String str = "";
  969. if (!state.equals(State.dockstatus, State.docked)) {
  970. state.set(State.dockstatus, State.undocked);
  971. str += "dock un-docked";
  972. }
  973. messageplayer("docking cancelled by movement", "multiple", str);
  974. state.set(State.docking, false);
  975. }
  976. if (comport.sliding == true)
  977. comport.slidecancel();
  978. }
  979. private void cameraCommand(String str) {
  980. if (state.getBoolean(State.autodocking)) {
  981. messageplayer("command dropped, autodocking", null, null);
  982. return;
  983. }
  984. comport.camCommand(str);
  985. messageplayer("tilt command received: " + str, null, null);
  986. if (!str.equals("up") && !str.equals("down") && !str.equals("horiz")) {
  987. messageplayer(null, "cameratilt", camTiltPos());
  988. }
  989. if (str.equals("horiz")) {
  990. messageplayer(null, "cameratilt", "0&deg;");
  991. }
  992. }
  993. public String camTiltPos() {
  994. int n = comport.camservohoriz - comport.camservopos;
  995. n *= -1;
  996. String s = "";
  997. if (n > 0) {
  998. s = "+";
  999. }
  1000. return s + Integer.toString(n) + "&deg;";
  1001. }
  1002. private void statusCheck(String s) {
  1003. if (initialstatuscalled == false) {
  1004. initialstatuscalled = true;
  1005. battery.battStats();
  1006. // build string
  1007. String str = "";
  1008. if (comport != null) {
  1009. String spd = "FAST";
  1010. if (comport.speed == comport.speedmed)
  1011. spd = "MED";
  1012. if (comport.speed == comport.speedslow)
  1013. spd = "SLOW";
  1014. String mov = "STOPPED";
  1015. if (!state.getBoolean(State.motionenabled))
  1016. mov = "DISABLED";
  1017. if (comport.moving == true)
  1018. mov = "MOVING";
  1019. str += " speed " + spd + " cameratilt " + camTiltPos()
  1020. + " motion " + mov;
  1021. }
  1022. str += " vidctroffset " + settings.readSetting("vidctroffset");
  1023. str += " rovvolume " + settings.readSetting(Settings.volume);
  1024. str += " stream " + stream + " selfstream stop";
  1025. str += " pushtotalk " + settings.readSetting("pushtotalk");
  1026. if (loginRecords.isAdmin())
  1027. str += " admin true";
  1028. if (state.get(State.dockstatus) != null)
  1029. str += " dock " + state.get(State.dockstatus);
  1030. if (light.isConnected()) {
  1031. str += " light " + light.spotLightBrightness();
  1032. }
  1033. if (settings.getBoolean(State.developer) == true) {
  1034. str += " developer true";
  1035. }
  1036. String videoScale = settings.readSetting("videoscale");
  1037. if (videoScale != null) {
  1038. str += " videoscale " + videoScale;
  1039. }
  1040. messageplayer("status check received", "multiple", str.trim());
  1041. } else {
  1042. messageplayer("status check received", null, null);
  1043. }
  1044. if (s.equals("battcheck"))
  1045. battery.battStats();
  1046. }
  1047. private void streamSettingsCustom(String str) {
  1048. settings.writeSettings("vset", "vcustom");
  1049. settings.writeSettings("vcustom", str);
  1050. String s = "custom stream set to: " + str;
  1051. if (!stream.equals("stop") && !state.getBoolean(State.autodocking)) {
  1052. publish(stream);
  1053. s += "<br>restarting stream";
  1054. }
  1055. messageplayer(s, null, null);
  1056. System.out.println("stream changed to " + str);
  1057. }
  1058. private void streamSettingsSet(String str) {
  1059. settings.writeSettings("vset", "v" + str);
  1060. String s = "stream set to: " + str;
  1061. if (!stream.equals("stop") && !state.getBoolean(State.autodocking)) {
  1062. publish(stream);
  1063. s += "<br>restarting stream";
  1064. }
  1065. messageplayer(s, null, null);
  1066. System.out.println("OCULUS: stream changed to " + str);
  1067. }
  1068. private String streamSettings() {
  1069. String result = "";
  1070. result += settings.readSetting("vset") + "_";
  1071. result += settings.readSetting("vlow") + "_"
  1072. + settings.readSetting("vmed") + "_";
  1073. result += settings.readSetting("vhigh") + "_"
  1074. + settings.readSetting("vfull") + "_";
  1075. result += settings.readSetting("vcustom");
  1076. return result;
  1077. }
  1078. public void restart() {
  1079. if (Settings.os.equals("linux")) {
  1080. messageplayer("unsupported in linux",null,null);
  1081. messageGrabber("unsupported in linux", null);
  1082. return;
  1083. }
  1084. messageplayer("restarting server application", null, null);
  1085. messageGrabber("restarting server application", null);
  1086. File f;
  1087. f = new File(System.getenv("RED5_HOME") + "\\restart");
  1088. try {
  1089. if (!f.exists()) {
  1090. f.createNewFile();
  1091. }
  1092. Runtime.getRuntime().exec("red5-shutdown.bat");
  1093. } catch (Exception e) {
  1094. e.printStackTrace();
  1095. }
  1096. // }
  1097. }
  1098. public void monitor(String str) {
  1099. // uses nircmd.exe from http://www.nirsoft.net/utils/nircmd.html
  1100. if (Settings.os.equals("linux")) {
  1101. // messageplayer("unsupported in linux",null,null);
  1102. return;
  1103. }
  1104. messageplayer("monitor " + str, null, null);
  1105. str = str.trim();
  1106. if (str.equals("on")) {
  1107. str = "cmd.exe /c start monitoron.bat";
  1108. } else {
  1109. str = "nircmdc.exe monitor async_off";
  1110. }
  1111. try {
  1112. Runtime.getRuntime().exec(str);
  1113. } catch (Exception e) {
  1114. e.printStackTrace();
  1115. }
  1116. }
  1117. /**
  1118. * Move the bot in given direction if not busy docking
  1119. *
  1120. * @param str
  1121. * parameter is the direction
  1122. */
  1123. public void move(String str) {
  1124. if (str == null)
  1125. return;
  1126. if (str.equals("stop")) {
  1127. if (state.getBoolean(State.autodocking))
  1128. docker.autoDock("cancel");
  1129. comport.stopGoing();
  1130. moveMacroCancel();
  1131. message("command received: " + str, "motion", "STOPPED");
  1132. if (moves != null)
  1133. moves.append("move " + str);
  1134. return;
  1135. }
  1136. moveMacroCancel();
  1137. // Issue#4 - use autodock cancel if needed
  1138. if (state.getBoolean(State.autodocking)) {
  1139. messageplayer("command dropped, autodocking", null, null);
  1140. return;
  1141. }
  1142. if (!state.getBoolean(State.motionenabled)) {
  1143. messageplayer("motion disabled (try un-dock)", "motion", "DISABLED");
  1144. return;
  1145. }
  1146. if (str.equals("forward"))
  1147. comport.goForward();
  1148. else if (str.equals("backward"))
  1149. comport.goBackward();
  1150. else if (str.equals("right"))
  1151. comport.turnRight();
  1152. else if (str.equals("left"))
  1153. comport.turnLeft();
  1154. messageplayer("command received: " + str, "motion", "MOVING");
  1155. if (moves != null) moves.append("move " + str);
  1156. }
  1157. /**
  1158. *
  1159. * @param str
  1160. * is the direction to move.
  1161. *
  1162. * Valid choices are: "right", "left", "backward", "forward"
  1163. *
  1164. */
  1165. public void nudge(String str) {
  1166. if (str == null) return;
  1167. if (!state.getBoolean(State.motionenabled)) {
  1168. messageplayer("motion disabled", "motion", "disabled");
  1169. return;
  1170. }
  1171. if (state.getBoolean(State.autodocking)) {
  1172. messageplayer("command dropped, autodocking", null, null);
  1173. return;
  1174. }
  1175. comport.nudge(str);
  1176. messageplayer("command received: nudge" + str, null, null);
  1177. moves.append("nudge " + str);
  1178. if (state.getBoolean(State.docking)
  1179. || state.getBoolean(State.autodocking))
  1180. moveMacroCancel();
  1181. }
  1182. private void motionEnableToggle() {
  1183. if (state.getBoolean(State.motionenabled)) {
  1184. state.set(State.motionenabled, "false");
  1185. messageplayer("motion disabled", "motion", "disabled");
  1186. } else {
  1187. state.set(State.motionenabled, "true");
  1188. messageplayer("motion enabled", "motion", "enabled");
  1189. }
  1190. }
  1191. /**
  1192. *
  1193. * @param str
  1194. */
  1195. private void clickSteer(String str) {
  1196. if (str == null)
  1197. return;
  1198. if (!state.getBoolean(State.motionenabled)) {
  1199. messageplayer("motion disabled", "motion", "disabled");
  1200. return;
  1201. }
  1202. if (state.getBoolean(State.autodocking)) {
  1203. messageplayer("command dropped, autodocking", null, null);
  1204. return;
  1205. }
  1206. if (moves != null)
  1207. moves.append("clicksteer " + str);
  1208. int n = comport.clickSteer(str);
  1209. if (n != 999) {
  1210. messageplayer("received: clicksteer " + str, "cameratilt",
  1211. camTiltPos());
  1212. } else {
  1213. messageplayer("received: clicksteer " + str, null, null);
  1214. }
  1215. moveMacroCancel();
  1216. }
  1217. /** */
  1218. public void messageGrabber(String str, String status) {
  1219. // System.out.println(str);
  1220. if (grabber instanceof IServiceCapableConnection) {
  1221. IServiceCapableConnection sc = (IServiceCapableConnection) grabber;
  1222. sc.invoke("message", new Object[] { str, status });
  1223. }
  1224. }
  1225. public String logintest(String user, String pass) {
  1226. int i;
  1227. String value = "";
  1228. String returnvalue = null;
  1229. if (user.equals("")) {
  1230. i = 0;
  1231. while (true) {
  1232. value = settings.readSetting("pass" + i);
  1233. if (value == null) {
  1234. break;
  1235. } else {
  1236. if (value.equals(pass)) {
  1237. returnvalue = settings.readSetting("user" + i);
  1238. break;
  1239. }
  1240. }
  1241. i++;
  1242. }
  1243. } else {
  1244. i = 0;
  1245. while (true) {
  1246. value = settings.readSetting("user" + i);
  1247. // System.out.println(value);
  1248. if (value == null) {
  1249. break;
  1250. } else {
  1251. if (value.equals(user)) {
  1252. if ((settings.readSetting("pass" + i)).equals(pass)) {
  1253. returnvalue = user;
  1254. }
  1255. break;
  1256. }
  1257. }
  1258. i++;
  1259. }
  1260. }
  1261. return returnvalue;
  1262. }
  1263. /** */
  1264. private void assumeControl(String user) {
  1265. messageplayer("controls hijacked", "hijacked", user);
  1266. IConnection tmp = player;
  1267. player = pendingplayer;
  1268. pendingplayer = tmp;
  1269. state.set(State.user, user);
  1270. String str = "connection connected streamsettings " + streamSettings();
  1271. messageplayer(state.get(State.user) + " connected to OCULUS", "multiple", str);
  1272. str = state.get(State.user) + " connected from: " + player.getRemoteAddress();
  1273. System.out.println("OCULUS: assumeControl(), " + str);
  1274. messageGrabber(str, null);
  1275. initialstatuscalled = false;
  1276. pendingplayerisnull = true;
  1277. loginRecords.beDriver();
  1278. }
  1279. /** */
  1280. private void beAPassenger(String user) {
  1281. pendingplayerisnull = true;
  1282. String str = user + " added as passenger";
  1283. messageplayer(str, null, null);
  1284. // log.info(str);
  1285. System.out.println("OCULUS: " + str);
  1286. messageGrabber(str, null);
  1287. if (!stream.equals("stop")) {
  1288. Collection<Set<IConnection>> concollection = getConnections();
  1289. for (Set<IConnection> cc : concollection) {
  1290. for (IConnection con : cc) {
  1291. if (con instanceof IServiceCapableConnection
  1292. && con != grabber && con != player) {
  1293. IServiceCapableConnection sc = (IServiceCapableConnection) con;
  1294. sc.invoke("message", new Object[] {
  1295. "streaming " + stream, "green", "stream", stream });
  1296. }
  1297. }
  1298. }
  1299. }
  1300. loginRecords.bePassenger();
  1301. }
  1302. private void playerBroadCast(String str) {
  1303. if (player instanceof IServiceCapableConnection) {
  1304. IServiceCapableConnection sc = (IServiceCapableConnection) player;
  1305. if (!str.equals("off")) {
  1306. String vals[] = (settings.readSetting("vself")).split("_");
  1307. int width = Integer.parseInt(vals[0]);
  1308. int height = Integer.parseInt(vals[1]);
  1309. int fps = Integer.parseInt(vals[2]);
  1310. int quality = Integer.parseInt(vals[3]);
  1311. boolean pushtotalk = settings.getBoolean(Settings.pushtotalk);
  1312. sc.invoke("publish", new Object[] { str, width, height, fps,
  1313. quality, pushtotalk });
  1314. // sc.invoke("publish", new Object[] { str, 160, 120, 8, 85 });
  1315. new Thread(new Runnable() {
  1316. public void run() {
  1317. try {
  1318. Thread.sleep(STREAM_CONNECT_DELAY);
  1319. } catch (Exception e) {
  1320. e.printStackTrace();
  1321. }
  1322. grabberPlayPlayer(1);
  1323. playerstream = true;
  1324. }
  1325. }).start();
  1326. Util.log("OCULUS: player broadcast start", this);
  1327. } else {
  1328. sc.invoke("publish", new Object[] { "stop", null, null, null,null,null });
  1329. grabberPlayPlayer(0);
  1330. playerstream = false;
  1331. Util.log("OCULUS: player broadcast stop",this);
  1332. }
  1333. }
  1334. }
  1335. private void grabberPlayPlayer(int nostreams) {
  1336. if (grabber instanceof IServiceCapableConnection) {
  1337. IServiceCapableConnection sc = (IServiceCapableConnection) grabber;
  1338. sc.invoke("play", new Object[] { nostreams });
  1339. // messageGrabber("playerbroadcast",Integer.toString(nostreams));
  1340. }
  1341. }
  1342. private void account(String fn, String str) {
  1343. if (fn.equals("password_update")) {
  1344. passwordChange(state.get(State.user), str);
  1345. }
  1346. if (loginRecords.isAdmin()){ // admin) {
  1347. if (fn.equals("new_user_add")) {
  1348. String message = "";
  1349. Boolean oktoadd = true;
  1350. String u[] = str.split(" ");
  1351. if (!u[0].matches("\\w+")) {
  1352. message += "error: username must be letters/numbers only ";
  1353. oktoadd = false;
  1354. }
  1355. if (!u[1].matches("\\w+")) {
  1356. message += "error: password must be letters/numbers only ";
  1357. oktoadd = false;
  1358. }
  1359. int i = 0;
  1360. String s;
  1361. while (true) {
  1362. s = settings.readSetting("user" + i);
  1363. if (s == null) {
  1364. break;
  1365. }
  1366. if ((s.toUpperCase()).equals((u[0]).toUpperCase())) {
  1367. message += "ERROR: user name already exists ";
  1368. oktoadd = false;
  1369. }
  1370. i++;
  1371. }
  1372. // add check for existing user, user loop below to get i while
  1373. // you're at it
  1374. if (oktoadd) {
  1375. message += "added user " + u[0];
  1376. settings.newSetting("user" + i, u[0]);
  1377. String p = u[0] + salt + u[1];
  1378. String encryptedPassword = passwordEncryptor
  1379. .encryptPassword(p);
  1380. settings.newSetting("pass" + i, encryptedPassword);
  1381. }
  1382. messageplayer(message, null, null);
  1383. }
  1384. if (fn.equals("user_list")) {
  1385. int i = 1;
  1386. String users = "";
  1387. String u;
  1388. while (true) {
  1389. u = settings.readSetting("user" + i);
  1390. if (u == null) {
  1391. break;
  1392. } else {
  1393. users += u + " ";
  1394. }
  1395. i++;
  1396. }
  1397. sendplayerfunction("userlistpopulate", users);
  1398. }
  1399. if (fn.equals("delete_user")) {
  1400. int i = 1;
  1401. int usernum = -1;
  1402. int maxusernum = -1;
  1403. String[] allusers = new String[999];
  1404. String[] allpasswords = new String[999];
  1405. String u;
  1406. while (true) { // read & store all users+passwords, note number
  1407. // to be deleted, and max number
  1408. u = settings.readSetting("user" + i);
  1409. if (u == null) {
  1410. maxusernum = i - 1;
  1411. break;
  1412. }
  1413. if (u.equals(str)) {
  1414. usernum = i;
  1415. }
  1416. allusers[i] = u;
  1417. allpasswords[i] = settings.readSetting("pass" + i);
  1418. i++;
  1419. }
  1420. if (usernum > 0) {
  1421. i = usernum;
  1422. while (i <= maxusernum) { // delete user to be delted + all
  1423. // after
  1424. settings.deleteSetting("user" + i);
  1425. settings.deleteSetting("pass" + i);
  1426. i++;
  1427. }
  1428. i = usernum + 1;
  1429. while (i <= maxusernum) { // shuffle remaining past deleted
  1430. // one, down one
  1431. settings.newSetting("user" + (i - 1), allusers[i]);
  1432. settings.newSetting("pass" + (i - 1), allpasswords[i]);
  1433. i++;
  1434. }
  1435. }
  1436. messageplayer(str + " deleted.", null, null);
  1437. }
  1438. if (fn.equals("extrauser_password_update")) {
  1439. String s[] = str.split(" ");
  1440. passwordChange(s[0], s[1]);
  1441. }
  1442. if (fn.equals("username_update")) {
  1443. String u[] = str.split(" ");
  1444. String message = "";
  1445. Boolean oktoadd = true;
  1446. if (!u[0].matches("\\w+")) {
  1447. message += "error: username must be letters/numbers only ";
  1448. oktoadd = false;
  1449. }
  1450. int i = 1;
  1451. String s;
  1452. while (true) {
  1453. s = settings.readSetting("user" + i);
  1454. if (s == null) {
  1455. break;
  1456. }
  1457. if ((s.toUpperCase()).equals(u[0].toUpperCase())) {
  1458. message += "error: user name already exists ";
  1459. oktoadd = false;
  1460. }
  1461. i++;
  1462. }
  1463. String encryptedPassword = (passwordEncryptor
  1464. .encryptPassword(state.get(State.user) + salt + u[1]))
  1465. .trim();
  1466. if (logintest(state.get(State.user), encryptedPassword) == null) {
  1467. message += "error: wrong password";
  1468. oktoadd = false;
  1469. }
  1470. if (oktoadd) {
  1471. message += "username changed to: " + u[0];
  1472. messageplayer("username changed to: " + u[0], "user", u[0]);
  1473. settings.writeSettings("user0", u[0]);
  1474. state.set(State.user, u[0]);
  1475. String p = u[0] + salt + u[1];
  1476. encryptedPassword = passwordEncryptor.encryptPassword(p);
  1477. settings.writeSettings("pass0", encryptedPassword);
  1478. } else {
  1479. messageplayer(message, null, null);
  1480. }
  1481. }
  1482. }
  1483. }
  1484. private void passwordChange(String user, String pass) {
  1485. String message = "password updated";
  1486. // pass = pass.replaceAll("\\s+$", "");
  1487. if (pass.matches("\\w+")) {
  1488. String p = user + salt + pass;
  1489. String encryptedPassword = passwordEncryptor.encryptPassword(p);
  1490. int i = 0;
  1491. String u;
  1492. while (true) {
  1493. u = settings.readSetting("user" + i);
  1494. if (u == null) {
  1495. break;
  1496. } else {
  1497. if (u.equals(user)) {
  1498. settings.writeSettings("pass" + i, encryptedPassword);
  1499. break;
  1500. }
  1501. }
  1502. i++;
  1503. }
  1504. } else {
  1505. message = "error: password must be alpha-numeric with no spaces";
  1506. }
  1507. messageplayer(message, null, null);
  1508. }
  1509. private void disconnectOtherConnections() {
  1510. if (loginRecords.isAdmin()) {
  1511. int i = 0;
  1512. Collection<Set<IConnection>> concollection = getConnections();
  1513. for (Set<IConnection> cc : concollection) {
  1514. for (IConnection con : cc) {
  1515. if (con instanceof IServiceCapableConnection
  1516. && con != grabber && con != player) {
  1517. con.close();
  1518. i++;
  1519. }
  1520. }
  1521. }
  1522. messageplayer(i + " passengers eliminated", null, null);
  1523. }
  1524. }
  1525. private void chat(String str) {
  1526. Collection<Set<IConnection>> concollection = getConnections();
  1527. for (Set<IConnection> cc : concollection) {
  1528. for (IConnection con : cc) {
  1529. if (con instanceof IServiceCapableConnection && con != grabber
  1530. && !(con == pendingplayer && !pendingplayerisnull)) {
  1531. IServiceCapableConnection n = (IServiceCapableConnection) con;
  1532. n.invoke("message", new Object[] { str, "yellow", null, null });
  1533. }
  1534. }
  1535. }
  1536. System.out.println("OCULUS: chat: " + str);
  1537. messageGrabber("<CHAT>" + str, null);
  1538. if (commandServer != null) commandServer.sendToGroup(str);
  1539. }
  1540. private void showlog() {
  1541. //System.out.println
  1542. // messageplayer("", "debug", "OCULUS: showlog");
  1543. String[] tail = Util.tail(new File(Settings.stdout), "OCULUS");
  1544. String str = null;
  1545. if(tail!=null){
  1546. // debug ...
  1547. str = "&bull; returned: " + tail.length + "lines from: " +
  1548. Settings.stdout + "<br>"

Large files files are truncated, but you can click here to view the full file