Search Unity

Menu system (contains Login system plus extras)

Discussion in 'Made With Unity' started by bloodtiger10, May 9, 2009.

  1. bloodtiger10

    bloodtiger10

    Joined:
    Nov 9, 2008
    Posts:
    619
    I am currently going to use this in my game Space (see signature) and I am updating this so please don't copy this code unless you really can't wait a week or two.

    Features I am adding
    1. Sha1/md5 option
    2. Cleaning it up and fixing some errors and making it cleaner
    3. Comments
    4. More

    for all those out there who want a menu system here you go. plus some extras

    [OUT OF DATE]

    php code

    cuser.php

    for creating the user
    Code (csharp):
    1.  
    2. <?php
    3.  
    4.         $db = mysql_connect('localhost', 'db_user', 'db_password') or die('Could not connect: ' . mysql_error());
    5.         mysql_select_db('db_database') or die('Could not select database');
    6.  
    7.         // Strings must be escaped to prevent SQL injection attack.
    8.         $email = $_REQUEST['email'];
    9.         $password = $_REQUEST['password'];
    10.         $username = $_REQUEST['username'];
    11.         $born = $_REQUEST['born'];
    12.         $nick = $_REQUEST['nick'];
    13.         $admin = $_REQUEST['admin'];
    14.        
    15.         $password2 = md5($password);
    16.        
    17.             // Send variables for the MySQL database class.
    18.             $query = "insert into users (username, password, email, born, nick, admin) values ('$username', '$password', '$email', '$born', '$nick', '$admin');";
    19.             $result = mysql_query($query) or die('Query failed: ' . mysql_error());
    20.             echo "registered";
    21. ?>
    22.  
    getuser.php

    for checking user
    Code (csharp):
    1.  
    2. <?php
    3.  
    4.     // Send variables for the MySQL database class.
    5.     $database = mysql_connect('localhost', 'db_user', 'db_password') or die('Could not connect: ' . mysql_error());
    6.     mysql_select_db('db_database') or die('Could not select database');
    7.  
    8.  
    9.     $username = $_REQUEST['username'];
    10.     $password = $_REQUEST['password'];
    11.  
    12.     $qry="SELECT * FROM users WHERE username='".mysql_real_escape_string($username)."'
    13.   AND password='".md5($password)."'";
    14.     $result=mysql_query($qry);
    15.  
    16.     if (mysql_num_rows($result)>0)
    17.     {
    18.         echo "right";
    19.     }
    20.     else
    21.     {
    22.         echo "wrong";
    23.     }
    24.  
    25. ?>
    26.  
    now the admin script (still working on this like how you need to login to acess these functions (not in this version but will be soon) )

    admin.php

    Code (csharp):
    1.  
    2. <?php
    3.  
    4. $database = mysql_connect('localhost', 'db_user', 'db_password') or die('Could not connect: ' . mysql_error());
    5.     mysql_select_db('db_database') or die('Could not select database');
    6.    
    7.     $command = $_REQUEST['command'];
    8.     $feed = $_REQUEST['feed'];
    9.     $deleteuser = $_REQUEST['user'];
    10.  
    11.         if ($command == "feed")
    12.         {
    13.             $sql = "DELETE FROM misc WHERE 1";
    14.             $result = mysql_query($sql);
    15.             $sql = "Insert Into misc (feed) values ('$feed')";
    16.             $result = mysql_query($sql);
    17.             echo "yes";
    18.         }
    19.        
    20.         if ($command == "delete")
    21.         {
    22.             $sql = "DELETE FROM users WHERE username='$deleteuser'";
    23.             $result = mysql_query($sql);
    24.             echo "yes";
    25.         }
    26.        
    27.         if ($command == "requestFeed")
    28.         {
    29.             $sql = "Select feed FROM misc";
    30.             $result = mysql_query($sql);
    31.             $arrary = mysql_fetch_array($result);
    32.             echo $arrary['feed'];
    33.         }
    34.    
    35. ?>
    36.  
    unity code

    javascript

    Code (csharp):
    1.  
    2. private var secretKey="mandownhash"; // Edit this value and make sure it's the same as the one stored on the server
    3.  
    4. var skin:GUISkin;
    5.  
    6. var createuserUrl="http://mandown.unity3dgallery.com/cuser.php";
    7. var getuserUrl="http://mandown.unity3dgallery.com/getuser.php";
    8. var feedURL="http://mandown.unity3dgallery.com/feed.txt";
    9. var usernameText="";
    10. var passwordText="";
    11. var userOK=false;
    12. var console="";
    13. var email = "";
    14. var born = "";
    15. var nick = "";
    16. var feed = "";
    17. var i = 0;
    18. var user = "";
    19. var adminCP = false;
    20. private var register = false;
    21. function createUser(username, password, email, born, nick) {
    22.     //This connects to a server side php script that will add the name and score to a MySQL DB.
    23.     // Supply it with a string representing the players name and the players score.
    24.     var hash=md5.Md5Sum(username + password + email + born + nick + secretKey);
    25.  
    26.     var createuser_url = createuserUrl + "username=" + WWW.EscapeURL(username) + "&password=" + WWW.EscapeURL(password) + WWW.EscapeURL(email) + WWW.EscapeURL(born) + WWW.EscapeURL(nick);
    27.        
    28.     // Post the URL to the site and create a download object to get the result.
    29.     var cu_post = WWW(createuser_url);
    30.     yield cu_post; // Wait until the download is done
    31.     if(cu_post.error) {
    32.         print("There was an error creating your user: " + cu_post.error);
    33.     }
    34. }
    35.  
    36. var version : int = 1;
    37.  
    38. function CheckVersion()
    39. {
    40.     var update_url = "http://mandown.unity3dgallery.com/version.txt";
    41.     update_post = WWW(update_url);
    42.     yield update_post; // Wait until the download is done
    43.     if(update_post.error)
    44.     {
    45.         print("There was an error loading the update URL: " + update_post.error);
    46.     }
    47.     else
    48.     {
    49.         var latestVersion : int;
    50.         latestVersion = int.Parse(update_post.data);
    51.         if (latestVersion >= version + 1)
    52.         {
    53.             System.Diagnostics.Process.Start("open","http://mandown.unity3dgallery.com/game/lvgame.7z");
    54.         }
    55.     }
    56. }
    57.  
    58. var feedBool = false;
    59. var feed2 = "";
    60. var feedS = true;
    61.  
    62. function Update()
    63. {
    64.     if (adminCP == false)
    65.     {
    66.         adminFeed = feed2;
    67.     }
    68.     if (userOK == true)
    69.     {
    70.         if (feedS == true)
    71.         {
    72.             feedUpdate();
    73.             feedS = false;
    74.         }
    75.         if (i<100000)
    76.         {
    77.             i++;
    78.         }
    79.         else
    80.         {
    81.             feedUpdate();  
    82.             adminFeed = feed2;
    83.         }
    84.        
    85.         if (feedBool == true)
    86.         {
    87.             feed = "Latest News: " + feed2 + " | " + i + " |";
    88.         }
    89.     }
    90. }
    91.  
    92. function feedUpdate()
    93. {
    94.     var feed_get = "http://mandown.unity3dgallery.com/admin.php?command=requestFeed";
    95.         feed_post = WWW(feed_get);
    96.         yield feed_post;
    97.         if(feed_post.error)
    98.         {
    99.             print("There was an error loading the feed: " + feed_post.error);
    100.             feed = "Could not connect to feed";
    101.             feedBool = false;
    102.             i = 0;
    103.         }
    104.         else
    105.         {
    106.            i = 0;
    107.            feedBool = true;
    108.            feed2 = feed_post.data;
    109.         }
    110. }
    111.  
    112. function BeginPage(width,height) {
    113.     GUILayout.BeginArea(Rect((width),(height),width,height));
    114. }
    115.  
    116. function EndPage() {
    117.     GUILayout.EndArea();
    118. }
    119.  
    120. var userToDelete = "";
    121. var feedChange = "";
    122. var adminDetect = false;
    123.  
    124. function detectIsAdmin()
    125. {
    126.     var createuser_url = "http://mandown.unity3dgallery.com/verify.php" + "?username=" + usernameText + "&password=" + md5.Md5Sum(passwordText);
    127.     var cu_get = WWW(createuser_url);
    128.     yield cu_get;
    129.    
    130.     if(cu_get.error) {
    131.         print("There was an error checking admin: " + cu_get.error);
    132.     }
    133.     else
    134.     {
    135.         if(cu_get.data == "yes")
    136.         {
    137.            adminDetect = true;
    138.         }
    139.        else
    140.        {
    141.           adminDetect = false;
    142.        }
    143.     }
    144. }
    145.  
    146. var adminTest = false;
    147.  
    148. var toolbarInt = 0;
    149. var toolbarStrings : String[] = ["Main Menu","Offline Maps", "Servers", "Forum", "Stats", "Map Creator"];
    150. var adminFeed = "";
    151.  
    152.  
    153. function OnGUI()
    154. {
    155.     GUI.matrix = Matrix4x4.TRS (Vector3.zero, Quaternion.identity, Vector3 (Screen.width / 600.0, Screen.height / 400.0, 1));
    156.     if (skin != null) {
    157.         GUI.skin = skin;
    158.     }
    159.    
    160.    if (register == false  userOK == false)
    161.    {
    162.     GUI.Box(Rect (125,50,400,300), "Login");
    163.     BeginPage(150,100);
    164.         GUI.Label(Rect (30,20,60,20), "Username:");
    165.         GUI.Label(Rect (30,47,60,20), "Password:");
    166.         EndPage(); 
    167.         usernameText = GUI.TextField(Rect (250,117,150,20), usernameText, 25);
    168.         passwordField.x = 250;
    169.         passwordField.y = 145;
    170.         passwordField.w = 150;
    171.         passwordField.h = 20;
    172.         passwordField.l = 25;
    173.         passwordText = passwordField.PasswordField(passwordText, "*");
    174.         if (GUI.Button(Rect (300,220,100,20), "Login") || Input.GetKeyDown("return"))
    175.           checkUser();
    176.         if (GUI.Button(Rect (300,260,100,20), "register"))
    177.         {
    178.           register = true;
    179.         }
    180.    }
    181.    
    182.    if (register == false  userOK == true)
    183.    {
    184.         if (adminTest == false)
    185.         {
    186.             detectIsAdmin();
    187.             adminTest = true;
    188.         }
    189.         GUI.Box(Rect (10,10,575,360), "Main Menu");
    190.         if (adminCP == false)
    191.         {
    192.             GUI.Label(Rect (20,20,500,20), feed);
    193.             toolbarInt = GUI.Toolbar (Rect (25, 40, 550, 50), toolbarInt, toolbarStrings);
    194.             if (toolbarInt == 0)
    195.             {
    196.             }
    197.             if (toolbarInt == 1)
    198.             {
    199.             }
    200.             if (toolbarInt == 2)
    201.             {
    202.             }
    203.             if (toolbarInt == 3)
    204.             {
    205.             }
    206.             if (toolbarInt == 4)
    207.             {
    208.             }
    209.             if (toolbarInt == 5)
    210.             {
    211.             }
    212.             if (toolbarInt == 6)
    213.             {
    214.             }
    215.             if (adminDetect == true  GUI.Button(Rect (425,325,150,20), "Admin Control Panel"))
    216.             {
    217.                 adminFeedBool = false;
    218.                 adminCP = true;
    219.             }
    220.         }
    221.         else if (adminCP == true)
    222.         {
    223.             adminFeed = GUI.TextField(Rect (25,25,200,25), adminFeed, 50);
    224.             user = GUI.TextField(Rect (25,50,200,25), user, 50);
    225.             GUI.Label(Rect (230,25,200,25), " Feed");
    226.             GUI.Label(Rect (230,50,200,25), " User to delete");
    227.             if (GUI.Button(Rect (250,325,150,20), "Apply Changes"))
    228.             {
    229.                 Apply();   
    230.             }
    231.             if (GUI.Button(Rect (425,325,150,20), "Back"))
    232.             {
    233.                 adminCP = false;
    234.             }
    235.         }
    236.    }
    237.    
    238.    if (register == true  userOK == false)
    239.    {
    240.     GUI.Box(Rect (100,50,420,300), "Register");
    241.         GUI.Label(Rect (150,80,60,20),"Username:");
    242.         GUI.Label(Rect (150,110,60,20),"Password:");
    243.         GUI.Label(Rect (150,140,60,20),"Email:");
    244.         GUI.Label(Rect (110,170,120,20),"Born (YYYY-MM-DD):");
    245.         GUI.Label(Rect (150,200,60,20),"Nickname:");
    246.       usernameText = GUI.TextField(Rect (210,80,180,20),usernameText, 25);
    247.       passwordField.x = 210;
    248.       passwordField.y = 110;
    249.       passwordField.w = 180;
    250.       passwordField.h = 20;
    251.       passwordField.l = 25;
    252.       passwordText = passwordField.PasswordField(passwordText, "*");
    253.       email = GUI.TextField(Rect (210,140,180,20),email, 25);
    254.       born = GUI.TextField(Rect (230,170,180,20),born, 25);
    255.       nick = GUI.TextField(Rect (210,200,180,20),nick, 25);
    256.       if (GUI.Button(Rect (300,260,100,100), "Register"))
    257.          registerUsername();
    258.    }
    259.    GUI.Label(Rect (150,300,150,50), console);
    260. }
    261.  
    262. function Apply()
    263. {
    264.     var feed_url = "http://mandown.unity3dgallery.com/admin.php?command=feed&feed=" + adminFeed;
    265.     var cu_get = WWW(feed_url);
    266.     yield cu_get;
    267.  
    268.         if(cu_get.error) {
    269.            print("There was an error applying changes: " + cu_get.error);
    270.         }
    271.         else
    272.         {
    273.            if(cu_get.data == "yes")
    274.            {
    275.                feedUpdate();
    276.            }
    277.        else
    278.      {
    279.           print("error could not change!");
    280.       }
    281.     }
    282.    
    283.     var delete_url = "http://mandown.unity3dgallery.com/admin.php?command=delete&user=" + user;
    284.     var cud_get = WWW(delete_url);
    285.     yield cud_get;
    286.  
    287.         if(cud_get.error) {
    288.            print("There was an error applying changes: " + cud_get.error);
    289.         }
    290.         else
    291.         {
    292.            if(cud_get.data == "yes")
    293.            {
    294.                feedUpdate();
    295.            }
    296.        else
    297.      {
    298.           print("error could not change!");
    299.       }
    300.     }
    301.     adminCP = false;
    302. }
    303.  
    304. function registerUsername()
    305. {
    306.     console = "registering you";
    307.     var createuser_url = createuserUrl + "?username=" + usernameText + "&password=" + md5.Md5Sum(passwordText) + "&email=" + email + "&born=" + born + "&nick=" + nick;
    308.     var cu_get = WWW(createuser_url);
    309.     yield cu_get;
    310.    
    311.     if(cu_get.error) {
    312.         console = "There was an error registering: " + cu_get.error;
    313.     }
    314.     else
    315.     {
    316.         if(cu_get.data == "registered")
    317.         {
    318.            console = "registered";
    319.            yield WaitForSeconds(3.0);
    320.            register = false;
    321.         }
    322.        else
    323.        {
    324.           console = "Error, please try again";  
    325.        }
    326.     }
    327. }
    328.  
    329. function checkUser() {
    330.     console = "Checking Username and Password";
    331.     var getuser_url = getuserUrl + "?username=" + usernameText + "&password=" + md5.Md5Sum(passwordText);
    332.     var cu_get = WWW(getuser_url);
    333.     yield cu_get;
    334.    
    335.     if(cu_get.error) {
    336.         console = "There was an error checking your username and password: " + cu_get.error;
    337.     }
    338.     else
    339.     {
    340.         if(cu_get.data == "right")
    341.         {
    342.            console = "Welcome back " + usernameText + " hope you enjoy the game!";
    343.            yield WaitForSeconds(3.0);
    344.            userOK=true;
    345.         }
    346.        else
    347.        {
    348.           userOK = false;
    349.           console = cu_get.data;  
    350.        }
    351.     }
    352.    
    353.     CheckVersion();
    354. }
    355.  
    all this can log a user in and register a user. it takes the year born nickname username password email and if they're admin. this saves everything in a mysql database with a md5 hash.

    you need the passwordField from the wiki for this to work and you need to call it passwordField.

    hope you enjoy!

    (this is from man down) (Open Source Americas army and well we are being open source by giving the communtiy how to do everything in it)

    this is only the first part.
     
  2. xandeck

    xandeck

    Joined:
    Apr 2, 2009
    Posts:
    563
    Very nice from you, lots of people will need it
     
  3. bloodtiger10

    bloodtiger10

    Joined:
    Nov 9, 2008
    Posts:
    619
    hey my team's intent with this project is to share everything about it to the community. It is an open source game. but I am rewriting it so I will come back with a better version soon.
     
  4. bloodtiger10

    bloodtiger10

    Joined:
    Nov 9, 2008
    Posts:
    619
    just a small update for the registration system and login system. [UPDATED UNITY CODE] go to first post for updated code.
     
  5. martaaay

    martaaay

    Joined:
    Apr 13, 2009
    Posts:
    136
    Nice little chunk of code!

    Be aware that this code allows for sql injection attacks. This line:
    Code (csharp):
    1.  
    2. $qry="SELECT * FROM users WHERE username='$username'
    3.   AND password='".md5($password)."'";
    4.  
    should be

    Code (csharp):
    1.  
    2. $qry="SELECT * FROM users WHERE username='".mysql_real_escape_string($username)."'
    3.   AND password='".md5($password)."'";
    4.  
    The md5 is safe because its output is bounded and does not need escaping.
     
  6. bloodtiger10

    bloodtiger10

    Joined:
    Nov 9, 2008
    Posts:
    619
    woops, I'll correct that, I have completed more of the final product including an rss feed (sort of).

    I will post the code soon. The new features are

    improved register system, admin control panel and a main menu. with servers and such.
    Other features will be

    Forum inside game,

    Team Speak or Microphone networking (aka team speak).

    Also adds screen resizing.
     
  7. bloodtiger10

    bloodtiger10

    Joined:
    Nov 9, 2008
    Posts:
    619
    [UPDATED]
     
  8. xandeck

    xandeck

    Joined:
    Apr 2, 2009
    Posts:
    563
    Nice to share... :wink:

    I'm an advanced programmer in PHP, will take a better look soon
     
  9. Veli

    Veli

    Joined:
    Mar 10, 2009
    Posts:
    301
  10. Dakta

    Dakta

    Joined:
    Apr 8, 2008
    Posts:
    492
    Very cool! I'll definitely be using this!

    (Remind me to share all my code with explanations, once I have a better demo.)


    Just a question: Where do you put the php, and where do you put the Unity JavaScript? I assume the JavaScript goes on an empty asset, but what about the php. I guess I'm kind of a web noob still...
     
  11. Veli

    Veli

    Joined:
    Mar 10, 2009
    Posts:
    301
    You put the php files on a webserver. Then you make unity talk with those files trhu URL :)
     
  12. Arges

    Arges

    Joined:
    Oct 5, 2008
    Posts:
    359
  13. Dakta

    Dakta

    Joined:
    Apr 8, 2008
    Posts:
    492
    Love that guy's stuff....
     
  14. Agrios

    Agrios

    Joined:
    Aug 21, 2009
    Posts:
    50
    Thanks for the code, helps me a lot,
    but I am getting some errors here.

    Is this some sort of an array and where is it declared?
     
  15. Tom163

    Tom163

    Joined:
    Nov 30, 2007
    Posts:
    1,290
    Good thing, and thanks for sharing. As you've seen, the community has already given some crucial input.

    I'd like to add that I would strongly recommend doing the md5 on the client side only. That's the proper place, so as to never send the user password across the net in plain text.
    There is no added security in applying md5 a second time. On the contrary, it will considerably increase the chances for a hash collision.

    Plus if you can, use SHA1. They're both considered broken, but SHA1 a lot less.
     
  16. perlohmann

    perlohmann

    Joined:
    Feb 12, 2009
    Posts:
    221
    Would also recomend to add a unique 'salt' entry in the database (unique for each password) that you combine with the password to remove the posibility of an easy dictionary attack.

    why use a salt? well if a hacker got his hands on your database and had a precomputed hash dictionary of lets say 10 million common passwords it would be rather easy to just compare the hashed values and thereby getting an unhashed password ready to use.

    by adding a unique salt to the password you would force a hacker to make a hash dictionary for each password entry in you database which is rather time consuming.

    How you add this salt is up to you. The most secure is making it a 2 step process where you first retreive the salt according to a unique username and apply this salt to the password on the client side before sending it to a webpage to do the hashed password comparison.

    The salt is not a secret by any means (it has to be pretty unique though). Its just there to protect from dictionary attacks.

    //perlohmann
     
  17. Dakta

    Dakta

    Joined:
    Apr 8, 2008
    Posts:
    492
    That's a great idea man!


    Still... It always helps if users use passwords with no dictionary definition, that include letters, numbers, and special characters. Much more secure that way.
     
  18. Tom163

    Tom163

    Joined:
    Nov 30, 2007
    Posts:
    1,290
    That's largely an illusion. Yes, I am a security expert and I've given talks on this subject. If you're interested, send me a PM and we can discuss it or I can send you a presentation or two.
     
  19. perlohmann

    perlohmann

    Joined:
    Feb 12, 2009
    Posts:
    221
    Ye usually the "best" passwords also have the biggest secrets behind them =) so if I were to hack something I would make sure that I had pretty obscure passwords in my "dictionary" too. =)

    The good thing about the salt method is that the strength of the password ie. being a readable word is not the biggest issue. The length of the word is though.
     
  20. bloodtiger10

    bloodtiger10

    Joined:
    Nov 9, 2008
    Posts:
    619
    hey guys I haven't responded to this but Man Down is dead (hence I haven't responded lately) but I am going to use this in my new game space (check signature) and so I will update this and add a lot more (and space is also open source just like man down).

    So yeah I'll update this change somethings make it a little more general, etc, etc, etc.

    I'll also comment it some more and add some things and make things a little more optional.

    Edit: I'll also add this to the wiki since I haven't. Once I get these new changes added/changed.
     
  21. bloodtiger10

    bloodtiger10

    Joined:
    Nov 9, 2008
    Posts:
    619
    ok I've updated it but not in the original post. If you really need the update version which includes more efficient code and sha1 hashes (md5 or sha1 your choice)

    pm other wise wait till this week end
     
  22. lavanraj2002

    lavanraj2002

    Joined:
    Jul 24, 2009
    Posts:
    35
    Hello there,
    Can you send me your update code... I need to create a login system from scratch.

    Appreciate all your help.
     
  23. bloodtiger10

    bloodtiger10

    Joined:
    Nov 9, 2008
    Posts:
    619
    hmm... you have use the original because I don't know where it is I haven't used unity for quite some time
     
  24. lavanraj2002

    lavanraj2002

    Joined:
    Jul 24, 2009
    Posts:
    35
    Hello, is it possible to look for it and send me. It would be a great help and appreciated.

    Thanks. :D :p
     
  25. bloodtiger10

    bloodtiger10

    Joined:
    Nov 9, 2008
    Posts:
    619
    I know I don't have it because when I updated the computer which had it to snow leopard I made totally new users. Sorry.
     
  26. elegantpig

    elegantpig

    Joined:
    Mar 24, 2010
    Posts:
    1
    thanks for your sharing.
     
  27. Robert G

    Robert G

    Joined:
    Nov 17, 2009
    Posts:
    233
    Although I'm not sure about this, but I think some fault in the "checkUser" function did go unnoticed.
    The 'cu_get.data == "right"' does not seem to be true even when the php script echo's "right" out.
    Instead the else statement get evaluated, still reflecting the "right" echo.

    I would like to hear if someone has the "Welcome+Username" working.

    Thanks in advance, Robert

    Code (csharp):
    1.  
    2. function checkUser() {
    3.  
    4.     console = "Controle van inlog gegevens.";
    5.     var getuser_url = getuserUrl + "?username=" + usernameText + "&password=" + md5functions.Md5Sum(passwordText);
    6.     var cu_get = WWW(getuser_url);
    7.     yield cu_get;
    8.    
    9.    if(cu_get.error) {
    10.         console = "There was an error checking your username and password: " + cu_get.error;
    11.     }
    12.     else
    13.     {
    14.         //although the PHP echo's out "right" this does not get evaluated
    15.         if(cu_get.data == "right")
    16.         {
    17.            console = "Welcome back " + usernameText + " hope you enjoy the game!";
    18.            yield WaitForSeconds(3.0);
    19.            //userOK=true;
    20.         }
    21.        else
    22.        //Instead this one gets evaluated
    23.        {
    24.           userOK = false;
    25.           console = cu_get.data+"Not right from PHP gets evaluated";  
    26.        }
    27.     }
    28.    
    29.     //CheckVersion();
    30. }
    31.  
     
  28. Maroy

    Maroy

    Joined:
    Dec 20, 2009
    Posts:
    35
    I fixed it by moving console = cu_get.data to the beginning and changing the if to ask if the console equals "right " because apparently it puts a space at the end. Probably not the optimal solution, but it works.

    Code (csharp):
    1. function checkUser() {
    2.     console = "Checking Username and Password";
    3.     var getuser_url = getuserUrl + "?username=" + usernameText + "&password=" + passwordText;
    4.     var cu_get = WWW(getuser_url);
    5.     yield cu_get;
    6.    
    7.     if(cu_get.error) {
    8.         console = "There was an error checking your username and password: " + cu_get.error;
    9.     }
    10.     else
    11.     {
    12.     console = cu_get.data;
    13.         if(console == "right ")
    14.         {
    15.            console = "Welcome back " + usernameText + " hope you enjoy the game!";
    16.            yield WaitForSeconds(3.0);
    17.            userOK=true;
    18.         }
    19.        else
    20.        {
    21.           userOK = false;
    22.        }
    23.     }
    24.    
    25.     CheckVersion();
    26. }
     
  29. Robert G

    Robert G

    Joined:
    Nov 17, 2009
    Posts:
    233
    Thanks Maroy for looking at this.

    I will have a look at your code and then try to determine why the original code is not working (if it isn't).
    So I still hope someone else will chime in telling me that they had the "Welcome+Username" working.
    That way I know there is some fault some were else in my code. Not only am I'm trying to have this working; I also would like to know where my code goes wrong.

    Thanks again, Robert
     
  30. Robbilie2

    Robbilie2

    Joined:
    Aug 4, 2010
    Posts:
    262
    hey i have many problems pls can u help me?

    1. passwordField

    i have the passwordField from the wiki passwordField.js

    and everytime i run the game it says: example: 'x' is not a member of 'passwordField'

    whats the problem?

    2. login

    where can i host the files best? i had a host with phpmyadmin and i created a table but i think somethingg was wrong...

    and now the host changed something so it doesnt work with this host anymore....

    can u give me a host and a screen of a table? thx.



    thanks for ur help.

    Robert
     
  31. jedy

    jedy

    Joined:
    Aug 1, 2010
    Posts:
    579
    Great work on the login system.
     
  32. Robbilie2

    Robbilie2

    Joined:
    Aug 4, 2010
    Posts:
    262
    hey guys i got every of my problems to work:)

    now i want to do that when the console is "right" load a new scene...

    i changed the code very small but it doesnt work :

    Code (csharp):
    1.  
    2. private var secretKey="dudi2008"; // Edit this value and make sure it's the same as the one stored on the server
    3.  
    4. var skin:GUISkin;
    5.  
    6. var createuserUrl="http://fantasticoworld.fa.funpic.de/cuser.php";
    7. var getuserUrl="http://fantasticoworld.fa.funpic.de/getuser.php";
    8. var feedURL="http://fantasticoworld.fa.funpic.de/feed.txt";
    9. var usernameText="";
    10. var passwordText="";
    11. var userOK=false;
    12. var console="";
    13. var email = "";
    14. var born = "";
    15. var nick = "";
    16. var feed = "";
    17. var i = 0;
    18. var user = "";
    19. var adminCP = false;
    20. private var register = false;
    21. function createUser(username, password, email, born, nick) {
    22.     //This connects to a server side php script that will add the name and score to a MySQL DB.
    23.     // Supply it with a string representing the players name and the players score.
    24.     var hash=md5.Md5Sum(username + password + email + born + nick + secretKey);
    25.  
    26.     var createuser_url = createuserUrl + "username=" + WWW.EscapeURL(username) + "&password=" + WWW.EscapeURL(password) + WWW.EscapeURL(email) + WWW.EscapeURL(born) + WWW.EscapeURL(nick);
    27.        
    28.     // Post the URL to the site and create a download object to get the result.
    29.     var cu_post = WWW(createuser_url);
    30.     yield cu_post; // Wait until the download is done
    31.     if(cu_post.error) {
    32.         print("There was an error creating your user: " + cu_post.error);
    33.     }
    34. }
    35.  
    36. var version : int = 1;
    37.  
    38. function CheckVersion()
    39. {
    40.     var update_url = "http://fantasticoworld.fa.funpic.de/version.txt";
    41.     update_post = WWW(update_url);
    42.     yield update_post; // Wait until the download is done
    43.     if(update_post.error)
    44.     {
    45.         print("There was an error loading the update URL: " + update_post.error);
    46.     }
    47.     else
    48.     {
    49.         var latestVersion : int;
    50.         latestVersion = int.Parse(update_post.data);
    51.         if (latestVersion >= version + 1)
    52.         {
    53.             System.Diagnostics.Process.Start("open","http://mandown.unity3dgallery.com/game/lvgame.7z");
    54.         }
    55.     }
    56. }
    57.  
    58. var feedBool = false;
    59. var feed2 = "";
    60. var feedS = true;
    61.  
    62. function Update()
    63. {
    64.    if (adminCP == false)
    65.    {
    66.       adminFeed = feed2;
    67.    }
    68.    if (userOK == true)
    69.    {
    70.       if (feedS == true)
    71.       {
    72.          feedUpdate();
    73.          feedS = false;
    74.       }
    75.       if (i<100000)
    76.       {
    77.          i++;
    78.       }
    79.       else
    80.       {
    81.          feedUpdate();  
    82.          adminFeed = feed2;
    83.       }
    84.      
    85.       if (feedBool == true)
    86.       {
    87.          feed = "Latest News: " + feed2 + " | " + i + " |";
    88.       }
    89.    }
    90. }
    91.  
    92. function feedUpdate()
    93. {
    94.    var feed_get = "http://fantasticoworld.fa.funpic.de/admin.php?command=requestFeed";
    95.       feed_post = WWW(feed_get);
    96.       yield feed_post;
    97.       if(feed_post.error)
    98.        {
    99.            print("There was an error loading the feed: " + feed_post.error);
    100.            feed = "Could not connect to feed";
    101.            feedBool = false;
    102.            i = 0;
    103.        }
    104.        else
    105.        {
    106.            i = 0;
    107.            feedBool = true;
    108.            feed2 = feed_post.data;
    109.          }
    110. }
    111.  
    112. function BeginPage(width,height) {
    113.     GUILayout.BeginArea(Rect((width),(height),width,height));
    114. }
    115.  
    116. function EndPage() {
    117.     GUILayout.EndArea();
    118. }
    119.  
    120. var userToDelete = "";
    121. var feedChange = "";
    122. var adminDetect = false;
    123.  
    124. function detectIsAdmin()
    125. {
    126.     var createuser_url = "http://fantasticoworld.fa.funpic.de/verify.php" + "?username=" + usernameText + "&password=" + md5.Md5Sum(passwordText);
    127.     var cu_get = WWW(createuser_url);
    128.     yield cu_get;
    129.    
    130.     if(cu_get.error) {
    131.         print("There was an error checking admin: " + cu_get.error);
    132.     }
    133.     else
    134.     {
    135.         if(cu_get.data == "yes")
    136.         {
    137.            adminDetect = true;
    138.         }
    139.        else
    140.        {
    141.           adminDetect = false;
    142.        }
    143.     }
    144. }
    145.  
    146. var adminTest = false;
    147.  
    148. var toolbarInt = 0;
    149. var toolbarStrings : String[] = ["Main Menu","Offline Maps", "Servers", "Forum", "Stats", "Map Creator"];
    150. var adminFeed = "";
    151.  
    152.  
    153. function OnGUI()
    154. {
    155.    GUI.matrix = Matrix4x4.TRS (Vector3.zero, Quaternion.identity, Vector3 (Screen.width / 600.0, Screen.height / 400.0, 1));
    156.    if (skin != null) {
    157.         GUI.skin = skin;
    158.     }
    159.    
    160.    if (register == false  userOK == false)
    161.    {
    162.       GUI.Box(Rect (125,50,400,300), "Login");
    163.       BeginPage(150,100);
    164.          GUI.Label(Rect (30,20,60,20), "Username:");
    165.          GUI.Label(Rect (30,47,60,20), "Password:");
    166.          EndPage();  
    167.          usernameText = GUI.TextField(Rect (250,117,150,20), usernameText, 25);
    168.          passwordText = GUI.PasswordField(Rect (250,145,150,20), passwordText, "*"[0], 25);
    169.          //passwordField.x = 250;
    170.          //passwordField.y = 145;
    171.          //passwordField.w = 150;
    172.          //passwordField.h = 20;
    173.          //passwordField.l = 25;
    174.          //passwordText = passwordField.PasswordField(passwordText, "*");
    175.          if (GUI.Button(Rect (300,220,100,20), "Login") || Input.GetKeyDown("return"))
    176.          checkUser();
    177.          if (GUI.Button(Rect (300,200,100,20), "register"))
    178.          {
    179.          register = true;
    180.          }
    181.    }
    182.    
    183.    if (register == false  userOK == true)
    184.    {
    185.          if (adminTest == false)
    186.          {
    187.             detectIsAdmin();
    188.             adminTest = true;
    189.          }
    190.          GUI.Box(Rect (10,10,575,360), "Main Menu");
    191.          if (adminCP == false)
    192.          {
    193.             GUI.Label(Rect (20,20,500,20), feed);
    194.             toolbarInt = GUI.Toolbar (Rect (25, 40, 550, 50), toolbarInt, toolbarStrings);
    195.             if (toolbarInt == 0)
    196.             {
    197.             }
    198.             if (toolbarInt == 1)
    199.             {
    200.             }
    201.             if (toolbarInt == 2)
    202.             {
    203.             }
    204.             if (toolbarInt == 3)
    205.             {
    206.             }
    207.             if (toolbarInt == 4)
    208.             {
    209.             }
    210.             if (toolbarInt == 5)
    211.             {
    212.             }
    213.             if (toolbarInt == 6)
    214.             {
    215.             }
    216.             if (adminDetect == true  GUI.Button(Rect (425,325,150,20), "Admin Control Panel"))
    217.             {
    218.                adminFeedBool = false;
    219.                adminCP = true;
    220.             }
    221.          }
    222.          else if (adminCP == true)
    223.          {
    224.             adminFeed = GUI.TextField(Rect (25,25,200,25), adminFeed, 50);
    225.             user = GUI.TextField(Rect (25,50,200,25), user, 50);
    226.             GUI.Label(Rect (230,25,200,25), " Feed");
    227.             GUI.Label(Rect (230,50,200,25), " User to delete");
    228.             if (GUI.Button(Rect (250,325,150,20), "Apply Changes"))
    229.             {
    230.                Apply();  
    231.             }
    232.             if (GUI.Button(Rect (425,325,150,20), "Back"))
    233.             {
    234.                adminCP = false;
    235.             }
    236.          }
    237.    }
    238.    
    239.    if (register == true  userOK == false)
    240.    {
    241.       GUI.Box(Rect (100,50,420,300), "Register");
    242.          GUI.Label(Rect (150,80,60,20),"Username:");
    243.          GUI.Label(Rect (150,110,60,20),"Password:");
    244.          GUI.Label(Rect (150,140,60,20),"Email:");
    245.       GUI.Label(Rect (110,170,120,20),"Born (YYYY-MM-DD):");
    246.       GUI.Label(Rect (150,200,60,20),"Nickname:");
    247.       usernameText = GUI.TextField(Rect (210,80,180,20),usernameText, 25);
    248.       passwordText = GUI.PasswordField(Rect (210,110,180,20), passwordText, "*"[0], 25);      
    249.       //passwordField.x = 210;
    250.       //passwordField.y = 110;
    251.       //passwordField.w = 180;
    252.       //passwordField.h = 20;
    253.       //passwordField.l = 25;
    254.       //passwordText = passwordField.PasswordField(passwordText, "*");
    255.       email = GUI.TextField(Rect (210,140,180,20),email, 25);
    256.       born = GUI.TextField(Rect (230,170,180,20),born, 25);
    257.       nick = GUI.TextField(Rect (210,200,180,20),nick, 25);
    258.       if (GUI.Button(Rect (300,260,100,100), "Register"))
    259.          registerUsername();
    260.    }
    261.    GUI.Label(Rect (150,300,150,50), console);
    262. }
    263.  
    264. function Apply()
    265. {
    266.    var feed_url = "http://fantasticoworld.fa.funpic.de/admin.php?command=feed&feed=" + adminFeed;
    267.       var cu_get = WWW(feed_url);
    268.      yield cu_get;
    269.  
    270.         if(cu_get.error) {
    271.             print("There was an error applying changes: " + cu_get.error);
    272.         }
    273.         else
    274.         {
    275.           if(cu_get.data == "yes")
    276.           {
    277.                 feedUpdate();
    278.           }
    279.        else
    280.      {
    281.             print("error could not change!");
    282.       }
    283.     }
    284.    
    285.     var delete_url = "http://fantasticoworld.fa.funpic.de/admin.php?command=delete&user=" + user;
    286.       var cud_get = WWW(delete_url);
    287.      yield cud_get;
    288.  
    289.         if(cud_get.error) {
    290.             print("There was an error applying changes: " + cud_get.error);
    291.         }
    292.         else
    293.         {
    294.           if(cud_get.data == "yes")
    295.           {
    296.                 feedUpdate();
    297.           }
    298.        else
    299.      {
    300.             print("error could not change!");
    301.       }
    302.     }
    303.     adminCP = false;
    304. }
    305.  
    306. function registerUsername()
    307. {
    308.     console = "registering you";
    309.     var createuser_url = createuserUrl + "?username=" + usernameText + "&password=" + md5.Md5Sum(passwordText) + "&email=" + email + "&born=" + born + "&nick=" + nick;
    310.     var cu_get = WWW(createuser_url);
    311.     yield cu_get;
    312.    
    313.     if(cu_get.error) {
    314.         console = "There was an error registering: " + cu_get.error;
    315.     }
    316.     else
    317.     {
    318.         if(cu_get.data == "registered")
    319.         {
    320.            console = "registered";
    321.            yield WaitForSeconds(3.0);
    322.            register = false;
    323.         }
    324.        else
    325.        {
    326.           console = "Error, please try again";  
    327.        }
    328.     }
    329. }
    330.  
    331. function checkUser() {
    332.     console = "Checking Username and Password";
    333.     var getuser_url = getuserUrl + "?username=" + usernameText + "&password=" + passwordText;
    334.     var cu_get = WWW(getuser_url);
    335.     yield cu_get;
    336.    
    337.     if(cu_get.error) {
    338.         console = "There was an error checking your username and password: " + cu_get.error;
    339.     }
    340.     else
    341.     {
    342.    console = cu_get.data;
    343.         if(console == "right")
    344.         {
    345.            console = "Welcome back " + usernameText + " hope you enjoy the game!";
    346.            yield WaitForSeconds(3.0);
    347.            Application.LoadLevel("new");
    348.            userOK=true;
    349.         }
    350.        else
    351.        {
    352.           userOK = false;
    353.        }
    354.     }
    355.    
    356.     CheckVersion();
    357. }
    358.  
    pls help me :)

    note: scene name is "new"[/code]
     
  33. Robbilie2

    Robbilie2

    Joined:
    Aug 4, 2010
    Posts:
    262
    hey guys
    If u want to get the script work right

    U have to change "right" or "false" to "right\n" or "false\n"

    i changed the console label to a textfield and found out, that after the log there was a return....

    In the script return doesnt work so unity told me to use \n .....


    So everyone who didnt get the script work right... That was the problem ;D

    Robert
     
  34. msborat

    msborat

    Joined:
    Jun 17, 2010
    Posts:
    89
    How do you fix the passwordField problem i have the same problem.

    I have the PasswordField script from the wiki
     
    Last edited: Oct 6, 2010
  35. Profas

    Profas

    Joined:
    Oct 15, 2009
    Posts:
    73
    There is a bug in your getuser.php in query should be .$password. instead of .md5($password). .
     
  36. MaxGaniyev

    MaxGaniyev

    Joined:
    Mar 18, 2010
    Posts:
    29
    Unknown identifier: 'md5' ??? please help me!
     
  37. cupsster

    cupsster

    Joined:
    Apr 14, 2009
    Posts:
    363
    it works but you must import md5 script form wiki.. there are js and c# versions
     
  38. MrRudak

    MrRudak

    Joined:
    Oct 17, 2010
    Posts:
    159
    hmm Pretty Nice Stuff, im needing a tutorial on how to make an interface...
     
  39. Magicpickle97

    Magicpickle97

    Joined:
    Feb 19, 2011
    Posts:
    89
    Unknown identifier 'md5'
    Assets/Login.js(52,40): BCE0020: An instance of type 'System.Diagnostics.Process' is required to access non static member 'Start'.

    does anyone know how to fix this?
     
  40. Magicpickle97

    Magicpickle97

    Joined:
    Feb 19, 2011
    Posts:
    89
    I think I fixed it

    [ code]
    private var secretKey="dudi2008"; // Edit this value and make sure it's the same as the one stored on the server

    var skin:GUISkin;

    var createuserUrl="http://fantasticoworld.fa.funpic.de/cuser.php";
    var getuserUrl="http://fantasticoworld.fa.funpic.de/getuser.php";
    var feedURL="http://fantasticoworld.fa.funpic.de/feed.txt";
    var usernameText="";
    var passwordText="";
    var userOK=false;
    var console="";
    var email = "";
    var born = "";
    var nick = "";
    var feed = "";
    var i = 0;
    var user = "";
    var adminCP = false;
    private var register = false;
    function createUser(username, password, email, born, nick) {
    //This connects to a server side php script that will add the name and score to a MySQL DB.
    // Supply it with a string representing the players name and the players score.
    var hash = (username + password + email + born + nick + secretKey);

    var createuser_url = createuserUrl + "username=" + WWW.EscapeURL(username) + "&password=" + WWW.EscapeURL(password) + WWW.EscapeURL(email) + WWW.EscapeURL(born) + WWW.EscapeURL(nick);

    // Post the URL to the site and create a download object to get the result.
    var cu_post = WWW(createuser_url);
    yield cu_post; // Wait until the download is done
    if(cu_post.error) {
    print("There was an error creating your user: " + cu_post.error);
    }
    }

    var version : int = 1;

    function CheckVersion()
    {
    var update_url = "http://fantasticoworld.fa.funpic.de/version.txt";
    update_post = WWW(update_url);
    yield update_post; // Wait until the download is done
    if(update_post.error)
    {
    print("There was an error loading the update URL: " + update_post.error);
    }
    else
    {
    var latestVersion : int;
    latestVersion = int.Parse(update_post.data);
    if (latestVersion >= version + 1)
    {
    }
    }
    }

    var feedBool = false;
    var feed2 = "";
    var feedS = true;

    function Update()
    {
    if (adminCP == false)
    {
    adminFeed = feed2;
    }
    if (userOK == true)
    {
    if (feedS == true)
    {
    feedUpdate();
    feedS = false;
    }
    if (i<100000)
    {
    i++;
    }
    else
    {
    feedUpdate();
    adminFeed = feed2;
    }

    if (feedBool == true)
    {
    feed = "Latest News: " + feed2 + " | " + i + " |";
    }
    }
    }

    function feedUpdate()
    {
    var feed_get = "http://fantasticoworld.fa.funpic.de/admin.php?command=requestFeed";
    feed_post = WWW(feed_get);
    yield feed_post;
    if(feed_post.error)
    {
    print("There was an error loading the feed: " + feed_post.error);
    feed = "Could not connect to feed";
    feedBool = false;
    i = 0;
    }
    else
    {
    i = 0;
    feedBool = true;
    feed2 = feed_post.data;
    }
    }

    function BeginPage(width,height) {
    GUILayout.BeginArea(Rect((width),(height),width,height));
    }

    function EndPage() {
    GUILayout.EndArea();
    }

    var userToDelete = "";
    var feedChange = "";
    var adminDetect = false;

    function detectIsAdmin()
    {
    var createuser_url = "http://fantasticoworld.fa.funpic.de/verify.php" + "?username=" + usernameText + "&password=" + passwordText;
    var cu_get = WWW(createuser_url);
    yield cu_get;

    if(cu_get.error) {
    print("There was an error checking admin: " + cu_get.error);
    }
    else
    {
    if(cu_get.data == "yes")
    {
    adminDetect = true;
    }
    else
    {
    adminDetect = false;
    }
    }
    }

    var adminTest = false;

    var toolbarInt = 0;
    var toolbarStrings : String[] = ["Main Menu","Offline Maps", "Servers", "Forum", "Stats", "Map Creator"];
    var adminFeed = "";


    function OnGUI()
    {
    GUI.matrix = Matrix4x4.TRS (Vector3.zero, Quaternion.identity, Vector3 (Screen.width / 600.0, Screen.height / 400.0, 1));
    if (skin != null) {
    GUI.skin = skin;
    }

    if (register == false userOK == false)
    {
    GUI.Box(Rect (125,50,400,300), "Login");
    BeginPage(150,100);
    GUI.Label(Rect (30,20,60,20), "Username:");
    GUI.Label(Rect (30,47,60,20), "Password:");
    EndPage();
    usernameText = GUI.TextField(Rect (250,117,150,20), usernameText, 25);
    passwordText = GUI.PasswordField(Rect (250,145,150,20), passwordText, "*"[0], 25);
    //passwordField.x = 250;
    //passwordField.y = 145;
    //passwordField.w = 150;
    //passwordField.h = 20;
    //passwordField.l = 25;
    //passwordText = passwordField.PasswordField(passwordText, "*");
    if (GUI.Button(Rect (300,220,100,20), "Login") || Input.GetKeyDown("return"))
    checkUser();
    if (GUI.Button(Rect (300,200,100,20), "register"))
    {
    register = true;
    }
    }

    if (register == false userOK == true)
    {
    if (adminTest == false)
    {
    detectIsAdmin();
    adminTest = true;
    }
    GUI.Box(Rect (10,10,575,360), "Main Menu");
    if (adminCP == false)
    {
    GUI.Label(Rect (20,20,500,20), feed);
    toolbarInt = GUI.Toolbar (Rect (25, 40, 550, 50), toolbarInt, toolbarStrings);
    if (toolbarInt == 0)
    {
    }
    if (toolbarInt == 1)
    {
    }
    if (toolbarInt == 2)
    {
    }
    if (toolbarInt == 3)
    {
    }
    if (toolbarInt == 4)
    {
    }
    if (toolbarInt == 5)
    {
    }
    if (toolbarInt == 6)
    {
    }
    if (adminDetect == true GUI.Button(Rect (425,325,150,20), "Admin Control Panel"))
    {
    adminFeedBool = false;
    adminCP = true;
    }
    }
    else if (adminCP == true)
    {
    adminFeed = GUI.TextField(Rect (25,25,200,25), adminFeed, 50);
    user = GUI.TextField(Rect (25,50,200,25), user, 50);
    GUI.Label(Rect (230,25,200,25), " Feed");
    GUI.Label(Rect (230,50,200,25), " User to delete");
    if (GUI.Button(Rect (250,325,150,20), "Apply Changes"))
    {
    Apply();
    }
    if (GUI.Button(Rect (425,325,150,20), "Back"))
    {
    adminCP = false;
    }
    }
    }

    if (register == true userOK == false)
    {
    GUI.Box(Rect (100,50,420,300), "Register");
    GUI.Label(Rect (150,80,60,20),"Username:");
    GUI.Label(Rect (150,110,60,20),"Password:");
    GUI.Label(Rect (150,140,60,20),"Email:");
    GUI.Label(Rect (110,170,120,20),"Born (YYYY-MM-DD):");
    GUI.Label(Rect (150,200,60,20),"Nickname:");
    usernameText = GUI.TextField(Rect (210,80,180,20),usernameText, 25);
    passwordText = GUI.PasswordField(Rect (210,110,180,20), passwordText, "*"[0], 25);
    //passwordField.x = 210;
    //passwordField.y = 110;
    //passwordField.w = 180;
    //passwordField.h = 20;
    //passwordField.l = 25;
    //passwordText = passwordField.PasswordField(passwordText, "*");
    email = GUI.TextField(Rect (210,140,180,20),email, 25);
    born = GUI.TextField(Rect (230,170,180,20),born, 25);
    nick = GUI.TextField(Rect (210,200,180,20),nick, 25);
    if (GUI.Button(Rect (300,260,100,100), "Register"))
    registerUsername();
    }
    GUI.Label(Rect (150,300,150,50), console);
    }

    function Apply()
    {
    var feed_url = "http://fantasticoworld.fa.funpic.de/admin.php?command=feed&feed=" + adminFeed;
    var cu_get = WWW(feed_url);
    yield cu_get;

    if(cu_get.error) {
    print("There was an error applying changes: " + cu_get.error);
    }
    else
    {
    if(cu_get.data == "yes")
    {
    feedUpdate();
    }
    else
    {
    print("error could not change!");
    }
    }

    var delete_url = "http://fantasticoworld.fa.funpic.de/admin.php?command=delete&user=" + user;
    var cud_get = WWW(delete_url);
    yield cud_get;

    if(cud_get.error) {
    print("There was an error applying changes: " + cud_get.error);
    }
    else
    {
    if(cud_get.data == "yes")
    {
    feedUpdate();
    }
    else
    {
    print("error could not change!");
    }
    }
    adminCP = false;
    }

    function registerUsername()
    {
    console = "registering you";
    var createuser_url = createuserUrl + "?username=" + usernameText + "&password=" + passwordText + "&email=" + email + "&born=" + born + "&nick=" + nick;
    var cu_get = WWW(createuser_url);
    yield cu_get;

    if(cu_get.error) {
    console = "There was an error registering: " + cu_get.error;
    }
    else
    {
    if(cu_get.data == "registered")
    {
    console = "registered";
    yield WaitForSeconds(3.0);
    register = false;
    }
    else
    {
    console = "Error, please try again";
    }
    }
    }

    function checkUser() {
    console = "Checking Username and Password";
    var getuser_url = getuserUrl + "?username=" + usernameText + "&password=" + passwordText;
    var cu_get = WWW(getuser_url);
    yield cu_get;

    if(cu_get.error) {
    console = "There was an error checking your username and password: " + cu_get.error;
    }
    else
    {
    console = cu_get.data;
    if(console == "right")
    {
    console = "Welcome back " + usernameText + " hope you enjoy the game!";
    yield WaitForSeconds(3.0);
    Application.LoadLevel("new");
    userOK=true;
    }
    else
    {
    userOK = false;
    }
    }

    CheckVersion();
    }
    [ /code]
     
  41. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,434
    You might want to repost and make sure your "code" tags are fixed.
     
  42. HolBol

    HolBol

    Joined:
    Feb 9, 2010
    Posts:
    2,887
    Yeah, dude, you don't put spaces in tags.
     
  43. Magicpickle97

    Magicpickle97

    Joined:
    Feb 19, 2011
    Posts:
    89
    sorry, I was just trying to get rid of all of the error messages
     
  44. Magicpickle97

    Magicpickle97

    Joined:
    Feb 19, 2011
    Posts:
    89
    Code (csharp):
    1.  
    2. private var secretKey="dudi2008"; // Edit this value and make sure it's the same as the one stored on the server
    3.  
    4. var skin:GUISkin;
    5.  
    6. var createuserUrl="http://fantasticoworld.fa.funpic.de/cuser.php";
    7. var getuserUrl="http://fantasticoworld.fa.funpic.de/getuser.php";
    8. var feedURL="http://fantasticoworld.fa.funpic.de/feed.txt";
    9. var usernameText="";
    10. var passwordText="";
    11. var userOK=false;
    12. var console="";
    13. var email = "";
    14. var born = "";
    15. var nick = "";
    16. var feed = "";
    17. var i = 0;
    18. var user = "";
    19. var adminCP = false;
    20. private var register = false;
    21. function createUser(username, password, email, born, nick) {
    22. //This connects to a server side php script that will add the name and score to a MySQL DB.
    23. // Supply it with a string representing the players name and the players score.
    24. var hash = (username + password + email + born + nick + secretKey);
    25.  
    26. var createuser_url = createuserUrl + "username=" + [url]WWW.EscapeURL(username[/url]) + "&password=" + [url]WWW.EscapeURL(password[/url]) + [url]WWW.EscapeURL(email[/url]) + [url]WWW.EscapeURL(born[/url]) + [url]WWW.EscapeURL(nick);[/url]
    27.  
    28. // Post the URL to the site and create a download object to get the result.
    29. var cu_post = WWW(createuser_url);
    30. yield cu_post; // Wait until the download is done
    31. if(cu_post.error) {
    32. print("There was an error creating your user: " + cu_post.error);
    33. }
    34. }
    35.  
    36. var version : int = 1;
    37.  
    38. function CheckVersion()
    39. {
    40. var update_url = "http://fantasticoworld.fa.funpic.de/version.txt";
    41. update_post = WWW(update_url);
    42. yield update_post; // Wait until the download is done
    43. if(update_post.error)
    44. {
    45. print("There was an error loading the update URL: " + update_post.error);
    46. }
    47. else
    48. {
    49. var latestVersion : int;
    50. latestVersion = int.Parse(update_post.data);
    51. if (latestVersion >= version + 1)
    52. {
    53. }
    54. }
    55. }
    56.  
    57. var feedBool = false;
    58. var feed2 = "";
    59. var feedS = true;
    60.  
    61. function Update()
    62. {
    63. if (adminCP == false)
    64. {
    65. adminFeed = feed2;
    66. }
    67. if (userOK == true)
    68. {
    69. if (feedS == true)
    70. {
    71. feedUpdate();
    72. feedS = false;
    73. }
    74. if (i<100000)
    75. {
    76. i++;
    77. }
    78. else
    79. {
    80. feedUpdate();
    81. adminFeed = feed2;
    82. }
    83.  
    84. if (feedBool == true)
    85. {
    86. feed = "Latest News: " + feed2 + " | " + i + " |";
    87. }
    88. }
    89. }
    90.  
    91. function feedUpdate()
    92. {
    93. var feed_get = "http://fantasticoworld.fa.funpic.de/admin.php?command=requestFeed";
    94. feed_post = WWW(feed_get);
    95. yield feed_post;
    96. if(feed_post.error)
    97. {
    98. print("There was an error loading the feed: " + feed_post.error);
    99. feed = "Could not connect to feed";
    100. feedBool = false;
    101. i = 0;
    102. }
    103. else
    104. {
    105. i = 0;
    106. feedBool = true;
    107. feed2 = feed_post.data;
    108. }
    109. }
    110.  
    111. function BeginPage(width,height) {
    112. GUILayout.BeginArea(Rect((width),(height),width,he ight));
    113. }
    114.  
    115. function EndPage() {
    116. GUILayout.EndArea();
    117. }
    118.  
    119. var userToDelete = "";
    120. var feedChange = "";
    121. var adminDetect = false;
    122.  
    123. function detectIsAdmin()
    124. {
    125. var createuser_url = "http://fantasticoworld.fa.funpic.de/verify.php" + "?username=" + usernameText + "&password=" + passwordText;
    126. var cu_get = WWW(createuser_url);
    127. yield cu_get;
    128.  
    129. if(cu_get.error) {
    130. print("There was an error checking admin: " + cu_get.error);
    131. }
    132. else
    133. {
    134. if(cu_get.data == "yes")
    135. {
    136. adminDetect = true;
    137. }
    138. else
    139. {
    140. adminDetect = false;
    141. }
    142. }
    143. }
    144.  
    145. var adminTest = false;
    146.  
    147. var toolbarInt = 0;
    148. var toolbarStrings : String[] = ["Main Menu","Offline Maps", "Servers", "Forum", "Stats", "Map Creator"];
    149. var adminFeed = "";
    150.  
    151.  
    152. function OnGUI()
    153. {
    154. GUI.matrix = Matrix4x4.TRS (Vector3.zero, Quaternion.identity, Vector3 (Screen.width / 600.0, Screen.height / 400.0, 1));
    155. if (skin != null) {
    156. GUI.skin = skin;
    157. }
    158.  
    159. if (register == false  userOK == false)
    160. {
    161. GUI.Box(Rect (125,50,400,300), "Login");
    162. BeginPage(150,100);
    163. GUI.Label(Rect (30,20,60,20), "Username:");
    164. GUI.Label(Rect (30,47,60,20), "Password:");
    165. EndPage();
    166. usernameText = GUI.TextField(Rect (250,117,150,20), usernameText, 25);
    167. passwordText = GUI.PasswordField(Rect (250,145,150,20), passwordText, "*"[0], 25);
    168. //passwordField.x = 250;
    169. //passwordField.y = 145;
    170. //passwordField.w = 150;
    171. //passwordField.h = 20;
    172. //passwordField.l = 25;
    173. //passwordText = passwordField.PasswordField(passwordText, "*");
    174. if (GUI.Button(Rect (300,220,100,20), "Login") || Input.GetKeyDown("return"))
    175. checkUser();
    176. if (GUI.Button(Rect (300,200,100,20), "register"))
    177. {
    178. register = true;
    179. }
    180. }
    181.  
    182. if (register == false  userOK == true)
    183. {
    184. if (adminTest == false)
    185. {
    186. detectIsAdmin();
    187. adminTest = true;
    188. }
    189. GUI.Box(Rect (10,10,575,360), "Main Menu");
    190. if (adminCP == false)
    191. {
    192. GUI.Label(Rect (20,20,500,20), feed);
    193. toolbarInt = GUI.Toolbar (Rect (25, 40, 550, 50), toolbarInt, toolbarStrings);
    194. if (toolbarInt == 0)
    195. {
    196. }
    197. if (toolbarInt == 1)
    198. {
    199. }
    200. if (toolbarInt == 2)
    201. {
    202. }
    203. if (toolbarInt == 3)
    204. {
    205. }
    206. if (toolbarInt == 4)
    207. {
    208. }
    209. if (toolbarInt == 5)
    210. {
    211. }
    212. if (toolbarInt == 6)
    213. {
    214. }
    215. if (adminDetect == true  GUI.Button(Rect (425,325,150,20), "Admin Control Panel"))
    216. {
    217. adminFeedBool = false;
    218. adminCP = true;
    219. }
    220. }
    221. else if (adminCP == true)
    222. {
    223. adminFeed = GUI.TextField(Rect (25,25,200,25), adminFeed, 50);
    224. user = GUI.TextField(Rect (25,50,200,25), user, 50);
    225. GUI.Label(Rect (230,25,200,25), " Feed");
    226. GUI.Label(Rect (230,50,200,25), " User to delete");
    227. if (GUI.Button(Rect (250,325,150,20), "Apply Changes"))
    228. {
    229. Apply();
    230. }
    231. if (GUI.Button(Rect (425,325,150,20), "Back"))
    232. {
    233. adminCP = false;
    234. }
    235. }
    236. }
    237.  
    238. if (register == true  userOK == false)
    239. {
    240. GUI.Box(Rect (100,50,420,300), "Register");
    241. GUI.Label(Rect (150,80,60,20),"Username:");
    242. GUI.Label(Rect (150,110,60,20),"Password:");
    243. GUI.Label(Rect (150,140,60,20),"Email:");
    244. GUI.Label(Rect (110,170,120,20),"Born (YYYY-MM-DD):");
    245. GUI.Label(Rect (150,200,60,20),"Nickname:");
    246. usernameText = GUI.TextField(Rect (210,80,180,20),usernameText, 25);
    247. passwordText = GUI.PasswordField(Rect (210,110,180,20), passwordText, "*"[0], 25);
    248. //passwordField.x = 210;
    249. //passwordField.y = 110;
    250. //passwordField.w = 180;
    251. //passwordField.h = 20;
    252. //passwordField.l = 25;
    253. //passwordText = passwordField.PasswordField(passwordText, "*");
    254. email = GUI.TextField(Rect (210,140,180,20),email, 25);
    255. born = GUI.TextField(Rect (230,170,180,20),born, 25);
    256. nick = GUI.TextField(Rect (210,200,180,20),nick, 25);
    257. if (GUI.Button(Rect (300,260,100,100), "Register"))
    258. registerUsername();
    259. }
    260. GUI.Label(Rect (150,300,150,50), console);
    261. }
    262.  
    263. function Apply()
    264. {
    265. var feed_url = "http://fantasticoworld.fa.funpic.de/admin.php?command=feed&feed=" + adminFeed;
    266. var cu_get = WWW(feed_url);
    267. yield cu_get;
    268.  
    269. if(cu_get.error) {
    270. print("There was an error applying changes: " + cu_get.error);
    271. }
    272. else
    273. {
    274. if(cu_get.data == "yes")
    275. {
    276. feedUpdate();
    277. }
    278. else
    279. {
    280. print("error could not change!");
    281. }
    282. }
    283.  
    284. var delete_url = "http://fantasticoworld.fa.funpic.de/admin.php?command=delete&user=" + user;
    285. var cud_get = WWW(delete_url);
    286. yield cud_get;
    287.  
    288. if(cud_get.error) {
    289. print("There was an error applying changes: " + cud_get.error);
    290. }
    291. else
    292. {
    293. if(cud_get.data == "yes")
    294. {
    295. feedUpdate();
    296. }
    297. else
    298. {
    299. print("error could not change!");
    300. }
    301. }
    302. adminCP = false;
    303. }
    304.  
    305. function registerUsername()
    306. {
    307. console = "registering you";
    308. var createuser_url = createuserUrl + "?username=" + usernameText + "&password=" + passwordText + "&email=" + email + "&born=" + born + "&nick=" + nick;
    309. var cu_get = WWW(createuser_url);
    310. yield cu_get;
    311.  
    312. if(cu_get.error) {
    313. console = "There was an error registering: " + cu_get.error;
    314. }
    315. else
    316. {
    317. if(cu_get.data == "registered")
    318. {
    319. console = "registered";
    320. yield WaitForSeconds(3.0);
    321. register = false;
    322. }
    323. else
    324. {
    325. console = "Error, please try again";
    326. }
    327. }
    328. }
    329.  
    330. function checkUser() {
    331. console = "Checking Username and Password";
    332. var getuser_url = getuserUrl + "?username=" + usernameText + "&password=" + passwordText;
    333. var cu_get = WWW(getuser_url);
    334. yield cu_get;
    335.  
    336. if(cu_get.error) {
    337. console = "There was an error checking your username and password: " + cu_get.error;
    338. }
    339. else
    340. {
    341. console = cu_get.data;
    342. if(console == "right")
    343. {
    344. console = "Welcome back " + usernameText + " hope you enjoy the game!";
    345. yield WaitForSeconds(3.0);
    346. Application.LoadLevel("new");
    347. userOK=true;
    348. }
    349. else
    350. {
    351. userOK = false;
    352. }
    353. }
    354.  
    355. CheckVersion();
    356. }
    357.  
     
  45. Grow

    Grow

    Joined:
    Apr 12, 2011
    Posts:
    335
  46. nhathien_zen

    nhathien_zen

    Joined:
    Mar 2, 2011
    Posts:
    5
    I have same problem , Rob can you fixed??? Or anyone help me same wrong. Thank 4 help me
     
  47. killerscripteres

    killerscripteres

    Joined:
    Oct 18, 2011
    Posts:
    27
    UP
    someone fix that?
     
  48. M_S4

    M_S4

    Joined:
    Jul 21, 2012
    Posts:
    4
    unkown identifer 'passwordField'
    unknown identifer 'md5'

    Pls Help me!
     
  49. davidflynn2

    davidflynn2

    Joined:
    Jul 13, 2012
    Posts:
    23
    Where is the location of the updated code I was wondering if you ever made it avaible?
     
  50. Jamz

    Jamz

    Joined:
    Oct 13, 2012
    Posts:
    1
    Hi there,

    Can you please provide me with the mysql tables.

    Thx.