<commit_before>require 'socket'

require "classless_mud/version"

class Game
  def initialize
    @players = []
  end

  def add_player player
    @players << player
    self.start_game_for player
  end

  def start_game_for player
    player.handle_message "game starting"
  end
end

class Player
  def initialize client, name
    @client = client
    @name = name
  end

  def handle_message message
    @client.puts message
  end
end

module ClasslessMud
  server = TCPServer.new 2000

  game = Game.new
  puts "Starting server on port 2000"
  loop do
    Thread.start(server.accept) do |client|
      client.puts "Enter name:"
      name = client.gets
      client.puts name
      player = Player.new client, name
      client.puts player
      game.add_player player
    end
  end<commit_msg>Add simple game loop with quit command<commit_after>require 'socket'

require "classless_mud/version"

class Game
  def initialize
    @players = []
  end

  def add_player player
    @players << player
    self.start_game_for player
  end

  def start_game_for player
    player.handle_message "game starting"
    loop do
      input = player.gets
      if input == 'quit'
        player.puts "Are you sure you want to quit? y/n: "
        response = player.gets
        player.puts response
        if response == 'y' || response == 'Y'
          player.puts "Thanks for playing"
          player.close_client
        end
      else
        player.handle_message input
      end
    end
  end
end

class Player
  def initialize client, name
    @client = client
    @name = name
  end

  def handle_message message
    self.puts message
  end

  def gets
    @client.gets.chomp
  end

  def puts message
    @client.puts message
  end

  def close_client
    @client.close
  end
end

module ClasslessMud
  server = TCPServer.new 2000

  game = Game.new
  puts "Starting server on port 2000"
  loop do
    Thread.start(server.accept) do |client|
      client.puts "Enter name:"
      name = client.gets
      client.puts name
      player = Player.new client, name
      client.puts player
      game.add_player player
    end
  end
{'fraction_non_alphanumeric': 0.06384976525821597, 'fraction_numerical': 0.007511737089201878, 'mean_word_length': 2.4096, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2930579', 'n_tokens_mistral': 680, 'n_tokens_neox': 651, 'n_words': 213}