]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/net_notice.qc
Merge branch 'master' into TimePath/csqc_sounds
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / net_notice.qc
1 #include "net_notice.qh"
2
3 REGISTER_NET_TEMP(TE_CSQC_SVNOTICE)
4
5 #ifdef SVQC
6 void sv_notice_join_think()
7 {SELFPARAM();
8     //NextLevel();
9     float argc = tokenizebyseparator(autocvar_sv_join_notices, "|");
10     if(argc > 0)
11     {
12         float i;
13         for(i = argc - 1; i >= 0; --i)
14             sv_notice_to(self.owner, argv(i), autocvar_sv_join_notices_time, false);
15     }
16     remove(self);
17 }
18
19 void sv_notice_join()
20 {SELFPARAM();
21     // to-do: make sv_join_notices support per-entry times
22     if(autocvar_sv_join_notices == "")
23         return;
24
25     entity n = spawn();
26     n.owner = self;
27     n.think = sv_notice_join_think;
28     n.nextthink = time + 1;
29 }
30
31 void sv_notice_to(entity _to, string _notice, float _howlong, float _modal)
32 {
33         msg_entity = _to;
34         WriteHeader(MSG_ONE, TE_CSQC_SVNOTICE);
35         WriteString(MSG_ONE, _notice);
36         WriteLong(MSG_ONE, _howlong);
37         WriteByte(MSG_ONE, _modal);
38 }
39
40 void sv_notice_toall(string _notice, float _howlong, float _modal)
41 {
42     entity _head;
43     FOR_EACH_REALCLIENT(_head)
44         sv_notice_to(_head, _notice, _howlong, _modal);
45
46 }
47
48 #endif // SVQC
49
50 #ifdef CSQC
51 NET_HANDLE(TE_CSQC_SVNOTICE, bool isNew)
52 {
53         cl_notice_read();
54         return true;
55 }
56 void cl_notice_read()
57 {
58     //float _done;
59     //float _modal;
60     entity _notice = new(sv_notice);
61     _notice.netname = strzone(ReadString());
62     _notice.alpha = ReadLong() + time;
63     _notice.skin = ReadByte();
64 }
65
66 float cl_notice_run()
67 {
68     entity _notes;
69     string _notice;
70     float m = false;
71
72     _notes = findchain(classname, "sv_notice");
73     if(!_notes)
74         return false;
75     const int M1 = 30;
76     const int M2 = 10;
77
78     vector v1, v2 = '0 0 0', v3;
79     v1 = '1 1 0' * M1;
80     v2_x = vid_conwidth - (2 * M1);
81     v2_y = vid_conheight - (2 * M1);
82
83     drawfill(v1, v2, '0 0 0', 0.5, DRAWFLAG_NORMAL);
84     v1 = '1 1 0' * (M1 + M2);
85     v2_x = vid_conwidth - (2 * (M1 + M2));
86     v2_y = vid_conheight - (2 * (M1 + M2));
87     drawfill(v1, v2, '0.5 0.5 0.5', 0.5, DRAWFLAG_NORMAL);
88     v3 = v1 + '10 10 0';
89
90     #define OUT(s,z) drawcolorcodedstring(v3, s, '1 1 0' * z, 1, DRAWFLAG_NORMAL); v3_y += z + 4
91
92     OUT(_("^1Server notices:"), 32);
93
94     //drawcolorcodedstring(v1 + '5 5 0', "^1Server notices:", '32 32 0', 1, DRAWFLAG_NORMAL);
95     while(_notes)
96     {
97
98         _notice = sprintf(_("^7%s (^3%d sec left)"), _notes.netname , rint(_notes.alpha - time));
99         OUT(_notice, 16);
100
101         if(_notes.skin)
102             m = true;
103
104         if(_notes.alpha <= time)
105         {
106             _notes.think = SUB_Remove;
107             _notes.nextthink = time;
108         }
109
110         _notes = _notes.chain;
111     }
112
113     #undef OUT
114
115     return m;
116 }
117
118 #endif // CSQC