Advertisement
Guest User

Untitled

a guest
Dec 21st, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 29.22 KB | None | 0 0
  1. package javasrc;
  2.  
  3. import java.io.IOException;
  4. import java.rmi.ConnectException;
  5. import java.rmi.NotBoundException;
  6. import java.rmi.RemoteException;
  7. import java.rmi.registry.LocateRegistry;
  8. import java.rmi.server.UnicastRemoteObject;
  9. import java.util.HashMap;
  10. import java.util.Scanner;
  11.  
  12. public class RMIClient extends UnicastRemoteObject implements RMIInterfaceClient{
  13. private static Scanner sc = new Scanner(System.in);
  14. private static RMIInterfaceServer server;
  15. private static RMIClient c;
  16. private static String username = null;
  17. public static int portaDownload;
  18.  
  19. public RMIClient() throws RemoteException {
  20. super();
  21. }
  22.  
  23. //##### MENUS #####
  24. public static void inicio() throws IOException { //Dar clear da consola
  25. System.out.println("\n####### BEM VINDO #######\n\n" +
  26. "1- Registar\n" +
  27. "2- Login\n");
  28.  
  29. int x = sc.nextInt();
  30. sc.nextLine(); //clear buffer
  31.  
  32. if (x==1 || x==2) {
  33. System.out.print("\nUsername: ");
  34. String a = sc.nextLine();
  35. System.out.print("Password: ");
  36. String b = sc.nextLine();
  37.  
  38. if (containForbiddenChars(a) || containForbiddenChars(b)) {
  39. inicio();
  40. }
  41.  
  42. HashMap<String, String> hLogin;
  43. boolean bol = false;
  44. while (true) {
  45. try {
  46. server = (RMIInterfaceServer) LocateRegistry.getRegistry(7000).lookup("serverName");
  47. server.ping();
  48.  
  49. if (bol) {
  50. Thread.sleep(4000);
  51. }
  52. hLogin = server.login(x, a, b);
  53. break;
  54. } catch (NotBoundException | ConnectException e ) {
  55. bol = true;
  56. } catch (InterruptedException e) {
  57. e.printStackTrace();
  58. }
  59. }
  60.  
  61. if (hLogin.get("success").compareTo("true")==0) {
  62. username = a;
  63. server.addUser(a, c);
  64. String sN = server.searchForNotifications(a);
  65. if (sN != null) {
  66. System.out.println(sN);
  67. }
  68. menu();
  69. }
  70. else {
  71. System.out.println("Erro");
  72. }
  73. }
  74. }
  75.  
  76. private static void menu() throws IOException {
  77. int x = 1;
  78.  
  79. while (x!=0) {
  80. System.out.println("0- Exit\n" +
  81. "1- Procurar Artistas/Álbuns/Músicas\n" +
  82. "2- Consultar Detalhes\n" +
  83. "3- Escrever Critica\n" +
  84. "4- Transferir Música -> Servidor\n" +
  85. "5- Partilhar Música\n" +
  86. "6- Transferir Música <- Servidor\n" +
  87. "EXTRAS ADMISTRADOR:\n" +
  88. "7- Gerir Artistas Álbuns e Músicas\n" +
  89. "8- Dar Privilégios");
  90.  
  91. x = sc.nextInt();
  92. sc.nextLine(); //Clear buffer
  93.  
  94. if (x==1) {
  95. menuUm();
  96. }
  97. else if (x==2) {
  98. menuDois();
  99. }
  100. else if (x==4) {
  101. menuQuatro();
  102. }
  103. else if (x==3) {
  104. menuTres();
  105. }
  106. else if (x==7) {
  107. menuSete();
  108. }
  109. else if(x==6){
  110. menuSeis();
  111. }
  112. else if (x==8) {
  113. menuOito();
  114. }
  115. }
  116. }
  117.  
  118. private static void menuUm() throws IOException {
  119. System.out.println("Name: ");
  120. String name = sc.nextLine();
  121.  
  122. if (containForbiddenChars(name)) {
  123. return;
  124. }
  125.  
  126. HashMap<String, String> hSearch;
  127. boolean bol = false;
  128. while (true) {
  129. try {
  130. server = (RMIInterfaceServer) LocateRegistry.getRegistry(7000).lookup("serverName");
  131. server.ping();
  132.  
  133. if (bol) {
  134. Thread.sleep(4000);
  135. }
  136. hSearch = server.search(name);
  137. break;
  138. } catch (NotBoundException | ConnectException e) {
  139. bol = true;
  140. } catch (InterruptedException e) {
  141. e.printStackTrace();
  142. }
  143.  
  144. }
  145.  
  146. if (hSearch.get("success").compareTo("false")==0) {
  147. System.out.println("Not found!");
  148. return;
  149. }
  150.  
  151. int nrArtists = Integer.parseInt(hSearch.get("num_artists"));
  152. for (int i=0; i<nrArtists; i++) {
  153. String temp = "artist_" + i + "_name";
  154. System.out.println(hSearch.get(temp));
  155. }
  156.  
  157. int nrAlbums = Integer.parseInt(hSearch.get("num_albuns"));
  158. for (int i=0; i<nrAlbums; i++) {
  159. String temp = "album_" + i + "_name";
  160. System.out.println(hSearch.get(temp));
  161. }
  162.  
  163. int nrMusics = Integer.parseInt(hSearch.get("num_musics"));
  164. for (int i=0; i<nrMusics; i++) {
  165. String temp = "music_" + i + "_name";
  166. System.out.println(hSearch.get(temp));
  167. }
  168. }
  169.  
  170. private static void menuDois() throws IOException {
  171. System.out.println("\n1- Artista\n" +
  172. "2- Album\n" +
  173. "3- Musica\n");
  174.  
  175. int x = sc.nextInt();
  176. sc.nextLine();
  177.  
  178. System.out.println("Artist name: ");
  179. String artistName = sc.nextLine();
  180. if (containForbiddenChars(artistName)) {
  181. return;
  182. }
  183. //Artista
  184. if (x==1) {
  185. HashMap<String, String> hArtistDetails;
  186. boolean bol = false;
  187. while (true) {
  188. try {
  189. server = (RMIInterfaceServer) LocateRegistry.getRegistry(7000).lookup("serverName");
  190. server.ping();
  191.  
  192. if (bol) {
  193. Thread.sleep(4000);
  194. }
  195. hArtistDetails = server.artistDetails(artistName);
  196. break;
  197. } catch (NotBoundException | ConnectException e) {
  198. bol = true;
  199. } catch (InterruptedException e) {
  200. e.printStackTrace();
  201. }
  202. }
  203. if (hArtistDetails.get("success").compareTo("false")==0) {
  204. return;
  205. }
  206.  
  207. System.out.println("Artist: " + artistName);
  208. System.out.println("Description: " + hArtistDetails.get("desc"));
  209.  
  210. System.out.println("---Albuns---");
  211. int nrAlbums = Integer.parseInt(hArtistDetails.get("num_albuns"));
  212. if (nrAlbums == 0) {
  213. System.out.println("Sem albuns");
  214. }
  215. for (int i=0; i<nrAlbums; i++) {
  216. String temp = "alb_" + i + "_name";
  217. System.out.println(hArtistDetails.get(temp));
  218. }
  219.  
  220. System.out.println("---Musicas---");
  221. int nrMusics = Integer.parseInt(hArtistDetails.get("num_mus"));
  222. if (nrMusics == 0) {
  223. System.out.println("Sem musicas");
  224. }
  225. for (int i=0; i<nrMusics; i++) {
  226. String temp = "mus_" + i + "_name";
  227. System.out.println(hArtistDetails.get(temp));
  228. }
  229. }
  230. //Album
  231. else if (x==2) {
  232. System.out.println("Album name: ");
  233. String albumName = sc.nextLine();
  234. if (containForbiddenChars(albumName)) {
  235. return;
  236. }
  237.  
  238. HashMap<String, String> hAlbumDetails;
  239. boolean bol = false;
  240. while (true) {
  241. try {
  242. server = (RMIInterfaceServer) LocateRegistry.getRegistry(7000).lookup("serverName");
  243. server.ping();
  244.  
  245. if (bol) {
  246. Thread.sleep(4000);
  247. }
  248. hAlbumDetails = server.albumDetails(artistName, albumName);
  249. break;
  250. } catch (NotBoundException | ConnectException e) {
  251. bol = true;
  252. } catch (InterruptedException e) {
  253. e.printStackTrace();
  254. }
  255. }
  256.  
  257. if (hAlbumDetails.get("success").compareTo("false")==0) {
  258. return;
  259. }
  260.  
  261. System.out.println("Artist name: " + artistName);
  262. System.out.println("Album name: " + hAlbumDetails.get("album_name"));
  263. System.out.println("Description: " + hAlbumDetails.get("desc"));
  264. System.out.println("Rating: " + hAlbumDetails.get("avg"));
  265.  
  266. int nrCritics = Integer.parseInt(hAlbumDetails.get("num_crits"));
  267. System.out.println("---Criticas---");
  268. if (nrCritics == 0) {
  269. System.out.println("Sem criticas");
  270. }
  271. for (int i=0; i<nrCritics; i++) {
  272. System.out.println(hAlbumDetails.get("crit_" + i));
  273. }
  274.  
  275. System.out.println("---Musicas---");
  276. int nrMusics = Integer.parseInt(hAlbumDetails.get("num_mus"));
  277. if (nrMusics == 0 ) {
  278. System.out.println("Sem musicas");
  279. }
  280. if (nrMusics > 0) {
  281. for (int i=0; i<nrMusics; i++) {
  282. System.out.println(hAlbumDetails.get("num_mus" + i) + " Duração: " + hAlbumDetails.get("dur_" + i));
  283. }
  284. }
  285. }
  286. else {
  287. System.out.println("Erro");
  288. }
  289.  
  290. }
  291.  
  292. private static void menuTres() throws IOException {
  293. System.out.println("Album name: ");
  294. String albumName = sc.nextLine();
  295. if (containForbiddenChars(albumName)){
  296. return;
  297. }
  298.  
  299. System.out.println("Artist name: ");
  300. String artistName = sc.nextLine();
  301. if (containForbiddenChars(artistName)){
  302. return;
  303. }
  304.  
  305. System.out.println("Pontuação (1-5): ");
  306. int score = sc.nextInt();
  307. sc.nextLine(); //Clear buffer
  308. if (score<1 || score>5) {
  309. System.out.println("Pontuação 1-5");
  310. return;
  311. }
  312.  
  313. System.out.println("Critica (300chars max): ");
  314. String critic = sc.nextLine();
  315. if (containForbiddenChars(critic)){
  316. return;
  317. }
  318. if (critic.length()>300) {
  319. System.out.println("Max 300 chars");
  320. return;
  321. }
  322.  
  323. HashMap<String, String> hWriteCritic;
  324. boolean bol = false;
  325. while (true) {
  326. try {
  327. server = (RMIInterfaceServer) LocateRegistry.getRegistry(7000).lookup("serverName");
  328. server.ping();
  329.  
  330. if (bol) {
  331. Thread.sleep(4000);
  332. }
  333. hWriteCritic = server.writeCritic(username, artistName, albumName, score, critic);
  334. break;
  335. } catch (NotBoundException | ConnectException e) {
  336. bol = true;
  337. } catch (InterruptedException e) {
  338. e.printStackTrace();
  339. }
  340.  
  341. }
  342.  
  343. if (hWriteCritic.get("success").compareTo("true")==0) {
  344. System.out.println("Critica escrita com sucesso");
  345. server.showCritics(albumName,artistName);
  346. }
  347. else {
  348. System.out.println("Erro");
  349. }
  350. }
  351.  
  352. private static void menuQuatro() throws IOException {
  353. String nrServer = server.nrMulticastServer();
  354.  
  355. System.out.println("Nome do ficheiro: ");
  356. String nomeFile = sc.nextLine();
  357.  
  358. new ClienteSV(Integer.parseInt(nrServer),nomeFile);
  359. }
  360. private static void menuSeis() throws IOException {
  361. System.out.println("Song name: ");
  362. String songName = sc.nextLine();
  363.  
  364. server.downloadMusic(songName,Integer.toString(portaDownload));
  365. }
  366.  
  367. private static void menuSete() throws IOException {
  368. HashMap<String, String> hIsAdmin;
  369. boolean bol = false;
  370. while (true) {
  371. try {
  372. server = (RMIInterfaceServer) LocateRegistry.getRegistry(7000).lookup("serverName");
  373. server.ping();
  374.  
  375. if (bol) {
  376. Thread.sleep(4000);
  377. }
  378. hIsAdmin = server.isAdmin(username);
  379. break;
  380. } catch (NotBoundException | ConnectException e) {
  381. bol = true;
  382. } catch (InterruptedException e) {
  383. e.printStackTrace();
  384. }
  385. }
  386.  
  387. if (hIsAdmin.get("check_admin").compareTo("true")!=0) {
  388. System.out.println("Permissões insuficientes");
  389. return;
  390. }
  391.  
  392. System.out.println("\n1- Artista\n" +
  393. "2- Album\n" +
  394. "3- Musica\n");
  395. int x = sc.nextInt();
  396. sc.nextLine(); //Clear buffer
  397. if (x<1 || x>3) {
  398. System.out.println("Inválido");
  399. return;
  400. }
  401.  
  402. System.out.println("1- Add\n" +
  403. "2- Edit (not avaiable for music)\n" +
  404. "3- Remove\n");
  405. int y = sc.nextInt();
  406. sc.nextLine(); //Clear buffer
  407. if (y<1 || y>3) {
  408. System.out.println("Inválido");
  409. return;
  410. }
  411.  
  412. //ARTISTA
  413. if (x==1) {
  414. System.out.println("Artist name: ");
  415. String artistName = sc.nextLine();
  416. if (containForbiddenChars(artistName)) {
  417. return;
  418. }
  419. //ADD
  420. if (y==1) {
  421. System.out.println("Description: ");
  422. String desc = sc.nextLine();
  423. if (containForbiddenChars(desc)) {
  424. return;
  425.  
  426. }
  427.  
  428. HashMap<String, String> hAddArtist;
  429. bol = false;
  430. while (true) {
  431. try {
  432. server = (RMIInterfaceServer) LocateRegistry.getRegistry(7000).lookup("serverName");
  433. server.ping();
  434.  
  435. if (bol) {
  436. Thread.sleep(4000);
  437. }
  438. hAddArtist = server.addArtist(artistName, desc);
  439. break;
  440. } catch (NotBoundException | ConnectException e) {
  441. bol = true;
  442. } catch (InterruptedException e) {
  443. e.printStackTrace();
  444. }
  445.  
  446. }
  447. if (hAddArtist.get("success").compareTo("true")==0) {
  448. System.out.println("Artista adicionado com sucesso");
  449. return;
  450. }
  451. }
  452. //EDIT
  453. else if (y==2) {
  454. System.out.println("New name: ");
  455. String newName = sc.nextLine();
  456. System.out.println("New desc: ");
  457. String newDesc = sc.nextLine();
  458. if (containForbiddenChars(newName) || containForbiddenChars(newDesc)) {
  459. return;
  460. }
  461.  
  462. HashMap<String, String> hEditArtist;
  463. bol = false;
  464. while (true) {
  465. try {
  466. server = (RMIInterfaceServer) LocateRegistry.getRegistry(7000).lookup("serverName");
  467. server.ping();
  468.  
  469. if (bol) {
  470. Thread.sleep(4000);
  471. }
  472. hEditArtist = server.editArtist(artistName, newName, newDesc);
  473. break;
  474. } catch (NotBoundException | ConnectException e) {
  475. bol = true;
  476. } catch (InterruptedException e) {
  477. e.printStackTrace();
  478. }
  479. }
  480.  
  481. if (hEditArtist.get("success").compareTo("true")==0) {
  482. System.out.println("Artista editado com sucesso");
  483. return;
  484. }
  485. }
  486. //REMOVE
  487. else {
  488.  
  489. HashMap<String, String> hRemoveArtist;
  490. bol = false;
  491. while (true) {
  492. try {
  493. server = (RMIInterfaceServer) LocateRegistry.getRegistry(7000).lookup("serverName");
  494. server.ping();
  495.  
  496. if (bol) {
  497. Thread.sleep(4000);
  498. }
  499. hRemoveArtist = server.removeArtist(artistName);
  500. break;
  501. } catch (NotBoundException | ConnectException e) {
  502. bol = true;
  503. } catch (InterruptedException e) {
  504. e.printStackTrace();
  505. }
  506. }
  507.  
  508. if (hRemoveArtist.get("success").compareTo("true")==0) {
  509. System.out.println("Artista removido com sucesso");
  510. return;
  511. }
  512. }
  513. }
  514. //ALBUM
  515. else if (x==2) {
  516. System.out.println("Artist name: ");
  517. String artistName = sc.nextLine();
  518. System.out.println("Album name: ");
  519. String albumName = sc.nextLine();
  520. if (containForbiddenChars(artistName) || containForbiddenChars(albumName)) {
  521. return;
  522. }
  523.  
  524. if (y==1 || y==2) {
  525. System.out.println("Description: ");
  526. String desc = sc.nextLine();
  527. if (containForbiddenChars(desc)) {
  528. return;
  529. }
  530. //ADD
  531. if (y==1) {
  532. HashMap<String, String> hAddAlbum;
  533. bol = false;
  534. while (true) {
  535. try {
  536. server = (RMIInterfaceServer) LocateRegistry.getRegistry(7000).lookup("serverName");
  537. server.ping();
  538.  
  539. if (bol) {
  540. Thread.sleep(4000);
  541. }
  542. hAddAlbum = server.addAlbum(username, artistName, albumName, desc);
  543. break;
  544. } catch (NotBoundException | ConnectException e) {
  545. bol = true;
  546. } catch (InterruptedException e) {
  547. e.printStackTrace();
  548. }
  549. }
  550.  
  551. if (hAddAlbum.get("success").compareTo("true")==0) {
  552. System.out.println("Album adicionado com sucesso");
  553. return;
  554. }
  555. }
  556. //EDIT
  557. else {
  558. System.out.println("New name: ");
  559. String newName = sc.nextLine();
  560. if (containForbiddenChars(newName)) {
  561. return;
  562. }
  563.  
  564. HashMap<String, String> hEditAlbum;
  565. bol = false;
  566. while (true) {
  567. try {
  568. server = (RMIInterfaceServer) LocateRegistry.getRegistry(7000).lookup("serverName");
  569. server.ping();
  570.  
  571. if (bol) {
  572. Thread.sleep(4000);
  573. }
  574. hEditAlbum = server.editAlbum(username, artistName, albumName, newName, desc);
  575. break;
  576. } catch (NotBoundException | ConnectException e) {
  577. bol = true;
  578. } catch (InterruptedException e) {
  579. e.printStackTrace();
  580. }
  581.  
  582. }
  583. if (hEditAlbum.get("success").compareTo("true")==0) {
  584. System.out.println("Album editado com sucesso");
  585.  
  586. int nrEditores = Integer.parseInt(hEditAlbum.get("num_editors"));
  587. for (int i=0; i<nrEditores; i++) {
  588. String adminToBeNotified = hEditAlbum.get("editor_" + i);
  589. if (adminToBeNotified.compareTo(username)!=0) {
  590. bol = false;
  591. while (true) {
  592. try {
  593. server = (RMIInterfaceServer) LocateRegistry.getRegistry(7000).lookup("serverName");
  594. server.ping();
  595.  
  596. if (bol) {
  597. Thread.sleep(4000);
  598. }
  599. server.notifyUserPromotion(adminToBeNotified, "ALTERAÇÃO NO ALBUM " + albumName ,"edit_album");
  600. break;
  601. } catch (NotBoundException | ConnectException e) {
  602. bol = true;
  603. } catch (InterruptedException e) {
  604. e.printStackTrace();
  605. }
  606. }
  607. }
  608. }
  609. return;
  610. }
  611. }
  612. }
  613. //REMOVE
  614. else {
  615. HashMap<String, String> hRemoveAlbum;
  616. bol = false;
  617. while (true) {
  618. try {
  619. server = (RMIInterfaceServer) LocateRegistry.getRegistry(7000).lookup("serverName");
  620. server.ping();
  621.  
  622. if (bol) {
  623. Thread.sleep(4000);
  624. }
  625. hRemoveAlbum = server.removeAlbum(artistName, albumName);
  626. break;
  627. } catch (NotBoundException | ConnectException e) {
  628. bol = true;
  629. } catch (InterruptedException e) {
  630. e.printStackTrace();
  631. }
  632. }
  633.  
  634. if (hRemoveAlbum.get("success").compareTo("true")==0) {
  635. System.out.println("Album removido com sucesso");
  636. return;
  637. }
  638. }
  639. }
  640. //MUSICA
  641. else {
  642. if (y==2) {
  643. System.out.println("Erro!");
  644. return;
  645. }
  646.  
  647. System.out.println("Artist name: ");
  648. String artistName = sc.nextLine();
  649. System.out.println("Album name: ");
  650. String albumName = sc.nextLine();
  651. System.out.println("Music name: ");
  652. String musicName = sc.nextLine();
  653. if (containForbiddenChars(musicName) || containForbiddenChars(artistName) || containForbiddenChars(albumName)) {
  654. return;
  655. }
  656. //ADD
  657. if (y==1) {
  658. System.out.println("Duração: ");
  659. String duration = sc.nextLine();
  660. HashMap<String, String> hAddSong;
  661. bol = false;
  662. while (true) {
  663. try {
  664. server = (RMIInterfaceServer) LocateRegistry.getRegistry(7000).lookup("serverName");
  665. server.ping();
  666.  
  667. if (bol) {
  668. Thread.sleep(4000);
  669. }
  670. hAddSong = server.addSong(artistName, albumName, musicName, duration);
  671. break;
  672. } catch (NotBoundException | ConnectException e) {
  673. bol = true;
  674. } catch (InterruptedException e) {
  675. e.printStackTrace();
  676. }
  677. }
  678.  
  679. if (hAddSong.get("success").compareTo("true")==0) {
  680. System.out.println("Musica adicionado com sucesso");
  681. return;
  682. }
  683. }
  684. //REMOVE
  685. else if (y==3){
  686. HashMap<String, String> hRemoveSong;
  687. bol = false;
  688. while (true) {
  689. try {
  690. server = (RMIInterfaceServer) LocateRegistry.getRegistry(7000).lookup("serverName");
  691. server.ping();
  692.  
  693. if (bol) {
  694. Thread.sleep(4000);
  695. }
  696. hRemoveSong = server.removeSong(artistName, albumName, musicName);
  697. break;
  698. } catch (NotBoundException | ConnectException e) {
  699. bol = true;
  700. } catch (InterruptedException e) {
  701. e.printStackTrace();
  702. }
  703. }
  704. if (hRemoveSong.get("success").compareTo("true")==0) {
  705. System.out.println("Musica removida com sucesso");
  706. return;
  707. }
  708. }
  709. }
  710. System.out.println("Erro");
  711. }
  712.  
  713. private static void menuOito() throws IOException {
  714. HashMap<String, String> hIsAdmin;
  715. boolean bol = false;
  716. while (true) {
  717. try {
  718. server = (RMIInterfaceServer) LocateRegistry.getRegistry(7000).lookup("serverName");
  719. server.ping();
  720.  
  721. if (bol) {
  722. Thread.sleep(4000);
  723. }
  724. hIsAdmin = server.isAdmin(username);
  725. break;
  726. } catch (NotBoundException | ConnectException e) {
  727. bol = true;
  728. } catch (InterruptedException e) {
  729. e.printStackTrace();
  730. }
  731. }
  732. if (hIsAdmin.get("check_admin").compareTo("false")==0) {
  733. System.out.println("Permissões insuficientes");
  734. return;
  735. }
  736.  
  737. System.out.println("Username");
  738. String newAdmin = sc.nextLine();
  739. if (containForbiddenChars(newAdmin)) {
  740. return;
  741. }
  742.  
  743. HashMap<String, String> hMakeAdmin;
  744. bol = false;
  745. while (true) {
  746. try {
  747. server = (RMIInterfaceServer) LocateRegistry.getRegistry(7000).lookup("serverName");
  748. server.ping();
  749.  
  750. if (bol) {
  751. Thread.sleep(4000);
  752. }
  753. hMakeAdmin = server.makeAdmin(newAdmin);
  754. break;
  755. } catch (NotBoundException | ConnectException e) {
  756. bol = true;
  757. } catch (InterruptedException e) {
  758. e.printStackTrace();
  759. }
  760. }
  761. if (hMakeAdmin.get("success").compareTo("true")==0) {
  762. System.out.println("Admin promovido com sucesso");
  763. bol = false;
  764. while (true) {
  765. try {
  766. server = (RMIInterfaceServer) LocateRegistry.getRegistry(7000).lookup("serverName");
  767. server.ping();
  768.  
  769. if (bol) {
  770. Thread.sleep(4000);
  771. }
  772. server.notifyUserPromotion(newAdmin, "PARABÉNS FOI PROMOVIDO!","promocao");
  773. break;
  774. } catch (NotBoundException | ConnectException e) {
  775. bol = true;
  776. } catch (InterruptedException e) {
  777. e.printStackTrace();
  778. }
  779. }
  780. }
  781. else {
  782. System.out.println("Erro");
  783. }
  784. }
  785.  
  786. //##### OUTROS #####
  787. private static boolean containForbiddenChars(String s) {
  788. if (s.contains("|") || s.contains(";") || s.contains("\n") || s.isEmpty()) {
  789. System.out.println("\n Input not allowed");
  790. return true;
  791. }
  792. else {
  793. return false;
  794. }
  795. }
  796.  
  797. // ------------------
  798. public static void main(String args[]) throws IOException {
  799.  
  800. int min =6500;
  801. int max = 7000;
  802. portaDownload = (int) Math.floor(Math.random() * ((max - min) + 1) + min);
  803. new TCPServerC(portaDownload,"/Users/joaomendes/Desktop/SDProjeto/ficheiros_cliente/").start();
  804. connectToServer();
  805. }
  806.  
  807. public static void connectToServer() throws IOException {
  808. c = new RMIClient();
  809.  
  810. while (true) {
  811. inicio();
  812. }
  813. }
  814.  
  815. //METODOS REMOTOS
  816.  
  817. public void displayMessage(String message) throws RemoteException {
  818. System.out.println(message);
  819. }
  820.  
  821. // METODOS REMOTOS QUE SAO USADOS PARA WEB
  822. @Override
  823. public String printOk() throws RemoteException {
  824. return null;
  825. }
  826.  
  827. @Override
  828. public String getUsername() throws RemoteException {
  829. return null;
  830. }
  831. @Override
  832. public String getAlbum() throws RemoteException {
  833. return null;
  834. }
  835.  
  836. @Override
  837. public String getArtist() throws RemoteException {
  838. return null;
  839. }
  840.  
  841. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement