s&box
04 September 2017

Dev Blog 1 - Webcon

About the web console system.
Garry Newman
Programmer
United Kingdom
Motivation
Most games have an in game console. They're usually used to run commands and set/get variables. When we first started making Sandbox Game, I decided that the console should be an external app. It should open when you press the console key - like the console in Source 2 works. This worked, and worked well. It was using WPF though, so was obviously windows only. So I considered using something like electron to create a cross platform app to replace it. Then I thought another step deeper.
Implementation
So in the current implementation, the game itself creates a tiny web server. It serves the console's webpages and javascript, and also listens to websockets on the same port. This means that you can navigate to the server's rcon url (localhost:27016) and the console will show, and connect to the game. You've got a direct TCP connection to the game. This ticks a lot of the boxes for us. It's totally cross platform, it offloads all the bullshit to an external process, you can copy and paste from and to it really easily, it survives the game if it crashes so you don't have to go looking through log files. It also means that we don't have to implement rcon, because you can set a username and password and access the console via your web browser remotely.
Tour
This is still kind of a working prototype, it's serving our functions right now and there's a lot of cleaning up to do.

Console Page

The console page is what you expect. If you click on an entry you get a stack trace Info returned from the game can be formatted however we want.

Assets

The assets page shows a list of loaded assets This is still kind of rough, but the intention is to show diagnostic information about how the asset was loaded. So any errors on loading would show here, load times etc.

Hotload

Sandbox can hotload c#. When you edit and save, it automatically compiles and reloads. The hotload tab shows diagnostic information about that process, so if it's slow we can find out why. Or if it's throwing errors, we can get more info.

Addons

The addons tab is really just there right now to make sure the "active/inactive" system for addons is working.
Shitty Bits

Code Jumping

In the old IDE implementation it was nice clicking on lines in the stack trace to jump to that line of code in VS/VSCode. We can't really do that in the web version natively - because we can't run code. One solution is to send a message back to the game and then the game runs the code to open VS to that file/line. That works but obviously doesn't work when the game is closed. There are other, better solutions though.

Quick Switching

At the moment we've got it so when you press the console key it opens the console webpage if it's not open, and switches to it if it is. Then if you press the console key on the webpage it switches back to the game. This assumes that you've got the console/webpage open and is the selected tab. The solution to this, which is the route I think we're going to take, is to simply show the webpage console in game like a traditional console. This feels like the right move as it means you'll still be able to easily access the console in full screen mode.