53 lines
1.8 KiB
TypeScript
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',
|
|
} |