server skeleton

This commit is contained in:
2026-05-30 18:08:48 +02:00
parent feef6cc80b
commit d29d61cada
2 changed files with 42 additions and 12 deletions
+38 -8
View File
@@ -58,6 +58,29 @@ send_payload :: proc(sock: net.TCP_Socket, pl: Payload) -> net.Network_Error {
return nil
}
poke_player :: proc(player: int) -> bool {
unimplemented()
}
Play_Action :: distinct Card
Discard_Action :: distinct Card
Hint_Action :: distinct Card
Action :: union {
Play_Action,
Discard_Action,
Hint_Action,
}
receive_action :: proc(player: int) -> (action: Action, is_valid: bool) {
unimplemented()
}
perform_action :: proc(game: ^Game, action: Action) {
unimplemented()
}
run_server :: proc(listen_addr: net.Endpoint, num_players: int, num_hints: int, num_lives: int) {
listener, list_err := net.listen_tcp(listen_addr)
if list_err != nil do panic(fmt.tprintln("failed to listen:", net.to_string(listen_addr)))
@@ -84,15 +107,22 @@ run_server :: proc(listen_addr: net.Endpoint, num_players: int, num_hints: int,
fmt.printfln("player %d's turn!", current_player)
for p in g.players {
fmt.println()
for c in p.hand {
fmt.println(c.value, c.color)
}
// for p in g.players {
// fmt.println()
// for c in p.hand {
// fmt.println(c.value, c.color)
// }
// }
action: Action
POKE: for {
poke_ok := poke_player(current_player)
if !poke_ok do panic(fmt.tprintln("failed to poke player", current_player))
action, is_valid := receive_action(current_player)
if is_valid do break POKE
fmt.println("invalid action received. try again.")
}
// body
perform_action(&g, action)
current_player = (current_player + 1) % num_players
free_all(context.temp_allocator)
break GAME_LOOP
+4 -4
View File
@@ -2,8 +2,8 @@
(interleave
{ odin run . -- h localhost:42069 2 | lines | each { "HOST | " ++ $in } }
{ sleep 300ms
odin run . -- c localhost:42069 | lines | each { "PLAYER 1 | " ++ $in } }
{ sleep 300ms
odin run . -- c localhost:42069 | lines | each { "PLAYER 2 | " ++ $in } })
{ sleep 500ms
odin run . -- c localhost:42069 | lines | each { "PLAYER 0 | " ++ $in } }
{ sleep 500ms
odin run . -- c localhost:42069 | lines | each { "PLAYER 1 | " ++ $in } })
| each { print $in } | ignore