squidGame/tgx-games-server/src/common/NetworkUtil.ts

53 lines
1.8 KiB
TypeScript

import exp from "constants";
const os = require('os');
export class NetworkUtil {
public static getLocalIPv4(): string | undefined {
// get information of all network interfaces
// 获取所有网络接口信息
const networkInterfaces = os.networkInterfaces();
let ipAddress;
Object.keys(networkInterfaces).forEach((interfaceName) => {
const interfaces = networkInterfaces[interfaceName];
// traverse IPv4 address for each network interface
// 遍历每个网络接口下的IPv4地址
for (let i = 0; i < interfaces.length; i++) {
const addressInfo = interfaces[i];
if (!addressInfo.internal && addressInfo.family === 'IPv4') {
ipAddress = addressInfo.address;
break;
}
}
});
return ipAddress;
}
}
export enum NetErrorMsg {
="success",
= "socket timeout",
= "socket error",
socket关闭 = "socket closed",
socket服务器关闭 = "socket closed by server",
socket客户端关闭 = "socket closed by client",
="gold insufficient",
="item insufficient",
="no card",
="NO_Room",
="delete failed",
="not login",
='save failed',
='user not exist',
='Map Level Not Found',
='Map Level Type Not Match',
='Not enough tili',
='Map Level Not Unlock',
='failed',
="no commander",
="no config data",
='compose failed',
}