From 30ecbd14534999f9f4cdc07992c2705ce87d0a77 Mon Sep 17 00:00:00 2001 From: Marco Cawthorne Date: Sat, 25 Mar 2023 17:34:26 -0700 Subject: [PATCH] Multiplayer: Load and display a server message of the day if present. --- src/client/init.qc | 3 ++ src/client/progs.src | 1 + src/client/vgui_motd.qc | 65 +++++++++++++++++++++++++++++ src/server/gamerules_multiplayer.qc | 2 + zpak001.pk3dir/fonts/ui.font | 5 +++ 5 files changed, 76 insertions(+) create mode 100644 src/client/vgui_motd.qc create mode 100644 zpak001.pk3dir/fonts/ui.font diff --git a/src/client/init.qc b/src/client/init.qc index 726a638..68d9680 100644 --- a/src/client/init.qc +++ b/src/client/init.qc @@ -28,9 +28,12 @@ ClientGame_Init(float apilevel, string enginename, float engineversion) registercommand("chooseteam"); } +void VGUI_ShowMOTD(); + void ClientGame_InitDone(void) { + VGUI_ShowMOTD(); } void diff --git a/src/client/progs.src b/src/client/progs.src index 1778181..08ca613 100644 --- a/src/client/progs.src +++ b/src/client/progs.src @@ -40,5 +40,6 @@ scoreboard.qc modelevent.qc ../../../src/client/include.src +vgui_motd.qc ../../../src/shared/include.src #endlist diff --git a/src/client/vgui_motd.qc b/src/client/vgui_motd.qc new file mode 100644 index 0000000..c5b2054 --- /dev/null +++ b/src/client/vgui_motd.qc @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2023 Marco Cawthorne + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER + * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING + * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +void +VGUI_ShowMOTD(void) +{ + static int initialized; + static VGUIButton winMotdClose; + static VGUIWindow winMotd; + static VGUILabel winMotdHostname; + static VGUILabel winMotdBody; + + static void VGUI_ShowMOTD_Close(void) + { + winMotd.Hide(); + } + + if (MOTD_GetLineCount() < 1i) + return; + + if (!initialized) { + initialized = TRUE; + winMotd = spawn(VGUIWindow); + winMotd.SetTitle("Message Of The Day"); + winMotd.SetSize('424 312'); + winMotd.SetStyleMask(0); + + winMotdClose = spawn(VGUIButton); + winMotdClose.SetTitle("OK"); + winMotdClose.SetPos([16, 266]); + winMotdClose.SetSize([160, 30]); + winMotdClose.SetFunc(VGUI_ShowMOTD_Close); + + winMotdHostname = spawn(VGUILabel); + winMotdHostname.SetTitle(serverkey("hostname")); + winMotdHostname.SetTextSize(19); + winMotdHostname.SetPos([16, 20]); + + winMotdBody = spawn(VGUILabel); + winMotdBody.SetTitle(MOTD_GetTextBody()); + winMotdBody.SetPos([16, 48]); + winMotdBody.SetSize([392, 210]); + + g_uiDesktop.Add(winMotd); + winMotd.Add(winMotdClose); + winMotd.Add(winMotdHostname); + winMotd.Add(winMotdBody); + } + + winMotd.Show(); + winMotd.SetPos((video_res / 2) - (winMotd.GetSize() / 2)); +} diff --git a/src/server/gamerules_multiplayer.qc b/src/server/gamerules_multiplayer.qc index 2c739e7..f978ac7 100644 --- a/src/server/gamerules_multiplayer.qc +++ b/src/server/gamerules_multiplayer.qc @@ -43,6 +43,8 @@ HLMultiplayerRules::IsTeamplay(void) void HLMultiplayerRules::InitPostEnts(void) { + MOTD_LoadDefault(); + if (IsTeamplay() == true) { int c; diff --git a/zpak001.pk3dir/fonts/ui.font b/zpak001.pk3dir/fonts/ui.font new file mode 100644 index 0000000..5bc364b --- /dev/null +++ b/zpak001.pk3dir/fonts/ui.font @@ -0,0 +1,5 @@ +color "255 200 0" +alpha 255 +rendersize "12 19" +path fonts/nimbus/NimbusSanL-Reg.otf +size 12 \ No newline at end of file