@@ -8,8 +8,6 @@ const TeamFortress2 = require('./index.js');
88const Language = require ( './language.js' ) ;
99const Schema = require ( './protobufs/generated/_load.js' ) ;
1010
11- const g_ItemSchemaRetrievalSemaphore = new Semaphore ( ) ;
12-
1311const 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+
5153handlers [ 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 } ` ) ;
0 commit comments