301 Days

A year of gamedev experiments.

Day 42 - Connection Tests Pt 1

| Comments

“I melted the ice of the polar caps, found the raiders of the lost ark, solved a case for the genius from Baker Street, helped to clean the Central Park. I created the plan for the Chinese wall, went to desert, made it rain, swam through a shark tank bloodily, (found Atlantis, by the way),

But today…"

–“Cake to Bake”, Aarzemnieki

Coding

Ok, we’ve had some fun putting together a few tests, but time to get a bit more methodical about it. Digging into the server code, where do we first show up?

GameSystems/Network/IO.cslink
71
72
73
74
75
76
77
78
79
80
public void HandleNewConnections()
{
    if (DragonsSpineMain.ServerStatus == DragonsSpineMain.ServerState.Running ||
        DragonsSpineMain.ServerStatus == DragonsSpineMain.ServerState.Locked)
    {
        while (listener.Pending())
        { //for as long as we have ppl waiting to connect...

            Socket newSock; //a socket to store their connection in
            newSock = listener.AcceptSocket(); //accept the connection

So it lets me connect if the server state is Running or Locked, but what other states are there?

DragonsSpineMain.cslink
41
public enum ServerState { Starting, Running, Locked, ShuttingDown, Restarting };

A little digging further shows that Starting is (as you’d expect) set early in Main, switching to Running when the main game loop starts once everything’s loaded. A developer-level account issuing either the /lockserver or /bootplayers command will set the server to Locked, preventing any non-GMs from entering the game world until a /unlockserver command sets the state back to Running. Similarly, a developer-level account issuing /shutdown will put the server in ShuttingDown, which has the same effect (oddly, it doesn’t actually start any shutting down of the server as far as I can see). I find no reference to Restarting outside of this enum.

So that presents us with a nice little set of tests:

features/connect.featurelink
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
Feature: Connection to server

Scenario: Disallow connection if server in Starting mode
Given the server executable is started
When I do not allow time for the server to complete startup
Then I can not connect to the server via telnet

Scenario: Allow connection if server in Running mode
Given the server is running
Then I can connect to the server via telnet

Scenario: Allow connection if server in Locked mode
Given the server is running
When I log on using a developer account
And I enter the chat
And I issue the "/lockserver" command
And I disconnect from the server
Then I can connect to the server via telnet

Scenario: Disallow connection if server in ShuttingDown mode
Given the server is running
When a developer issues the shutdown command
Then I can not connect to the server via telnet

Some of these steps require us to get our hands pretty dirty. First, thing, how do we know that the server is running? With our database connection, we could make sure the Live* tables are updating, but that’s not guaranteed if the ProcessEmptyWorld server parameter has been set to false and no one is logged in. We need access to the logs or some other indicator of server activity. We can:

  1. Access the logs via Windows file-share shenanigans
  2. Set up a file server (TFTP?) to allow us to grab the logs
  3. Be forced to run the server local to where the tests are running
  4. Modify the server to put state info into the DB
  5. Modify the server to put log entries into the DB
  6. other

For a relatively clean solution (we’ll need the server to be as “run anywhere” as possible), I’m going to try #5. Tomorrow.


Day 42 code - tests

Comments