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