#!/usr/bin/env ruby require 'rubygems' require 'tinder' require 'open3' # CHANGE THESE TO FIT config = { # CAMPFIRE USER DETAILS :campfire_subdomain => '[techbelly]', :campfire_user => '[someone]', :campfire_password => '[password]', :campfire_room_name => 'Planetfall', # ZCODE DETAILS :dfrotz => '/Users/ben/Projects/campfrotz/dfrotz', :game => '/Users/ben/Projects/campfrotz/Planetfa.z3' } # editing this on the server campfire = Tinder::Campfire.new config[:campfire_subdomain] campfire.login config[:campfire_user], config[:campfire_password] room = campfire.find_room_by_name config[:campfire_room_name] frotzin, frotzout, frotzerr = Open3.popen3("#{config[:dfrotz]} -Z0 -w 3000 -p #{config[:game]}") room.speak "FROTZ STARTED" room.speak "Send messages to the game in ALL CAPS." def send_message_to_game? msg msg == msg.upcase end Thread.new do loop do while output = select([frotzout,frotzerr],nil,nil,0.25) output[0].each do |stream| room.speak(stream.gets) end end end end room.listen do |m| message = m[:message] frotzin.puts(message) if send_message_to_game?(message) end