mirror of
https://github.com/cliffe/BreakEscape.git
synced 2026-02-21 19:28:03 +00:00
Refactor whitespace and comments for consistency in BreakEscape controllers and models
- Cleaned up unnecessary whitespace in `games_controller.rb`, `missions_controller.rb`, `game.rb`, `mission.rb`, `routes.rb`, `seeds.rb`, and migration files to enhance code readability. - Standardized comment formatting across various files to maintain consistency and improve clarity.
This commit is contained in:
@@ -62,9 +62,9 @@ module BreakEscape
|
||||
elsif params[:standalone_flags].present?
|
||||
flags = if params[:standalone_flags].is_a?(Array)
|
||||
params[:standalone_flags]
|
||||
else
|
||||
else
|
||||
params[:standalone_flags].split(',').map(&:strip).reject(&:blank?)
|
||||
end
|
||||
end
|
||||
initial_player_state['standalone_flags'] = flags
|
||||
end
|
||||
|
||||
@@ -424,7 +424,7 @@ module BreakEscape
|
||||
authorize @game if defined?(Pundit)
|
||||
|
||||
task_id = params[:task_id]
|
||||
|
||||
|
||||
unless task_id.present?
|
||||
return render json: { success: false, error: 'Missing task_id' }, status: :bad_request
|
||||
end
|
||||
@@ -453,7 +453,7 @@ module BreakEscape
|
||||
end
|
||||
|
||||
result = @game.update_task_progress!(task_id, progress)
|
||||
|
||||
|
||||
Rails.logger.debug "[BreakEscape] Task progress updated: #{task_id} = #{progress}"
|
||||
render json: result
|
||||
end
|
||||
|
||||
@@ -27,7 +27,7 @@ module BreakEscape
|
||||
# - Standalone mode: Flag input form
|
||||
redirect_to "/break_escape/games/new?mission_id=#{@mission.id}"
|
||||
else
|
||||
# Legacy behavior for non-VM missions - auto-create game
|
||||
# Legacy behavior for non-VM missions - auto-create game
|
||||
@game = Game.find_or_create_by!(
|
||||
player: current_player,
|
||||
mission: @mission
|
||||
|
||||
@@ -345,7 +345,7 @@ module BreakEscape
|
||||
# Initialize objectives state structure
|
||||
def initialize_objectives
|
||||
return unless scenario_data['objectives'].present?
|
||||
|
||||
|
||||
player_state['objectivesState'] ||= {
|
||||
'aims' => {}, # { aimId: { status, completedAt } }
|
||||
'tasks' => {}, # { taskId: { status, progress, completedAt } }
|
||||
@@ -356,15 +356,15 @@ module BreakEscape
|
||||
# Complete a task with server-side validation
|
||||
def complete_task!(task_id, validation_data = {})
|
||||
initialize_objectives
|
||||
|
||||
|
||||
task = find_task_in_scenario(task_id)
|
||||
return { success: false, error: 'Task not found' } unless task
|
||||
|
||||
|
||||
# Check if already completed
|
||||
if player_state.dig('objectivesState', 'tasks', task_id, 'status') == 'completed'
|
||||
return { success: true, taskId: task_id, message: 'Already completed' }
|
||||
end
|
||||
|
||||
|
||||
# Validate based on task type
|
||||
case task['type']
|
||||
when 'collect_items'
|
||||
@@ -390,22 +390,22 @@ module BreakEscape
|
||||
when 'custom'
|
||||
# Custom tasks are completed via ink tags - no validation needed
|
||||
end
|
||||
|
||||
|
||||
# Mark task complete
|
||||
player_state['objectivesState']['tasks'][task_id] = {
|
||||
'status' => 'completed',
|
||||
'completedAt' => Time.current.iso8601
|
||||
}
|
||||
|
||||
|
||||
# Process onComplete actions
|
||||
process_task_completion(task)
|
||||
|
||||
|
||||
# Check if aim is now complete
|
||||
check_aim_completion(task['aimId'])
|
||||
|
||||
|
||||
# Update statistics
|
||||
self.tasks_completed = (self.tasks_completed || 0) + 1
|
||||
|
||||
|
||||
save!
|
||||
{ success: true, taskId: task_id }
|
||||
end
|
||||
@@ -413,11 +413,11 @@ module BreakEscape
|
||||
# Update task progress (for collect_items tasks)
|
||||
def update_task_progress!(task_id, progress)
|
||||
initialize_objectives
|
||||
|
||||
|
||||
player_state['objectivesState']['tasks'][task_id] ||= {}
|
||||
player_state['objectivesState']['tasks'][task_id]['progress'] = progress
|
||||
save!
|
||||
|
||||
|
||||
{ success: true, taskId: task_id, progress: progress }
|
||||
end
|
||||
|
||||
@@ -472,11 +472,11 @@ module BreakEscape
|
||||
# Process task.onComplete actions
|
||||
def process_task_completion(task)
|
||||
return unless task['onComplete']
|
||||
|
||||
|
||||
if task['onComplete']['unlockTask']
|
||||
unlock_objective_task!(task['onComplete']['unlockTask'])
|
||||
end
|
||||
|
||||
|
||||
if task['onComplete']['unlockAim']
|
||||
unlock_objective_aim!(task['onComplete']['unlockAim'])
|
||||
end
|
||||
@@ -498,11 +498,11 @@ module BreakEscape
|
||||
def check_aim_completion(aim_id)
|
||||
aim = scenario_data['objectives']&.find { |a| a['aimId'] == aim_id }
|
||||
return unless aim
|
||||
|
||||
|
||||
all_complete = aim['tasks'].all? do |task|
|
||||
task_status(task['taskId']) == 'completed'
|
||||
end
|
||||
|
||||
|
||||
if all_complete
|
||||
player_state['objectivesState']['aims'][aim_id] = {
|
||||
'status' => 'completed',
|
||||
@@ -551,9 +551,9 @@ module BreakEscape
|
||||
# Build VM context only if mission requires VMs and we're in Hacktivity mode
|
||||
vm_context = if mission&.requires_vms? && BreakEscape::Mission.hacktivity_mode?
|
||||
build_vm_context
|
||||
else
|
||||
else
|
||||
{}
|
||||
end
|
||||
end
|
||||
|
||||
# Add flags_by_vm and vm_ips from player_state for standalone mode
|
||||
state = player_state.is_a?(Hash) ? player_state : {}
|
||||
@@ -618,7 +618,7 @@ module BreakEscape
|
||||
# Ensure it's a hash before attempting to access it
|
||||
state = player_state.is_a?(Hash) ? player_state : {}
|
||||
vm_set_id = state['vm_set_id']
|
||||
|
||||
|
||||
return {} unless vm_set_id && BreakEscape::Mission.hacktivity_mode?
|
||||
|
||||
vm_set = ::VmSet.find_by(id: vm_set_id)
|
||||
|
||||
@@ -110,11 +110,11 @@ module BreakEscape
|
||||
|
||||
require 'nokogiri'
|
||||
doc = Nokogiri::XML(xml_content)
|
||||
|
||||
|
||||
# Remove namespaces for simpler XPath queries
|
||||
# SecGen uses xmlns="http://www.github/cliffe/SecGen/marker"
|
||||
doc.remove_namespaces!
|
||||
|
||||
|
||||
flags_by_vm = {}
|
||||
|
||||
doc.xpath('//system').each do |system|
|
||||
@@ -152,7 +152,7 @@ module BreakEscape
|
||||
vm = vm_context['vms'].find { |v| v['title'] == title }
|
||||
return vm.to_json if vm
|
||||
end
|
||||
|
||||
|
||||
# Standalone mode: use fallback, but override IP from vm_ips if available
|
||||
result = fallback.dup
|
||||
if vm_context && vm_context['vm_ips'] && vm_context['vm_ips'][title]
|
||||
|
||||
@@ -25,12 +25,12 @@ BreakEscape::Engine.routes.draw do
|
||||
put 'sync_state' # Periodic state sync
|
||||
post 'unlock' # Validate unlock attempt
|
||||
post 'inventory' # Update inventory
|
||||
|
||||
|
||||
# Objectives system
|
||||
get 'objectives' # Get current objective state
|
||||
post 'objectives/tasks/:task_id', to: 'games#complete_task', as: 'complete_task'
|
||||
put 'objectives/tasks/:task_id', to: 'games#update_task_progress', as: 'update_task_progress'
|
||||
|
||||
|
||||
# VM/Flag integration
|
||||
post 'flags', to: 'games#submit_flag' # Submit CTF flag for validation
|
||||
end
|
||||
|
||||
@@ -16,4 +16,3 @@ class RemoveUniqueGameConstraint < ActiveRecord::Migration[7.0]
|
||||
name: 'index_games_on_player_and_mission_non_unique'
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ cybok_total = 0
|
||||
|
||||
scenario_dirs.each do |dir|
|
||||
scenario_name = File.basename(dir)
|
||||
|
||||
|
||||
if SKIP_DIRS.include?(scenario_name)
|
||||
puts " SKIP: #{scenario_name}"
|
||||
skipped_count += 1
|
||||
|
||||
Reference in New Issue
Block a user