Ver Fonte

small cleanup

Paul Klumpp há 12 anos atrás
pai
commit
dc577b49c5
2 ficheiros alterados com 43 adições e 58 exclusões
  1. 13 19
      central.rb
  2. 30 39
      connection.rb

+ 13 - 19
central.rb

@@ -3,9 +3,7 @@
  
 require 'rubygems'
 require 'digest/md5'
-require 'open3'
 
-#STDIN.sync = true
 STDOUT.sync = true
 
 $role_receives = ["ASSIGN_RE", "UNASSIGN_RE", "PING_RE", "ASSIGNMENTS_RE", "REQ_BC", "BC_RE"]
@@ -50,7 +48,7 @@ def put_not_to(to, cmd, payload)
 end
 
 def work(line)
-	put_log "GOT LINE: #{line}"
+	#put_log "GOT LINE: #{line}"
 	
 	line =~ /^\d+-\d+-\d+ \d+:\d+:\d+ \+\d+: (.+)$/
 	
@@ -72,28 +70,24 @@ def work(line)
 			cmd = $1
 		end
 		
+		if line =~ /^[A-Z_]+ (.+)/
+			payload = $1
+		end
+		
 		if allowed(cmd)	
+			# an allowed command with a seemingly valid payload has been received
 			
 			put_log "from: #{from}"
 			put_log "cmd: #{cmd}"
 			put_log "line: #{line}"
-
-			payload = ""
-			if line =~ /^[A-Z_]+ (.+)/
-				payload = $1
-			end
-			
-			# an allowed commands with a seemingly valid payload has been received
-			puts cmd
-			puts payload
+			put_log "payload #{payload}"
 			
 			if cmd == "REQ_BC"
 				
-				payload =~ /^(.+),(.+),(.+),'(.+)','(.+)'$/
-				#             n    f    s     ni     txt
-				# $&
-				# The string matched by the last successful pattern match in this scope, or nil if the last pattern match failed. (Mnemonic: like & in some editors.) This variable is read-only.
-				if not $& == nil
+				if payload =~ /^(.+),(.+),(.+),'(.+)','(.+)'$/
+					#             n    f    s     ni     txt
+					# $&
+					# The string matched by the last successful pattern match in this scope, or nil if the last pattern match failed. (Mnemonic: like & in some editors.) This variable is read-only.
 					network = $1
 					freqname = $2
 					source = $3
@@ -115,8 +109,8 @@ def work(line)
 
 			end # of REQ_BC
 
-		else
-			put_log "UH '#{line}'"
+		else # of allowed cmd - means .. we don't handle these:
+			put_log "'#{line}'"
 		end
 	end
 	

+ 30 - 39
connection.rb

@@ -360,7 +360,7 @@ def main
 		
 		if check_allow_processing(inputmessage, $user)
 			
-			if inputmessage =~ /^([!]?to):([a-zA-Z_]+): (.+)/
+			if inputmessage =~ /^([!]?to):([a-zA-Z_\.]+): (.+)/
 				sendmode = $1
 				to_user = $2
 				inputmessage = $3
@@ -371,28 +371,25 @@ def main
 			if inputmessage =~ /^([A-Z_]+)/
 				cmd = $1
 			end
+			# now we have the cmd .. or not ;)
+			
+		  if inputmessage =~ /^[a-zA-Z_]+ (.+)/
+				payload = $1
+			end
+			# now we can use payload
 			
 			if allowed_cmd(cmd)
-
-				
-				if inputmessage =~ /^[a-zA-Z_]+ (.+)/
-					payload = $1
-				end
-
 				if cmd == "PING"
 					put_log "PONG"
 
-				elsif inputmessage =~ /^(REQ_BC)/
+				elsif cmd == "REQ_BC"
 
-					inputmessage =~ /^(REQ_BC) (.+),(.+),(.+),'(.+)','(.+)'$/
-					#                           n    f    s     ni     txt
-					error = 0
-					# $&
-					# The string matched by the last successful pattern match in this scope, or nil if the last pattern match failed. (Mnemonic: like & in some editors.) This variable is read-only.
-					if $& == nil
-						put_log "SYS Command format is REQ_BC <network>,<frequency>,<source/channel>,'<nickname>','<message>'"
-						error = 1
-					else
+					# help with format .. but send the raw payload
+					if payload =~ /^(.+),(.+),(.+),'(.+)','(.+)'$/
+						#              n    f    s     ni     txt
+						error = 0
+						# $&
+						# The string matched by the last successful pattern match in this scope, or nil if the last pattern match failed. (Mnemonic: like & in some editors.) This variable is r
 						command = "BC"
 						network = $2
 						freqname = $3
@@ -400,51 +397,45 @@ def main
 						nickname = $5
 						text = $6
 
-						if network =~ /^(QWalt)|(QDEV)/
-						else
+						if not network =~ /^(QWalt)|(QDEV)/
 							put_log "SYS Network name #{network} is unknown: QWalt or QDEV allowed."
 							error = 1
 						end
 
-						if freqname =~ /^(-qw-)|(-spam-)|(-dev-)/
-						else
+						if not freqname =~ /^(-qw-)|(-spam-)|(-dev-)/
 							put_log "SYS Frequency name is unknown #{freqname}"
 							error = 1
 						end
 
-						if source =~ /^(#.+)|(qw:\/\/)|(http:\/\/)/
-						else
+						if not source =~ /^(#.+)|(qw:\/\/)|(http:\/\/)/
 							put_log "SYS Source string is not in the form ^(#.+)|(qw:\/\/)|(http:\/\/)  was: #{source}"
 							error = 1
 						end
 
-						if nickname =~ /^.+/ 
-						else
+						if not nickname =~ /^.+/ 
 							put_log "SYS Nickname string is not in the form ^.+  #{nickname}"
 							error = 1
 						end
 
-						if text =~ /^.+/
-						else
+						if not text =~ /^.+/
 							put_log "SYS Message string is not in the form ^.+ #{text}"
 							error = 1
 						end
+						
+					else # of check syntax
+						put_log "SYS Command format is REQ_BC <network>,<frequency>,<source/channel>,'<nickname>','<message>'"
+						error = 1
 					end
 
 					if error == 0
-						# building hash here (bcid)
-						#bcid = Digest::MD5.hexdigest("%d %s %s %s %s %s" % [Time.now.utc.to_i, network, freqname, source, nickname, text])
-
-						#finalmessage = "%s %s %s,%s,%s,'%s','%s'" % [command, bcid, network, freqname, source, nickname, text]
-						#send("/topic/messages", finalmessage)
-						#put_log "BC_ID #{bcid} for: #{network},#{freqname},#{source}"
 						
-						finalmessage = "%s,%s,%s,'%s','%s'" % [network, freqname, source, nickname, text]
-						send_cmd("REQ_BC", finalmessage)
-					
+						payload = "%s,%s,%s,'%s','%s'" % [network, freqname, source, nickname, text]
+						send_cmd(cmd, payload)
+						# send REQ_BC to the corresponding role.
+						
 					end
 
-				elsif inputmessage =~ /^(BC_RE)/ 
+				elsif cmd == "BC_RE"
 					
 					inputmessage =~ /^(BC_RE) (.+) (.+)=(\d+),(.+)=(\d+)$/
 					if $& == nil
@@ -472,7 +463,7 @@ def main
 					end
 
 					
-				elsif inputmessage =~ /^(C)/ 
+				elsif cmd == "C"
 					
 					inputmessage =~ /^(C) (.+)$/
 					error = 0
@@ -504,7 +495,7 @@ def main
 						
 					end
 					
-				end
+				end # of if command == xyz
 			
 			
 			else  # of if allowed command