Skip to content

Commit

Permalink
Merge branch 'dev' into stable
Browse files Browse the repository at this point in the history
  • Loading branch information
Niilyx committed Jul 29, 2024
2 parents 1ee4e52 + 06808f5 commit 5cfa051
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
20 changes: 20 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"dockerode": "^3.3.4",
"fastify": "^4.16.0",
"fastify-decorators": "^3.15.0",
"iconv-lite": "^0.6.3",
"ioredis": "^5.3.1",
"reflect-metadata": "^0.1.13"
},
Expand Down
13 changes: 7 additions & 6 deletions src/realms/rest/emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Static, Type } from "@sinclair/typebox"
import { SocketStream } from "@fastify/websocket"
import { WebSocket } from "ws"
import RedisClient from "../../clients/Redis"
import iconv from 'iconv-lite'

export const websockets = new Map<SocketStream, Set<EmitterMessageType>>()

Expand Down Expand Up @@ -91,11 +92,11 @@ export const emitterMessage = Type.Union(

export type EmitterMessage = Static<typeof emitterMessage>

// eslint-disable-next-line no-control-regex
const ANSI_ESCAPE = /\x1b\[*m/g;

function removeAnsiColorCodes(str: string):string {
return str.replace(ANSI_ESCAPE, "");
function ANSItoUTF8(text: string): string {
// convert string to buffer for iconv
const buffer = Buffer.from(text, 'binary');
const res_buff = iconv.encode(iconv.decode(buffer, 'win1251'), 'utf8');
return res_buff.toString('utf8');
}

export const prepareRedisListeners = () => {
Expand All @@ -105,7 +106,7 @@ export const prepareRedisListeners = () => {
if (channel === "emitter") {
const body = JSON.parse(message.toString()) as EmitterMessage
if (body.type === "serverLog") {
body.payload.message = removeAnsiColorCodes(body.payload.message)
body.payload.message = ANSItoUTF8(body.payload.message)
}
emitter.emit(body.type, body.payload)
}
Expand Down

0 comments on commit 5cfa051

Please sign in to comment.