lucaspoffo / renet

Server/Client network library for multiplayer games with authentication and connection management made with Rust
Apache License 2.0
624 stars 67 forks source link

Distinguish Events that are sent on custom server side. #37

Closed dennym closed 1 year ago

dennym commented 1 year ago

Heyhey. Currently I try to use renet on my bevy project to communicate with a simple elixir UDP server that just logs into the console while running.

~~As the the messages are send in bincode I already implemented some simple logic to get the bincode deserialized to an elixir struct. Unfortunately my actual test text message I try to send is overshadowed by plenty of messages I believe come from the RenetClient.~~

This is I believe the Message that is internally sent by RenetClient. And I tried to get the binary back to a term. Unfortunately a simple :erlang.binary_to_term won't work since the binary seems some different structure. Maybe you have an idea or recommendation how I can implement this on elixir side. Maybe this is even worth a separate library to enable a different server language for renet.

best regards Denny

lucaspoffo commented 1 year ago

Hey Denny,

If you are trying to read raw UDP packets on the Elixir side, this will be a hard endeavor, since you need to implement the authentication and encryption protocol, which is done by renetcode. After that, you would need to implement the protocol for reliable messages over UDP that is done in rechannel.

My suggestion would be to use FFI bindings with renet on the elixir side. I would check with someone in the elixir community about using Rust FFI and Elixir, maybe they know some better way to do what you want.

dennym commented 1 year ago

Ahh you caught me right in my edit :) I removed the whole bincode part since it is totally unimportant for the actual issue. It slowly dawned on me that I basically have to translate the server and the netcode to elixir to get anywhere.

I already had the FFI in the back of my head. My experience in the past it is usually not that nice to use when the rust logic and return values are more complex. Its nice when there are 2 simple inputs and the return is a simple basic data type. But returning structs and enums through it becomes heavy. Usually while trying this the back of the head tries to negotiate with itself to just write the whole thing by hand.

I will give it a go over the weekend and will come back with the results :)

Thanks for the input

lucaspoffo commented 1 year ago

I guess it would be still easier to use FFI instead of implementing the whole protocol. The only structs/enums are ServerEvent, NetworkInfo, and Bytes I think, the others used types are basic ones. I've never done FFI so I don't really know how hard/possible it's :/

Anyway, good luck. I'll be closing this issue, but you can open a discussion (just enabled it on the repo) or post on this issue about your progress, I'm curious about your usage with Elixir :)