Jump to content
×
×
  • Create New...

How to make the in-game shop (web browser) automatically login a player on your website


Recommended Posts

This is a little tutorial on how to connect the game to the item shop of your website.

By clicking on the coin in the game client the web browser will be opened and connected to your website.

I'll explain how to automatically login the player to the item shop :)

 

First of all open cmd_general.cpp and look for do_in_game_mall and replace the whole function with this

 


ACMD(do_in_game_mall)
{
		char buf[512+1];
		char sas[33];
		MD5_CTX ctx;

		const char secretKey[] = "my secret key"; // <<--- EDIT THIS!!!
		const char websiteUrl[] = "http://mywebsite/shop"; // <<--- EDIT THIS!!!

		snprintf(buf, sizeof(buf), "%u%s", ch->GetAID(), secretKey);

		MD5Init(&ctx);
		MD5Update(&ctx, (const unsigned char *) buf, strlen(buf));
#ifdef __FreeBSD__
		MD5End(&ctx, sas);
#else
		static const char hex[] = "0123456789abcdef";
		unsigned char digest[16];
		MD5Final(digest, &ctx);
		int i;
		for (i = 0; i < 16; ++i) {
			sas[i+i] = hex[digest[i] >> 4];
			sas[i+i+1] = hex[digest[i] & 0x0f];
		}
		sas[i+i] = '\0';
#endif

		snprintf(buf, sizeof(buf), "mall %s?aid=%u&secret=%s", websiteUrl, ch->GetAID(), sas);

		ch->ChatPacket(CHAT_TYPE_COMMAND, buf);
}

 

Edit secretKey and websiteUrl with your information. The key can be a random string.

 

What happens is the following:

  • aid = account id
  • secret = md5( account id + your secret key )

 

So your website you can check if the secret is corrent and then login the player. You can do something like this:

 

<?php

$secretKey = $_GET['secret'];
$accountId = $_GET['aid'];

$generatedSecret = md5($accountId . $secretKey);

if ($generatedSecret == $secretKey) {
    // ok, proceed with login
} else {
    // invalid secret
}

 

Edited by Cappuccino
  • Love 1
  • Good 3
Link to comment
Share on other sites

  • 3 months later...
On 2/7/2021 at 7:35 PM, Cappuccino said:

This is a little tutorial on how to connect the game to the item shop of your website.

By clicking on the coin in the game client the web browser will be opened and connected to your website.

I'll explain how to automatically login the player to the item shop :)

 

First of all open cmd_general.cpp and look for do_in_game_mall and replace the whole function with this

 



ACMD(do_in_game_mall)
{
		char buf[512+1];
		char sas[33];
		MD5_CTX ctx;

		const char secretKey[] = "my secret key"; // <<--- EDIT THIS!!!
		const char websiteUrl[] = "http://mywebsite/shop"; // <<--- EDIT THIS!!!

		snprintf(buf, sizeof(buf), "%u%s", ch->GetAID(), secretKey);

		MD5Init(&ctx);
		MD5Update(&ctx, (const unsigned char *) buf, strlen(buf));
#ifdef __FreeBSD__
		MD5End(&ctx, sas);
#else
		static const char hex[] = "0123456789abcdef";
		unsigned char digest[16];
		MD5Final(digest, &ctx);
		int i;
		for (i = 0; i < 16; ++i) {
			sas[i+i] = hex[digest[i] >> 4];
			sas[i+i+1] = hex[digest[i] & 0x0f];
		}
		sas[i+i] = '\0';
#endif

		snprintf(buf, sizeof(buf), "mall %s?aid=%u&secret=%s", websiteUrl, ch->GetAID(), sas);

		ch->ChatPacket(CHAT_TYPE_COMMAND, buf);
}

 

Edit secretKey and websiteUrl with your information. The key can be a random string.

 

What happens is the following:

  • aid = account id
  • secret = md5( account id + your secret key )

 

So your website you can check if the secret is corrent and then login the player. You can do something like this:

 


<?php

$secretKey = $_GET['secret'];
$accountId = $_GET['aid'];

$generatedSecret = md5($accountId . $secretKey);

if ($generatedSecret == $secretKey) {
    // ok, proceed with login
} else {
    // invalid secret
}

 

Thanks for share this. I tested it with Chromium, and it works! 

Edited by Equinox
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.