This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Jummit's profile picture

server/client system for games

Started by Jummit, 30 August 2017 - 12:40 PM
Jummit #1
Posted 30 August 2017 - 02:40 PM
I realy struggle to make a server/client system for a turnbased computercraft game. Here is my basic concept:
  1. Server sends a message to the client who's turn it is
  2. Server sends game table to every client, so they can display the ui correctly
  3. Clients listens to server messages
  4. Clients use this table to display the ui
  5. Client which got the turn message waits for user input
  6. Client sends the server what action the user did
  7. Server looks at the 'Game rules' and changes the world table if the user action is valid
  8. Repeat everything again
I never did this before. Is this a good concept? How did you do you're server/client stuff?
Edited on 01 September 2017 - 06:00 AM
KingofGamesYami #2
Posted 30 August 2017 - 02:50 PM
I don't really do networking very often, but in general it works as a "call and response" system - where the client requests the server to do something, and the server responds. If the server doesn't respond within a reasonable amount of time, it can't be reached.

In the real world, you would want to keep the amount of data being sent back and forth pretty low. In CC, you don't have to worry that much as everything is virtual (unless you're using http obviously).
Bomb Bloke #3
Posted 30 August 2017 - 03:23 PM
A lot depends on whether you're making some sort of turn-based system (where the server would only have to deal with one client at once, in a predictable order), or a real-time system (where the server would need to be able to handle communications from clients at any time and in any order).
Jummit #4
Posted 30 August 2017 - 03:47 PM
A lot depends on whether you're making some sort of turn-based system (where the server would only have to deal with one client at once, in a predictable order), or a real-time system (where the server would need to be able to handle communications from clients at any time and in any order).
edited the post:
I realy struggle to make a server/client system for a turnbased computercraft game.
Dave-ee Jones #5
Posted 31 August 2017 - 01:11 AM
It might be better to do a turn-based-game with channels, as the server can broadcast "It's this guy's turn" and all the other clients can go "Okay, boss" instead of the one client getting the info and the other clients are going "Server? Are you there? Hello? Is it my turn yet?".

This would also mean that the server can check for BOTH clients at once, a client saying "Hey, I'm Player 1, can I move here?" while the other client says "Is Player 1's turn over yet?"

The server could also make periodic updates for time limits and things like that, and they can broadcast the game's board over the channel. This could also mean you can have spectators who can draw the game's board on their screen. That's where you would make use of "protocols" (not to be confused with rednet's protocols) to determine the difference between a spectator update and a player update, or even a global one for both (like "It's Player 1's turn!").
Lupus590 #6
Posted 31 August 2017 - 02:52 PM
I wouldn't have clients ask "Is player X's turn over yet?", having the client have a watchdog timer which the server has to reset would be a good idea though.
Dave-ee Jones #7
Posted 01 September 2017 - 12:29 AM
I wouldn't have clients ask "Is player X's turn over yet?", having the client have a watchdog timer which the server has to reset would be a good idea though.

Agreed. It would be better for the client to have a timer while listening to the server, and have the server tell the client it's their turn now.