Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Websocket対応について #29

Open
BambooTuna opened this issue May 11, 2020 · 0 comments
Open

Websocket対応について #29

BambooTuna opened this issue May 11, 2020 · 0 comments

Comments

@BambooTuna
Copy link
Collaborator

BambooTuna commented May 11, 2020

概要

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}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant