Advertisement
Guest User

Untitled

a guest
Apr 17th, 2014
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.58 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class LoginMenu : MonoBehaviour
  5. {
  6. //url of the login script, wich is server side.
  7. string loginURL = "http://127.0.0.1/login.php";
  8. //creation of the strings we use to log in.
  9. string userName = "";
  10. string passWord = "";
  11. string problem = "";
  12. //creating the int's for the height and width of the screen.
  13. int rectWidth = 430;
  14. int rectHeight = 240;
  15. //create the int to check if ppl spam the login button.
  16. int passTries = 0;
  17.  
  18. //makes the big box for our menu.
  19. void OnGUI()
  20. {
  21. GUI.Window (0, new Rect((Screen.width - rectWidth) / 2, (Screen.height - rectHeight) / 2, rectWidth, rectHeight), LoginWindow, "Login");
  22. }
  23.  
  24. //creates al the text fields and puts the in the right position.
  25. void LoginWindow(int windowID)
  26. {
  27. GUI.Label (new Rect(170, 40, 130, 100), "----Username----");
  28. userName = GUI.TextField(new Rect(30, 60, 375, 30), userName);
  29. GUI.Label (new Rect(170, 92, 130, 100), "----Password----");
  30. passWord = GUI.PasswordField(new Rect(30, 115, 375, 30), passWord, "*"[0], 25);
  31.  
  32. //creates a login button and executes code when clicked
  33. if (GUI.Button (new Rect(25, 160, 175, 50), "Login"))
  34. {
  35. if (passTries >= 3)
  36. {
  37. problem = "Maximum tries of 3 reached, please wait 10 min";
  38. StartCoroutine(MaximumTries());
  39. }
  40. else
  41. {
  42. StartCoroutine(handleLogin(userName, passWord));
  43. }
  44. }
  45. //makes a register button and loads the register menu if clicked.
  46. if (GUI.Button (new Rect (225, 160, 175, 50), "Register"))
  47. {
  48. Application.LoadLevel ("Register");
  49. }
  50. //this displays the error if there is one.
  51. GUI.Label(new Rect(120, 210, 300, 100), problem);
  52.  
  53. }
  54. //this send the info that is filled in to the login file on the server.
  55. IEnumerator handleLogin(string userNamez, string passWordz)
  56. {
  57. problem = "Checking username and password....";
  58. string login_URL = loginURL + "?username=" + userNamez + "&password=" + passWordz;
  59. WWW loginReader = new WWW (login_URL);
  60. yield return loginReader;
  61.  
  62. if (loginReader.error != null)
  63. {
  64. problem = "Could not locate page";
  65. }
  66. else
  67. {
  68.  
  69. if (loginReader.text == "right")
  70. {
  71. problem = "logged in";
  72. }
  73. else
  74. {
  75. problem = " invalid user/pass";
  76. passTries += 1;
  77. }
  78. }
  79.  
  80. }
  81.  
  82.  
  83. //this disables the login if people have spammed the login button with the wrong password for more than 3 tries
  84. IEnumerator MaximumTries()
  85. {
  86. yield return new WaitForSeconds(1);// set to 600 when putting in the game
  87. passTries = 0;
  88.  
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement