Kaynağa Gözat

more cleanup

Paul Klumpp 12 yıl önce
ebeveyn
işleme
7f38e7d235
2 değiştirilmiş dosya ile 23 ekleme ve 54 silme
  1. 2 2
      central.rb
  2. 21 52
      connection.rb

+ 2 - 2
central.rb

@@ -100,7 +100,7 @@ def work(line)
 					
 					# so it only reaches the issuer of REQ_BC
 					put_to(from, "BC_ID", "#{bcid} for: #{network},#{freqname},#{source}")
-					#$broadcasts[bcid] = m_user
+					$broadcasts[bcid] = from
 					
 					finalmessage = "%s %s,%s,%s,'%s','%s'" % [bcid, network, freqname, source, nickname, text]
 					put_not_to(from, "BC", finalmessage)
@@ -133,7 +133,7 @@ end
 
 def giving
 	inputmessage = ""
-	while inputmessage != "PART" 
+	while inputmessage != "quit" 
 		
 		inputmessage = ""
 		inputmessage = STDIN.gets.chomp

+ 21 - 52
connection.rb

@@ -5,42 +5,11 @@ require 'rubygems'
 require 'stomp'
 require 'digest/md5'
 
-
-#users = [ "mihawksrv", "qwnu", "qwnuposter", "pauldevqw", "paulkibito" ]
-
-
-# WRITE COMMANDS as ROLE everyone:
-# PING		- reply from central: PONG
-# WHO		- reply from everyone: WHO_RE
-# C		- reply from central: C 
-# PART		- reply from central: SYS Goodbye
-
-# WRITE COMMANDS as ROLE broadcast:
-# REQ_BC	- reply from central: BC_ID
-# BC_RE
-
-# WRITE COMMANDS as ROLE adminspecbots:
-# REQ_ASSIGN	- reply from specbot: assign_re..
-# REQ_UNASSIGN	- reply from specbot: unassign_re..
-# REQ_PING	- reply from specbots: ping_re..
-# REQ_ASSIGNMENTS	- reply from specbot: assignments_re..
-
-# WRITE COMMANDS as ROLE specbot:
-# ASSIGN_RE
-# UNASSIGN_RE
-# PING_RE
-# ASSIGNMENTS_RE
-
-# USERS: ROLE
-# paulkibito: broadcast
-# qwnu: broadcast
-# mihawk: broadcast specbot
-# pauldevqw: broadcast specbot
-# qwsbalance: adminspecbots
-#
 # .. allowed commands .. ROLES = CAPABILITIES
 # normal users have ROLE broadcast. Roles are defined on a per-user basis .. in a config.
 
+$version = "0.10big_yadda"
+
 $role_commands = Hash[
 	"everyone" => ["PING", "WHO", "C", "PART"], 
 	
@@ -177,7 +146,7 @@ def consuming()
 					put_log "C #{m_user}: #{m_pload}"
 					
 				elsif m_cmd =~ /^WHO$/
-					reply_to_msg(msg, "WHO_RE", "#{$user}' ROLES: #{$user_roles[$user].join(", ")}")
+					reply_to_msg(msg, "WHO_RE", "#{$user}' on '#{$version}' ROLES: #{$user_roles[$user].join(", ")}")
 
 				elsif m_cmd =~ /^PART$/
 					put_log "PARTED User '#{m_user}' just left the party."
@@ -338,7 +307,7 @@ def main
 	
 	$broadcasts = Hash.new
 	
-	put_log "HELLO Hi user '#{$user}'! How are you?"
+	put_log "HELLO Hi user '#{$user}'! How are you? I'm #{$version}"
 	put_log "ROLES #{$my_roles.join(", ")}"
 	put_log "COMMANDS #{$my_cmds.join(", ")}"
 	
@@ -437,10 +406,8 @@ def main
 
 				elsif cmd == "BC_RE"
 					
-					inputmessage =~ /^(BC_RE) (.+) (.+)=(\d+),(.+)=(\d+)$/
-					if $& == nil
-						put_log "SYS Format is BC_RE <bcid> <userstring>=<usercount>,<itemstring>=<itemcount>"
-					else
+					if inputmessage =~ /^(BC_RE) (.+) (.+)=(\d+),(.+)=(\d+)$/
+						
 						command = $1
 						bcid = $2
 						user_string = $3
@@ -448,38 +415,40 @@ def main
 						item_string = $5
 						item_count = $6
 						
-						
-						finalmessage = "%s %s %s=%d,%s=%d" % [command, bcid, user_string, user_count, item_string, item_count]
+						payload = "%s %s %s=%d,%s=%d" % [command, bcid, user_string, user_count, item_string, item_count]
 						# according bcid it is possible to get the originating user.. so send only to his topic!
 						
 						if $broadcasts[bcid]
 							to_user = $broadcasts[bcid]
 							put_log "SYS Broadcast reply bcid: #{bcid} underway. To: '#{to_user}'."
-							send("/topic/#{to_user}-replies", finalmessage)
+							send("/topic/#{to_user}-replies", payload)
+							#send_cmd(cmd, payload)  .. and thus: central_brain has to collect the BC_REs
 						else
 							put_log "SYS Broadcast reply bcid: #{bcid} underway."
-							send("/topic/messages", finalmessage)
+							send("/topic/broadcast", payload)
+							#send_cmd(cmd, payload)  .. and thus: central_brain has to collect the BC_REs
+							
 						end
+					else
+						put_log "SYS Format is BC_RE <bcid> <userstring>=<usercount>,<itemstring>=<itemcount>"
 					end
 
 					
 				elsif cmd == "C"
 					
-					inputmessage =~ /^(C) (.+)$/
-					error = 0
-					if $& == nil
-						put_log "SYS Format is C <chattext>"
-						error = 1
+					if payload =~ /^(.+)$/
+						put_log "C #{$user}: #{$1}"
+						send_cmd("C", "#{$1}")
 					else
-						put_log "C #{$user}: #{$2}"
-						send_cmd("C", "#{$2}")
+						put_log "SYS Format is C <chattext>"
 					end
 					
-				elsif inputmessage =~ /^(WHO)/
+				elsif cmd == "WHO"
+					
 					put_log "SYS Asking who's here."
 					send_cmd("WHO", "is here?")
 
-				elsif inputmessage =~ /^(PART)$/
+				elsif cmd == "PART"
 					put_log "SYS Goodbye '#{$user}'."
 					send_cmd("PART", "The party was fun.")