rework PF_stuffcmd so it can't lose chars

This commit is contained in:
Bill Currie 2001-01-07 12:15:38 +00:00
parent 8723fde566
commit 73d26a4e32

View file

@ -668,7 +668,7 @@ PF_stuffcmd (progs_t *pr)
char *str; char *str;
client_t *cl; client_t *cl;
char *buf; char *buf;
int i; char *p;
entnum = G_EDICTNUM (pr, OFS_PARM0); entnum = G_EDICTNUM (pr, OFS_PARM0);
if (entnum < 1 || entnum > MAX_CLIENTS) if (entnum < 1 || entnum > MAX_CLIENTS)
@ -680,20 +680,24 @@ PF_stuffcmd (progs_t *pr)
buf = cl->stufftext_buf; buf = cl->stufftext_buf;
if (strlen (buf) + strlen (str) >= MAX_STUFFTEXT) if (strlen (buf) + strlen (str) >= MAX_STUFFTEXT)
PR_RunError (pr, "stufftext buffer overflow"); PR_RunError (pr, "stufftext buffer overflow");
strncat (buf, str, MAX_STUFFTEXT - strlen (buf)); strcat (buf, str);
for (i = strlen (buf); i >= 0; i--) { if (!strcmp (buf, "disconnect\n")) {
if (buf[i] == '\n') { // so long and thanks for all the fish
if (!strcmp (buf, "disconnect\n")) { cl->drop = true;
// so long and thanks for all the fish buf[0] = 0;
cl->drop = true; return;
buf[0] = 0; }
return;
} p = strrchr (buf, '\n');
ClientReliableWrite_Begin (cl, svc_stufftext, 2 + strlen (buf)); if (p) {
ClientReliableWrite_String (cl, buf); char t = p[1];
buf[0] = 0; p[1] = 0;
} ClientReliableWrite_Begin (cl, svc_stufftext, 2 + p - buf);
ClientReliableWrite_String (cl, buf);
p[1] = t;
strcpy (buf, p + 1); // safe because this is a downward, in
// buffer move
} }
} }