User Control Panel
Advertisements

HELP US, HELP YOU!

P2P in MSN.pm

 
Post new topic   Reply to topic    Bot Depot Forum Index -> MSN.pm Development
View unanswered posts
Author Message
Siebe
God Like
God Like


Joined: 06 Jan 2004
Posts: 562
Location: Netherlands
Reputation: 39.8Reputation: 39.8Reputation: 39.8Reputation: 39.8

PostPosted: Fri Apr 02, 2004 7:49 pm    Post subject: Reply with quote

Ok, so first of all, thanks for letting me in, I hope we can get some good coding work done Smile. I have experience with P2P mostly (if it comes to non-standart protocol stuff that is), DP's CE's, Ink etc.

First of all, I would like to know which of the MSN.pm around here is the latest Wink, so I can look over it and check it out. I think P2P won't be that hard to implent, and I'll make some free time today/this night to get some basics started (-:
Back to top
eric256
The Keymaker
The Keymaker


Joined: 03 May 2006
Posts: 2292
Location: Colorado
Reputation: 47Reputation: 47Reputation: 47Reputation: 47Reputation: 47

PostPosted: Fri Apr 02, 2004 8:16 pm    Post subject: Reply with quote

1.3.10 the one just released beta to the public is the newest. I have a couple of changes but i'm waiting to see if they work. I can add them in to any version without trouble though.

Realy I would love to see spliting it into seperate modules as the next step.


Perhaps Net::MSN,Net::MSN::NameServer,Net::MSN::SwitchBoard, and perhpas Net::MSN::File and Net::MSN::P2P. The Net::MSN would be what the bots talk to. It would handle registering events etc. It would store the user name and create the Initial connection to Ne::MSN::NameServer. The Net::MSN module would also allwo the other modules to register sockets so we have all socket watching done in one central location. So Net::MSN has a do_one_loop that checks all the sockets and sends the appropriate data to the appropriate objects and closes or creates objects as needed. So if you send a file request it would goto the Net::MSN::SwitchBoard (isn't that the chatting one?) and then that could spawn a new Net::MSN::File object. The File object registers the socket it creates with the main so that any time there is new data there it can get called.


I hope that makes some sense. I know that an older version of MSN.pm that i released in this forum is already split out like that. Of course it never got adopted yet so it maybe be easier to re split these out. Could definitly be far easier.

_________________
Eric256
Proud previous owner and current admin of Bot-depot.com
Back to top
Siebe
God Like
God Like


Joined: 06 Jan 2004
Posts: 562
Location: Netherlands
Reputation: 39.8Reputation: 39.8Reputation: 39.8Reputation: 39.8

PostPosted: Fri Apr 02, 2004 8:17 pm    Post subject: Reply with quote

Yes, this would be a big advantage. Especially cause people who want to contribute won't have to digg in heaps of code Wink

Err, ok, lemme get that version Smile
Thanks, I'll post whenever I got something for you guys Wink
Back to top
Siebe
God Like
God Like


Joined: 06 Jan 2004
Posts: 562
Location: Netherlands
Reputation: 39.8Reputation: 39.8Reputation: 39.8Reputation: 39.8

PostPosted: Fri Apr 02, 2004 10:27 pm    Post subject: Reply with quote

Ok, let me see. I've got the MSNObject sorted, and I'm now ready to implent the P2P transfers.. But I need to get the <*lazy*>raw message from the server, any ideas? I've looked in CMD_MSG, but I can't really make up how to get the raw message.. Hm.

Edit: Nevermind, I got it sorted. Apparantly $header would do aswel Wink
*goes back to work*
Back to top
Siebe
God Like
God Like


Joined: 06 Jan 2004
Posts: 562
Location: Netherlands
Reputation: 39.8Reputation: 39.8Reputation: 39.8Reputation: 39.8

PostPosted: Sat Apr 03, 2004 12:06 am    Post subject: Reply with quote

Well, here goes Very Happy
I've done my best to make it as simple as possible, and this should be about it for DP transfers. Let me know if you find bugs, so I can solve them Smile.

At the moment a DP is set using "$self->display_picture("");". This ofcourse can be changed, but I think we can keep it this way since then the user can decide whether to take a DP or not.

Thanks to Eric for his uberleet ( Razz) andromeda to test this Smile

Quote:
- Two new modules (standart):
MIME::Base64
Digest::SHA1 qw(sha1 sha1_hex sha1_base64);

- New variables:
my ($DPData, $MSNObject);
my %p2ptransfers = ();

- set_status has changed:
sub set_status {
  my $self = shift || croak(strMethodOnly);
  my $status = shift || 'NLN 536870964';
  $self->GetMaster->send('CHG', $status.' '.$MSNObject)
}

- New sub 'display_picture':
=head2 display_picture

Sets your display picture

$msn->display_picture("path/to/file.png");

=cut

sub display_picture {
my $self = shift || croak(strMethodOnly);
my $file = shift;

if(!$file) {
  # Remove DP
  $MSNObject = ""; $DPData = "";
 
} else {
  if(-e $file) {
   # Read the file, store it and make the MSNObject
   open(DP, $file); binmode(DP);
   while() { $DPData .= $_; }
   close($file);
  
   # SHA1D and first part of object
   my $sha1d = sha1_base64($DPData).'=';
   my $object = '  
   # SHA1C
   my $sha1c = $object;
      $sha1c =~ s/      $sha1c =~ s/(.*?)=\"(.*?)\" (.*?)=\"(.*)\"/$1$2" $3$4"/g;
      $sha1c =~ s/\s//g;
      $sha1c =~ s/\"//g;
      $sha1c = sha1_base64($sha1c).'=';
 
   # Finish
   $MSNObject = uri_escape($object.' SHA1C="'.$sha1c.'" />');
  
   # Set new status & return
   $self->set_status();
   return 1;
  
  } else {
   carp "Could not find the file $file";
   return 0;
  }
}
}

- New reference to sub in CMD_MSG:
elsif ($header->{'Content-Type'} =~ /application\/x-msnmsgrp2p/)
{
$self->p2p_transfer($user, $msg);   
}

- New sub for creating / getting DWords:
sub MakeDWord {
my $word = shift;
my $little = shift;

my $a = ($word / 16777220) % 256;
my $b = ($word / 65536) % 256;
my $c = ($word / 256) %256;
my $d = $word % 256;

return ($little ? chr($a).chr($b).chr($c).chr($d) : chr($d).chr($c).chr($b).chr($a));
}

sub GetDWord {
my $word = shift;
my $little = shift;

my $a = ord(substr($word, 0, 1));
my $b = ord(substr($word, 1, 1));
my $c = ord(substr($word, 2, 1));
my $d = ord(substr($word, 3, 1));

$a = $little ? $a * 16777220 : $a;
$b = $little ? $b * 65536 : $b * 256;
$c = $little ? $c * 256 : $c * 65536;
$d = $little ? $d: $d * 16777220;

return ($a+$b+$c+$d);
}

- New sub p2p_transfer:
sub p2p_transfer {
my $self = shift || croak(strMethodOnly);
my $user = shift;
my $data = shift;

# Grab parameters if this is an invitation
my ($euf, $sessid, $callid, $branch, $context);
if(index($data, "INVITE MSNMSGR:") > 0) {
  my @lines = split("\n", $data);
  foreach my $param (@lines) {
   if($param) {
    my @value = split(' ', $param);
    my $cmd = $value[0];
   
    if($cmd eq "EUF-GUID:") {   $euf = $value[1];
    } elsif($cmd eq "SessionID:") { $sessid = $value[1];
    } elsif($cmd eq "Call-ID:") {  $callid = $value[1];
    } elsif($cmd eq "Via:") {   $branch = substr($param, index($param, 'branch=')+7);
    } elsif($cmd eq "Context:") {  $context = decode_base64($value[1]);
    }
   }
  }
}

# Grab binary fields
my %fields;
$fields{1} = substr($data, 0, 4);
$fields{2} = substr($data, 4, 4);
$fields{4} = substr($data, 16, Cool;
$fields{7} = substr($data, 32, 4);
$fields{8} = substr($data, 36, 4);

# Check if this a start of a new transfer
if($euf) {
  # Make a unique BID
  MakeBaseID:
  my $bid = 1000 + int(rand(10000000));
  if($p2ptransfers{$bid}{SessionID}) { goto MakeBaseID; }
 
  # Then send the BaseID message
  my $bin = (chr(0)x4).MakeDWord($bid).(chr(0)xCool.$fields{4}.(chr(0)x4).MakeDWord(2).$fields{2}.$fields{7}.$fields{4}.(chr(0)x4);
     $bin = "MIME-Version: 1.0\*lazy*\nContent-Type: application/x-msnmsgrp2p\*lazy*\nP2P-Dest: $user\*lazy*\n\*lazy*\n$bin";
  $self->_send("MSG 99 D ".length($bin)."\*lazy*\n$bin");
   
  # Check if this is a Emote/DP/FTP
  if ($euf eq '{A4268EEC-FEC5-49E5-95C3-F126696BDBF6}') {
   # DP or Emote
   if($context =~ /msnpm\.tmp/) {
    # DP
    # Store information we need later on
    $p2ptransfers{$bid}{SessionID} = $sessid;

    # Then send the 200OK   
    my $okdata = "\*lazy*\n\*lazy*\nSessionID: $sessid\*lazy*\n\0";
       $okdata = "MSNSLP/1.0 200 OK\*lazy*\n" .
           "To:            "From: {bot}->{settings}->{Handle}."\*lazy*\n" .
           "Via: MSNSLP/1.0/TLP ;branch=$branch\*lazy*\n" .
           "CSeq: 1 \*lazy*\n" .
           "Call-ID: $callid\*lazy*\n" .
           "Max-Forwards: 0\*lazy*\n" .
              "Content-Type: application/x-msnmsgr-sessionreqbody\*lazy*\n" .
           "Content-Length: ".length($okdata).$okdata;
    my $bin = (chr(0)x4).MakeDWord($bid-3).(chr(0)xCool.MakeDWord(length($okdata)).(chr(0)x4).MakeDWord(length($okdata)).(chr(0)x4).MakeDWord(100).(chr(0)x4).(chr(0)xCool;
       $bin = "MIME-Version: 1.0\*lazy*\nContent-Type: application/x-msnmsgrp2p\*lazy*\nP2P-Dest: $user\*lazy*\n\*lazy*\n$bin$okdata".(chr(0)x4);
    $self->_send("MSG 99 D ".length($bin)."\*lazy*\n$bin");
   
   } else {
    # ToDo: Emotes
   }
 
  } elsif($euf eq '{5D3E02AB-6190-11D3-BBBB-00C04F795683}') {
   # ToDo: FTP
  }
 
} else {
  my $bid = GetDWord($fields{7});
  my $process = GetDWord($fields{8});
  if($process == 100) {
   # Send the DataPrep message
   $bid+=3;
   my $bin = MakeDWord($p2ptransfers{$bid}{SessionID}).MakeDWord($bid-2).(chr(0)xCool.MakeDWord(4).(chr(0)x4).MakeDWord(4).(chr(0)x4).MakeDWord(101).(chr(0)xCool.(chr(0)xCool.MakeDWord(4, 1);
      $bin = "MIME-Version: 1.0\*lazy*\nContent-Type: application/x-msnmsgrp2p\*lazy*\nP2P-Dest: $user\*lazy*\n\*lazy*\n$bin";
   $self->_send("MSG 99 D ".length($bin)."\*lazy*\n$bin");
  
  } elsif($process == 101) {
   # Send the actual DP data
   $bid+=2;
  
   # Predefined values (this saves time instead of having to create them in each loop)
   my $L = 1;
   my $FileL = MakeDWord(length($DPData));
   my $BID = MakeDWord($bid-1);
   my $SID = MakeDWord($p2ptransfers{$bid}{SessionID});
  
   do {
       my $TFileD = substr($DPData, $L-1, 1202);
       my $bin = $SID.$BID.MakeDWord($L-1).(chr(0)x4).$FileL.(chr(0)x4).MakeDWord(length($TFileD)).(chr(0)x4).MakeDWord(102).(chr(0)x4).(chr(0)xCool.$TFileD.MakeDWord(4, 1);
          $bin = "MIME-Version: 1.0\*lazy*\nContent-Type: application/x-msnmsgrp2p\*lazy*\nP2P-Dest: $user\*lazy*\n\*lazy*\n$bin";
    $self->_send("MSG 99 D ".length($bin)."\*lazy*\n$bin");
       $L += length($TFileD);
   } while ($L < length($DPData));

   # Remove object from p2ptransfers hash
   # We are done *big smile*
   delete $p2ptransfers{$bid};
  
  }
 
}
}


PS. Bit of a problem here, you all have a 3 letter code, but I only have one name lol. "st" would do Razz
Back to top
eric256
The Keymaker
The Keymaker


Joined: 03 May 2006
Posts: 2292
Location: Colorado
Reputation: 47Reputation: 47Reputation: 47Reputation: 47Reputation: 47

PostPosted: Sat Apr 03, 2004 1:29 am    Post subject: Reply with quote

Do you have a DP i could use? Or at least what restrictions are there on the pic you choose?
_________________
Eric256
Proud previous owner and current admin of Bot-depot.com
Back to top
Siebe
God Like
God Like


Joined: 06 Jan 2004
Posts: 562
Location: Netherlands
Reputation: 39.8Reputation: 39.8Reputation: 39.8Reputation: 39.8

PostPosted: Sat Apr 03, 2004 1:33 am    Post subject: Reply with quote

Thanks to Keenie for spotting a bug. Fixed now (please change it yourself, I've underlined it, or download the new module again).

And erm, here are some DP's.
There is no restriction really, except that it HAS to be PNG.
Back to top
Siebe
God Like
God Like


Joined: 06 Jan 2004
Posts: 562
Location: Netherlands
Reputation: 39.8Reputation: 39.8Reputation: 39.8Reputation: 39.8

PostPosted: Sat Apr 03, 2004 3:04 am    Post subject: Reply with quote

Well, know that I know Eric hates globals I rewrote some parts, and stumbled on a bug (fixed now Smile). Have fun.
I'll do emoticons tomorrow Wink
Back to top
eric256
The Keymaker
The Keymaker


Joined: 03 May 2006
Posts: 2292
Location: Colorado
Reputation: 47Reputation: 47Reputation: 47Reputation: 47Reputation: 47

PostPosted: Sat Apr 03, 2004 6:22 pm    Post subject: Reply with quote

Any ideas why this works for messenger 6.1 but not for trillian?
_________________
Eric256
Proud previous owner and current admin of Bot-depot.com
Back to top
Siebe
God Like
God Like


Joined: 06 Jan 2004
Posts: 562
Location: Netherlands
Reputation: 39.8Reputation: 39.8Reputation: 39.8Reputation: 39.8

PostPosted: Sat Apr 03, 2004 7:02 pm    Post subject: Reply with quote

Does Trillian support the full P2P?
Back to top
Display posts from previous:   
Post new topic   Reply to topic    Bot Depot Forum Index -> MSN.pm Development All times are GMT
Page 1 of 1

 



Protected by phpBB Security phpBB-TweakS
phpBB Security Has Blocked 9 Exploit Attempts.
Antispam Captcha Mod by phpbb-security.com
Powered by phpBB © 2001, 2005 phpBB Group