<commit_before>#!/usr/bin/env ruby -w
module Ghostpoker
  class Server
    def initialize(port, ip)
      @server = TCPServer.open(ip, port)
      @connections = Hash.new
      @clients = Hash.new
      @connections[:server] = @server
      @connections[:clients] = @clients
    end

    def run
      loop {
        Thread.start(@server.accept) do |client|
          player = Player.get client.gets
          ap player.name
          ap player.money
          @connections[:clients][player.money] = client
        end
      }.join
    end

    def listen_user_message(username, client)
      #loop {<commit_msg>Added locking of the resource when checking for an existing user<commit_after>#!/usr/bin/env ruby -w
module Ghostpoker
  class Server
    def initialize(port, ip)
      @server = TCPServer.open(ip, port)
      @connections = Hash.new
      @clients = Hash.new
      @players = Hash.new
      @connections[:server]  = @server
      @connections[:clients] = @clients
      @connections[:players] = @players
      $mutex = Mutex.new
    end

    def run
      loop {
        Thread.start(@server.accept) do |client|
          player = Player.get client.gets
          $mutex.lock
          @connections[:client].each do |other_name, other_client|
            if other_name == player.name || other_client == client
              client.puts "This username is already in use"
              Thread.kill self
            end
          end
          $mutex.unlock
          @connections[:clients][player.name] = client
          @connections[:players][player.name] = player
        end
      }.join
    end

    def listen_user_message(username, client)
      #loop {
{'fraction_non_alphanumeric': 0.10113704368641532, 'fraction_numerical': 0.0, 'mean_word_length': 2.084870848708487, 'pattern_counts': {'":': 0, '<': 3, '<?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': '6684788', 'n_tokens_mistral': 496, 'n_tokens_neox': 473, 'n_words': 124}