From 0ea5fc66924303d1bf73ba283a383e2aadee02f2 Mon Sep 17 00:00:00 2001 From: neodarz Date: Sat, 11 Aug 2018 20:21:34 +0200 Subject: Initial commit --- docs/doxygen/nel/a02306.html | 2295 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 2295 insertions(+) create mode 100644 docs/doxygen/nel/a02306.html (limited to 'docs/doxygen/nel/a02306.html') diff --git a/docs/doxygen/nel/a02306.html b/docs/doxygen/nel/a02306.html new file mode 100644 index 00000000..054019dd --- /dev/null +++ b/docs/doxygen/nel/a02306.html @@ -0,0 +1,2295 @@ + + +NeL: NLNET::CCallbackNetBase class Reference + + + +
+

NLNET::CCallbackNetBase Class Reference

#include <callback_net_base.h> +

+

Inheritance diagram for NLNET::CCallbackNetBase: +

+ +NLNET::CCallbackClient +NLNET::CCallbackServer + +

Detailed Description

+Layer 3
Author:
Vianney Lecroart

+Nevrax France

+
Date:
2001
+ +

+ +

+Definition at line 75 of file callback_net_base.h. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Public Types

enum  TRecordingState { Off, +Record, +Replay + }

Public Member Functions

void addCallbackArray (const TCallbackItem *callbackarray, NLMISC::CStringIdArray::TStringId arraysize)
void authorizeOnly (const char *callbackName, TSockId hostid=InvalidSockId)
virtual bool connected () const
 This function is implemented in the client and server class.

virtual bool dataAvailable ()
 This function is implemented in the client and server class.

virtual void disconnect (TSockId hostid=InvalidSockId)
 This function is implemented in the client and server class.

void displayAllMyAssociations ()
virtual void displayReceiveQueueStat (NLMISC::CLog *log=NLMISC::InfoLog)=0
virtual void displaySendQueueStat (NLMISC::CLog *log=NLMISC::InfoLog, TSockId destid=InvalidSockId)=0
virtual void displayThreadStat (NLMISC::CLog *log=NLMISC::InfoLog)=0
virtual bool flush (TSockId hostid=InvalidSockId)=0
uint64 getBytesReceived ()
uint64 getBytesSent ()
virtual uint64 getReceiveQueueSize ()=0
virtual uint64 getSendQueueSize ()=0
NLMISC::CStringIdArraygetSIDA ()
 Use this function to get the String ID Array needed when you want to create a message.

virtual TSockId getSockId (TSockId hostid=InvalidSockId)=0
 returns the sockid of a connection. On a server, this function returns the parameter. On a client, it returns the connection.

virtual const CInetAddresshostAddress (TSockId hostid)
 Returns the address of the specified host.

void ignoreAllUnknownId (bool b)
bool isAServer () const
 Returns true if this is a CCallbackServer.

virtual void send (const CMessage &buffer, TSockId hostid=InvalidSockId, bool log=true)=0
void sendAllMyAssociations (TSockId to)
 Used by client and server class.

void setDefaultCallback (TMsgCallback defaultCallback)
 Sets default callback for unknown message types.

void setDisconnectionCallback (TNetCallback cb, void *arg)
 Sets callback for disconnections (or NULL to disable callback).

void setOtherSideAssociations (const char **associationarray, NLMISC::CStringIdArray::TStringId arraysize)
virtual void update (sint32 timeout=0)
 This function is implemented in the client and server class.

virtual ~CCallbackNetBase ()

Protected Member Functions

void baseUpdate (sint32 timeout=0)
 Used by client and server class.

 CCallbackNetBase (TRecordingState rec=Off, const std::string &recfilename="", bool recordall=true)
 Constructor.

void checkThreadId () const
void processOneMessage ()
 Read a message from the network and process it.

virtual void receive (CMessage &buffer, TSockId *hostid)=0
 On this layer, you can't call directly receive, It s the update() function that receive and call your callaback.


Protected Attributes

uint64 _BytesReceived
uint64 _BytesSent
std::vector< TCallbackItem_CallbackArray
TMsgCallback _DefaultCallback
bool _FirstUpdate
NLMISC::CStringIdArray _InputSIDA
bool _IsAServer
TNetCallback _NewDisconnectionCallback
 Used by client and server class.

NLMISC::CStringIdArray _OutputSIDA
uint _ThreadId

Private Attributes

TNetCallback _DisconnectionCallback
void * _DisconnectionCbArg
NLMISC::TTime _LastMovedStringArray
NLMISC::TTime _LastUpdateTime

Friends

void cbnbMessageAskAssociations (CMessage &msgin, TSockId from, CCallbackNetBase &netbase)
void cbnbMessageRecvAssociations (CMessage &msgin, TSockId from, CCallbackNetBase &netbase)
void cbnbNewDisconnection (TSockId from, void *data)
+


Member Enumeration Documentation

+

+ + + + +
+ + +
enum NLNET::CCallbackNetBase::TRecordingState +
+
+ + + + + +
+   + + +

+

Enumeration values:
+ + + + +
Off  +
Record  +
Replay  +
+
+ +

+Definition at line 163 of file callback_net_base.h. +

+

00163 { Off, Record, Replay };
+
+


Constructor & Destructor Documentation

+

+ + + + +
+ + + + + + + + + +
virtual NLNET::CCallbackNetBase::~CCallbackNetBase  )  [inline, virtual]
+
+ + + + + +
+   + + +

+ +

+Definition at line 78 of file callback_net_base.h. +

+

00078 {}
+
+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
NLNET::CCallbackNetBase::CCallbackNetBase TRecordingState  rec = Off,
const std::string &  recfilename = "",
bool  recordall = true
[protected]
+
+ + + + + +
+   + + +

+Constructor. +

+ +

+Definition at line 148 of file callback_net_base.cpp. +

+References _BytesReceived, _BytesSent, _NewDisconnectionCallback, _ThreadId, addCallbackArray(), NLNET::cbnbMessageAssociationArray, NLNET::cbnbNewDisconnection(), NLMISC::createDebug(), NLMISC::getThreadId(), Record, and Replay. +

+

00148                                                                                                     :
+00149         _FirstUpdate (true), _DisconnectionCallback(NULL), _DisconnectionCbArg(NULL)
+00150 #ifdef USE_MESSAGE_RECORDER
+00151         , _MR_RecordingState(rec), _MR_UpdateCounter(0)
+00152 #endif
+00153 {
+00154         _ThreadId = getThreadId ();
+00155         _NewDisconnectionCallback = cbnbNewDisconnection;
+00156 
+00157         _BytesSent = 0;
+00158         _BytesReceived = 0;
+00159 
+00160         createDebug(); // for addNegativeFilter to work even in release and releasedebug modes
+00161 
+00162         // add the callback needed to associate messages with id
+00163         addCallbackArray (cbnbMessageAssociationArray, sizeof (cbnbMessageAssociationArray) / sizeof (cbnbMessageAssociationArray[0]));
+00164 
+00165 #ifdef USE_MESSAGE_RECORDER
+00166         switch ( _MR_RecordingState )
+00167         {
+00168         case Record :
+00169                 _MR_Recorder.startRecord( recfilename, recordall );
+00170                 break;
+00171         case Replay :
+00172                 _MR_Recorder.startReplay( recfilename );
+00173                 break;
+00174         default:;
+00175                 // No recording
+00176         }
+00177 #endif
+00178 }
+
+
+


Member Function Documentation

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
void NLNET::CCallbackNetBase::addCallbackArray const TCallbackItem callbackarray,
NLMISC::CStringIdArray::TStringId  arraysize
+
+ + + + + +
+   + + +

+Appends callback array with the specified array. You can add callback only *after* adding the server or the client.

Parameters:
+ + +
arraysize is the number of callback items.
+
+ +

+Definition at line 184 of file callback_net_base.cpp. +

+References _CallbackArray, _OutputSIDA, NLMISC::CStringIdArray::addString(), NLNET::TCallbackItem::Callback, checkThreadId(), nlassert, NLMISC::CStringIdArray::resize(), sint, NLMISC::CStringIdArray::size(), NLMISC::CStringIdArray::TStringId, and uint. +

+Referenced by NLNET::CCallbackClient::CCallbackClient(), CCallbackNetBase(), NLNET::CPacsClient::connect(), NLNET::CNamingClient::connect(), NLNET::CLoginClient::connectToShard(), NLNET::CUnifiedNetwork::init(), NLNET::CLoginServer::init(), and NLNET::_CUniTime::installServer(). +

+

00185 {
+00186         checkThreadId ();
+00187 
+00188         // be sure that the 2 array have the same size
+00189         nlassert (_CallbackArray.size () == (uint)_OutputSIDA.size ());
+00190 
+00191         if (arraysize == 1 && callbackarray[0].Callback == NULL && string("") == callbackarray[0].Key)
+00192         {
+00193                 // it's an empty array, ignore it
+00194                 return;
+00195         }
+00196 
+00197         // resize the array
+00198         sint oldsize = _CallbackArray.size();
+00199 
+00200         _CallbackArray.resize (oldsize + arraysize);
+00201         _OutputSIDA.resize (oldsize + arraysize);
+00202 
+00203 //TOO MUCH MESSAGE      nldebug ("L3NB_CB: Adding %d callback to the array", arraysize);
+00204 
+00205         for (sint i = 0; i < arraysize; i++)
+00206         {
+00207                 CStringIdArray::TStringId ni = oldsize + i;
+00208 //TOO MUCH MESSAGE              nldebug ("L3NB_CB: Adding callback to message '%s', id '%d'", callbackarray[i].Key, ni);
+00209                 // copy callback value
+00210                 
+00211                 _CallbackArray[ni] = callbackarray[i];
+00212                 // add the string to the string id array
+00213                 _OutputSIDA.addString (callbackarray[i].Key, ni);
+00214 
+00215         }
+00216 //      nldebug ("LNETL3NB_CB: Added %d callback Now, there're %d callback associated with message type", arraysize, _CallbackArray.size ());
+00217 }
+
+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
void NLNET::CCallbackNetBase::authorizeOnly const char *  callbackName,
TSockId  hostid = InvalidSockId
+
+ + + + + +
+   + + +

+Sets the callback that you want the other side calls. If it didn't call this callback, it will be disconnected If cb is NULL, we authorize *all* callback. On a client, the hostid must be InvalidSockId (or ommited). On a server, you must provide a hostid. +

+Definition at line 471 of file callback_net_base.cpp. +

+References NLNET::CBufSock::asString(), NLNET::CBufSock::AuthorizedCallback, checkThreadId(), getSockId(), nlassert, nldebug, and NLNET::TSockId. +

+Referenced by NLNET::cbShardValidation(), and NLNET::ClientConnection(). +

+

00472 {
+00473         checkThreadId ();
+00474 
+00475         nldebug ("LNETL3NB: authorizeOnly (%s, %s)", callbackName, hostid->asString().c_str());
+00476 
+00477         hostid = getSockId (hostid);
+00478         
+00479         nlassert (hostid != InvalidSockId);
+00480 
+00481         hostid->AuthorizedCallback = (callbackName == NULL)?"":callbackName;
+00482 }
+
+

+ + + + +
+ + + + + + + + + + +
void NLNET::CCallbackNetBase::baseUpdate sint32  timeout = 0  )  [protected]
+
+ + + + + +
+   + + +

+Used by client and server class. +

+ +

+Definition at line 328 of file callback_net_base.cpp. +

+References _FirstUpdate, _InputSIDA, _LastMovedStringArray, _LastUpdateTime, checkThreadId(), dataAvailable(), NLMISC::CStringIdArray::getAskedStringArray(), NLMISC::CStringIdArray::getNeedToAskedStringArray(), H_AUTO, NLMISC::CStringIdArray::moveNeedToAskToAskedStringArray(), nlassert, nldebug, NLMISC::nlSleep(), processOneMessage(), send(), NLMISC::CMemStream::serial(), sint32, size, NLMISC::CStringIdArray::TStringId, and NLMISC::TTime. +

+Referenced by NLNET::CCallbackServer::update(), and NLNET::CCallbackClient::update(). +

+

00329 {
+00330         H_AUTO(L3UpdateCallbackNetBase);
+00331 
+00332         checkThreadId ();
+00333 
+00334         // slow down the layer H_AUTO (CCallbackNetBase_baseUpdate);
+00335 
+00336         nlassert( timeout >= -1 );
+00337         TTime t0 = CTime::getLocalTime();
+00338 
+00339         //
+00340         // The first time, we init time counters
+00341         //
+00342         if (_FirstUpdate)
+00343         {
+00344 //              nldebug("LNETL3NB: First update()");
+00345                 _FirstUpdate = false;
+00346                 _LastUpdateTime = t0;
+00347                 _LastMovedStringArray = t0;
+00348         }
+00349 
+00350         //
+00351         // Every 1 seconds if we have new unknown association, we ask them to the other side
+00352         //
+00353         if (t0 - _LastUpdateTime >  1000)
+00354         {
+00355 //              nldebug("LNETL3NB: baseUpdate()");
+00356                 _LastUpdateTime = t0;
+00357 
+00358                 const set<string> &sa = _InputSIDA.getNeedToAskedStringArray ();
+00359                 if (!sa.empty ())
+00360                 {
+00361                         CMessage msgout (_InputSIDA, "AA");
+00362                         //nlassert (sa.size () < 65536); // no size limit anymore
+00363                         CStringIdArray::TStringId size = sa.size ();
+00364                         nldebug ("LNETL3NB_ASSOC: I need %d string association, ask them to the other side", size);
+00365                         msgout.serial (size);
+00366                         for (set<string>::iterator it = sa.begin(); it != sa.end(); it++)
+00367                         {
+00368                                 nldebug ("LNETL3NB_ASSOC:  what is the id of '%s'?", (*it).c_str ());
+00369                                 string str(*it);
+00370                                 msgout.serial (str);
+00371                         }
+00372                         // send the message to the other side
+00373                         send (msgout, 0);
+00374                         _InputSIDA.moveNeedToAskToAskedStringArray();
+00375                         _LastMovedStringArray = t0;
+00376                 }
+00377         }
+00378 
+00379         //
+00380         // Every 60 seconds if we have not answered association, we ask again to get them!
+00381         //
+00382         if (!_InputSIDA.getAskedStringArray().empty() && t0 - _LastMovedStringArray > 60000)
+00383         {
+00384                 // we didn't have an answer for the association, resend them
+00385                 const set<string> sa = _InputSIDA.getAskedStringArray ();
+00386                 CMessage msgout (_InputSIDA, "AA");
+00387                 //nlassert (sa.size () < 65536); // no size limit anymore
+00388                 CStringIdArray::TStringId size = sa.size ();
+00389                 nldebug ("LNETL3NB_ASSOC: client didn't answer my asked association, retry! I need %d string association, ask them to the other side", size);
+00390                 msgout.serial (size);
+00391                 for (set<string>::iterator it = sa.begin(); it != sa.end(); it++)
+00392                 {
+00393                         nldebug ("LNETL3NB_ASSOC:  what is the id of '%s'?", (*it).c_str ());
+00394                         string str(*it);
+00395                         msgout.serial (str);
+00396                 }
+00397                 // sends the message to the other side
+00398                 send (msgout, 0);
+00399                 _LastMovedStringArray = t0;
+00400         }
+00401 
+00402         /*
+00403          * timeout -1    =>  read one message in the queue or nothing if no message in queue
+00404          * timeout 0     =>  read all messages in the queue
+00405          * timeout other =>  read all messages in the queue until timeout expired (at least all one time)
+00406          */
+00407 
+00408         bool exit = false;
+00409 
+00410         while (!exit)
+00411         {
+00412                 // process all messages in the queue
+00413                 while (dataAvailable ())
+00414                 {
+00415                         processOneMessage ();
+00416                         if (timeout == -1)
+00417                         {
+00418                                 exit = true;
+00419                                 break;
+00420                         }
+00421                 }
+00422 
+00423                 // need to exit?
+00424                 if (timeout == 0 || (sint32)(CTime::getLocalTime() - t0) > timeout)
+00425                 {
+00426                         exit = true;
+00427                 }
+00428                 else
+00429                 {
+00430                         // enable multithreading on windows :-/
+00431                         // slow down the layer H_AUTO (CCallbackNetBase_baseUpdate_nlSleep);
+00432                         nlSleep (10);
+00433                 }
+00434         }
+00435 
+00436 #ifdef USE_MESSAGE_RECORDER
+00437         _MR_UpdateCounter++;
+00438 #endif
+00439 
+00440 }
+
+

+ + + + +
+ + + + + + + + + +
void NLNET::CCallbackNetBase::checkThreadId  )  const [protected]
+
+ + + + + +
+   + + +

+ +

+Definition at line 533 of file callback_net_base.cpp. +

+Referenced by addCallbackArray(), authorizeOnly(), baseUpdate(), NLNET::CCallbackClient::connect(), NLNET::CCallbackServer::connected(), NLNET::CCallbackClient::connected(), NLNET::CCallbackServer::dataAvailable(), NLNET::CCallbackClient::dataAvailable(), NLNET::CCallbackServer::disconnect(), NLNET::CCallbackClient::disconnect(), displayAllMyAssociations(), NLNET::CCallbackServer::flush(), NLNET::CCallbackClient::flush(), NLNET::CCallbackServer::getSockId(), NLNET::CCallbackClient::getSockId(), NLNET::CCallbackServer::hostAddress(), isAServer(), processOneMessage(), NLNET::CCallbackServer::receive(), NLNET::CCallbackClient::receive(), NLNET::CCallbackServer::send(), NLNET::CCallbackClient::send(), NLNET::CCallbackServer::sendAllMyAssociations(), NLNET::CCallbackServer::setConnectionCallback(), NLNET::CCallbackServer::setDisconnectionCallback(), setDisconnectionCallback(), NLNET::CCallbackClient::setDisconnectionCallback(), setOtherSideAssociations(), NLNET::CCallbackServer::update(), and NLNET::CCallbackClient::update(). +

+

00534 {
+00535 /*      some people use this class in different thread but with a mutex to be sure to have
+00536         no concurent access
+00537         if (getThreadId () != _ThreadId)
+00538         {
+00539                 nlerror ("You try to access to the same CCallbackClient or CCallbackServer with 2 differents thread (%d and %d)", _ThreadId, getThreadId());
+00540         }
+00541 */
+00542 }
+
+

+ + + + +
+ + + + + + + + + +
virtual bool NLNET::CCallbackNetBase::connected  )  const [inline, virtual]
+
+ + + + + +
+   + + +

+This function is implemented in the client and server class. +

+ +

+Reimplemented in NLNET::CCallbackClient, and NLNET::CCallbackServer. +

+Definition at line 136 of file callback_net_base.h. +

+References nlstop. +

+

00136 { nlstop; return false; }
+
+

+ + + + +
+ + + + + + + + + +
virtual bool NLNET::CCallbackNetBase::dataAvailable  )  [inline, virtual]
+
+ + + + + +
+   + + +

+This function is implemented in the client and server class. +

+ +

+Reimplemented in NLNET::CCallbackClient, and NLNET::CCallbackServer. +

+Definition at line 132 of file callback_net_base.h. +

+References nlstop. +

+Referenced by baseUpdate(). +

+

00132 { nlstop; return false; }
+
+

+ + + + +
+ + + + + + + + + + +
virtual void NLNET::CCallbackNetBase::disconnect TSockId  hostid = InvalidSockId  )  [inline, virtual]
+
+ + + + + +
+   + + +

+This function is implemented in the client and server class. +

+ +

+Reimplemented in NLNET::CCallbackClient, and NLNET::CCallbackServer. +

+Definition at line 138 of file callback_net_base.h. +

+References nlstop, and NLNET::TSockId. +

+Referenced by NLNET::cbShardValidation(), processOneMessage(), NLNET::CUnifiedNetwork::CUnifiedConnection::TConnection::reset(), and NLNET::uncbServiceIdentification(). +

+

00138 { nlstop; }
+
+

+ + + + +
+ + + + + + + + + +
void NLNET::CCallbackNetBase::displayAllMyAssociations  ) 
+
+ + + + + +
+   + + +

+ +

+Definition at line 464 of file callback_net_base.cpp. +

+References _OutputSIDA, checkThreadId(), and NLMISC::CStringIdArray::display(). +

+Referenced by NLNET::CLoginClient::connectToShard(). +

+

00465 {
+00466         checkThreadId ();
+00467 
+00468         _OutputSIDA.display ();
+00469 }
+
+

+ + + + +
+ + + + + + + + + + +
virtual void NLNET::CCallbackNetBase::displayReceiveQueueStat NLMISC::CLog log = NLMISC::InfoLog  )  [pure virtual]
+
+ + + + + +
+   + + +

+ +

+Implemented in NLNET::CCallbackClient, and NLNET::CCallbackServer.

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
virtual void NLNET::CCallbackNetBase::displaySendQueueStat NLMISC::CLog log = NLMISC::InfoLog,
TSockId  destid = InvalidSockId
[pure virtual]
+
+ + + + + +
+   + + +

+ +

+Implemented in NLNET::CCallbackClient, and NLNET::CCallbackServer.

+

+ + + + +
+ + + + + + + + + + +
virtual void NLNET::CCallbackNetBase::displayThreadStat NLMISC::CLog log = NLMISC::InfoLog  )  [pure virtual]
+
+ + + + + +
+   + + +

+ +

+Implemented in NLNET::CCallbackClient, and NLNET::CCallbackServer.

+

+ + + + +
+ + + + + + + + + + +
virtual bool NLNET::CCallbackNetBase::flush TSockId  hostid = InvalidSockId  )  [pure virtual]
+
+ + + + + +
+   + + +

+Force to send all data pending in the send queue. On a client, the hostid isn't used and must be InvalidSockId On a server, you must provide a hostid. +

+Implemented in NLNET::CCallbackClient, and NLNET::CCallbackServer.

+

+ + + + +
+ + + + + + + + + +
uint64 NLNET::CCallbackNetBase::getBytesReceived  )  [inline]
+
+ + + + + +
+   + + +

+ +

+Definition at line 88 of file callback_net_base.h. +

+References _BytesReceived, and uint64. +

+Referenced by NLNET::CUnifiedNetwork::getBytesReceived(). +

+

00088 { return _BytesReceived; }
+
+

+ + + + +
+ + + + + + + + + +
uint64 NLNET::CCallbackNetBase::getBytesSent  )  [inline]
+
+ + + + + +
+   + + +

+ +

+Definition at line 87 of file callback_net_base.h. +

+References _BytesSent, and uint64. +

+Referenced by NLNET::CUnifiedNetwork::getBytesSent(). +

+

00087 { return _BytesSent; }
+
+

+ + + + +
+ + + + + + + + + +
virtual uint64 NLNET::CCallbackNetBase::getReceiveQueueSize  )  [pure virtual]
+
+ + + + + +
+   + + +

+ +

+Implemented in NLNET::CCallbackClient, and NLNET::CCallbackServer.

+

+ + + + +
+ + + + + + + + + +
virtual uint64 NLNET::CCallbackNetBase::getSendQueueSize  )  [pure virtual]
+
+ + + + + +
+   + + +

+ +

+Implemented in NLNET::CCallbackClient, and NLNET::CCallbackServer.

+

+ + + + +
+ + + + + + + + + +
NLMISC::CStringIdArray& NLNET::CCallbackNetBase::getSIDA  )  [inline]
+
+ + + + + +
+   + + +

+Use this function to get the String ID Array needed when you want to create a message. +

+ +

+Definition at line 129 of file callback_net_base.h. +

+References _InputSIDA. +

+Referenced by NLNET::cbcMessageRecvAllAssociations(), NLNET::cbnbMessageAskAssociations(), NLNET::cbnbMessageRecvAssociations(), NLNET::cbServerAskUniversalTime(), NLNET::cbShardValidation(), NLNET::CLoginClient::connectToShard(), NLNET::CNetDisplayer::doDisplay(), NLNET::CNamingClient::queryServicePort(), NLNET::CNamingClient::registerService(), NLNET::CNamingClient::registerServiceWithSId(), NLNET::CNamingClient::resendRegisteration(), NLNET::CCallbackServer::sendAllMyAssociations(), setOtherSideAssociations(), and NLNET::CNamingClient::unregisterService(). +

+

00129 { return _InputSIDA; }
+
+

+ + + + +
+ + + + + + + + + + +
virtual TSockId NLNET::CCallbackNetBase::getSockId TSockId  hostid = InvalidSockId  )  [pure virtual]
+
+ + + + + +
+   + + +

+returns the sockid of a connection. On a server, this function returns the parameter. On a client, it returns the connection. +

+ +

+Implemented in NLNET::CCallbackClient, and NLNET::CCallbackServer. +

+Referenced by authorizeOnly(), NLNET::CUnifiedNetwork::CUnifiedConnection::TConnection::getAppId(), processOneMessage(), and NLNET::CUnifiedNetwork::CUnifiedConnection::TConnection::setAppId().

+

+ + + + +
+ + + + + + + + + + +
const CInetAddress & NLNET::CCallbackNetBase::hostAddress TSockId  hostid  )  [virtual]
+
+ + + + + +
+   + + +

+Returns the address of the specified host. +

+ +

+Reimplemented in NLNET::CCallbackClient, and NLNET::CCallbackServer. +

+Definition at line 443 of file callback_net_base.cpp. +

+References nlstop, and NLNET::TSockId. +

+Referenced by NLNET::cbServerAskUniversalTime(), NLNET::cbShardValidation(), and NLNET::uncbServiceIdentification(). +

+

00444 {
+00445         // should never be called
+00446         nlstop;
+00447         static CInetAddress tmp;
+00448         return tmp;
+00449 }
+
+

+ + + + +
+ + + + + + + + + + +
void NLNET::CCallbackNetBase::ignoreAllUnknownId bool  b  )  [inline]
+
+ + + + + +
+   + + +

+If you ignore all unknown id, the net will not ask for other side to know new association. It's used in the naming service for example because the naming client will never answer. In this case, it will always send the message with the full string name (slower) +

+Definition at line 157 of file callback_net_base.h. +

+References _InputSIDA, and NLMISC::CStringIdArray::ignoreAllUnknownId(). +

+

00158         {
+00159                 _InputSIDA.ignoreAllUnknownId (b);
+00160         }
+
+

+ + + + +
+ + + + + + + + + +
bool NLNET::CCallbackNetBase::isAServer  )  const [inline]
+
+ + + + + +
+   + + +

+Returns true if this is a CCallbackServer. +

+ +

+Definition at line 126 of file callback_net_base.h. +

+References _IsAServer, and checkThreadId(). +

+

00126 { checkThreadId (); return _IsAServer; }
+
+

+ + + + +
+ + + + + + + + + +
void NLNET::CCallbackNetBase::processOneMessage  )  [protected]
+
+ + + + + +
+   + + +

+Read a message from the network and process it. +

+ +

+Definition at line 223 of file callback_net_base.cpp. +

+References _BytesReceived, _CallbackArray, _DefaultCallback, _OutputSIDA, NLNET::CBufSock::asString(), NLNET::CBufSock::AuthorizedCallback, checkThreadId(), disconnect(), NLNET::CMessage::getId(), NLNET::CMessage::getName(), getSockId(), NLNET::CMessage::length(), nldebug, nlwarning, receive(), sint16, NLNET::TMsgCallback, NLNET::CMessage::toString(), NLNET::TSockId, NLMISC::CStringIdArray::TStringId, and NLNET::CMessage::TypeHasAnId. +

+Referenced by baseUpdate(). +

+

00224 {
+00225         checkThreadId ();
+00226 
+00227         // slow down the layer H_AUTO (CCallbackNetBase_processOneMessage);
+00228 
+00229         CMessage msgin (_OutputSIDA, "", true);
+00230         TSockId tsid;
+00231         receive (msgin, &tsid);
+00232 
+00233         _BytesReceived += msgin.length ();
+00234         
+00235         // now, we have to call the good callback
+00236         NLMISC::CStringIdArray::TStringId pos = -1;
+00237         if (msgin.TypeHasAnId)
+00238         {
+00239                 pos = msgin.getId ();
+00240         }
+00241         else
+00242         {
+00243                 std::string name = msgin.getName ();
+00244                 sint16 i;
+00245                 for (i = 0; i < (sint16) _CallbackArray.size (); i++)
+00246                 {
+00247                         if (name == _CallbackArray[i].Key)
+00248                         {
+00249                                 pos = i;
+00250                                 break;
+00251                         }
+00252                 }
+00253         }
+00254 
+00255         TMsgCallback    cb = NULL;
+00256         if (pos < 0 || pos >= (sint16) _CallbackArray.size ())
+00257         {
+00258                 if (_DefaultCallback == NULL)
+00259                 {
+00260                         nlwarning ("LNETL3NB_CB: Callback %s not found in _CallbackArray", msgin.toString().c_str());
+00261                 }
+00262                 else
+00263                 {
+00264                         cb = _DefaultCallback;
+00265                 }
+00266         }
+00267         else
+00268         {
+00269                 cb = _CallbackArray[pos].Callback;
+00270         }
+00271 
+00272         TSockId realid = getSockId (tsid);
+00273 
+00274         if (!realid->AuthorizedCallback.empty() && msgin.getName() != realid->AuthorizedCallback)
+00275         {
+00276                 nlwarning ("LNETL3NB_CB: %s try to call the callback %s but only %s is authorized. Disconnect him!", tsid->asString().c_str(), msgin.toString().c_str(), tsid->AuthorizedCallback.c_str());
+00277                 disconnect (tsid);
+00278         }
+00279         else if (cb == NULL)
+00280         {
+00281                 nlwarning ("LNETL3NB_CB: Callback %s is NULL, can't call it", msgin.toString().c_str());
+00282         }
+00283         else
+00284         {
+00285                 nldebug ("LNETL3NB_CB: Calling callback (%s)%s", msgin.getName().c_str(), (cb==_DefaultCallback)?" DEFAULT_CB":"");
+00286                 cb(msgin, realid, *this);
+00287         }
+00288         
+00289 /*
+00290         if (pos < 0 || pos >= (sint16) _CallbackArray.size ())
+00291         {
+00292                 if (_DefaultCallback == NULL)
+00293                         nlwarning ("LNETL3NB_CB: Callback %s not found in _CallbackArray", msgin.toString().c_str());
+00294                 else
+00295                 {
+00296                         // ...
+00297                 }
+00298         }
+00299         else
+00300         {
+00301                 TSockId realid = getSockId (tsid);
+00302 
+00303                 if (!realid->AuthorizedCallback.empty() && msgin.getName() != realid->AuthorizedCallback)
+00304                 {
+00305                         nlwarning ("LNETL3NB_CB: %s try to call the callback %s but only %s is authorized. Disconnect him!", tsid->asString().c_str(), msgin.toString().c_str(), tsid->AuthorizedCallback.c_str());
+00306                         disconnect (tsid);
+00307                 }
+00308                 else if (_CallbackArray[pos].Callback == NULL)
+00309                 {
+00310                         nlwarning ("LNETL3NB_CB: Callback %s is NULL, can't call it", msgin.toString().c_str());
+00311                 }
+00312                 else
+00313                 {
+00314                         nldebug ("LNETL3NB_CB: Calling callback (%s)", _CallbackArray[pos].Key);
+00315                         _CallbackArray[pos].Callback (msgin, realid, *this);
+00316                 }
+00317         }
+00318 */
+00319 }
+
+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
virtual void NLNET::CCallbackNetBase::receive CMessage buffer,
TSockId hostid
[protected, pure virtual]
+
+ + + + + +
+   + + +

+On this layer, you can't call directly receive, It s the update() function that receive and call your callaback. +

+ +

+Implemented in NLNET::CCallbackClient, and NLNET::CCallbackServer. +

+Referenced by processOneMessage().

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
virtual void NLNET::CCallbackNetBase::send const CMessage buffer,
TSockId  hostid = InvalidSockId,
bool  log = true
[pure virtual]
+
+ + + + + +
+   + + +

+Sends a message to special connection. On a client, the hostid isn't used. On a server, you must provide a hostid. If you hostid = InvalidSockId, the message will be sent to all connected client. +

+Implemented in NLNET::CCallbackClient, and NLNET::CCallbackServer. +

+Referenced by baseUpdate(), NLNET::cbnbMessageAskAssociations(), NLNET::cbServerAskUniversalTime(), NLNET::cbShardValidation(), and NLNET::NLMISC_COMMAND().

+

+ + + + +
+ + + + + + + + + + +
void NLNET::CCallbackNetBase::sendAllMyAssociations TSockId  to  ) 
+
+ + + + + +
+   + + +

+Used by client and server class. +

+ +

+Reimplemented in NLNET::CCallbackServer.

+

+ + + + +
+ + + + + + + + + + +
void NLNET::CCallbackNetBase::setDefaultCallback TMsgCallback  defaultCallback  )  [inline]
+
+ + + + + +
+   + + +

+Sets default callback for unknown message types. +

+ +

+Definition at line 110 of file callback_net_base.h. +

+References _DefaultCallback, and NLNET::TMsgCallback. +

+Referenced by NLNET::CUnifiedNetwork::addService(), and NLNET::CUnifiedNetwork::init(). +

+

00110 { _DefaultCallback = defaultCallback; }
+
+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
void NLNET::CCallbackNetBase::setDisconnectionCallback TNetCallback  cb,
void *  arg
[inline]
+
+ + + + + +
+   + + +

+Sets callback for disconnections (or NULL to disable callback). +

+ +

+Reimplemented in NLNET::CCallbackClient, and NLNET::CCallbackServer. +

+Definition at line 113 of file callback_net_base.h. +

+References checkThreadId(), and NLNET::TNetCallback. +

+

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
void NLNET::CCallbackNetBase::setOtherSideAssociations const char **  associationarray,
NLMISC::CStringIdArray::TStringId  arraysize
+
+ + + + + +
+   + + +

+Gives some association of the other side. The goal is, in specific case, we don't want to ask associations to the other side (client is not secure for example). In this case, we can set other side associations by hand using this functions. +

+Definition at line 451 of file callback_net_base.cpp. +

+References NLMISC::CStringIdArray::addString(), checkThreadId(), getSIDA(), nldebug, sint, and NLMISC::CStringIdArray::TStringId. +

+

00452 {
+00453         checkThreadId ();
+00454 
+00455         nldebug ("LNETL3NB_ASSOC: setOtherSideAssociations() sets %d association strings", arraysize);
+00456 
+00457         for (sint i = 0; i < arraysize; i++)
+00458         {
+00459                 nldebug ("LNETL3NB_ASSOC:  association '%s' -> %d", associationarray[i], i);
+00460                 getSIDA().addString (associationarray[i], i);
+00461         }
+00462 }
+
+

+ + + + +
+ + + + + + + + + + +
virtual void NLNET::CCallbackNetBase::update sint32  timeout = 0  )  [inline, virtual]
+
+ + + + + +
+   + + +

+This function is implemented in the client and server class. +

+ +

+Reimplemented in NLNET::CCallbackClient, and NLNET::CCallbackServer. +

+Definition at line 134 of file callback_net_base.h. +

+References nlstop, and sint32. +

+

00134 { nlstop; }
+
+


Friends And Related Function Documentation

+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
void cbnbMessageAskAssociations CMessage msgin,
TSockId  from,
CCallbackNetBase netbase
[friend]
+
+ + + + + +
+   + + +

+ +

+Definition at line 88 of file callback_net_base.cpp. +

+

00089 {
+00090         CMessage msgout (netbase.getSIDA(), "RA");
+00091         CStringIdArray::TStringId size;
+00092         msgin.serial (size);
+00093 
+00094         nldebug ("LNETL3NB_ASSOC: The other side want %d string associations", size);
+00095 
+00096         msgout.serial (size);
+00097 
+00098         for (sint i = 0; i < size; i++)
+00099         {
+00100                 string name;
+00101                 msgin.serial (name);
+00102                 nldebug ("LNETL3NB_ASSOC:  sending association '%s' -> %d", name.c_str (), netbase._OutputSIDA.getId(name));
+00103 
+00104                 // if this assert occurs, it means that the other side ask an unknown message
+00105                 // or that there are different types of client (with differents callbackarray) and one of the client doesn't have this callback
+00106                 nlassert(netbase._OutputSIDA.getId(name) != -1);
+00107 
+00108                 msgout.serial (name);
+00109 
+00110                 CStringIdArray::TStringId id = netbase._OutputSIDA.getId (name);
+00111                 msgout.serial (id);
+00112         }
+00113         // send the message to the other side
+00114         netbase.send (msgout, from);
+00115 }
+
+

+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
void cbnbMessageRecvAssociations CMessage msgin,
TSockId  from,
CCallbackNetBase netbase
[friend]
+
+ + + + + +
+   + + +

+ +

+Definition at line 55 of file callback_net_base.cpp. +

+

00056 {
+00057         // receive a new message association
+00058 
+00059         CStringIdArray::TStringId size;
+00060         msgin.serial (size);
+00061 
+00062         nldebug ("LNETL3NB_ASSOC: The other side gave me %d association strings", size);
+00063 
+00064         for (CStringIdArray::TStringId i = 0; i < size; i++)
+00065         {
+00066                 std::string name;
+00067                 CStringIdArray::TStringId id;
+00068 
+00069                 msgin.serial (name);
+00070                 msgin.serial (id);
+00071 
+00072                 // if id == -1, it means that there are no callback associated to this message
+00073                 // it should not happen, it mean that one side send a message that the other side
+00074                 // can't manage in his callbackarray.
+00075                 // to resolve the problem, add the callback in the callbackarray in the other side
+00076                 // and put NULL if you don't want to manage this message
+00077                 nlassert (id != -1);
+00078 
+00079                 nldebug ("LNETL3NB_ASSOC:  association '%s' -> %d", name.c_str (), id);
+00080                 netbase.getSIDA().addString (name, id);
+00081         }
+00082 }
+
+

+ + + + +
+ + + + + + + + + + + + + + + + + + + +
void cbnbNewDisconnection TSockId  from,
void *  data
[friend]
+
+ + + + + +
+   + + +

+ +

+Definition at line 127 of file callback_net_base.cpp. +

+

00128 {
+00129         nlassert (data != NULL);
+00130         CCallbackNetBase *base = (CCallbackNetBase *)data;
+00131 
+00132         nldebug("LNETL3NB: cbnbNewDisconnection()");
+00133 
+00134 #ifdef USE_MESSAGE_RECORDER
+00135         // Record or replay disconnection
+00136         base->noticeDisconnection( from );
+00137 #endif
+00138         
+00139         // Call the client callback if necessary
+00140         if (base->_DisconnectionCallback != NULL)
+00141                 base->_DisconnectionCallback (from, base->_DisconnectionCbArg);
+00142 }
+
+


Field Documentation

+

+ + + + +
+ + +
uint64 NLNET::CCallbackNetBase::_BytesReceived [protected] +
+
+ + + + + +
+   + + +

+ +

+Definition at line 167 of file callback_net_base.h. +

+Referenced by CCallbackNetBase(), getBytesReceived(), and processOneMessage().

+

+ + + + +
+ + +
uint64 NLNET::CCallbackNetBase::_BytesSent [protected] +
+
+ + + + + +
+   + + +

+ +

+Definition at line 167 of file callback_net_base.h. +

+Referenced by CCallbackNetBase(), and getBytesSent().

+

+ + + + +
+ + +
std::vector<TCallbackItem> NLNET::CCallbackNetBase::_CallbackArray [protected] +
+
+ + + + + +
+   + + +

+ +

+Definition at line 196 of file callback_net_base.h. +

+Referenced by addCallbackArray(), and processOneMessage().

+

+ + + + +
+ + +
TMsgCallback NLNET::CCallbackNetBase::_DefaultCallback [protected] +
+
+ + + + + +
+   + + +

+ +

+Definition at line 199 of file callback_net_base.h. +

+Referenced by processOneMessage(), and setDefaultCallback().

+

+ + + + +
+ + +
TNetCallback NLNET::CCallbackNetBase::_DisconnectionCallback [private] +
+
+ + + + + +
+   + + +

+ +

+Definition at line 222 of file callback_net_base.h. +

+Referenced by NLNET::cbnbNewDisconnection().

+

+ + + + +
+ + +
void* NLNET::CCallbackNetBase::_DisconnectionCbArg [private] +
+
+ + + + + +
+   + + +

+ +

+Definition at line 223 of file callback_net_base.h. +

+Referenced by NLNET::cbnbNewDisconnection().

+

+ + + + +
+ + +
bool NLNET::CCallbackNetBase::_FirstUpdate [protected] +
+
+ + + + + +
+   + + +

+ +

+Definition at line 202 of file callback_net_base.h. +

+Referenced by baseUpdate().

+

+ + + + +
+ + +
NLMISC::CStringIdArray NLNET::CCallbackNetBase::_InputSIDA [protected] +
+
+ + + + + +
+   + + +

+ +

+Definition at line 188 of file callback_net_base.h. +

+Referenced by baseUpdate(), getSIDA(), and ignoreAllUnknownId().

+

+ + + + +
+ + +
bool NLNET::CCallbackNetBase::_IsAServer [protected] +
+
+ + + + + +
+   + + +

+ +

+Definition at line 201 of file callback_net_base.h. +

+Referenced by isAServer().

+

+ + + + +
+ + +
NLMISC::TTime NLNET::CCallbackNetBase::_LastMovedStringArray [private] +
+
+ + + + + +
+   + + +

+ +

+Definition at line 220 of file callback_net_base.h. +

+Referenced by baseUpdate().

+

+ + + + +
+ + +
NLMISC::TTime NLNET::CCallbackNetBase::_LastUpdateTime [private] +
+
+ + + + + +
+   + + +

+ +

+Definition at line 219 of file callback_net_base.h. +

+Referenced by baseUpdate().

+

+ + + + +
+ + +
TNetCallback NLNET::CCallbackNetBase::_NewDisconnectionCallback [protected] +
+
+ + + + + +
+   + + +

+Used by client and server class. +

+ +

+Definition at line 170 of file callback_net_base.h. +

+Referenced by CCallbackNetBase().

+

+ + + + +
+ + +
NLMISC::CStringIdArray NLNET::CCallbackNetBase::_OutputSIDA [protected] +
+
+ + + + + +
+   + + +

+ +

+Definition at line 193 of file callback_net_base.h. +

+Referenced by addCallbackArray(), NLNET::cbnbMessageAskAssociations(), displayAllMyAssociations(), and processOneMessage().

+

+ + + + +
+ + +
uint NLNET::CCallbackNetBase::_ThreadId [protected] +
+
+ + + + + +
+   + + +

+

Todo:
ace: debug feature that we should remove one day nefore releasing the game
+ +

+Definition at line 232 of file callback_net_base.h. +

+Referenced by CCallbackNetBase().

+


The documentation for this class was generated from the following files: +
Generated on Tue Mar 16 13:55:30 2004 for NeL by + +doxygen +1.3.6
+ + -- cgit v1.2.1