mirror of
https://github.com/Shpoike/Quakespasm.git
synced 2025-02-14 16:01:44 +00:00
host_cmd.c (Host_Say_f, Host_Tell_f): adjustments, mostly inspired from
the darkplaces engine. git-svn-id: http://svn.code.sf.net/p/quakespasm/code/trunk/quakespasm@317 af15c1b1-3010-417e-b628-4374ebc0bcbd
This commit is contained in:
parent
b06952472b
commit
7271fcb9fe
1 changed files with 56 additions and 26 deletions
|
@ -1282,9 +1282,10 @@ void Host_Say(qboolean teamonly)
|
||||||
{
|
{
|
||||||
client_t *client;
|
client_t *client;
|
||||||
client_t *save;
|
client_t *save;
|
||||||
int j, remquot = 0;
|
int j;
|
||||||
const char *p;
|
const char *p;
|
||||||
char text[MAXCMDLINE];
|
char text[MAXCMDLINE], *p2;
|
||||||
|
qboolean quoted;
|
||||||
qboolean fromServer = false;
|
qboolean fromServer = false;
|
||||||
|
|
||||||
if (cmd_source == src_command)
|
if (cmd_source == src_command)
|
||||||
|
@ -1308,24 +1309,39 @@ void Host_Say(qboolean teamonly)
|
||||||
|
|
||||||
p = Cmd_Args();
|
p = Cmd_Args();
|
||||||
// remove quotes if present
|
// remove quotes if present
|
||||||
|
quoted = false;
|
||||||
if (*p == '"')
|
if (*p == '"')
|
||||||
{
|
{
|
||||||
p++;
|
p++;
|
||||||
remquot = 1;
|
quoted = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// turn on color set 1
|
// turn on color set 1
|
||||||
if (!fromServer)
|
if (!fromServer)
|
||||||
sprintf (text, "%c%s: ", 1, save->name);
|
q_snprintf (text, sizeof(text), "\001%s: %s", save->name, p);
|
||||||
else
|
else
|
||||||
sprintf (text, "%c<%s> ", 1, hostname.string);
|
q_snprintf (text, sizeof(text), "\001<%s> %s", hostname.string, p);
|
||||||
|
|
||||||
j = sizeof(text) - 2 - Q_strlen(text); // -2 for /n and null terminator
|
// check length & truncate if necessary
|
||||||
strncat (text, p, j);
|
j = Q_strlen(text);
|
||||||
j = Q_strlen(text) - 1;
|
if (j >= sizeof(text) - 1)
|
||||||
if (remquot && text[j] == '"')
|
{
|
||||||
text[j] = '\0';
|
text[sizeof(text) - 2] = '\n';
|
||||||
strcat (text, "\n");
|
text[sizeof(text) - 1] = '\0';
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
p2 = text + j;
|
||||||
|
while ((const char *)p2 > (const char *)text &&
|
||||||
|
(p2[-1] == '\r' || p2[-1] == '\n' || (p2[-1] == '\"' && quoted)) )
|
||||||
|
{
|
||||||
|
if (p2[-1] == '\"' && quoted)
|
||||||
|
quoted = false;
|
||||||
|
p2[-1] = '\0';
|
||||||
|
p2--;
|
||||||
|
}
|
||||||
|
p2[0] = '\n';
|
||||||
|
p2[1] = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
for (j = 0, client = svs.clients; j < svs.maxclients; j++, client++)
|
for (j = 0, client = svs.clients; j < svs.maxclients; j++, client++)
|
||||||
{
|
{
|
||||||
|
@ -1338,7 +1354,8 @@ void Host_Say(qboolean teamonly)
|
||||||
}
|
}
|
||||||
host_client = save;
|
host_client = save;
|
||||||
|
|
||||||
Sys_Printf("%s", &text[1]);
|
if (cls.state == ca_dedicated)
|
||||||
|
Sys_Printf("%s", &text[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1358,9 +1375,10 @@ void Host_Tell_f(void)
|
||||||
{
|
{
|
||||||
client_t *client;
|
client_t *client;
|
||||||
client_t *save;
|
client_t *save;
|
||||||
int j, remquot = 0;
|
int j;
|
||||||
const char *p;
|
const char *p;
|
||||||
char text[MAXCMDLINE];
|
char text[MAXCMDLINE], *p2;
|
||||||
|
qboolean quoted;
|
||||||
|
|
||||||
if (cmd_source == src_command)
|
if (cmd_source == src_command)
|
||||||
{
|
{
|
||||||
|
@ -1371,25 +1389,37 @@ void Host_Tell_f(void)
|
||||||
if (Cmd_Argc () < 3)
|
if (Cmd_Argc () < 3)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Q_strcpy(text, host_client->name);
|
|
||||||
Q_strcat(text, ": ");
|
|
||||||
|
|
||||||
p = Cmd_Args();
|
p = Cmd_Args();
|
||||||
|
|
||||||
// remove quotes if present
|
// remove quotes if present
|
||||||
|
quoted = false;
|
||||||
if (*p == '"')
|
if (*p == '"')
|
||||||
{
|
{
|
||||||
p++;
|
p++;
|
||||||
remquot = 1;
|
quoted = true;
|
||||||
}
|
}
|
||||||
|
q_snprintf (text, sizeof(text), "%s: %s", host_client->name, p);
|
||||||
|
|
||||||
// check length & truncate if necessary
|
// check length & truncate if necessary
|
||||||
j = sizeof(text) - 2 - Q_strlen(text); // -2 for /n and null terminator
|
j = Q_strlen(text);
|
||||||
strncat (text, p, j);
|
if (j >= sizeof(text) - 1)
|
||||||
j = Q_strlen(text) - 1;
|
{
|
||||||
if (remquot && text[j] == '"')
|
text[sizeof(text) - 2] = '\n';
|
||||||
text[j] = '\0';
|
text[sizeof(text) - 1] = '\0';
|
||||||
strcat (text, "\n");
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
p2 = text + j;
|
||||||
|
while ((const char *)p2 > (const char *)text &&
|
||||||
|
(p2[-1] == '\r' || p2[-1] == '\n' || (p2[-1] == '\"' && quoted)) )
|
||||||
|
{
|
||||||
|
if (p2[-1] == '\"' && quoted)
|
||||||
|
quoted = false;
|
||||||
|
p2[-1] = '\0';
|
||||||
|
p2--;
|
||||||
|
}
|
||||||
|
p2[0] = '\n';
|
||||||
|
p2[1] = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
save = host_client;
|
save = host_client;
|
||||||
for (j = 0, client = svs.clients; j < svs.maxclients; j++, client++)
|
for (j = 0, client = svs.clients; j < svs.maxclients; j++, client++)
|
||||||
|
|
Loading…
Reference in a new issue