Web Registration Check

Web Registration Check

Postby dzienny » 20 Jun 2012, 18:03

The web registration check feature was added in the version 8.2 of MCDzienny.
It lets an owner of a server to require a web/forum registration of players for being able to buy a higher rank in a shop.
The feature is turned off by default as it will be useful only for a handful of servers. Also a knowledge of programming is needed in order to make it work correctly.

Below is the example of the plugin that is needed at an MCDzienny server side:
Code: Select all
using System.IO;
using System.Net;

namespace MCDzienny
{
    public class CmdRegistrationCheck : Command
    {
        // Don't change it.
        public override string name { get { return ""; } }
        public override string shortcut { get { return ""; } }
        public override string type { get { return ""; } }
        public override bool museumUsable { get { return false; } }
        public override LevelPermission defaultRank { get { return LevelPermission.Banned; } }

        // Init is executed only once when the server starts.
        public override void Init()
        {
            // In the following line you tell the program to invoke DoRegistrationCheck
            // method when a player registration check is needed.
            Player.PlayerRegisteredCheck += DoRegistrationCheck;
        }

        // Here's the place where you want to write your registration check.
        // The code has to include a part where it connects to your website
        // and ask it whether the calling user is registered or not.
        // This requires some sort of communication method between
        // your web server and your minecraft server.
        // The easiest way I can think of is using a POST/GET HTTP method.
        // You can code a web server part of a code in PHP for example.

        // Player p - player that is a subject of a check,
        // bool isRegistered - variable that is by default set to 'false'
        //                     if the player is recognized as registered
        //                     you have to set this variable to 'true'.
        // *When the isRegistered for a player is set to 'true' this state
        // is saved to a database, so that the check will not be performed
        // again and again, as it'd be pointless.
        private void DoRegistrationCheck(Player p, ref bool isRegistered)
        {
            // Assuming that you decided to use GET HTTP method, example:
            string query;
            query = "http://writeYourWebsiteAddressHere.com/yourSubpageJustForRespondingToQueries.php?player-name=" + p.name;

            using (StreamReader sr = new StreamReader(WebRequest.Create(query).GetResponse().GetResponseStream()))
            {
                // 1. The first line of the response is read.
                // 2. Then the white spaces at the beginning and at the end are
                // removed.
                // 3. Then the text is changed to the lowercase.
                // *You don't really have to do the 2. and 3. step
                // if you do your web site coding well.
                string result = sr.ReadLine().Trim().ToLower();

                // In this example the php site is returing "ok" text
                // if a player is found in the web site database.
                // No action is needed if he is not found.
                if (result == "ok")
                {
                    isRegistered = true;
                }
            }
        }

        // Don't change it.
        public override void Help(Player p) { }
        public override void Use(Player p, string message) { }
    }
}


*The default message in case a player is not registered is: "%cYou have to register on the forum before you can get a higher rank!". You can define your own message by a following line to 'messages/messages.txt' file :
Code: Select all
RegistrationRequired = "Your message"
User avatar
dzienny
Administrator
 
Posts: 1181
Joined: 23 Jan 2011, 14:27

Re: Web Registration Check

Postby Lapito » 20 Nov 2012, 22:07

I want to put this in my server, but I can't find anyone that can make a registration checker for xenforo :(
Lapito
 
Posts: 24
Joined: 08 Feb 2011, 00:17


Return to Help in Coding

Who is online

Users browsing this forum: No registered users and 4 guests

cron