Send player ID and add more logging because this fucking sucks donkey assboner
This commit is contained in:
parent
eba63c4902
commit
4bd5303cfd
18
main.go
18
main.go
@ -47,6 +47,7 @@ func main() {
|
||||
for {
|
||||
if time.Since(lastTick) >= tickRate {
|
||||
lastTick = time.Now()
|
||||
// log.Printf("Last tick: %s", lastTick)
|
||||
processActions()
|
||||
}
|
||||
}
|
||||
@ -55,10 +56,26 @@ func main() {
|
||||
func handleConnection(conn net.Conn) {
|
||||
defer conn.Close()
|
||||
|
||||
// Assign a new player ID and add the player to the game state
|
||||
playerID := len(players) + 1
|
||||
players[playerID] = &Player{ID: playerID, X: 5, Y: 5} // Start at default position
|
||||
fmt.Printf("Player %d connected\n", playerID)
|
||||
|
||||
// Send player ID to the client
|
||||
serverMsg := &pb.ServerMessage{
|
||||
PlayerId: int32(playerID),
|
||||
}
|
||||
data, err := proto.Marshal(serverMsg)
|
||||
if err != nil {
|
||||
log.Printf("Failed to marshal ServerMessage for player %d: %v", playerID, err)
|
||||
return
|
||||
}
|
||||
if _, err := conn.Write(data); err != nil {
|
||||
log.Printf("Failed to send player ID to player %d: %v", playerID, err)
|
||||
return
|
||||
}
|
||||
|
||||
// Listen for incoming actions from this player
|
||||
buf := make([]byte, 4096)
|
||||
for {
|
||||
n, err := conn.Read(buf)
|
||||
@ -74,6 +91,7 @@ func handleConnection(conn net.Conn) {
|
||||
continue
|
||||
}
|
||||
|
||||
// Queue the action for processing in the game loop
|
||||
actionQueue[playerID] = append(actionQueue[playerID], action)
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user