mChat add message

Support for mods released by phpbbmodders.net found at either https://github.com/phpbbmodders/ or the MODDB at http://www.phpbb.com
Forum rules
Please only request support for mods released by phpbbmodders.net found at either https://github.com/phpbbmodders/ or the MODDB at http://www.phpbb.com
User avatar
tumba25
Supporter
Supporter
Posts: 1049
Joined: 24 Oct 2007, 13:10
Real name: Jari Kanerva
Location: Kokkola, Finland.
Contact:

Re: mChat add message

Post by tumba25 »

Ok, great. I'll set up a test site. phpBB 3.0 or 3.1?
deejay_xb
Member
Member
Posts: 87
Joined: 03 Apr 2011, 06:29
Contact:

Re: mChat add message

Post by deejay_xb »

phpbb 3.0.12 :D
Image
User avatar
tumba25
Supporter
Supporter
Posts: 1049
Joined: 24 Oct 2007, 13:10
Real name: Jari Kanerva
Location: Kokkola, Finland.
Contact:

Re: mChat add message

Post by tumba25 »

Now it's up, sorry for the delay. That forum is only up temporarily and will be deleted as soon as your app is done or development stops for some other reason.

You will need to register.

Code: Select all

mchat.dark-side.net
deejay_xb
Member
Member
Posts: 87
Joined: 03 Apr 2011, 06:29
Contact:

Re: mChat add message

Post by deejay_xb »

ty, but i need to find how the autogenerate form_token is made..
maybe rich can help?
Image
User avatar
tumba25
Supporter
Supporter
Posts: 1049
Joined: 24 Oct 2007, 13:10
Real name: Jari Kanerva
Location: Kokkola, Finland.
Contact:

Re: mChat add message

Post by tumba25 »

deejay_xb wrote:maybe rich can help?
Hope so. I'll play around with the Android studio later to see if I can get the same result as mChat.
User avatar
RMcGirr83
Supporter
Supporter
Posts: 6242
Joined: 30 Nov 2006, 14:23
Real name: Rich McGirr

Re: mChat add message

Post by RMcGirr83 »

The form token is generated within the includes/functions.php file within the add_form_key function which is done within mchat.php file via add_form_key('mchat_posting');
deejay_xb
Member
Member
Posts: 87
Joined: 03 Apr 2011, 06:29
Contact:

Re: mChat add message

Post by deejay_xb »

this is in functions.php

Code: Select all

$now = time();
	$token_sid = ($user->data['user_id'] == ANONYMOUS && !empty($config['form_token_sid_guests'])) ? $user->session_id : '';
	$token = sha1($now . $user->data['user_form_salt'] . $form_name . $token_sid);
time() is current php time;
$token_sid = $user->session_id;
$form_name = 'mchat_posting';

so $token = sha1( time() $user->data['user_form_salt'] mchat_posting $user->session_id )

is this ok?

edit:
example:
time() = 1421591728
user_form_salt = 68cb19d150c03331
form_name = mchat_posting
user_session_id = 866c119c443d2828691acc126bb92291
token = 142159172868cb19d150c03331mchat_posting866c119c443d2828691acc126bb92291

correct or not?
Image
User avatar
tumba25
Supporter
Supporter
Posts: 1049
Joined: 24 Oct 2007, 13:10
Real name: Jari Kanerva
Location: Kokkola, Finland.
Contact:

Re: mChat add message

Post by tumba25 »

Ok, played a bit with this, here is what I found.

Code: Select all

$token_sid = ($user->data['user_id'] == ANONYMOUS && !empty($config['form_token_sid_guests'])) ? $user->session_id : '';
That makes $token_sid empty for logged in users. It only holds a value for guests. And the form name is mchat_posting.

This is the data needed to create the token.

Code: Select all

$now       = time();
$form_salt = $user->data['user_form_salt'];
$form_name = 'mchat_posting';
$token_sid = ''; 

$token = sha1($now . $form_salt . $form_name . $token_sid);
User avatar
tumba25
Supporter
Supporter
Posts: 1049
Joined: 24 Oct 2007, 13:10
Real name: Jari Kanerva
Location: Kokkola, Finland.
Contact:

Re: mChat add message

Post by tumba25 »

You will also need $config['form_token_lifetime']. If it's -1, then you don't need to bother with the form creation time. If not, you need to.

Code: Select all

$max = max(30, $config['form_token_lifetime']);
$diff = time() - abs($form_creation_time);
if ($diff <= $max) {
    // Good to go.
} else {
    // Form to old, need a new one.
}
User avatar
tumba25
Supporter
Supporter
Posts: 1049
Joined: 24 Oct 2007, 13:10
Real name: Jari Kanerva
Location: Kokkola, Finland.
Contact:

Re: mChat add message

Post by tumba25 »

@RMcGirr83: Do you have a non mini version of mchat_ajax_mini.js?

@deejay_xb: You really need to get the form token and form created time from mChat. The best would have been a API, but since the author didn't think about that you need to scrape it from the site.
User avatar
RMcGirr83
Supporter
Supporter
Posts: 6242
Joined: 30 Nov 2006, 14:23
Real name: Rich McGirr

Re: mChat add message

Post by RMcGirr83 »

tumba25 wrote:@RMcGirr83: Do you have a non mini version of mchat_ajax_mini.js?
It is in the download of the mod within the contrib directory
User avatar
tumba25
Supporter
Supporter
Posts: 1049
Joined: 24 Oct 2007, 13:10
Real name: Jari Kanerva
Location: Kokkola, Finland.
Contact:

Re: mChat add message

Post by tumba25 »

RMcGirr83 wrote:
tumba25 wrote:@RMcGirr83: Do you have a non mini version of mchat_ajax_mini.js?
It is in the download of the mod within the contrib directory
So it is, thanks.
deejay_xb
Member
Member
Posts: 87
Joined: 03 Apr 2011, 06:29
Contact:

Re: mChat add message

Post by deejay_xb »

ok so token is sha1('time''user_form_salt''mchat_posting')
:D
and it seems that is correct:

Code: Select all

time() = 1421591728
user_form_salt = 68cb19d150c03331
form_name = postform
string = 142159172868cb19d150c03331mchat_posting

token = sha1(142159172868cb19d150c03331mchat_posting)
token = 379ad196d7b4b446d96b882f3ce231ddb50a90fc
and

Code: Select all

mchat autogenerated form_token = 379ad196d7b4b446d96b882f3ce231ddb50a90fc
Image
User avatar
RMcGirr83
Supporter
Supporter
Posts: 6242
Joined: 30 Nov 2006, 14:23
Real name: Rich McGirr

Re: mChat add message

Post by RMcGirr83 »

The code you posted doesn't look anything like what tumba25 posted. Well it does but it isn't correct. Use what tumba25 posted.
deejay_xb
Member
Member
Posts: 87
Joined: 03 Apr 2011, 06:29
Contact:

Re: mChat add message

Post by deejay_xb »

do i need something else because:

Code: Select all

http://www.gameforest.ro/mchat.php?mode=add&message=testdecacat2&addbbcode20=100&addbbcode_custom=%23&creation_time=1421350220&form_token=cc82c5c4493aa22shjewja6800618817930fe57
does not work.. it does nothing, no error, no message in mchat..
Image
Post Reply