WULogin FAQ

Q: How do I get started?
Q: Why do I only see a blank screen after Login?
Q: What data can I fetch during login?
Q: Am I supposed to see the PostLogin screen after login?
Q: Why are the static values in WULogin empty directly after login?
Q: What does the error: “Necessary data rewind not possible” mean?
Q: Can I save data to my WordPress database if I install this kit?
Q: I have a user management plugin installed. Is this kit compatible with that?
Q: If I want to add custom behaviour or integrate this kit with other WP plugins, does this kit allow for that?
Q: What does the error: “Invalid message length” mean?


Q: How do I get started?
Q: Why do I only see a blank screen after Login?

The WordPress Login kit will authenticate your identity and log you in if your credentials match up. Once it’s done that, it triggers an event to tell you “You are successfully logged in”. It is now up to you to decide what you want to do now. Example: Load the next scene… How you do that is by first registering to the event and then running your own code once the event fires. This means 2 things:

  1. The login kit can be up and running in under 2 minutes and do what it’s supposed to do, but for your game to integrate with it you will need to write an extra script or function of your own
  2. You never need to edit anything in this kit to make it do custom things in your project. Just wait for the event to fire then tell your project to do whatever it is you want to happen when that happens

Example:
Create a new script and add the following:

void Start()
{
    WULogin.onLoggedIn += LoadNextLevel;
}

void LoadNextLevel(CML response)
{
    SceneManager.LoadScene("MainMenu");
}

Q: What data can I fetch during login?

In the inspector you will find a number of checkboxes that you can tick to select what fields you want to return from the WP_users table. Right below that you will find an array where you can specify any field you desire and that is basically the short answer to this question: If the field exists in usermeta then it can be fetched. Just enter it’s name in the array and immediately after successful login that information will be available to your application


Q: Am I supposed to see the PostLogin screen after login?

No. If you show the prefab while not logged in then the main login screen shows to give you the option of logging in or creating an account. If you show the prefab while you are logged in, those options are pointless. Instead, then you show the PostLogin page to give them the option to log out or to go back to playing the game. See the demo scene for an example of how to show the prefab with the PostLogin screen


Q: Why are the static values in WULogin empty directly after login?

I have attempted to fix this issue but some people still sometimes report having this issue pop up so let me explain it in case you ever encounter it. When you login the kit sends the success event to every function that is listening for it. Usually there will be at least 2 functions that respond to it. One is the one that you created to run your own code after login. The other is one of mine that takes the server’s response and stores it statically for your ease of use later. Depending on which function runs first, the static data will be available or it will not.

Just to play it safe I would recommend you use the static fields anywhere in your project EXCEPT in your login success event response function. All the data that will be stored statically are also passed to your function so simply use the data that was passed to your function rather than relying on the static data.

Example:

void AfterLogin(CML response)
{
    string nickname = response[0].String("nickname");
    string email = response[0].String("user_email");
}

Q: What does the error: “Necessary data rewind not possible” mean?

This means that the URL you are giving the WULogin plugin is no a direct link to your site and that it get redirected first. Unity’s WWW class does not support this redirection so you will need to find out where and why and how your URL is getting redirected and figure out the solution from there.

This is mostly related to how your server is setup. Many people don’t realise that www is simply a subdomain like any other subdomain and that some websites are setup to forward any link that starts with www to just / while others work the other way around. Other sites have http redirect to https while others use framed redirects to make www.mysite.com point to www.someothersite.com/users/12345/wordpress for example.

If you are getting that error then it means you need to give my plugin the URL of your website up to the folder that CONTAINS wp-content. I.e. if WordPress is installed at www.mysite.com then wp-content will be located at www.mysite.com/wp-content so you need to give my prefab the url http://www.mysite.com

One customer spent 2 days trying to get past this rewind error. I told her to remove “www.” from her URL and it worked perfectly. It turns out her site was redirecting all www traffic to /.

Another customer struggled for days to get past this error so I told him to change “http” to “https” and it worked perfectly. Turns out his server was setup to forward all http calls to https.

You need to figure out what is causing your URL to be forwarded and then use the final, forwarded url as the url in the prefab.


Q: Can I save data to my WordPress database if I install this kit?

Mostly when people ask that question they mean “any data” and the short answer is no. However, with that being said, the information that WordPress creates for all users when their account is created (username, web site url, AIM, biography etc) that info is available to you via the kit and that information you can modify as much as you want.


Q: I have a user management plugin installed. Is this kit compatible with that?

That is a bit of a tricky one to answer since “compatible” is a very broad term. If there is any information that you need from that other plugin and that information is stored in the usermeta table then, yes, you can fetch that info back, no problem at all. If the plugin contains data that you need but which it stores in custom tables then, no, this kit does not support that right out of the box, no.

One customer did have this request once and it took something like 3 lines of code to fetch the data he wanted and pass that along with the login information and provide the compatibility he wanted. For further customisation a little more work will be needed but this kit is designed to be super, super easy to modify to add new features of whatever nature you require.


Q: If I want to add custom behaviour or integrate this kit with other WP plugins, does this kit allow for that?

Absolutely yes. There are a number of security precautions in place to prevent tampering with your website (I take care of that so you don’t have to worry about that) but with that said, adding new functions to the kit(s) is extremely, EXTREMELY simple and only has a few steps…

  1. Each kit has a CONST value defined within it inside of Unity. The login kit has the value “LOGIN”, for example. What you need to do is open the file named unity_functions.php and create a function that starts with the CONST value from the kit you wish to extend (but in lower case) followed by whatever name you want to call the function. After that, just add your custom code to that function. That easy.
    Example:

    function loginHalloWorld() {}
  2. Your output from the function must be sent back as a single string or else WindowsRT platforms will throw out errors. Always use only my SendNode and SendField functions to format your response as proper CML. When ready, send the base64 encoded results to Unity using the SendToUnity function. Errors can be reported using the PrintError function.
    Example:

    function loginHalloWorld()
    {
      if (!current_user_can("read"))
      {
         SendToUnity( PrintError("This user doesn't even have read authority") );
         return;
      } 
    
      global $current_user;
      $favorite_color = get_user_meta($current_user->ID, "fav_color", true);
      $response = SendNode("custom data");
      $response .= SendField("five", 5);
      $response .= SendField("favorite_color", $favorite_color);
      SendToUnity($response);
    }
  3. In Unity, duplicate one of the functions in WULogin.cs that call WPServer.ContactServer (or create one yourself. Duplicating it just saves you some typing) and for the action to perform, pass it the name of your function, minus the prefix and that is it. You have now added a custom action to the kit.
    Example:

    public void CallMyFunction(CML onSuccess, cmlData onFailed = null)
    {
    WPServer.ContactServer("HalloWorld", login_filepath, LOGINConstant, null, onSuccess, onFailed);
    }

    Done. You now have a function, complete with error handling, that you can call to trigger your custom function


Q: What does the error: “Invalid message length” mean?

You should look at this error as a guardian angel looking out for you. The WUSS kits request data from the server and then parses the result into the data you requested. If there is anything wrong on your website your website will attempt to tell you via HTML that it assumes will appear in a web browser. Also, some plugins that you might have installed on your website might deem itself so important that it will send data with every page request. These two situations will result in invalid data being sent along with the server response but thanks to how I am sending the data from the server this invalid data gets reported as an error message rather than getting parsed and invalidating your received data.

Simply Look at what the server response is and you will see it contains garbled text (the valid data) as well as HTML code that will either tell you what problem your website is reporting or it will give you a clue as to what plugin on your website needs some adjustment.

So, in short, this error is telling you that there is something wrong on your website and letting you know in advance that this problem would lead to your data being invalid. It gives you a chance to fix whatever is wrong with your site before publishing and ending up with a broken game.