GIDForums  

Go Back   GIDForums > Computer Programming Forums > MySQL / PHP Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rating: Thread Rating: 7 votes, 5.00 average.
  #1  
Old 19-Jan-2003, 03:44
Andrew Andrew is offline
Member
 
Join Date: May 2002
Location: Yarm, Teesside, England
Posts: 145
Andrew will become famous soon enough
Exclamation

PHP MSN Scripty Thing



The following script no-longer works due to MSN changing their protocols. Please see the last post in this thread for a newer version.

* Andrew has been very busy over the last few months *

I got bored :P So... I decided to do something challenging (Micro$oft stuff) and attempt to write a PHP MSN Bot thingy.

http://mysober.co.uk/msn/ :grin:


index.php
PHP Code:

<?php
$rand=rand(1,9999999);
require("common.php");


// *** Challenge ***
function challenge($output){
  global $fp;
  list($cmd, $zero, $stuff) = explode(" ", $output);
  $stuff=trim($stuff);
  $replymd5 = md5($stuff . "Q1P7W2E4J9R8U3S5");
  sendmessage("QRY 10 [email]msmsgs@msnmsgr.com[/email] 32\r\n". trim($replymd5));
  }

// *** Switchboard ***
function switchboard($output){
  global $passport, $rand;
  list ($aaa,$sid,$chatipy,$aac,$hash,$aae,$name) = split(" ", $output);
  list ($chatip,$aae) = split(":", $chatipy);
  $name=urldecode($name);
  $name=emoticon($name);
  $output=urlencode($output);
  $passport=urlencode($passport);

  echo"<script>window.open('sb.php?passport=". $passport ."&output=". $output ."','". $rand ."','width=400,height=400,status=no,toolbar=no,menubar=no,scrollbars=yes');</script>";
  }

// *** Connect ***
function connect(){
  global $passport, $password, $fp, $protocolversion;
  //check connection
  $fp = fsockopen("messenger.hotmail.com",1863, $errno, $errstr, 30);
  //Send msn version codes
  sendmessage("VER 3 ". $protocolversion ." CVRO\r\n");
  readdata();
  //more stuff
  sendmessage("INF 4\r\n");
  readdata();
  //send user name
  sendmessage("USR 5 MD5 I $passport\r\n");
  $notipx = readdata();


  @list ($aaa,$aab,$aac,$notipy,$aad) = split(" ", $notipx);
  @list ($notip,$aae) = split(":", $notipy);
  fclose($fp);
  $fp = fsockopen($notip,1863, $errno, $errstr, 30);
  //socket_set_blocking($fp,FALSE);

  sendmessage("VER 3 ". $protocolversion ." CVRO\r\n");
  readdata();

  sendmessage("INF 4\r\n");
  readdata();

  sendmessage("USR 5 MD5 I $passport\r\n");
  $reply=readdata();
  list($one,$two) = split("USR 5 MD5 S ",$reply, 2);
  $password="$two$password";
  $password=str_replace("\r\n","","$password");
  $password=md5($password);

  sendmessage("USR 6 MD5 S $password\r\n");
  readdata();

  sendmessage("CHG 9 NLN\r\n");
  readdata();

  sendmessage("REA 254 This%20is%20a%20Bot\r\n");
  readdata();

  sendmessage("SYN 8 0");
  readdata();

  }

if($passport!=""){
?>
<html>
<head>
<SCRIPT LANGUAGE="JavaScript">
function black() {
document.bgColor = "#000000";
}
var I = 0;
function scrollit() {
if (I == "1") {stop = true}
else {
self.scroll(0,999999999999999999999999999999999999);
setTimeout("scrollit()", 1);
}
}
scrollit()
// End -->

</SCRIPT>
</head>
<body bgcolor="#000000" text="#ffffff">
<H1>MSN Messenger</h1><hr>
<p align="right">
<font color="#ff0000">Messages to us</font><br>
<font color="#00ff00">Messages from us</font>
</p>
<hr>
<?php
// Set the PHP Timeout to 0, so we wont get killed by PHP
error_reporting(E_ALL);
set_time_limit(0);

connect();

readdata();
while (!feof($fp)){
$output=readdata();

  //We have been challenged
  if(ereg("CHL",$output)){ challenge($output); }


  //Open chat session
  if(ereg("RNG",$output)){ switchboard($output); }

}


?><hr>
<b>!!!! End Of Script !!!!</b>
<script>alert("Error: The end of the script has been prematurely reached.");</script>
</body>
</html><?php
}else{
?>
<html>
<head>
</head>
<body bgcolor="#000000" text="#ffffff">
<table><tr><td valign="bottom"><img alt="MSN" src="logo.gif" height="60" width="140"></td><td valign="bottom"><h1>Messenger</h1></td></tr></table><hr>
<form method="post" action="">
Username:<input name="passport" type="text" value="@hotmail.com"><br>
Password:<input name="password" type="password"><br>
<input type="submit" value="login">
</form>
<hr>
<small>©2002 Andrew Duffell</small>
</body>
</html>
<?php
}

?>

</body>
</html>


common.php

PHP Code:

<?php
ob_implicit_flush();

//$protocolversion="MSNP7 MSNP6 MSNP5 MSNP4"; //Version 7
$protocolversion="MSNP5 MSNP4";             //Version 5

//--
//Functions go below here...
//--

// *** Send Message ***
function sendmessage($message){
  global $fp;
  fputs($fp, $message);
  echo "<font color=\"#00ff00\" size=\"-1\">". htmlspecialchars($message) ."</font><br>";
  }

// *** Read Data ***
function readdata(){
  global $fp;
  $output=fgets($fp,128);
  echo "<font color=\"#ff0000\" size=\"-1\">". htmlspecialchars($output) ."</font><br>";
  return $output;
  }

// *** Send Chat ***
function chat($chatmessage){
  global $fp;
  $message ="MIME-Version: 1.0" . "\r\n";
  $message .="Content-Type: text/plain; charset=UTF-8" . "\r\n\r\n";
  $message .= $chatmessage;
  $len = strlen($message);
  fputs($fp, "MSG 100 N ".$len ."\r\n".$message);
  echo "<font color=\"#00ff00\" size=\"-1\">". htmlspecialchars($message) ."</font><br>";
  }

//Nicked from the playpen :P  Sorry Phlamethrower :P
$funky_replace_array = array(
  "(6)",  "<img src=\"emoticons/devil.png\">",
  "(A)",  "<img src=\"emoticons/angel.png\">",
  "(K)",  "<img src=\"emoticons/kiss.png\">",
  ":@",  "<img src=\"emoticons/angry_smile.png\">",
  "(?)",  "<img src=\"emoticons/asl.png\">",
  ":[",  "<img src=\"emoticons/bat.png\">",
  ":-[",  "<img src=\"emoticons/bat.png\">",
  "(B)",  "<img src=\"emoticons/beer_yum.png\">",
  "(&)",  "<img src=\"emoticons/bowwow.png\">"

);
function emoticon($text){
global $funky_replace_array;
$text=urldecode($text);
for ($num=0;$num<count($funky_replace_array);$num=$num+2)
  $text = str_replace($funky_replace_array[$num],$funky_replace_array[$num+1],$text);
return $text;
}

?>


sb.php

PHP Code:

<html>
<head>
<SCRIPT LANGUAGE="JavaScript">
function black() {
document.bgColor = "#000000";
}

/*function scrollit() {
self.scroll(0,999999999999999999999999999999999999);
}
scrollit()*/
</SCRIPT>
</head>
<body bgcolor="#000000" text="#ffffff">
<small>
<?php
require("common.php");

$output=urldecode($output);
$passport=urldecode($passport);
list ($aaa,$sid,$chatipy,$aac,$hash,$aae,$name) = split(" ", $output);
list ($chatip,$aae) = split(":", $chatipy);
$name=urldecode($name);
$name=emoticon($name);
echo"Chat with ". $name ."<br>";

$fp = fsockopen($chatip,1863, $errno, $errstr, 30);

sendmessage("ANS 1 $passport $hash $sid\r\n");
readdata();

chat("Hello");

while (!feof($fp)){
//fgets($fp,256);
$output=fgets($fp,2048);
//$output=str_replace("\r\n","<br>",$output);
echo "<font color=\"#ff0000\">".emoticon($output)."</font><br>";

if( (ereg("****",strtolower($output))) || (ereg("dick",strtolower($output))) ){chat("Please do not swear!");}

if(ereg("/time",$output)){$time=date("H:i");chat($time);}

if(ereg("BYE",$output)){list($one,$leftuser) = split(" ",$output, 2);echo $leftuser." has left the session<br>";}

if(ereg("KILL",$output)){
chat("Bai");
sendmessage("OUT");
echo"Connection to switchboard closed<br><script>self.close();</script>";
exit;
}

if(ereg("TypingUser: ",$output)){
echo"<script>document.bgColor = \"#113311\";setTimeout(\"black()\", 5000);</script>";
}
}
?>
</small>
</body>
</html> 



It is pretty messy (the code) but I don't care so you shouldn't ;)
You can open a chat sesson to the bot but not from the bot.
__________________
Andrew
  #2  
Old 19-Jan-2003, 10:31
JdS's Avatar
JdS JdS is offline
Senior Member
 
Join Date: Aug 2001
Location: KUL, Malaysia
Posts: 3,371
JdS will become famous soon enough
Wow, that's some piece of work! Where do you get your (MSN specific) information?
  #3  
Old 19-Jan-2003, 12:42
Andrew Andrew is offline
Member
 
Join Date: May 2002
Location: Yarm, Teesside, England
Posts: 145
Andrew will become famous soon enough
Quote:
Originally posted by JdS
Where do you get your (MSN specific) information?


I just searched on Google for MSN Messenger Protocol and found this site all about the protocol. The URL is http://www.hypothetic.org/docs/msn/. It is really foos and they also have a forum there for protocol discussion.
__________________
Andrew
  #4  
Old 19-Jan-2003, 20:32
JdS's Avatar
JdS JdS is offline
Senior Member
 
Join Date: Aug 2001
Location: KUL, Malaysia
Posts: 3,371
JdS will become famous soon enough
mysober.co.uk, what's that?
  #5  
Old 21-Mar-2003, 04:44
doublehops
 
Posts: n/a
Andrew, thats great. I looked for ages looking for protocol information on the net but could'nt find anything until I came across your thread. I have however had problems trying to implement it. It seems that the reponses I get differ from the ones when I log in via your site. Have you changed your code since this posting to reflect changes at MSN. If so, and you are still around, are you able to advise me of these changes.

Thanks,
Damien.
  #6  
Old 10-Jun-2003, 10:47
Pounder Pounder is offline
Awaiting Email Confirmation
 
Join Date: Jun 2003
Posts: 1
Pounder is an unknown quantity at this point
When me and my friends (using both @hotmail.com and other domain accounts) try to use your script it always says "The script ended prematurely" or something similar. Why does it always do this?
  #7  
Old 19-Aug-2003, 16:09
jrobbio's Avatar
jrobbio jrobbio is offline
Regular Member
 
Join Date: Jan 2003
Location: Loughborough, England
Posts: 840
jrobbio will become famous soon enough
Does this thing still work Andrew? I'm trying to find a decent free online MSN messenger protocol. http://www.mister-i.com/ looks very similar don't you think and they are charging for it hmm.

Rob
  #8  
Old 16-Nov-2003, 03:27
Andrew Andrew is offline
Member
 
Join Date: May 2002
Location: Yarm, Teesside, England
Posts: 145
Andrew will become famous soon enough
The script above no-longer works due to MSN changing their protocols.
__________________
Andrew
  #9  
Old 16-Nov-2003, 03:32
Andrew Andrew is offline
Member
 
Join Date: May 2002
Location: Yarm, Teesside, England
Posts: 145
Andrew will become famous soon enough
Quote:
Originally posted by doublehops
Andrew, thats great. I looked for ages looking for protocol information on the net but could'nt find anything until I came across your thread. I have however had problems trying to implement it. It seems that the reponses I get differ from the ones when I log in via your site. Have you changed your code since this posting to reflect changes at MSN. If so, and you are still around, are you able to advise me of these changes.

Sorry for the late reply When you posted this question the code here and on my site was identical. I can only think that perhaps you were using a different PHP version. Anyway, that is pretty irrelivent now...
__________________
Andrew
  #10  
Old 16-Nov-2003, 03:38
Andrew Andrew is offline
Member
 
Join Date: May 2002
Location: Yarm, Teesside, England
Posts: 145
Andrew will become famous soon enough

New PHP MSN Script


A person by the name of 'jpg' on hypothetic.org has updated the script to work with the new protocol. He has posted it on their forums, and I will link the source (zip) from here:
http://mysober.co.uk/msn/new.zip (This link expires in November 2004)
__________________
Andrew
 
 

Recent GIDBlogToyota - 2009 May Promotion by Nihal

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Optimizing your web server with Turck MMCache for PHP JdS Web Hosting Forum 2 07-Jan-2004 08:48
apache2 - php cgi fehler - schleife inna Apache Web Server Forum 8 27-Nov-2003 10:55
[Linux] Installing PHP --with-mcrypt JdS Web Hosting Forum 0 20-Aug-2003 09:40
PHP in HTML jrobbio Web Design Forum 4 24-Jul-2003 07:05
All the big PHP script collections that matter jrobbio MySQL / PHP Forum 5 06-Jun-2003 17:14

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 00:34.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.