Jump to content

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
  • Good 3
  • Love 1
Link to comment
Share on other sites

  • 3 months later...
  • Premium
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

  • 2 years 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 the share bro, i was triyng to use your system but i cant make the php side read the info and make the authentication.

Could u please share more info about how to adapt? I use an itemshop shared by @ TMP4 

 

Quote

 

The authentication code block:

 

<?php
if(isset($_POST['login']) && $_POST['login'] == 'Login') {
  $user = mysqli_real_escape_string($sqlServ, $_POST['user']);
  $pw = mysqli_real_escape_string($sqlServ, $_POST['pw']);
  $SQLF = "SELECT * from account.account where login = '$user' and password = PASSWORD('$pw')";
  $check = mysqli_query($sqlServ, $SQLF);
  $num = mysqli_num_rows($check);

  if($num > 0) {

    $array = mysqli_fetch_array($check);
    $_SESSION['id'] = $array['login'];
    $_SESSION['acc_id'] = $array['id'];
    $_SESSION['coins'] = $array['coins'];
    $_SESSION['status'] = $array['status'];
    $_SESSION['email'] = $array['email'];
    $_SESSION['real_name'] = $array['real_name'];
    $_SESSION['social_id'] = $array['social_id'];

    echo'<meta http-equiv="refresh" content="0; URL=?s=home"> ';
  } else {
    echo '<div class="boxui box-title"></div>
		<div class="boxui box-con">
		<div class="wrap">
		<br /><br /><font color="red"><b>wrong User or password.</b></font><br /><br /><br />
		</div>
		</div>
		<div class="boxui box-end"></div>';
  }
}
?>

 

@ piktorvik could you please share your authentication code is? i've tried my best but couldn't do it work 😕

  • Metin2 Dev 1
Link to comment
Share on other sites

  • 2 weeks later...

Announcements



×
×
  • Create New...

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.