📄 msncam.tcl
字号:
proc setObjOption { obj option value } { global objects if { [info exists objects($obj)] } { set my_list [set objects($obj)] } else { set my_list [list] } array set my_obj $my_list set my_obj($option) $value set my_list [array get my_obj] set objects($obj) $my_list}proc getObjOption { obj option {def ""}} { global objects if { [info exists objects($obj)] } { set my_list [set objects($obj)] } else { return $def } array set my_obj $my_list if { [info exists my_obj($option)] } { return [set my_obj($option)] } else { return $def }}proc nbread { sock numChars } { set tmpsize 0 set tmpdata "" if { [catch { #To avoid to be recalled when we do update set oldfileevent [fileevent $sock readable] fileevent $sock readable "" while { $tmpsize < $numChars && ![eof $sock] } { append tmpdata [read $sock [expr {$numChars - $tmpsize}]] set tmpsize [string length $tmpdata] update } fileevent $sock readable $oldfileevent } errormsg] } { status_log "Error in nbread : $errormsg" white #We are here if there is an error in the catch return "" } else { return $tmpdata }}proc nbgets { sock {varName ""} } { set char " " set data "" while { $char != "\n" && $char != "" } { set char [nbread $sock 1] append data $char } set data [string range $data 0 [expr {[string length $data] - 2}] ] if { $varName != "" } { upvar 1 $varName buffer set buffer $data return [string length $data] } return $data}namespace eval ::MSNCAM { namespace export CancelCam SendInvite AskWebcam CamCanceled #////////////////////////////////////////////////////////////////////////////// # CamCanceled ( chat sid ) # This function is called when a file transfer is canceled by the remote contact proc CamCanceled { chatid sid } { set grabber [getObjOption $sid grabber] set window [getObjOption $sid window] #draw a notification in the window (gui) ::CAMGUI::CamCanceled $chatid if {![catch {tk windowingsystem} wsystem] && $wsystem == "aqua"} { set grabber .grabber.seq #Delete the button of current cams sending, on Mac OS X, if it exists if { [winfo exists .grabber.delete_$sid] } { destroy .grabber.delete_$sid set ::activegrabbers [expr {$::activegrabbers - 1}] } } else { if { [::CAMGUI::IsGrabberValid $grabber] } { ::CAMGUI::CloseGrabber $grabber $window } } # close file for log of the webcam... set fd [getObjOption $sid weblog] if { $fd != "" } { catch { close $fd } } if { [winfo exists $window] } { wm protocol $window WM_DELETE_WINDOW "destroy $window" $window.q configure -command "destroy $window" if { [getObjOption $sid producer] } { #We disable the button which show the properties $window.settings configure -state disable -command "" } } set listening [getObjOption $sid listening_socket] if { $listening != "" } { catch { close $listening } } setObjOption $sid listening_socket "" } #////////////////////////////////////////////////////////////////////////////// # CancelFT ( chatid sid ) # This function is called when a file transfer is canceled by the user proc CancelCam { chatid sid } { set session_data [::MSNP2P::SessionList get $sid] set user_login [lindex $session_data 3] set callid [lindex $session_data 5] set socket [getObjOption $sid socket] setObjOption $socket state "END" if {[getObjOption $sid canceled] == 1 } { return } setObjOption $sid canceled 1 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]]" status_log "Canceling webcam $sid with $chatid \n" red ::MSNP2P::SendPacket [::MSN::SBFor $chatid] [::MSNP2P::MakePacket $sid [::MSNP2P::MakeMSNSLP "BYE" $user_login [::config::getKey login] $branchid 0 $callid 0 1 "dAMAgQ==\r\n"] 1] if { $socket != "" } { status_log "Connected through socket $socket : closing socket\n" red catch { close $socket } CloseUnusedSockets $sid "" } CamCanceled $chatid $sid #::MSNP2P::SessionList unset $sid } #////////////////////////////////////////////////////////////////////////////// # RejectFT ( chatid sid branchuid uid ) # This function is called when a file transfer is rejected/canceled proc RejectFT { chatid sid branchuid uid } { # All we need to do is send a DECLINE set slpdata [::MSNP2P::MakeMSNSLP "DECLINE" [lindex [::MSNP2P::SessionList get $sid] 3] [::config::getKey login] $branchuid 1 $uid 0 0 $sid] ::MSNP2P::SendPacket [::MSN::SBFor $chatid] [::MSNP2P::MakePacket $sid $slpdata 1] # And we unset our sid vars ::MSNP2P::SessionList unset $sid } proc RejectFTOpenSB { chatid sid branchuid uid } { #Execute the reject webcam protocol if {[catch {::MSNCAM::RejectFT $chatid $sid $branchuid $uid} res]} { status_log "Error in InvitationRejected: $res\n" red return 0 } } #////////////////////////////////////////////////////////////////////////////// # AcceptFT ( chatid dest branchuid cseq uid sid filename1 ) # This function is called when a file transfer is accepted by the user (local) proc AcceptWebcam { chatid dest branchuid cseq uid sid producer} { setObjOption $sid producer $producer setObjOption $sid inviter 0 setObjOption $sid chatid $chatid setObjOption $sid reflector 0 if { $producer } { setObjOption $sid source [::config::getKey "webcamDevice" "0"] } # Let's make and send a 200 OK Message set slpdata [::MSNP2P::MakeMSNSLP "OK" $dest [::config::getKey login] $branchuid [expr {$cseq + 1}] $uid 0 0 $sid] ::MSNP2P::SendPacket [::MSN::SBFor $chatid] [::MSNP2P::MakePacket $sid $slpdata 1] SendAcceptInvite $sid $chatid status_log "::MSNCAM::SendAcceptInvite $sid $chatid\n" green SendSyn $sid $chatid } proc AcceptWebcamOpenSB {chatid dest branchuid cseq uid sid producer } { if {[catch {::MSNCAM::AcceptWebcam $chatid $dest $branchuid $cseq $uid $sid $producer} res]} { status_log "Error in InvitationAccepted: $res\n" red return 0 } } proc SendAcceptInvite { sid chatid} { set session [::MSNP2P::SessionList get $sid] set branchid [lindex $session 9] set callid [lindex $session 5] set dest [lindex $session 3] 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]]" status_log "branchid : $branchid\n" red set netid [abook::getDemographicField netid] set conntype [abook::getDemographicField conntype] set upnp [abook::getDemographicField upnpnat] if { $netid == "" || $conntype == "" } { abook::getIPConfig set netid [abook::getDemographicField netid] set conntype [abook::getDemographicField conntype] if { $netid == "" } { set netid 0 } if { $conntype == "" } {set conntype "Firewall" } } ::MSNP2P::SessionList set $sid [list -1 -1 -1 -1 "INVITE1" -1 -1 -1 -1 $branchid] set slpdata [::MSNP2P::MakeMSNSLP "INVITE" $dest [::config::getKey login] $branchid "0 " $callid 0 1 "TRUDPv1 TCPv1" \ $netid $conntype $upnp "false"] status_log "size : [string length $slpdata]\n" red ::MSNP2P::SendPacket [::MSN::SBFor $chatid] [::MSNP2P::MakePacket $sid $slpdata 1] } proc SendReflData { sid chatid refldata } { set MsgId [lindex [::MSNP2P::SessionList get $sid] 0] set dest [lindex [::MSNP2P::SessionList get $sid] 3] incr MsgId ::MSNP2P::SessionList set $sid [list $MsgId -1 -1 -1 -1 -1 -1 -1 -1 -1 ] binary scan $refldata H* refldata set refldata "ReflData:[string toupper $refldata]\x00" status_log "ReflData is : $refldata" set h1 "\x80\x00\x00\x00\x08\x00" set refldata [ToUnicode $refldata] set h2 [binary format i [string length $refldata]] set footer "\x00\x00\x00\x04" set msg "${h1}${h2}${refldata}" set size [string length $msg] set data "[binary format ii $sid $MsgId][binword 0][binword $size][binary format iiii $size 0 [expr { int([expr {rand() * 1000000000}])%125000000 + 4}] 0][binword 0]${msg}${footer}" set theader "MIME-Version: 1.0\r\nContent-Type: application/x-msnmsgrp2p\r\nP2P-Dest: $dest\r\n\r\n" status_log "Sending Refldata : $data" green ::MSNP2P::SendPacket [::MSN::SBFor $chatid] "${theader}${data}" } proc SendSyn { sid chatid } { if { [getObjOption $sid send_syn] == 1 } { status_log "Try to send double syn" return } set MsgId [lindex [::MSNP2P::SessionList get $sid] 0] set dest [lindex [::MSNP2P::SessionList get $sid] 3] incr MsgId ::MSNP2P::SessionList set $sid [list $MsgId -1 -1 -1 -1 -1 -1 -1 -1 -1 ] set h1 "\x80[binary format s [myRand 0 65000]]\x01\x08\x00" set syn [ToUnicode "syn\x00"] set h2 [binary format i [string length $syn]] set footer "\x00\x00\x00\x04" set msg "${h1}${h2}${syn}" set size [string length $msg] set data "[binary format ii $sid $MsgId][binword 0][binword $size][binary format iiii $size 0 [expr {int([expr {rand() * 1000000000}])%125000000 + 4}] 0][binword 0]${msg}${footer}" set theader "MIME-Version: 1.0\r\nContent-Type: application/x-msnmsgrp2p\r\nP2P-Dest: $dest\r\n\r\n" ::MSNP2P::SendPacket [::MSN::SBFor $chatid] "${theader}${data}" setObjOption $sid send_syn 1 } proc SendAck { sid chatid } { set MsgId [lindex [::MSNP2P::SessionList get $sid] 0] set dest [lindex [::MSNP2P::SessionList get $sid] 3] incr MsgId ::MSNP2P::SessionList set $sid [list $MsgId -1 -1 -1 -1 -1 -1 -1 -1 -1 ] set h1 "\x80\xea\x00\x00\x08\x00" set ack [ToUnicode "ack\x00"] set h2 [binary format i [string length $ack]] set footer "\x00\x00\x00\x04" set msg "${h1}${h2}${ack}" set size [string length $msg] set data "[binary format ii $sid $MsgId][binword 0][binword $size][binary format iiii $size 0 [expr {int([expr {rand() * 1000000000}])%125000000 + 4}] 0][binword 0]${msg}${footer}" set theader "MIME-Version: 1.0\r\nContent-Type: application/x-msnmsgrp2p\r\nP2P-Dest: $dest\r\n\r\n" ::MSNP2P::SendPacket [::MSN::SBFor $chatid] "${theader}${data}" } proc SendReceivedViewerData { chatid sid } { set MsgId [lindex [::MSNP2P::SessionList get $sid] 0] set dest [lindex [::MSNP2P::SessionList get $sid] 3] incr MsgId ::MSNP2P::SessionList set $sid [list $MsgId -1 -1 -1 -1 -1 -1 -1 -1 -1 ] set h1 "\x80\xec[binary format c [myRand 0 255]]\x03\x08\x00" set recv [ToUnicode "receivedViewerData\x00"] set h2 [binary format i [string length $recv]] set footer "\x00\x00\x00\x04" set msg "${h1}${h2}${recv}" set size [string length $msg] set data "[binary format ii $sid $MsgId][binword 0][binword $size][binary format iiii $size 0 [expr {int([expr {rand() * 1000000000}])%125000000 + 4}] 0][binword 0]${msg}${footer}" set theader "MIME-Version: 1.0\r\nContent-Type: application/x-msnmsgrp2p\r\nP2P-Dest: $dest\r\n\r\n" ::MSNP2P::SendPacket [::MSN::SBFor $chatid] "${theader}${data}" } #Askwebcam queue, open connection before sending invitation proc AskWebcamQueue { chatid } { ::MSN::ChatQueue $chatid [list ::MSNCAM::AskWebcam $chatid] } #SendInvite queue, open connection before sending invitation proc SendInviteQueue {chatid} { ::MSN::ChatQueue $chatid [list ::MSNCAM::SendInvite $chatid] } proc StartVideoConferenceQueue { chatid } { ::MSN::ChatQueue $chatid [list ::MSNCAM::StartVideoconference $chatid] } proc SendInvite { chatid } { SendCamInvitation $chatid "4BD96FC0-AB17-4425-A14A-439185962DC8" "\{B8BE70DE-E2CA-4400-AE03-88FF85B9F4E8\}" } proc AskWebcam { chatid } { SendCamInvitation $chatid "1C9AA97E-9C05-4583-A3BD-908A196F1E92" "\{B8BE70DE-E2CA-4400-AE03-88FF85B9F4E8\}" } proc StartVideoConference { chatid } { SendCamInvitation $chatid "4BD96FC0-AB17-4425-A14A-439185962DC8" "\{0425E797-49F1-4D37-909A-031116119D9B\}" } proc SendCamInvitation { chatid guid context } { if {[::ChatWindow::For $chatid]==0} { ::amsn::chatUser $chatid } status_log "Sending Webcam Request\n" set sid [expr {int([expr {rand() * 1000000000}])%125000000 + 4}] # Generate BranchID and CallID 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]]" set callid "[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]]" set dest [lindex [::MSN::usersInChat $chatid] 0] if { $context == "\{B8BE70DE-E2CA-4400-AE03-88FF85B9F4E8\}" } { setObjOption $sid webcam 1 setObjOption $sid conference 0 } else { setObjOption $sid webcam 0 setObjOption $sid conference 1 } # This is a fixed value... it must be that way or the invite won't work set context [ToUnicode $context] ::MSNP2P::SessionList set $sid [list 0 0 0 $dest 0 $callid 0 "webcam" "$context" "$branchid"] setObjOption $sid inviter 1 setObjOption $sid chatid $chatid setObjOption $sid reflector 0 if { $guid == "4BD96FC0-AB17-4425-A14A-439185962DC8" } { setObjOption $sid producer 1 setObjOption $sid source [::config::getKey "webcamDevice" "0"] ::CAMGUI::InvitationToSendSent $chatid } else { setObjOption $sid producer 0 ::CAMGUI::InvitationToReceiveSent $chatid } status_log "branchid : [lindex [::MSNP2P::SessionList get $sid] 9]\n" # Create and send our packet set slpdata [::MSNP2P::MakeMSNSLP "INVITE" $dest [::config::getKey login] $branchid 0 $callid 0 0 $guid $sid 4 \ [string map { "\n" "" } [::base64::encode "$context"]]] ::MSNP2P::SendPacketExt [::MSN::SBFor $chatid] $sid $slpdata 1 status_log "Sent an INVITE to [::MSN::usersInChat $chatid] on chatid $chatid for webcam\n" red
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -