Skip to content

Commit

Permalink
Merge pull request #75 from Hanspagh/development
Browse files Browse the repository at this point in the history
Release 1.1.2
  • Loading branch information
ecly committed Mar 10, 2018
2 parents 1322703 + 143a6e8 commit 9862945
Show file tree
Hide file tree
Showing 11 changed files with 959 additions and 31 deletions.
4 changes: 3 additions & 1 deletion .deliver/config
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ BUILD_AT="/home/worker/app_build"
PRODUCTION_HOSTS="buddy.gg"
PRODUCTION_USER="worker"
DELIVER_TO="/home/worker/app_release"
AUTO_VERSION=revision
# We manually increment versions in mix.exs
# using semantic versioning instead.
# AUTO_VERSION=revision

pre_erlang_get_and_update_deps() {
# copy it on the build host to the build directory when building
Expand Down
661 changes: 661 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

32 changes: 27 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,35 @@
# Backend service for Buddy.gg
# Backend service for buddy.gg
Somewhat generic player matching service built with phoenix, utilizing genservers and sockets to avoid having an underlying database.
Currently build only support matching players from League of Legends, but can quite easily be expanded to other games

## Run local
To start the server:
- Install dependencies with mix deps.get
- Start Phoenix endpoint with mix phx.server
- Install dependencies with `mix deps.get`
- Start Phoenix endpoint with `mix phx.server`
Now you can visit localhost:4000 from your browser.

## Deploy to production
Deployment is handled with [edeliver](https://github.com/edeliver/edeliver) and [conform](https://github.com/bitwalker/conform). See the respected repos for more information.
To test interactively in IEx:
- Install depedencies with `mix.deps.get`
- Star IEx with `iex -S mix phx.server`

## Run tests
`mix test`

## Development
*Features* should be implemented on feature branches based on [development] and rebased thereinto with Pull Requests.
New features should not add any issues to `mix credo`.

*Releases* should be merged from [development] into [master], whereafter [master] is rebased into [development].

## Deployment
**Development**:
Branch 'development' is automatically deployed to Heroku at: https://lolbuddy.herokuapp.com/api/

Test: https://lolbuddy.herokuapp.com/api/summoner/euw/Lethly

**Master**:
Branch Master is manually deployed to DO at https://api.buddy.gg/api/

Test: https://api.buddy.gg/api/summoner/euw/Lethly

Deployment is handled with [edeliver](https://github.com/edeliver/edeliver) and [conform](https://github.com/bitwalker/conform). See the respected repos for more information.
13 changes: 4 additions & 9 deletions lib/lol_buddy/players/matching.ex
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,8 @@ defmodule LolBuddy.Players.Matching do
lr = get_rank(low)

cond do
ht == "CHALLENGER" ->
false

ht == "MASTER" ->
# master and challenger have equal restrictions
ht == "MASTER" || ht == "CHALLENGER" ->
lr in 1..3

# now we may can assume ht is diamond
Expand Down Expand Up @@ -131,11 +129,8 @@ defmodule LolBuddy.Players.Matching do
def tier_compatible?(league1, league2) do
{h, l} = sort_leagues(league1, league2)
tier_diff = tier_to_int(h.tier) - tier_to_int(l.tier)
# challenger's may only walk alone
cond do
h.tier == "CHALLENGER" ->
false

cond do
# special handling for d1 as it cannot queue with its entire league
h.tier == "DIAMOND" && get_rank(h) == 1 ->
rank_compatible?(h, l)
Expand Down Expand Up @@ -204,7 +199,7 @@ defmodule LolBuddy.Players.Matching do
6

"CHALLENGER" ->
7
6
end
end

Expand Down
8 changes: 5 additions & 3 deletions lib/lol_buddy/players/player.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ defmodule LolBuddy.Players.Player do
@comment_char_limit 100
@riot_name_length_limit 16
@role_limit 5
@language_limit 5
@champion_limit 3

@doc """
Expand Down Expand Up @@ -61,9 +62,9 @@ defmodule LolBuddy.Players.Player do

@doc """
Validates that the given player adheres to the desired structure
as well as uses limited lengths for most strings. This is solely
to avoid potential adversarial player submissions that could damage
the system.
as well as uses limited lengths for most strings and lists. This is
solely to avoid potential adversarial player submissions that could
damage the system.
We do not care if empty lists are submitted, although this should
generally be avoided in the frontend.
Expand All @@ -77,6 +78,7 @@ defmodule LolBuddy.Players.Player do
String.length(data["name"]) <= @riot_name_length_limit &&
map_size(data["userInfo"]["selectedRoles"]) <= @role_limit &&
length(data["champions"]) <= @champion_limit &&
length(data["userInfo"]["languages"]) <= @language_limit &&
(data["userInfo"]["comment"] == nil ||
String.length(data["userInfo"]["comment"]) <= @comment_char_limit) &&
Criteria.validate_criteria_json(data["userInfo"]["criteria"])
Expand Down
6 changes: 6 additions & 0 deletions lib/lol_buddy/riot_api/champions.ex
Original file line number Diff line number Diff line change
Expand Up @@ -838,6 +838,12 @@ defmodule LolBuddy.RiotApi.Champions do
key: "Zoe",
name: "Zoe",
title: "the Aspect of Twilight"
},
%{
id: 145,
key: "Kaisa",
name: "Kai'Sa",
title: "Daughter of the Void"
}
]

Expand Down
22 changes: 20 additions & 2 deletions test/players/matching_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -273,9 +273,27 @@ defmodule LolBuddy.MatchingTest do
refute Matching.tier_compatible?(master, diamond4)
end

test "challenger is always incompatible" do
test "challenger may queue with challenger" do
challenger = %{type: "RANKED_SOLO_5x5", tier: "CHALLENGER", rank: 1}
refute Matching.tier_compatible?(challenger, challenger)
assert Matching.tier_compatible?(challenger, challenger)
end

test "challenger may queue with master" do
challenger = %{type: "RANKED_SOLO_5x5", tier: "CHALLENGER", rank: 1}
master = %{type: "RANKED_SOLO_5x5", tier: "MASTER", rank: 1}
assert Matching.tier_compatible?(challenger, master)
end

test "challenger may queue with diamond 3" do
challenger = %{type: "RANKED_SOLO_5x5", tier: "CHALLENGER", rank: 1}
diamond3 = %{type: "RANKED_SOLO_5x5", tier: "DIAMOND", rank: 3}
assert Matching.tier_compatible?(challenger, diamond3)
end

test "challenger may not queue with diamond 3" do
challenger = %{type: "RANKED_SOLO_5x5", tier: "CHALLENGER", rank: 1}
diamond4 = %{type: "RANKED_SOLO_5x5", tier: "DIAMOND", rank: 4}
refute Matching.tier_compatible?(challenger, diamond4)
end

test "gold with no rank is compatible with plat/gold/silver" do
Expand Down
25 changes: 19 additions & 6 deletions test/players/player_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,9 @@ defmodule LolBuddy.PlayerTest do

bad_user_info =
data["userInfo"]
|> Map.replace!("comment", long_comment)
|> Map.put("comment", long_comment)

bad_data = Map.replace!(data, "userInfo", bad_user_info)
bad_data = Map.put(data, "userInfo", bad_user_info)
refute Player.validate_player_json(bad_data)
end

Expand All @@ -133,9 +133,9 @@ defmodule LolBuddy.PlayerTest do

bad_user_info =
data["userInfo"]
|> Map.replace!("comment", no_comment)
|> Map.put("comment", no_comment)

bad_data = Map.replace!(data, "userInfo", bad_user_info)
bad_data = Map.put(data, "userInfo", bad_user_info)
assert Player.validate_player_json(bad_data)
end

Expand All @@ -146,14 +146,27 @@ defmodule LolBuddy.PlayerTest do
data["userInfo"]
|> Map.update!("selectedRoles", &Map.put(&1, "a", "b"))

bad_data = Map.replace!(data, "userInfo", bad_user_info)
bad_data = Map.put(data, "userInfo", bad_user_info)
refute Player.validate_player_json(bad_data)
end

test "too many selected languages is invalid" do
data = Poison.Parser.parse!(@player)

too_many_languages = ["DK", "ENG", "SWE", "NO", "BR", "SP"]

bad_user_info =
data["userInfo"]
|> Map.put("languages", too_many_languages)

bad_data = Map.put(data, "userInfo", bad_user_info)
refute Player.validate_player_json(bad_data)
end

test "too long player name is invalid" do
data = Poison.Parser.parse!(@player)
long_name = String.duplicate("a", 17)
bad_data = Map.replace!(data, "name", long_name)
bad_data = Map.put(data, "name", long_name)
refute Player.validate_player_json(bad_data)
end

Expand Down
6 changes: 6 additions & 0 deletions test/riot_api/champions_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,10 @@ defmodule LolBuddyRiotApi.ChampionsTest do
name = LolBuddy.RiotApi.Champions.find_by_id(id).name
assert name == "Kog'Maw"
end

test "kai'sa id" do
id = 145
name = LolBuddy.RiotApi.Champions.find_by_id(id).name
assert name == "Kai'Sa"
end
end
10 changes: 5 additions & 5 deletions tsung-config.xml → tsung-config.local.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<!-- Each remote server that Tsung should performance test against. Only one would be needed if you have a load balancer. -->
<servers>
<server host="buddy.gg" port="80" type="tcp" />
<server host="localhost" port="4000" type="tcp" />
</servers>

<!-- Describe how load will be ramped up to your application over time -->
Expand Down Expand Up @@ -48,7 +48,7 @@
</request>

<!-- We need to change the session type to websocket -->
<change_type new_type="ts_websocket" host="buddy.gg" port="80" server_type="tcp" restore="true" store="true" bidi="true"/>
<change_type new_type="ts_websocket" host="localhost" port="4000" server_type="tcp" restore="true" store="true" bidi="true"/>

<!-- Try to connect on a websocket -->
<!-- See https://github.com/LearnBoost/socket.io-spec for more information -->
Expand Down Expand Up @@ -90,7 +90,7 @@
</request>

<!-- We need to change the session type to websocket -->
<change_type new_type="ts_websocket" host="buddy.gg" port="80" server_type="tcp" restore="true" store="true" bidi="true"/>
<change_type new_type="ts_websocket" host="localhost" port="4000" server_type="tcp" restore="true" store="true" bidi="true"/>

<!-- Try to connect on a websocket -->
<!-- See https://github.com/LearnBoost/socket.io-spec for more information -->
Expand Down Expand Up @@ -132,7 +132,7 @@
</request>

<!-- We need to change the session type to websocket -->
<change_type new_type="ts_websocket" host="buddy.gg" port="80" server_type="tcp" restore="true" store="true" bidi="true"/>
<change_type new_type="ts_websocket" host="localhost" port="4000" server_type="tcp" restore="true" store="true" bidi="true"/>

<!-- Try to connect on a websocket -->
<!-- See https://github.com/LearnBoost/socket.io-spec for more information -->
Expand Down Expand Up @@ -174,7 +174,7 @@
</request>

<!-- We need to change the session type to websocket -->
<change_type new_type="ts_websocket" host="buddy.gg" port="80" server_type="tcp" restore="true" store="true" bidi="true"/>
<change_type new_type="ts_websocket" host="localhost" port="4000" server_type="tcp" restore="true" store="true" bidi="true"/>

<!-- Try to connect on a websocket -->
<!-- See https://github.com/LearnBoost/socket.io-spec for more information -->
Expand Down
Loading

0 comments on commit 9862945

Please sign in to comment.