ck3c.xpdbk.com WebSocket API 文档 (WSS)

概述

本API是check3c.xpdbk.com这个前端使用的API

游戏内名字是 3C3U_XPDBK_COM

本 API 文档描述了如何通过安全的 WebSocket (WSS) 协议与 ck3c.xpdbk.com 服务器进行通信。通过 WSS,您可以实时接收 3C3U 服务器的游戏事件和统计信息,例如聊天消息、玩家加入/离开、死亡、击杀、成就,以及服务器的在线人数和队列人数。

安全性

由于使用了 WSS 协议,您的连接是加密的,可以防止数据被窃听或篡改。

接口地址

连接方式

  1. 客户端: 使用支持 WebSocket Secure (WSS) 的客户端库。
  2. 连接: 创建一个到 wss://ck3c.xpdbk.com 的 WSS 连接。
  3. 认证: (如果需要) 某些接口可能需要认证,具体认证方式(例如,Token)将另行提供。请确保您的客户端在建立连接后,立即发送认证信息。

消息格式

服务器和客户端之间的所有消息都使用 JSON (JavaScript Object Notation) 格式。

基本结构:

{
  "type": "<消息类型>",
  "data": <消息数据>
}

消息类型 (服务器 -> 客户端)

服务器会主动推送以下类型的消息给客户端:

1. welcome

连接成功后,服务器发送的欢迎消息。

type: "welcome"

data:

{
  "message": "已连接到 3C3U 服务器信息流!"
}

2. stats

服务器的统计信息。

type: "stats"

data:

{
  "chat": {
    "total": 1234,  // 总聊天消息数
    "byPlayer": {
      "玩家A": 123,  // 玩家A 发送了 123 条消息
      "玩家B": 456   // 玩家B 发送了 456 条消息
    }
  },
  "death": {
    "total": 50,     // 总死亡次数
    "byPlayer": {
      "玩家A": 10,   // 玩家A 死了 10 次
      "玩家C": 5     // 玩家C 死了 5 次
    },
    "byReason": {
      "fall_damage": 20,  // 摔死 20 次
      "lava": 10        // 淹死在熔岩中 10 次
    }
  },
  // ... 其他统计信息 (kill, join, leave, achievement, onlineTime, firstSeen, lastSeen)
}

3. chatLog

最近的聊天记录。

type: "chatLog"

data:

[
  {
    "timestamp": "2024-01-01T12:00:00.000Z",  // 消息发送的时间
    "playerName": "玩家A",                // 发送消息的玩家
    "message": "大家好!"                      // 消息内容
  },
  {
    "timestamp": "2024-01-01T12:00:10.000Z",
    "playerName": "玩家B",
    "message": "你好!"
  }
  // ... 更多聊天记录
]

4. tabUpdate

服务器标签(Tab 列表)信息。

type: "tabUpdate"

data:

{
  "onlinePlayers": 200,    // 在线玩家总数
  "playingPlayers": 180,   // 正在游戏的玩家数量(可能小于 onlinePlayers)
  "queuePlayers": 20,     // 排队玩家数量
  "timestamp": "2024-01-01T12:00:00.000Z",  // 更新时间
  "onlinePlayerNames": ["玩家A", "玩家B", "玩家C"]  // 在线玩家名称列表
}

5. 实时事件消息 (chat, death, join, leave, achievement, kill, system)

服务器会实时推送以下类型的事件消息:

通用结构:

{
  "type": "<消息类型>",
  "data": {
    // 事件相关的数据
  }
}

例子:

{
  "type": "chat",
  "data": {
    "timestamp": "2024-01-01T12:00:00.000Z",
    "playerName": "玩家A",
    "message": "有人在吗?"
  }
}
{
  "type": "death",
  "data": {
    "message": "[玩家B] 被骷髅射死了!"
  }
}
{
  "type": "join",
  "data": {
    "message": "[玩家C] 加入了游戏!"
  }
}
{
  "type": "system",
  "data": {
    "timestamp": "2024-01-01T12:00:00.000Z",
    "playerName": "System",
    "message": "服务器正在重启..."
  }
}

消息类型 (客户端 -> 服务器)

客户端可以发送以下消息给服务器:

1. getStats

请求服务器发送最新的统计信息。

type: "getStats"

data: (空对象)

{}

2. getChatLog

请求服务器发送聊天记录。

type: "getChatLog"

data:

{
  "days": 7  // 可选,要获取的聊天记录天数 (默认为 1 天)
}

代码示例 (JavaScript)

const WebSocket = require('ws');

const ws = new WebSocket('wss://ck3c.xpdbk.com');

ws.onopen = () => {
  console.log('成功连接到 wss://ck3c.xpdbk.com!');

  // 发送获取统计信息的请求
  ws.send(JSON.stringify({ type: 'getStats', data: {} }));

  // 发送获取 7 天聊天记录的请求
  ws.send(JSON.stringify({ type: 'getChatLog', data: { days: 7 } }));
};

ws.onmessage = (event) => {
  const message = JSON.parse(event.data);
  console.log('收到消息:', message);

  if (message.type === 'stats') {
    console.log('统计数据:', message.data);
  } else if (message.type === 'chatLog') {
    console.log('聊天记录:', message.data);
  } else if (message.type === 'tabUpdate') {
    console.log('在线人数:', message.data.onlinePlayers);
    console.log('队列人数:', message.data.queuePlayers);
  } else if (message.type === 'chat') {
    console.log('新聊天消息:', message.data.playerName, message.data.message);
  }
  // ... 处理其他类型的消息
};

ws.onclose = () => {
  console.log('连接已关闭');
};

ws.onerror = (error) => {
  console.error('发生错误:', error);
};

注意事项