From c64c67a1de2eb75a4c3417a6c19a946726e13e7c Mon Sep 17 00:00:00 2001 From: Jakob MG Date: Tue, 21 Feb 2012 03:45:42 +0100 Subject: [PATCH] un-ignorable sv_notices system. set sv_notice important info 1| imprtant info 2 in your server to have those messagess unconditionally printed to clients for sv_notices_time on connect --- defaultXonotic.cfg | 3 ++ qcsrc/client/Main.qc | 4 ++ qcsrc/client/View.qc | 6 ++- qcsrc/client/progs.src | 3 +- qcsrc/common/constants.qh | 1 + qcsrc/common/net_notice.qc | 93 ++++++++++++++++++++++++++++++++++++++ qcsrc/common/net_notice.qh | 12 +++++ qcsrc/server/cl_client.qc | 13 ++++++ qcsrc/server/progs.src | 3 ++ 9 files changed, 135 insertions(+), 3 deletions(-) create mode 100644 qcsrc/common/net_notice.qc create mode 100644 qcsrc/common/net_notice.qh diff --git a/defaultXonotic.cfg b/defaultXonotic.cfg index 27ec131f7e..d9db20f19c 100644 --- a/defaultXonotic.cfg +++ b/defaultXonotic.cfg @@ -1926,3 +1926,6 @@ if_dedicated set g_start_delay 15 "delay before the game starts, so everyone can // enable menu syncing alias menu_sync "menu_cmd sync" + +set sv_join_notices "" +set sv_join_notices_time 15 \ No newline at end of file diff --git a/qcsrc/client/Main.qc b/qcsrc/client/Main.qc index aad3e1dc04..12343e6a24 100644 --- a/qcsrc/client/Main.qc +++ b/qcsrc/client/Main.qc @@ -1167,6 +1167,10 @@ float CSQC_Parse_TempEntity() Net_VehicleSetup(); bHandled = true; break; + case TE_CSQC_SVNOTICE: + cl_notice_read(); + 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/client/View.qc b/qcsrc/client/View.qc index c23c2c78fd..a08117616d 100644 --- a/qcsrc/client/View.qc +++ b/qcsrc/client/View.qc @@ -374,6 +374,7 @@ float checkfail[16]; #define BUTTON_3 4 #define BUTTON_4 8 +float cl_notice_run(); void CSQC_UpdateView(float w, float h) { entity e; @@ -1394,7 +1395,7 @@ void CSQC_UpdateView(float w, float h) wcross_color = stov(autocvar_crosshair_dot_color); CROSSHAIR_DRAW(wcross_resolution * autocvar_crosshair_dot_size, "gfx/crosshairdot.tga", f * autocvar_crosshair_dot_alpha); - // FIXME why don't we use wcross_alpha here? + // FIXME why don't we use wcross_alpha here?cl_notice_run(); wcross_color = wcross_color_old; } } @@ -1468,6 +1469,9 @@ void CSQC_UpdateView(float w, float h) else if(hud == HUD_BUMBLEBEE) CSQC_BUMBLE_HUD(); } + + cl_notice_run(); + // let's reset the view back to normal for the end setproperty(VF_MIN, '0 0 0'); setproperty(VF_SIZE, '1 0 0' * w + '0 1 0' * h); diff --git a/qcsrc/client/progs.src b/qcsrc/client/progs.src index 8756fe9447..d3a3a07d81 100644 --- a/qcsrc/client/progs.src +++ b/qcsrc/client/progs.src @@ -23,7 +23,6 @@ Defs.qc ../common/command/generic.qh ../common/command/shared_defs.qh ../common/urllib.qh - command/cl_cmd.qh autocvars.qh @@ -61,6 +60,7 @@ hud.qc scoreboard.qc mapvoting.qc csqcmodel_hooks.qc +../common/net_notice.qc rubble.qc hook.qc @@ -101,7 +101,6 @@ noise.qc ../server/w_all.qc ../common/explosion_equation.qc ../common/urllib.qc - command/cl_cmd.qc ../warpzonelib/anglestransform.qc diff --git a/qcsrc/common/constants.qh b/qcsrc/common/constants.qh index 3e97956901..c40e9fc49a 100644 --- a/qcsrc/common/constants.qh +++ b/qcsrc/common/constants.qh @@ -46,6 +46,7 @@ const float TE_CSQC_NEX_SCOPE = 116; const float TE_CSQC_MINELAYER_MAXMINES = 117; const float TE_CSQC_HAGAR_MAXROCKETS = 118; const float TE_CSQC_VEHICLESETUP = 119; +const float TE_CSQC_SVNOTICE = 120; 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/common/net_notice.qc b/qcsrc/common/net_notice.qc new file mode 100644 index 0000000000..c28649b86f --- /dev/null +++ b/qcsrc/common/net_notice.qc @@ -0,0 +1,93 @@ +#ifdef SVQC + +void sv_notice_to(entity _to, string _notice, float _howlong, float _modal) +{ + msg_entity = _to; + WriteByte(MSG_ONE, SVC_TEMPENTITY); + WriteByte(MSG_ONE, TE_CSQC_SVNOTICE); + WriteString(MSG_ONE, _notice); + WriteLong(MSG_ONE, _howlong); + WriteByte(MSG_ONE, _modal); +} + +void sv_notice_toall(string _notice, float _howlong, float _modal) +{ + entity _head; + FOR_EACH_REALCLIENT(_head) + sv_notice_to(_head, _notice, _howlong, _modal); + +} + +#endif // SVQC + +#ifdef CSQC +void SUB_Remove() +{ remove(self); } + +void cl_notice_read() +{ + entity _notice; + float _done; + float _modal; + _notice = spawn(); + _notice.classname = "sv_notice"; + _notice.netname = strzone(ReadString()); + _notice.alpha = ReadLong() + time; + _notice.skin = ReadByte(); +} + +float cl_notice_run() +{ + entity _notes; + string _notice; + float c, m = FALSE; + + _notes = findchain(classname, "sv_notice"); + if(!_notes) + return FALSE; + #define M1 30 + #define M2 10 + + vector v1, v2, v3; + v1 = '1 1 0' * M1; + v2_x = vid_conwidth - (2 * M1); + v2_y = vid_conheight - (2 * M1); + + drawfill(v1, v2, '0 0 0', 0.5, DRAWFLAG_NORMAL); + v1 = '1 1 0' * (M1 + M2); + v2_x = vid_conwidth - (2 * (M1 + M2)); + v2_y = vid_conheight - (2 * (M1 + M2)); + drawfill(v1, v2, '0.5 0.5 0.5', 0.5, DRAWFLAG_NORMAL); + v3 = v1 + '10 10 0'; + + #define OUT(s,z) drawcolorcodedstring(v3, s, '1 1 0' * z, 1, DRAWFLAG_NORMAL); v3_y += z + 4 + + OUT("^1Server notices:", 32); + + //drawcolorcodedstring(v1 + '5 5 0', "^1Server notices:", '32 32 0', 1, DRAWFLAG_NORMAL); + while(_notes) + { + + _notice = sprintf("^7%s (^3%d sec left)", _notes.netname , rint(_notes.alpha - time)); + OUT(_notice, 16); + + if(_notes.skin) + m = TRUE; + + if(_notes.alpha <= time) + { + _notes.think = SUB_Remove; + _notes.nextthink = time; + } + + _notes = _notes.chain; + } + + #undef OUT + #undef M1 + #undef M2 + + return m; +} + +#endif // CSQC diff --git a/qcsrc/common/net_notice.qh b/qcsrc/common/net_notice.qh new file mode 100644 index 0000000000..f7ba8f00ae --- /dev/null +++ b/qcsrc/common/net_notice.qh @@ -0,0 +1,12 @@ +#ifdef CSQC +void cl_notice_read(); +void sv_notice_to(entity _to, string _notice, float _howlong, float _modal); +#endif + +#ifdef SVQC +string autocvar_sv_join_notices; +float autocvar_sv_join_notices_time; + +void sv_notice_to(entity _to, string _notice, float _howlong, float _modal); +void sv_notice_toall(string _notice, float _howlong, float _modal); +#endif diff --git a/qcsrc/server/cl_client.qc b/qcsrc/server/cl_client.qc index 6f7cda2b8c..5fc0859139 100644 --- a/qcsrc/server/cl_client.qc +++ b/qcsrc/server/cl_client.qc @@ -645,6 +645,7 @@ Called when a client spawns in the server ============= */ //void() ctf_playerchanged; + void PutClientInServer (void) { if(clienttype(self) == CLIENTTYPE_BOT) @@ -927,6 +928,18 @@ void PutClientInServer (void) } else if(self.classname == "observer" || (g_ca && !allowed_to_spawn)) { PutObserverInServer (); } + + // to-do: make sv_join_notices support per-entry times + if(!autocvar_sv_join_notices || autocvar_sv_join_notices == "") + return; + + float argc = tokenizebyseparator(autocvar_sv_join_notices, "|"); + if(argc > 0) + { + float i; + for(i = argc - 1; i >= 0; --i) + sv_notice_to(self, argv(i), autocvar_sv_join_notices_time, FALSE); + } //if(g_ctf) // ctf_playerchanged(); diff --git a/qcsrc/server/progs.src b/qcsrc/server/progs.src index 9a459c5fd4..4ce318377e 100644 --- a/qcsrc/server/progs.src +++ b/qcsrc/server/progs.src @@ -21,6 +21,7 @@ sys-post.qh ../common/command/rpn.qh ../common/command/generic.qh ../common/command/shared_defs.qh +../common/net_notice.qh autocvars.qh constants.qh @@ -152,6 +153,8 @@ campaign.qc ../common/command/markup.qc ../common/command/rpn.qc ../common/command/generic.qc +../common/net_notice.qc + command/common.qc command/banning.qc command/radarmap.qc -- 2.39.2