henrysdev

henrysdev

Multiplayer Bot Architecture for Phoenix App?

I have a multiplayer web game that uses Phoenix Channels for communication with clients via websockets. I’d like to add server-side bot players to my game.

I’ve given some thought on where in the stack to add the bots. My current plan is to simulate the bots at the “edge” of the system as GenServers that are subscribed to the same phoenix endpoint channel that actual clients are. It is my understanding that they will need to maintain virtual Socket connections to accomplish this.

I’ve been trying to figure out how to explicitly create sockets and subscribe them to a Phoenix Channel. I’ve looked at the code for channel testing utilities as a starting point.

Alternatively, I was considering implementing an intermediate “event server” sitting between the game server and the actual endpoint channel. This event server would be a pass through for all game chit chat and would allow me to handle event delegation to bots and actual clients discriminately. In this case, a bot would still be a GenServer with event behaviors but it would not need to simulate an actual socket. Curious to hear thoughts.

Marked As Solved

madclaws

madclaws

I will go with second approach, although we can avoid that event server, and game-server can actually handle event delegation to bots/players. Bots will be genservers and will be registered with the game-server, and when bots have to send any message to phoenix channel, they can do that by MyAppWeb.Endpoint.broadcast!(channel_name, "bot_msg", %{"msg" => "attack"}). Channel name can be stored in the game-server.

Also Liked

dmitrykleymenov

dmitrykleymenov

I don’t think that creatng an imulation for socket is a good idea. It looks like bot even doesn’t belong to web application. I would place it somewhere in OTP app, it’s hard to tell exact where, since i don’t know how you handle every player, but if through gen servers, Bot.Server could be near Player.Server

dmitrykleymenov

dmitrykleymenov

I think more clear way to do that is to send messages directly to game server, inside OTP. And game will send it on a regular basis to players(as does on real player events)

Where Next?

Popular in Questions Top

Tee
can someone please explain to me how Enum.reduce works with maps
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
Kagamiiiii
Student & New to elixir. Nice language. I want to convert a english character, e.g. “a”, which is stored in a variable, to it’s asci...
New
vac
Hi, I'm quite new in Elixir and I'm trying to format a string to a PEM format. I have the certificate value like MIIDBTCCAe2...... and ...
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
LegitStack
I’m trying to make a websocket server in Phoenix or raw Elixir. I heard about gun, I think I could use cowboy, but since I’m not that sma...
New
kostonstyle
Hi all I want to have a unix time, from the current time plus 1 hour. DateTime.now + 1 hour How to get it in elixir? Thanks
New
beno
I will often find my self writing things similar to: case some_value do nil -> something() "" -> something() _ -> someth...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers' Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New

Other popular topics Top

JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1140 51847 244
New
William
I would like to know that is there any online source for learning Phoenix Framework for building E-Commerce Store? Any advantage on build...
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
ycv005
I have followed this StackOverflow post to install the specific version of Erlang. And When I am running mix ecto.setup then getting fol...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
beno
I will often find my self writing things similar to: case some_value do nil -> something() "" -> something() _ -> someth...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New

We're in Beta

About us Mission Statement