mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-26 22:31:05 +00:00
add backbufs to client_t. can now easily send reliable data to the client
This commit is contained in:
parent
872498a1f0
commit
4eb2842400
4 changed files with 30 additions and 18 deletions
|
@ -33,12 +33,14 @@
|
|||
#define __client_h
|
||||
|
||||
#include "netchan.h"
|
||||
#include "qw/msg_backbuf.h"
|
||||
|
||||
typedef struct client_s {
|
||||
struct info_s *userinfo;
|
||||
struct connection_s *con;
|
||||
int drop;
|
||||
netchan_t netchan;
|
||||
backbuf_t backbuf;
|
||||
} client_t;
|
||||
|
||||
typedef struct challenge_s {
|
||||
|
|
|
@ -45,8 +45,10 @@ extern double realtime;
|
|||
extern cbuf_t *qtv_cbuf;
|
||||
extern cbuf_args_t *qtv_args;
|
||||
|
||||
struct client_s;
|
||||
|
||||
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_flush_redirect (void);
|
||||
|
||||
|
|
|
@ -80,8 +80,8 @@ client_drop (client_t *cl)
|
|||
static void
|
||||
cl_new_f (client_t *cl, void *unused)
|
||||
{
|
||||
qtv_printf ("\"qtv list\" for a list of servers\n");
|
||||
qtv_printf ("\"qtv connect <servername>\" to connect to a server\n");
|
||||
qtv_printf ("\"cmd list\" for a list of servers\n");
|
||||
qtv_printf ("\"cmd connect <servername>\" to connect to a server\n");
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -202,16 +202,18 @@ client_exec_command (client_t *cl, const char *s)
|
|||
|
||||
if (!u) {
|
||||
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_end_redirect ();
|
||||
}
|
||||
} else {
|
||||
if (!u->no_redirect)
|
||||
qtv_begin_redirect (RD_CLIENT);
|
||||
u->func (cl, u->userdata);
|
||||
if (!u->no_redirect)
|
||||
qtv_end_redirect ();
|
||||
if (u->func) {
|
||||
if (!u->no_redirect)
|
||||
qtv_begin_redirect (RD_CLIENT, cl);
|
||||
u->func (cl, u->userdata);
|
||||
if (!u->no_redirect)
|
||||
qtv_end_redirect ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -337,6 +339,8 @@ client_handler (connection_t *con, void *object)
|
|||
//cl->send_message = true;
|
||||
//if (cl->state != cs_zombie)
|
||||
client_parse_message (cl);
|
||||
if (cl->backbuf.num_backbuf)
|
||||
MSG_Reliable_Send (&cl->backbuf);
|
||||
Netchan_Transmit (&cl->netchan, 0, NULL);
|
||||
if (cl->drop) {
|
||||
Connection_Del (cl->con);
|
||||
|
@ -393,6 +397,8 @@ client_connect (connection_t *con, void *object)
|
|||
|
||||
cl = calloc (1, sizeof (client_t));
|
||||
Netchan_Setup (&cl->netchan, con->address, qport, NC_READ_QPORT);
|
||||
cl->backbuf.netchan = &cl->netchan;
|
||||
cl->backbuf.name = "FIXME";
|
||||
cl->userinfo = userinfo;
|
||||
cl->con = con;
|
||||
con->object = cl;
|
||||
|
|
|
@ -84,6 +84,7 @@ static cvar_t *fs_globalcfg;
|
|||
static cvar_t *fs_usercfg;
|
||||
|
||||
redirect_t qtv_redirected;
|
||||
client_t *qtv_redirect_client;
|
||||
dstring_t outputbuf = {&dstring_default_mem};
|
||||
|
||||
static void
|
||||
|
@ -157,34 +158,34 @@ qtv_flush_redirect (void)
|
|||
count -= bytes;
|
||||
}
|
||||
} else if (qtv_redirected == RD_CLIENT) {
|
||||
#if 0
|
||||
client_t *cl = qtv_redirect_client;
|
||||
p = outputbuf.str;
|
||||
while (count) {
|
||||
// +/- 3 for svc_print, PRINT_HIGH and nul byte
|
||||
// min of 4 because we don't want to send an effectively empty
|
||||
// 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
|
||||
// the rest of the data. getting rudely disconnected would be much
|
||||
// more annoying than losing the tail end of the output
|
||||
if (bytes <= 0)
|
||||
break;
|
||||
ClientReliableWrite_Begin (cl, svc_print, bytes + 3);
|
||||
ClientReliableWrite_Byte (cl, PRINT_HIGH);
|
||||
ClientReliableWrite_SZ (cl, p, bytes);
|
||||
ClientReliableWrite_Byte (cl, 0);
|
||||
MSG_ReliableWrite_Begin (&cl->backbuf, svc_print, bytes + 3);
|
||||
MSG_ReliableWrite_Byte (&cl->backbuf, PRINT_HIGH);
|
||||
MSG_ReliableWrite_SZ (&cl->backbuf, p, bytes);
|
||||
MSG_ReliableWrite_Byte (&cl->backbuf, 0);
|
||||
p += bytes;
|
||||
count -= bytes;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
dstring_clear (&outputbuf);
|
||||
}
|
||||
|
||||
void
|
||||
qtv_begin_redirect (redirect_t rd)
|
||||
qtv_begin_redirect (redirect_t rd, client_t *cl)
|
||||
{
|
||||
qtv_redirected = rd;
|
||||
qtv_redirect_client = cl;
|
||||
dstring_clear (&outputbuf);
|
||||
}
|
||||
|
||||
|
@ -193,6 +194,7 @@ qtv_end_redirect (void)
|
|||
{
|
||||
qtv_flush_redirect ();
|
||||
qtv_redirected = RD_NONE;
|
||||
qtv_redirect_client = 0;
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -312,7 +314,7 @@ qtv_ping (void)
|
|||
static void
|
||||
qtv_status (void)
|
||||
{
|
||||
qtv_begin_redirect (RD_PACKET);
|
||||
qtv_begin_redirect (RD_PACKET, 0);
|
||||
Sys_Printf ("\\*version\\%s qtv %s", QW_VERSION, VERSION);
|
||||
qtv_end_redirect ();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue