From: Keith F. <ven...@us...> - 2002-03-05 07:17:51
|
Update of /cvsroot/planeshift/planeshift/src/common/net In directory usw-pr-cvs1:/tmp/cvs-serv31784 Modified Files: netthread.h netthread.cpp Log Message: Added centralized broadcast function here. Index: netthread.h =================================================================== RCS file: /cvsroot/planeshift/planeshift/src/common/net/netthread.h,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** netthread.h 4 Mar 2002 00:20:23 -0000 1.15 --- netthread.h 5 Mar 2002 07:17:48 -0000 1.16 *************** *** 29,32 **** --- 29,37 ---- #define PS_STD_PORT 1243 + #define BC_EVERYONEBUTSELF 1 // Broadcast scope + #define BC_GROUP 2 + #define BC_GUILD 3 + #define BC_SECTOR 4 + /** * This is the network thread handling packets sending/receiving to/from network *************** *** 47,53 **** /** this starts a new network thread */ bool StartThread(); ! ! /** This puts a message in the outgoing queue */ ! // virtual bool SendMessage(MsgEntry* me); /** This receives subscribed periodic timer events to detect linkdead clients */ --- 52,58 ---- /** this starts a new network thread */ bool StartThread(); ! ! /** This repeats the same msg out to a bunch of Clients. */ ! void Broadcast(MsgEntry *me, int scope=BC_EVERYONEBUTSELF); /** This receives subscribed periodic timer events to detect linkdead clients */ Index: netthread.cpp =================================================================== RCS file: /cvsroot/planeshift/planeshift/src/common/net/netthread.cpp,v retrieving revision 1.25 retrieving revision 1.26 diff -C2 -d -r1.25 -r1.26 *** netthread.cpp 5 Mar 2002 05:22:12 -0000 1.25 --- netthread.cpp 5 Mar 2002 07:17:48 -0000 1.26 *************** *** 170,173 **** --- 170,213 ---- } + void NetThread::Broadcast(MsgEntry *me, int scope) + { + switch (scope) + { + case BC_EVERYONEBUTSELF: + { + // send the message to each client except the client that originated it + uint32_t originalclient = me->clientnum; + + BinaryTreeIterator<Client> *i = clients->GetIterator(); + Client* p; + + // Copy message to send out to everyone + MsgEntry *newmsg = new MsgEntry(me); + newmsg->msgid = (uint32_t) newmsg; + + // Message is copied again into packet sections, so we can reuse same one. + + for (p = i->First(); p; p = i->Next()) + { + if (p->GetClientNum() != originalclient) + { + newmsg->clientnum = p->GetClientNum(); + SendMessage (newmsg); + } + } + + newmsg->DecRef(); + + break; + } + default: + psprintf("\nIllegal Broadcast scope %d!\n",scope); + break; + } + } + + + + void NetThread::Trigger() { |