Wikia

Freeciv

Connection States

703pages on
this wiki
Talk0

IntroductionEdit

This document codifies the connection states of a client to the server. In doing so, we will try to reduce code complexity in places like stdinhand.c

States:

  • Unconnected (0)
  • Connected to Nothing (1)
  • Connected as Player X (2)
  • Connected as Player Y (3)
  • Connected as Observer to Player X (4)
  • Connected as Observer to Player Y (5)

N.B. States 2,3 and 4,5 are considered different states, since we must perform actions in changing from Player X to Player Y.

Definitions:

  • controlling: a connection that can issue commands for a player, chat in the name of that player, etc
  • observing: a connection that receives updates from the server for a player, but cannot issue commands.
  • detached: a connection that is neither controlling or observing.

Commands:

  • /take
  • /detach
  • /observe

Changing From State 2 to State 3Edit

If a connection controls a player X and wants to change to player Y:

  • check game.allowtake for permissions to take control of Y.
  • detach any other controlling connection from Y.
  • check if X should become AI (game.autotoggle). if so, toggle X to AI.
  • detach from X.
  • take control of Y.
  • if Y is AI, check if Y should become human (game.autotoggle).

Notes: While a client controls X, the client possesses the player, map, and game state for X. When switching to Y, the client needs to flush X's state and be transferred Y's state. The rulesets will be the same for either player, so the rulesets should not be flushed.

Changing From State 4 to State 5Edit

If a connection observes player X and wants observe player Y:

  • check game.allowtake for permissions to observe Y
  • detach from X
  • if Y is the global Observer, and Y doesn't exist, create Y
  • observe Y

Around Wikia's network

Random Wiki