This repository has been archived by the owner on Jun 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #301 from renatomassaro/pftp
Public FTP
- Loading branch information
Showing
92 changed files
with
4,676 additions
and
804 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 17 additions & 21 deletions
38
lib/account/websocket/channel/account/requests/bootstrap.ex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,27 @@ | ||
defmodule Helix.Account.Websocket.Channel.Account.Requests.Bootstrap do | ||
import Helix.Websocket.Request | ||
|
||
require Helix.Websocket.Request | ||
request Helix.Account.Websocket.Channel.Account.Requests.Bootstrap do | ||
|
||
Helix.Websocket.Request.register() | ||
alias Helix.Account.Public.Account, as: AccountPublic | ||
|
||
defimpl Helix.Websocket.Requestable do | ||
def check_params(request, _socket), | ||
do: reply_ok(request) | ||
|
||
alias Helix.Websocket.Utils, as: WebsocketUtils | ||
alias Helix.Account.Public.Account, as: AccountPublic | ||
def check_permissions(request, _socket), | ||
do: reply_ok(request) | ||
|
||
def check_params(request, _socket), | ||
do: {:ok, request} | ||
def handle_request(request, socket) do | ||
entity_id = socket.assigns.entity_id | ||
|
||
def check_permissions(request, _socket), | ||
do: {:ok, request} | ||
meta = %{ | ||
bootstrap: AccountPublic.bootstrap(entity_id) | ||
} | ||
|
||
def handle_request(request, socket) do | ||
entity_id = socket.assigns.entity_id | ||
|
||
meta = %{bootstrap: AccountPublic.bootstrap(entity_id)} | ||
|
||
{:ok, %{request| meta: meta}} | ||
end | ||
update_meta(request, meta, reply: true) | ||
end | ||
|
||
def reply(request, socket) do | ||
data = AccountPublic.render_bootstrap(request.meta.bootstrap) | ||
WebsocketUtils.reply_ok(data, socket) | ||
end | ||
render(request, _socket) do | ||
data = AccountPublic.render_bootstrap(request.meta.bootstrap) | ||
{:ok, data} | ||
end | ||
end |
75 changes: 34 additions & 41 deletions
75
lib/account/websocket/channel/account/requests/email_reply.ex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,46 @@ | ||
defmodule Helix.Account.Websocket.Channel.Account.Requests.EmailReply do | ||
import Helix.Websocket.Request | ||
|
||
request Helix.Account.Websocket.Channel.Account.Requests.EmailReply do | ||
@moduledoc """ | ||
Implementation of the `EmailReply` request, which allows the player to send | ||
an (storyline) email reply to the Contact (story character) | ||
""" | ||
|
||
require Helix.Websocket.Request | ||
|
||
Helix.Websocket.Request.register() | ||
|
||
defimpl Helix.Websocket.Requestable do | ||
|
||
alias Helix.Websocket.Utils, as: WebsocketUtils | ||
alias Helix.Story.Public.Story, as: StoryPublic | ||
alias Helix.Story.Public.Story, as: StoryPublic | ||
|
||
def check_params(request, _socket) do | ||
with \ | ||
true <- is_binary(request.unsafe["reply_id"]) | ||
do | ||
params = %{ | ||
reply_id: request.unsafe["reply_id"] | ||
} | ||
def check_params(request, _socket) do | ||
with \ | ||
true <- is_binary(request.unsafe["reply_id"]) | ||
do | ||
params = %{ | ||
reply_id: request.unsafe["reply_id"] | ||
} | ||
|
||
{:ok, %{request| params: params}} | ||
else | ||
_ -> | ||
{:error, %{message: "bad_request"}} | ||
end | ||
update_params(request, params, reply: true) | ||
else | ||
_ -> | ||
bad_request() | ||
end | ||
end | ||
|
||
@doc """ | ||
Permissions whether that reply is valid within the player's current context | ||
are checked at StoryPublic- and StoryAction-level | ||
""" | ||
def check_permissions(request, _socket), | ||
do: {:ok, request} | ||
|
||
def handle_request(request, socket) do | ||
entity_id = socket.assigns.entity_id | ||
reply_id = request.params.reply_id | ||
|
||
case StoryPublic.send_reply(entity_id, reply_id) do | ||
:ok -> | ||
{:ok, request} | ||
error -> | ||
error | ||
end | ||
@doc """ | ||
Permissions whether that reply is valid within the player's current context | ||
are checked at StoryPublic- and StoryAction-level | ||
""" | ||
def check_permissions(request, _socket), | ||
do: reply_ok(request) | ||
|
||
def handle_request(request, socket) do | ||
entity_id = socket.assigns.entity_id | ||
reply_id = request.params.reply_id | ||
|
||
case StoryPublic.send_reply(entity_id, reply_id) do | ||
:ok -> | ||
reply_ok(request) | ||
{:error, %{message: msg}} -> | ||
reply_error(msg) | ||
end | ||
|
||
def reply(_request, socket), | ||
do: WebsocketUtils.reply_ok(%{}, socket) | ||
end | ||
|
||
render_empty() | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
defmodule Helix.Entity.Henforcer.Entity do | ||
|
||
import Helix.Henforcer | ||
|
||
alias Helix.Server.Model.Server | ||
alias Helix.Server.Henforcer.Server, as: ServerHenforcer | ||
alias Helix.Entity.Model.Entity | ||
alias Helix.Entity.Query.Entity, as: EntityQuery | ||
|
||
@type entity_exists_relay :: %{entity: Entity.t} | ||
@type entity_exists_error :: | ||
{false, {:entity, :not_found}, entity_exists_relay} | ||
|
||
@spec entity_exists?(Entity.id) :: | ||
{true, entity_exists_relay} | ||
| entity_exists_error | ||
@doc """ | ||
Henforces the given Entity exists. | ||
""" | ||
def entity_exists?(entity_id = %Entity.ID{}) do | ||
with entity = %Entity{} <- EntityQuery.fetch(entity_id) do | ||
reply_ok(relay(%{entity: entity})) | ||
else | ||
_ -> | ||
reply_error({:entity, :not_found}) | ||
end | ||
end | ||
|
||
@type owns_server_relay :: %{entity: Entity.t, server: Server.t} | ||
@type owns_server_relay_partial :: owns_server_relay | ||
@type owns_server_error :: | ||
{false, {:server, :not_belongs}, owns_server_relay_partial} | ||
| entity_exists_error | ||
| ServerHenforcer.server_exists_error | ||
|
||
@spec owns_server?(Entity.idt, Server.idt) :: | ||
{true, owns_server_relay} | ||
| owns_server_error | ||
@doc """ | ||
Henforces the Entity is the owner of the given server. | ||
""" | ||
def owns_server?(entity_id = %Entity.ID{}, server) do | ||
henforce entity_exists?(entity_id) do | ||
owns_server?(relay.entity, server) | ||
end | ||
end | ||
|
||
def owns_server?(entity, server_id = %Server.ID{}) do | ||
henforce(ServerHenforcer.server_exists?(server_id)) do | ||
owns_server?(entity, relay.server) | ||
end | ||
end | ||
|
||
def owns_server?(entity = %Entity{}, server = %Server{}) do | ||
with \ | ||
owner = %Entity{} <- EntityQuery.fetch_by_server(server), | ||
true <- owner == entity | ||
do | ||
reply_ok() | ||
else | ||
_ -> | ||
reply_error({:server, :not_belongs}) | ||
end | ||
|> wrap_relay(%{entity: entity, server: server}) | ||
end | ||
end |
Oops, something went wrong.