Skip to content

Websocket対応について #29

@BambooTuna

Description

@BambooTuna

概要

WebGLでプレイできるようにするために通信をWebsocketに移行
親と子どちらも一つのWebsocketコネクションを最後まで使う。

データ型

JoinRoomResponse

  1. roomId: String
  2. vagrant: Int

ReadyResponse

  1. roomId: String
  2. ghostRecord: List[Any]
  3. member: List[Member]
  4. yourDirection: Direction

Member(Object)

  1. accountName: String
  2. direction: Direction

Direction(Enum)

  1. "Up"
  2. "Down"
  3. "Left"
  4. "Right"

Coordinate

  1. x: Float
  2. y: Float
  3. z: Float
  4. elapsedTime: Int

Operation

  1. direction: Direction
  2. strength: Float

SendResultRequest

  1. ghostRecord: List[Coordinate]
  2. isGameClear: Boolean
  3. elapsedTime: Int

SimpleGameResult

  1. isGameClear: Boolean
  2. elapsedTime: Int

ErrorResponse

  1. errorType: ErrorType
  2. message: String

ErrorType(Enum)

  1. "RoomNotFound"
    ランダム参加にて部屋がない場合・合言葉が間違っている場合

  2. "LostConnection"
    ゲーム参加者のコネクションが切れた場合

  3. "MalformedMessageType"
    送信のデータ形式が間違っている場合

親の流れ

$ wscat -c "ws://localhost:18080/create_room?accountId=parent&accountName=parentName"
or
$ wscat -c "ws://localhost:18080/create_room?accountId=parent&accountName=parentName&roomKey=abc"

// 人が入ってきたらJoinRoomResponseが届く(JoinRoomResponse)
< {"roomId":"1f348ba9bf264296bc6fa87e55575781", "vagrant":3}
< {"roomId":"1f348ba9bf264296bc6fa87e55575781", "vagrant":2}
< {"roomId":"1f348ba9bf264296bc6fa87e55575781", "vagrant":1}
< {"roomId":"1f348ba9bf264296bc6fa87e55575781", "vagrant":0}

// 揃ったらReadyResponseが届く(ReadyResponse)
< 
{
    "roomId":"1f348ba9bf264296bc6fa87e55575781", 
    "yourDirection":"Up", 
    "member":[
        {
        "accountName":"parent",
        "direction":"Up"
        }, 
        {
        "accountName":"child1",
        "direction":"Down"
        }, 
        {
        "accountName":"child2",
        "direction":"Left"
        }, 
        {
        "accountName":"child3",
        "direction":"Right"
        }
    ]
}
// ゲームスタート

// 親はCoordinateを送信する(Coordinate)
> {"x":0.1, "y":0.1, "z":0.1, "elapsedTime":1}

// 子の操作情報が届く(Operation)
< {"direction":"Left", "strength":0.1}
< {"direction":"Down", "strength":0.1}
> {"x":0.1, "y":0.1, "z":0.1, "elapsedTime":2}
< {"direction":"Right", "strength":0.1}
> {"x":0.1, "y":0.1, "z":0.1, "elapsedTime":3}

// リザルトの送信(SendResultRequest)
> {"ghostRecord":[], "isGameClear":true, "elapsedTime":180}

子の流れ

$ wscat -c "ws://localhost:18080/join_room?accountId=child1&accountName=child1Name"
or
$ wscat -c "ws://localhost:18080/join_room?accountId=child1&accountName=child1Name&roomKey=abc"

// 人が入ってきたらJoinRoomResponseが届く(JoinRoomResponse)
< {"roomId":"1f348ba9bf264296bc6fa87e55575781", "vagrant":2}
< {"roomId":"1f348ba9bf264296bc6fa87e55575781", "vagrant":1}
< {"roomId":"1f348ba9bf264296bc6fa87e55575781", "vagrant":0}

// 揃ったらReadyResponseが届く(ReadyResponse)
< 
{
    "roomId":"1f348ba9bf264296bc6fa87e55575781", 
    "yourDirection":"Down", 
    "member":[
        {
        "accountName":"parent",
        "direction":"Up"
        }, 
        {
        "accountName":"child1",
        "direction":"Down"
        }, 
        {
        "accountName":"child2",
        "direction":"Left"
        }, 
        {
        "accountName":"child3",
        "direction":"Right"
        }
    ]
}

// ゲームスタート

// 親のCoordinate情報が届く(Coordinate)
< {"x":0.1, "y":0.1, "z":0.1, "elapsedTime":1}

// 子の操作情報を送信する(Operation)
> {"direction":"Down", "strength":0.1}
< {"x":0.1, "y":0.1, "z":0.1, "elapsedTime":2}
< {"x":0.1, "y":0.1, "z":0.1, "elapsedTime":3}

// リザルトが届く(SimpleGameResult)
< {"isGameClear":true, "elapsedTime":180}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions