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

📄 config.tcl

📁 Linux下的MSN聊天程序源码
💻 TCL
📖 第 1 页 / 共 4 页
字号:
		set webcam_dir ""		# Set variables for default profile		::config::setKey save_password 0		::config::setKey keep_logs 0		::config::setKey log_event_connect 0		::config::setKey log_event_disconnect 0		::config::setKey log_event_email 0		::config::setKey log_event_state 0	}}#///////////////////////////////////////////////////////////////////////////////# CreateProfile ( email )# Creates a new profile# email : email of new profileproc CreateProfile { email } {	global HOME HOME2 log_dir webcam_dir password lockSock loginmode	if { [LoginList exists 0 $email] == 1 } {		msg_box [trans profileexists]		return -1	}	# If first time loading from default profile, make sure .amsn/config exists	if { ($HOME == $HOME2) && ([file exists [file join $HOME2 config.xml]] == 0) } {		save_config	}	set oldlogin [::config::getKey login]	status_log "Creating new profile for $email\n" blue	# Create a new profile with $email	# Set HOME dir and create it	set dirname [string map {"@" "_" "." "_"} $email]	#set dirname [split $email "@ ."]	#set dirname [join $dirname "_"]	set newHOMEdir "[file join $HOME2 $dirname]"	create_dir $newHOMEdir	set log_dir "[file join ${newHOMEdir} logs]"	create_dir $log_dir	set webcam_dir "[file join ${newHOMEdir} webcam]"	create_dir $webcam_dir	# Load default config initially	file copy -force [file join $HOME2 config.xml] $newHOMEdir	set oldhome $HOME	set HOME $newHOMEdir	::config::setKey login $email	load_config	save_config	::config::setKey login $oldlogin	set HOME $oldhome	load_config	unset oldhome	unset newHOMEdir	# Add to login list	LoginList add 0 $email 0	SaveLoginList	# Redraw combobox with new profile	if { [winfo exists .login] } {		set loginmode 1		RefreshLogin .login.main 1		.login.main.box list delete 0 end		set idx 0		set tmp_list ""		while { [LoginList get $idx] != 0 } {			lappend tmp_list [LoginList get $idx]			incr idx		}		eval .login.main.box list insert end $tmp_list		unset idx		unset tmp_list		# Select the new profile in combobox		set window .login.main.box		set cb [$window list get 0 [LoginList size 0]]		set index [lsearch $cb $email]		$window select $index	}	return 0}proc gethomes {} {	global HOME HOME2 log_dir	status_log "HOME = $HOME \nHOME2 = $HOME2\nlogin = [::config::getKey login]\nlog_dir = $log_dir\n"}#///////////////////////////////////////////////////////////////////////////////# DeleteProfile ( email )# Delete profile given by email, has to be different than the current profile# entrypath : Path to the combobox containing the profiles list in preferencesproc DeleteProfile { email entrypath } {	global HOME2	if { $email == "" } {		return	}	#Reload profiles file	LoadLoginList 1	# Make sure profile isn't locked	if { $email == [::config::getKey login] } {		msg_box [trans cannotdeleteprofile]		return	}	if { [CheckLock $email] == -1 } {		msg_box [trans cannotdeleteprofile]		return	}	set answer [::amsn::messageBox "[trans confirmdelete ${email}]" yesno question]	if {$answer == "no"} {	return	}	set dir [string map {"@" "_" "." "_"} $email]	#set dir [split $email "@ ."]	#set dir [join $dir "_"]	set entryidx [$entrypath curselection]	if {$entryidx == "" } {		set entryidx 0	}	catch { file delete -force [file join $HOME2 $dir] }	$entrypath list delete $entryidx	$entrypath select 0	LoginList unset 0 $email	# Lets save it into the file	SaveLoginList}#///////////////////////////////////////////////////////////////////////////////# CheckLock ( email )# Check Lock of profile given by email# Return -1 if profile is already locked, returns 0 otherwiseproc CheckLock { email } {	global response LockList	set response ""	set Port [LoginList getlock 0 $email]	status_log "CheckLock: LoginList getlock called. Lock=$Port\n" blue	if { $Port != 0 } {		if { [catch {socket -server phony $Port} newlockSock] != 0  } {			status_log "CheckLock Port is already in use: $newlockSock\n" red			# port is taken, let's make sure it's a profile lock			foreach {local_host} { localhost "[info hostname]" 127.0.0.1 } {				if {[catch {socket $local_host $Port} clientSock] == 0 } {					set done 1					status_log "CheckLock: Can connect to port. Sending PING\n" blue					fileevent $clientSock readable "lockcltHdl $clientSock"					fconfigure $clientSock -buffering line					puts $clientSock "AMSN_LOCK_PING"					after 5000 [list set response failed]					vwait response					if { $response == "AMSN_LOCK_PONG" } {						status_log "CheckLock: Got PONG response\n" green						# profile is locked						close $clientSock						return -1					} elseif { $response == "failed" } {						status_log "CheckLock: failed to get response from port $Port. Reseting to 0\n" blue						LoginList changelock 0 $email 0					} else {						status_log "CheckLock: another program using port $Port. Reseting to 0\n" blue						# other non amsn program is using the lock port, we better reset the lock to 0						LoginList changelock 0 $email 0					}				break				}			}		} else {			status_log "CheckLock: Port $Port is free!!\n" green			close $newlockSock		}	} else {		status_log "CheckLock: Port is zero\n" blue	}	return 0}proc lockcltHdl { sock } {	global response	set response [gets $sock]}#///////////////////////////////////////////////////////////////////////////////# GetRandomProfilePort ()# Returns a random port in range 60535-65335proc GetRandomProfilePort { } {	set trigger 0	while { $trigger == 0 } {		# Generate random port between 60535 and 65535		set Port [expr rand()]		set Port [expr {$Port * 5000}]		set Port [expr {int($Port)}]		set Port [expr {$Port + 60535}]		# Check if port isn't on another profile already		if { [LoginList lockexists 0 $Port] != 1 } {			set trigger 1		}	}	return $Port}#///////////////////////////////////////////////////////////////////////////////# LockProfile ( email )# Creates a new lock for given profile, tries random ports until one worksproc LockProfile { email } {	status_log "LockProfile: Locking $email\n" blue	global lockSock	set tries 0	while { $tries < 5 } {		set Port [GetRandomProfilePort]		status_log "LockProfile: Got random port $Port\n" blue		if { [catch {socket -server lockSvrNew $Port} newlockSock] == 0  } {			LoginList changelock 0 $email $Port			set lockSock $newlockSock			break		} elseif {$tries >= 5} {			::amsn::errorMsg "Unable to get a socket from locahost.\n Check your /etc/hosts file, please."			exit 1		} else {			catch {status_log "unable to create socket on port $Port - $newlockSock"}			incr tries		}	}#	if { $trigger == 1 } {		#vwait events#	}}proc lockSvrNew { sock addr port} {	status_log "lockSvrNew: Accepting connection on port $port\n" blue#	if { $addr == "127.0.0.1" } {		fileevent $sock readable "lockSvrHdl $addr $sock"		fconfigure $sock -buffering line#	}}proc lockSvrHdl { addr sock } {	status_log "lockSvrHdl: handling connection\n" blue	set command [gets $sock]	if {[eof $sock]} {	    catch {close $sock}	    close_remote $sock	} else {		if { $command == "AMSN_LOCK_PING" } {			# don't allow anyone to ping and know we are an amsn port unless it's coming from the localhost			if { $addr == "127.0.0.1" } {				status_log "lockSvrHdl: PING - PONG\n" blue				catch {puts $sock "AMSN_LOCK_PONG"}			}		} else {		    read_remote $command $sock		}	}}#///////////////////////////////////////////////////////////////////////# WinRegKey ( [addrem] )# Adds or removes the registry key to start amsn on startup (windows only)# Arguments:#  - addrem => choice of adding or removing the registry key: (add/remove)# Result: Returns 0/1 for failure/success (note failure could include failure to remove the temporary#         file after completion, but the registry key may have still been created/removedproc WinRegKey { addrem } {	if {$::tcl_platform(platform) == "windows"} {	    set filename [file join $::env(TEMP) amsn_addrem.reg]		if { [catch { set file_id [open "$filename" w]} res]} {			msg_box "Failed to create temporary file with error:\n$res"			return 0		}		puts $file_id "REGEDIT4\n"		puts $file_id "\[HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Run\]"		if { $addrem == "add" } {		    set amsn_path [file nativename [file normalize [file join [file dirname [info nameofexecutable]] .. amsn.exe]]]		    puts $file_id "\"amsn\"=\"\\\"[string map {"\\" "\\\\"} $amsn_path]\\\"\"\n"		} else {		    puts $file_id "\"amsn\"=-"		}				close $file_id		if { [catch { exec regedit /s "$filename"} res]} {			msg_box "Failed to create/remove the registry key with error:\n$res"			return 0		}				if { [catch { file delete "$filename"} res]} {			msg_box "Failed to delete temporary file with error:\n$res"			return 0		}		return 1	}	return 0} #///////////////////////////////////////////////////////////////////////#///////////////////////////////////////////////////////////////////////# create_dir(path)# Creates a directoryproc create_dir {path} {   global tcl_platform   if {[file isdirectory $path] == 0} {      if { [catch {file mkdir $path} res]} {         return -1      }      if {$tcl_platform(platform) == "unix"} {         file attributes $path -permissions 00700      }      return 0   } else {      return 1   }}#///////////////////////////////////////////////////////////////////////if { $initialize_amsn == 1 } {	###############################################################	create_dir $HOME	create_dir $HOME/plugins	create_dir $HOME/skins	#create_dir $log_dir	#create_dir [::config::getKey receiveddir]	scan_languages	::config::configDefaults	::config::loadGlobal	load_lang ;#Load default english language	load_lang [::config::getGlobalKey language]	;# Load of logins/profiles in combobox	;# Also sets the newest login as config(login)	;# and modifies HOME with the newest user	if { [LoadLoginList]==-1 } {		exit	}	global gui_language	set gui_language [::config::getGlobalKey language]	load_config		;# So this loads the config of this newest dude	# Init skin and smileys	::skin::reloadSkin [::config::getGlobalKey skin]}

⌨️ 快捷键说明

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