Skip to content

Commit 5a9df95

Browse files
committed
tweaks
1 parent ff3a2fe commit 5a9df95

2 files changed

Lines changed: 10 additions & 25 deletions

File tree

handlers.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ const TeamFortress2 = require('./index.js');
88
const Language = require('./language.js');
99
const Schema = require('./protobufs/generated/_load.js');
1010

11-
const g_ItemSchemaRetrievalSemaphore = new Semaphore();
12-
1311
const handlers = TeamFortress2.prototype._handlers;
1412

1513
// ClientWelcome, ServerWelcome, ClientGoodbye, and ServerGoodbye
@@ -48,6 +46,10 @@ handlers[Language.ServerGoodbye] = function(body) {
4846
};
4947

5048
// Item schema
49+
let g_ItemSchema = null;
50+
let g_ItemSchemaVersion = null;
51+
let g_ItemSchemaRetrievalSemaphore = new Semaphore();
52+
5153
handlers[Language.UpdateItemSchema] = async function(body) {
5254
let release = await g_ItemSchemaRetrievalSemaphore.waitAsync();
5355

@@ -59,7 +61,7 @@ handlers[Language.UpdateItemSchema] = async function(body) {
5961

6062
this.emit('itemSchema', schemaVersion, schemaUrl);
6163

62-
if (schemaVersion !== this.itemSchemaVersion) {
64+
if (schemaVersion !== g_ItemSchemaVersion) {
6365
let client = new HttpClient();
6466

6567
let result = await client.request({
@@ -71,10 +73,13 @@ handlers[Language.UpdateItemSchema] = async function(body) {
7173
throw new Error(`HTTP error ${result.statusCode}`);
7274
}
7375

74-
this.itemSchema = VDF.parse(result.textBody).items_game;
75-
this.itemSchemaVersion = schemaVersion;
76+
g_ItemSchema = VDF.parse(result.textBody).items_game;
77+
g_ItemSchemaVersion = schemaVersion;
7678
}
7779

80+
this.itemSchema = g_ItemSchema;
81+
this.itemSchemaVersion = g_ItemSchemaVersion;
82+
7883
this.emit('itemSchemaLoaded');
7984
} catch (err) {
8085
this.emit('debug', `Unable to download items_game.txt: ${err.message}`);

index.js

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ const VDF = require('kvparser');
77
const Language = require('./language.js');
88
const Schema = require('./protobufs/generated/_load.js');
99

10-
const g_ItemSchemaCache = new Map();
11-
1210
const STEAM_APPID = 440;
1311

1412
module.exports = TeamFortress2;
@@ -29,24 +27,6 @@ function TeamFortress2(steam) {
2927
this.haveGCSession = false;
3028
this._isInTF2 = false;
3129

32-
Object.defineProperty(this, 'itemSchema', {
33-
get: function() {
34-
return g_ItemSchemaCache.get('itemSchema');
35-
},
36-
set: function(value) {
37-
g_ItemSchemaCache.set('itemSchema', value);
38-
}
39-
});
40-
41-
Object.defineProperty(this, 'itemSchemaVersion', {
42-
get: function() {
43-
return g_ItemSchemaCache.get('itemSchemaVersion');
44-
},
45-
set: function(value) {
46-
g_ItemSchemaCache.set('itemSchemaVersion', value);
47-
}
48-
});
49-
5030
this._steam.on('receivedFromGC', (appid, msgType, payload) => {
5131
if (appid != STEAM_APPID) {
5232
return; // we don't care

0 commit comments

Comments
 (0)