Skip to content
xiaoqch edited this page Sep 7, 2021 · 8 revisions

NOTE

假人的WebSocket服务器只允许本地连接(即127.0.0.1,本地回环地址)

在v0.2.7之后,可以在Json消息的根对象中加入"id":"packet_id"作为包ID
并且服务端会在响应消息中附带此ID,以区分不同的包
为了兼容更早的版本,不附带包ID也可以正常收发

State枚举的值

  • 连接中: 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": ""
    }
}