From b6a81d33f198580385e7f4f3bed27e751612cc98 Mon Sep 17 00:00:00 2001 From: terencehill Date: Mon, 9 Sep 2013 18:50:46 +0200 Subject: [PATCH] Add support for networking a temporary low quality server banner via WritePicture/ReadPicture, only if the client lacks it --- commands.cfg | 1 + qcsrc/client/Main.qc | 37 ++++++++++++++++++++++++++++++------- qcsrc/common/constants.qh | 1 + qcsrc/server/cl_client.qc | 13 +++++++++++-- qcsrc/server/command/cmd.qc | 22 ++++++++++++++++++++++ 5 files changed, 65 insertions(+), 9 deletions(-) diff --git a/commands.cfg b/commands.cfg index dca2334bc..58f216aa8 100644 --- a/commands.cfg +++ b/commands.cfg @@ -146,6 +146,7 @@ seta cl_autoswitch 1 "automatically switch to newly picked up weapons if they ar alias autoswitch "qc_cmd_cmd autoswitch ${* ?}" // Whether or not to switch automatically when getting a better weapon alias checkfail "qc_cmd_cmd checkfail ${* ?}" // Report if a client-side check failed alias clientversion "qc_cmd_cmd clientversion ${* ?}" // Release version of the game +//alias getserverpic "qc_cmd_cmd getserverpic ${* ?}" // Retrieve server banner from the server //alias mv_getpicture "qc_cmd_cmd mv_getpicture ${* ?}" // Retrieve mapshot picture from the server alias join "qc_cmd_cmd join ${* ?}" // Become a player in the game alias ready "qc_cmd_cmd ready ${* ?}" // Qualify as ready to end warmup stage (or restart server if allowed) diff --git a/qcsrc/client/Main.qc b/qcsrc/client/Main.qc index 97afd1433..edc1a6fb0 100644 --- a/qcsrc/client/Main.qc +++ b/qcsrc/client/Main.qc @@ -1193,14 +1193,33 @@ void Net_ReadServerInfo() if(welcomedialog_args) strunzone(welcomedialog_args); welcomedialog_args = strcat("name \"", ReadString(), "\""); - welcomedialog_args = strcat(welcomedialog_args, "ip \"", ReadString(), "\""); - welcomedialog_args = strcat(welcomedialog_args, "motd \"", MakeConsoleSafe(strreplace("\n", "\\n", ReadString())), "\""); + welcomedialog_args = strcat(welcomedialog_args, " ip \"", ReadString(), "\""); + welcomedialog_args = strcat(welcomedialog_args, " motd \"", MakeConsoleSafe(strreplace("\n", "\\n", ReadString())), "\""); string pic = ReadString(); - if(pic != "") - welcomedialog_args = strcat(welcomedialog_args, "pic \"", pic, "\""); - localcmd("\nmenu_cmd directmenu Welcome ", welcomedialog_args, "\n"); - welcomedialog_args = string_null; - return; + if(pic == "" || PreviewExists(pic) ) + { + if(pic != "") + welcomedialog_args = strcat(welcomedialog_args, " pic \"", pic, "\""); + localcmd("\nmenu_cmd directmenu Welcome ", welcomedialog_args, "\n"); + welcomedialog_args = string_null; + return; + } else { + welcomedialog_args = strzone(welcomedialog_args); + print(_("Requesting server banner...\n")); + localcmd("\ncmd getserverpic\n"); + } +} + +void Net_ReadServerInfo_Pic() +{ + if(welcomedialog_args) + { + localcmd("\nmenu_cmd directmenu Welcome ", strcat(welcomedialog_args, " pic \"", ReadPicture(), "\""), "\n"); + strunzone(welcomedialog_args); + welcomedialog_args = string_null; + } + else // just get the image, we don't want to display the welcome dialog + ReadPicture(); } // CSQC_Parse_TempEntity : Handles all temporary entity network data in the CSQC layer. @@ -1268,6 +1287,10 @@ float CSQC_Parse_TempEntity() Net_ReadServerInfo(); bHandled = true; break; + case TE_CSQC_SERVERINFO_PIC: + Net_ReadServerInfo_Pic(); + bHandled = true; + break; default: // No special logic for this temporary entity; return 0 so the engine can handle it bHandled = false; diff --git a/qcsrc/common/constants.qh b/qcsrc/common/constants.qh index 8e2f9544a..e769ad88a 100644 --- a/qcsrc/common/constants.qh +++ b/qcsrc/common/constants.qh @@ -43,6 +43,7 @@ const float TE_CSQC_HAGAR_MAXROCKETS = 111; const float TE_CSQC_VEHICLESETUP = 112; const float TE_CSQC_SVNOTICE = 113; const float TE_CSQC_SERVERINFO = 114; +const float TE_CSQC_SERVERINFO_PIC = 115; const float RACE_NET_CHECKPOINT_HIT_QUALIFYING = 0; // byte checkpoint, short time, short recordtime, string recordholder const float RACE_NET_CHECKPOINT_CLEAR = 1; diff --git a/qcsrc/server/cl_client.qc b/qcsrc/server/cl_client.qc index 6ce80df78..83ca126fe 100644 --- a/qcsrc/server/cl_client.qc +++ b/qcsrc/server/cl_client.qc @@ -726,7 +726,7 @@ void DecodeLevelParms (void) self.parm_idlesince = max(self.parm_idlesince, time - sv_maxidle + 60); } -void MOTD_send() +void serverinfo_welcomemessage_send() { msg_entity = self; WriteByte(MSG_ONE, SVC_TEMPENTITY); @@ -734,6 +734,15 @@ void MOTD_send() WriteString(MSG_ONE, "128.03.192.999"); // FIXME: send the real server ip WriteString(MSG_ONE, autocvar_hostname); WriteString(MSG_ONE, getwelcomemessage()); + WriteString(MSG_ONE, strcat("128.03.192.999", "/banner")); +} + +void serverinfo_pic_send() +{ + msg_entity = self; + WriteByte(MSG_ONE, SVC_TEMPENTITY); + WriteByte(MSG_ONE, TE_CSQC_SERVERINFO_PIC); + WritePicture(MSG_ONE, strcat("128.03.192.999", "/banner"), 3072); } /* @@ -1236,7 +1245,7 @@ void ClientConnect (void) if(IS_REAL_CLIENT(self)) { - MOTD_send(); + serverinfo_welcomemessage_send(); sv_notice_join(); } diff --git a/qcsrc/server/command/cmd.qc b/qcsrc/server/command/cmd.qc index ec9c33b19..facdaa22c 100644 --- a/qcsrc/server/command/cmd.qc +++ b/qcsrc/server/command/cmd.qc @@ -116,6 +116,26 @@ void ClientCommand_clientversion(float request, float argc) // internal command, } } +void ClientCommand_getserverpic(float request) // internal command, used only by code +{ + switch(request) + { + case CMD_REQUEST_COMMAND: + { + serverinfo_pic_send(); + return; + } + + default: + case CMD_REQUEST_USAGE: + { + sprint(self, "\nUsage:^3 cmd getserverpic\n"); + sprint(self, " No arguments required.\n"); + return; + } + } +} + void ClientCommand_mv_getpicture(float request, float argc) // internal command, used only by code { switch(request) @@ -563,6 +583,7 @@ void ClientCommand_(float request) CLIENT_COMMAND("checkfail", ClientCommand_checkfail(request, command), "Report if a client-side check failed") \ CLIENT_COMMAND("clientversion", ClientCommand_clientversion(request, arguments), "Release version of the game") \ CLIENT_COMMAND("mv_getpicture", ClientCommand_mv_getpicture(request, arguments), "Retrieve mapshot picture from the server") \ + CLIENT_COMMAND("getserverpic", ClientCommand_getserverpic(request), "Retrieve server banner from the server") \ CLIENT_COMMAND("join", ClientCommand_join(request), "Become a player in the game") \ CLIENT_COMMAND("ready", ClientCommand_ready(request), "Qualify as ready to end warmup stage (or restart server if allowed)") \ CLIENT_COMMAND("say", ClientCommand_say(request, arguments, command), "Print a message to chat to all players") \ @@ -649,6 +670,7 @@ void SV_ParseClientCommand(string command) // exempt commands which are not subject to floodcheck case "begin": break; // handled by engine in host_cmd.c case "download": break; // handled by engine in cl_parse.c + case "getserverpic": break; // handled by server in this file case "mv_getpicture": break; // handled by server in this file case "pause": break; // handled by engine in host_cmd.c case "prespawn": break; // handled by engine in host_cmd.c -- 2.39.2