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