juegos

Juegos de terminal de Pancho: Catan (TUI, GUI, web, servidor, PicoCalc), ajedrez, calculadora y minijuegos
git clone https://git.lu3dhn.xyz/juegos.git
Log | Files | Refs

session.h (2712B)


      1 /* session.h - una partida vista desde este cliente: local (corremos la autoridad)
      2  * o remota (servidor VPS / host LAN). */
      3 #ifndef SESSION_H
      4 #define SESSION_H
      5 
      6 #include <stdio.h>
      7 #include "../core/host.h"
      8 #include "../core/ctrl.h"
      9 #include "paths.h"
     10 
     11 #define LOG_CHAT    '\x01'          /* marca de linea de chat (se dibuja de otro color) */
     12 #define LOG_WHISPER '\x02'          /* chat privado */
     13 #define LOG_MOVE    '\x03'          /* movida: el nombre del que juega va de su color */
     14 #define LOG_ALERT   '\x04'          /* algo que te paso a vos (te robaron): toda la linea resaltada */
     15 
     16 typedef struct Net Net;
     17 
     18 typedef struct Session {
     19     bool     local;              /* true: la autoridad corre aca */
     20     Host     host;
     21     Game     view;               /* estado redactado (cliente remoto) */
     22     Undo     view_undo;
     23     const Game *g;
     24     uint8_t  local_mask;
     25     bool     handoff;
     26     char     names[MAXP][20];
     27     char   **log;                   /* registro completo (crece); chat/movidas: marca + asiento + texto */
     28     int      nlog, caplog;
     29     FILE    *save;
     30     char     save_path[512];
     31     long long next_bot_ms;
     32     int      bot_delay_ms;
     33     Net     *net;
     34     char     status[128];
     35     int      last_err;
     36     bool     err_pending;
     37     bool     ended;              /* la conexion se cerro / la partida termino */
     38     bool     replaying;
     39 } Session;
     40 
     41 /* Partida local nueva (hotseat, bots, o host LAN si despues se abre la red). */
     42 void sess_new_local(Session *s, const Opts *o, uint64_t seed, const uint8_t kinds[MAXP], char names[MAXP][20]);
     43 bool sess_resume(Session *s, const char *path, char *err, int errlen);
     44 void sess_set_bots(Session *s, int level);      /* 0 facil, 1 medio, 2 dificil: ISMCTS con mas iteraciones */
     45 int  bot_iters(int level);   /* bots heuristicos o con busqueda */
     46 /* partida local terminada: la pasa a juego libre (reescribe OPTS y la recarga) */
     47 bool sess_go_free(Session *s, char *err, int errlen);
     48 int  sess_submit(Session *s, Move *m);
     49 void sess_poll(Session *s);
     50 int  sess_timeout(const Session *s);
     51 int  sess_fds(const Session *s, int *fds, int max);
     52 void sess_close(Session *s);
     53 void sess_add_log(Session *s, const char *line);
     54 void sess_log_clear(Session *s);
     55 void sess_chat_in(Session *s, int from, int to, const char *text);   /* llego un mensaje */
     56 /* Lo que escribio el usuario: texto para todos o "/w nombre texto" (tambien /msg,
     57  * /whisper). Devuelve NULL si salio bien o un texto de error para mostrar. */
     58 const char *sess_say(Session *s, const char *input);
     59 void sess_on_move(Session *s, const Move *m);   /* para la vista remota */
     60 
     61 /* la partida guardada mas reciente (los .catan de data_dir()/saves) */
     62 bool latest_save(char *out, int n);
     63 
     64 #endif