]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Begin re-writing sending mechanism for notification system
authorSamual Lenks <samual@xonotic.org>
Thu, 31 Jan 2013 10:52:49 +0000 (05:52 -0500)
committerSamual Lenks <samual@xonotic.org>
Thu, 31 Jan 2013 10:52:49 +0000 (05:52 -0500)
qcsrc/client/Main.qc
qcsrc/common/constants.qh
qcsrc/common/notifications.qc

index 7b300dd508e5f9d688c91511a1025e4349a1af52..cd7e3a28f60db084763bfbd67873aa5f489c93d7 100644 (file)
@@ -779,7 +779,8 @@ void CSQC_Ent_Update(float bIsNewEntity)
                case ENT_CLIENT_TURRET: ent_turret(); break; 
                case ENT_CLIENT_MODEL: CSQCModel_Read(bIsNewEntity); break;
                case ENT_CLIENT_ITEM: ItemRead(bIsNewEntity); break;  
-               case ENT_CLIENT_BUMBLE_RAYGUN: bumble_raygun_read(bIsNewEntity); break;  
+               case ENT_CLIENT_BUMBLE_RAYGUN: bumble_raygun_read(bIsNewEntity); break;
+               case ENT_CLIENT_NOTIFICATION: Read_Notification(bIsNewEntity); break;
                default:
                        //error(strcat(_("unknown entity type in CSQC_Ent_Update: %d\n"), self.enttype));
                        error(sprintf(_("Unknown entity type in CSQC_Ent_Update (enttype: %d, edict: %d, classname: %s)\n"), self.enttype, num_for_edict(self), self.classname));
@@ -1225,10 +1226,6 @@ float CSQC_Parse_TempEntity()
                        cl_notice_read();
                        bHandled = true;
                        break;
-               case TE_CSQC_NOTIFICATION:
-                       Read_Notification();
-                       bHandled = true;
-                       break;
                default:
                        // No special logic for this temporary entity; return 0 so the engine can handle it
                        bHandled = false;
index dc128e62f448836c56c8184b7cd6884974c96fd8..2b5599ba19fae9cf7c20cb664869ac06fda9f5aa 100644 (file)
@@ -47,7 +47,6 @@ const float TE_CSQC_MINELAYER_MAXMINES = 117;
 const float TE_CSQC_HAGAR_MAXROCKETS = 118;
 const float TE_CSQC_VEHICLESETUP = 119;
 const float TE_CSQC_SVNOTICE = 120;
-const float TE_CSQC_NOTIFICATION = 121;
 
 const float RACE_NET_CHECKPOINT_HIT_QUALIFYING = 0; // byte checkpoint, short time, short recordtime, string recordholder
 const float RACE_NET_CHECKPOINT_CLEAR = 1;
@@ -100,6 +99,7 @@ const float ENT_CLIENT_WARPZONE_TELEPORTED = 32;
 const float ENT_CLIENT_MODEL = 33;
 const float ENT_CLIENT_ITEM = 34;
 const float ENT_CLIENT_BUMBLE_RAYGUN = 35;
+const float ENT_CLIENT_NOTIFICATION 36;
 
 const float ENT_CLIENT_TURRET = 40;
 const float ENT_CLIENT_AUXILIARYXHAIR = 50;
index ad884add3c1d37ad7695be97ed0f88bf1acc4c1d..5f9beb70e84afda5e1c04708fc393e4df933d7c6 100644 (file)
@@ -294,30 +294,74 @@ void Local_Notification_Without_VarArgs(float net_type, float net_name, float st
 //  Notification Networking
 // =========================
 
+#define NOTIF_ONE 1
+#define NOTIF_ONE_SPECTATABLE 2
+#define NOTIF_TEAM 3
+#define NOTIF_TEAM_EXCEPT 4
+#define NOTIF_ANY 5
+#define NOTIF_ANY_EXCEPT 6
+
+.float nent_broadcast;
+.entity nent_client;
+.float nent_net_type;
+.float nent_net_name;
+.string nent_strings[4];
+.float nent_floats[4];
+
 #ifdef CSQC
-void Read_Notification(void)
+void Read_Notification(float is_new)
 {
        float net_type = ReadByte();
        float net_name = ReadShort();
 
        float stringcount = stof(Get_Field_Value(F_STRNUM, net_type, net_name));
        float floatcount = stof(Get_Field_Value(F_FLNUM, net_type, net_name));
-       
-       Local_Notification_Without_VarArgs(net_type, net_name,
-               stringcount, floatcount,
-               ((stringcount >= 1) ? ReadString() : NO_STR_ARG),
-               ((stringcount >= 2) ? ReadString() : NO_STR_ARG),
-               ((stringcount >= 3) ? ReadString() : NO_STR_ARG),
-               ((stringcount == 4) ? ReadString() : NO_STR_ARG),
-               ((floatcount >= 1) ? ReadLong() : NO_FL_ARG),
-               ((floatcount >= 2) ? ReadLong() : NO_FL_ARG),
-               ((floatcount >= 3) ? ReadLong() : NO_FL_ARG),
-               ((floatcount == 4) ? ReadLong() : NO_FL_ARG));
+
+       string s1 = ((stringcount >= 1) ? ReadString() : NO_STR_ARG);
+       string s2 = ((stringcount >= 2) ? ReadString() : NO_STR_ARG);
+       string s3 = ((stringcount >= 3) ? ReadString() : NO_STR_ARG);
+       string s4 = ((stringcount == 4) ? ReadString() : NO_STR_ARG);
+       float f1 = ((floatcount >= 1) ? ReadLong() : NO_FL_ARG);
+       float f2 = ((floatcount >= 2) ? ReadLong() : NO_FL_ARG);
+       float f3 = ((floatcount >= 3) ? ReadLong() : NO_FL_ARG);
+       float f4 = ((floatcount == 4) ? ReadLong() : NO_FL_ARG);
+
+       if(is_new) { Local_Notification_Without_VarArgs(net_type, net_name, stringcount, floatcount, s1, s2, s3, s4, f1, f2, f3, f4); }
 }
 #endif
 
 #ifdef SVQC
-void Send_Notification(entity client, float broadcast, float net_type, float net_name, ...count)
+float Write_Notification(entity client, float sf)
+{
+       float send;
+       
+       switch(self.nent_broadcast)
+       {
+               case NOTIF_ONE: { if(client == self.nent_client) { send = TRUE; } break; }
+               case NOTIF_ONE_SPECTATABLE: { if((client == self.nent_client) || (client.classname == STR_SPECTATOR && client.enemy == self.nent_client)) { send = TRUE; } break; }
+               case NOTIF_TEAM: { if(client.team == self.nent_client.team) { send = TRUE; } break; }
+               case NOTIF_TEAM_EXCEPT: { if((client != self.nent_client) && (client.team == self.nent_client.team)) { send = TRUE; } break; }
+               case NOTIF_ANY: { send = TRUE; break; }
+               case NOTIF_ANY_EXCEPT: { if(client != self.nent_client) { send = TRUE; } break; }
+               default: { send = FALSE; break; }
+       }
+
+       if(send)
+       {
+               float stringcount = stof(Get_Field_Value(F_STRNUM, self.nent_net_type, self.nent_net_name));
+               float floatcount = stof(Get_Field_Value(F_FLNUM, self.nent_net_type, self.nent_net_name));
+               
+               WriteByte(MSG_ENTITY, ENT_CLIENT_NOTIFICATION);
+               WriteByte(MSG_ENTITY, self.nent_net_type);
+               WriteShort(MSG_ENTITY, self.nent_net_name);
+               for(i = 0; i < stringcount; ++i) { WriteString(MSG_ENTITY, self.nent_strings[i]); } 
+               for(i = 0; i < floatcount; ++i) { WriteLong(MSG_ENTITY, self.nent_floats[stringcount + i]); }
+       }
+
+       return send; 
+}
+
+void Send_Notification(float broadcast, entity client, float net_type, float net_name, ...count)
 {
        if((broadcast == MSG_BROADCAST || broadcast == MSG_ONE) && net_type && net_name)
        {
@@ -335,40 +379,15 @@ void Send_Notification(entity client, float broadcast, float net_type, float net
                //if(Count_Proper_Strings(NO_STR_ARG, s1, s2) > stringcount) { backtrace("Too many string arguments for notification!\n"); return; }
                //if(Count_Proper_Floats(NO_FL_ARG, f1, f2, f3) > floatcount) { backtrace("Too many float arguments for notification!\n"); return; }
 
-               #define WRITE_NOTIFICATION(msg) \
-                       WriteByte(msg, SVC_TEMPENTITY); \
-                       WriteByte(msg, TE_CSQC_NOTIFICATION); \
-                       WriteByte(msg, net_type); \
-                       WriteShort(msg, net_name); \
-                       for(i = 0; i < stringcount; ++i) \
-                               { tmp_s = ...(i, string); WriteString(msg, tmp_s); dprint("WriteString(...(", ftos(i), ", string)); - ", tmp_s, "\n"); } \
-                       for(i = 0; i < floatcount; ++i) \
-                               { tmp_f = ...((stringcount + i), float); WriteLong(msg, tmp_f); dprint("WriteLong(...(", ftos((stringcount + i)), ", float)); - ", ftos(tmp_f), "\n"); }
-
-                       
-               switch(broadcast)
-               {
-                       case MSG_ONE: // personal/direct notification sent to ONE person and their spectators
-                       {
-                               if(client && (clienttype(client) == CLIENTTYPE_REAL) && (client.flags & FL_CLIENT))
-                               {
-                                       msg_entity = client;
-                                       WRITESPECTATABLE_MSG_ONE({WRITE_NOTIFICATION(MSG_ONE)});
-                               }
-                               break;
-                       }
-                       
-                       case MSG_BROADCAST: // global notification sent to EVERYONE
-                       {
-                               WRITE_NOTIFICATION(MSG_BROADCAST)
-                               break;
-                       }
-
-                       case MSG_ALL: { backtrace("DO NOT USE MSG_ALL FOR NOTIFICATIONS, IT IS BAD!\n"); break; }
-                       default: { backtrace("Unknown MSG_ type to write with!\n"); break; }
-               }
+               entity notif = spawn();
+               notif.nent_broadcast = broadcast;
+               notif.nent_client = client;
+               notif.nent_net_type = net_type;
+               notif.nent_net_name = net_name;
+               for(i = 0; i < stringcount; ++i) { tmp_s = ...(i, string); notif.nent_strings[i] = tmp_s; dprint("WriteString(...(", ftos(i), ", string)); - ", tmp_s, "\n"); } 
+               for(i = 0; i < floatcount; ++i) { tmp_f = ...((stringcount + i), float); notif.nent_floats[i] = tmp_f; dprint("WriteLong(...(", ftos((stringcount + i)), ", float)); - ", ftos(tmp_f), "\n"); }
 
-               #undef WRITE_NOTIFICATION
+               Net_LinkEntity(notif, FALSE, 0.5, Write_Notification);
 
                if(!server_is_local)
                {
@@ -378,37 +397,27 @@ void Send_Notification(entity client, float broadcast, float net_type, float net
        else { backtrace("Incorrect usage of Send_Notification!\n"); }
 }
 
-void Send_Notification_Without_VarArgs(entity client, float broadcast, float net_type, float net_name, float stringcount, float floatcount, string s1, string s2, string s3, string s4, float f1, float f2, float f3, float f4)
+void Send_Notification_Without_VarArgs(float broadcast, entity client, float net_type, float net_name, float stringcount, float floatcount, string s1, string s2, string s3, string s4, float f1, float f2, float f3, float f4)
 {              
-       #define VARITEM(stringc,floatc,args) if((stringcount == stringc) && (floatcount == floatc)) { Send_Notification(client, broadcast, net_type, net_name, args); return; }
+       #define VARITEM(stringc,floatc,args) if((stringcount == stringc) && (floatcount == floatc)) { Send_Notification(broadcast, client, net_type, net_name, args); return; }
        EIGHT_VARS_TO_VARARGS_VARLIST
        #undef VARITEM
 
-       Send_Notification(client, broadcast, net_type, net_name); // some notifications don't have any arguments at all
+       Send_Notification(broadcast, client, net_type, net_name); // some notifications don't have any arguments at all
 }
 
 void Send_Notification_Legacy_Wrapper(entity client, float broadcast, float net_type, float net_name, string s1, string s2, float f1, float f2, float f3)
 {
        float stringcount = stof(Get_Field_Value(F_STRNUM, net_type, net_name));
        float floatcount = stof(Get_Field_Value(F_FLNUM, net_type, net_name));
-       Send_Notification_Without_VarArgs(client, broadcast, net_type, net_name, stringcount, floatcount, s1, s2, NO_STR_ARG, NO_STR_ARG, f1, f2, f3, NO_FL_ARG);
+       Send_Notification_Without_VarArgs(broadcast, client, net_type, net_name, stringcount, floatcount, s1, s2, NO_STR_ARG, NO_STR_ARG, f1, f2, f3, NO_FL_ARG);
 }
 
-void Send_Notification_ToTeam(float targetteam, entity except, float net_type, float net_name, ...count)
+/*void Send_Notification_ToTeam(float targetteam, entity except, float net_type, float net_name, ...count)
 {
        float stringcount = stof(Get_Field_Value(F_STRNUM, net_type, net_name));
        float floatcount = stof(Get_Field_Value(F_FLNUM, net_type, net_name));
-       
-       entity tmp_entity;
-       FOR_EACH_REALCLIENT(tmp_entity)
-       {
-               if(tmp_entity.classname == STR_PLAYER)
-               if(tmp_entity.team == targetteam)
-               if(tmp_entity != except)
-               {
-                       Send_Notification_Without_VarArgs(tmp_entity, MSG_ONE, net_type, net_name, stringcount, floatcount, IFSTR(0), IFSTR(1), IFSTR(2), IFSTR(3), IFFL(0), IFFL(1), IFFL(2), IFFL(3));
-               }
-       }
+       Send_Notification_Without_VarArgs(NOTIF_TEAM, tmp_entity, net_type, net_name, stringcount, floatcount, IFSTR(0), IFSTR(1), IFSTR(2), IFSTR(3), IFFL(0), IFFL(1), IFFL(2), IFFL(3));
 }
 
 // WARNING: use this ONLY if you need exceptions or want to exclude spectators, otherwise use Send_Notification(world, MSG_BROADCAST, ...)
@@ -426,7 +435,7 @@ void Send_Notification_ToAll(entity except, float spectators, float net_type, fl
                        Send_Notification_Without_VarArgs(tmp_entity, MSG_ONE, net_type, net_name, stringcount, floatcount, IFSTR(0), IFSTR(1), IFSTR(2), IFSTR(3), IFFL(0), IFFL(1), IFFL(2), IFFL(3));
                }
        }
-}
+}*/
 
 
 // =============================