<commit_before>module Wayfarer
	module Engine

		attr_reader :user
		attr_reader :character
		attr_accessor :identifier
		attr_accessor :target

		#Used by admin non-game connections
		attr_accessor :admin

		#Used by server connections
		attr_accessor :plane

		def character=(val)
			@mutex = Mutex.new
			@icd = Time.now.to_f * 1000
			@queue = Queue.new
			@character = val
			@user = val.account
		end

		def throttle(method, json = {}, icd = 150)
			now = Time.now.to_f  * 1000
			if now - icd >= @icd
				# Can perform action
				@icd += icd
				@icd = now + icd if @icd <= now
				return false
			else
				# Throttle

				locked = @mutex.try_lock
				icd = @icd + icd - now < icd ? @icd + icd - now : icd
				icd = 1 if icd < 1
				if @queue.length >= 5
					Entity::Message.send_transient([character.id], "Cannot queue #{method}, please wait for the #{@queue.length} queued throttled actions to complete!", MessageType::DEBUG)
				else
					@queue.push [method, json, icd]
					Entity::Message.send_transient([character.id], "Queueing #{method} for ~#{icd}ms due to input throttle...", MessageType::DEBUG)
				end

				if locked

					start = Time.now

					while @queue.length > 0 do
						command = @queue.pop
						@icd = Time.now.to_f * 1000 + command[2] + 100
						sleep command[2].to_f / 1000.to_f
						Entity::Message.send_transient([character.id], "Executing throttled #{command[0]}, #{@queue.length} other commands remain in the queue...", MessageType::DEBUG)
						@icd = 0
						self.__send__ command[0], command[1]
						@icd = Time.now.to_f * 1000 + command[2]
						if Time.now - start > 5
							Entity::Message.send_transient([character.id], 'Throttled queued actions taking too long, clearing queue - Please spam inputs less!', MessageType::DEBUG)
							@queue.clear
							@icd = 0
							return true
						end
					end


					@mutex.unlock
				end

				return true
			end
		end
<commit_msg>simpler throttle<commit_after>module Wayfarer
	module Engine

		attr_reader :user
		attr_reader :character
		attr_accessor :identifier
		attr_accessor :target

		#Used by admin non-game connections
		attr_accessor :admin

		#Used by server connections
		attr_accessor :plane

		def character=(val)
			@icd = Time.now.to_f * 1000
			@character = val
			@user = val.account
		end

		def throttle(method, json = {}, icd = 150)
			now = Time.now.to_f  * 1000
			if now - icd >= @icd
				# Can perform action
				@icd += icd
				@icd = now + icd if @icd <= now
				return false
			else
				# Throttle
				w = (@icd - (now - icd)).to_f.abs / 1000
				Entity::Message.send_transient([character.id], "Queueing #{method} for ~#{w}ms due to input throttle...", MessageType::DEBUG)
				sleep w
				return false
				end
			end
		end

{'fraction_non_alphanumeric': 0.11305616338439095, 'fraction_numerical': 0.019693654266958426, 'mean_word_length': 2.742155525238745, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 8, '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': '6111850', 'n_tokens_mistral': 1211, 'n_tokens_neox': 913, 'n_words': 272}