Giter Club home page Giter Club logo

tcpgameserver's Introduction

TCP Authoritative Game Server

Slow and Simple authoritative game server made in Go intended for turn based games.

The server handles clients, creating rooms and joining.

server responsibilities maintains and reconnects the player connections sends all input requests to the admin player admin player sends all state updates to the server for relaying

Admin - <- input Jugué la carta 3 de mi mani

sequenceDiagram
    Client->>+Server: Connect
    Server->>-Client: Message : Connected
Loading

login - Login Request

First request from client to server. Should be done after connecting so the server can reconnect if it finds the client id.

sequenceDiagram
    Client->>Server: Login Request
    Note over Client,Server: Username,ClientID
    Server->>Client: Login Response
    Server-->>Client: Reconnect 
Loading
{
  "type": "login",
  "content": {
    "username": "John", // 
    "clientid": "", //if set check for reconnect
  }
}

Login Response:

{
  "type": "login",
  "content": {
    "username": "John-1", // checks uniqueness? 
    "clientid": "[09aZ]" //if set check for reconnect
    "seat": 0-9 // seat number
  }
}

create - Create Room Request

{
  "type": "create"
  // no content for now, password, max players, version, etc
}

Create Response:

{
  "type": "create",
  "content": {
    "code": "R4e2" // room code 
    "isadmin": true
  }
}

join - Join Room Request

{
  "type": "join",
  "content": {
    "code": "R4e2"
    // password, version, etc
  }
}

TODO Send client a response

Broadcasted Response:

{
  "type": "playerJoined",
  "content": {
    "username": "John",
    "isadmin" : false
  }
}

TODO Admin needs to update this player with the lobby preferences

input

Inputs are made by clients and validated on the admin´s client game. The server adds the client´s id and relays the input to the admin.

Request from client:

{
  "type": "input",
  "content": {
    // any json, 
  }
}

Response from server to admin:

{
  "type": "input",
  "clientid" : 0,
  "content": {
    // any json, 
  }
}

broadcast

Admins can broadcast a message to all clients. The server verifies if the client has admin privileges in the room and relays the same message to everyone in the room.

For admin authoritative gameplay these should be what changes the state of the game.

{
  "type": "broadcast",
  "content": {
    // any 
  }
}

send

Admins can send a message to a single player and the server relays it to the client.

{
  "type": "send",
  "playerid" : "id",
  "content": {
     // any 
  }
}
{
  "type": "join",
  "content": {
    "code": "D4R9",
    "username": "John",
    "userid": ""       
  }
}

Credits

Code heavily based on https://github.com/joshheinrichs/go-chat-tcp

tcpgameserver's People

Contributors

notbloom avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.