COSCUP
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Write
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Versions and GitHub Sync Note Insights Sharing URL Help
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Write
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       owned this note    owned this note      
    Published Linked with GitHub
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    # 來做一個日系卡牌手遊吧! - 蒼時弦也 {%hackmd tGp8pt49Q2aT5cD5TFyaIA %} > 請從這裡開始 ## 工商時間 每周二晚上 ruby默默會 https://www.facebook.com/rubymokumokukai/ 五倍紅寶石台北出礦坑 / 台北市衡陽路 7 號 5 樓 ## 起源 接到做手遊的case 網路上其實找不到手遊的source 先不討論連線遊戲,只討論卡牌手遊 ## 今天想討論 * 概觀 * 架構 * **開發** 今天重點 * 部署 * 拓展 ### 手遊伺服器 會斷線和不會斷線 手遊是非長連線類型,送完狀態就斷線 不會斷線就是socket之類的 ## http協議 通常只有登入會用tcp 登入後就會用udp廣播 所以很容易瞬移 想長連線可能會用websocket轉長連線,但他還是有效能問題 ## 手遊Server 先暫定為 使用 WebServer 可能的選項 * php * python * java * node.s * ruby * golang * etc... 要考慮的問題:針對5人以下小團隊,人少能不能handle? ## RoR * 日本手遊常用 * 開發時程短 * 容易上手 * 生態系完整 (很多套件 裝一裝就好了) 怪物彈珠就是用RoR做的 不用擔心Server負擔重 負擔重的都不是在Server上 ## RoR在台灣 * 效能上略差 * 台灣不好找人 (社群邊緣) * 不容易拓展 (套件是整坨寫,所以很難拆micro service) ## 要選什麼語言或框架 人力資源 遊戲性質 部署方式 依照團隊狀況選擇適合的方案 ## OAuth2 * Facebook google等第三方登入 * 不代表安全 * 容易管理API權限 * (手遊)有時候會客製化調整 搞不好以前手遊都沒做 Https 所以都是裸奔狀態 ## 或是用雲端服務 * Firebase * AWS Cognito AWS是因為是贊助商得提一下(笑) Firebase聽說後台找不到匯出... Firebase小心收費問題 ## API設計 * 全程SSL加密連線 * 參考RESTful設計 (沒有狀態設計) * JSON格式方便串接 * 盡量自己設計 配合Deserialize 例如有個任務列表 要開始遊戲 按下開始遊戲後,回傳一個開始成功,遊戲才觸發換場景 切換到對話,真正輸出對話,傳下一句話,才真正顯示對話 設計API要注意確保沒有狀態 ## 中間人攻擊 客戶端 發送資料← → 回傳資料 伺服器 雲端服務基本上都能協助配置SSL ## OAuth2 有現成的套件 都用doorkeeper解決 > 你以為很簡單? 難在客戶端的安全性 ## 登入安全性 要使用HSM加密 Hardware Security Module 大部分手機都支援 在玩家手機上產生密鑰或指紋 把Token做AES加密塞進去 Oauth Refresh Token 驗證Token也要認Device ID > 不過你用Unity這些得自己想辦法 ## RESTful API 採 動作/資源 的思考模式 實作好懂 統一 ## JSON JsonUtility.FormJson<story> 不能傳array > 文本資料一定要送嗎 ## 客戶端資料庫 SQLite蠻好用的 建議用SQLCipher加密 多語系可處理 平常只傳PKey ## AssetBundle 把圖檔跟主程式拆出來單獨下載 遊戲更新可能是Zip包含文本跟圖檔 伺服器要實作Bundle API App store或GooglePlay可能有時間差 手遊大多數都是增加功能,所以 包 zip應該可以 ## 抽卡機制 假設總卡片1000張,每抽掉一張就減少一張 很簡單的設定機率演算法 其實就是卡池放 X(類型)*Y (數量)種卡 ## PickUp卡池的做法 3%變6%怎麼解? 會把PickUp卡分出來 先抽是哪一堆 再抽卡 PickUp卡池 和 普通卡池 分出來 有可能你抽到稀有卡池,但還是普通卡 > 特定幾點抽卡容易中,可能是Seed沒寫好 ## Demo 回去會把Source Code放出來 ## 測試 * 伺服器跟遊戲同 基本上可以自動化測試 * Request測試為主 * 檢查玩家每一個API操作都在預期內 * 測試成功之外要測試失敗的情況 * 用測試去驗證API變動的情況 * Client端也可以作這部分測試 ## 如何部署 機房 vs VPS vs 雲端 ### 機房 * 穩定度無法保證 ex:辦公室停電 * 專業機房花費昂貴 * 維持成本高 * 適合作為團隊內部測試用 (辦公室放一台小機器) * 連線速度較快(都在台灣) * 升級硬體規格容易 ### VPS * 可以用實惠的價格租用 * 穩定度在可接受範圍內 * 需要能夠自行部署伺服器 * 許多功能需要自己建置 > ex:unlight 要收了 有玩家要募資200萬繼續營運,但根據內部人員說一個月大概燒100萬,也只能用2個月 ### VPS比較 Digital Ocean 功能多 CPU相對差 Linode 老牌服務商 基本上只有純VPS ### 雲端 * 實際上非常昂貴 (在有賺錢之前) * 各類服務齊全 * 遇到大型活動比較好對應 * 供應商(AWS)有很多完整解決方案 * 應用得當可以省很多力氣 * 功能太多反而不好學習 ### 雲端 Azure 大部分服務比較貴 GCP 台灣為主的服務,痛點是要習慣Google的玩法,在GCP是沒辦法透過區網連線的,有一些東西違反你的理解 AWS 大部分安定 很多人用但也有實驗性服務要有踩雷的決心 只用EC2算安全 如果某些服務不會傭就不要用 EC2/ELC幾乎都很穩跟好用 如果不會裝環境 可以考慮Heroku or Firebase Firebase幾乎整合到好,但是脫離不好用 NoSQL表面上看起來很好用 但坑很多 因為Unity,遊戲圈都會整合Firebase 沒有key沒辦法搜尋好友 ## 建置環境 * 選Linux OS:CentOS/Amazon Linux * 安裝環境:yum install or 自行編譯 * 設定伺服器:WebServer Worker數量 * 安全設定 防火牆 或用AWS的OpsWork工具直接生成 伺服器用預設值可接受 資料庫建議照機器規格用設定檔產生器提整過 AWS RDS之類的服務也是一種方式 有預算用Aurora 是AWS優化過的版本 防火牆如果有ufw可以直接用(否則萬一設定IP tables不小心把自己擋在門外就再也進不去了) * DigitalOcean可以用後台直接設定 * 被擋住就從後台打開就好 雲端服務就是VPC 缺點是VPC目前版本小複雜 要讀文件 ## 如何拓展 Cache 將不常變動的資料快取 文字腳本 同時寫入資料庫跟快取 讀取時先讀快取 LoadBalance 加機器 DatabaseSharding 透過將使用者切到不同資料庫伺服器減少壓力 使用演算法影響切分的效果 可以用雲端服務稱一陣子 (EX:AWS Aurora 通常需要應用成的實驗 SOA Service-Oriented Architecture 從會員系統開始拆 缺點是會有延遲 手遊比較不用拆 MMOrpg可能就要開 地圖 戰鬥 之類的 大部分是DB瓶頸先出現 後來是Web瓶頸 之後是跨國所以裝CloudFront 有活動爆人數就加AutoScale > MySQL 上限1000 > 錯誤訊息 too many connection ## 公司規定 企劃不能連資料庫 但每個企劃都有DB Client 原廠維運功劇 Insert into 忘記加where 規定不能下sql ## 機器人 來自112的同學不要在\w+送中文好嗎 伺服器500 依舊努力重試,結果CPU從20% > 50% 驗證碼追加之後少了200萬機器人 驗證碼公司擔心他們會被打爆 > 不知道為什麼企劃會被抓去改程式 Github可以找到各種線上遊戲的開源(X) 實作版 可以找到tcp之類的長連線遊戲 Unity不太能做連線遊戲 要自己搞定 ## 總結 考慮團隊狀況 沒有規定不能混合使用,例如AWS當Server 資料送GCP分析 或RoR ActionCable效能不理想 改用Golang AnyCable 沒有最佳解 只有最適合的方案 如果時間是問題 花錢也是一種解法 ###### tags: `COSCUP2018` `ruby`

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully