add backbufs to client_t. can now easily send reliable data to the client

This commit is contained in:
Bill Currie 2004-02-22 06:19:38 +00:00
parent 872498a1f0
commit 4eb2842400
4 changed files with 30 additions and 18 deletions

View file

@ -33,12 +33,14 @@
#define __client_h #define __client_h
#include "netchan.h" #include "netchan.h"
#include "qw/msg_backbuf.h"
typedef struct client_s { typedef struct client_s {
struct info_s *userinfo; struct info_s *userinfo;
struct connection_s *con; struct connection_s *con;
int drop; int drop;
netchan_t netchan; netchan_t netchan;
backbuf_t backbuf;
} client_t; } client_t;
typedef struct challenge_s { typedef struct challenge_s {

View file

@ -45,8 +45,10 @@ extern double realtime;
extern cbuf_t *qtv_cbuf; extern cbuf_t *qtv_cbuf;
extern cbuf_args_t *qtv_args; extern cbuf_args_t *qtv_args;
struct client_s;
void qtv_printf (const char *fmt, ...) __attribute__((format(printf,1,2))); void qtv_printf (const char *fmt, ...) __attribute__((format(printf,1,2)));
void qtv_begin_redirect (redirect_t rd); void qtv_begin_redirect (redirect_t rd, struct client_s *cl);
void qtv_end_redirect (void); void qtv_end_redirect (void);
void qtv_flush_redirect (void); void qtv_flush_redirect (void);

View file

@ -80,8 +80,8 @@ client_drop (client_t *cl)
static void static void
cl_new_f (client_t *cl, void *unused) cl_new_f (client_t *cl, void *unused)
{ {
qtv_printf ("\"qtv list\" for a list of servers\n"); qtv_printf ("\"cmd list\" for a list of servers\n");
qtv_printf ("\"qtv connect <servername>\" to connect to a server\n"); qtv_printf ("\"cmd connect <servername>\" to connect to a server\n");
} }
static void static void
@ -202,16 +202,18 @@ client_exec_command (client_t *cl, const char *s)
if (!u) { if (!u) {
if (ucmd_unknown && !ucmd_unknown ()) { if (ucmd_unknown && !ucmd_unknown ()) {
qtv_begin_redirect (RD_CLIENT); qtv_begin_redirect (RD_CLIENT, cl);
qtv_printf ("Bad user command: %s\n", qtv_args->argv[0]->str); qtv_printf ("Bad user command: %s\n", qtv_args->argv[0]->str);
qtv_end_redirect (); qtv_end_redirect ();
} }
} else { } else {
if (!u->no_redirect) if (u->func) {
qtv_begin_redirect (RD_CLIENT); if (!u->no_redirect)
u->func (cl, u->userdata); qtv_begin_redirect (RD_CLIENT, cl);
if (!u->no_redirect) u->func (cl, u->userdata);
qtv_end_redirect (); if (!u->no_redirect)
qtv_end_redirect ();
}
} }
} }
@ -337,6 +339,8 @@ client_handler (connection_t *con, void *object)
//cl->send_message = true; //cl->send_message = true;
//if (cl->state != cs_zombie) //if (cl->state != cs_zombie)
client_parse_message (cl); client_parse_message (cl);
if (cl->backbuf.num_backbuf)
MSG_Reliable_Send (&cl->backbuf);
Netchan_Transmit (&cl->netchan, 0, NULL); Netchan_Transmit (&cl->netchan, 0, NULL);
if (cl->drop) { if (cl->drop) {
Connection_Del (cl->con); Connection_Del (cl->con);
@ -393,6 +397,8 @@ client_connect (connection_t *con, void *object)
cl = calloc (1, sizeof (client_t)); cl = calloc (1, sizeof (client_t));
Netchan_Setup (&cl->netchan, con->address, qport, NC_READ_QPORT); Netchan_Setup (&cl->netchan, con->address, qport, NC_READ_QPORT);
cl->backbuf.netchan = &cl->netchan;
cl->backbuf.name = "FIXME";
cl->userinfo = userinfo; cl->userinfo = userinfo;
cl->con = con; cl->con = con;
con->object = cl; con->object = cl;

View file

@ -84,6 +84,7 @@ static cvar_t *fs_globalcfg;
static cvar_t *fs_usercfg; static cvar_t *fs_usercfg;
redirect_t qtv_redirected; redirect_t qtv_redirected;
client_t *qtv_redirect_client;
dstring_t outputbuf = {&dstring_default_mem}; dstring_t outputbuf = {&dstring_default_mem};
static void static void
@ -157,34 +158,34 @@ qtv_flush_redirect (void)
count -= bytes; count -= bytes;
} }
} else if (qtv_redirected == RD_CLIENT) { } else if (qtv_redirected == RD_CLIENT) {
#if 0 client_t *cl = qtv_redirect_client;
p = outputbuf.str; p = outputbuf.str;
while (count) { while (count) {
// +/- 3 for svc_print, PRINT_HIGH and nul byte // +/- 3 for svc_print, PRINT_HIGH and nul byte
// min of 4 because we don't want to send an effectively empty // min of 4 because we don't want to send an effectively empty
// message // message
bytes = ClientReliableCheckSize (cl, count + 3, 4) - 3; bytes = MSG_ReliableCheckSize (&cl->backbuf, count + 3, 4) - 3;
// if writing another packet would overflow the client, just drop // if writing another packet would overflow the client, just drop
// the rest of the data. getting rudely disconnected would be much // the rest of the data. getting rudely disconnected would be much
// more annoying than losing the tail end of the output // more annoying than losing the tail end of the output
if (bytes <= 0) if (bytes <= 0)
break; break;
ClientReliableWrite_Begin (cl, svc_print, bytes + 3); MSG_ReliableWrite_Begin (&cl->backbuf, svc_print, bytes + 3);
ClientReliableWrite_Byte (cl, PRINT_HIGH); MSG_ReliableWrite_Byte (&cl->backbuf, PRINT_HIGH);
ClientReliableWrite_SZ (cl, p, bytes); MSG_ReliableWrite_SZ (&cl->backbuf, p, bytes);
ClientReliableWrite_Byte (cl, 0); MSG_ReliableWrite_Byte (&cl->backbuf, 0);
p += bytes; p += bytes;
count -= bytes; count -= bytes;
} }
#endif
} }
dstring_clear (&outputbuf); dstring_clear (&outputbuf);
} }
void void
qtv_begin_redirect (redirect_t rd) qtv_begin_redirect (redirect_t rd, client_t *cl)
{ {
qtv_redirected = rd; qtv_redirected = rd;
qtv_redirect_client = cl;
dstring_clear (&outputbuf); dstring_clear (&outputbuf);
} }
@ -193,6 +194,7 @@ qtv_end_redirect (void)
{ {
qtv_flush_redirect (); qtv_flush_redirect ();
qtv_redirected = RD_NONE; qtv_redirected = RD_NONE;
qtv_redirect_client = 0;
} }
static void static void
@ -312,7 +314,7 @@ qtv_ping (void)
static void static void
qtv_status (void) qtv_status (void)
{ {
qtv_begin_redirect (RD_PACKET); qtv_begin_redirect (RD_PACKET, 0);
Sys_Printf ("\\*version\\%s qtv %s", QW_VERSION, VERSION); Sys_Printf ("\\*version\\%s qtv %s", QW_VERSION, VERSION);
qtv_end_redirect (); qtv_end_redirect ();
} }