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

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
renatomassaro committed Oct 14, 2017
1 parent b7bf1a8 commit 35cad71
Show file tree
Hide file tree
Showing 30 changed files with 1,368 additions and 733 deletions.
38 changes: 17 additions & 21 deletions lib/account/websocket/channel/account/requests/bootstrap.ex
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 lib/account/websocket/channel/account/requests/email_reply.ex
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
22 changes: 16 additions & 6 deletions lib/hell/hell/utils.ex
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,35 @@ defmodule HELL.Utils do
def ensure_list(value),
do: [value]

@spec concat_atom(atom | String.t, atom | String.t) ::
atom
@doc """
Concatenates two elements, returning an atom.
"""
def concat_atom(a, b) when is_atom(a) and is_atom(b),
do: concat_atom(Atom.to_string(a), Atom.to_string(b))
def concat_atom(a, b) when is_binary(a) and is_atom(b),
do: concat_atom(a, Atom.to_string(b))
def concat_atom(a, b) when is_atom(a) and is_binary(b),
def concat_atom(a, b) when is_atom(a),
do: concat_atom(Atom.to_string(a), b)
def concat_atom(a, b) when is_atom(b),
do: concat_atom(a, Atom.to_string(b))
def concat_atom(a, b) when is_binary(a) and is_binary(b),
do: String.to_atom(a <> b)

@spec concat(atom | String.t, atom | String.t) ::
String.t
@doc """
Concatenates two strings. It's a more readable option to Kernel.<>/2, intended
to be used on pipes.
to be used on pipes. It can also handle concatenation of atoms, in which case
this function will always return a string. See also `concat_atom/2`.
"""
def concat(a, b) when is_atom(a),
do: concat(Atom.to_string(a), b)
def concat(a, b) when is_atom(b),
do: concat(a, Atom.to_string(b))
def concat(a, b) when is_binary(a) and is_binary(b),
do: a <> b

def concat(a, b, c),
do: concat(a, b) |> concat(c)

def atom_contains?(a, value) when is_atom(a) do
a
|> Atom.to_string()
Expand Down
13 changes: 13 additions & 0 deletions lib/server/websocket/channel/server.ex
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ defmodule Helix.Server.Websocket.Channel.Server do

alias Helix.Websocket.Socket, as: Websocket

alias Helix.Software.Websocket.Requests.PFTP.Server.Enable,
as: PFTPServerEnableRequest

alias Helix.Server.Websocket.Channel.Server.Join, as: ServerJoin
alias Helix.Server.Websocket.Channel.Server.Requests.Bootstrap,
as: BootstrapRequest
Expand Down Expand Up @@ -88,6 +91,16 @@ defmodule Helix.Server.Websocket.Channel.Server do
Websocket.handle_request(request, socket)
end

@doc """
Activates/enables the PublicFTP server of the player.
Params:
None
"""
def handle_in("pftp.server.enable", params, socket) do
request = PFTPServerEnableRequest.new(params)
Websocket.handle_request(request, socket)
end

@doc """
Browses to the specified address, which may be an IPv4 or domain name.
Expand Down
53 changes: 28 additions & 25 deletions lib/server/websocket/channel/server/requests/bootstrap.ex
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
Loading

0 comments on commit 35cad71

Please sign in to comment.