Skip to content
This repository has been archived by the owner on Jun 11, 2023. It is now read-only.

Commit

Permalink
Merge pull request #396 from renatomassaro/nasty-virus
Browse files Browse the repository at this point in the history
Expand Storyline to include NastyVirus sub-chapter
  • Loading branch information
renatomassaro committed Jun 14, 2018
2 parents bd4537c + ed6eb1e commit b74ea5a
Show file tree
Hide file tree
Showing 22 changed files with 738 additions and 127 deletions.
29 changes: 22 additions & 7 deletions events.json
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,11 @@
},
"Story.Story": {
"receives": [
"Client.Action.Performed",
"Process.Created",
"Story.Step.Email.Sent",
"Story.Step.Reply.Sent",
"Story.Step.ActionRequested"
"Story.Step.ActionRequested",
],
"emits": [
"Story.Step.Proceeded",
Expand Down Expand Up @@ -188,8 +190,8 @@
"File.Added",
"File.Deleted",
"File.Uploaded",
"StoryEmailSentEvent",
"StoryReplySentEvent",
"Story.Email.Sent",
"Story.Reply.Sent",
"Story.Step.Restarted",
"Story.Step.Proceeded",
"Virus.Installed",
Expand All @@ -199,16 +201,29 @@
"Tutorial": {
"steps": {
"SetupPC": {
"filters": ["Account.Created"],
"emits": []
"filters": [],
"emits": ["Story.Email.Sent"]
},
"DownloadCracker": {
"filters": [
"File.Downloaded",
"File.Deleted"
"File.Deleted",
"Process.Created"
],
"emits": [
"File.Added",
"Story.Email.Sent"
]
},
"NastyVirus": {
"filters": [
"Process.Created",
"Client.Action.Performed",
"Server.Password.Acquired"
],
"emits": [
"File.Added"
"File.Added",
"Story.Email.Sent"
]
}
}
Expand Down
35 changes: 35 additions & 0 deletions lib/client/event/action.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import Helix.Event

defmodule Helix.Client.Event.Action do

event Performed do
@moduledoc """
`ClientActionPerformedEvent` is emitted when the client performed a custom
action that should be tracked by the backend for a specific behaviour.
Examples include the tutorial quest, which awaits for the player to open
apps in order to proceed with the storyline.
"""

alias Helix.Entity.Model.Entity
alias Helix.Client.Model.Client

event_struct [:client, :entity_id, :action]

@type t ::
%__MODULE__{
client: Client.t,
entity_id: Entity.id,
action: Client.action
}

@spec new(Client.t, Entity.id, Client.action) ::
t
def new(client, entity_id, action) do
%__MODULE__{
client: client,
entity_id: entity_id,
action: action
}
end
end
end
10 changes: 3 additions & 7 deletions lib/client/public/public.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ defmodule Helix.Client.Public.Client do
alias Helix.Client.Model.Client
alias Helix.Client.Web1.Public.Bootstrap, as: Web1Bootstrap

alias Helix.Client.Web1.Event.Action.Performed, as: Web1ActionPerformedEvent
alias Helix.Client.Event.Action.Performed, as: ClientActionPerformedEvent

@typep bootstrap_result :: Web1Bootstrap.bootstrap
@typep render_bootstrap_result :: Web1Bootstrap.rendered_bootstrap
Expand Down Expand Up @@ -39,12 +39,11 @@ defmodule Helix.Client.Public.Client do
It's up to the handlers of the `ClientActionPerformedEvent` to determine what
should be done with such information.
Emits: `Web1ActionPerformedEvent`
Emits: `ClientActionPerformedEvent`
"""
def broadcast_action(client, entity_id, action) do
client
|> get_action_event()
|> apply(:new, [entity_id, action])
|> ClientActionPerformedEvent.new(entity_id, action)
|> Event.emit()
end

Expand All @@ -61,7 +60,4 @@ defmodule Helix.Client.Public.Client do
do: Web1Bootstrap.render_bootstrap(bootstrap)
defp dispatch(_, :render_bootstrap, _),
do: %{}

defp get_action_event(:web1),
do: Web1ActionPerformedEvent
end
41 changes: 0 additions & 41 deletions lib/client/web1/event/action.ex

This file was deleted.

6 changes: 4 additions & 2 deletions lib/client/web1/model/web1.ex
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
defmodule Helix.Client.Web1.Model.Web1 do

@type action :: :tutorial_accessed_task_manager
@type action ::
:tutorial_accessed_task_manager
| :tutorial_spotted_nasty_virus

@actions [:tutorial_accessed_task_manager]
@actions [:tutorial_accessed_task_manager, :tutorial_spotted_nasty_virus]
@actions_str Enum.map(@actions, &to_string/1)

def valid_actions,
Expand Down
12 changes: 10 additions & 2 deletions lib/event/dispatcher.ex
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ defmodule Helix.Event.Dispatcher do
alias Helix.Core.Listener.Event.Handler.Listener, as: ListenerHandler
alias Helix.Account.Event, as: AccountEvent
alias Helix.Account.Event.Handler, as: AccountHandler
alias Helix.Client.Web1.Event, as: Web1Event
alias Helix.Client.Event, as: ClientEvent
alias Helix.Entity.Event, as: EntityEvent
alias Helix.Entity.Event.Handler, as: EntityHandler
alias Helix.Log.Event, as: LogEvent
Expand Down Expand Up @@ -86,7 +86,12 @@ defmodule Helix.Event.Dispatcher do
##############################################################################

# All
event Web1Event.Action.Performed
event ClientEvent.Action.Performed

# Custom handlers
event ClientEvent.Action.Performed,
StoryHandler.Story,
:event_handler

##############################################################################
# Entity events
Expand Down Expand Up @@ -147,6 +152,9 @@ defmodule Helix.Event.Dispatcher do
event ProcessEvent.Process.Created,
ProcessHandler.TOP,
:recalque_handler
event ProcessEvent.Process.Created,
StoryHandler.Story,
:event_handler

event ProcessEvent.TOP.BringMeToLife,
ProcessHandler.TOP,
Expand Down
6 changes: 0 additions & 6 deletions lib/process/event/process.ex
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,6 @@ defmodule Helix.Process.Event.Process do
def whom_to_notify(event),
do: %{server: [event.gateway_id, event.target_id]}
end

listenable do
listen(event = %_{confirmed: true}) do
[event.process.src_file_id, event.process.tgt_file_id]
end
end
end

event Completed do
Expand Down
11 changes: 9 additions & 2 deletions lib/server/event/server/password.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ defmodule Helix.Server.Event.Server.Password do

event Acquired do
@moduledoc """
The ServerPasswordAcquiredEvent is fired after a Bruteforce attack has been
completed, and the attacker discovered the target's server root password.
The `ServerPasswordAcquiredEvent` is fired after a Bruteforce attack has
been completed, and the attacker discovered the target's server root
password.
"""

alias Helix.Entity.Model.Entity
Expand Down Expand Up @@ -61,5 +62,11 @@ defmodule Helix.Server.Event.Server.Password do
def whom_to_notify(event),
do: %{account: event.entity_id}
end

listenable do
listen(event) do
[event.server_id]
end
end
end
end
13 changes: 12 additions & 1 deletion lib/software/make/file.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@ defmodule Helix.Software.Make.File do

alias Helix.Software.Event.File.Added, as: FileAddedEvent

@type modules :: cracker_modules
@type modules ::
cracker_modules
| spyware_modules

@type cracker_modules :: %{bruteforce: version, overflow: version}
@type spyware_modules :: %{vir_spyware: version}

@type data :: %{optional(:path) => File.path}

Expand All @@ -36,6 +39,14 @@ defmodule Helix.Software.Make.File do
file
end

@spec spyware(file_parent, spyware_modules, data) ::
file_return(:virus_spyware)
@doc """
Generates a spyware.
"""
def spyware(parent, modules, data \\ %{}),
do: file(parent, :virus_spyware, modules, data)

@spec file(file_parent, Software.type, modules, data) ::
file_return(Software.type)
defp file(server = %Server{}, type, modules, data) do
Expand Down
2 changes: 2 additions & 0 deletions lib/story/event/handler/story.ex
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,8 @@ defmodule Helix.Story.Event.Handler.Story do
do: emit(event, [], from: source_event)
defp emit(event, [], from: source_event),
do: Event.emit(event, from: source_event)
defp emit(event, [sleep: 0], from: source_event),
do: emit(event, from: source_event)
defp emit(event, [sleep: interval], from: source_event),
do: Event.emit_after(event, interval * 1000, from: source_event)
end
Loading

0 comments on commit b74ea5a

Please sign in to comment.