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

Commit

Permalink
Merge 53dac79 into 41f2031
Browse files Browse the repository at this point in the history
  • Loading branch information
renatomassaro committed Feb 15, 2018
2 parents 41f2031 + 53dac79 commit 359789d
Show file tree
Hide file tree
Showing 36 changed files with 1,820 additions and 108 deletions.
46 changes: 46 additions & 0 deletions lib/account/websocket/channel/account.ex
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ channel Helix.Account.Websocket.Channel.Account do
alias Helix.Network.Websocket.Requests.Bounce.Create, as: BounceCreateRequest
alias Helix.Network.Websocket.Requests.Bounce.Update, as: BounceUpdateRequest
alias Helix.Network.Websocket.Requests.Bounce.Remove, as: BounceRemoveRequest
alias Helix.Software.Websocket.Requests.Virus.Collect, as: VirusCollectRequest
alias Helix.Story.Websocket.Requests.Email.Reply, as: EmailReplyRequest

@doc """
Expand Down Expand Up @@ -187,6 +188,51 @@ channel Helix.Account.Websocket.Channel.Account do
"""
topic "bounce.remove", BounceRemoveRequest

@doc """
Collects money off of active viruses.
Params:
*gateway_id: Which gateway server is being used as origin.
*viruses: List of viruses (`File.id`) that we should collect
bounce_id: Which bounce should be used. If omitted, we assume none.
atm_id: Which ATM the account_number belongs to. See [1] and [2].
account_number: Which account should we send the money to. See [1] and [2].
wallet: Which bitcoin address should we send the money to. See [1].
[1] - Bank account or bitcoin wallet information may be optional if none of
the viruses being collected will use them. For example, if the player is
collecting money from 3 `spyware` viruses, no wallet is required. Similarly,
if all viruses being collected are `miner`, no bank account is required. If
there are both bitcoin-rewarding and cash-rewarding viruses, both payment
information are required. This will be henforced!
[2] - I don't always need bank account information (see [1]), but when I do, I
require both `atm_id` and `account_number`. This will be henforced as well.
Returns: :ok
Events:
- process_created: Emitted *for each virus* when VirusCollectProcess is
created.
- process_create_failed: Emitted when one or more of the underlying collect
processes were not started due to lack of hardware resources.
Errors:
Henforcer:
- payment_invalid: Required payment information is missing.
- virus_not_active: One of the viruses at `viruses` isn't active
- virus_not_found: One of the viruses at `viruses` wasn't found
- bank_account_not_belongs: Given `{atm_id, account_number}` does not belong
- bounce_not_belongs: Given `bounce_id` does not belong to the player
- server_not_belongs: Given `gateway_id` does not belong to the player
Input:
- bad_virus: One of the entries at `viruses` is invalid.
+ base errors
"""
topic "virus.collect", VirusCollectRequest

@doc """
Intercepts and handles outgoing events.
"""
Expand Down
73 changes: 73 additions & 0 deletions lib/entity/henforcer/entity.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,16 @@ defmodule Helix.Entity.Henforcer.Entity do
alias Helix.Network.Model.Network
alias Helix.Network.Query.Network, as: NetworkQuery
alias Helix.Software.Henforcer.Storage, as: StorageHenforcer
alias Helix.Software.Henforcer.Virus, as: VirusHenforcer
alias Helix.Software.Model.File
alias Helix.Software.Model.Storage
alias Helix.Software.Model.Virus
alias Helix.Server.Henforcer.Component, as: ComponentHenforcer
alias Helix.Server.Henforcer.Server, as: ServerHenforcer
alias Helix.Server.Model.Component
alias Helix.Server.Model.Server
alias Helix.Server.Query.Component, as: ComponentQuery
alias Helix.Universe.Bank.Model.BankAccount
alias Helix.Entity.Model.Entity
alias Helix.Entity.Query.Entity, as: EntityQuery

Expand Down Expand Up @@ -235,4 +239,73 @@ defmodule Helix.Entity.Henforcer.Entity do
end
|> wrap_relay(%{entity: entity, bounce: bounce})
end

@type owns_virus_relay :: %{entity: Entity.t, virus: Virus.t}
@type owns_virus_relay_partial :: map
@type owns_virus_error ::
{false, {:virus, :not_belongs}, owns_virus_relay_partial}
| entity_exists_error
| VirusHenforcer.virus_exists_error

@spec owns_virus?(Entity.idt, File.idt | Virus.t) ::
{true, owns_virus_relay}
| owns_virus_error
@doc """
Henforces the Entity is the owner (installed) the given virus.
"""
def owns_virus?(entity_id = %Entity.ID{}, virus) do
henforce entity_exists?(entity_id) do
owns_virus?(relay.entity, virus)
end
end

def owns_virus?(entity, virus_id = %File.ID{}) do
henforce VirusHenforcer.virus_exists?(virus_id) do
owns_virus?(entity, relay.virus)
end
end

def owns_virus?(entity, virus = %File{}) do
henforce VirusHenforcer.virus_exists?(virus.file_id) do
owns_virus?(entity, relay.virus)
end
end

def owns_virus?(entity = %Entity{}, virus = %Virus{}) do
if virus.entity_id == entity.entity_id do
reply_ok()
else
reply_error({:virus, :not_belongs})
end
|> wrap_relay(%{entity: entity, virus: virus})
end

@type owns_bank_account_relay ::
%{entity: Entity.t, bank_account: BankAccount.t}
@type owns_bank_account_relay_partial :: map
@type owns_bank_account_error ::
{false, {:bank_account, :not_belongs}, owns_bank_account_relay_partial}
| entity_exists_error

@spec owns_bank_account?(Entity.idt, BankAccount.t) ::
{true, owns_bank_account_relay}
| owns_bank_account_error
@doc """
Henforces the Entity is the owner of the given bank account.
"""
def owns_bank_account?(entity_id = %Entity.ID{}, bank_account) do
henforce entity_exists?(entity_id) do
owns_bank_account?(relay.entity, bank_account)
end
end

def owns_bank_account?(entity = %Entity{}, bank_account = %BankAccount{}) do
# TODO #260
if to_string(entity.entity_id) == to_string(bank_account.owner_id) do
reply_ok()
else
reply_error({:bank_account, :not_belongs})
end
|> wrap_relay(%{entity: entity, bank_account: bank_account})
end
end
5 changes: 5 additions & 0 deletions lib/event/dispatcher.ex
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ defmodule Helix.Event.Dispatcher do
event SoftwareEvent.Firewall.Stopped
event SoftwareEvent.LogForge.LogCreate.Processed
event SoftwareEvent.LogForge.LogEdit.Processed
event SoftwareEvent.Virus.Collect.Processed
event SoftwareEvent.Virus.Installed
event SoftwareEvent.Virus.InstallFailed

Expand Down Expand Up @@ -227,6 +228,10 @@ defmodule Helix.Event.Dispatcher do
LogHandler.Log,
:log_forge_conclusion

event SoftwareEvent.Virus.Collect.Processed,
SoftwareHandler.Virus,
:handle_collect

##############################################################################
# Story events
##############################################################################
Expand Down
1 change: 1 addition & 0 deletions lib/network/henforcer/bounce.ex
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ defmodule Helix.Network.Henforcer.Bounce do
end
end

# REVIEW: Why the empty map?
@type can_use_bounce_relay :: EntityHenforcer.owns_bounce_relay | %{}
@type can_use_bounce_relay_partial :: map
@type can_use_bounce_error :: EntityHenforcer.owns_bounce_error
Expand Down
2 changes: 2 additions & 0 deletions lib/network/model/connection.ex
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ defmodule Helix.Network.Model.Connection do
@type public_ftp :: t_of_type(:public_ftp)
@type bank_login :: t_of_type(:bank_login)
@type wire_transfer :: t_of_type(:wire_transfer)
@type virus_collect :: t_of_type(:virus_collect)
@type cracker_bruteforce :: t_of_type(:cracker_bruteforce)

@type meta :: map | nil
Expand All @@ -37,6 +38,7 @@ defmodule Helix.Network.Model.Connection do
| :public_ftp
| :bank_login
| :wire_transfer
| :virus_collect
| :cracker_bruteforce

@type close_reasons :: :normal | :force
Expand Down
Loading

0 comments on commit 359789d

Please sign in to comment.