const char *getDebugName() { static char buffer[512]; dSprintf(buffer, sizeof(buffer), "%s - \"", getClassName()); expandEscape(buffer + dStrlen(buffer), mString.getString()); dStrcat(buffer, "\""); return buffer; }
void NetStringTable::expandString(NetStringHandle &inString, char *buf, U32 bufSize, U32 argc, const char **argv) { buf[0] = StringTagPrefixByte; dSprintf(buf + 1, bufSize - 1, "%d ", inString.getIndex()); const char *string = inString.getString(); if (string != NULL) { U32 index = dStrlen(buf); while(index < bufSize) { char c = *string++; if(c == '%') { c = *string++; if(c >= '1' && c <= '9') { U32 strIndex = c - '1'; if(strIndex >= argc) continue; // start copying out of arg index const char *copy = argv[strIndex]; // skip past any tags: if(*copy == StringTagPrefixByte) { while(*copy && *copy != ' ') copy++; if(*copy) copy++; } while(*copy && index < bufSize) buf[index++] = *copy++; continue; } } buf[index++] = c; if(!c) break; } buf[bufSize - 1] = 0; } else { dStrcat(buf, "<NULL>"); } }
U32 ConnectionStringTable::getNetSendId(NetStringHandle &string) { // see if the entry is in the hash table right now U32 hashIndex = string.getIndex() % EntryCount; for(Entry *walk = mHashTable[hashIndex]; walk; walk = walk->nextHash) if(walk->string == string) return walk->index; AssertFatal(0, "Net send id is not in the table. Error!"); return 0; }
U32 ConnectionStringTable::checkString(NetStringHandle &string, bool *isOnOtherSide) { // see if the entry is in the hash table right now U32 hashIndex = string.getIndex() % EntryCount; for(Entry *walk = mHashTable[hashIndex]; walk; walk = walk->nextHash) { if(walk->string == string) { pushBack(walk); if(isOnOtherSide) *isOnOtherSide = walk->receiveConfirmed; return walk->index; } } // not in the hash table, means we have to add it Entry *newEntry; // pull the new entry from the LRU list. newEntry = mLRUHead.nextLink; pushBack(newEntry); // remove the string from the hash table Entry **hashWalk; for (hashWalk = &mHashTable[newEntry->string.getIndex() % EntryCount]; *hashWalk; hashWalk = &((*hashWalk)->nextHash)) { if(*hashWalk == newEntry) { *hashWalk = newEntry->nextHash; break; } } newEntry->string = string; newEntry->receiveConfirmed = false; newEntry->nextHash = mHashTable[hashIndex]; mHashTable[hashIndex] = newEntry; mParent->postNetEvent(new NetStringEvent(newEntry->index, string)); if(isOnOtherSide) *isOnOtherSide = false; return newEntry->index; }
virtual void process(NetConnection *connection) { Con::printf("Mapping string: %s to index: %d", mString.getString(), mIndex); connection->mapString(mIndex, mString); }
virtual void write(NetConnection* /*ps*/, BitStream *bstream) { bstream->writeInt(mIndex, ConnectionStringTable::EntryBitSize); bstream->writeString(mString.getString()); }