-
Notifications
You must be signed in to change notification settings - Fork 26
WebSocket API
xiaoqch edited this page Sep 7, 2021
·
8 revisions
假人的WebSocket服务器只允许本地连接(即127.0.0.1,本地回环地址)
在v0.2.7之后,可以在Json消息的根对象中加入"id":"packet_id"
作为包ID
并且服务端会在响应消息中附带此ID,以区分不同的包
为了兼容更早的版本,不附带包ID也可以正常收发
- 连接中: 0
- 已连接: 1
- 断开连接中: 2
- 已断开连接: 3
- 重新连接中: 4
- 停止中: 5
- 已停止: 6
若发生了一下几个事件之一,WebSocket服务端会发送信息给所有已连接的客户端
{
"event": "add",
"data": {
"name": "name",
"state": 0
}
}
{
"event": "remove",
"data": {
"name": "name"
}
}
{
"event": "connect",
"data": {
"name": "name",
"state": 0
}
}
{
"event": "disconnect",
"data": {
"name": "name",
"state": 0
}
}
{
"type": "list"
}
{
"type": "add",
"data": {
"name": "假人名称",
"skin": "假人皮肤(steve或alex)",
"allowChatControl": true
}
}
注: allowChatControl
默认为false
{
"type": "remove",
"data": {
"name": "假人名称"
}
}
{
"type": "getState",
"data": {
"name": "假人名称"
}
}
{
"type": "getState_all"
}
{
"type": "disconnect",
"data": {
"name": "假人名称"
}
}
{
"type": "connect",
"data": {
"name": "假人名称"
}
}
{
"id": "包ID(任意字符,可选)",
"type": "remove_all"
}
{
"id": "包ID(任意字符,可选)",
"type": "disconnect_all"
}
{
"id": "包ID(任意字符)",
"type": "connect_all"
}
{
"type": "setChatControl",
"data": {
"name": "假人名称",
"allowChatControl": true
}
}
注: true
表示启用false
表示禁用
{
"type": "list",
"data": {
"list": [
"假人名称1",
"假人名称2"
]
}
}
{
"type": "add",
"data": {
"name": "假人名称",
"success": true,
"reason": ""
}
}
{
"type": "remove",
"data": {
"name": "假人名称",
"success": true,
"reason": ""
}
}
{
"type": "getState",
"data": {
"name": "假人名称",
"success": true,
"reason": "",
"state": 0
}
}
{
"type": "getState_all",
"data": {
"playersData": {
"FakePlayer1": {
"state": 0,
"allowChatControl": false
},
"FakePlayer2": {
"state": 1,
"allowChatControl": true
}
}
}
}
{
"type": "disconnect",
"data": {
"name": "假人名称",
"success": true,
"reason": ""
}
}
{
"type": "connect",
"data": {
"name": "假人名称",
"success": true,
"reason": ""
}
}
{
"id": "包ID(照原样响应,原本没有此项响应就没有此项)",
"type": "remove_all",
"data": {
"list": [
"移除的假人列表"
]
}
}
{
"id": "包ID(照原样响应)",
"type": "disconnect_all",
"data": {
"list": [
"断开连接的假人列表"
]
}
}
{
"id": "包ID(照原样响应)",
"type": "connect_all",
"data": {
"list": [
"连接的假人列表"
]
}
}
{
"type": "setChatControl",
"data": {
"name": "假人名称",
"success": true,
"reason": ""
}
}