Skip to content

Commit

Permalink
Merged amended pull request "Sync with Q2PRO: Miscellaneous": #433
Browse files Browse the repository at this point in the history
  • Loading branch information
apanteleev committed Feb 19, 2025
2 parents 9e937de + 5155d2e commit e82ba8c
Show file tree
Hide file tree
Showing 12 changed files with 71 additions and 43 deletions.
2 changes: 1 addition & 1 deletion inc/common/mdfour.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,

typedef struct mdfour {
uint32_t A, B, C, D;
uint32_t count;
uint64_t count;
uint8_t block[64];
} mdfour_t;

Expand Down
4 changes: 4 additions & 0 deletions inc/common/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,8 @@ void Com_PageInMemory(void *buffer, size_t size);

color_index_t Com_ParseColor(const char *s);

#if USE_DEBUG
char *Com_MakePrintable(const char *s);
#endif

#endif // UTILS_H
1 change: 1 addition & 0 deletions inc/shared/shared.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ q_noreturn q_printf(2, 3);
#define Com_Printf(...) Com_LPrintf(PRINT_ALL, __VA_ARGS__)
#define Com_WPrintf(...) Com_LPrintf(PRINT_WARNING, __VA_ARGS__)
#define Com_EPrintf(...) Com_LPrintf(PRINT_ERROR, __VA_ARGS__)
#define Com_NPrintf(...) Com_LPrintf(PRINT_NOTICE, __VA_ARGS__)

#define Q_assert(expr) \
do { if (!(expr)) Com_Error(ERR_FATAL, "%s: assertion `%s' failed", __func__, #expr); } while (0)
Expand Down
4 changes: 2 additions & 2 deletions src/client/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1234,7 +1234,7 @@ static void CL_ConnectionlessPacket(void)

c = Cmd_Argv(0);

Com_DPrintf("%s: %s\n", NET_AdrToString(&net_from), string);
Com_DPrintf("%s: %s\n", NET_AdrToString(&net_from), Com_MakePrintable(string));

// challenge from the server we are connecting to
if (!strcmp(c, "challenge")) {
Expand Down Expand Up @@ -2541,7 +2541,7 @@ static void exec_server_string(cmdbuf_t *buf, const char *text)
return; // no tokens
}

Com_DPrintf("stufftext: %s\n", text);
Com_DPrintf("stufftext: %s\n", Com_MakePrintable(text));

s = Cmd_Argv(0);

Expand Down
10 changes: 5 additions & 5 deletions src/client/parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ static void CL_ParseConfigstring(int index)
maxlen = CS_SIZE(index);
len = MSG_ReadString(s, maxlen);

SHOWNET(2, " %d \"%s\"\n", index, s);
SHOWNET(2, " %d \"%s\"\n", index, Com_MakePrintable(s));

if (len >= maxlen) {
Com_WPrintf(
Expand Down Expand Up @@ -928,7 +928,7 @@ static void CL_ParsePrint(void)
level = MSG_ReadByte();
MSG_ReadString(s, sizeof(s));

SHOWNET(2, " %i \"%s\"\n", level, s);
SHOWNET(2, " %i \"%s\"\n", level, Com_MakePrintable(s));

if (level != PRINT_CHAT) {
Com_Printf("%s", s);
Expand Down Expand Up @@ -986,7 +986,7 @@ static void CL_ParseCenterPrint(void)
char s[MAX_STRING_CHARS];

MSG_ReadString(s, sizeof(s));
SHOWNET(2, " \"%s\"\n", s);
SHOWNET(2, " \"%s\"\n", Com_MakePrintable(s));
SCR_CenterPrint(s);

if (!cls.demo.playback && cl.serverstate != ss_broadcast) {
Expand All @@ -1000,14 +1000,14 @@ static void CL_ParseStuffText(void)
char s[MAX_STRING_CHARS];

MSG_ReadString(s, sizeof(s));
SHOWNET(2, " \"%s\"\n", s);
SHOWNET(2, " \"%s\"\n", Com_MakePrintable(s));
Cbuf_AddText(&cl_cmdbuf, s);
}

static void CL_ParseLayout(void)
{
MSG_ReadString(cl.layout, sizeof(cl.layout));
SHOWNET(2, " \"%s\"\n", cl.layout);
SHOWNET(2, " \"%s\"\n", Com_MakePrintable(cl.layout));
}

static void CL_ParseInventory(void)
Expand Down
2 changes: 1 addition & 1 deletion src/common/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -977,7 +977,7 @@ void Qcommon_Init(int argc, char **argv)

// Print the engine version early so that it's definitely included in the console log.
// The log file is opened during the execution of one of the config files above.
Com_LPrintf(PRINT_NOTICE, "\nEngine version: " APPLICATION " " LONG_VERSION_STRING ", built on " __DATE__ "\n\n");
Com_NPrintf("\nEngine version: " APPLICATION " " LONG_VERSION_STRING ", built on " __DATE__ "\n\n");
Com_DPrintf("Compiled features: %s\n", Com_GetFeatures());

Netchan_Init();
Expand Down
19 changes: 7 additions & 12 deletions src/common/mdfour.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,6 @@ static void copy64(uint32_t *M, const uint8_t *in)
M[i] = RL32(in);
}

static void copy4(uint8_t *out, uint32_t x)
{
WL32(out, x);
}

void mdfour_begin(struct mdfour *md)
{
md->A = 0x67452301;
Expand All @@ -97,19 +92,19 @@ static void mdfour_tail(struct mdfour *md)
{
uint8_t buf[128];
uint32_t M[16];
uint32_t b = md->count * 8;
uint64_t b = md->count * 8;
uint32_t n = md->count & 63;

memset(buf, 0, 128);
memcpy(buf, md->block, n);
buf[n] = 0x80;

if (n <= 55) {
copy4(buf + 56, b);
WL64(buf + 56, b);
copy64(M, buf);
mdfour64(md, M);
} else {
copy4(buf + 120, b);
WL64(buf + 120, b);
copy64(M, buf);
mdfour64(md, M);
copy64(M, buf + 64);
Expand Down Expand Up @@ -152,10 +147,10 @@ void mdfour_result(struct mdfour *md, uint8_t *out)
{
mdfour_tail(md);

copy4(out, md->A);
copy4(out + 4, md->B);
copy4(out + 8, md->C);
copy4(out + 12, md->D);
WL32(out, md->A);
WL32(out + 4, md->B);
WL32(out + 8, md->C);
WL32(out + 12, md->D);
}

uint32_t Com_BlockChecksum(const void *buffer, size_t len)
Expand Down
40 changes: 40 additions & 0 deletions src/common/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -517,4 +517,44 @@ size_t Com_FormatSizeLong(char *dest, size_t destsize, int64_t bytes)
return Q_scnprintf(dest, destsize, "unknown size");
}

#if USE_DEBUG

static int get_escape_char(int c)
{
switch (c) {
case '\a': return 'a';
case '\b': return 'b';
case '\t': return 't';
case '\n': return 'n';
case '\v': return 'v';
case '\f': return 'f';
case '\r': return 'r';
case '\\': return '\\';
case '"': return '"';
}
return 0;
}

char *Com_MakePrintable(const char *s)
{
static char buffer[4096];
char *o = buffer;
char *end = buffer + sizeof(buffer);

while (*s && o < end - 1) {
int c = *s++;
int e = get_escape_char(c);

if (e)
o += Q_scnprintf(o, end - o, "\\%c", e);
else if (!Q_isprint(c))
o += Q_scnprintf(o, end - o, "\\x%02X", c);
else
*o++ = c;
}

*o = 0;
return buffer;
}

#endif
8 changes: 4 additions & 4 deletions src/server/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1241,11 +1241,11 @@ static void SVC_RemoteCommand(void)
}

if (type == RCON_LIMITED) {
Com_Printf("Limited rcon from %s:\n%s\n",
NET_AdrToString(&net_from), s);
Com_NPrintf("Limited rcon from %s:\n%s\n",
NET_AdrToString(&net_from), s);
} else {
Com_Printf("Rcon from %s:\n%s\n",
NET_AdrToString(&net_from), s);
Com_NPrintf("Rcon from %s:\n%s\n",
NET_AdrToString(&net_from), s);
}

SV_PacketRedirect();
Expand Down
4 changes: 2 additions & 2 deletions src/server/mvd.c
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ static void dummy_add_message(client_t *client, byte *data,

data[length] = 0;
text = (char *)(data + 1);
Com_DPrintf("dummy stufftext: %s\n", text);
Com_DPrintf("dummy stufftext: %s\n", Com_MakePrintable(text));
Cbuf_AddText(&dummy_buffer, text);
}

Expand Down Expand Up @@ -1614,7 +1614,7 @@ static void parse_stringcmd(gtv_client_t *client)
Cmd_TokenizeString(string, false);

Com_DPrintf("dummy stringcmd from %s[%s]: %s\n", client->name,
NET_AdrToString(&client->stream.address), string);
NET_AdrToString(&client->stream.address), Com_MakePrintable(string));
dummy_command();
}

Expand Down
4 changes: 2 additions & 2 deletions src/server/user.c
Original file line number Diff line number Diff line change
Expand Up @@ -1339,7 +1339,7 @@ static void SV_ParseFullUserinfo(void)
}

Com_DDPrintf("%s(%s): %s [%d]\n", __func__,
sv_client->name, sv_client->userinfo, userinfoUpdateCount);
sv_client->name, Com_MakePrintable(sv_client->userinfo), userinfoUpdateCount);

SV_UpdateUserinfo();
userinfoUpdateCount++;
Expand Down Expand Up @@ -1475,7 +1475,7 @@ static void SV_ParseClientCommand(void)
return;
}

Com_DDPrintf("%s(%s): %s\n", __func__, sv_client->name, buffer);
Com_DDPrintf("%s(%s): %s\n", __func__, sv_client->name, Com_MakePrintable(buffer));

SV_ExecuteUserCommand(buffer);
stringCmdCount++;
Expand Down
16 changes: 2 additions & 14 deletions src/shared/shared.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,24 +66,12 @@ vec_t VectorNormalize(vec3_t v)
}

return length;

}

vec_t VectorNormalize2(const vec3_t v, vec3_t out)
{
float length, ilength;

length = VectorLength(v);

if (length) {
ilength = 1 / length;
out[0] = v[0] * ilength;
out[1] = v[1] * ilength;
out[2] = v[2] * ilength;
}

return length;

VectorCopy(v, out);
return VectorNormalize(out);
}

void ClearBounds(vec3_t mins, vec3_t maxs)
Expand Down

0 comments on commit e82ba8c

Please sign in to comment.