]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/notifications.qc
Merge remote-tracking branch 'origin/master' into samual/notification_rewrite
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / notifications.qc
1 // ================================================
2 //  Unified notification system, written by Samual
3 //  Last updated: February, 2013
4 // ================================================
5
6 entity Get_Notif_Ent(float net_type, float net_name)
7 {
8         switch(net_type)
9         {
10                 case MSG_INFO: return msg_info_notifs[net_name - 1];
11                 case MSG_CENTER: return msg_center_notifs[net_name - 1];
12                 case MSG_WEAPON: return msg_weapon_notifs[net_name - 1];
13                 case MSG_DEATH: return msg_death_notifs[net_name - 1];
14         }
15         backtrace(sprintf("Get_Notif_Ent(%d, %d): Improper net type!\n", net_type, net_name));
16         return world;
17 }
18
19
20 // ===============================
21 //  Frontend Notification Pushing
22 // ===============================
23
24 void Dump_Notifications(float fh, float alsoprint)
25 {
26         #define NOTIF_WRITE(a) { \
27                 fputs(fh, a); \
28                 if(alsoprint) { print(a); } }
29         #define NOTIF_WRITE_SETA(name,default,text) { \
30                 notif_msg = \
31                         sprintf( \
32                                 "seta notification_%s %d \"notif string: %s^7\"\n", \
33                                 name, default, strreplace("\{3}", "", strreplace("\n", "\\n", text)) \
34                         ); \
35                 NOTIF_WRITE(notif_msg) }
36
37         string notif_msg;
38         float i;
39         entity e;
40
41         // Note: This warning only applies to the notifications.cfg file that is output...
42
43         // You ARE supposed to manually edit this function to add i.e. hard coded
44         // notification variables for mutators or game modes or such and then
45         // regenerate the notifications.cfg file from the new code.
46
47         NOTIF_WRITE("// ********************************************** //\n");
48         NOTIF_WRITE("// ** WARNING - DO NOT MANUALLY EDIT THIS FILE ** //\n");
49         NOTIF_WRITE("// **                                          ** //\n");
50         NOTIF_WRITE("// **  This file is automatically generated    ** //\n");
51         NOTIF_WRITE("// **  by code with the command 'dumpnotifs'.  ** //\n");
52         NOTIF_WRITE("// **                                          ** //\n");
53         NOTIF_WRITE("// **  If you add a new notification, please   ** //\n");
54         NOTIF_WRITE("// **  regenerate this file with that command  ** //\n");
55         NOTIF_WRITE("// **  making sure that the output matches     ** //\n");
56         NOTIF_WRITE("// **  with the lists and defaults in code.    ** //\n");
57         NOTIF_WRITE("// **                                          ** //\n");
58         NOTIF_WRITE("// ********************************************** //\n");
59
60         // These notifications will also append their string as a comment...
61         // This is not necessary, and does not matter if they vary between config versions,
62         // it is just a semi-helpful tool for those who want to manually change their user settings.
63
64         NOTIF_WRITE(sprintf("\n// MSG_INFO notifications (count = %d):\n", NOTIF_INFO_COUNT));
65         for(i = 1; i <= NOTIF_INFO_COUNT; ++i)
66         {
67                 e = Get_Notif_Ent(MSG_INFO, i);
68                 if not(e) { backtrace("Dump_Notifications(): Missing notification entity!\n"); return; }
69                 NOTIF_WRITE_SETA(e.nent_name, e.nent_default, e.nent_string);
70         }
71
72         NOTIF_WRITE(sprintf("\n// MSG_CENTER notifications (count = %d):\n", NOTIF_CENTER_COUNT));
73         for(i = 1; i <= NOTIF_CENTER_COUNT; ++i)
74         {
75                 e = Get_Notif_Ent(MSG_CENTER, i);
76                 if not(e) { backtrace("Dump_Notifications(): Missing notification entity!\n"); return; }
77                 NOTIF_WRITE_SETA(e.nent_name, e.nent_default, e.nent_string);
78         }
79
80         NOTIF_WRITE(sprintf("\n// MSG_WEAPON notifications (count = %d):\n", NOTIF_WEAPON_COUNT));
81         for(i = 1; i <= NOTIF_WEAPON_COUNT; ++i)
82         {
83                 e = Get_Notif_Ent(MSG_WEAPON, i);
84                 if not(e) { backtrace("Dump_Notifications(): Missing notification entity!\n"); return; }
85                 NOTIF_WRITE_SETA(e.nent_name, e.nent_default, sprintf("infoname: %s, centername: %s",
86                         e.nent_msginfo.nent_name, e.nent_msgcenter.nent_name));
87         }
88
89         NOTIF_WRITE(sprintf("\n// MSG_DEATH notifications (count = %d):\n", NOTIF_DEATH_COUNT));
90         for(i = 1; i <= NOTIF_DEATH_COUNT; ++i)
91         {
92                 e = Get_Notif_Ent(MSG_DEATH, i);
93                 if not(e) { backtrace("Dump_Notifications(): Missing notification entity!\n"); return; }
94                 NOTIF_WRITE_SETA(e.nent_name, e.nent_default, sprintf("infoname: %s, centername: %s",
95                         e.nent_msginfo.nent_name, e.nent_msgcenter.nent_name));
96         }
97
98         // edit these to match whichever cvars are used for specific notification options
99         NOTIF_WRITE("\n// HARD CODED notification variables:\n");
100         NOTIF_WRITE("seta notification_allow_chatboxprint 1 \"Allow notifications to be printed to chat box by setting notification cvar to 2 (You can also set this cvar to 2 to force ALL notifications to be printed to the chatbox)\"\n");
101         NOTIF_WRITE("seta notification_show_location 0 \"Append location information to MSG_INFO death/kill messages\"\n");
102         NOTIF_WRITE("seta notification_show_location_string \"\" \"Replacement string piped into sprintf, so you can do different messages like this: ' at the %s' or ' (near %s)'\"\n");
103         NOTIF_WRITE("seta notification_show_sprees 1 \"Print information about sprees in death/kill messages\"\n");
104         NOTIF_WRITE("seta notification_show_sprees_center 1 \"Show spree information in MSG_CENTER messages... 0 = off, 1 = target (but only for first victim) and attacker\"\n");
105         NOTIF_WRITE("seta notification_show_sprees_center_specialonly 1 \"Don't show spree information in MSG_CENTER messages if it isn't an achievement\"\n");
106         NOTIF_WRITE("seta notification_show_sprees_info 3 \"Show spree information in MSG_INFO messages... 0 = off, 1 = target only, 2 = attacker only, 3 = target and attacker\"\n");
107         NOTIF_WRITE("seta notification_show_sprees_info_newline 0 \"Show attacker spree information for MSG_INFO messages on a separate line than the death notification itself\"\n");
108         NOTIF_WRITE("seta notification_show_sprees_info_specialonly 1 \"Don't show attacker spree information in MSG_INFO messages if it isn't an achievement\"\n");
109         NOTIF_WRITE("seta notification_errors_are_fatal 1 \"If a notification fails upon initialization, cause a Host_Error to stop the program\"\n");
110         NOTIF_WRITE("seta notification_ctf_pickup_team_verbose 1 \"Show extra information if a team mate picks up a flag\"\n");
111         NOTIF_WRITE("seta notification_ctf_pickup_enemy_verbose 1 \"Show extra information if an enemy picks up a flag\"\n");
112         NOTIF_WRITE("seta notification_ctf_capture_verbose 1 \"Show extra information when someone captures a flag\"\n");
113         NOTIF_WRITE("seta notification_frag_verbose 1 \"Show extra information when you frag someone (or when you are fragged\"\n");
114
115         NOTIF_WRITE(sprintf("\n// Notification counts (total = %d): MSG_INFO = %d, MSG_CENTER = %d, MSG_WEAPON = %d, MSG_DEATH = %d\n",
116                 (NOTIF_INFO_COUNT + NOTIF_CENTER_COUNT + NOTIF_WEAPON_COUNT + NOTIF_DEATH_COUNT), 
117                 NOTIF_INFO_COUNT, NOTIF_CENTER_COUNT, NOTIF_WEAPON_COUNT, NOTIF_DEATH_COUNT));
118         
119         return;
120         #undef NOTIF_WRITE_SETA
121         #undef NOTIF_WRITE
122 }
123
124 #ifdef SVQC
125 void Notification_GetCvars()
126 {
127         GetCvars_handleFloat(get_cvars_s, get_cvars_f, FRAG_VERBOSE, "notification_frag_verbose");
128 }
129 #endif
130
131 string Local_Notification_sprintf(string input, string args, 
132         string s1, string s2, string s3, string s4,
133         float f1, float f2, float f3, float f4)
134 {
135         #ifdef NOTIFICATIONS_DEBUG
136         dprint(
137                 sprintf("Local_Notification_sprintf('%s^7', '%s', %s, %s);\n",
138                         strreplace("\n", "\\n", input),
139                         args,
140                         sprintf("'%s^7', '%s^7', '%s^7', '%s^7'", s1, s2, s3, s4),
141                         sprintf("%d, %d, %d, %d", f1, f2, f3, f4)
142                 )
143         );
144         #endif
145         
146         string selected;
147         float sel_num;
148         for(sel_num = 0; sel_num < NOTIF_MAX_ARGS; ++sel_num) { arg_slot[sel_num] = ""; }
149
150         string tmp_s;
151
152         for(sel_num = 0;(args != "");)
153         {
154                 selected = car(args); args = cdr(args);
155                 NOTIF_HIT_MAX(NOTIF_MAX_ARGS, "Local_Notification_sprintf")
156                 switch(strtolower(selected))
157                 {
158                         #define ARG_CASE(prog,selected,result) \
159                                 #ifdef CSQC \
160                                         #if (prog != ARG_SV) \
161                                                 case selected: { arg_slot[sel_num] = result; ++sel_num; break; } \
162                                         #endif \
163                                 #else \
164                                         #if (prog != ARG_CS) \
165                                                 case selected: { arg_slot[sel_num] = result; ++sel_num; break; } \
166                                         #endif \
167                                 #endif
168                         NOTIF_ARGUMENT_LIST
169                         #undef ARG_CASE
170                         default: NOTIF_HIT_UNKNOWN(NOTIF_MAX_ARGS, "Local_Notification_sprintf")
171                 }
172         }
173         return sprintf(input, arg_slot[0], arg_slot[1], arg_slot[2], arg_slot[3], arg_slot[4], arg_slot[5], arg_slot[6]);
174 }
175
176 #ifdef CSQC
177 void Local_Notification_HUD_Notify_Push(string icon, string hudargs, string s1, string s2, string s3, string s4)
178 {
179         string selected;
180         float sel_num;
181         arg_slot[0] = ""; arg_slot[1] = "";
182
183         for(sel_num = 0;(hudargs != "");)
184         {
185                 selected = car(hudargs); hudargs = cdr(hudargs);
186                 NOTIF_HIT_MAX(NOTIF_MAX_HUDARGS, "Local_Notification_HUD_Notify_Push")
187                 switch(strtolower(selected))
188                 {
189                         #define ARG_CASE(prog,selected,result) \
190                                 #if (prog == ARG_CS_SV_HA) \
191                                         case selected: { arg_slot[sel_num] = result; ++sel_num; break; } \
192                                 #endif
193                         NOTIF_ARGUMENT_LIST
194                         #undef ARG_CASE
195                         default: NOTIF_HIT_UNKNOWN(NOTIF_MAX_HUDARGS, "Local_Notification_HUD_Notify_Push")
196                 }
197         }
198         HUD_Notify_Push(icon, arg_slot[0], arg_slot[1]);
199 }
200
201 void Local_Notification_centerprint_generic(string input, string durcnt, float cpid, float f1, float f2)
202 {
203         string selected;
204         float sel_num;
205         arg_slot[0] = ""; arg_slot[1] = "";
206
207         for(sel_num = 0;(durcnt != "");)
208         {
209                 selected = car(durcnt); durcnt = cdr(durcnt);
210                 NOTIF_HIT_MAX(NOTIF_MAX_DURCNT, "Local_Notification_centerprint_generic")
211                 switch(strtolower(selected))
212                 {
213                         #define ARG_CASE(prog,selected,result) \
214                                 #if (prog == ARG_CS_SV_DC) \
215                                         case selected: { arg_slot[sel_num] = result; ++sel_num; break; } \
216                                 #endif
217                         NOTIF_ARGUMENT_LIST
218                         #undef ARG_CASE
219                         default:
220                         {
221                                 if(ftos(stof(selected)) != "") { arg_slot[sel_num] = selected; ++sel_num; }
222                                 else { NOTIF_HIT_UNKNOWN(NOTIF_MAX_DURCNT, "Local_Notification_centerprint_generic") }
223                                 break;
224                         }
225                 }
226         }
227         centerprint_generic(cpid, input, stof(arg_slot[0]), stof(arg_slot[1]));
228 }
229 #endif
230
231 void Local_Notification(float net_type, float net_name, ...count)
232 {
233         // check supplied type and name for errors
234         string checkargs = "";
235         #define CHECKARG_TYPENAME(type) case MSG_##type##: \
236                 { if(!net_name || (net_name > NOTIF_##type##_COUNT)) \
237                 { checkargs = sprintf("Improper name: %d!", net_name); } break; }
238         switch(net_type)
239         {
240                 CHECKARG_TYPENAME(INFO)
241                 CHECKARG_TYPENAME(CENTER)
242                 CHECKARG_TYPENAME(WEAPON)
243                 CHECKARG_TYPENAME(DEATH)
244                 default: { checkargs = sprintf("Improper type: %d!", checkargs, net_type); break; }
245         }
246         #undef CHECKARG_TYPENAME
247         if(checkargs != "") { backtrace(sprintf("Incorrect usage of Local_Notification: %s\n", checkargs)); return; }
248
249         entity notif = Get_Notif_Ent(net_type, net_name);
250         if not(notif) { backtrace("Local_Notification: Could not find notification entity!\n"); return; }
251         if not(notif.nent_enabled) { print("Local_Notification: Entity was disabled...\n"); return; }
252
253         if((notif.nent_stringcount + notif.nent_floatcount) > count)
254         {
255                 backtrace(sprintf(
256                         strcat(
257                                 "Not enough arguments for Local_Notification(%d, %s, ...)! ",
258                                 "stringcount(%d) + floatcount(%d) > count(%d)\n", 
259                                 "Check the definition and function call for accuracy...?\n"
260                         ),
261                         net_type, notif.nent_name, notif.nent_stringcount, notif.nent_floatcount, count));
262                 return;
263         }
264         else if((notif.nent_stringcount + notif.nent_floatcount) < count)
265         {
266                 backtrace(sprintf(
267                         strcat(
268                                 "Too many arguments for Local_Notification(%d, %s, ...)! ",
269                                 "stringcount(%d) + floatcount(%d) < count(%d)\n",
270                                 "Check the definition and function call for accuracy...?\n"
271                         ),
272                         net_type, notif.nent_name, notif.nent_stringcount, notif.nent_floatcount, count));
273                 return;
274         }
275
276         string s1 = ((0 < notif.nent_stringcount) ? ...(0, string) : "");
277         string s2 = ((1 < notif.nent_stringcount) ? ...(1, string) : "");
278         string s3 = ((2 < notif.nent_stringcount) ? ...(2, string) : "");
279         string s4 = ((3 < notif.nent_stringcount) ? ...(3, string) : "");
280         float f1 = ((0 < notif.nent_floatcount) ? ...((notif.nent_stringcount + 0), float) : 0);
281         float f2 = ((1 < notif.nent_floatcount) ? ...((notif.nent_stringcount + 1), float) : 0);
282         float f3 = ((2 < notif.nent_floatcount) ? ...((notif.nent_stringcount + 2), float) : 0);
283         float f4 = ((3 < notif.nent_floatcount) ? ...((notif.nent_stringcount + 3), float) : 0);
284
285         #ifdef NOTIFICATIONS_DEBUG
286         dprint(
287                 sprintf("Local_Notification(%d, %s, %s, %s);\n",
288                         net_type,
289                         notif.nent_name,
290                         sprintf("'%s^7', '%s^7', '%s^7', '%s^7'", s1, s2, s3, s4),
291                         sprintf("%d, %d, %d, %d", f1, f2, f3, f4)
292                 )
293         );
294         #endif
295         
296         switch(net_type)
297         {
298                 case MSG_INFO:
299                 {
300                         print(
301                                 Local_Notification_sprintf(
302                                         notif.nent_string,
303                                         notif.nent_args, 
304                                         s1, s2, s3, s4,
305                                         f1, f2, f3, f4)
306                         );
307                         #ifdef CSQC 
308                         if(notif.nent_icon != "")
309                         {
310                                 Local_Notification_HUD_Notify_Push(
311                                         notif.nent_icon,
312                                         notif.nent_hudargs,
313                                         s1, s2, s3, s4);
314                         } 
315                         #endif 
316                         break;
317                 }
318                 
319                 #ifdef CSQC
320                 case MSG_CENTER:
321                 {
322                         Local_Notification_centerprint_generic(
323                                 Local_Notification_sprintf(
324                                         notif.nent_string,
325                                         notif.nent_args, 
326                                         s1, s2, s3, s4,
327                                         f1, f2, f3, f4),
328                                 notif.nent_durcnt,
329                                 notif.nent_cpid,
330                                 f1, f2);
331                         break;
332                 }
333                 #endif
334                 
335                 case MSG_WEAPON:
336                 case MSG_DEATH:
337                 {
338                         if(notif.nent_msginfo)
339                         if(notif.nent_msginfo.nent_enabled)
340                         {
341                                 Local_Notification_WOVA(
342                                         MSG_INFO,
343                                         notif.nent_msginfo.nent_id, 
344                                         notif.nent_msginfo.nent_stringcount, 
345                                         notif.nent_msginfo.nent_floatcount, 
346                                         s1, s2, s3, s4,
347                                         f1, f2, f3, f4);
348                         }
349                         #ifdef CSQC
350                         if(notif.nent_msgcenter)
351                         if(notif.nent_msgcenter.nent_enabled)
352                         {
353                                 Local_Notification_WOVA(
354                                         MSG_CENTER,
355                                         notif.nent_msgcenter.nent_id, 
356                                         notif.nent_msgcenter.nent_stringcount, 
357                                         notif.nent_msgcenter.nent_floatcount, 
358                                         s1, s2, s3, s4,
359                                         f1, f2, f3, f4); 
360                         }
361                         #endif
362                         break;
363                 }
364         }
365 }
366
367 // WOVA = Without Variable Arguments 
368 void Local_Notification_WOVA(float net_type, float net_name,
369         float stringcount, float floatcount,
370         string s1, string s2, string s3, string s4,
371         float f1, float f2, float f3, float f4)
372 {
373         #define VARITEM(stringc,floatc,args) \
374                 if((stringcount == stringc) && (floatcount == floatc)) \
375                         { Local_Notification(net_type, net_name, args); return; }
376         EIGHT_VARS_TO_VARARGS_VARLIST
377         #undef VARITEM
378         Local_Notification(net_type, net_name); // some notifications don't have any arguments at all
379 }
380
381
382 // =========================
383 //  Notification Networking
384 // =========================
385
386 #ifdef CSQC
387 void Read_Notification(float is_new)
388 {
389         float net_type = ReadByte();
390         float net_name = ReadShort();
391
392         entity notif = Get_Notif_Ent(net_type, net_name);
393         if not(notif) { print("Read_Notification: Could not find notification entity!\n"); return; }
394
395         string s1 = ((0 < notif.nent_stringcount) ? ReadString() : "");
396         string s2 = ((1 < notif.nent_stringcount) ? ReadString() : "");
397         string s3 = ((2 < notif.nent_stringcount) ? ReadString() : "");
398         string s4 = ((3 < notif.nent_stringcount) ? ReadString() : "");
399         float f1 = ((0 < notif.nent_floatcount) ? ReadLong() : 0);
400         float f2 = ((1 < notif.nent_floatcount) ? ReadLong() : 0);
401         float f3 = ((2 < notif.nent_floatcount) ? ReadLong() : 0);
402         float f4 = ((3 < notif.nent_floatcount) ? ReadLong() : 0);
403
404         #ifdef NOTIFICATIONS_DEBUG
405         dprint(sprintf("Read_Notification(%d) at %f: net_name = %s.\n", is_new, time, notif.nent_name));
406         #endif
407         
408         if(is_new)
409         {
410                 Local_Notification_WOVA(
411                         net_type, net_name,
412                         notif.nent_stringcount,
413                         notif.nent_floatcount,
414                         s1, s2, s3, s4,
415                         f1, f2, f3, f4);
416         }
417 }
418 #endif
419
420 #ifdef SVQC
421 void Net_Notification_Remove()
422 {
423         float i;
424         for(i = 0; i < 4; ++i) { if(self.nent_strings[i]) { strunzone(self.nent_strings[i]); } }
425         remove(self);
426 }
427
428 float Net_Write_Notification(entity client, float sf)
429 {
430         float i, send = FALSE;
431         
432         switch(self.nent_broadcast)
433         {
434                 case NOTIF_ONE: // send to one client and their spectator
435                 {
436                         if(
437                                 (client == self.nent_client)
438                                 ||
439                                 (
440                                         (client.classname == STR_SPECTATOR)
441                                         &&
442                                         (client.enemy == self.nent_client)
443                                 )
444                         ) { send = TRUE; }
445                         break;
446                 }
447                 case NOTIF_ONE_ONLY: // send ONLY to one client
448                 {
449                         if(client == self.nent_client) { send = TRUE; }
450                         break;
451                 }
452                 case NOTIF_TEAM: // send only to X team and their spectators
453                 {
454                         if(
455                                 (client.team == self.nent_client.team)
456                                 ||
457                                 (
458                                         (client.classname == STR_SPECTATOR)
459                                         &&
460                                         (client.enemy.team == self.nent_client.team)
461                                 )
462                         ) { send = TRUE; }
463                         break;
464                 }
465                 case NOTIF_TEAM_EXCEPT: // send only to X team and their spectators, except for Y person and their spectators
466                 {
467                         if(
468                                 (client != self.nent_client)
469                                 &&
470                                 (
471                                         (client.team == self.nent_client.team)
472                                         ||
473                                         (
474                                                 (client.classname == STR_SPECTATOR)
475                                                 &&
476                                                 (
477                                                         (client.enemy != self.nent_client)
478                                                         &&
479                                                         (client.enemy.team == self.nent_client.team)
480                                                 )
481                                         )
482                                 )
483                         ) { send = TRUE; }
484                         break;
485                 }
486                 case NOTIF_ANY: // send to everyone
487                 {
488                         send = TRUE;
489                         break;
490                 }
491                 case NOTIF_ANY_EXCEPT: // send to everyone except X person and their spectators
492                 {
493                         if(
494                                 (client != self.nent_client)
495                                 &&
496                                 !(
497                                         (client.classname == STR_SPECTATOR)
498                                         &&
499                                         (client.enemy == self.nent_client)
500                                 )
501                         ) { send = TRUE; }
502                         break;
503                 }
504                 default: { send = FALSE; break; }
505         }
506
507         if(send)
508         {               
509                 WriteByte(MSG_ENTITY, ENT_CLIENT_NOTIFICATION);
510                 WriteByte(MSG_ENTITY, self.nent_net_type);
511                 WriteShort(MSG_ENTITY, self.nent_net_name);
512                 for(i = 0; i < self.nent_stringcount; ++i) { WriteString(MSG_ENTITY, self.nent_strings[i]); } 
513                 for(i = 0; i < self.nent_floatcount; ++i) { WriteLong(MSG_ENTITY, self.nent_floats[i]); }
514         }
515
516         return send; 
517 }
518
519 void Send_Notification(float broadcast, entity client,
520         float net_type, float net_name, ...count)
521 {
522         // check supplied broadcast, target, type, and name for errors
523         string checkargs = "";
524         #define CHECKARG_TYPENAME(type) case MSG_##type##: \
525                 { if(!net_name || (net_name > NOTIF_##type##_COUNT)) \
526                 { checkargs = sprintf("Improper name: %d!", net_name); } break; }
527         switch(net_type)
528         {
529                 CHECKARG_TYPENAME(INFO)
530                 CHECKARG_TYPENAME(CENTER)
531                 CHECKARG_TYPENAME(WEAPON)
532                 CHECKARG_TYPENAME(DEATH)
533                 default: { checkargs = sprintf("Improper type: %d!", checkargs, net_type); break; }
534         }
535         #undef CHECKARG_TYPENAME
536         if(checkargs != "") { checkargs = strcat(checkargs, " "); }
537         switch(broadcast)
538         {
539                 case NOTIF_ONE:
540                 case NOTIF_ONE_ONLY:
541                 {
542                         if(IS_NOT_A_CLIENT(client))
543                                 { checkargs = sprintf("%sNo client provided!", checkargs); }
544                         break;
545                 }
546                 
547                 case NOTIF_ANY_EXCEPT:
548                 {
549                         if(IS_NOT_A_CLIENT(client))
550                                 { checkargs = sprintf("%sException can't be a non-client!", checkargs); }
551                         break;
552                 }
553                 
554                 case NOTIF_ANY:
555                 {
556                         if(client)
557                                 { checkargs = sprintf("%sEntity provided when world was required!", checkargs); }
558                         break;
559                 }
560                 
561                 case NOTIF_TEAM:
562                 case NOTIF_TEAM_EXCEPT:
563                 {
564                         if not(teamplay) { checkargs = sprintf("%sTeamplay not active!", checkargs); }
565                         else if(IS_NOT_A_CLIENT(client))
566                         {
567                                 if(broadcast == NOTIF_TEAM) { checkargs = sprintf("%sNo client provided!", checkargs); }
568                                 else { checkargs = sprintf("%sException can't be a non-client!", checkargs); }
569                         }
570                         break;
571                 }
572                 
573                 default: { checkargs = sprintf("%sImproper broadcast: %d!", checkargs, broadcast); break; }
574         }
575         if(checkargs != "") { backtrace(sprintf("Incorrect usage of Send_Notification: %s\n", checkargs)); return; }
576
577         // retreive counts for the arguments of this notification
578         entity notif = Get_Notif_Ent(net_type, net_name);
579         if not(notif) { backtrace("Send_Notification: Could not find notification entity!\n"); return; }
580
581         if((notif.nent_stringcount + notif.nent_floatcount) > count)
582         {
583                 backtrace(sprintf(
584                         strcat(
585                                 "Not enough arguments for Send_Notification(%d, %d, %s, ...)! ",
586                                 "stringcount(%d) + floatcount(%d) > count(%d)\n", 
587                                 "Check the definition and function call for accuracy...?\n"
588                         ),
589                         broadcast, net_type, notif.nent_name, notif.nent_stringcount, notif.nent_floatcount, count));
590                 return;
591         }
592         else if((notif.nent_stringcount + notif.nent_floatcount) < count)
593         {
594                 backtrace(sprintf(
595                         strcat(
596                                 "Too many arguments for Send_Notification(%d, %d, %s, ...)! ",
597                                 "stringcount(%d) + floatcount(%d) < count(%d)\n",
598                                 "Check the definition and function call for accuracy...?\n"
599                         ),
600                         broadcast, net_type, notif.nent_name, notif.nent_stringcount, notif.nent_floatcount, count));
601                 return;
602         }
603
604         #ifdef NOTIFICATIONS_DEBUG
605         string s1 = ((0 < notif.nent_stringcount) ? ...(0, string) : "");
606         string s2 = ((1 < notif.nent_stringcount) ? ...(1, string) : "");
607         string s3 = ((2 < notif.nent_stringcount) ? ...(2, string) : "");
608         string s4 = ((3 < notif.nent_stringcount) ? ...(3, string) : "");
609         float f1 = ((0 < notif.nent_floatcount) ? ...((notif.nent_stringcount + 0), float) : 0);
610         float f2 = ((1 < notif.nent_floatcount) ? ...((notif.nent_stringcount + 1), float) : 0);
611         float f3 = ((2 < notif.nent_floatcount) ? ...((notif.nent_stringcount + 2), float) : 0);
612         float f4 = ((3 < notif.nent_floatcount) ? ...((notif.nent_stringcount + 3), float) : 0);
613         dprint(
614                 sprintf("Send_Notification(%d, %d, %s, %s, %s - %d %d);\n",
615                         broadcast,
616                         net_type,
617                         notif.nent_name,
618                         sprintf("'%s^7', '%s^7', '%s^7', '%s^7'", s1, s2, s3, s4),
619                         sprintf("%d, %d, %d, %d", f1, f2, f3, f4),
620                         notif.nent_stringcount, notif.nent_floatcount
621                 )
622         );
623         #endif
624
625         entity net_notif = spawn();
626         net_notif.nent_broadcast = broadcast;
627         net_notif.nent_client = client;
628         net_notif.nent_net_type = net_type;
629         net_notif.nent_net_name = net_name;
630         net_notif.nent_stringcount = notif.nent_stringcount;
631         net_notif.nent_floatcount = notif.nent_floatcount;
632         
633         float i;
634         for(i = 0; i < net_notif.nent_stringcount; ++i) { net_notif.nent_strings[i] = strzone(...(i, string)); }
635         for(i = 0; i < net_notif.nent_floatcount; ++i) { net_notif.nent_floats[i] = ...((net_notif.nent_stringcount + i), float); }
636         
637         net_notif.think = Net_Notification_Remove;
638         net_notif.nextthink = (time + 0.5); 
639
640         Net_LinkEntity(net_notif, FALSE, 0, Net_Write_Notification);
641
642         if((!server_is_local) && (broadcast == NOTIF_ANY || broadcast == NOTIF_ANY_EXCEPT) && (net_type != MSG_CENTER))
643         {
644                 Local_Notification_WOVA(
645                         net_type, net_name,
646                         notif.nent_stringcount,
647                         notif.nent_floatcount,
648                         IFSTR(0), IFSTR(1), IFSTR(2), IFSTR(3),
649                         IFFL(0), IFFL(1), IFFL(2), IFFL(3));
650         }
651 }
652
653 // WOVA = Without Variable Arguments 
654 void Send_Notification_WOVA(float broadcast, entity client,
655         float net_type, float net_name,
656         string s1, string s2, string s3, string s4,
657         float f1, float f2, float f3, float f4)
658 {
659         entity notif = Get_Notif_Ent(net_type, net_name);
660         
661         #ifdef NOTIFICATIONS_DEBUG
662         dprint(
663                 sprintf("Send_Notification_WOVA(%d, %d, %s, %s, %s - %d %d);\n",
664                         broadcast,
665                         net_type,
666                         notif.nent_name,
667                         sprintf("'%s^7', '%s^7', '%s^7', '%s^7'", s1, s2, s3, s4),
668                         sprintf("%d, %d, %d, %d", f1, f2, f3, f4),
669                         notif.nent_stringcount, notif.nent_floatcount
670                 )
671         );
672         #endif
673         
674         #define VARITEM(stringc,floatc,args) \
675                 if((notif.nent_stringcount == stringc) && (notif.nent_floatcount == floatc)) \
676                         { Send_Notification(broadcast, client, net_type, net_name, args); return; }
677         EIGHT_VARS_TO_VARARGS_VARLIST
678         #undef VARITEM
679         Send_Notification(broadcast, client, net_type, net_name); // some notifications don't have any arguments at all
680 }
681
682
683 // =============================
684 //  LEGACY NOTIFICATION SYSTEMS
685 // =============================
686
687 void Send_CSQC_Centerprint_Generic(entity e, float id, string s, float duration, float countdown_num)
688 {
689         if ((clienttype(e) == CLIENTTYPE_REAL) && (e.flags & FL_CLIENT))
690         {
691                 msg_entity = e;
692                 WRITESPECTATABLE_MSG_ONE({
693                         WriteByte(MSG_ONE, SVC_TEMPENTITY);
694                         WriteByte(MSG_ONE, TE_CSQC_CENTERPRINT_GENERIC);
695                         WriteByte(MSG_ONE, id);
696                         WriteString(MSG_ONE, s);
697                         if (id != 0 && s != "")
698                         {
699                                 WriteByte(MSG_ONE, duration);
700                                 WriteByte(MSG_ONE, countdown_num);
701                         }
702                 });
703         }
704 }
705 #endif // ifdef SVQC