F - 7 GameLift RealTimeサーバでマルチ プレイゲームを作る 04 · •...
Transcript of F - 7 GameLift RealTimeサーバでマルチ プレイゲームを作る 04 · •...
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
T O K Y O
20
19
.10
.03
-0
4GameLift RealTimeサーバでマルチプレイゲームを作る
ハンリャン(Fan Liang)ソリューションアーキテクトAmazon Web Service Japan K.K.
F - 7
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Agenda
マルチプレイゲームについて
Amazon GameLiftの紹介
GameLift Realtime Serversでサンプルゲームを作る
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
自己紹介
Fan Liang(ハンリャン)
ソリューションアーキテクト
ゲームのお客様を担当
好きな AWS サービス:Amazon GameLift
最近のゲーム:World of Warcraft Classic
3
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
マルチプレイゲームとは
他のプレイヤーと一緒に同じゲーム環境で対戦・協力して遊ぶゲームモードのこと
ローカル オンライン
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
ゲームにおけるユーザー間の連携度合い
個人プレイを中心したゲームプレイヤー間の連携はなしもしくはフレンドサポート機能だけ
個人プレイを中心としたゲーム
一部対戦や共同プレイの機能があります。
セッションベースで、マルチプレイを中心としたゲーム複数ユーザーで対戦するゲーム
大量のユーザーが同じ世界でプレイできるゲーム
本日のメイントピック
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
AZ AZ
CloudFront
S3
ALB
API(EC2/ECS)
ElastiCache
RDS(master)
VPC
API(EC2/ECS)
ElastiCache
RDS(slave)
ロードバランサー
APIサーバ
キャッシュ
データベース
アセット配信
個人プレイ中心のゲームバックエンドン構成
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
典型的なセッションベースのゲームフロー
APIサーバ
• 新規登録/ログイン• 認証認可, セッション管理• ロビー/イベント• ステータス /リーダーボード• ゲームモード, オプション• マッチング• ゲーム終了, チート対策
ゲームサーバ
• ゲームマップホスト• セッション管理• ゲームプレイ、マップ更新• データ同期• ゲームプレイ; チート対策• ゲーム終了レポート
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Backend
専用ゲームサーバ
マルチプレイヤーゲームを作るために
例えば、
• プレイヤーをどのようにマッチングさせる?
• 低レイテンシーをどう実現する?
• スケーリングはどのように行う?
• セキュリティはどう確保する?
• 専用ゲームサーバを作るために
どんな専門的な知識が必要か?
など……
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Amazon GameLift
セッションベースのマルチプレイヤーゲーム専用のゲ
ームサーバをデプロイ、運用、スケーリングするため
のマネージドサービスです
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Amazon GameLift
11
低レイテンシの実現16のAWSリージョンの中でプレイヤーにとって最も近いゲームサーバにセッションを割り当て
FlexMatchのカスタムマッチメイクで高機能なゲームプレイを実現レイテンシのバランス、Wait時間、対戦レベルに適した独自のマッチメイキングロジックを実装
手間のかかる作業は完了済ソフトウェアをビルドするためのエンジニア作業+GameLift
による信頼性の高い運用
キャパシティプランニングなしでローコスト&ハイスケールユーザが必要なキャパシティを自動でスケールアップ・ダウン、実際に利用した分だけお支払い
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Backend
専用ゲームサーバ
マルチプレイヤーゲームを作るために
Amazon GameLift
例えば、
• プレイヤーをどのようにマッチングさせる?
• 低レイテンシーをどう実現する?
• スケーリングはどのように行う?
• セキュリティはどう確保する?
• 専用ゲームサーバを作るために
どんな専門的な知識が必要か?
など……
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
GameLiftの実装パターン
Amazon GameLift
Server SDK
カスタムゲームサーバ
リアルタイムサーバ
接続
Amazon GameLift
Amazon GameLift
Amazon GameLift
Realtime Client SDK
クライアント
クライアントゲームサーバ
ゲームサーバ
ゲームサーバ
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
GameLiftの実装パターン
Amazon GameLift
Server SDK
カスタムゲームサーバ
リアルタイムサーバ
接続
Amazon GameLift
Amazon GameLift
Amazon GameLift
Realtime Client SDK
クライアント
クライアントゲームサーバ
ゲームサーバ
ゲームサーバ
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
Node.jsベースのゲームサーバ
Javascriptを使ってゲームサーバの振る舞いを定義
ステートフル or ステートレス
TCP/UDP対応
Amazon GameLiftのマッチメイキングとのインテグレーション
1プレイヤーにつき1ヶ月あたり数円のコスト
Amazon GameLiftRealtime Servers
GameLift Realtime Servers
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
GameLift Realtime Servers
プレイヤー間で少量のデータを交換
複雑度が低い処理
Role Playing
Card Games
MobileMatch 3
Turn based strategy
Real time strategy
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
参考ユースケース
簡単なゲームサーバロジック
プレイヤーの確認
チート検出
ペアメッセージング
スクリプトのハンドリング
サーバの初期化時
プレイヤー受け入れ時
プレイヤーの接続/切断時
Realtime Scripts
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
依存するライブラリを含めたスクリプトをzipでかためてパッケージング
AWSコンソールもしくはS3バケットにアップロード
Realtime Scripts
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
C#をサポート
クライアントコールは同期アクションと非同期コールバックをサポート
Game client integration
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
21
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
サンプルゲームについて
対戦機能のあるテトリスを作る
相手に邪魔ブロックを送信する機能を追加する
サンプルはUnityで作っているが、別のゲームエンジンからも利用可能。コードはサンプルであり、プロダクションレベルではない
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
対戦機能あるテトリスのDemo
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
マルチプレイに改装するため
サーバの準備とSDKの導入
ロビーの部分実装部屋の作成/加入/検索
ゲームの部分実装ゲーム準備OK/ゲーム開始盤面の情報を共有1行削除したら、相手にランダムブロック
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
マルチプレイに改装するため
サーバの準備とSDKの導入
ロビーの部分実装部屋の作成/加入/検索
ゲームの部分実装ゲーム準備OK/ゲーム開始盤面の情報を共有1行削除したら、相手にランダムブロック
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
サーバサイドの準備
Server scriptsをGameLiftにアップロードする
サーバの数とスペックを決めて、起動する
その他サーバの設定
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
クライエントサイドの準備
公式サイトからGameLift SDKとGamelift Realtime ClientSDK2つをダウンロードする
パッケージをビルドし、プロジェクトにインポート
注意点:GameLift Realtime Client SDKは現在C#のみサポート。
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
マルチプレイに改装するため
サーバの準備とSDKの導入
ロビーの部分実装部屋の作成/加入/検索
ゲームの部分実装ゲーム準備OK/ゲーム開始盤面の情報を共有1行削除したら、相手にランダムブロック
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
部屋の作成
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
部屋作成の裏側はどのように動いているか
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
部屋の加入
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
部屋加入の裏側はどのように動いているか
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
部屋の加入
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
部屋の検索
34
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
ゲーム終了の際に
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
マルチプレイに改装するため
サーバの準備とSDKの導入
ロビーの部分実装部屋の作成/加入/検索
ゲームの部分実装ゲーム準備OK/ゲーム開始盤面の情報を共有1行削除したら、相手にランダムブロック
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
ゲーム準備OK/ゲーム開始のプロセス
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
ゲーム準備OK/ゲーム開始のプロセス
コネクションを作る
クライアントからOKを送信
サーバからゲーム開始をクライエントに送る
クライアントから受信し、関連動作を行う
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
ゲーム準備OK/ゲーム開始のプロセス
realtime serverとクライエント間コネクションが確立された
TCPとUDPの両方で通信可能
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
RTMessageの構造(Protobufを利用して送信)opcode(必須):開発者定義のオペレーションコードpayload:メッセージの内容targetGroup:送信グループtargetPlayer:送信対象deliveryIntent:送信タイプ(TCP/UDP)
40
RTMessageの構造
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
サンプルテトリスのopcode定義
41
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
クライエントからOKを送信
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
サーバからゲーム開始をクライエントに送る(1)
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
サーバからゲーム開始をクライエントに送る(2)
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
サーバからデータ受信
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
マルチプレイに改装するため
サーバの準備とSDKの導入
ロビーの部分実装部屋の作成/加入/検索
ゲームの部分実装ゲーム準備OK/ゲーム開始盤面の情報を共有1行削除したら、相手にランダムブロック
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
盤面の情報を共有(1)
盤面情報キャプチャ
Viewerにセット
テトリス盤面の情報をシリアライズして、ネットワーク経由で送信する
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
盤面の情報を共有(2)
GridManager.cs:テトリス盤面の情報を記録する
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
盤面の情報を共有(3)
Viewer.cs:情報された情報を表示する
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
盤面の情報を共有(4)
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
マルチプレイに改装するため
サーバの準備とSDKの導入
ロビーの部分実装部屋の作成/加入/検索
ゲームの部分実装ゲーム準備OK/ゲーム開始盤面の情報を共有1行削除したら、相手にランダムブロック
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
サーバロジック追加(相手にランダムブロック)
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
まとめ:Amazon GameLift利用するメリット
SDKを利用し、数行のコードだけで、セッションとマッチングの管理ができる
通信フレームワークが定義されているので、ゲームロジックを専念できる
わずかなコストで数百万のプレイヤーにスケーリングできる
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
アンケートご協力のお願いお手持ちの受講票のアンケート用QRコードから
アンケートにお答えいただくと、記念品を差し上げております。
※イメージです
プレゼントの引き換えは、神田明神の会場出口付近(屋外)までお越しください
IT情報安全守護
2019 年 10 月 1 日〜11 月 5 日開催amzn.to/AWSInnovateJP
申し込み受付中
AWS 最新アップデート / コンテナ / AIML / AWS アンチパターン /
認定試験対策講座など60セッション
オンラインで参加できるカンファレンス、全 60 セッション
10/9, 10/15 ライブ配信
AWS エキスパートへのQ&A
修了証明書の発行業務時間に視聴
2019 年 10 月 1 日〜11 月 5 日開催amzn.to/AWSInnovateJP
Application Development
Container
Serverless
オンラインで参加できるカンファレンス、全 60 セッション
おすすめセッション
Thank you!
© 2019, Amazon Web Services, Inc. or its affiliates. All rights reserved.
ハンリャン(Fan Liang)