Torque2D Reference

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes

- Class List
- Class Index
- Class Hierarchy
- Class Members

Classes | Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | Protected Member Functions | Protected Attributes | Static Protected Attributes | Friends | List of all members
NetConnection Class Reference

`#include <netConnection.h>`

Inheritance diagram for NetConnection:

## Classes
struct | GhostRef
struct | GhostSave
| Structure to track ghost-always objects and their ghost indices. More...
struct | PacketNotify

## Public Types
enum | Constants { HashTableSize = 127 }
enum | NetConnectionFlags { ConnectionToServer = BIT(0), ConnectionToClient = BIT(1), LocalClientConnection = BIT(2), NetworkConnection = BIT(3) }
enum | NetConnectionState { NotConnected, AwaitingChallengeResponse, AwaitingConnectRequest, AwaitingConnectResponse, Connected }
Public Types inherited from SimSet
typedef SimObjectList::iterator | iterator
typedef SimObjectList::value_type | value
Public Types inherited from SimObject
enum | WriteFlags { SelectedOnly = BIT(0) }

## Public Member Functions
void | sendDisconnectPacket (const char *reason)
virtual bool | canRemoteCreate ()
virtual void | onTimedOut ()
virtual void | onConnectTimedOut ()
virtual void | onDisconnect (const char *reason)
virtual void | onConnectionRejected (const char *reason)
virtual void | onConnectionEstablished (bool isInitiator)
virtual void | handleStartupError (const char *errorString)
virtual void | writeConnectRequest (BitStream *stream)
virtual bool | readConnectRequest (BitStream *stream, const char **errorString)
virtual void | writeConnectAccept (BitStream *stream)
virtual bool | readConnectAccept (BitStream *stream, const char **errorString)
void | connect (const NetAddress *address)
U32 | getNetClassGroup ()
void | setSimulatedNetParams (F32 packetLoss, U32 ping)
bool | isConnectionToServer ()
bool | isLocalConnection ()
bool | isNetworkConnection ()
void | setIsConnectionToServer ()
void | setIsLocalClientConnection ()
void | setNetworkConnection (bool net)
virtual void | setEstablished ()
void | setRemoteConnectionObject (NetConnection *connection)
| Call this if the "connection" is local to this app. This short-circuits the protocol layer. More...
void | setSequence (U32 connectSequence)
void | setAddressDigest (U32 digest[4])
void | getAddressDigest (U32 digest[4])
U32 | getSequence ()
void | setProtocolVersion (U32 protocolVersion)
U32 | getProtocolVersion ()
F32 | getRoundTripTime ()
F32 | getPacketLoss ()
void | checkMaxRate ()
void | handlePacket (BitStream *stream)
void | processRawPacket (BitStream *stream)
void | handleNotify (bool recvd)
void | handleConnectionEstablished ()
void | keepAlive ()
const NetAddress * | getNetAddress ()
void | setNetAddress (const NetAddress *address)
Net::Error | sendPacket (BitStream *stream)
bool | checkTimeout (U32 time)
| returns true if the connection timed out More...
void | checkPacketSend (bool force)
bool | missionPathsSent () const
void | setMissionPathsSent (const bool s)
void | onRemove ()
| Called when the object is removed from the sim. More...
| NetConnection ()
| ~NetConnection ()
void | setConnectionState (U32 state)
U32 | getConnectionState ()
void | setGhostFrom (bool ghostFrom)
| Sets whether ghosts transmit from this side of the connection. More...
void | setGhostTo (bool ghostTo)
| Sets whether ghosts are allowed from the other side of the connection. More...
void | setSendingEvents (bool sending)
| Sets whether this side actually sends the events that are posted to it. More...
void | setTranslatesStrings (bool xl)
| Sets whether this connection is capable of translating strings. More...
void | setNetClassGroup (U32 group)
| Sets the group of NetClasses this connection traffics in. More...
bool | isEstablished ()
| Is the connection established? More...
| DECLARE_CONOBJECT (NetConnection)
virtual PacketNotify * | allocNotify ()
Public Member Functions inherited from ConnectionProtocol
| ConnectionProtocol ()
void | buildSendPacketHeader (BitStream *bstream, S32 packetType=0)
void | sendPingPacket ()
void | sendAckPacket ()
void | setConnectionEstablished ()
bool | windowFull ()
bool | connectionEstablished ()
void | setConnectSequence (U32 connectSeq)
Public Member Functions inherited from SimGroup
| ~SimGroup ()
virtual void | addObject (SimObject *)
| Add an object to the group. More...
void | addObject (SimObject *, SimObjectId)
void | addObject (SimObject *, const char *name)
virtual void | removeObject (SimObject *)
| Remove an object from the group. More...
virtual SimObject * | findObject (const char *name)
| Find an object in the group. More...
bool | processArguments (S32 argc, const char **argv)
| Process constructor options. (ie, new SimObject(1,2,3)) More...
| DECLARE_CONOBJECT (SimGroup)
Public Member Functions inherited from SimSet
| SimSet ()
| ~SimSet ()
virtual void | onDeleteNotify (SimObject *object)
virtual U32 | getTamlChildCount (void) const
| Called when Taml attempts to compile a list of children. More...
virtual SimObject * | getTamlChild (const U32 childIndex) const
| Called when Taml attempts to compile a list of children. More...
virtual void | addTamlChild (SimObject *pSimObject)
| Called when Taml attempts to populate an objects children during a read. More...
void | callOnChildren (const char *method, S32 argc, const char *argv[], bool executeOnChildGroups=true)
virtual void | write (Stream &stream, U32 tabStop, U32 flags=0)
SimObject * | findObjectByInternalName (const char *internalName, bool searchChildren=false)
virtual bool | writeObject (Stream *stream)
virtual bool | readObject (Stream *stream)
void | lock ()
void | unlock ()
| DECLARE_CONOBJECT (SimSet)
void | _setVectorAssoc (const char *file, const U32 line)
virtual void | pushObject (SimObject *)
virtual void | popObject ()
| Remove an object from the end of the list. More...
void | bringObjectToFront (SimObject *obj)
void | pushObjectToBack (SimObject *obj)
SimObject * | front ()
SimObject * | first ()
SimObject * | last ()
bool | empty ()
S32 | size () const
iterator | begin ()
iterator | end ()
value | operator[] (S32 index)
iterator | find (iterator first, iterator last, SimObject *obj)
iterator | find (SimObject *obj)
template<typename T >
bool | containsType (void)
virtual bool | reOrder (SimObject *obj, SimObject *target=0)
SimObject * | at (S32 index) const
void | deleteObjects (void)
void | clear ()
Public Member Functions inherited from SimObject
StringTableEntry | getClassNamespace () const
StringTableEntry | getSuperClassNamespace () const
void | setClassNamespace (const char *classNamespace)
void | setSuperClassNamespace (const char *superClassNamespace)
void | pushScriptCallbackGuard (void)
void | popScriptCallbackGuard (void)
S32 | getScriptCallbackGuard (void)
Namespace * | getNamespace ()
| Return the object's namespace. More...
const char * | tabComplete (const char *prevText, S32 baseLen, bool)
virtual void | dump ()
virtual void | dumpClassHierarchy ()
SimObject * | clone (const bool copyDynamicFields)
virtual void | copyTo (SimObject *object)
template<typename T >
bool | isType (void)
virtual bool | handlesConsoleMethod (const char *fname, S32 *routingId)
| DECLARE_CONOBJECT (SimObject)
Notify * | removeNotify (void *ptr, Notify::Type)
| Remove a notification from the list. More...
void | deleteNotify (SimObject *obj)
| Notify an object when we are deleted. More...
void | clearNotify (SimObject *obj)
| Notify an object when we are cleared. More...
void | clearAllNotifications ()
| Remove all notifications for this object. More...
void | processDeleteNotifies ()
| Send out deletion notifications. More...
void | registerReference (SimObject **obj)
void | unregisterReference (SimObject **obj)
const char * | getDataField (StringTableEntry slotName, const char *array)
void | setDataField (StringTableEntry slotName, const char *array, const char *value)
const char * | getPrefixedDataField (StringTableEntry fieldName, const char *array)
void | setPrefixedDataField (StringTableEntry fieldName, const char *array, const char *value)
const char * | getPrefixedDynamicDataField (StringTableEntry fieldName, const char *array, const S32 fieldType=-1)
void | setPrefixedDynamicDataField (StringTableEntry fieldName, const char *array, const char *value, const S32 fieldType=-1)
StringTableEntry | getDataFieldPrefix (StringTableEntry fieldName)
U32 | getDataFieldType (StringTableEntry slotName, const char *array)
SimFieldDictionary * | getFieldDictionary ()
void | clearDynamicFields (void)
| Clear all dynamic fields. More...
void | setCanSaveDynamicFields (bool bCanSave)
| Set whether fields created at runtime should be saved. Default is true. More...
bool | getCanSaveDynamicFields (void) const
| Get whether fields created at runtime should be saved. Default is true. More...
void | setInternalName (const char *newname)
StringTableEntry | getInternalName ()
| Get the internal of of this control. More...
virtual bool | save (const char *pcFilePath, bool bOnlySelected=false)
| Save object as a TorqueScript File. More...
virtual bool | isMethod (const char *methodName)
| Check if a method exists in the objects current namespace. More...
SimObjectId | getId (void) const
StringTableEntry | getIdString (void) const
U32 | getType () const
const StringTableEntry | getName (void) const
void | setId (SimObjectId id)
void | assignName (const char *name)
SimGroup * | getGroup () const
bool | isChildOfGroup (SimGroup *pGroup)
bool | isProperlyAdded () const
bool | isDeleted () const
bool | isRemoved () const
bool | isLocked ()
void | setLocked (bool b)
bool | isHidden ()
void | setHidden (bool b)
void | setProgenitorFile (const char *pFile)
StringTableEntry | getProgenitorFile (void) const
void | setPeriodicTimerID (const S32 timerID)
S32 | getPeriodicTimerID (void) const
bool | isPeriodicTimerActive (void) const
bool | isSelected () const
bool | isExpanded () const
void | setSelected (bool sel)
void | setExpanded (bool exp)
void | setModDynamicFields (bool dyn)
void | setModStaticFields (bool sta)
| SimObject ()
virtual | ~SimObject ()
virtual bool | onAdd ()
| Called when the object is added to the sim. More...
virtual void | onGroupAdd ()
| Called when the object is added to a SimGroup. More...
virtual void | onGroupRemove ()
| Called when the object is removed from a SimGroup. More...
virtual void | onNameChange (const char *name)
| Called when the object's name is changed. More...
virtual void | onStaticModified (const char *slotName, const char *newValue=NULL)
virtual void | inspectPreApply ()
virtual void | inspectPostApply ()
virtual void | onEditorEnable ()
| Called when the editor is activated. More...
virtual void | onEditorDisable ()
| Called when the editor is deactivated. More...
bool | registerObject ()
bool | registerObject (U32 id)
bool | registerObject (const char *name)
bool | registerObject (const char *name, U32 id)
void | unregisterObject ()
void | deleteObject ()
bool | addToSet (SimObjectId)
bool | addToSet (const char *)
bool | removeFromSet (SimObjectId)
bool | removeFromSet (const char *)
virtual bool | writeField (StringTableEntry fieldname, const char *value)
virtual void | writeFields (Stream &stream, U32 tabStop)
virtual void | buildFilterList ()
void | addFieldFilter (const char *fieldName)
void | removeFieldFilter (const char *fieldName)
void | clearFieldFilters ()
bool | isFiltered (const char *fieldName)
void | assignFieldsFrom (SimObject *obj)
void | assignDynamicFieldsFrom (SimObject *obj)
Public Member Functions inherited from ConsoleObject
const AbstractClassRep::Field * | findField (StringTableEntry fieldName) const
| Get a reference to a field by name. More...
virtual AbstractClassRep * | getClassRep () const
| Gets the ClassRep. More...
bool | setField (const char *fieldName, const char *value)
| Set the value of a field. More...
virtual | ~ConsoleObject ()
const AbstractClassRep::FieldList & | getFieldList () const
| Get a list of all the fields. This information cannot be modified. More...
AbstractClassRep::FieldList & | getModifiableFieldList ()
bool & | getDynamicGroupExpand ()
S32 | getClassId (U32 netClassGroup) const
const char * | getClassName () const

## Static Public Member Functions
static NetConnection * | getConnectionToServer ()
static NetConnection * | getLocalClientConnection ()
static void | setLocalClientConnection (NetConnection *conn)
static bool | filesWereDownloaded ()
static char * | getErrorBuffer ()
static void | setLastError (const char *fmt,...)
static NetConnection * | lookup (const NetAddress *remoteAddress)
| Find a NetConnection, if any, with the specified address. More...
static void | consoleInit ()
Static Public Member Functions inherited from SimObject
static void | initPersistFields ()
Static Public Member Functions inherited from ConsoleObject
static const char * | lookupClassName (const U32 in_classTag)
| Get the classname from a class tag. More...
static void | initPersistFields ()
static void | consoleInit ()
static ConsoleObject * | create (const char *in_pClassName)
static ConsoleObject * | create (const U32 groupId, const U32 typeId, const U32 in_classId)
static AbstractClassRep * | getStaticClassRep ()
| Get the abstract class information for this class. More...
static AbstractClassRep * | getParentStaticClassRep ()
| Get the abstract class information for this class's superclass. More...

## Public Attributes
U32 | mConnectionSendCount
| number of connection messages we've sent. More...
U32 | mConnectionState
| State of the connection, from NetConnectionState. More...
PacketNotify * | mNotifyQueueHead
| Head of packet notify list. More...
PacketNotify * | mNotifyQueueTail
| Tail of packet notify list. More...

## Static Public Attributes
static char | mErrorBuffer [256]

## Protected Member Functions
virtual void | readPacket (BitStream *bstream)
virtual void | writePacket (BitStream *bstream, PacketNotify *note)
virtual void | packetReceived (PacketNotify *note)
virtual void | packetDropped (PacketNotify *note)
virtual void | connectionError (const char *errorString)
Protected Member Functions inherited from SimObject
virtual void | onTamlPreWrite (void)
| Taml callbacks. More...
virtual void | onTamlPostWrite (void)
| Called after Taml has finished writing the object. More...
virtual void | onTamlPreRead (void)
| Called prior to Taml reading the object. More...
virtual void | onTamlPostRead (const TamlCustomNodes &customNodes)
virtual void | onTamlAddParent (SimObject *pParentObject)
| Called after Taml has finished reading the object and has added the object to any parent. More...
virtual void | onTamlCustomWrite (TamlCustomNodes &customNodes)
| Called during the writing of the object to allow custom properties to be written. More...
virtual void | onTamlCustomRead (const TamlCustomNodes &customNodes)
| Called during the reading of the object to allow custom properties to be read. More...
void | linkNamespaces ()
void | unlinkNamespaces ()
Protected Member Functions inherited from ConsoleObject
| ConsoleObject ()
| ConsoleObject (const ConsoleObject &)

## Protected Attributes
U32 | mConnectSendCount
U32 | mConnectLastSendTime
Protected Attributes inherited from ConnectionProtocol
U32 | mLastSeqRecvdAtSend [32]
U32 | mLastSeqRecvd
U32 | mHighestAckedSeq
U32 | mLastSendSeq
U32 | mAckMask
U32 | mConnectSequence
U32 | mLastRecvAckAck
bool | mConnectionEstablished
Protected Attributes inherited from SimSet
SimObjectList | objectList
void * | mMutex
Protected Attributes inherited from SimObject
SimObjectId | mId
| Id number for this object. More...
StringTableEntry | mIdString
Namespace * | mNameSpace
U32 | mTypeMask
S32 | mScriptCallbackGuard
| Whether the object is executing a script callback. More...
bool | mCanSaveFieldDictionary
| true if dynamic fields (added at runtime) should be saved, defaults to true More...
StringTableEntry | mInternalName
| Stores object Internal Name. More...
StringTableEntry | mClassName
| Stores the class name to link script class namespaces. More...
StringTableEntry | mSuperClassName
| Stores super class name to link script class namespaces. More...

## Static Protected Attributes
static SimObjectPtr< NetConnection > | mServerConnection
static SimObjectPtr< NetConnection > | mLocalClientConnection
static bool | mFilesWereDownloaded = false
Static Protected Attributes inherited from SimObject
static SimObject::Notify * | mNotifyFreeList = NULL

## Friends
class | NetInterface

## Global Connection List
NetConnection * | getNext ()
static NetConnection * | getConnectionList ()

## Event Manager
bool | postNetEvent (NetEvent *event)
| Post an event to this connection. More...

## Networked string table
void | mapString (U32 netId, NetStringHandle &string)
U32 | checkString (NetStringHandle &string, bool *isOnOtherSide=NULL)
U32 | getNetSendId (NetStringHandle &string)
void | confirmStringReceived (NetStringHandle &string, U32 index)
NetStringHandle | translateRemoteStringId (U32 id)
void | validateSendString (const char *str)
void | packString (BitStream *stream, const char *str)
void | unpackString (BitStream *stream, char readBuffer[1024])
void | packNetStringHandleU (BitStream *stream, NetStringHandle &h)
NetStringHandle | unpackNetStringHandleU (BitStream *stream)

## Ghost manager
enum | GhostConstants { GhostIdBitSize = 12, MaxGhostCount = 1 << GhostIdBitSize, GhostLookupTableSize = 1 << GhostIdBitSize, GhostIndexBitSize = 4 }
| Some configuration values. More...
enum | GhostStates { GhostAlwaysDone, ReadyForNormalGhosts, EndGhosting, GhostAlwaysStarting, SendNextDownloadRequest, FileDownloadSizeMessage, NumConnectionMessages }
GhostInfo ** | mGhostArray
| Linked list of ghostInfos ghosted by this side of the connection. More...
U32 | mGhostZeroUpdateIndex
| Index in mGhostArray of first ghost with 0 update mask. More...
U32 | mGhostFreeIndex
| Index in mGhostArray of first free ghost. More...
U32 | mGhostsActive
bool | mGhosting
| Am I currently ghosting objects? More...
bool | mScoping
| am I currently scoping objects? More...
U32 | mGhostingSequence
| Sequence number describing this ghosting session. More...
NetObject ** | mLocalGhosts
GhostInfo * | mGhostRefs
| mLocalGhosts pointer is NULL if mGhostTo is false More...
GhostInfo ** | mGhostLookupTable
| Table indexed by object id to GhostInfo. Null if ghostFrom is false. More...
SimObjectPtr< NetObject > | mScopeObject
U32 | getGhostsActive ()
bool | isGhostingTo ()
| Are we ghosting to someone? More...
bool | isGhostingFrom ()
| Are we ghosting from someone? More...
void | ghostOnRemove ()
| Called by onRemove, to shut down the ghost subsystem. More...
virtual void | doneScopingScene ()
void | setScopeObject (NetObject *object)
| Set the object around which we are currently scoping network traffic. More...
NetObject * | getScopeObject ()
| Get the object aorund which we are currently scoping network traffic. More...
void | objectInScope (NetObject *object)
| Add an object to scope. More...
void | objectLocalScopeAlways (NetObject *object)
| Add an object to scope, marking that it should always be scoped to this connection. More...
void | objectLocalClearAlways (NetObject *object)
NetObject * | resolveGhost (S32 id)
| Get a NetObject* from a ghost ID (on client side). More...
NetObject * | resolveObjectFromGhostIndex (S32 id)
| Get a NetObject* from a ghost index (on the server side). More...
S32 | getGhostIndex (NetObject *object)
void | ghostPushNonZero (GhostInfo *gi)
| Move a GhostInfo into the nonzero portion of the list (so that we know to update it). More...
void | ghostPushToZero (GhostInfo *gi)
| Move a GhostInfo into the zero portion of the list (so that we know not to update it). More...
void | ghostPushZeroToFree (GhostInfo *gi)
| Move a GhostInfo from the zero portion of the list to the free portion. More...
void | ghostPushFreeToZero (GhostInfo *info)
| Move a GhostInfo from the free portion of the list to the zero portion. More...
void | resetGhosting ()
void | activateGhosting ()
| Activate ghosting, once it's enabled. More...
bool | isGhosting ()
| Are we ghosting? More...
void | detachObject (GhostInfo *info)
| Begin to stop ghosting an object. More...
void | setGhostAlwaysObject (NetObject *object, U32 index)
| Mark an object to be always ghosted. Index is the ghost index of the object. More...
void | sendConnectionMessage (U32 message, U32 sequence=0, U32 ghostCount=0)
virtual void | handleConnectionMessage (U32 message, U32 sequence, U32 ghostCount)
void | clearGhostInfo ()
bool | validateGhostArray ()
void | ghostPacketDropped (PacketNotify *notify)
void | ghostPacketReceived (PacketNotify *notify)
void | ghostWritePacket (BitStream *bstream, PacketNotify *notify)
void | ghostReadPacket (BitStream *bstream)
void | freeGhostInfo (GhostInfo *)
void | ghostWriteStartBlock (ResizeBitStream *stream)
void | ghostReadStartBlock (BitStream *stream)

## File transfer
Vector< char * > | mMissingFileList
Stream * | mCurrentDownloadingFile
| Stream for currently uploading file (if any). More...
void * | mCurrentFileBuffer
| Storage for currently downloading file. More...
U32 | mCurrentFileBufferSize
| Size of currently downloading file in bytes. More...
U32 | mCurrentFileBufferOffset
| Our position in the currently downloading file in bytes. More...
U32 | mNumDownloadedFiles
| Number of files we have downloaded. More...
char | mLastFileErrorBuffer [256]
| Error storage for file transfers. More...
Vector< GhostSave > | mGhostAlwaysSaveList
| List of objects to ghost-always. More...
bool | startSendingFile (const char *fileName)
| Start sending the specified file over the link. More...
void | chunkReceived (U8 *chunkData, U32 chunkLen)
| Called when we receive a FileChunkEvent. More...
void | sendNextFileDownloadRequest ()
| Get the next file... More...
void | sendFileChunk ()
| Post the next FileChunkEvent. More...
virtual void | fileDownloadSegmentComplete ()
| Called when we finish downloading file data. More...
void | loadNextGhostAlwaysObject (bool hadNewFiles)

## Demo Recording
enum | DemoBlockTypes { BlockTypePacket, BlockTypeSendPacket, NetConnectionBlockTypeCount }
enum | DemoConstants { MaxNumBlockTypes = 16, MaxBlockSize = 0x1000 }
bool | isRecording ()
bool | isPlayingBack ()
U32 | getNextBlockType ()
void | recordBlock (U32 type, U32 size, void *data)
virtual void | handleRecordedBlock (U32 type, U32 size, void *data)
bool | processNextBlock ()
bool | startDemoRecord (const char *fileName)
bool | replayDemoRecord (const char *fileName)
void | startDemoRead ()
void | stopRecording ()
void | stopDemoPlayback ()
virtual void | writeDemoStartBlock (ResizeBitStream *stream)
virtual bool | readDemoStartBlock (BitStream *stream)
virtual void | demoPlaybackComplete ()

## Additional Inherited Members
Static Protected Member Functions inherited from SimObject
static bool | setClass (void *obj, const char *data)
static bool | setSuperClass (void *obj, const char *data)
static bool | writeCanSaveDynamicFields (void *obj, StringTableEntry pFieldName)
static bool | writeInternalName (void *obj, StringTableEntry pFieldName)
static bool | setParentGroup (void *obj, const char *data)
static bool | writeParentGroup (void *obj, StringTableEntry pFieldName)
static bool | writeSuperclass (void *obj, StringTableEntry pFieldName)
static bool | writeClass (void *obj, StringTableEntry pFieldName)
static SimObject::Notify * | allocNotify ()
| Get a free Notify structure. More...
static void | freeNotify (SimObject::Notify *)
| Mark a Notify structure as free. More...
Static Protected Member Functions inherited from ConsoleObject
static void | addGroup (const char *in_pGroupname, const char *in_pGroupDocs=NULL)
static void | endGroup (const char *in_pGroupname)
static void | addField (const char *in_pFieldname, const U32 in_fieldType, const dsize_t in_fieldOffset, const U32 in_elementCount=1, EnumTable *in_table=NULL, const char *in_pFieldDocs=NULL)
static void | addField (const char *in_pFieldname, const U32 in_fieldType, const dsize_t in_fieldOffset, AbstractClassRep::WriteDataNotify in_writeDataFn, const U32 in_elementCount=1, EnumTable *in_table=NULL, const char *in_pFieldDocs=NULL)
static void | addField (const char *in_pFieldname, const U32 in_fieldType, const dsize_t in_fieldOffset, const char *in_pFieldDocs)
static void | addField (const char *in_pFieldname, const U32 in_fieldType, const dsize_t in_fieldOffset, AbstractClassRep::WriteDataNotify in_writeDataFn, const char *in_pFieldDocs)
static void | addFieldV (const char *in_pFieldname, const U32 in_fieldType, const dsize_t in_fieldOffset, ConsoleTypeValidator *v, const char *in_pFieldDocs=NULL)
static void | addProtectedField (const char *in_pFieldname, const U32 in_fieldType, const dsize_t in_fieldOffset, AbstractClassRep::SetDataNotify in_setDataFn, AbstractClassRep::GetDataNotify in_getDataFn=&defaultProtectedGetFn, const U32 in_elementCount=1, EnumTable *in_table=NULL, const char *in_pFieldDocs=NULL)
static void | addProtectedField (const char *in_pFieldname, const U32 in_fieldType, const dsize_t in_fieldOffset, AbstractClassRep::SetDataNotify in_setDataFn, AbstractClassRep::GetDataNotify in_getDataFn=&defaultProtectedGetFn, AbstractClassRep::WriteDataNotify in_writeDataFn=&defaultProtectedWriteFn, const U32 in_elementCount=1, EnumTable *in_table=NULL, const char *in_pFieldDocs=NULL)
static void | addProtectedField (const char *in_pFieldname, const U32 in_fieldType, const dsize_t in_fieldOffset, AbstractClassRep::SetDataNotify in_setDataFn, AbstractClassRep::GetDataNotify in_getDataFn=&defaultProtectedGetFn, const char *in_pFieldDocs=NULL)
static void | addProtectedField (const char *in_pFieldname, const U32 in_fieldType, const dsize_t in_fieldOffset, AbstractClassRep::SetDataNotify in_setDataFn, AbstractClassRep::GetDataNotify in_getDataFn=&defaultProtectedGetFn, AbstractClassRep::WriteDataNotify in_writeDataFn=&defaultProtectedWriteFn, const char *in_pFieldDocs=NULL)
static void | addDepricatedField (const char *fieldName)
static bool | removeField (const char *in_pFieldname)

## Detailed Description

Torque network connection.

# Introduction

NetConnection is the glue that binds a networked Torque game together. It combines the low-level notify protocol implemented in ConnectionProtocol with a SimGroup to provide a powerful basis for implementing a multiplayer game protocol.

On top of this basis it implements several distinct subsystems:

- Event manager, which is responsible for transmitting NetEvents over the wire. It deals with ensuring that the various types of NetEvents are delivered appropriately, and with notifying the event of its delivery status.
- Move manager, which is responsible for transferring a Move to the server 32 times a second (on the client) and applying it to the control object (on the server).
- Ghost manager, which is responsible for doing scoping calculations (on the server side) and transmitting most-recent ghost information to the client.
- File transfer; it is often the case that clients will lack important files when connecting to a server which is running a mod or new map. This subsystem allows the server to transfer such files to the client.
- Networked String Table; string data can easily soak up network bandwidth, so for efficiency, we implement a networked string table. We can then notify the connection of strings we will reference often, such as player names, and transmit only a tag, instead of the whole string.
- Demo Recording is also implemented in NetConnection. A demo in Torque is a log of the network traffic between client and server; when a NetConnection records a demo, it simply logs this data to a file. When it plays a demo back, it replays the logged data.
- The Connection Database is used to keep track of all the NetConnections; it can be iterated over (for instance, to send an event to all active connections), or queried by address.

# On Events

The Event Manager is exposed to the outside world via postNetEvent(), which accepts NetEvents.

See also
  NetEvent for a more thorough explanation of how to use events.

# On Ghosting and Scoping

Ghosting is the most complex, and most powerful, part of Torque's networking capabilities. It allows the information sent to clients to be very precisely matched to what they need, so that no excess bandwidth is wasted. The control object's onCameraScopeQuery() is called, to determine scoping information for the client; then objects which are in scope are then transmitted to the client, prioritized by the results of their getPriority() method.

There is a cap on the maximum number of ghosts; ghost IDs are currently sent via a 10-bit field, ergo, there is a cap of 1024 objects ghosted per client. This can be easily raised; see the GhostConstants enum.

Each object ghosted is assigned a ghost ID; the client is only aware of the ghost ID. This acts to enhance game security, as it becomes difficult to map objects from one connection to another, or to reliably identify objects from ID alone. IDs are also reassigned based on need, making it hard to track objects that have fallen out of scope (as any object which the player shouldn't see would).

resolveGhost() is used on the client side, and resolveObjectFromGhostIndex() on the server side, to turn ghost IDs into object references.

The NetConnection is a SimGroup. On the client side, it contains all the objects which have been ghosted to that client. On the server side, it is empty; it can be used (typically in script) to hold objects related to the connection. For instance, you might place an observation camera in the NetConnnection. In both cases, when the connection is destroyed, so are the contained objects.

See also
  NetObject, which is the superclass for ghostable objects, and ShapeBase, which is the base for player and vehicle classes.

## Member Enumeration Documentation

enum Constants

Enumerator
HashTableSize |

enum DemoBlockTypes

Enumerator
BlockTypePacket |
BlockTypeSendPacket |
NetConnectionBlockTypeCount |

enum DemoConstants

Enumerator
MaxNumBlockTypes |
MaxBlockSize |

enum GhostConstants

Some configuration values.

Enumerator
GhostIdBitSize |
MaxGhostCount |
GhostLookupTableSize |
GhostIndexBitSize |

enum GhostStates
| protected

Enumerator
GhostAlwaysDone |
ReadyForNormalGhosts |
EndGhosting |
GhostAlwaysStarting |
SendNextDownloadRequest |
FileDownloadSizeMessage |
NumConnectionMessages |

enum NetConnectionFlags

Enumerator
ConnectionToServer |
ConnectionToClient |
LocalClientConnection |
NetworkConnection |

enum NetConnectionState

Enumerator
NotConnected |
AwaitingChallengeResponse | We've sent a challenge request, awaiting the response.
AwaitingConnectRequest | We've received a challenge request and sent a challenge response.
AwaitingConnectResponse | We've received a challenge response and sent a connect request.
Connected | We've accepted a connect request, or we've received a connect response accept.

## Constructor & Destructor Documentation

NetConnection | ( |  | ) |

~NetConnection | ( |  | ) |

## Member Function Documentation

void activateGhosting | ( |  | ) |

Activate ghosting, once it's enabled.

NetConnection::PacketNotify * allocNotify | ( |  | ) |
| virtual

Reimplemented in GameConnection.

bool canRemoteCreate | ( |  | ) |
| virtual

Reimplemented in GameConnection.

void checkMaxRate | ( |  | ) |

void checkPacketSend | ( | bool | force | ) |

U32 checkString | ( | NetStringHandle & | string,
|  | bool * | isOnOtherSide = `NULL`
| ) |  |
| inline

bool checkTimeout | ( | U32 | time | ) |

returns true if the connection timed out

void chunkReceived | ( | U8 * | chunkData,
|  | U32 | chunkLen
| ) |  |

Called when we receive a FileChunkEvent.

void clearGhostInfo | ( |  | ) |
| protected

void confirmStringReceived | ( | NetStringHandle & | string,
|  | U32 | index
| ) |  |
| inline

void connect | ( | const NetAddress * | address | ) |

void connectionError | ( | const char * | errorString | ) |
| protected virtual

Reimplemented in GameConnection.

void consoleInit | ( |  | ) |
| static

DECLARE_CONOBJECT | ( | NetConnection |  | ) |

void demoPlaybackComplete | ( |  | ) |
| virtual

void detachObject | ( | GhostInfo * | info | ) |

Begin to stop ghosting an object.

virtual void doneScopingScene | ( |  | ) |
| inline virtual

Called when we're done with normal scoping.

This gives subclasses a chance to shove things into scope, such as the results of a sensor network calculation, that would otherwise be awkward to add.

void fileDownloadSegmentComplete | ( |  | ) |
| virtual

Called when we finish downloading file data.

static bool filesWereDownloaded | ( |  | ) |
| inline static

void freeGhostInfo | ( | GhostInfo * | ghost | ) |
| protected

void getAddressDigest | ( | U32 | digest[4] | ) |

static NetConnection* getConnectionList | ( |  | ) |
| inline static

U32 getConnectionState | ( |  | ) |
| inline

static NetConnection* getConnectionToServer | ( |  | ) |
| inline static

static char* getErrorBuffer | ( |  | ) |
| inline static

S32 getGhostIndex | ( | NetObject * | object | ) |

Get the ghost index corresponding to a given NetObject. This is only meaningful on the server side.

U32 getGhostsActive | ( |  | ) |
| inline

static NetConnection* getLocalClientConnection | ( |  | ) |
| inline static

const NetAddress * getNetAddress | ( |  | ) |

U32 getNetClassGroup | ( |  | ) |
| inline

U32 getNetSendId | ( | NetStringHandle & | string | ) |
| inline

NetConnection* getNext | ( |  | ) |
| inline

U32 getNextBlockType | ( |  | ) |
| inline

F32 getPacketLoss | ( |  | ) |
| inline

U32 getProtocolVersion | ( |  | ) |
| inline

F32 getRoundTripTime | ( |  | ) |
| inline

NetObject* getScopeObject | ( |  | ) |

Get the object aorund which we are currently scoping network traffic.

U32 getSequence | ( |  | ) |

void ghostOnRemove | ( |  | ) |

Called by onRemove, to shut down the ghost subsystem.

void ghostPacketDropped | ( | PacketNotify * | notify | ) |
| protected

void ghostPacketReceived | ( | PacketNotify * | notify | ) |
| protected

void ghostPushFreeToZero | ( | GhostInfo * | info | ) |
| inline

Move a GhostInfo from the free portion of the list to the zero portion.

void ghostPushNonZero | ( | GhostInfo * | gi | ) |
| inline

Move a GhostInfo into the nonzero portion of the list (so that we know to update it).

void ghostPushToZero | ( | GhostInfo * | gi | ) |
| inline

Move a GhostInfo into the zero portion of the list (so that we know not to update it).

void ghostPushZeroToFree | ( | GhostInfo * | gi | ) |
| inline

Move a GhostInfo from the zero portion of the list to the free portion.

void ghostReadPacket | ( | BitStream * | bstream | ) |
| protected

void ghostReadStartBlock | ( | BitStream * | stream | ) |
| protected

void ghostWritePacket | ( | BitStream * | bstream,
|  | PacketNotify * | notify
| ) |  |
| protected

void ghostWriteStartBlock | ( | ResizeBitStream * | stream | ) |
| protected

void handleConnectionEstablished | ( |  | ) |
| virtual

Implements ConnectionProtocol.

void handleConnectionMessage | ( | U32 | message,
|  | U32 | sequence,
|  | U32 | ghostCount
| ) |  |
| virtual

Handle message from sendConnectionMessage().

This is called to handle messages sent via sendConnectionMessage.

Parameters

  message | One of GhostStates
  sequence | A sequence number, if any.
  ghostCount | A count of ghosts relating to this message.

Reimplemented in GameConnection.

void handleNotify | ( | bool | recvd | ) |
| virtual

Implements ConnectionProtocol.

void handlePacket | ( | BitStream * | stream | ) |
| virtual

Implements ConnectionProtocol.

void handleRecordedBlock | ( | U32 | type,
|  | U32 | size,
|  | void * | data
| ) |  |
| virtual

void handleStartupError | ( | const char * | errorString | ) |
| virtual

Reimplemented in GameConnection.

bool isConnectionToServer | ( |  | ) |
| inline

bool isEstablished | ( |  | ) |
| inline

Is the connection established?

bool isGhosting | ( |  | ) |
| inline

Are we ghosting?

bool isGhostingFrom | ( |  | ) |
| inline

Are we ghosting from someone?

bool isGhostingTo | ( |  | ) |
| inline

Are we ghosting to someone?

bool isLocalConnection | ( |  | ) |
| inline

bool isNetworkConnection | ( |  | ) |
| inline

bool isPlayingBack | ( |  | ) |
| inline

bool isRecording | ( |  | ) |
| inline

void keepAlive | ( |  | ) |
| virtual

Implements ConnectionProtocol.

void loadNextGhostAlwaysObject | ( | bool | hadNewFiles | ) |

This is part of the file transfer logic; basically, we call this every time we finish downloading new files. It attempts to load the GhostAlways objects; if they fail, it marks an error and we have chance to retry.

NetConnection * lookup | ( | const NetAddress * | remoteAddress | ) |
| static

Find a NetConnection, if any, with the specified address.

void mapString | ( | U32 | netId,
|  | NetStringHandle & | string
| ) |  |
| inline

bool missionPathsSent | ( |  | ) | const
| inline

void objectInScope | ( | NetObject * | object | ) |

Add an object to scope.

void objectLocalClearAlways | ( | NetObject * | object | ) |

Mark an object that is being ghosted as not always needing to be scoped.

This undoes objectLocalScopeAlways(), but doesn't immediately flush it from scope.

Instead, the standard scoping mechanisms will clear it from scope when it is appropos to do so.

void objectLocalScopeAlways | ( | NetObject * | object | ) |

Add an object to scope, marking that it should always be scoped to this connection.

void onConnectionEstablished | ( | bool | isInitiator | ) |
| virtual

Reimplemented in GameConnection.

void onConnectionRejected | ( | const char * | reason | ) |
| virtual

Reimplemented in GameConnection.

void onConnectTimedOut | ( |  | ) |
| virtual

Reimplemented in GameConnection.

void onDisconnect | ( | const char * | reason | ) |
| virtual

Reimplemented in GameConnection.

void onRemove | ( |  | ) |
| virtual

Called when the object is removed from the sim.

Reimplemented from SimGroup.

void onTimedOut | ( |  | ) |
| virtual

Reimplemented in GameConnection.

void packetDropped | ( | PacketNotify * | note | ) |
| protected virtual

Reimplemented in GameConnection.

void packetReceived | ( | PacketNotify * | note | ) |
| protected virtual

Reimplemented in GameConnection.

void packNetStringHandleU | ( | BitStream * | stream,
|  | NetStringHandle & | h
| ) |  |

void packString | ( | BitStream * | stream,
|  | const char * | str
| ) |  |

bool postNetEvent | ( | NetEvent * | event | ) |

Post an event to this connection.

bool processNextBlock | ( |  | ) |

void processRawPacket | ( | BitStream * | stream | ) |
| virtual

Reimplemented from ConnectionProtocol.

bool readConnectAccept | ( | BitStream * | stream,
|  | const char ** | errorString
| ) |  |
| virtual

Reimplemented in GameConnection.

bool readConnectRequest | ( | BitStream * | stream,
|  | const char ** | errorString
| ) |  |
| virtual

Reimplemented in GameConnection.

bool readDemoStartBlock | ( | BitStream * | stream | ) |
| virtual

Reimplemented from ConnectionProtocol.

void readPacket | ( | BitStream * | bstream | ) |
| protected virtual

Reimplemented in GameConnection.

void recordBlock | ( | U32 | type,
|  | U32 | size,
|  | void * | data
| ) |  |

bool replayDemoRecord | ( | const char * | fileName | ) |

void resetGhosting | ( |  | ) |

Stop all ghosting activity and inform the other side about this.

Turns off ghosting.

NetObject * resolveGhost | ( | S32 | id | ) |

Get a NetObject* from a ghost ID (on client side).

NetObject * resolveObjectFromGhostIndex | ( | S32 | id | ) |

Get a NetObject* from a ghost index (on the server side).

void sendConnectionMessage | ( | U32 | message,
|  | U32 | sequence = `0`,
|  | U32 | ghostCount = `0`
| ) |  |

Send ghost connection handshake message.

As part of the ghoost connection process, extensive hand-shaking must be performed.

This is done by passing ConnectionMessageEvents; this is a helper function to more effectively perform this task. Messages are dealt with by handleConnectionMessage().

Parameters

  message | One of GhostStates
  sequence | A sequence number, if any.
  ghostCount | A count of ghosts relating to this message.

void sendDisconnectPacket | ( | const char * | reason | ) |

void sendFileChunk | ( |  | ) |

Post the next FileChunkEvent.

void sendNextFileDownloadRequest | ( |  | ) |

Get the next file...

Net::Error sendPacket | ( | BitStream * | stream | ) |
| virtual

Implements ConnectionProtocol.

void setAddressDigest | ( | U32 | digest[4] | ) |

void setConnectionState | ( | U32 | state | ) |
| inline

void setEstablished | ( |  | ) |
| virtual

void setGhostAlwaysObject | ( | NetObject * | object,
|  | U32 | index
| ) |  |

Mark an object to be always ghosted. Index is the ghost index of the object.

void setGhostFrom | ( | bool | ghostFrom | ) |

Sets whether ghosts transmit from this side of the connection.

void setGhostTo | ( | bool | ghostTo | ) |

Sets whether ghosts are allowed from the other side of the connection.

void setIsConnectionToServer | ( |  | ) |
| inline

void setIsLocalClientConnection | ( |  | ) |
| inline

void setLastError | ( | const char * | fmt,
|  |  | ...
| ) |  |
| static

static void setLocalClientConnection | ( | NetConnection * | conn | ) |
| inline static

void setMissionPathsSent | ( | const bool | s | ) |
| inline

void setNetAddress | ( | const NetAddress * | address | ) |

void setNetClassGroup | ( | U32 | group | ) |

Sets the group of NetClasses this connection traffics in.

void setNetworkConnection | ( | bool | net | ) |
| inline

void setProtocolVersion | ( | U32 | protocolVersion | ) |
| inline

void setRemoteConnectionObject | ( | NetConnection * | connection | ) |
| inline

Call this if the "connection" is local to this app. This short-circuits the protocol layer.

void setScopeObject | ( | NetObject * | object | ) |

Set the object around which we are currently scoping network traffic.

void setSendingEvents | ( | bool | sending | ) |

Sets whether this side actually sends the events that are posted to it.

void setSequence | ( | U32 | connectSequence | ) |

void setSimulatedNetParams | ( | F32 | packetLoss,
|  | U32 | ping
| ) |  |
| inline

void setTranslatesStrings | ( | bool | xl | ) |

Sets whether this connection is capable of translating strings.

void startDemoRead | ( |  | ) |

bool startDemoRecord | ( | const char * | fileName | ) |

bool startSendingFile | ( | const char * | fileName | ) |

Start sending the specified file over the link.

void stopDemoPlayback | ( |  | ) |

void stopRecording | ( |  | ) |

NetStringHandle translateRemoteStringId | ( | U32 | id | ) |
| inline

NetStringHandle unpackNetStringHandleU | ( | BitStream * | stream | ) |

void unpackString | ( | BitStream * | stream,
|  | char | readBuffer[1024]
| ) |  |

bool validateGhostArray | ( |  | ) |
| protected

void validateSendString | ( | const char * | str | ) |

void writeConnectAccept | ( | BitStream * | stream | ) |
| virtual

Reimplemented in GameConnection.

void writeConnectRequest | ( | BitStream * | stream | ) |
| virtual

Reimplemented in GameConnection.

void writeDemoStartBlock | ( | ResizeBitStream * | stream | ) |
| virtual

Reimplemented from ConnectionProtocol.

void writePacket | ( | BitStream * | bstream,
|  | PacketNotify * | note
| ) |  |
| protected virtual

Reimplemented in GameConnection.

## Friends And Related Function Documentation

friend class NetInterface
| friend

## Member Data Documentation

U32 mConnectionSendCount

number of connection messages we've sent.

U32 mConnectionState

State of the connection, from NetConnectionState.

U32 mConnectLastSendTime
| protected

U32 mConnectSendCount
| protected

Stream* mCurrentDownloadingFile
| protected

Stream for currently uploading file (if any).

void* mCurrentFileBuffer
| protected

Storage for currently downloading file.

U32 mCurrentFileBufferOffset
| protected

Our position in the currently downloading file in bytes.

U32 mCurrentFileBufferSize
| protected

Size of currently downloading file in bytes.

char mErrorBuffer
| static

bool mFilesWereDownloaded = false
| static protected

Vector<GhostSave> mGhostAlwaysSaveList
| protected

List of objects to ghost-always.

GhostInfo** mGhostArray
| protected

Linked list of ghostInfos ghosted by this side of the connection.

U32 mGhostFreeIndex
| protected

Index in mGhostArray of first free ghost.

bool mGhosting
| protected

Am I currently ghosting objects?

- Track actve ghosts on client side

U32 mGhostingSequence
| protected

Sequence number describing this ghosting session.

GhostInfo** mGhostLookupTable
| protected

Table indexed by object id to GhostInfo. Null if ghostFrom is false.

GhostInfo* mGhostRefs
| protected

mLocalGhosts pointer is NULL if mGhostTo is false

Allocated array of ghostInfos. Null if ghostFrom is false.

U32 mGhostsActive
| protected

U32 mGhostZeroUpdateIndex
| protected

Index in mGhostArray of first ghost with 0 update mask.

char mLastFileErrorBuffer[256]
| protected

Error storage for file transfers.

SimObjectPtr< NetConnection > mLocalClientConnection
| static protected

NetObject** mLocalGhosts
| protected

Local ghost for remote object.

Vector<char *> mMissingFileList
| protected

List of files missing for this connection.

The currently downloading file is always first in the list (ie, [0]).

PacketNotify* mNotifyQueueHead

Head of packet notify list.

PacketNotify* mNotifyQueueTail

Tail of packet notify list.

U32 mNumDownloadedFiles
| protected

Number of files we have downloaded.

SimObjectPtr<NetObject> mScopeObject
| protected

The object around which we are scoping this connection.

This is usually the player object, or a related object, like a vehicle that the player is driving.

bool mScoping
| protected

am I currently scoping objects?

SimObjectPtr< NetConnection > mServerConnection
| static protected

The documentation for this class was generated from the following files:

- network/netConnection.h
- network/netConnection.cc
- network/netDownload.cc
- network/netEvent.cc
- network/netGhost.cc