- Server sends a message to the client who's turn it is
- Server sends game table to every client, so they can display the ui correctly
- Clients listens to server messages
- Clients use this table to display the ui
- Client which got the turn message waits for user input
- Client sends the server what action the user did
- Server looks at the 'Game rules' and changes the world table if the user action is valid
- Repeat everything again
This is a read-only snapshot of the ComputerCraft forums,
taken in April 2020.
server/client system for games
Started by Jummit, 30 August 2017 - 12:40 PMPosted 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:
Edited on 01 September 2017 - 06:00 AM
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).
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).
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).
Posted 30 August 2017 - 03:47 PM
edited the post: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).
I realy struggle to make a server/client system for a turnbased computercraft game.
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!").
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!").
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.
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.