添加双语注释
This commit is contained in:
1 parent
9227d94e79
commit
4ceba6a609
14 files changed
+542
-74
No files matched your search
+16
-1
@@ -5,6 +5,8 @@
|
||||
const crypto = require('crypto');
|
||||
const ws = require('ws');
|
||||
|
||||
// Generate a new RSA key pair
|
||||
// 生成一个新的 RSA 密钥对
|
||||
const generateRSAKeyPair = () => {
|
||||
try {
|
||||
console.log('Generating new RSA keypair...');
|
||||
@@ -62,6 +64,8 @@ console.log('server started', config.wsHost, config.wsPort);
|
||||
var clients = {};
|
||||
var channels = {};
|
||||
|
||||
// WebSocket server connection event handler
|
||||
// WebSocket 服务器连接事件处理程序
|
||||
wss.on('connection', (connection) => {
|
||||
|
||||
if (
|
||||
@@ -256,6 +260,8 @@ wss.on('connection', (connection) => {
|
||||
|
||||
});
|
||||
|
||||
// Process encrypted messages
|
||||
// 处理加密消息
|
||||
const processEncryptedMessage = (clientId, message) => {
|
||||
let decrypted = null;
|
||||
|
||||
@@ -288,6 +294,8 @@ const processEncryptedMessage = (clientId, message) => {
|
||||
}
|
||||
};
|
||||
|
||||
// Handle channel join requests
|
||||
// 处理加入频道请求
|
||||
const handleJoinChannel = (clientId, decrypted) => {
|
||||
if (
|
||||
!isString(decrypted.p) ||
|
||||
@@ -314,6 +322,8 @@ const handleJoinChannel = (clientId, decrypted) => {
|
||||
}
|
||||
};
|
||||
|
||||
// Handle client messages
|
||||
// 处理客户端消息
|
||||
const handleClientMessage = (clientId, decrypted) => {
|
||||
if (
|
||||
!isString(decrypted.p) ||
|
||||
@@ -345,6 +355,8 @@ const handleClientMessage = (clientId, decrypted) => {
|
||||
}
|
||||
};
|
||||
|
||||
// Handle channel messages
|
||||
// 处理频道消息
|
||||
const handleChannelMessage = (clientId, decrypted) => {
|
||||
if (
|
||||
!isObject(decrypted.p) ||
|
||||
@@ -381,6 +393,8 @@ const handleChannelMessage = (clientId, decrypted) => {
|
||||
}
|
||||
};
|
||||
|
||||
// Broadcast member list to channel
|
||||
// 向频道广播成员列表
|
||||
const broadcastMemberList = (channel) => {
|
||||
try {
|
||||
const members = channels[channel];
|
||||
@@ -409,7 +423,8 @@ const broadcastMemberList = (channel) => {
|
||||
|
||||
|
||||
|
||||
|
||||
// Log events with timestamps and levels
|
||||
// 记录带时间戳和级别的事件
|
||||
const logEvent = (source, message, level) => {
|
||||
if (
|
||||
level !== 'debug' ||
|
||||
|
||||
Reference in new issue
Block a user