⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 msnp2p.tcl

📁 Linux下的MSN聊天程序源码
💻 TCL
📖 第 1 页 / 共 4 页
字号:
		#	        set cOffset [int2word $cOffset1 $cOffset2]		#	        set cTotalDataSize [int2word $cTotalDataSize1 $cTotalDataSize2]		#   	        set cAckSize [int2word $cAckSize1 $cAckSize2]		#status_log "Read header : $cSid $cId $cOffset $cTotalDataSize $cMsgSize $cFlags $cAckId $cAckUID $cAckSize\n" red		#status_log "Sid : $cSid -> " red		set cSid [$message cget -sessionid]		set cId [$message cget -identifier]		set cOffset [$message cget -offset]		set cTotalDataSize [$message cget -totalsize]		set cMsgSize [$message cget -datalength]		set cFlags [$message cget -flag]		set cAckId [$message cget -ackid]		set cAckUID [$message cget -ackuid]		set cAckSize [$message cget -acksize]		set data [$message getBody]		if {$cSid == "0" && $cMsgSize != "0" && $cMsgSize != $cTotalDataSize } {			if { ![info exists chunkedData($cId)] } {				set chunkedData($cId) "[string range $data 0 [expr { $cMsgSize - 1}]]"			} else {				set chunkedData($cId) "$chunkedData($cId)[string range $data 0 [expr { $cMsgSize - 1}]]"			}			#			status_log "Data is now : $chunkedData($cId)\n\n";			status_log "chunked data :  $cTotalDataSize - $cMsgSize - $cOffset - [string length $chunkedData($cId)]"			if { $cTotalDataSize != [expr {$cMsgSize + $cOffset}] } {				#	status_log "not enough data to complete chunk...$cTotalDataSize - $cOffset - $cMsgSize - [string length $chunkedData($cId)]" 				return			} else {				#status_log "data completed... $cTotalDataSize - $cOffset - [string length $chunkedData($cId)]"				set data $chunkedData($cId)				unset chunkedData($cId)				#				set headend 0				set cMsgSize $cTotalDataSize			}		}		if { [lindex [SessionList get $cSid] 7] == "ignore" } {			status_log "MSNP2P | $cSid -> Ignoring packet! not for us!\n"			return		}		# Check if this is an ACK Message		# TODO : Actually check if the ACK is good ? check size and all that crap...		if { $cMsgSize == 0 } {			# Let us check if any of our sessions is waiting for an ACK			set sid [SessionList findid $cAckId]			status_log "GOT SID : $sid for Ackid : $cAckId\n"			if { $sid != -1 } {			 	#status_log "MSNP2P | $sid -> Got MSNP2P ACK " red			 	# We found a session id that is waiting for an ACK			 	set step [lindex [SessionList get $sid] 4]				# Just these 2 for now, will probably need more with file transfers				switch $step {					DATAPREP {						# Set the right variables, prepare to send data after next ack						SessionList set $sid [list -1 4 0 -1 "SENDDATA" -1 -1 -1 -1 -1]						# We need to send a data preparation message						SendPacket [::MSN::SBFor $chatid] [MakePacket $sid [binary format i 0]]						status_log "MSNP2P | $sid -> Sent DATA Preparation\n" red					}					SENDDATA {						#status_log "MSNP2P | $sid -> Sending DATA now\n" red						set file [lindex [SessionList get $sid] 8]						if { $file != "" } {							SendData $sid $chatid "[lindex [SessionList get $sid] 8]"						} else {							SendData $sid $chatid "[::skin::GetSkinFile displaypic [::config::getKey displaypic]]"						}					}					DATASENT {						SessionList set $sid [list -1 -1 0 -1 0 -1 -1 -1 -1 -1]						#status_log "MSNP2P | $sid -> Got ACK for sending data, now sending BYE\n" red						set branchid "[format %X [myRand 4369 65450]][format %X [myRand 4369 65450]]-[format %X [myRand 4369 65450]]-[format %X [myRand 4369 65450]]-[format %X [myRand 4369 65450]]-[format %X [myRand 4369 65450]][format %X [myRand 4369 65450]][format %X [myRand 4369 65450]]"						SendPacket [::MSN::SBFor $chatid] [MakePacket $sid [MakeMSNSLP "BYE" [lindex [SessionList get $sid] 3] [::config::getKey login] "$branchid" "0" [lindex [SessionList get $sid] 5] 0 0] 1]					}				}			}			return		}		#status_log "ReadData : data : $data"		# Check if this is an INVITE message		if { [string first "INVITE MSNMSGR" $data] != -1 } {			#status_log "Got an invitation!\n" red			# Let's get the session ID, destination email, branchUID, UID, AppID, Cseq			set idx [expr {[string first "SessionID:" $data] + 11}]			set idx2 [expr {[string first "\r\n" $data $idx] - 1}]			set sid [string range $data $idx $idx2]			set idx [expr {[string first "From: <msnmsgr:" $data] + 15}]			set idx2 [expr {[string first "\r\n" $data $idx] - 2}]			set dest [string range $data $idx $idx2]			set idx [expr {[string first "branch=\{" $data] + 8}]			set idx2 [expr {[string first "\}" $data $idx] - 1}]			set branchuid [string range $data $idx $idx2]			set idx [expr {[string first "Call-ID: \{" $data] + 10}]			set idx2 [expr {[string first "\}" $data $idx] - 1}]			set uid [string range $data $idx $idx2]			set idx [expr {[string first "CSeq:" $data] + 6}]			set idx2 [expr {[string first "\r\n" $data $idx] - 1}]			set cseq [string range $data $idx $idx2]			set idx [expr {[string first "Content-Type: " $data $idx] + 14}]			set idx2 [expr {[string first "\r\n" $data $idx] - 1}]			set ctype [string range $data $idx $idx2]			status_log "Got INVITE with content-type : $ctype\n" red			if { $ctype == "application/x-msnmsgr-transreqbody"} {				set sid [SessionList findcallid $uid]				set type [lindex [SessionList get $sid] 7]				#this catches an error with MSN7, still need to find out why sid = -1				if {$sid == -1} {return}				set idx [expr {[string first "Conn-Type: " $data] + 11}]				set idx2 [expr {[string first "\r\n" $data $idx] - 1}]				set conntype [string range $data $idx $idx2]				set idx [expr {[string first "UPnPNat: " $data] + 9}]				set idx2 [expr {[string first "\r\n" $data $idx] - 1}]				set upnp [string range $data $idx $idx2]				# Let's send an ACK				SendPacket [::MSN::SBFor $chatid] [MakeACK $sid 0 $cTotalDataSize $cId $cAckId]				if { $type == "filetransfer" } {					# We received an invite for a FT, send 200 OK					::MSN6FT::answerFTInvite $sid $chatid $branchuid $conntype				} elseif { $type == "webcam" } {					::MSNCAM::answerCamInvite $sid $chatid $branchuid				}			} elseif { $ctype == "application/x-msnmsgr-sessionreqbody" } {				# Let's check if it's an invitation for buddy icon or emoticon				set idx [expr {[string first "EUF-GUID:" $data] + 11}]				set idx2 [expr {[string first "\}" $data $idx] - 1}]				set eufguid [string range $data $idx $idx2]				set idx [expr {[string first "Context:" $data] + 9}]				set idx2 [expr {[string first "\r\n" $data $idx] - 1}]				set context [string range $data $idx $idx2]				if { $eufguid == "A4268EEC-FEC5-49E5-95C3-F126696BDBF6" ||				     $eufguid == "5D3E02AB-6190-11D3-BBBB-00C04F795683" ||				     $eufguid == "E073B06B-636E-45B7-ACA4-6D4B5978C93C" ||				     $eufguid == "4BD96FC0-AB17-4425-A14A-439185962DC8" ||				     $eufguid == "1C9AA97E-9C05-4583-A3BD-908A196F1E92"} {					status_log "MSNP2P | $sid $dest -> Got INVITE for buddy icon, emoticon, or file transfer, or Wink(MSN 7)\n" red					# Make new data structure for this session id					if { $eufguid == "A4268EEC-FEC5-49E5-95C3-F126696BDBF6" } {						# Buddyicon or emoticon						if { [GetFilenameFromContext $context] != "" } {							SessionList set $sid [list 0 0 0 $dest 0 $uid 0 "bicon" [GetFilenameFromContext $context] ""]						} else {							status_log "MSNP2P | $sid -> This is not an invitation for us, don't reply.\n" red							# Now we tell this procedure to ignore all packets with this sid							SessionList set $sid [list 0 0 0 0 0 0 0 "ignore" 0 ""]							return						}					} elseif { $eufguid == "5D3E02AB-6190-11D3-BBBB-00C04F795683" } {						# File transfer						#check if a conversation is open with that contact						#no need to test either a chatwindow has been created or not, because MakeFor is going to do it ! 						::ChatWindow::MakeFor $chatid						SessionList set $sid [list 0 0 0 $dest 0 $uid 0 "filetransfer" "" "$branchuid"]						# Let's send an ACK						SendPacket [::MSN::SBFor $chatid] [MakeACK $sid 0 $cTotalDataSize $cId $cAckId]						status_log "MSNP2P | $sid $dest -> Sent ACK for INVITE\n" red						# Let's get filename and filesize from context						set idx [expr {[string first "Context:" $data] + 9}]						set context [base64::decode [string range $data $idx end]]						::MSN6FT::GotFileTransferRequest $chatid $dest $branchuid $cseq $uid $sid $context						return					} elseif { $eufguid =="E073B06B-636E-45B7-ACA4-6D4B5978C93C"} {						#We received Winks						status_log "####WINKS RECEIVED####\n" blue						set decoding [base64::decode $context]						status_log "$decoding\n" blue						status_log "######################\n" blue						# Let's notify the user that he/she has received a Wink						SendMessageFIFO [list ::amsn::WinWrite $chatid "\n [trans winkreceived [::abook::getDisplayNick $chatid]]\n" black "" 0] "::amsn::messages_stack($chatid)" "::amsn::messages_flushing($chatid)"					} elseif { $eufguid == "4BD96FC0-AB17-4425-A14A-439185962DC8" ||						   $eufguid == "1C9AA97E-9C05-4583-A3BD-908A196F1E92" }	{						#check if a conversation is open with that contact						#no need to test either a chatwindow has been created or not, because MakeFor is going to do it ! 						::ChatWindow::MakeFor $chatid						if { $eufguid == "4BD96FC0-AB17-4425-A14A-439185962DC8" } {							set producer 0						} else {								set producer 1						}						status_log "we got an webcam invitation" red						set context [base64::decode $context]						set context [FromUnicode $context]						#answerFtInvite $sid $chatid $branchuid $conntype						# Let's send an ACK						SendPacket [::MSN::SBFor $chatid] [MakeACK $sid 0 $cTotalDataSize $cId $cAckId]						SessionList set $sid [list 0 0 0 $dest 0 $uid 0 "webcam" "" "$branchuid"]												if { $context != "\{B8BE70DE-E2CA-4400-AE03-88FF85B9F4E8\}" } {							status_log "Received a video conferenced invitation.. we do not support this"							::CAMGUI::InvitationRejected $chatid $sid $branchuid $uid							#::MSNCAM::RejectFT $chatid $sid $branchuid $uid							::CAMGUI::GotVideoConferenceInvitation $chatid							return						}												::CAMGUI::AcceptOrRefuse $chatid $dest $branchuid $cseq $uid $sid $producer						status_log "MSNP2P | $sid $dest -> Sent ACK for INVITE\n" red						return					}					# Let's send an ACK					SendPacket [::MSN::SBFor $chatid] [MakeACK $sid 0 $cTotalDataSize $cId $cAckId]					status_log "MSNP2P | $sid $dest -> Sent ACK for INVITE\n" red					# Let's make and send a 200 OK Message					set slpdata [MakeMSNSLP "OK" $dest [::config::getKey login] $branchuid [expr {$cseq + 1}] $uid 0 0 $sid]					SendPacket [::MSN::SBFor $chatid] [MakePacket $sid $slpdata 1]					status_log "MSNP2P | $sid $dest -> Sent 200 OK Message\n" red										# Send Data Prep AFTER ACK received (set AfterAck)					SessionList set $sid [list -1 -1 -1 -1 "DATAPREP" -1 -1 -1 -1 -1]										return				}			} elseif { $ctype == "application/x-msnmsgr-transrespbody" } {								set idx [expr {[string first "Call-ID: \{" $data] + 10}]				set idx2 [expr {[string first "\}" $data $idx] -1}]				set uid [string range $data $idx $idx2]				set sid [SessionList findcallid $uid]				set idx [expr {[string first "Listening: " $data] + 11}]				set idx2 [expr {[string first "\r\n" $data $idx] -1}]				set listening [string range $data $idx $idx2]								#status_log "MSNP2P | $sid -> Got 200 OK for File transfer, parsing result\n"				#status_log "MSNP2P | $sid -> Found uid = $uid , lestening = $listening\n"				if { $sid != -1 }  {					SendPacket [::MSN::SBFor $chatid] [MakeACK $sid 0 $cTotalDataSize $cId $cAckId]					set type [lindex [SessionList get $sid] 7]					if { $listening == "true" } {						set idx [expr {[string first "Nonce: \{" $data] + 8}]						set idx2 [expr {[string first "\r\n" $data $idx] -2}]						set nonce [string range $data $idx $idx2]						if {[string first "IPv4External-Addrs: " $data] != -1 } {							set idx [expr {[string first "IPv4External-Addrs: " $data] + 20}]							set idx2 [expr {[string first "\r\n" $data $idx] -1}]							set addr [string range $data $idx $idx2]							set idx [expr {[string first "IPv4External-Port: " $data] + 19}]							set idx2 [expr {[string first "\r\n" $data $idx] -1}]							set port [string range $data $idx $idx2]						} else {							set idx [expr {[string first "IPv4Internal-Addrs: " $data] + 20}]							set idx2 [expr {[string first "\r\n" $data $idx] -1}]							set addr [string range $data $idx $idx2]							set idx [expr {[string first "IPv4Internal-Port: " $data] + 19}]							set idx2 [expr {[string first "\r\n" $data $idx] -1}]							set port [string range $data $idx $idx2]						}						status_log "MSNP2P | $sid -> Receiver is listening with $addr : $port\n" red						#after 5500 "::MSNP2P::SendData $sid $chatid [lindex [SessionList get $sid] 8]"						if {$type == "filetransfer" } {							::MSN6FT::ConnectSockets $sid $nonce $addr $port 0						} elseif { $type == "webcam" } {							::MSNCAM::connectMsnCam2 $sid $nonce $addr $port 0						}					}				}			}		}		# Check if it is a 200 OK message		if { [string first "MSNSLP/1.0 200 OK" $data] != -1 } {			# Send a 200 OK ACK			set first [string first "SessionID:" $data]			if { $first != -1 } {				set idx [expr {[string first "SessionID:" $data] + 11}]				set idx2 [expr {[string first "\r\n" $data $idx] -1}]				set sid [string range $data $idx $idx2]				set type [lindex [SessionList get $sid] 7]				if { $type == "ignore" } {					#status_log "MSNP2P | $sid -> Ignoring packet! not for us!\n"					return				}				#status_log "MSNP2P | $sid -> Got 200 OK message, sending an ACK for it\n" red				SendPacket [::MSN::SBFor $chatid] [MakeACK $sid 0 $cTotalDataSize $cId $cAckId]				if { $type == "filetransfer" } {					::MSN6FT::SendFTInvite $sid $chatid				}			} else {				set idx [expr {[string first "Call-ID: \{" $data] + 10}]				set idx2 [expr {[string first "\}" $data $idx] -1}]				set uid [string range $data $idx $idx2]				set sid [SessionList findcallid $uid]				set idx [expr {[string first "Listening: " $data] + 11}]				set idx2 [expr {[string first "\r\n" $data $idx] -1}]				set listening [string range $data $idx $idx2]				#status_log "MSNP2P | $sid -> Got 200 OK for File transfer, parsing result\n"				#status_log "MSNP2P | $sid -> Found uid = $uid , lestening = $listening\n"				set type [lindex [SessionList get $sid] 7]				if { $sid != -1 }  {					SendPacket [::MSN::SBFor $chatid] [MakeACK $sid 0 $cTotalDataSize $cId $cAckId]					if { $listening == "true" } {						set idx [expr {[string first "Nonce: \{" $data] + 8}]						set idx2 [expr {[string first "\r\n" $data $idx] -2}]						set nonce [string range $data $idx $idx2]						if {[string first "IPv4External-Addrs: " $data] != -1 } {							set idx [expr {[string first "IPv4External-Addrs: " $data] + 20}]							set idx2 [expr {[string first "\r\n" $data $idx] -1}]							set addr [string range $data $idx $idx2]							set idx [expr {[string first "IPv4External-Port: " $data] + 19}]							set idx2 [expr {[string first "\r\n" $data $idx] -1}]							set port [string range $data $idx $idx2]						} else {							set idx [expr {[string first "IPv4Internal-Addrs: " $data] + 20}]							set idx2 [expr {[string first "\r\n" $data $idx] -1}]							set addr [string range $data $idx $idx2]							set idx [expr {[string first "IPv4Internal-Port: " $data] + 19}]							set idx2 [expr {[string first "\r\n" $data $idx] -1}]							set port [string range $data $idx $idx2]						}						status_log "MSNP2P | $sid -> Receiver is listening with $addr : $port\n" red						#after 5500 "::MSNP2P::SendData $sid $chatid [lindex [SessionList get $sid] 8]"						if { $type == "filetransfer" } {							::MSNP2P::SessionList set $sid [list -1 -1 -1 -1 "INVITE2" -1 -1 -1 -1 -1]							::MSN6FT::ConnectSockets $sid $nonce $addr $port 1						} elseif { $type == "webcam" } {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -