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.
- Loading branch information
1 parent
b7bf1a8
commit 35cad71
Showing
30 changed files
with
1,368 additions
and
733 deletions.
There are no files selected for viewing
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 -> | ||
reply_error(error) | ||
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
53 changes: 28 additions & 25 deletions
53
lib/server/websocket/channel/server/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,38 +1,41 @@ | ||
defmodule Helix.Server.Websocket.Channel.Server.Requests.Bootstrap do | ||
import Helix.Websocket.Request | ||
|
||
require Helix.Websocket.Request | ||
request Helix.Server.Websocket.Channel.Server.Requests.Bootstrap do | ||
@moduledoc """ | ||
ServerBootstrapRequest is used to allow the client to resync its local data | ||
with the Helix server. | ||
Helix.Websocket.Request.register() | ||
It returns the ServerBootstrap, which is the exact same struct returned after | ||
joining a local or remote server Channel. | ||
""" | ||
|
||
defimpl Helix.Websocket.Requestable do | ||
alias Helix.Server.Public.Server, as: ServerPublic | ||
|
||
alias Helix.Websocket.Utils, as: WebsocketUtils | ||
alias Helix.Server.Public.Server, as: ServerPublic | ||
def check_params(request, _socket), | ||
do: {:ok, request} | ||
|
||
def check_params(request, _socket), | ||
do: {:ok, request} | ||
def check_permissions(request, socket) do | ||
|
||
def check_permissions(request, socket) do | ||
|
||
if socket.assigns.meta.access_type == :remote do | ||
{:ok, request} | ||
else | ||
{:error, %{message: "own_server_bootstrap"}} | ||
end | ||
if socket.assigns.meta.access_type == :remote do | ||
reply_ok(request) | ||
else | ||
reply_error("own_server_bootstrap") | ||
end | ||
end | ||
|
||
def handle_request(request, socket) do | ||
entity_id = socket.assigns.entity_id | ||
server_id = socket.assigns.destination.server_id | ||
def handle_request(request, socket) do | ||
entity_id = socket.assigns.entity_id | ||
server_id = socket.assigns.destination.server_id | ||
|
||
meta = %{bootstrap: ServerPublic.bootstrap(server_id, entity_id)} | ||
meta = %{ | ||
bootstrap: ServerPublic.bootstrap(server_id, entity_id) | ||
} | ||
|
||
{:ok, %{request| meta: meta}} | ||
end | ||
update_meta(request, meta, reply: true) | ||
end | ||
|
||
def reply(request, socket) do | ||
data = ServerPublic.render_bootstrap(request.meta.bootstrap) | ||
WebsocketUtils.reply_ok(data, socket) | ||
end | ||
render(request, _socket) do | ||
data = ServerPublic.render_bootstrap(request.meta.bootstrap) | ||
{:ok, data} | ||
end | ||
end |
Oops, something went wrong.