]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Create a way to kill notifications (including centerprints) from code
authorSamual Lenks <samual@xonotic.org>
Tue, 26 Feb 2013 23:26:46 +0000 (18:26 -0500)
committerSamual Lenks <samual@xonotic.org>
Tue, 26 Feb 2013 23:26:46 +0000 (18:26 -0500)
qcsrc/common/notifications.qc
qcsrc/server/arena.qc

index 8f60424d3af6a2cbb5f0d985248a2fa2caafa0ac..eea9205ffd5a8f86c8254f67247997db74af1201 100644 (file)
@@ -3,6 +3,19 @@
 //  Last updated: February, 2013
 // ================================================
 
+string Get_Notif_TypeName(float net_type)
+{
+       switch(net_type)
+       {
+               case MSG_INFO: return "MSG_INFO";
+               case MSG_CENTER: return "MSG_CENTER";
+               case MSG_WEAPON: return "MSG_WEAPON";
+               case MSG_DEATH: return "MSG_DEATH";
+       }
+       backtrace(sprintf("Get_Notif_TypeName(%d): Improper net type!\n", net_type));
+       return "your ass";
+}
+
 entity Get_Notif_Ent(float net_type, float net_name)
 {
        switch(net_type)
@@ -389,6 +402,25 @@ void Read_Notification(float is_new)
        float net_type = ReadByte();
        float net_name = ReadShort();
 
+       if(net_type == (-1 * MSG_CENTER))
+       {
+               if(is_new)
+               {
+                       if(net_name == 0)
+                       {
+                               print("clearing all centerprints\n");
+                               reset_centerprint_messages();
+                       }
+                       else
+                       {
+                               entity notif = Get_Notif_Ent(net_type, net_name);
+                               if not(notif) { print("Read_Notification: Could not find notification entity!\n"); return; }
+                               centerprint_generic(notif.nent_cpid, "", 0, 0);
+                       }
+               }
+               return;
+       }
+       
        entity notif = Get_Notif_Ent(net_type, net_name);
        if not(notif) { print("Read_Notification: Could not find notification entity!\n"); return; }
 
@@ -516,6 +548,34 @@ float Net_Write_Notification(entity client, float sf)
        return send; 
 }
 
+void Kill_Notification(float broadcast, entity client, float net_type, float net_name)
+{
+       entity notif;
+
+       // if this is a centerprint, we must tell the client
+       // to kill the cpid in the centerprint queue
+       if(net_type == MSG_CENTER)
+       {
+               notif = Get_Notif_Ent(net_type, net_name);
+               if not(notif) { backtrace("Kill_Notification: Could not find notification entity!\n"); return; }
+
+               notif = spawn();
+               notif.classname = "net_kill_notification";
+               notif.nent_broadcast = broadcast;
+               notif.nent_client = client;
+               notif.nent_net_type = (-1 * MSG_CENTER);
+               notif.nent_net_name = net_name;
+               Net_LinkEntity(notif, FALSE, 0.5, Net_Write_Notification);
+       }
+
+       for(notif = world; (notif = find(notif, classname, sprintf("net_%s", strtolower(Get_Notif_TypeName(net_type)))));)
+       {
+               // now kill the old send notification entity
+               print(sprintf("killed '%s'\n", notif.classname));
+               notif.think();
+       }
+}
+
 void Send_Notification(float broadcast, entity client,
        float net_type, float net_name, ...count)
 {
@@ -623,6 +683,7 @@ void Send_Notification(float broadcast, entity client,
        #endif
 
        entity net_notif = spawn();
+       net_notif.classname = sprintf("net_%s", strtolower(Get_Notif_TypeName(net_type)));
        net_notif.nent_broadcast = broadcast;
        net_notif.nent_client = client;
        net_notif.nent_net_type = net_type;
index 96250923ef71fd7a66c06207e30db474c33f3bfd..8d9d8a0f895f95d004c533e5761c336d70d07461 100644 (file)
@@ -201,6 +201,8 @@ void Arena_Warmup()
                {
                        FOR_EACH_REALCLIENT(e)
                                Send_CSQC_Centerprint_Generic_Expire(e, CPID_ARENA);
+
+                       //Kill_Notification(MSG_CENTER, CPID_ARENA);
                        warmup = 0;
                }
                if(champion && g_arena)