trophy 80
Nov 2022 19 posts
Currently, dedicated servers download the gamemode from sbox, but if the server side code is not uploaded on sbox, how that will work ? 

What happens if i want to create mutiple dedicated servers withing the same gamemode ?

I think we should have the possibility to upload the server side code on sbox, but needing to authenticate our sbox account on the dedicated server to download the server side. That will prevent anybody to get the server side code if there are no access on the organization
trophy 45
Jun 2023 23 posts
How about the following approach:
You can make a [Private] attribute that can be used to mark both methods and classes. Classes marked with this attribute will not be added to the client assembly, and methods marked with this attribute will not have a body.
trophy 1240
Jul 2021 15 posts
I think y'all did not read garrys 2 assumptions when it comes to people wanted sever side code. 

 We started talking more about how serverside code is going to work. I am assuming the following:

1. People who want serverside code are going to be self hosting all of their servers
2. It will only be on dedicated servers
trophy 175
Apr 2025 14 posts
Multiple projects, client and server. Have some network message base class that lets us send  data across the network and specify recipients (probably by connection). A message handler that would let us subscribe to received network messages would be useful.
trophy 2430
Apr 2021 74 posts
devultj 11 months ago edited 11 months ago
Hello - I've been working on implementing a version of this over the last few days, and here's where we're at:

- We're keeping with one project.. I think. It's simpler that way - it's the most pragmatic method
- We're isolating this to dedicated servers running a .sbproj - so local projects (but still published)
    - You can still publish the project - we'll strip the server code for you, so that's still safe
    - Publishing the project means you can make use of us for distributing assets - our longer term plan is to create a manifest and upload everything, kinda like FastDL but automatic. But for now, it's not super necessary

- When a client joins a server, the server will get rid of all the private server code

To a developer - this is how you'll create server-only / private code.

#if SERVER
    if ( true ) { ... } 
#endif
Alternatively, if you have a file called Something.Server.cs - we'll wrap this whole file in a #if SERVER for you - a bit of syntactical sugar.

What do you guys think about this? Is it useful? Will it be enough? We know there's issues currently running local projects on a dedicated server (related to assets) but I'm going to fix that shortly.
trophy 80
Nov 2022 19 posts
I think that should be good later to have the ability to upload the server side code to sbox, because if i have multiple dedicated servers on a dedicated machine that doesnt have the sbox project, i cant run the server code

With the current way, i need to install the sbox server on docker, then clone the github repo in the container to run the local project. Its fine for now, but should be good if we can upload them later on sbox, like the idea i have sent in the older post above
trophy 2430
Apr 2021 74 posts
I don't see the problem you are trying to describe - if it's in a git repository, you can run it
trophy 590
May 2021 2 posts
To a developer - this is how you'll create server-only / private code.

#if SERVER
    if ( true ) { ... } 
#endif
Alternatively, if you have a file called Something.Server.cs - we'll wrap this whole file in a #if SERVER for you - a bit of syntactical sugar.

I'm curious if you've considered using attributes as another way to strip server code. Saves having the pre-processor directives everywhere:
[AttributeUsage( AttributeTargets.All )]
public sealed class ServerOnlyAttribute : Attribute;


public class YourSharedClass
{
  [ServerOnly]
  private ServerStruct instance;

  private void SomeClientMethod()
  {
    // TODO: Generator walks trees and throws error for this?
    // Or just let C# complain about no field after strip idk
    instance = new();
  }

  [ServerOnly]
  private void SomeServerMethod()
  {
    instance = new(); // Works as normal
  }
}

[ServerOnly]
public struct ServerStruct
{

}
trophy 230
Feb 2023 3 posts
I feel like the attributes could get messy pretty quickly, the `#if server` would simply strip out the block not allowing you to compile(fail fast is favorable).

Also if SERVER is defined, I think you can use the [Conditional("SERVER")] attribute possibly?
trophy 590
May 2021 2 posts
I feel like the attributes could get messy pretty quickly, the `#if server` would simply strip out the block not allowing you to compile(fail fast is favorable).

There are tradeoffs, yeah. I would suggest both ways exist so that the end user can make their choice. The #if server path won't work well with IDE linting since:

We're keeping with one project.. I think. It's simpler that way - it's the most pragmatic method

So you either define the SERVER constant and nothing changes in the IDE, but fail in S&box. Or omit it, and it always shows compiler errors in the IDE.

With the attribute approach, you can use Rozlyn analyzers to catch someone accessing something from an uncertain context. I have made a few analyzers for S&box quirks in the past, so I may be able to write a POC for that if needed.

Also if SERVER is defined, I think you can use the [Conditional("SERVER")] attribute possibly?

That attribute can only be applied to class and method declarations, sadly.
trophy 2430
Apr 2021 74 posts
Having it on a class / method declaration is enough for me - I don't really see the use in having it on a property / field - you don't want it magically getting compiled away, you only want it stubbed so stuff can still compile.

I can look into making ConditionalAttribute work - I didn't know this was something built-in to C#. It doesn't make stuff into disabled text trivia which is a shame,  we can figure out an alternative solution easily enough.
trophy 5
May 2021 9 posts
Yeah that sounds good. Especially the automatic wrapping of something.server.cs files.

How does this work with hotloading (if that even works on dedicated servers) ?
trophy 2430
Apr 2021 74 posts
Just works, we strip the server code back out when sending hotloaded assemblies
trophy 1780
Jul 2022 6 posts
Is this live in main or staging to try out?
trophy 4781
May 2021 134 posts
Staging!
trophy 1780
Jul 2022 6 posts
Just tested with Classname.Server.cs and it indeed strips it from the published library, just leaves a little tidbit within:

#if SERVER
#endif

Basic, but working (for dedicated servers only), which is pretty great for now.
trophy 1240
Oct 2021 148 posts
huge! Can't wait for it to go live on public depot! Time to start my long waited projects >:)
trophy 2430
Apr 2021 74 posts
We're live! Any pain points?

I've been working on something that should make development a little easier. It's still one project, but split out into two csproj's - The non-server csproj hides server files.
trophy 175
Apr 2025 14 posts
Started experimenting with a new project relying on a dedicated server. One thing I will say is how testing & iterating can be quite awkward as my editor doesn't have access to the 'server' code unless I modify the compiler constants to include SERVER. The added side effect is that then includes all the server code for my 'clients' when testing, which I don't want.

Would it be possible to allow us to launch the dedicated server code from the editor instance and connect to it using a client that doesn't have the server code?
people
Log in to reply
You can't reply if you're not logged in. That would be crazy.