guillaumebrunerie / dixit-elixir Goto Github PK
View Code? Open in Web Editor NEWA Dixit server in Elixir
A Dixit server in Elixir
In particular, use a Registry
instead of the GameRegister
module, so that if a game crashes, it doesn't crash everything else.
A priori c’était après avoir tenté de recharger la page, après avoir laissé la partie en plan pendant un certain temps.
22:59:16.016 pid=<0.676.0> [info] [GR] Existing player: Moi
22:59:16.017 pid=<0.691.0> [debug] :s PLAYERS Yoo 0 Moi 0 Marie 0
22:59:16.017 pid=<0.691.0> [debug] :s TELLING Yoo
22:59:16.017 pid=<0.691.0> [debug] :s CARDS 98 45 100 75 19 30
22:59:26.803 pid=<0.690.0> [debug] :r TELL 15
22:59:26.805 pid=<0.676.0> [error] GenServer Dixit.GameRegister terminating
** (stop) exited in: GenServer.call(#PID<0.683.0>, {:send_state, %{deck: [77, 6, 16, 48, 59, 105, 104, 50, 11, 102, 23, 29, 78, 95, 46, 40, 97, 1, 27, 47, 25, 24, 9, 53, 28, 32, 86, 67, 92, 56, 49, 72, 8, 5, 41, 65, 35, 60, 54, 7, 31, 13, 4, 58, 80, 52, 12, ...], hands: %{"Marie" => '&*GIW"', "Moi" => [98, 45, 100, 75, 19, 30], "Yoo" => [79, 64, 37, 36, 15, 10]}, phaseT: %{phaseS: %{answer: 15, phaseV: nil, selected: %{"Marie" => nil, "Moi" => nil}}, teller: "Yoo"}, players: ["Yoo", "Moi", "Marie"], scores: %{"Marie" => 0, "Moi" => 0, "Yoo" => 0}}}, 5000)
** (EXIT) no process: the process is not alive or there's no process currently associated with the given name, possibly because its application isn't started
(elixir 1.11.2) lib/gen_server.ex:1027: GenServer.call/3
(elixir 1.11.2) lib/enum.ex:792: anonymous fn/3 in Enum.each/2
(stdlib 3.14) maps.erl:233: :maps.fold_1/3
(elixir 1.11.2) lib/enum.ex:2197: Enum.each/2
(dixit 0.1.0) lib/gameregister.ex:74: Dixit.GameRegister.handle_call/3
(stdlib 3.14) gen_server.erl:715: :gen_server.try_handle_call/4
(stdlib 3.14) gen_server.erl:744: :gen_server.handle_msg/6
(stdlib 3.14) proc_lib.erl:226: :proc_lib.init_p_do_apply/3
Last message (from #PID<0.690.0>): {:tell, 15}
State: %{games: %{"default" => %{gamepid: #PID<0.681.0>, players: %{"Marie" => #PID<0.683.0>, "Moi" => #PID<0.691.0>, "Yoo" => #PID<0.690.0>}}}, players: %{#PID<0.680.0> => %{game: "default", name: "Yoo"}, #PID<0.682.0> => %{game: "default", name: "Moi"}, #PID<0.683.0> => %{game: "default", name: "Marie"}, #PID<0.690.0> => %{game: "default", name: "Yoo"}, #PID<0.691.0> => %{game: "default", name: "Moi"}}}
Client #PID<0.690.0> is alive
(stdlib 3.14) gen.erl:208: :gen.do_call/4
(elixir 1.11.2) lib/gen_server.ex:1024: GenServer.call/3
(dixit 0.1.0) lib/player.ex:65: Dixit.Player.deal_with_message/2
(dixit 0.1.0) lib/player.ex:143: Dixit.Player.handle_info/2
(stdlib 3.14) gen_server.erl:689: :gen_server.try_dispatch/4
(stdlib 3.14) gen_server.erl:765: :gen_server.handle_msg/6
(stdlib 3.14) proc_lib.erl:226: :proc_lib.init_p_do_apply/3
22:59:26.808 pid=<0.690.0> [error] GenServer #PID<0.690.0> terminating
** (stop) exited in: GenServer.call(Dixit.GameRegister, {:tell, 15}, 5000)
** (EXIT) exited in: GenServer.call(#PID<0.683.0>, {:send_state, %{deck: [77, 6, 16, 48, 59, 105, 104, 50, 11, 102, 23, 29, 78, 95, 46, 40, 97, 1, 27, 47, 25, 24, 9, 53, 28, 32, 86, 67, 92, 56, 49, 72, 8, 5, 41, 65, 35, 60, 54, 7, 31, 13, 4, 58, 80, 52, 12, ...], hands: %{"Marie" => '&*GIW"', "Moi" => [98, 45, 100, 75, 19, 30], "Yoo" => [79, 64, 37, 36, 15, 10]}, phaseT: %{phaseS: %{answer: 15, phaseV: nil, selected: %{"Marie" => nil, "Moi" => nil}}, teller: "Yoo"}, players: ["Yoo", "Moi", "Marie"], scores: %{"Marie" => 0, "Moi" => 0, "Yoo" => 0}}}, 5000)
** (EXIT) no process: the process is not alive or there's no process currently associated with the given name, possibly because its application isn't started
(elixir 1.11.2) lib/gen_server.ex:1027: GenServer.call/3
(dixit 0.1.0) lib/player.ex:65: Dixit.Player.deal_with_message/2
(dixit 0.1.0) lib/player.ex:143: Dixit.Player.handle_info/2
(stdlib 3.14) gen_server.erl:689: :gen_server.try_dispatch/4
(stdlib 3.14) gen_server.erl:765: :gen_server.handle_msg/6
(stdlib 3.14) proc_lib.erl:226: :proc_lib.init_p_do_apply/3
Last message: {:tcp, #Port<0.32>, <<129, 137, 245, 217, 191, 216, 161, 156, 243, 148, 213, 232, 138, 213, 255>>}
State: %{buffer: "", socket: #Port<0.32>, ws?: true}
Maybe it’s ok if we are still in the first SELECTING phase?
If a game has not been used for a certain duration of time (1 hour?) it should self destruct.
If two clients connect to the same game and with the same name, maybe the second one should not steal the connection to the first one, but both could be working and mimicking what the other does.
When a player joins/rejoins, they should get everything related to the current state, but otherwise they should receive only what changed.
The server crashes some times when it is not used, possibly because of too many crashes of a process in a few seconds:
Note that the supervisor that reaches maximum restart intensity will exit with :shutdown reason. In this case the supervisor will only be restarted if its child specification was defined with the :restart option set to :permanent (the default).
In our case it seems it’s because of a few random queries (probably intended to hurt us).
08:21:49.674 pid=<0.769.0> [info] Hello from a player
08:21:49.674 pid=<0.769.0> [debug] :recv "HEAD / HTTP/1.0"
08:21:49.674 pid=<0.769.0> [warn] Unknown header: HEAD / HTTP/1.0
08:21:49.674 pid=<0.769.0> [debug] :recv ""
08:21:49.674 pid=<0.760.0> [error] Task #PID<0.760.0> started from Dixit.MainSupervisor terminating
** (MatchError) no match of right hand side value: {:error, {:badarg, [{Dixit.Player, :"-handshake/2-fun-1-", 1, [file: 'lib/player.ex', line: 100]}, {Dixit.Player, :handshake, 2, [file: 'lib/player.ex', line: 100]}, {Dixit.Player, :init, 1, [file: 'lib/player.ex', line: 21]}, {:gen_server, :init_it, 2, [file: 'gen_server.erl', line: 417]}, {:gen_server, :init_it, 6, [file: 'gen_server.erl', line: 385]}, {:proc_lib, :init_p_do_apply, 3, [file: 'proc_lib.erl', line: 226]}]}}
(dixit 0.1.0) lib/networklistener.ex:36: Dixit.NetworkListener.loop_acceptor/2
(elixir 1.11.2) lib/task/supervised.ex:90: Task.Supervised.invoke_mfa/2
(stdlib 3.14) proc_lib.erl:226: :proc_lib.init_p_do_apply/3
Function: &Dixit.NetworkListener.listen/1
Args: [[port: 4020, ws?: true]]
08:21:49.675 pid=<0.770.0> [info] Accepting connections on port 4020 (WebSockets)
08:21:49.675 pid=<0.771.0> [info] Accepting connections on port 4000 (plain text)
08:21:50.392 pid=<0.772.0> [info] Hello from a player
08:21:50.392 pid=<0.772.0> [debug] :recv "GET /system_api.php HTTP/1.1"
08:21:50.392 pid=<0.772.0> [warn] Unknown header: GET /system_api.php HTTP/1.1
08:21:50.392 pid=<0.772.0> [debug] :recv "Host: 54.38.184.182:4020"
08:21:50.392 pid=<0.772.0> [debug] :recv "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36"
08:21:50.392 pid=<0.772.0> [debug] :recv "Accept-Encoding: gzip, deflate"
08:21:50.392 pid=<0.772.0> [debug] :recv "Accept: */*"
08:21:50.392 pid=<0.772.0> [debug] :recv "Connection: keep-alive"
08:21:50.392 pid=<0.772.0> [warn] Unknown header: Connection: keep-alive
08:21:50.392 pid=<0.772.0> [debug] :recv ""
08:21:50.393 pid=<0.770.0> [error] Task #PID<0.770.0> started from Dixit.MainSupervisor terminating
** (MatchError) no match of right hand side value: {:error, {:badarg, [{Dixit.Player, :"-handshake/2-fun-1-", 1, [file: 'lib/player.ex', line: 100]}, {Dixit.Player, :handshake, 2, [file: 'lib/player.ex', line: 100]}, {Dixit.Player, :init, 1, [file: 'lib/player.ex', line: 21]}, {:gen_server, :init_it, 2, [file: 'gen_server.erl', line: 417]}, {:gen_server, :init_it, 6, [file: 'gen_server.erl', line: 385]}, {:proc_lib, :init_p_do_apply, 3, [file: 'proc_lib.erl', line: 226]}]}}
(dixit 0.1.0) lib/networklistener.ex:36: Dixit.NetworkListener.loop_acceptor/2
(elixir 1.11.2) lib/task/supervised.ex:90: Task.Supervised.invoke_mfa/2
(stdlib 3.14) proc_lib.erl:226: :proc_lib.init_p_do_apply/3
Function: &Dixit.NetworkListener.listen/1
Args: [[port: 4020, ws?: true]]
08:21:50.394 pid=<0.773.0> [info] Accepting connections on port 4020 (WebSockets)
08:21:50.394 pid=<0.774.0> [info] Accepting connections on port 4000 (plain text)
08:21:50.811 pid=<0.775.0> [info] Hello from a player
08:21:50.811 pid=<0.775.0> [debug] :recv "GET /system_api.php HTTP/1.1"
08:21:50.811 pid=<0.775.0> [warn] Unknown header: GET /system_api.php HTTP/1.1
08:21:50.811 pid=<0.775.0> [debug] :recv "Host: 54.38.184.182:4020"
08:21:50.811 pid=<0.775.0> [debug] :recv "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36"
08:21:50.811 pid=<0.775.0> [debug] :recv "Accept-Encoding: gzip, deflate"
08:21:50.812 pid=<0.775.0> [debug] :recv "Accept: */*"
08:21:50.812 pid=<0.775.0> [debug] :recv "Connection: keep-alive"
08:21:50.812 pid=<0.775.0> [warn] Unknown header: Connection: keep-alive
08:21:50.812 pid=<0.775.0> [debug] :recv ""
08:21:50.812 pid=<0.773.0> [error] Task #PID<0.773.0> started from Dixit.MainSupervisor terminating
** (MatchError) no match of right hand side value: {:error, {:badarg, [{Dixit.Player, :"-handshake/2-fun-1-", 1, [file: 'lib/player.ex', line: 100]}, {Dixit.Player, :handshake, 2, [file: 'lib/player.ex', line: 100]}, {Dixit.Player, :init, 1, [file: 'lib/player.ex', line: 21]}, {:gen_server, :init_it, 2, [file: 'gen_server.erl', line: 417]}, {:gen_server, :init_it, 6, [file: 'gen_server.erl', line: 385]}, {:proc_lib, :init_p_do_apply, 3, [file: 'proc_lib.erl', line: 226]}]}}
(dixit 0.1.0) lib/networklistener.ex:36: Dixit.NetworkListener.loop_acceptor/2
(elixir 1.11.2) lib/task/supervised.ex:90: Task.Supervised.invoke_mfa/2
(stdlib 3.14) proc_lib.erl:226: :proc_lib.init_p_do_apply/3
Function: &Dixit.NetworkListener.listen/1
Args: [[port: 4020, ws?: true]]
08:21:50.813 pid=<0.776.0> [info] Accepting connections on port 4020 (WebSockets)
08:21:50.813 pid=<0.777.0> [info] Accepting connections on port 4000 (plain text)
08:21:51.229 pid=<0.778.0> [info] Hello from a player
08:21:51.229 pid=<0.778.0> [debug] :recv "GET /c/version.js HTTP/1.1"
08:21:51.229 pid=<0.778.0> [warn] Unknown header: GET /c/version.js HTTP/1.1
08:21:51.229 pid=<0.778.0> [debug] :recv "Host: 54.38.184.182:4020"
08:21:51.229 pid=<0.778.0> [debug] :recv "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36"
08:21:51.229 pid=<0.778.0> [debug] :recv "Accept-Encoding: gzip, deflate"
08:21:51.230 pid=<0.778.0> [debug] :recv "Accept: */*"
08:21:51.230 pid=<0.778.0> [debug] :recv "Connection: keep-alive"
08:21:51.230 pid=<0.778.0> [warn] Unknown header: Connection: keep-alive
08:21:51.230 pid=<0.778.0> [debug] :recv ""
08:21:51.230 pid=<0.776.0> [error] Task #PID<0.776.0> started from Dixit.MainSupervisor terminating
** (MatchError) no match of right hand side value: {:error, {:badarg, [{Dixit.Player, :"-handshake/2-fun-1-", 1, [file: 'lib/player.ex', line: 100]}, {Dixit.Player, :handshake, 2, [file: 'lib/player.ex', line: 100]}, {Dixit.Player, :init, 1, [file: 'lib/player.ex', line: 21]}, {:gen_server, :init_it, 2, [file: 'gen_server.erl', line: 417]}, {:gen_server, :init_it, 6, [file: 'gen_server.erl', line: 385]}, {:proc_lib, :init_p_do_apply, 3, [file: 'proc_lib.erl', line: 226]}]}}
(dixit 0.1.0) lib/networklistener.ex:36: Dixit.NetworkListener.loop_acceptor/2
(elixir 1.11.2) lib/task/supervised.ex:90: Task.Supervised.invoke_mfa/2
(stdlib 3.14) proc_lib.erl:226: :proc_lib.init_p_do_apply/3
Function: &Dixit.NetworkListener.listen/1
Args: [[port: 4020, ws?: true]]
08:21:51.232 pid=<0.568.0> [info] Application dixit exited: shutdown
{"Kernel pid terminated",application_controller,"{application_terminated,dixit,shutdown}"}
Kernel pid terminated (application_controller) ({application_terminated,dixit,shutdown})
Crash dump is being written to: erl_crash.dump...done
I cannot implement TLS myself, therefore I need to use an existing library. Options:
Phoenix.Socket.Transport
cowboy
That is introduce new commands, sent to only one player:
TOLD 42
SELECTED 57
VOTED 18
(In order to be able to show how far we are from the end of the game.)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.