Facepunch / sbox-issues

173 stars 11 forks source link

Server-side and Client-side only code in a single code base #5770

Open rndtrash opened 2 months ago

rndtrash commented 2 months ago

For?

S&Box

What can't you do?

I'm unable to hide the server-side code of my s&box game from the clients. For some games it makes no sense for any player to host their own room (see #5769), and some games might include financial operations like microtransactions on the server side that have an impact on the gameplay and let the server owners have an income.

The server owners might also want to do server-side only modifications such as pay-walled gameplay mechanics and core systems.

Being able to earn money from the servers will ineviatbly fulfill the need of a game creators in processing power to let all the interested gamers to play their game.

How would you like it to work?

I would like to have a function attribute like [ServerRpc] that acts as a simple function when called on the server, but turns into a RPC when used in the client-side DLL.

[ServerRpc]
public void BuyVip(Player caller, ...) {
  caller.Balance -= 10;
}

protected void OnButtonClick(...) {
  BuyVip();
}

What have you tried?

I have tried making my own WebSocket server, but it makes sense to make one from scratch only for simple games like tycoons or .IO-likes.

I have tried making a separate S&box game that acts as a server, runs the physics, traces, etc., and talks with another S&box game that acts as a client through the WebSockets, but it feels like I am reinventing the wheel, and it results in a duplication of the game resources.

All in all, I want to have both the server- and client-side code as a single codebase that can use the exact same resources and talk to each other with the S&box net protocol.

Additional context

CC @Titanovsky

Related: #5769

MrBrax commented 2 months ago

this is exactly what i imagined c# #if would be used for, feels like the exact use case for server and client only methods