Xonotic
net_notice.qc
Go to the documentation of this file.
1 #include "net_notice.qh"
2 
3 REGISTER_NET_TEMP(TE_CSQC_SVNOTICE)
4 
5 #ifdef SVQC
6 void sv_notice_join_think(entity this)
7 {
8  int argc = tokenizebyseparator(autocvar_sv_join_notices, "|");
9  if (argc <= 0) return;
10  for (int i = 0; i < argc; ++i)
11  sv_notice_to(this, argv(i), autocvar_sv_join_notices_time, false);
12 }
13 
14 void sv_notice_join(entity _to)
15 {
16  // to-do: make sv_join_notices support per-entry times
17  if (autocvar_sv_join_notices == "") return;
18  defer(_to, 1, sv_notice_join_think);
19 }
20 
21 void sv_notice_to(entity _to, string _notice, float _howlong, float _modal)
22 {
23  msg_entity = _to;
24  WriteHeader(MSG_ONE, TE_CSQC_SVNOTICE);
25  WriteString(MSG_ONE, _notice);
26  WriteLong(MSG_ONE, _howlong);
27  WriteByte(MSG_ONE, _modal);
28 }
29 
30 void sv_notice_toall(string _notice, float _howlong, float _modal)
31 {
32  FOREACH_CLIENT(IS_REAL_CLIENT(it), sv_notice_to(it, _notice, _howlong, _modal));
33 }
34 
35 #endif // SVQC
36 
37 #ifdef CSQC
38 NET_HANDLE(TE_CSQC_SVNOTICE, bool isNew)
39 {
40  cl_notice_read();
41  return true;
42 }
43 entity cl_notices;
44 void cl_notice_read()
45 {
46  entity _notice = new_pure(sv_notice);
47  _notice.netname = strzone(ReadString());
48  _notice.alpha = ReadLong() + time;
49  _notice.skin = ReadByte();
50  if(!cl_notices)
51  cl_notices = LL_NEW();
52  LL_PUSH(cl_notices, _notice);
53 }
54 
55 void cl_notice_run()
56 {
57  if (!cl_notices)
58  return;
59 
60  bool flag = false;
61  LL_EACH(cl_notices, it.alpha > time, { flag = true; break; });
62  if (!flag)
63  {
64  LL_DELETE(cl_notices);
65  return;
66  }
67 
68  const int M1 = 30;
69  const int M2 = 10;
70 
71  vector v1 = '1 1 0' * M1;
72  vector v2 = '0 0 0';
73  v2.x = vid_conwidth - (2 * M1);
74  v2.y = vid_conheight - (2 * M1);
75  drawfill(v1, v2, '0 0 0', 0.5, DRAWFLAG_NORMAL);
76 
77  v1 = '1 1 0' * (M1 + M2);
78  v2.x = vid_conwidth - (2 * (M1 + M2));
79  v2.y = vid_conheight - (2 * (M1 + M2));
80  drawfill(v1, v2, '0.5 0.5 0.5', 0.5, DRAWFLAG_NORMAL);
81 
82  vector v3 = v1 + '10 10 0';
83  #define OUT(s, z) MACRO_BEGIN \
84  drawcolorcodedstring(v3, s, '1 1 0' * z, 1, DRAWFLAG_NORMAL); \
85  v3.y += z + 4; \
86  MACRO_END
87 
88  float cur_time = 0;
89  float time_width = 48;
90  OUT(_("^1Server notices:"), 32);
91  LL_EACH(cl_notices, it.alpha > time, {
92  if(it.alpha - cur_time > 0.1)
93  {
94  cur_time = it.alpha;
95  string s = sprintf("^3%d", ceil(cur_time - time));
96  drawcolorcodedstring(v3 + eX * 0.5 * (time_width - stringwidth(s, true, '1 1 0' * 16)), s, '1 1 0' * 16, 1, DRAWFLAG_NORMAL);
97  v3.x = v1.x + 10 + time_width;
98  }
99  OUT(it.netname, 16);
100  });
101  #undef OUT
102 }
103 
104 #endif // CSQC
float vid_conheight
#define ReadString
#define LL_EACH(list, cond, body)
Definition: linkedlist.qh:73
entity() spawn
#define FOREACH_CLIENT(cond, body)
Definition: utils.qh:49
#define NET_HANDLE(id, param)
Definition: net.qh:12
float vid_conwidth
#define IS_REAL_CLIENT(v)
Definition: utils.qh:17
entity LL_PUSH(LinkedList this, entity e)
Push to tail.
Definition: linkedlist.qh:21
#define LL_DELETE(...)
Definition: linkedlist.qh:63
entity msg_entity
Definition: progsdefs.qc:63
const float DRAWFLAG_NORMAL
Definition: csprogsdefs.qc:317
vector(float skel, float bonenum) _skel_get_boneabs_hidden
#define tokenizebyseparator
Definition: dpextensions.qh:21
#define new_pure(class)
purely logical entities (.origin doesn&#39;t work)
Definition: oo.qh:62
#define REGISTER_NET_TEMP(id)
Definition: net.qh:33
float time
Definition: csprogsdefs.qc:16
#define LL_NEW()
Definition: linkedlist.qh:14