# HW2-雙人連機遊戲 Part 2 (two-player online game part 2)
## Timeline
Demo Deadline 2024/11/11(一) or 2024/11/14(四) 視教學進度而定
## Introduction
這次作業的目標是改變HW1玩家之間的連線方式,從原本兩名玩家透過 TCP/UDP 直接進行點對點連線,改為透過中央的 lobby server 溝通協調後,再以點對點方式開始遊戲。學生需要完成並Demo兩個程式:lobby server 和 client。client 端必須具備註冊、登入及登出的功能,並且使用者須透過一組 username 和 password 進行操作。當 client 登入後,lobby server 需要顯示當前線上玩家的狀況,並允許玩家建立遊戲房間或加入其他玩家的房間,進而開始遊戲。
The goal of this assignment is to modify the connection method between players from HW1. Instead of having two players connect directly via TCP/UDP in a peer-to-peer manner, the connection should now be coordinated through a central lobby server before the game starts in a peer-to-peer mode. Students are required to complete and demonstrate two programs: a lobby server and a client. The client must support functions for registration, login, and logout, and users should operate using a username and password. After a client logs in, the lobby server should display the current status of online players and allow players to create game rooms or join other players' rooms to start the game.
## A.運行大廳server (Run the lobby server)
#### 主要行為者
- **伺服器管理員 (Server Administrator)**
#### 系統 (System)
- **遊戲大廳伺服器 (Lobby Server)**
#### 先決條件
- 登入系計中Linux server。
#### 觸發事件
- 啟動遊戲大廳伺服器。
#### 主成功情境 (Main Success Scenario)
1. 執行遊戲大廳伺服器程式,並指定必要的參數(如port號等)。
Run the game lobby server program and specify the necessary parameters (such as the port number, etc.).
2. 系統成功啟動遊戲大廳伺服器,並顯示伺服器運行狀態的訊息。
The system successfully started the game lobby server and displayed a message showing the server's running status.
3. 伺服器準備好接收來自玩家的連接請求。
The server is ready to receive connection requests from players.
#### 擴展情境 (Extension)
1a. **啟動失敗 (primary actor)**:
1. 如果伺服器程式無法啟動(例如因為port已被佔用或錯誤的配置),則顯示錯誤訊息。
If the server program fails to start (for example, due to the port being occupied or incorrect configuration), an error message is displayed.
2. 伺服器管理員需要檢查錯誤訊息,進行必要的故障排除後重新嘗試啟動。
The server administrator needs to check the error message, perform the necessary troubleshooting, and then retry starting the server.
#### 後置條件 (postconditions)
- 大廳伺服器成功運行後,所有玩家可以開始連接到該伺服器,並進行遊戲相關操作。
After the lobby server is successfully running, all players can start connecting to the server and perform game-related operations.
## B.註冊 (Register)
#### 主要行為者 (primary actor)
- **玩家 (Client)**
#### 系統 (system)
- **遊戲大廳伺服器 (Lobby Server)**
#### 先決條件 (preconditions)
- 遊戲大廳伺服器正在運行,允許新玩家註冊。
The game lobby server is running, allowing new players to register.
#### 觸發事件 (trigger event)
- 玩家選擇註冊新帳號。
The player chooses to register a new account.
#### 主成功情境 (Main Success Scenario)
1. 玩家開啟遊戲客戶端並選擇註冊。
The player opens the game client and selects to register.
2. 玩家輸入玩家名稱和一組密碼。
The player enters a username and a password.
3. 遊戲大廳伺服器驗證玩家名稱是否已經存在。
The game lobby server verifies whether the username already exists.
4. 如果玩家名稱不存在,遊戲大廳伺服器將玩家名稱和密碼儲存。
If the username does not exist, the game lobby server will store the username and password.
5. 玩家成功註冊,並收到確認訊息。
The player successfully registers and receives a confirmation message.
#### 擴展情境 (Extensions)
1a. **玩家名稱重複 (The username is already taken)**:
1. 遊戲大廳伺服器發現玩家名稱已經被註冊。
The game lobby server finds that the username has already been registered.
2. 伺服器回應 "使用者名稱已存在" 錯誤訊息。
The server responds with an error message: "Username already exists."
3. 玩家收到錯誤提示,要求輸入另一個名稱進行註冊。
The player receives an error prompt, requesting them to enter another username for registration.
#### 例外狀況 (Exception)
- 遊戲大廳伺服器關閉 (The game lobby server is shutting down):
- 伺服器關閉後不需要保存玩家註冊資料,所有資料不會寫入檔案,也不會持久化。
After the server shuts down, there is no need to save player registration data; all information will not be written to files and will not be persisted.
#### 後置條件 (postconditions)
- 玩家成功註冊後,執行登入操作。
After the player successfully registers, they proceed to the login operation.
## C.登入 (Login)
#### 主要行為者 (primary actor)
- **玩家 (Client)**
#### 系統 (System)
- **遊戲大廳伺服器 (Lobby Server)**
#### 先決條件 (precondition)
1. 遊戲大廳伺服器必須處於運行狀態,並且玩家之前已經註冊。
The game lobby server must be running, and the player must have registered previously.
#### 觸發事件 (trigger event)
- 玩家選擇登入遊戲大廳。
The player chooses to log into the game lobby.
#### 主成功情境 (Main Success Scenario)
1. 玩家開啟遊戲客戶端並選擇登入。
The player opens the game client and selects to log in.
2. 玩家輸入使用者名稱。
The player enters the username.
3. 遊戲大廳伺服器驗證使用者名稱是否存在。
The game lobby server verifies whether the username exists.
4. 如果使用者名稱存在,遊戲大廳伺服器提示玩家輸入密碼
If the username exists, the game lobby server prompts the player to enter their password.
5. 遊戲大廳伺服器驗證密碼正確性。
The game lobby server verifies the correctness of the password.
6. 驗證通過後,玩家成功登入遊戲大廳。
After the verification is successful, the player logs into the game lobby.
8. 玩家能夠看到當前所有的遊戲房間和其他在線玩家。
The player is able to see all current game rooms and other online players.
#### 擴展情境 (Extensions)
1a. **玩家未註冊 (The player is not registered)**:
1. 遊戲大廳伺服器發現該玩家並未註冊,回應 "使用者不存在" 錯誤訊息。
The game lobby server discovers that the player is not registered and responds with the error message: "User does not exist."
2. 玩家收到錯誤提示,無法登入,並提示進行註冊。
The player receives an error prompt, unable to log in, and is advised to register.
2a. **密碼錯誤 (Incorrect password)**:
1. 玩家輸入的密碼錯誤。
The password entered by the player is incorrect.
2. 遊戲大廳伺服器回應 "密碼錯誤" 錯誤訊息。
The game lobby server responds with the error message: "Incorrect password."
3. 玩家收到錯誤提示,重新嘗試登入。
The player receives an error prompt and tries to log in again.
#### 例外狀況 (Exception)
- 遊戲大廳伺服器崩潰或無法連線 (The game lobby server crashes or cannot connect):
- 玩家無法登入,顯示連線錯誤訊息。
The player is unable to log in, and a connection error message is displayed.
#### 後置條件 (poscondition)
- 玩家成功登入後,玩家狀態表示為「閒置中」,且能夠看到線上狀況
After successfully logging in, the player's status is shown as "idle," and they can view the online status of other players
## D.登出 (Logout)
- **玩家 (client)**
#### 系統 (System)
- **遊戲大廳伺服器 (Lobby Server)**
#### 先決條件 (precondition)
- 玩家已經登入遊戲大廳並在線上。
The player has logged into the game lobby and is online.
#### 觸發事件 (trigger event)
- 玩家選擇從遊戲大廳登出。
The player chooses to log out from the game lobby.
#### 主成功情境 (Main Success Scenario)
1. 玩家在遊戲大廳中選擇「登出」選項。
The player selects the "Log Out" option in the game lobby.
2. 系統接收到登出請求。
The system receives the logout request.
3. 遊戲大廳伺服器處理登出請求 (The game lobby server processes the logout request):
- 移除該玩家的狀態,並從線上玩家列表中刪除。
The player's status is removed, and they are deleted from the online players list.
4. 系統確認登出成功,並向玩家顯示登出訊息。
The system confirms a successful logout and displays a logout message to the player.
5. 玩家成功登出,返回到登入/註冊界面。
The player successfully logs out and returns to the login/register screen.
#### 擴展情境 (Extensions)
1a. **登出失敗 (Logout failed)**:
1. 如果伺服器在處理登出請求時遇到錯誤(例如伺服器崩潰或網絡問題),則顯示錯誤訊息。
If the server encounters an error while processing the logout request (such as a server crash or network issues), an error message is displayed.
2. 玩家可以選擇重試登出。
The player can choose to retry logging out.
#### 例外狀況 (Exception)
- **伺服器錯誤 (Server error)**:
- 若遊戲大廳伺服器無法成功登出玩家,將顯示錯誤訊息。
If the game lobby server cannot successfully log out the player, an error message will be displayed.
#### 後置條件 (Postcondition)
- 玩家登出後,將不再顯示在線上玩家列表中,並無法執行任何遊戲操作,直到重新登入。
After logging out, the player will no longer be displayed in the online players list and will not be able to perform any game actions until they log in again.
## E.顯示線上情形 (Display online status)
#### 主要行為者 (primary actor)
- **玩家 (Client)**
#### 系統 (System)
- **遊戲大廳伺服器 (Lobby Server)**
#### 先決條件 (precondition)
- 玩家已經登入遊戲大廳伺服器。
The player has logged into the game lobby server.
#### 觸發事件 (trigger event)
- 玩家登入後自動觸發。
The player has logged into the game lobby server.
#### 主成功情境 (Main Success Scenario)
1. 玩家進入遊戲大廳,伺服器自動顯示以下資訊 (The player enters the game lobby, and the server automatically displays the following information):
- 當前線上的所有玩家名稱以及狀態(例如:遊戲中、閒置中)。
The names and statuses of all currently online players (e.g., playing, idle).
- 所有公開遊戲的房間(包含創建者、遊戲類型、房間狀態)。
All public game rooms (including the creator, game type, and room status).
2. 當有玩家登出時,遊戲大廳會從列表中移除該玩家。
When a player logs out, the game lobby will remove that player from the list.
#### 擴展情境 (Extensions)
1a. **無玩家在線 (No players online)**:
1. 如果遊戲大廳中沒有玩家在線,顯示 "目前無玩家在線" 訊息。
If there are no players online in the game lobby, display the message "Currently, no players are online."
2a. **無公開遊戲房間 (No public game rooms available)**:
1. 如果沒有任何公開遊戲房間正在等待對手,顯示 "無公開房間等待玩家" 訊息。
If there are no public game rooms waiting for players, display the message "No public rooms waiting for players."
#### 例外狀況 (Exception)
- 伺服器無法更新線上玩家狀態 (The server is unable to update the online player status):
- 如果遊戲大廳伺服器發生錯誤或無法連線,玩家無法看到正確的線上玩家列表和公開房間資訊。
If the game lobby server encounters an error or cannot connect, players will not be able to see the correct online player list and public room information.
#### 後置條件 (poscondition)
- 玩家可以根據顯示的公開房間和線上玩家列表,等待其他玩家邀請或選擇要執行的以下操作 (Players can wait for invitations from other players or choose to perform the following actions based on the displayed public rooms and online player list):
1. 在 lobby server 上建立遊戲房間
Create a game room on the lobby server.
3. 加入public room
Join a public room.
4. 登出
Logout
## F.建立遊戲房間並 邀請其他玩家加入 / 等待其他人主動加入 (Create a game room and invite other players to join / wait for others to join proactively.)
#### 主要行為者 (primary actor)
- **房間創建者 (Room Host)**
- **閒置中的玩家 (Idle Peer)**
#### 系統 (system)
- **遊戲大廳伺服器 (Lobby Server)**
- **遊戲伺服器 (Game Server)**
#### 先決條件 (precondition)
- 房間創建者已經登入遊戲大廳,並處於「閒置」狀態。
The room creator is logged into the game lobby and is in an "idle" state.
#### 觸發事件 (trigger event)
- 房間創建者選擇在遊戲大廳中創建遊戲房間。
The room creator chooses to create a game room in the game lobby.
#### 主成功情境 (Main Success Scenario)
1. **房間創建者**在遊戲大廳中選擇「創建房間」功能。
The **room creator** selects the "Create Room" feature in the game lobby.
2. **房間創建者**選擇遊戲類型,至少要有<span style="color:red;">2種以上</span>的遊戲可以選擇。
The **room creator** selects a game type, with at least <span style="color:red;">two or more</span> games available for selection.
3. **房間創建者**選擇房間類型 (The **room creator** selects the room type):
- **Public Room (公開房間)**:允許任何玩家查看並加入。
**Public Room**: Allows any player to view and join.
- **Private Room (私人房間)**:僅能邀請處於「閒置」狀態的玩家加入。
**Private Room**: Only players who are in an "idle" state can be invited to join.
4. **Public Room情境** (**Public Room Scenario**):
1. **房間創建者**創建公開房間後,**遊戲大廳伺服器**將該房間顯示在公開房間列表中,所有大廳中的玩家可以看到並選擇加入。
After the **room creator** creates a public room, the **game lobby server** displays that room in the public room list, allowing all players in the lobby to see it and choose to join.
2. 在沒有玩家加入前,**遊戲大廳伺服器**將房間狀態設為「等待中」。
Before any players join, the **game lobby server** sets the room status to "Waiting."
3. 當有玩家加入房間後,**遊戲大廳伺服器**將房間狀態更新為「遊戲中」,並將房間中的玩家狀態從公開列表中更新為「遊戲中」。
When a player joins the room, the **game lobby server** updates the room status to "In Game" and changes the status of players in the room from the public list to "In Game."
4. **Private Room情境** (**Private Room Scenario**):
1. **房間創建者**創建私人房間後,通過**遊戲大廳伺服器**選擇性邀請其他「閒置」狀態的玩家加入房間。
After the **room creator** creates a private room, they selectively invite other players who are in an "idle" state to join the room through the **game lobby server**.
2. **閒置中的玩家**收到邀請後可以選擇接受或拒絕。
**Idle players** who receive the invitation can choose to accept or decline it.
3. 當**閒置中的玩家**接受邀請並加入房間後,**遊戲大廳伺服器**將玩家的狀態更新為「遊戲中」。
When an **idle player** accepts the invitation and joins the room, the **game lobby server** updates the player's status to "In Game."
5. **房間狀態更新** (**Room Status Update**):
1. **遊戲大廳伺服器**將房間創建者的狀態設為「房間中」直到有其他玩家加入。
The **game lobby server** sets the room creator's status to "In Room" until other players join.
2. 當遊戲開始後,**遊戲大廳伺服器**將房間狀態從「等待中」更新為「遊戲中」,房間不再接受新玩家。
Once the game starts, the **game lobby server** updates the room status from "Waiting" to "In Game," and the room will no longer accept new players.
3. **房間創建者**與加入的玩家狀態都更新為「遊戲中」。
The status of both the **room creator** and the joined players is updated to "In Game."
#### 擴展情境 (Extensions)
1a. **房間創建失敗** (**Room creation failed**):
1. 若創建遊戲房間失敗,**遊戲大廳伺服器**會通知創建者錯誤訊息,並讓其重新嘗試。
If the game room creation fails, the **game lobby server** will notify the creator with an error message and allow them to retry.
2a. **玩家拒絕私人房間邀請** (**Player declines the private room invitation**):
1. 若**閒置中的玩家**拒絕邀請,**遊戲大廳伺服器**通知**房間創建者**邀請被拒絕,並允許創建者邀請其他玩家。
If an **idle player** declines the invitation, the **game lobby server** notifies the **room creator** that the invitation was declined and allows the creator to invite other players.
#### 例外狀況 (Exception)
- **伺服器錯誤** (**Server error**):
- 若**遊戲大廳伺服器**無法成功處理房間創建、邀請或狀態更新,則會通知玩家發生錯誤並請其重新嘗試。
If the **game lobby server** is unable to successfully process room creation, invitations, or status updates, it will notify the player that an error has occurred and ask them to retry.
#### 後置條件 (poscondition)
- **房間創建者**成功建立房間,並等待其他玩家加入。
The **room creator** successfully establishes the room and waits for other players to join.
- **公開房間**顯示在大廳的公開房間列表中,並在滿員前表示為「等待中」。
The **public room** is displayed in the lobby's public room list and is marked as "Waiting" until it is full.
- **私人房間**邀請的玩家加入後,狀態更新為「遊戲中」並開始遊戲,房間不再接受新玩家。
After the invited players join the **private room**, their status is updated to "In Game," and the game starts; the room will no longer accept new players.
- 遊戲開始後,房間和玩家的狀態更新為「遊戲中」。
After the game starts, the room and players' statuses are updated to "In Game."
## G.等待其他玩家邀請 (Waiting for invitations from other players)
#### 主要行為者 (primary actor)
- **閒置中的玩家 (Idle Peer)**
- **私人房間創建者 (Private Room Host)**
#### 系統 (system)
- **遊戲大廳伺服器 (Lobby Server)**
- **遊戲伺服器 (Game Server)**
#### 先決條件 (precondition)
- 閒置中的玩家已經登入遊戲大廳,並且狀態為「閒置」。
The idle player has logged into the game lobby and their status is "Idle."
- 房間創建者已創建了一個私人房間。
The room creator has created a private room.
#### 觸發事件 (trigger event)
- 有玩家處於「閒置」的狀態。
There are players in an "idle" state.
- 房間創建者向閒置中的玩家發出邀請。
The room creator sends an invitation to the idle players.
#### 主成功情境 (Main Success Scenario)
1. **房間創建者**向**「閒置」的玩家**發出邀請,並將邀請訊息發送至遊戲大廳伺服器。
The **room creator** sends an invitation to the **idle players** and transmits the invitation message to the game lobby server.
2. **遊戲大廳伺服器**將邀請訊息傳送給**閒置中的玩家**,詢問是否接受邀請。
The **game lobby server** sends the invitation message to the **idle players**, asking if they accept the invitation.
3. **閒置中的玩家**選擇接受邀請。
The **idle player** chooses to accept the invitation.
4. **遊戲大廳伺服器**通知**房間創建者**邀請已被接受。
The **game lobby server** notifies the **room creator** that the invitation has been accepted.
5. **遊戲大廳伺服器**向**房間創建者**請求該房間的遊戲伺服器IP和port號。
The **game lobby server** requests the game server's IP and port number for the room from the **room creator**.
6. **房間創建者**開啟遊戲伺服器,並將IP和port號傳送給遊戲大廳伺服器。
The **room creator** starts the game server and sends the IP and port number to the game lobby server.
7. **遊戲大廳伺服器**將房間創建者的遊戲伺服器IP和port號發送給接受邀請的**閒置中的玩家**。
The **game lobby server** sends the room creator's game server IP and port number to the accepting **idle player**.
8. **閒置中的玩家**使用收到的IP和port號連接遊戲伺服器並成功加入遊戲。
The **idle player** uses the received IP and port number to connect to the game server and successfully joins the game.
9. **遊戲大廳伺服器**將房間內所有玩家的狀態更新為「遊戲中」。
The **game lobby server** updates the status of all players in the room to "In Game."
10. 遊戲開始。
Game start
#### 擴展情境 (Extensions)
1a. **閒置中的玩家拒絕邀請** (The **idle player** declines the invitation):
1. **閒置中的玩家**選擇拒絕邀請,遊戲大廳伺服器通知**房間創建者**邀請被拒絕。
The **idle player** chooses to decline the invitation, and the game lobby server notifies the **room creator** that the invitation has been declined.
2. **閒置中的玩家**仍保持在大廳中的「閒置」狀態,並可以進行其他操作。
The **idle player** remains in the "Idle" state in the lobby and can perform other actions.
2a. **遊戲伺服器啟動失敗** (**Game server startup failed**):
1. 如果**房間創建者**無法啟動遊戲伺服器,遊戲大廳伺服器通知**閒置中的玩家**加入失敗,並讓他們重新選擇操作。
If the **room creator** is unable to start the game server, the game lobby server informs the **idle players** that the join attempt has failed and prompts them to select another action.
#### 例外狀況 (Exception)
- **伺服器錯誤** (**Server error**):
- 如果遊戲大廳伺服器無法請求或傳遞遊戲伺服器的IP和port號,則通知玩家出現錯誤,並允許玩家重新嘗試或進行其他操作。
If the game lobby server fails to request or transmit the game server's IP and port number, it notifies the players of an error and allows them to retry or perform other actions.
#### 後置條件 (poscondition)
- **閒置中的玩家**成功連接到遊戲伺服器,並開始遊戲。
The **idle player** successfully connects to the game server and starts the game.
- **遊戲大廳伺服器**將房間內玩家狀態更新為「遊戲中」。
The **game lobby server** updates the status of players in the room to "In Game."
- 若玩家拒絕邀請,則狀態保持為「閒置」並可繼續進行其他操作。
If the player declines the invitation, their status remains "Idle," and they can continue to perform other actions.
## H.加入公開遊戲房間 (Join a public game room)
#### 主要行為者 (primary actor)
- **閒置中的玩家 (Idle Peer)**
- **公開房間創建者 (Public Room Host)**
#### 系統 (system)
- **遊戲大廳伺服器 (Lobby Server)**
- **遊戲伺服器 (Game Server)**
#### 先決條件 (precondition)
- 玩家已經登入遊戲大廳,並且狀態為「閒置」。
The player has logged into the game lobby and their status is "Idle."
- 大廳中有公開的遊戲房間可供加入。
There are public game rooms available to join in the lobby.
#### 觸發事件 (trigger event)
- 閒置中的玩家選擇加入一個公開遊戲房間功能。
The idle player chooses to join a public game room.
#### 主成功情境 (Main Success Scenario)
1. **閒置中的玩家**在遊戲大廳中選擇一個公開遊戲房間加入。
The **idle player** selects a public game room to join in the game lobby.
2. **遊戲大廳伺服器**收到玩家的加入請求,並向房間創建者(房主)請求該房間的遊戲伺服器IP和port號。
The **game lobby server** receives the player's join request and requests the game server's IP and port number for the room from the room creator (host).
3. **房間創建者**開啟遊戲伺服器,並將IP和port號傳送給遊戲大廳伺服器。
The **room creator** starts the game server and sends the IP and port number to the game lobby server.
4. **遊戲大廳伺服器**將房間創建者的遊戲伺服器IP和port號發送給加入的玩家。
The **game lobby server** sends the room creator's game server IP and port number to the joining player.
5. **閒置中的玩家**使用接收到的IP和port號,連接到房間創建者的遊戲伺服器並成功加入遊戲。
The **idle player** uses the received IP and port number to connect to the room creator's game server and successfully joins the game.
6. **遊戲大廳伺服器**將房間狀態從「等待中」更新為「遊戲中」,並將房間內所有玩家的狀態更新為「遊戲中」。
The **game lobby server** updates the room status from "Waiting" to "In Game" and changes the status of all players in the room to "In Game."
7. 遊戲開始。
Game start
#### 擴展情境 (Extensions)
1a. **房間滿員** (**Room is full**):
1. 如果房間已經滿員,遊戲大廳伺服器通知玩家無法加入該房間,並返回公開房間列表供玩家重新選擇。
If the room is already full, the game lobby server notifies the player that they cannot join the room and returns them to the public room list for them to make another selection.
2a. **遊戲伺服器啟動失敗** (**Game server startup failed**):
1. 如果房間創建者無法啟動遊戲伺服器,遊戲大廳伺服器通知玩家加入失敗,並請玩家選擇其他公開房間。
If the room creator is unable to start the game server, the game lobby server notifies the player of the failed joining attempt and prompts them to choose another public room.
#### 例外狀況 (Exception)
- **伺服器錯誤** (**server error**):
- 如果遊戲大廳伺服器無法請求或傳遞遊戲伺服器的IP和port,將通知玩家出現錯誤,並請他們重新嘗試加入房間。
If the game lobby server is unable to request or relay the game server's IP and port, it will notify the player of an error and prompt them to retry joining the room.
#### 後置條件 (poscondition)
- 玩家成功連接到遊戲伺服器,遊戲開始,並且房間狀態更新為「遊戲中」。
The player successfully connects to the game server, the game starts, and the room status is updated to "In Game."
- 在公開列表中,玩家狀態更新為「遊戲中」。
In the public list, the player's status is updated to "In Game."
## I.進行遊戲 (play game)
#### 主要行為者 (primary actor)
- **房間創建者 (Room Host)**
- **房間加入者 (Room Participant)**
#### 系統 (system)
- **遊戲大廳伺服器 (Lobby Server)**
- **遊戲伺服器 (Game Server)**
#### 先決條件 (precondition)
- **房間創建者**已經成功創建房間。
The **room creator** has successfully created the room.
- **房間加入者**已加入房間。
The **room joiner** has successfully joined the room.
#### 觸發事件 (trigger event)
- 房間內滿兩人後,根據創建房間時選擇的遊戲自動開始。
Once the room is filled with two players, the game will automatically start based on the game selected when the room was created.
#### 主成功情境 (Main Success Scenario)
1. **房間創建者**作為**遊戲伺服器**,開啟遊戲伺服器。
The **room creator**, acting as the **game server**, has started the game server.
2. **房間加入者**通過**遊戲大廳伺服器**取得**房間創建者**的IP與Port,並連接到遊戲伺服器。
The **room joiner** obtains the **IP** and **port** of the **room creator** through the **game lobby server** and successfully connects to the game server.
3. **房間創建者**與**房間加入者**進行遊戲。
The **room creator** and **room joiner** begin the game, with both players actively participating in the gameplay. The game server manages their interactions and game state.
4. 當遊戲結束後 (After the game ends):
1. **遊戲伺服器**或**房間創建者**通知**遊戲大廳伺服器**遊戲已結束。
"The game server or room creator notifies the game lobby server that the game has ended."
2. **遊戲大廳伺服器**自動解散遊戲房間,並將兩位玩家的狀態更新為「閒置」。
"The game lobby server automatically dissolves the game room and updates the status of both players to 'idle'."
3. 房間從公開房間列表中移除,兩位玩家可以繼續進行其他操作。
"The room is removed from the public room list, and both players can continue with other actions."
#### 擴展情境 (Extensions)
1a. **遊戲無法開始** (**The game cannot start**):
1. 若遊戲伺服器無法啟動或發生錯誤,**遊戲大廳伺服器**將通知玩家錯誤,並允許重試或解散房間。
If the game server fails to start or encounters an error, the **lobby server** will notify the players of the error and allow them to either retry or dissolve the room.
2. 若遊戲伺服器port已被綁定,**遊戲伺服器**應要能重新選擇可以綁定的port。(自動更換或通知**房間創建者**重新輸入等)
If the game server port is already bound, the **game server** should be able to reselect a bindable port (either automatically change to an available port or notify the **room creator** to re-enter a port, etc.).
2a. **房間加入者無法連接遊戲伺服器** (**The room joiner cannot connect to the game server**):
1. 若**房間加入者**無法成功連接遊戲伺服器,將收到連接錯誤訊息,並可以選擇重新連接或退出房間。
If the **room joiner** is unable to successfully connect to the game server, they will receive a connection error message and can choose to reconnect or exit the room.
#### 例外狀況 (exception)
- **伺服器錯誤** (**server error**):
- 若**遊戲伺服器**或**遊戲大廳伺服器**在遊戲過程中發生錯誤,遊戲將被中止,並通知兩位玩家重新進行其他操作。
If an error occurs in the **game server** or **lobby server** during the game, the game will be terminated, and both players will be notified to perform other operations.
#### 後置條件 (postcondition)
- **遊戲房間**自動解散,兩位玩家的狀態更新為「閒置」。
The **game room** will automatically dissolve, and both players' statuses will be updated to "idle."
- 兩位玩家可以在遊戲大廳中執行其他操作(如創建新房間、加入公開房間等)。
Both players can perform other actions in the game lobby, such as creating a new room or joining a public room.
## 流程示意圖 (Sequence Diagram)

## 注意事項
1. 圖片僅供同學更了解流程用,實作細節請以文字描述為主。
The images are provided for students to better understand the process; please focus on textual descriptions for implementation details.
2. 不限制實作語言。
There are no restrictions on the implementation language
3. 所有實作請使用TCP協定。
All implementations must use the TCP protocol
4. 所有使用到的port請設在10000以上。
All ports used must be set above 10,000.
5. Demo時會請同學把兩支程式放到系計中Server上跑,建議開發時用系計中server測試為主。
During the demo, students will be asked to run both programs on the server in the system. It is recommended to primarily test on the server in the system during development.
6. 請避免使用系計中server沒有的library,以免不能正常執行。
Please avoid using libraries that are not available on the server in the system to ensure proper execution
7. 遊戲請設計2個以上,類型不限。
Please design at least two games, of any type
8. Public room一定要顯示在公開列表中,Private room則可顯示可不顯示。
Public rooms must be displayed in the public list, while private rooms can choose whether or not to display
9. 所有client端之間的溝通,在遊戲開始前都應該透過lobby server進行。
All communication between clients before the game starts should go through the lobby server
10. 遊戲開始後是peer to peer的連線,遊戲判斷不需要透過lobby server。
After the game starts, the connection is peer-to-peer, and game validation does not need to go through the lobby server
11. 若沒有達成要求,會斟酌扣分,若在本作業不是以lobby server溝通的方式,你可能拿到零分。
If the requirements are not met, points may be deducted. Specifically, if this assignment does not utilize lobby server communication, you may receive a score of zero.
12. 若對題目有任何疑問,或是遇到實作上問題,歡迎同學在上機課的時候詢問助教,或是透過E3寄信發問,請盡量不要直接寄信,避免助教漏掉。
If you have any questions about the assignment or encounter any implementation issues, feel free to ask the TA during lab sessions or send an inquiry via E3. Please try to avoid sending emails directly to prevent the TA from missing your message.
13. Demo deadline前可以重複Demo直到你分數滿意為止。
You can repeat the demo until you are satisfied with your score before the demo deadline.
## 評分標準 (Grading Criteria)
1. 完整實作玩家遊戲大廳註冊的功能 (10%)
Complete implementation of the player registration function in the game lobby (10%)
2. 完整實作玩家遊戲大廳登入的功能 (10%)
Complete implementation of the player login function in the game lobby (10%)
3. 完整實作登出功能 (10%)
Complete implementation of the logout function (10%)
4. 完整實作大廳List功能 (10%)
Complete implementation of the lobby list function (10%)
5. 完整實作創建房間功能 (10%)
Complete implementation of the room creation function (10%)
6. 完整實作等待其他玩家邀請功能 (10%)
Complete implementation of the functionality to wait for invitations from other players (10%)
7. 完整實作加入遊戲房間功能 (10%)
Complete implementation of the function to join game rooms (10%)
8. 完整實作進行遊戲功能 (10%)
Complete implementation of the function to play the game (10%)
9. 遊戲趣味性(遊戲複雜度、遊戲特殊性) (10%)
Game enjoyment (game complexity, uniqueness of the game) (10%)
10. 防爆 (10%)
Anti-cheat measures (10%)