syntax = "proto3";

package freeexile.network;

// Base message envelope with cryptographic sequence and nonce
message PacketEnvelope {
  uint64 sequence_number = 1;
  uint64 timestamp_ms = 2;
  bytes nonce = 3;             // 12-byte unique nonce for ChaCha20-Poly1305
  bytes encrypted_payload = 4; // Ciphertext
  bytes auth_tag = 5;          // 16-byte Poly1305 MAC tag
}

// Touch Biometrics collected on iOS for anti-bot behavioral ML
message TouchBiometrics {
  float major_radius = 1;      // Touch area contact radius in points
  float force = 2;             // Touch pressure force
  float micro_tremor_hz = 3;   // Frequency analysis of biological hand jitter (8-12Hz)
  float trajectory_curvature = 4; // Curvature deviation from straight line (0 = straight bot line)
  uint32 device_type = 5;      // 1 = iPhone Genuine, 2 = iPad Genuine, 99 = Unknown/Emulator
  bytes app_attest_token = 6;  // Apple App Attest signed statement
}

// Player movement input sent from Client to Server (Zero client authority on final coordinates)
message PlayerMoveInput {
  uint32 entity_id = 1;
  float dir_x = 2;             // Normalized direction vector X
  float dir_y = 3;             // Normalized direction vector Y
  uint32 input_sequence = 4;
  TouchBiometrics biometrics = 5;
}

// Authoritative World State broadcast from Server to Client
message EntitySnapshot {
  uint32 entity_id = 1;
  float pos_x = 2;
  float pos_y = 3;
  float velocity_x = 4;
  float velocity_y = 5;
  uint32 current_hp = 6;
  uint32 max_hp = 7;
  uint32 animation_state = 8;
  uint64 last_processed_input_seq = 9;
}

message WorldStateSync {
  uint64 server_tick = 1;
  repeated EntitySnapshot entities = 2;
}
