From d693bc27ff46ee9ed3d75bb2e2fd19a78c4bb0dc Mon Sep 17 00:00:00 2001 From: Adam Olsen Date: Mon, 5 Nov 2001 07:53:03 +0000 Subject: [PATCH] - merge the svc_strings arrays for cl_parse.c and net_packetlog.c into net_svc.c, and add add a NET_SVC_GetString function to access it. As an added bonus, it actually boundschecks it! - preexpand that annoying SHOWNET macro, which was only used twice, and was quite small and pointless - whitespace cleanup and a comment typo fix --- qw/include/net_svc.h | 1 + qw/include/protocol.h | 2 +- qw/source/cl_parse.c | 89 +++------------------------------------ qw/source/net_packetlog.c | 86 +++---------------------------------- qw/source/net_svc.c | 71 +++++++++++++++++++++++++++++++ 5 files changed, 85 insertions(+), 164 deletions(-) diff --git a/qw/include/net_svc.h b/qw/include/net_svc.h index aade83023..9f6c26667 100644 --- a/qw/include/net_svc.h +++ b/qw/include/net_svc.h @@ -199,6 +199,7 @@ typedef struct net_svc_deltapacketentities_s entity_state_t deltas[MAX_PACKET_ENTITIES]; } net_svc_deltapacketentities_t; +const char *NET_SVC_GetString (int type); net_status_t NET_SVC_Print_Emit (net_svc_print_t *block, sizebuf_t *buf); net_status_t NET_SVC_Print_Parse (net_svc_print_t *block, msg_t *msg); net_status_t NET_SVC_Damage_Emit (net_svc_damage_t *block, sizebuf_t *buf); diff --git a/qw/include/protocol.h b/qw/include/protocol.h index 298131568..665fdb71e 100644 --- a/qw/include/protocol.h +++ b/qw/include/protocol.h @@ -224,7 +224,7 @@ U_GLOWSIZE | U_GLOWCOLOR | U_COLORMOD | \ U_EXTEND2) #define U_GROUP_EXTEND2 (U_GLOWTRAIL | U_VIEWMODEL | U_FRAME2) -// I skip the UNISED and EXTEND3 bits because although they exist in +// I skip the UNUSED and EXTEND3 bits because although they exist in // QSG2, they're not usable #define U_VERSION_ID ((U_GROUP_ORIG | U_GROUP_MOREBITS) & ~U_EXTEND1) diff --git a/qw/source/cl_parse.c b/qw/source/cl_parse.c index d5c289ac4..4925d0ab0 100644 --- a/qw/source/cl_parse.c +++ b/qw/source/cl_parse.c @@ -72,85 +72,6 @@ static const char rcsid[] = #include "sbar.h" #include "view.h" -char *svc_strings[] = { - "svc_bad", - "svc_nop", - "svc_disconnect", - "svc_updatestat", - "svc_version", // [long] server version - "svc_setview", // [short] entity number - "svc_sound", // - "svc_time", // [float] server time - "svc_print", // [string] null terminated string - "svc_stufftext", // [string] stuffed into client's console - // buffer the string should be \n terminated - "svc_setangle", // [vec3] set view angle to this absolute value - - "svc_serverdata", // [long] version ... - "svc_lightstyle", // [byte] [string] - "svc_updatename", // [byte] [string] - "svc_updatefrags", // [byte] [short] - "svc_clientdata", // - "svc_stopsound", // - "svc_updatecolors", // [byte] [byte] - "svc_particle", // [vec3] - "svc_damage", // [byte] impact [byte] blood [vec3] from - - "svc_spawnstatic", - "OBSOLETE svc_spawnbinary", - "svc_spawnbaseline", - - "svc_temp_entity", // - "svc_setpause", - "svc_signonnum", - "svc_centerprint", - "svc_killedmonster", - "svc_foundsecret", - "svc_spawnstaticsound", - "svc_intermission", - "svc_finale", - - "svc_cdtrack", - "svc_sellscreen", - - "svc_smallkick", - "svc_bigkick", - - "svc_updateping", - "svc_updateentertime", - - "svc_updatestatlong", - "svc_muzzleflash", - "svc_updateuserinfo", - "svc_download", - "svc_playerinfo", - "svc_nails", - "svc_choke", - "svc_modellist", - "svc_soundlist", - "svc_packetentities", - "svc_deltapacketentities", - "svc_maxspeed", - "svc_entgravity", - - "svc_setinfo", - "svc_serverinfo", - "svc_updatepl", - "NEW PROTOCOL", - "NEW PROTOCOL", - "NEW PROTOCOL", - "NEW PROTOCOL", - "NEW PROTOCOL", - "NEW PROTOCOL", - "NEW PROTOCOL", - "NEW PROTOCOL", - "NEW PROTOCOL", - "NEW PROTOCOL", - "NEW PROTOCOL", - "NEW PROTOCOL", - "NEW PROTOCOL" -}; - int oldparsecountmod; int parsecountmod; double parsecounttime; @@ -1207,13 +1128,15 @@ CL_ParseServerMessage (void) cmd = MSG_ReadByte (net_message); if (cmd == -1) { - net_message->readcount++; // so the EOM showner has the right - // value - SHOWNET ("END OF MESSAGE"); + if (cl_shownet->int_val == 2) + Con_Printf ("%3i:%s\n", net_message->readcount, + "END OF MESSAGE"); break; } - SHOWNET (svc_strings[cmd]); + if (cl_shownet->int_val == 2) + Con_Printf ("%3i:%s\n", net_message->readcount - 1, + NET_SVC_GetString (cmd)); // other commands switch (cmd) { diff --git a/qw/source/net_packetlog.c b/qw/source/net_packetlog.c index b318ee00a..aa83fa73f 100644 --- a/qw/source/net_packetlog.c +++ b/qw/source/net_packetlog.c @@ -1,11 +1,11 @@ /* - net_packetlog.c + net_packetlog.c - packet logging/parsing - for debugging and educational purposes + packet logging/parsing - for debugging and educational purposes - **EXPERIMENTAL** + **EXPERIMENTAL** - Copyright (C) 2000 Jukka Sorjonen + Copyright (C) 2000 Jukka Sorjonen This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -56,6 +56,7 @@ static const char rcsid[] = #include "compat.h" #include "net.h" +#include "net_svc.h" #include "protocol.h" #include "server.h" @@ -70,81 +71,6 @@ void Parse_Server_Packet (void); void Parse_Client_Packet (void); void Net_LogStop (void); -// note: this is SUPPOSED to be duplicate, like many others -const char *svc_string[] = { - "svc_bad", - "svc_nop", - "svc_disconnect", - "svc_updatestat", - "svc_version", // [long] server version - "svc_setview", // [short] entity number - "svc_sound", // - "svc_time", // [float] server time - "svc_print", // [string] null terminated string - "svc_stufftext", // [string] stuffed into client's - // console buffer the string - // should be \n terminated - "svc_setangle", // [vec3] set the view angle to this - // absolute value - "svc_serverdata", // [long] version ... - "svc_lightstyle", // [byte] [string] - "svc_updatename", // [byte] [string] - "svc_updatefrags", // [byte] [short] - "svc_clientdata", // - "svc_stopsound", // - "svc_updatecolors", // [byte] [byte] - "svc_particle", // [vec3] - "svc_damage", // [byte] impact [byte] blood [vec3] - // from - "svc_spawnstatic", - "svc_spawnbinary", - "svc_spawnbaseline", - "svc_temp_entity", // - "svc_setpause", - "svc_signonnum", - "svc_centerprint", - "svc_killedmonster", - "svc_foundsecret", - "svc_spawnstaticsound", - "svc_intermission", - "svc_finale", // [string] music [string] text - "svc_cdtrack", // [byte] track [byte] looptrack - "svc_sellscreen", - "svc_smallkick", // Quake svc_cutscene - "svc_bigkick", - "svc_updateping", - "svc_updateentertime", - "svc_updatestatlong", - "svc_muzzleflash", - "svc_updateuserinfo", - "svc_download", - "svc_playerinfo", - "svc_nails", - "svc_chokecount", - "svc_modellist", - "svc_soundlist", - "svc_packetentities", - "svc_deltapacketentities", - "svc_maxspeed", - "svc_entgravity", - "svc_setinfo", - "svc_serverinfo", - "svc_updatepl", - "NEW PROTOCOL", - "NEW PROTOCOL", - "NEW PROTOCOL", - "NEW PROTOCOL", - "NEW PROTOCOL", - "NEW PROTOCOL", - "NEW PROTOCOL", - "NEW PROTOCOL", - "NEW PROTOCOL", - "NEW PROTOCOL", - "NEW PROTOCOL", - "NEW PROTOCOL", - "NEW PROTOCOL" -}; - const char *clc_string[] = { "clc_bad", "clc_nop", @@ -451,7 +377,7 @@ Parse_Server_Packet () MSG_GetReadCount (&packet) - 1, c); if (c < 53) - Net_LogPrintf ("%s: ", svc_string[c]); + Net_LogPrintf ("%s: ", NET_SVC_GetString (c)); // else Net_LogPrintf("(UNK: %d): ",c); if (MSG_GetReadCount (&packet) > packet.message->cursize) diff --git a/qw/source/net_svc.c b/qw/source/net_svc.c index 2af6327a6..078f60f46 100644 --- a/qw/source/net_svc.c +++ b/qw/source/net_svc.c @@ -51,6 +51,77 @@ static const char rcsid[] = #include "msg_ucmd.h" // FIXME #include "net_svc.h" +static const char *net_svc_strings[] = { + "svc_bad", + "svc_nop", + "svc_disconnect", + "svc_updatestat", + "svc_version", // [long] server version + "svc_setview", // [short] entity number + "svc_sound", // + "svc_time", // [float] server time + "svc_print", // [string] null terminated string + "svc_stufftext", // [string] stuffed into client's + // console buffer the string + // should be \n terminated + "svc_setangle", // [vec3] set the view angle to this + // absolute value + "svc_serverdata", // [long] version ... + "svc_lightstyle", // [byte] [string] + "svc_updatename", // [byte] [string] + "svc_updatefrags", // [byte] [short] + "svc_clientdata", // + "svc_stopsound", // + "svc_updatecolors", // [byte] [byte] + "svc_particle", // [vec3] + "svc_damage", // [byte] impact [byte] blood [vec3] + // from + "svc_spawnstatic", + "svc_spawnbinary", + "svc_spawnbaseline", + "svc_temp_entity", // + "svc_setpause", + "svc_signonnum", + "svc_centerprint", + "svc_killedmonster", + "svc_foundsecret", + "svc_spawnstaticsound", + "svc_intermission", + "svc_finale", // [string] music [string] text + "svc_cdtrack", // [byte] track [byte] looptrack + "svc_sellscreen", + "svc_smallkick", // Quake svc_cutscene + "svc_bigkick", + "svc_updateping", + "svc_updateentertime", + "svc_updatestatlong", + "svc_muzzleflash", + "svc_updateuserinfo", + "svc_download", + "svc_playerinfo", + "svc_nails", + "svc_chokecount", + "svc_modellist", + "svc_soundlist", + "svc_packetentities", + "svc_deltapacketentities", + "svc_maxspeed", + "svc_entgravity", + "svc_setinfo", + "svc_serverinfo", + "svc_updatepl", +}; + +const char * +NET_SVC_GetString (int type) +{ + if (type >= 0 && type < (sizeof (net_svc_strings) / sizeof (const char *))) + return net_svc_strings[type]; + else + return "Invalid Block Type"; +} + + net_status_t NET_SVC_Print_Emit (net_svc_print_t *block, sizebuf_t *buf) {