Skip to content

Networking

Tom Dicks edited this page Aug 23, 2022 · 3 revisions

Zelands uses Twisted for client/server networking and has a protocol built on AMP.

Server joining process:

  1. Client initiates TCP connection
  2. Client sends PlayerConnected (hi there I'm a client, here's my client ID)
  3. Server replies PlayerConnected response (thanks you're authed or here's your new client ID)
  4. Server sends PlayerSpawn (Oi client, I've spawned you in the game world, you need to render stuff)

Clientside Actions

These are sent from client to server, and are a way for the client to tell the server that the player has performed actions.

Player connection/disconnection

  • Player connects to the game - PlayerConnected (after TCP session)
  • Player disconnects from the game - PlayerDisconnected (clean disconnect, clear up stuff and say bye)

Player Position

  • Player moves position - PlayerMoved
    • Parameters - x, y, status

Player Item Actions These are dependent on the player's currently equipped item. Game behaviour such as damage is calculated on the server, and effects are rendered on the client.

  • Player change item - PlayerItemEquipped
    • Parameters - ID of new item, slot
  • Player performs primary action - PlayerPrimaryAction (shoot a gun, melee etc)
  • Player performs secondary action - PlayerSecondaryAction (do something else)
  • Player performs a tertiary action - PlayerTertiaryAction (reload?)
  • Player picks up an item - PlayerItemCollected
    • Parameters - ID of the item
    • Item will be removed from the game world and added to the player's inventory
    • Some server-side logic would be needed to check whether the player can actually reach this item...
  • Player drops an item - PlayerItemDropped
    • Parameters - ID of the item
    • The item will be removed from the player's inventory and dropped in front of the player's facing direction
    • A cool-off might be needed to stop the item from being picked up immediately by the same player.

Serverside Actions

These are sent from server to client, and serve to inform connected clients of events happening in the game world.

Server instructions to the client

  • Player back in the game - PlayerSpawn (happens after a death of some kind, the server has spawned the player and now the client should resume play)
    • Parameters - x, y, status
  • Client should render a message - ShowMessage
    • Parameters - message, type (middle screen, "chat" window, or other?)

Entity existence and location

  • An entity in the game has spawned - EntitySpawned
    • A new entity has appeared in the game which the client should render
    • Parameters - uid, x, y, orientation, entity
  • An entity in the game has moved position and/or orientation - EntityMoved
    • Instruct the client to place the entity in the new location and orientation
    • Parameters - uid, x, y, orientation
  • An entity in the game should be removed by the client - EntityRemoved
    • The client should remove this entity with no fanfare or other action
    • Parameters - uid
  • An entity in the game has died or been killed - EntityDied
    • The client should play the entity's death animation
    • Parameters - uid, killer_id, item_id
  • An entity in the game has been wounded or damaged - EntityDamaged
    • This is mainly for playing a damage animation, pushback will be via EntityMoved
    • Parameters - uid

Entity actions

  • An entity in the game has equipped an item - EntityItemEquipped
    • For clientside this is just a matter of rendering the new item on the owning entity
    • Parameters - ID of the new item, slot
  • An entity in the game has performed primary action - EntityPrimaryAction
    • Client should render the appropriate animation for the item
  • An entity in the game has performed secondary action - EntitySecondaryAction
    • Client should render the appropriate animation for the item
  • An entity in the game has performed secondary action - EntityTertiaryAction
    • Client should render the appropriate animation for the item

Entity item collections and drops

  • The client will be told to spawn or remove items when other players collect/drop them. There is no need for ItemCollected or ItemDropped entity actions.

Clone this wiki locally