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

📄 msncam.tcl

📁 Linux下的MSN聊天程序源码
💻 TCL
📖 第 1 页 / 共 5 页
字号:
	}	proc answerCamInvite { sid chatid branchid } {		::MSNP2P::SessionList set $sid [list -1 -1 -1 -1 -1 -1 -1 -1 -1 "$branchid" ]		set session [::MSNP2P::SessionList get $sid]		set dest [lindex $session 3]		set callid [lindex $session 5]		set slpdata [::MSNP2P::MakeMSNSLP "DECLINE" $dest [::config::getKey login] $branchid 1 $callid 0 3]		::MSNP2P::SendPacket [::MSN::SBFor $chatid] [::MSNP2P::MakePacket $sid $slpdata 1]		SendSyn $sid $chatid	}	proc OpenCamPort { port sid} {		while { [catch {set sock [socket -server "::MSNCAM::handleMsnCam $sid" $port] } ] } {			incr port		}		setObjOption $sid listening_socket $sock		status_log "Opening server on port $port\n" red		return $port	}	proc handleMsnCam { sid sock ip port } {		if { [info exists ::test_webcam_reflector] && $::test_webcam_reflector} {			status_log "Received connection from $ip on port $port - socket $sock\n" red			status_log "Closing the socket to allow testing of the reflector...\n" red			catch { close $sock}			return		}		setObjOption $sock sid $sid		setObjOption $sock server 1		setObjOption $sock state "AUTH"		setObjOption $sock reflector 1		status_log "Received connection from $ip on port $port - socket $sock\n" red		fconfigure $sock -blocking 0 -buffering none -translation {binary binary}		set connected_ips [getObjOption $sid connected_ips]		lappend connected_ips [list $ip $port $sock]		setObjOption $sid connected_ips $connected_ips		if { [getObjOption $sid socket] == "" } {			#setObjOption $sid socket $sock			fileevent $sock readable "::MSNCAM::ReadFromSock $sock"		}	}	proc connectMsnCam { sid ip port } {		if { [info exists ::test_webcam_reflector] && $::test_webcam_reflector} {			return 0		}		if { [catch {set sock [socket -async $ip $port] } ] } {			status_log "ERROR CONNECTING TO THE SERVER\n\n" red			return 0		} else {			setObjOption $sock sid $sid			setObjOption $sock server 0			setObjOption $sock state "AUTH"			setObjOption $sock reflector 0			status_log "connectedto $ip on port $port  - $sock\n" red			return $sock		}	}	proc ConnectToReflector { sid refldata } {		set ru [string range $refldata [expr {[string first "ru=" $refldata] + 3}] end]		if { [string first "&" $ru] != -1 } {			set ru [string range $ru 0 [expr {[string first "&" $ru] -1}]]		}		set ti [string range $refldata [expr {[string first "ti=" $refldata] + 3}] end]		if { [string first "&" $ti] != -1 } {			set ti [string range $ti 0 [expr {[string first "&" $ti] -1}]]		}		if { [string first "http://" $ru] != -1 } {			set ru [string range $ru [expr {[string first "http://" $ru] + 7}] end]		}		set host [string range $ru 0 [expr {[string first ":" $ru]-1}]]		set port [string range $ru [expr {[string first ":" $ru]+1}] end]				status_log "Connecting to reflector : $host at $port\n$ru - [string first ":" $ru]\n$ti\n$refldata\n" red		if { [catch {set sock [socket $host $port] } ] } {			status_log "ERROR CONNECTING TO THE SERVER\n\n" red			::MSNCAM::CancelCam [getObjOption $sid chatid] $sid		} else {			setObjOption $sid socket $sock			setObjOption $sid reflector 1			setObjOption $sock sid $sid			setObjOption $sock server 0			setObjOption $sock state "TID"			setObjOption $sock tid "$ti"			setObjOption $sock reflector 1			status_log "connected to $host on port $port  - $sock\n" red						fconfigure $sock -blocking 0 -buffering none -translation {binary binary} -encoding binary 			fileevent $sock readable "::MSNCAM::ReadFromSock $sock"			fileevent $sock writable "::MSNCAM::WriteToSock $sock"			return $sock		}	}	proc PausePlayCam { window sock } {		set state [getObjOption $sock state]		after cancel "catch {fileevent $sock writable \"::MSNCAM::WriteToSock $sock\" }"		if {$state == "SEND"} {			setObjOption $sock state "PAUSED"			$window.pause configure -text "[trans playwebcamsend]"		} elseif {$state == "TSP_SEND" } {			setObjOption $sock state "TSP_PAUSED"			$window.pause configure -text "[trans playwebcamsend]"			catch { fileevent $sock writable "::MSNCAM::WriteToSock $sock" }		} elseif {$state == "PAUSED" } {			setObjOption $sock state "SEND"			$window.pause configure -text "[trans pausewebcamsend]"			catch { fileevent $sock writable "::MSNCAM::WriteToSock $sock" }		}  elseif {$state == "TSP_PAUSED" } {			setObjOption $sock state "TSP_SEND"			$window.pause configure -text "[trans pausewebcamsend]"			catch { fileevent $sock writable "::MSNCAM::WriteToSock $sock" }		} 	}	proc ReadFromSock { sock } {		set sid [getObjOption $sock sid]		set producer [getObjOption $sid producer]		set server [getObjOption $sock server]		set state [getObjOption $sock state]		set reflector [getObjOption $sid reflector]		set my_rid [getObjOption $sid my_rid]		set rid [getObjOption $sid rid]		set session [getObjOption $sid session]	 	if { [eof $sock] } { 			status_log "WebCam Socket $sock closed\n" 			close $sock 			return 		}		set data ""		switch $state {			"AUTH"			{				if { $server } {					nbgets $sock data					status_log "Received Data on socket $sock $my_rid - $rid server=$server - state=$state : \n$data\n" red					if { $data == "recipientid=${my_rid}&sessionid=${session}\r" } {						nbgets $sock						setObjOption $sock state "CONNECTED"						catch { fileevent $sock writable "::MSNCAM::WriteToSock $sock" }						setObjOption $sid socket $sock						CloseUnusedSockets $sid $sock					} else {						AuthFailed $sid $sock					}				}			}			"TSP_OK" 			{				nbgets $sock data				status_log "Received Data on Reflector socket $sock $my_rid - $rid server=$server - state=$state : \n$data\n" red				if { $data == "TSP/1.0 200 OK\r" } {					nbgets $sock 					setObjOption $sock state "TSP_CONNECTED"				} else {					status_log "ERROR AUTHENTICATING TO THE REFLECTOR - $data\n" red				}			}			"TSP_CONNECTED"			{				nbgets $sock data				status_log "Received Data on Reflector socket $sock $my_rid - $rid server=$server - state=$state : \n$data\n" red				if { $data == "CONNECTED\r" } {					nbgets $sock 					if { $producer } {						setObjOption $sock state "TSP_SEND"						catch { fileevent $sock writable "::MSNCAM::WriteToSock $sock" }					} else {						setObjOption $sock state "TSP_RECEIVE"					}									} else {					status_log "ERROR CONNECTING TO THE REFLECTOR - $data\n" red				}			}			"CONNECTED"			{				if { $server == 0 } {					nbgets $sock data					status_log "Received Data on socket $sock sending=$producer - server=$server - state=$state : \n$data\n" red					if { $data == "connected\r" } {						nbgets $sock						setObjOption $sid socket $sock						CloseUnusedSockets $sid $sock						puts -nonewline $sock "connected\r\n\r\n"						status_log "Sending \"connected\" to the server\n" red						if { $producer } {							setObjOption $sock state "SEND"							catch { fileevent $sock writable "::MSNCAM::WriteToSock $sock" }							AuthSuccessfull $sid $sock						} else {							setObjOption $sock state "RECEIVE"							AuthSuccessfull $sid $sock						}					} else {						status_log "ERROR2 : $data -  [nbgets $sock] - [nbgets $sock]\n" red						AuthFailed $sid $sock					}				}			}			"SEND" -			"CONNECTED2"			{				if {$server} {					set data [nbread $sock 13]					status_log "Received Data on socket $sock sending=$producer - server=$server - state=$state : \n$data\n" red					if { $data == "connected\r\n\r\n" } {						setObjOption $sid socket $sock						if { $producer == 0} {							setObjOption $sock state "RECEIVE"						}					} elseif { $producer == 0 } {						set header "${data}[nbread $sock 11]"						setObjOption $sock state "RECEIVE"						set size [GetCamDataSize $header]						if { $size > 0 } {							set data "$header[nbread $sock $size]"							::CAMGUI::ShowCamFrame $sid $data						} elseif { $size != 0 } {							setObjOption $sock state "END"							status_log "ERROR1 : $header - invalid data received" red						} else {							::CAMGUI::GotPausedFrame $sid						}					} else {						setObjOption $sock state "END"						status_log "ERROR2 : $data - [nbgets $sock] - [nbgets $sock]\n" red					}				} else {					setObjOption $sock state "END"					status_log "ERROR3 : [nbgets $sock] - should never received data on state $state when we're the client\n" red				}			}			"TSP_SEND" 			{							set data [nbread $sock 4]				#status_log "Received $data on state TSP_SEND" blue				if { $data == "\xd2\x04\x00\x00" } {					catch { fileevent $sock writable "::MSNCAM::WriteToSock $sock" }				} else {					setObjOption $sock state "END"					status_log "ERROR4 : Received $data from socket on state TSP_SEND \n" red				}			}                        "TSP_PAUSED"                        {                                set data [nbread $sock 4]                                if { $data != "\xd2\x04\x00\x00" } {                                        setObjOption $sock state "END"                                        status_log "ERROR4 : Received $data from socket on state TSP_PAUSED \n" red                                }                        }			"TSP_RECEIVE" -			"RECEIVE"			{				set header [nbread $sock 24]				set size [GetCamDataSize $header]				if { $size > 0 } {					set data "$header[nbread $sock $size]"					if { [::config::getKey webcamlogs] == 1 } {						set fd [getObjOption $sid weblog]						if { $fd == "" } {							set email [string tolower [lindex [::MSNP2P::SessionList get $sid] 3]]							if { ![catch {set fd [open [file join $::webcam_dir ${email}.cam] a]}] } {								fconfigure $fd -translation binary								setObjOption $sid weblog $fd								# Update cam sessions metadata								::log::UpdateCamMetadata $email							}						}											catch {puts -nonewline $fd $data}					}					catch { fileevent $sock readable "" }					after 0 "::CAMGUI::ShowCamFrame $sid [list $data];						 catch {fileevent $sock readable \"::MSNCAM::ReadFromSock $sock\"}"					if { $reflector } {						catch { fileevent $sock writable "::MSNCAM::WriteToSock $sock" }					}					#::CAMGUI::ShowCamFrame $sid $data				} elseif {$size != 0 }  {					#AuthFailed $sid $sock					setObjOption $sock state "END"					status_log "ERROR5 : $data - invalid data received" red				} else {					::CAMGUI::GotPausedFrame $sid				}			}			"END"			{				set chatid [getObjOption $sid chatid]				status_log "Closing socket $sock because it's in END state\n" red				catch { close $sock }				CancelCam $chatid $sid			}			default			{				status_log "option $state of socket $sock : [getObjOption $sock state] not defined.. receiving data [nbgets $sock]... closing \n" red				setObjOption $sock state "END"				catch { close $sock }			}		}		#puts  "Received Data on socket $sock sending=$sending - server=$server - state=$state : \n$data\n"		#status_log "Received Data on socket $sock sending=$sending - server=$server - state=$state : \n$data\n" red	}	proc WriteToSock { sock } {		catch { fileevent $sock writable "" }		set sid [getObjOption $sock sid]		set sending [getObjOption $sock sending]		set server [getObjOption $sock server]		set state [getObjOption $sock state]		set producer [getObjOption $sid producer]		set reflector [getObjOption $sid reflector]		set rid [getObjOption $sid rid]		set session [getObjOption $sid session]		# Uncomment next line to test for failed authentifications...		#set session 0		if { [fconfigure $sock -error] != "" } {			status_log "ERROR writing to socket!!! : [fconfigure $sock -error]" red			catch { close $sock }			return		}		set data ""		switch $state {			"AUTH"			{				if { $server == 0 } {					set data "recipientid=$rid&sessionid=$session\r\n\r\n"					setObjOption $sock state "CONNECTED"				}			}			"TID" 			{				if {$producer} {					set data "PROD [getObjOption $sock tid] TSP/1.0\r\n\r\n"					setObjOption $sock state "TSP_OK"				} else {					set data "VIEW [getObjOption $sock tid] TSP/1.0\r\n\r\n"					setObjOption $sock state "TSP_OK"				}			}			"CONNECTED"			{				set data "connected\r\n\r\n"				if { $producer } {					setObjOption $sock state "SEND"					catch { fileevent $sock writable "::MSNCAM::WriteToSock $sock" }					AuthSuccessfull $sid $sock				} else {					setObjOption $sock state "CONNECTED2"					AuthSuccessfull $sid $sock				}			}                        "TSP_SEND"			{                                after 250 "::CAMGUI::GetCamFrame $sid $sock"                        }

⌨️ 快捷键说明

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