I’ve been developing a networked multiplayer game (with LiteNetLib) and I would like it to have the functionality to send content from the server to the client (so the user only has to mod the server). However, because the server is a command line application, I need to create my content manager (and possibly also a graphics device?) on the server to load this content. I’ve been looking at the source for MonoGame and have found that the content manager requires an IServiceProvider, but I’m not sure what I will need to do. So what I’m asking is how do you create a ContentManager for a program which isn’t ‘linked’ to a game class such as a server.
Thanks in Advance.
The reason why you need a GraphicsDevice when, for instance, loading a Texture2D, is because MonoGame loads the bitmap into videoram, ready for use in actual rendering. But, as you say, this is not what the server will be doing, or even NEEDS to do: contentManager does too much.
So, solution: your server should only manage files (nothing to do with the contentmanager) and send the needed files to the client (eg. .PNGs). The client receives these files into memory, and can then do Texture2D.LoadFromStream() to actually start using it for rendering…
So, both server nor client need the content pipeline of MonoGame, it’s just not made for your scenario (although the server could use it, but it will actually make things more complicated than just managing files and the bytes within). Your client directly loads content/assets from files/streams that your server has sent them.
But conclusion: you need to write all this yourself
Last but not least: your server-distributes-all approach may be viable in your case, but I would advise against it. It’s a lot of custom programming-work, and you need to download all needed assets each time the game starts. I don’t know any commercial game that works like this. Game clients typically are installed with all possible resources, and then the server tells them only the minimal info they need to get things going (“load level x!”).
Thanks for your reply,
I went with the ‘server-also-having-content’ approach, as I would prefer for mods to only be managed on the server side and then sent to the client (the client will still have their copy of the base game assets). Thank you for your solution.
@persn answers your question.
Also, XNB files are formatted for the platform they are meant to run on.
Compiling assets using the content pipeline during runtime is tricky and will only work for certain platforms. Using PNG/WAV files will slow everything down.
However, I don’t see why you couldn’t keep multiple kinds of XNB files for each platform, then send those over to be loaded during runtime. In that case, your server’s job would be to simply send over XNB files, which doesn’t require a graphics device?