From 3c3e17dd178d5940c7bdbb5a219af4a4d7ede5fe Mon Sep 17 00:00:00 2001 From: terencehill Date: Mon, 19 Aug 2013 22:27:05 +0200 Subject: [PATCH] Add a welcome dialog to the menu that shows up upon connection to the server --- qcsrc/client/Main.qc | 9 +++ qcsrc/common/constants.qh | 1 + qcsrc/menu/classes.c | 1 + qcsrc/menu/command/menu_cmd.qc | 16 +++++- qcsrc/menu/skin-customizables.inc | 1 + qcsrc/menu/xonotic/dialog_welcome.c | 89 +++++++++++++++++++++++++++++ qcsrc/menu/xonotic/mainwindow.c | 8 ++- qcsrc/server/cl_client.qc | 14 +++++ 8 files changed, 134 insertions(+), 5 deletions(-) create mode 100644 qcsrc/menu/xonotic/dialog_welcome.c diff --git a/qcsrc/client/Main.qc b/qcsrc/client/Main.qc index 42fadc0c1..973325c38 100644 --- a/qcsrc/client/Main.qc +++ b/qcsrc/client/Main.qc @@ -1187,6 +1187,11 @@ void Net_WeaponComplain() } } +void Net_ReadServerInfo() +{ + localcmd("\nmenu_cmd directmenu Welcome serverinfo_name \"", ReadString() , "\" serverinfo_ip \"", ReadString(), "\" serverinfo_MOTD \"", ReadString(), "\"\n"); +} + // CSQC_Parse_TempEntity : Handles all temporary entity network data in the CSQC layer. // You must ALWAYS first acquire the temporary ID, which is sent as a byte. // Return value should be 1 if CSQC handled the temporary entity, otherwise return 0 to have the engine process the event. @@ -1248,6 +1253,10 @@ float CSQC_Parse_TempEntity() cl_notice_read(); bHandled = true; break; + case TE_CSQC_SERVERINFO: + Net_ReadServerInfo(); + 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 1a70b341d..7ec36abe1 100644 --- a/qcsrc/common/constants.qh +++ b/qcsrc/common/constants.qh @@ -42,6 +42,7 @@ const float TE_CSQC_MINELAYER_MAXMINES = 110; 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 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/menu/classes.c b/qcsrc/menu/classes.c index f00971674..f1f4905bf 100644 --- a/qcsrc/menu/classes.c +++ b/qcsrc/menu/classes.c @@ -27,6 +27,7 @@ #include "xonotic/commandbutton.c" #include "xonotic/bigcommandbutton.c" #include "xonotic/dialog_firstrun.c" +#include "xonotic/dialog_welcome.c" #include "xonotic/dialog_teamselect.c" #include "xonotic/dialog_sandboxtools.c" #include "xonotic/dialog_settings.c" diff --git a/qcsrc/menu/command/menu_cmd.qc b/qcsrc/menu/command/menu_cmd.qc index 2c0b1edf3..f4d056539 100644 --- a/qcsrc/menu/command/menu_cmd.qc +++ b/qcsrc/menu/command/menu_cmd.qc @@ -53,6 +53,9 @@ void GameCommand(string theCommand) if(argv(0) == "directmenu" || argv(0) == "directpanelhudmenu") { + float i; + entity e; + string s; string filter = string_null; if(argv(0) == "directpanelhudmenu") filter = strzone("HUD"); @@ -60,9 +63,6 @@ void GameCommand(string theCommand) if(argc == 1) { print(_("Available options:\n")); - float i; - entity e; - string s; for(i = 0, e = world; (e = nextent(e)); ) if(e.classname != "vtbl" && e.name != "") @@ -80,6 +80,16 @@ void GameCommand(string theCommand) } else if(argc == 2 && !isdemo()) // don't allow this command in demos m_goto(strcat(filter, argv(1))); // switch to a menu item + else if(argc > 2 && !isdemo()) + { + for(i = 0, e = world; (e = nextent(e)); ) + if(e.classname != "vtbl" && e.name == strcat(filter, argv(1))) + if(e.readInputArgs) + { + e.readInputArgs(e, 2, argc - 1); + m_goto(strcat(filter, argv(1))); + } + } if(filter) strunzone(filter); return; diff --git a/qcsrc/menu/skin-customizables.inc b/qcsrc/menu/skin-customizables.inc index 6b5cac042..9a9f124ba 100644 --- a/qcsrc/menu/skin-customizables.inc +++ b/qcsrc/menu/skin-customizables.inc @@ -69,6 +69,7 @@ SKINBEGIN SKINVECTOR(COLOR_DIALOG_CROSSHAIR, '1 0.7 0.7'); SKINVECTOR(COLOR_DIALOG_HUD, '1 0.7 0.7'); SKINVECTOR(COLOR_DIALOG_SERVERINFO, '0.7 0.7 1'); + SKINVECTOR(COLOR_DIALOG_WELCOME, '1 0.7 0.7'); SKINVECTOR(COLOR_DIALOG_CVARS, '1 0 0'); SKINVECTOR(COLOR_DIALOG_HUDCONFIRM, '1 0 0'); diff --git a/qcsrc/menu/xonotic/dialog_welcome.c b/qcsrc/menu/xonotic/dialog_welcome.c new file mode 100644 index 000000000..837797831 --- /dev/null +++ b/qcsrc/menu/xonotic/dialog_welcome.c @@ -0,0 +1,89 @@ +#ifdef INTERFACE +CLASS(XonoticWelcomeDialog) EXTENDS(XonoticRootDialog) + METHOD(XonoticWelcomeDialog, fill, void(entity)) + ATTRIB(XonoticWelcomeDialog, title, string, _("Welcome")) + ATTRIB(XonoticWelcomeDialog, color, vector, SKINCOLOR_DIALOG_WELCOME) + ATTRIB(XonoticWelcomeDialog, intendedWidth, float, 0.7) + ATTRIB(XonoticWelcomeDialog, rows, float, 16) + ATTRIB(XonoticWelcomeDialog, columns, float, 4) + ATTRIB(XonoticWelcomeDialog, name, string, "Welcome") + + METHOD(XonoticWelcomeDialog, configureDialog, void(entity)) + METHOD(XonoticWelcomeDialog, readInputArgs, void(entity, float, float)) + ATTRIB(XonoticWelcomeDialog, serverinfo_name, string, string_null) + ATTRIB(XonoticWelcomeDialog, serverinfo_name_ent, entity, world) + ATTRIB(XonoticWelcomeDialog, serverinfo_ip, string, string_null) + ATTRIB(XonoticWelcomeDialog, serverinfo_ip_ent, entity, world) + ATTRIB(XonoticWelcomeDialog, serverinfo_MOTD, string, string_null) + ATTRIB(XonoticWelcomeDialog, serverinfo_MOTD_ent, entity, world) +ENDCLASS(XonoticWelcomeDialog) +#endif + +#ifdef IMPLEMENTATION +void welcomeDialog_resetStrings(entity me) +{ + if(me.serverinfo_name) + strunzone(me.serverinfo_name); + me.serverinfo_name = strzone(_("")); + + if(me.serverinfo_ip) + strunzone(me.serverinfo_ip); + me.serverinfo_ip = strzone(_("")); + + if(me.serverinfo_MOTD) + strunzone(me.serverinfo_MOTD); + me.serverinfo_MOTD = strzone(_("")); +} +void XonoticWelcomeDialog_configureDialog(entity me) +{ + welcomeDialog_resetStrings(me); + SUPER(XonoticWelcomeDialog).configureDialog(me); +} +void XonoticWelcomeDialog_readInputArgs(entity me, float starting_arg, float arg_count) +{ + float i; + welcomeDialog_resetStrings(me); + for(i = starting_arg; i < arg_count; ++i) + { + if(argv(i) == "serverinfo_name") + { + if(me.serverinfo_name) + strunzone(me.serverinfo_name); + me.serverinfo_name = strzone(argv(i + 1)); + me.serverinfo_name_ent.setText(me.serverinfo_name_ent, me.serverinfo_name); + ++i; + } + else if(argv(i) == "serverinfo_ip") + { + if(me.serverinfo_ip) + strunzone(me.serverinfo_ip); + me.serverinfo_ip = strzone(argv(i + 1)); + me.serverinfo_ip_ent.setText(me.serverinfo_ip_ent, me.serverinfo_ip); + ++i; + } + else if(argv(i) == "serverinfo_MOTD") + { + if(me.serverinfo_MOTD) + strunzone(me.serverinfo_MOTD); + me.serverinfo_MOTD = strzone(argv(i + 1)); + me.serverinfo_MOTD_ent.setText(me.serverinfo_MOTD_ent, me.serverinfo_MOTD); + ++i; + } + } +} + +void XonoticWelcomeDialog_fill(entity me) +{ + entity e; + + me.TR(me); + me.TD(me, 1, 4, me.serverinfo_name_ent = makeXonoticTextLabel(0.5, "")); + me.TR(me); + me.TD(me, 1, 4, me.serverinfo_ip_ent = makeXonoticTextLabel(0.5, "")); + me.TR(me); + me.TR(me); + me.TD(me, 1, 4, e = makeXonoticTextLabel(0.5, _("MOTD"))); + me.TR(me); + me.TD(me, 1, 4, me.serverinfo_MOTD_ent = makeXonoticTextLabel(0.5, "")); +} +#endif diff --git a/qcsrc/menu/xonotic/mainwindow.c b/qcsrc/menu/xonotic/mainwindow.c index f9d86c2dd..5dc781e72 100644 --- a/qcsrc/menu/xonotic/mainwindow.c +++ b/qcsrc/menu/xonotic/mainwindow.c @@ -198,8 +198,12 @@ void MainWindow_configureMainWindow(entity me) i = spawnXonoticTeamSelectDialog(); i.configureDialog(i); me.addItemCentered(me, i, i.intendedWidth * eX + i.intendedHeight * eY, SKINALPHAS_MAINMENU_z); - - + + i = spawnXonoticWelcomeDialog(); + i.configureDialog(i); + me.addItemCentered(me, i, i.intendedWidth * eX + i.intendedHeight * eY, SKINALPHAS_MAINMENU_z); + + // main dialogs/windows me.mainNexposee = n = spawnXonoticNexposee(); /* diff --git a/qcsrc/server/cl_client.qc b/qcsrc/server/cl_client.qc index d7ca62ba0..3e897f343 100644 --- a/qcsrc/server/cl_client.qc +++ b/qcsrc/server/cl_client.qc @@ -726,6 +726,17 @@ void DecodeLevelParms (void) self.parm_idlesince = max(self.parm_idlesince, time - sv_maxidle + 60); } +void MOTD_send() +{ + msg_entity = self; + WriteByte(MSG_ONE, SVC_TEMPENTITY); + WriteByte(MSG_ONE, TE_CSQC_SERVERINFO); + 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, "Welcome to this server. Have fun!"); +} + /* ============= ClientKill @@ -1225,7 +1236,10 @@ void ClientConnect (void) self.model_randomizer = random(); if(IS_REAL_CLIENT(self)) + { + MOTD_send(); sv_notice_join(); + } MUTATOR_CALLHOOK(ClientConnect); } -- 2.39.2