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.

First 5 of 5 Posts! Switch mode

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

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.

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)

henrysdev

henrysdev

Yeah, I’m leaning this way too now. I currently do MyAppWeb.Endpoint.broadcast... from my game server to push events to clients, so I could just add an extra function call to “broadcast” the event to bots as well. Probably don’t even need a middleman event server to your point. Was thinking adding an event server would improve modularity/testability but probably is more complexity than its worth.

madclaws

madclaws

Yeah, From game-server we can broadcast like usual to the channel.

Where Next?

Trending in Questions Top

jonnycharles
I’m in search of an Elixir library that offers PDF generation capabilities similar to Ruby’s Prawn. While there have been discussions abo...
New
spammy
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
silverdr
Using Phoenix.LiveView.TagEngine as an EEx.Engine is deprecated! To compile HEEx, use Phoenix.LiveView.TagEngine.compile/2 instead. Sta...
New
saveman71
Hello ! We want new/edit form pages to POST/PUT to their own URL rather than the resources REST defaults (post /things, put /things/:id)...
New
dli
Before I dive in myself, did anyone successfully sprinkle Hologram into their existing LiveView app? Looking for hints regarding: Addi...
New
bottlenecked
Hi all, I wanted to ask how the community is dealing with post-release steps. Today we have Ecto migrations, which make sure that the db...
New
michallepicki
I am using Oban and occasionally, shortly after a deployment, a handful of jobs can fail because of dependency on other parts of the syst...
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New
ausimian
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New
type1fool
I just stumbled on a newly redesigned elixir-lang.org. :tada: It looks like @Software_Mansion did the work, and I think it is generally a...
New
akoutmos
@hugobarauna and I (Alex Koutmos) have been hard at work on writing a book on Nerves that takes you from simply blinking LEDs to building...
New

We're in Beta

About us Mission Statement