g-man-tf2

module
v0.7.0-rc.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 28, 2026 License: BSD-3-Clause

README ΒΆ

G-MAN TF2

High-Performance Team Fortress 2 Domain & Economy Suite for Go

"Professionals have standards."

Go Version Go Reference License Zero-Alloc SKU Linter Parity

G-MAN TF2 is the production-grade Team Fortress 2 domain module and economy engine built for the G-MAN automation framework. It bridges Valve Game Coordinator (GC) protocols, live SOCache inventory synchronization, and lossless metal arithmetic into a decoupled, thread-safe Go architecture.

πŸ‡ΊπŸ‡Έ English β€’ πŸ‡·πŸ‡Ί Русский β€’ πŸ“ Parity Specification
go get github.com/lemon4ksan/g-man-tf2

⚑ Key Features

  • Game Coordinator & SOCache Engine (pkg/tf2): Zero-allocation stream parsing of Valve GC Shared Object Cache updates (CMsgSOCacheSubscribed, SO_UPDATE, SO_DESTROY) with instant craft, smelt, and achievement dispatching.
  • Trie-Accelerated Schema Engine (pkg/schema): Dual-index caching (Defindex + Normalized ASCII Trie) parsing official TF2 items_game.txt schemas with sub-millisecond lookups and ~10 MB heap footprint.
  • Lossless Currency & Scrap Arithmetic (pkg/currency): Exact integer scrap arithmetic (currency.Scrap, currency.Currency) eliminating IEEE 754 floating-point rounding errors during multi-key trade valuations.
  • Automated Smelting & Change-Making (pkg/crafting): Class-aware weapon pair combining (CombineWeapons), automated metal uncrafting/crafting, and instant change balancing during trade offer reviews.
  • Native Multi-Service Integrations (pkg/services): High-throughput, typed clients built on aoni for backpack.tf, PriceDB (real-time WebSockets), Mannco.store, Crit.tf, Express-load, and Rep.tf.
  • Decoupled Onion Trade Middlewares (pkg/trading): Composable trading pipeline components (StockLimitMiddleware, PricerMiddleware, AutoCounterMiddleware) for g-man offer evaluation.

βš”οΈ Go vs. Node.js: Why G-MAN TF2 Wins

Historically, Node.js libraries (tf2autobot, tf2-schema, tf2-currencies) have powered TF2 trade bots. In production at scale, JavaScript single-threading and V8 memory pressure create substantial operational bottlenecks:

Dimension πŸ€– G-MAN TF2 (Go) πŸ“¦ Node.js (tf2autobot / tf2-schema) Why it matters
Active Heap per Bot ~8 - 12 MB ~180 - 350 MB Run 20x to 40x more TF2 bots on a single entry-level VPS without OOM kills.
Schema Initialization <40 ms (Trie + Flat Index) 3.5 - 8.0 seconds (V8 JSON tree) Instant bot boot times and immediate recovery from network reconnects.
Currency Math Exact Integer Scrap (int) float + bignumber.js workarounds Zero rounding bugs or floating point drift when balancing 0.11 scrap change.
GC Latency Sub-millisecond Up to 150ms V8 GC pauses Eliminates offer processing lag during high-frequency trade spikes.
Concurrency Native CSP Goroutines Single-threaded Event Loop Multiple accounts, price webhooks, and GC sessions run simultaneously without blocking.

πŸš€ Quick Start

1. Initialize Steam Client with TF2 Plugins
package main

import (
	"context"
	"os"

	"github.com/lemon4ksan/foundation/async/logkit"
	"github.com/lemon4ksan/g-man/pkg/steam"
	"github.com/lemon4ksan/g-man/pkg/steam/auth"
	"github.com/lemon4ksan/g-man/pkg/steam/sys/apps"
	"github.com/lemon4ksan/g-man/pkg/steam/sys/directory"
	"github.com/lemon4ksan/g-man/pkg/steam/sys/gc"
	"github.com/lemon4ksan/g-man/pkg/storage/jsonfile"
	"github.com/lemon4ksan/g-man/pkg/trading/web"

	"github.com/lemon4ksan/g-man-tf2/pkg/backpack"
	"github.com/lemon4ksan/g-man-tf2/pkg/schema"
	"github.com/lemon4ksan/g-man-tf2/pkg/tf2"
)

func main() {
	ctx := context.Background()
	store, _ := jsonfile.New("storage.json")
	logger := logkit.New(logkit.DefaultConfig(logkit.LevelInfo))

	// 1. Initialize core Steam Client with TF2 domain modules
	client, err := steam.NewClient(steam.DefaultConfig(),
		steam.WithLogger(logger),
		steam.WithStorage(store),
		gc.WithModule(),
		apps.WithModule(),
		tf2.WithModule(),
		schema.WithModule(schema.DefaultConfig()),
		backpack.WithModule(),
		web.WithModule(web.DefaultConfig()),
	)
	if err != nil {
		panic(err)
	}
	defer client.Close()

	// 2. Access live backpack tracking synced over Game Coordinator
	bp := backpack.From(client)
	sub := client.Bus().Subscribe(&tf2.BackpackLoadedEvent{})
	go func() {
		for event := range sub.C() {
			if bpEvent, ok := event.(*tf2.BackpackLoadedEvent); ok {
				pure := bp.GetPureStock()
				logger.Info("TF2 Backpack synced!",
					logkit.Int("total_items", bpEvent.Count),
					logkit.Int("keys", pure.Keys),
					logkit.Float64("refined", pure.TotalRefined()),
				)
			}
		}
	}()

	if err := client.Run(); err != nil {
		panic(err)
	}

	// 3. Resolve CM and login
	dir := directory.New(client)
	server, _ := dir.GetOptimalCMServer(ctx)
	login := auth.NewLogOnDetails(os.Getenv("STEAM_USER"), os.Getenv("STEAM_PASS"))

	if err := client.ConnectAndLogin(ctx, server, login); err != nil {
		panic(err)
	}

	client.Wait()
}
2. Lossless Metal & Currency Equations
package main

import (
	"fmt"

	"github.com/lemon4ksan/g-man-tf2/pkg/currency"
)

func main() {
	// Parse float-based refined into exact integer scrap
	scrap := currency.ToScrap(45.33) // 408 Scrap

	// Convert back safely without precision loss
	ref := currency.ToRefined(scrap) // 45.33

	// Create multi-currency struct
	cur := currency.New(2, 45.33)
	fmt.Println(cur.String()) // "2 keys, 45.33 ref"
}
3. Register TF2 Onion-Trading Middlewares
package main

import (
	"github.com/lemon4ksan/foundation/async/logkit"
	"github.com/lemon4ksan/g-man/pkg/trading/engine"
	"github.com/lemon4ksan/g-man-tf2/pkg/backpack"
	"github.com/lemon4ksan/g-man-tf2/pkg/schema"
	"github.com/lemon4ksan/g-man-tf2/pkg/services/pricedb"
	"github.com/lemon4ksan/g-man-tf2/pkg/trading"
)

func RegisterPipeline(
	tradeEngine *engine.Engine,
	bp *backpack.Backpack,
	priceMgr *pricedb.Manager,
	schemaMod *schema.Manager,
	logger logkit.Logger,
) {
	stockCfg := trading.StockConfig{
		MaxTotal:   3000,
		DefaultMax: 20,
		MaxPerSKU: map[string]int{
			"5021;6": 500, // Limit Mann Co. Supply Crate Keys to 500
		},
	}

	tradeEngine.Use(
		// 1. Enforce inventory maximums per SKU
		trading.StockLimitMiddleware(bp, stockCfg, logger),

		// 2. Validate trade prices against PriceDB real-time feeds
		trading.PricerMiddleware(priceMgr, schemaMod.Get, logger),
	)
}

πŸ“‚ Package Architecture

pkg/
β”œβ”€β”€ tf2/              # TF2 Game Coordinator driver & live SOCache storage
β”œβ”€β”€ backpack/         # In-memory inventory projections & item reservation locks
β”œβ”€β”€ crafting/         # Automated weapon combining and metal smelting recipes
β”œβ”€β”€ schema/           # items_game schema parser with Trie & Defindex indexing
β”œβ”€β”€ sku/              # Zero-allocation canonical SKU parser & string formatter
β”œβ”€β”€ currency/         # Exact integer scrap math & key-metal currency equations
β”œβ”€β”€ services/         # Native HTTP/WebSocket clients powered by aoni
β”‚   β”œβ”€β”€ pricedb/      # PriceDB real-time pricing client & WebSocket stream
β”‚   β”œβ”€β”€ bptf/         # backpack.tf API client & listing manager
β”‚   β”œβ”€β”€ crit/         # Crit.tf storefront listing synchronizer
β”‚   β”œβ”€β”€ mannco/       # Mannco.store API & WebSocket market stream
β”‚   β”œβ”€β”€ express/      # Express-load fast inventory service client
β”‚   └── rep/          # Rep.tf trust, feedback, and scammer verification
β”œβ”€β”€ trading/          # Onion-style trading middlewares for g-man trade engine
└── reason/           # Standardized TF2 trade rejection & review reason codes

πŸ“¦ Ecosystem

  • g-man: Core Steam client SDK and multi-game automation runtime.
  • g-man-cli: High-performance background daemon (g-mand) and TUI management CLI (gmanctl).
  • aoni: High-performance network stack, HTTP/2, and WebSocket client engine.
  • foundation: Zero-allocation concurrency, async logging (logkit), and data structures.

Disclaimer: This software is not affiliated with, maintained by, or endorsed by Valve Corporation or any of its subsidiaries. Steam, Team Fortress 2, and all related Valve properties are registered trademarks of Valve Corporation.

This project is licensed under the BSD 3-Clause License. See LICENSE for full details.

Directories ΒΆ

Path Synopsis
cmd
bot command
coverage command
examples
inventory command
maintenance command
internal
bytesconv
Package bytesconv provides zero-allocation byte slice and string manipulation utilities, optimized for Go compiler SSA passes, bounds check elimination (BCE), and SWAR execution.
Package bytesconv provides zero-allocation byte slice and string manipulation utilities, optimized for Go compiler SSA passes, bounds check elimination (BCE), and SWAR execution.
stringpool
Package stringpool implements thread-safe string interning across 64 shards to eliminate duplicate string allocations.
Package stringpool implements thread-safe string interning across 64 shards to eliminate duplicate string allocations.
pkg
backpack
Package backpack manages local inventory caching, item locking, stock calculation, and structural layout sorting for Team Fortress 2.
Package backpack manages local inventory caching, item locking, stock calculation, and structural layout sorting for Team Fortress 2.
behavior/pricemanager
Package pricemanager provides a backpack.tf price manager for the g-man-tf2 bot.
Package pricemanager provides a backpack.tf price manager for the g-man-tf2 bot.
crafting
Package crafting automates metal condensing, weapon smelting, and trade change balancing.
Package crafting automates metal condensing, weapon smelting, and trade change balancing.
currency
Package currency handles Team Fortress 2 monetary calculations, parsing, and formatting.
Package currency handles Team Fortress 2 monetary calculations, parsing, and formatting.
reason
Package reason contains TF2-specific trade decision reason codes.
Package reason contains TF2-specific trade decision reason codes.
schema
Package schema maintains and indexes Team Fortress 2 item definitions, qualities, attributes, and particle effects.
Package schema maintains and indexes Team Fortress 2 item definitions, qualities, attributes, and particle effects.
services/bptf
Package bptf implements a client for the backpack.tf API to manage classified listings and audit user reputations.
Package bptf implements a client for the backpack.tf API to manage classified listings and audit user reputations.
services/crit
Package crit provides a client for interacting with the crit.tf API.
Package crit provides a client for interacting with the crit.tf API.
services/express
Package express provides a client for the Express Load API.
Package express provides a client for the Express Load API.
services/mannco
Package mannco provides the TF2 Mannco.store API client.
Package mannco provides the TF2 Mannco.store API client.
services/pricedb
Package pricedb implements a client for the PriceDB.io API to track TF2 item prices.
Package pricedb implements a client for the PriceDB.io API to track TF2 item prices.
services/rep
Package rep provides utilities for checking user bans against various ban lists.
Package rep provides utilities for checking user bans against various ban lists.
sku
Package sku provides zero-allocation parsing, generation, and validation for Team Fortress 2 Stock Keeping Unit (SKU) strings.
Package sku provides zero-allocation parsing, generation, and validation for Team Fortress 2 Stock Keeping Unit (SKU) strings.
tf2
Package tf2 integrates with the Team Fortress 2 Game Coordinator.
Package tf2 integrates with the Team Fortress 2 Game Coordinator.
trading
Package trading implements Team Fortress 2 automated trading, valuation, and security logic.
Package trading implements Team Fortress 2 automated trading, valuation, and security logic.
protobuf
tf2

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL