diff --git a/conf/config.yaml b/conf/config.yaml index 7424243db5e12cc023d4f1471d927b5884d94791..b5da3ca1e142ef7477c75182f8f1350b2b2c2341 100644 --- a/conf/config.yaml +++ b/conf/config.yaml @@ -9,7 +9,7 @@ :restart_delay: 10 :address: 0.0.0.0 :intro_file: intro.txt -:start_room: fc511e2c-863e-daf1-87be-6214f59c013a +:start_room: 16326a80-4ec1-91b7-cfad-3e3d79b7a619 :restart_limit: 15 :mccp: false :mssp: false diff --git a/lib/aethyr/core/connection/player_connect.rb b/lib/aethyr/core/connection/player_connect.rb index 4a4c5591bff911ddd0f455ead9f03df539b4f5ff..ed722a7981cb803fbbc2eb22d5d26c7ed895046e 100644 --- a/lib/aethyr/core/connection/player_connect.rb +++ b/lib/aethyr/core/connection/player_connect.rb @@ -15,12 +15,13 @@ class PlayerConnection include Editor #Input buffer - attr_reader :in_buffer, :display + attr_reader :in_buffer, :display, :socket attr_accessor :word_wrap - def initialize(display, addrinfo, *args) + def initialize(socket, addrinfo, *args) super(*args) - @display = display + @display = Display.new(socket) + @socket = socket @in_buffer = [] @paginator = nil @@ -120,6 +121,7 @@ class PlayerConnection #Close the io connection def close - close_connection_after_writing + display.close + @closed = true end end diff --git a/lib/aethyr/core/connection/server.rb b/lib/aethyr/core/connection/server.rb index 764e98b54d9708e59654814145790cb451bb4468..cbf1b6b38c8673d4f7706a62b536a8c7d2f31629 100644 --- a/lib/aethyr/core/connection/server.rb +++ b/lib/aethyr/core/connection/server.rb @@ -67,32 +67,24 @@ module Aethyr end players.each do |player| - player.display.set_term - player.receive_data + begin + player.receive_data + rescue Exception => e + log "Closing connection for #{player}" + begin + player.socket.close + rescue + end + players.delete(player) + log e.message + "\n" + e.backtrace.join("\n") unless player.closed? + end end end -# 4.times do # Adjust this number for the pool size -# next unless fork.nil? # Parent only calls fork -# loop do # Child does this work -# handle_client(*listener.accept) -# end -# return 0 -# end - clean_up_children return 0 # Return code -# EventMachine.run do -# EventMachine.add_periodic_timer(ServerConfig.update_rate) { $manager.update_all } -# if ServerConfig.save_rate and ServerConfig.save_rate > 0 -# EventMachine.add_periodic_timer(ServerConfig.save_rate * 60) { log "Automatic state save."; $manager.save_all } -# end -# EventMachine.start_server address, port, PlayerConnection -# File.open("logs/server.log", "a") { |f| f.puts "#{Time.now} Server started." } -# log "Server up and running on #{address}:#{port}", 0 -# end rescue Interrupt => i log "Received interrupt: halting", 0 log i.inspect @@ -119,8 +111,7 @@ module Aethyr def handle_client(socket, addrinfo) begin - display = Display.new(socket) - player = PlayerConnection.new(display, addrinfo) + player = PlayerConnection.new(socket, addrinfo) puts "Connected: #{addrinfo.inspect}\n" return player rescue Errno::ECONNRESET, Errno::EPIPE @@ -138,63 +129,6 @@ module Aethyr puts 'All children have exited. Goodbye!' end -# def process_requests(socket) -# begin -# # initialize ncurses -# scr = Ncurses.newterm("vt100", socket, socket) -# Ncurses.set_term(scr) -# Ncurses.resizeterm(25, 80) -# Ncurses.cbreak # provide unbuffered input -# Ncurses.noecho # turn off input echoing -# Ncurses.nonl # turn off newline translation -# -# Ncurses.stdscr.intrflush(false) # turn off flush-on-interrupt -# Ncurses.stdscr.keypad(true) # turn on keypad mode -# -# Ncurses.stdscr.addstr("Press a key to continue") # output string -# Ncurses.stdscr.getch # get a charachter -# -# scr = Ncurses.stdscr -# -# #moving -# scr.clear() # clear screen -# scr.move(5,5) # move cursor -# scr.addstr("move(5,5)") -# scr.refresh() # update screen -# sleep(2) -# scr.move(2,2) -# scr.addstr("move(2,2)") -# scr.refresh() -# sleep(2) -# scr.move(10, 2) -# -# # two_borders -# # make a new window as tall as the screen and half as wide, in the left half -# # of the screen -# one = Ncurses::WINDOW.new(0, Ncurses.COLS() / 2, 0, 0) -# # make one for the right half -# two = Ncurses::WINDOW.new(0, Ncurses.COLS() - (Ncurses.COLS() / 2), -# 0, Ncurses.COLS() / 2) -# one.border(*([0]*8)) -# two.border(*([0]*8)) -# one.move(3,3) -# two.move(2,5) -# one.addstr("move(3,3)") -# two.addstr("move(2,5)") -# two.move(5,3) -# two.addstr("Press a key to continue") -# one.noutrefresh() # copy window to virtual screen, don't update real screen -# two.noutrefresh() -# Ncurses.doupdate() # update read screen -# two.getch() -# -# ensure -# Ncurses.echo -# Ncurses.nocbreak -# Ncurses.nl -# Ncurses.endwin -# end -# end end def self.main diff --git a/lib/aethyr/core/render/display.rb b/lib/aethyr/core/render/display.rb index f64003ca4d505eca8a6c692096170b893d60adb2..fe0e94440a347939cad9e046d2f93a1f6f713fb9 100644 --- a/lib/aethyr/core/render/display.rb +++ b/lib/aethyr/core/render/display.rb @@ -175,6 +175,7 @@ class Display Ncurses.nocbreak Ncurses.nl Ncurses.endwin + @socket.close end # Sets colors to defaults