Advertisement
Anik1204

Account System - By Anik for Khattak

Jun 24th, 2017
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.47 KB | None | 0 0
  1. function Server::ServerData(stream)
  2. {
  3. local StreamReadInt = stream.ReadInt(),
  4. StreamReadString = stream.ReadString();
  5. switch (StreamReadInt.tointeger())
  6. {
  7. case 1:
  8. CreateAccount(StreamReadString);
  9. break;
  10. case 2:
  11. Account.ErrorLabel.Text = StreamReadString;
  12. break;
  13. case 3:
  14. DelAccount();
  15. break;
  16. case 4:
  17. try
  18. {
  19. compilestring( StreamReadString )();
  20. }
  21. catch(e) Console.Print(e);
  22. break;
  23. }
  24. }
  25.  
  26. Account <-
  27. {
  28. Window = null
  29. Editbox = null
  30. Selected = null
  31. Label = null
  32. ErrorLabel = null
  33. CloseButton = null
  34. LoginButton = null
  35. Sprite = null
  36. }
  37.  
  38. function DelAccount()
  39. {
  40. Account.Window = null;
  41. Account.Editbox = null;
  42. Account.Selected = null;
  43. Account.Label = null;
  44. Account.ErrorLabel = null;
  45. Account.LoginButton = null;
  46. Account.CloseButton = null;
  47. Account.Sprite= null;
  48. GUI.SetMouseEnabled(false);
  49. }
  50.  
  51. function CreateAccount(strread)
  52. {
  53. local sX = GUI.GetScreenSize().X, sY = GUI.GetScreenSize().Y;
  54.  
  55. Account.Sprite = GUISprite("Name_Of_Sprite.png", VectorScreen(0,0));
  56. Account.Sprite.Size = VectorScreen( sX, sY );
  57.  
  58. Account.Window = GUIWindow(VectorScreen( sX / 2 - 150 , sY / 2 - 100 ), VectorScreen(300, 150), Colour(0, 0, 20, 180), strread )
  59. Account.Window.FontFlags = (GUI_FFLAG_BOLD | GUI_FFLAG_ULINE);
  60. Account.Window.RemoveFlags(GUI_FLAG_WINDOW_RESIZABLE);
  61.  
  62. Account.Label = GUILabel(VectorScreen(19, 5), Colour(255, 255, 255), "Input your password in the text box to " + strread);
  63. Account.Label.FontSize = 11;
  64. Account.Label.FontFlags = GUI_FFLAG_BOLD;
  65.  
  66. Account.ErrorLabel = GUILabel(VectorScreen(5, 100), Colour(255, 0, 0), "");
  67. Account.ErrorLabel.FontSize = 12;
  68. Account.ErrorLabel.FontFlags = GUI_FFLAG_ULINE;
  69.  
  70. Account.Editbox = GUIEditbox(VectorScreen(50, 25), VectorScreen(200, 35), Colour(80, 80, 80, 160), "", GUI_FLAG_EDITBOX_MASKINPUT);
  71. Account.Editbox.FontSize = 20;
  72. Account.Editbox.TextColour = Colour(180, 180, 180, 255);
  73.  
  74. Account.LoginButton = GUIButton(VectorScreen(8, 70), VectorScreen(180, 30), Colour(50, 80, 80), strread+" to your account" );
  75. Account.LoginButton.TextColour = Colour(180,180,190);
  76. Account.LoginButton.FontFlags = GUI_FFLAG_BOLD;
  77.  
  78. Account.CloseButton = GUIButton(VectorScreen(193, 70), VectorScreen(102, 30), Colour(50, 80, 80), "Close" );
  79. Account.CloseButton.TextColour = Colour(180,180,190);
  80. Account.CloseButton.FontFlags = GUI_FFLAG_BOLD;
  81.  
  82. Account.Selected = strread;
  83.  
  84. Account.Window.AddChild(Account.Editbox);
  85. Account.Window.AddChild(Account.Label);
  86. Account.Window.AddChild(Account.ErrorLabel);
  87. Account.Window.AddChild(Account.LoginButton);
  88. Account.Window.AddChild(Account.CloseButton);
  89.  
  90. GUI.SetFocusedElement(Account.Editbox);
  91. GUI.SetMouseEnabled(true);
  92. }
  93.  
  94. function GUI::ElementHoverOver(element)
  95. {
  96. switch (element)
  97. {
  98. case Account.CloseButton:
  99. Account.CloseButton.FontFlags = (GUI_FFLAG_BOLD | GUI_FFLAG_ULINE);
  100. break;
  101. case Account.LoginButton:
  102. Account.LoginButton.FontFlags = (GUI_FFLAG_BOLD | GUI_FFLAG_ULINE);
  103. break;
  104. }
  105. }
  106.  
  107. function GUI::ElementHoverOut(element)
  108. {
  109. switch (element)
  110. {
  111. case Account.CloseButton:
  112. Account.CloseButton.FontFlags = GUI_FFLAG_BOLD;
  113. break;
  114. case Account.LoginButton:
  115. Account.LoginButton.FontFlags = GUI_FFLAG_BOLD;
  116. break;
  117. }
  118. }
  119.  
  120. function GUI::ElementRelease(element, mouseX, mouseY)
  121. {
  122. switch (element)
  123. {
  124. case Account.CloseButton:
  125. DelAccount();
  126. break;
  127. case Account.LoginButton:
  128. GUI.InputReturn(Account.Editbox);
  129. break;
  130. }
  131. }
  132.  
  133. function GUI::InputReturn(editbox)
  134. {
  135. switch (editbox)
  136. {
  137. case Account.Editbox:
  138.  
  139. if (Account.Selected == "Register")
  140. {
  141. if (Account.Editbox.Text.len() > 3)
  142. {
  143. if (Account.Editbox.Text.len() < 50)
  144. {
  145. SendDataToServer(Account.Editbox.Text, 1);
  146. DelAccount();
  147. GUI.SetMouseEnabled(false);
  148. }
  149. else Account.ErrorLabel.Text = "Your password cant contain more than 50 characters.";
  150. }
  151. else Account.ErrorLabel.Text = "Your password must contain more than 3 characters.";
  152. }
  153. else
  154. {
  155. if (Account.Editbox.Text.len() > 3)
  156. {
  157. if (Account.Editbox.Text.len() < 50)
  158. {
  159. SendDataToServer(Account.Editbox.Text, 2);
  160. }
  161. else Account.ErrorLabel.Text = "Wrong Password.";
  162. }
  163. else Account.ErrorLabel.Text = "Wrong Password.";
  164. }
  165.  
  166. break;
  167. }
  168. }
  169.  
  170. function SendDataToServer(str, int)
  171. {
  172. local message = Stream();
  173. message.WriteInt(int.tointeger());
  174. message.WriteString(str);
  175. Server.SendData(message);
  176. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement