Class: CEML::Processor

Inherits:
Object
  • Object
show all
Defined in:
lib/ceml/processor.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.method_missing(*args) ⇒ Object

queue processing =



165
# File 'lib/ceml/processor.rb', line 165

def self.method_missing(*args); Queue.new.calls << args; end

.runObject



166
# File 'lib/ceml/processor.rb', line 166

def self.run(); Queue.new.run(self); end

Instance Method Details

#add_cast(incident_id, castings) ⇒ Object



40
41
42
43
44
# File 'lib/ceml/processor.rb', line 40

def add_cast(incident_id, castings)
  i = IncidentModel.new(incident_id)
  i.add_castings(castings)
  i.run(self)
end

#launch(incident_id, bytecode) ⇒ Object

incidents =



35
36
37
38
# File 'lib/ceml/processor.rb', line 35

def launch(incident_id, bytecode)
  incident_id ||= gen_code
  IncidentModel.new(incident_id).bytecode.value = bytecode
end

#log(s) ⇒ Object



127
128
129
# File 'lib/ceml/processor.rb', line 127

def log(s)
  CEML.log 1, s
end

#override_abort(new_message, player, player_obj) ⇒ Object



114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/ceml/processor.rb', line 114

def override_abort(new_message, player, player_obj)
  incident = player_obj.top_incident
  if incident
    incident.release(player_obj.id)
    unlatch(player[:squad_id], player[:id], incident.id)
    reset_player(player[:squad_id], player[:id])
    tell(player[:squad_id], player[:id], :message, :msg => 'aborted')
  else
    reset_player(player[:squad_id], player[:id])
    tell(player[:squad_id], player[:id], :message, :msg => 'nothing to abort from')
  end
end

#ping(bundle_id, player) ⇒ Object

requests =



51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/ceml/processor.rb', line 51

def ping(bundle_id, player)
  # log "ping(): #{bundle_id}, #{player[:id]}"
  Player.update(bundle_id, player, self) do |player|
    if incident_id = Player.new(player[:id]).top_incident_id
      IncidentModel.new(incident_id).run(self)
    else
      if player[:received]
        player_did_report({:player => player, :squad_id => bundle_id, :city => player[:city]}, nil)
      end
      simple_audition(bundle_id, player)
    end
  end
end

#player_answered_q(data, what) ⇒ Object Also known as: player_set



143
144
145
# File 'lib/ceml/processor.rb', line 143

def player_answered_q(data, what)
  Player.update data[:player][:bundle_id], data[:player].like(:id, :qs_answers), self
end

#player_did_report(*args) ⇒ Object



157
158
# File 'lib/ceml/processor.rb', line 157

def player_did_report(*args)
end

#player_said(data, what) ⇒ Object



131
132
133
# File 'lib/ceml/processor.rb', line 131

def player_said(data, what)
  tell('_', data[:player][:id], what[:key], what)
end

#player_seeded(data, what) ⇒ Object



148
149
150
151
152
153
154
155
# File 'lib/ceml/processor.rb', line 148

def player_seeded(data, what)
  p = data[:player].dup
  p.delete(:roles)
  p[:seeded] = "#{p[:bundle_id]}:#{what[:target]}:#{what[:role]}"
  CEML.log 3, "#{p[:id]}: seeded as #{p[:seeded]}"

  self.class.seed(p[:bundle_id], what[:target], p)
end

#recognize_override(cmd, new_message, player, player_obj) ⇒ Object

callbacks =



107
108
109
110
111
112
# File 'lib/ceml/processor.rb', line 107

def recognize_override(cmd, new_message, player, player_obj)
  if respond_to?("override_#{cmd}")
    send("override_#{cmd}", new_message, player, player_obj)
    true
  end
end

#reset_bundle(id) ⇒ Object



22
23
24
# File 'lib/ceml/processor.rb', line 22

def reset_bundle(id)
  Bundle.new(id).reset
end

#reset_player(bundle_id, player_id) ⇒ Object



65
66
67
# File 'lib/ceml/processor.rb', line 65

def reset_player(bundle_id, player_id)
  Bundle.new(bundle_id).reset_player(player_id)
end

#run_latestObject



26
27
28
# File 'lib/ceml/processor.rb', line 26

def run_latest
  IncidentModel.run_latest(self)
end

#seed(bundle_id, stanza_name, player) ⇒ Object



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/ceml/processor.rb', line 86

def seed(bundle_id, stanza_name, player)
  # log "seed(): #{bundle_id}, #{stanza_name}, #{player[:id]}"
  player[:tags].delete('new')
  Player.new(player[:id]).merge_new_player_data(player)

  # CEML.log 1, "UPDATED"

  b = Bundle.new(bundle_id)
  if incident_id = b.absorb?(player, stanza_name)
    IncidentModel.new(incident_id).run(self)
    true
  else
    b.register_in_rooms(player, stanza_name)
    false
  end
end

#set_bundle(id, castables) ⇒ Object

scripts/bundles =



16
17
18
19
20
# File 'lib/ceml/processor.rb', line 16

def set_bundle(id, castables)
  # log "set_bundle(): #{id}, #{castables.inspect}"
  castables.each{ |c| c.bundle_id = id }
  Bundle.new(id).castables = castables
end

#simple_audition(bundle_id, player) ⇒ Object

internals =



73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/ceml/processor.rb', line 73

def simple_audition(bundle_id, player)
  # log "audition(): #{bundle_id}, #{player[:id]}"
  b = Bundle.new(bundle_id)
  b.clear_from_all_rooms(player[:id])

  if incident_id = b.absorb?(player)
    IncidentModel.new(incident_id).run(self)
    return true
  end
  player_did_report({:player => player, :squad_id => bundle_id, :city => player[:city]}, nil)
  b.register_in_rooms(player)
end

#tell(sqid, player_id, key, meta) ⇒ Object



139
140
141
# File 'lib/ceml/processor.rb', line 139

def tell(sqid, player_id, key, meta)
  CEML.tells[player_id] << meta.merge(:key => key) if CEML.tells
end

#unlatch(sqid, player_id, incident_id) ⇒ Object



135
136
137
# File 'lib/ceml/processor.rb', line 135

def unlatch(sqid, player_id, incident_id)
  #no op
end