Skip to content

Commit

Permalink
Steam microservices (#360)
Browse files Browse the repository at this point in the history
  • Loading branch information
Geczy committed Oct 6, 2023
2 parents 0e7694e + 0ad5d3b commit dc904ec
Show file tree
Hide file tree
Showing 8 changed files with 218 additions and 180 deletions.
12 changes: 5 additions & 7 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ services:
restart: on-failure

twitch-chat:
image: "ghcr.io/dotabod/twitch-chat:v2.0"
image: "ghcr.io/dotabod/twitch-chat:v2.1"
platform: linux/amd64
container_name: twitch-chat
restart: on-failure
Expand All @@ -31,7 +31,7 @@ services:
- ./packages/twitch/chat/locales:/app/packages/twitch/chat/locales

steam:
image: "ghcr.io/dotabod/steam:v2.0"
image: "ghcr.io/dotabod/steam:v2.1"
platform: linux/amd64
container_name: steam
restart: on-failure
Expand All @@ -48,11 +48,9 @@ services:
- STEAM_USER
- STEAM_WEB_API
- NODE_ENV
volumes:
- ./packages/steam/locales:/app/packages/steam/locales

twitch-events:
image: "ghcr.io/dotabod/twitch-events:v2.0"
image: "ghcr.io/dotabod/twitch-events:v2.1"
platform: linux/amd64
container_name: twitch-events
restart: on-failure
Expand All @@ -78,7 +76,7 @@ services:
- TWITCH_EVENTSUB_SECRET

dota:
image: "ghcr.io/dotabod/dota:v2.0"
image: "ghcr.io/dotabod/dota:v2.1"
platform: linux/amd64
container_name: dota
restart: on-failure
Expand Down Expand Up @@ -121,7 +119,7 @@ services:
nginx:
container_name: nginx
restart: on-failure
image: "ghcr.io/dotabod/nginx:v2.0"
image: "ghcr.io/dotabod/nginx:v2.1"
platform: linux/amd64
volumes:
- ./services/nginx/default.conf:/etc/nginx/templates/default.conf.template
Expand Down
1 change: 0 additions & 1 deletion packages/dota/src/dota/events/gsi-events/newdata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ async function saveMatchData(client: SocketClient) {
if (!steamServerId && !lobbyType) {
if (steamServerLookupMap.has(matchId)) return

// Wrap the steamSocket.emit in a Promise
const getDelayedDataPromise = new Promise<string>((resolve, reject) => {
steamSocket.emit('getUserSteamServer', client.steam32Id, (err: any, cards: any) => {
if (err) {
Expand Down
2 changes: 1 addition & 1 deletion packages/dota/src/dota/lib/getPlayers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export async function getPlayers({
})

const getCardsPromise = new Promise<Cards[]>((resolve, reject) => {
steamSocket.emit('getCards', accountIds, (err: any, cards: any) => {
steamSocket.emit('getCards', accountIds, false, (err: any, cards: any) => {
if (err) {
reject(err)
} else {
Expand Down
2 changes: 1 addition & 1 deletion packages/dota/src/steam/ws.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ import { logger } from '../utils/logger.js'
export const steamSocket = io('ws://steam:5035')

steamSocket.on('connect', () => {
logger.info('We alive on dotabod steam server!')
logger.info('We alive on steamSocket steam server!')
})
3 changes: 1 addition & 2 deletions packages/dota/src/twitch/commands/items.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ async function getItems({
locale: string
command: string
}) {
const { hero, items, playerIdx, player } = await profileLink({
const { hero, items, playerIdx } = await profileLink({
command,
packet,
locale,
Expand Down Expand Up @@ -81,7 +81,6 @@ async function getItems({
throw new CustomError(t('missingMatchData', { emote: 'PauseChamp', lng: locale }))
}

// Wrap the steamSocket.emit in a Promise
const getDelayedDataPromise = new Promise<DelayedGames>((resolve, reject) => {
steamSocket.emit(
'getRealTimeStats',
Expand Down
3 changes: 1 addition & 2 deletions packages/dota/src/twitch/commands/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ commandHandler.registerCommand('test', {
steamServerId,
})

// Wrap the steamSocket.emit in a Promise
const getDelayedDataPromise = new Promise<DelayedGames>((resolve, reject) => {
steamSocket.emit(
'getRealTimeStats',
Expand Down Expand Up @@ -91,7 +90,7 @@ commandHandler.registerCommand('test', {
const { accountIds } = await getAccountsFromMatch({
gsi: client.gsi,
})
steamSocket.emit('getCards', accountIds, (err: any, response: any) => {
steamSocket.emit('getCards', accountIds, false, (err: any, response: any) => {
console.log(response, err) // one response per client
})

Expand Down
19 changes: 11 additions & 8 deletions packages/steam/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,17 @@ io.on('connection', (socket) => {
hasDotabodSocket = false
})

socket.on('getCards', async function (accountIds: number[], callback: callback) {
if (!isConnectedToSteam) return
try {
callback(null, await dota.getCards(accountIds))
} catch (e: any) {
callback(e.message, null)
}
})
socket.on(
'getCards',
async function (accountIds: number[], refetchCards: boolean, callback: callback) {
if (!isConnectedToSteam) return
try {
callback(null, await dota.getCards(accountIds, refetchCards))
} catch (e: any) {
callback(e.message, null)
}
},
)

socket.on('getCard', async function (accountId: number, callback: callback) {
if (!isConnectedToSteam) return
Expand Down
Loading

0 comments on commit dc904ec

Please sign in to comment.