Advertisement
TrodelHD

Untitled

May 10th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.82 KB | None | 0 0
  1. package connection;
  2.  
  3. import java.io.IOException;
  4. import java.io.ObjectOutputStream;
  5.  
  6. import Converter.Converter;
  7. import DataSaveSystem.getAllNames;
  8. import DataSaveSystem.getFullProjekt;
  9. import Rights.Right;
  10. import UserData.UserDataBase;
  11.  
  12. public class InputListener {
  13.  
  14. public InputListener(byte[][] message, ObjectOutputStream output, Right rights, WaitingForMessage waitingForMessage) {
  15. if(rights!=null){
  16. try {
  17. String def = new String(message[0]);
  18. if(def.equals("get")){
  19. if(rights.canDownloadt()){
  20. /*
  21. * Alle Get Meldunden
  22. */
  23. String type = new String(message[1]);
  24. if(type.equals("allProjectNames")){
  25. sendMessageBack(getAllNames.getAllNamesInByte(), output);
  26. }else if(type.equals("fullProject")){
  27. String name = new String(message[2]);
  28. sendMessageBack(getFullProjekt.getFullProjekt(name), output);
  29. }
  30. }else{
  31. noPerrmission(output);
  32. }
  33. }
  34. } catch (Exception e) {
  35. // TODO: handle exception
  36. }
  37.  
  38. }else{
  39. //Keine Rechte
  40. try {
  41. String def = new String(message[0]);
  42. System.out.println(def);
  43. if(def.equals("login")){
  44. try {
  45. String Username = new String(message[1]);
  46. String Password = new String(message[2]);
  47. Right right = UserDataBase.getRightsFormUser(Username, Password);
  48. if(right!=null){
  49. waitingForMessage.rights=right;
  50. sendMessageBack(createSimpleMessage("loginResponse", "true", right.getName()), output);
  51. System.out.println("login true "+Username+" "+Password+" "+right.getName());
  52. }else{
  53. sendMessageBack(createSimpleMessage("loginResponse", "false"), output);
  54. System.out.println("login false "+Username+" "+Password);
  55. }
  56.  
  57. } catch (Exception e) {
  58.  
  59. }
  60. }else{
  61. sendMessageBack(createSimpleMessage("error", "noLogin"), output);
  62. }
  63.  
  64. } catch (Exception e) {}
  65.  
  66. }
  67.  
  68.  
  69.  
  70.  
  71. Converter conver = new Converter();
  72. conver.createFileformByteArray("TestDataSend.jpg", message[1]);
  73.  
  74. //if(message.get(0).equals("ChatMessage")){ChatMessage(message.get(1));}
  75. }
  76. private void noPerrmission(ObjectOutputStream output){
  77. sendMessageBack(createSimpleMessage("error", "noPermission"), output);
  78. }
  79. private byte[][] createSimpleMessage(String def,String message){
  80. byte[][] re = new byte[2][];
  81. re[0] = def.getBytes();
  82. re[1] = message.getBytes();
  83. return re;
  84. }
  85. private byte[][] createSimpleMessage(String def,String message,String message2){
  86. byte[][] re = new byte[3][];
  87. re[0] = def.getBytes();
  88. re[1] = message.getBytes();
  89. re[2] = message2.getBytes();
  90. return re;
  91. }
  92. private void sendMessageBack(byte[][] Message,ObjectOutputStream output){
  93. try {
  94. output.writeObject(Message);
  95. output.flush();
  96. } catch (IOException e) {
  97.  
  98. }
  99. }
  100.  
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement