File indexing completed on 2025-01-19 06:55:04
0001 #!/usr/bin/env ruby 0002 require 'kmuddy.rb' 0003 require 'eventserver.rb' 0004 require 'variablesock.rb' 0005 0006 include KMuddy # not necessary in order to use KMuddy interface; 0007 # I included this for easy access to the debug() 0008 # function, which just writes to STDOUT. 0009 $myport = 4567 0010 0011 evserver = EventServer.new($myport) # port can be anything. 0012 varsock = VariableSock.new() # no special options required here. 0013 threads = [ ] 0014 0015 # one thread for parsing STDIN, one for parsing "events". 0016 threads << Thread.new { 0017 while line = STDIN.gets.chomp 0018 # Normally one would parse the line of text from the server here. 0019 # Instead, I demonstrate the 'set' method of the VariableSock. 0020 # Check your variables in KMuddy after you receive text from the 0021 # mud. 0022 varsock.set("lastline",line) 0023 debug(varsock.get("lastline")) 0024 end 0025 } 0026 0027 threads << Thread.new { 0028 while (event = evserver.accept) 0029 line = event.gets.chomp 0030 debug(line) unless line.empty? 0031 exit(0) if line == "quit" 0032 varsock.command(line) 0033 event.close 0034 end 0035 } 0036 0037 threads.each { |task| task.join }