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