Skip to main content

soup_sdk/chat/
commands.rs

1use crate::chat::constants::message_codes;
2
3// --- 채팅 명령어 타입 ---
4// format_message에서 사용됩니다.
5#[derive(Debug, PartialEq, Eq, Clone, Copy)]
6pub enum MessageType {
7    // 구현
8    Ping,
9    Connect,
10    JOIN,
11    ParticipantListRequest,
12    Unknown,
13}
14
15impl From<u32> for MessageType {
16    fn from(code: u32) -> Self {
17        match code {
18            message_codes::PING => Self::Ping,
19            message_codes::CONNECT => Self::Connect,
20            message_codes::JOIN => Self::JOIN,
21            // 알 수 없는 명령어는 Unknown으로 처리합니다.
22            _ => Self::Unknown,
23        }
24    }
25}
26
27impl MessageType {
28    pub fn to_code(&self) -> u32 {
29        match self {
30            Self::Ping => message_codes::PING,
31            Self::Connect => message_codes::CONNECT,
32            Self::JOIN => message_codes::JOIN,
33            Self::ParticipantListRequest => message_codes::EXIT,
34            Self::Unknown => 0, // 알 수 없는 명령어는 0으로 처리
35        }
36    }
37}
38
39/// 외부에서 백그라운드 연결 루프로 보내는 명령.
40#[derive(Debug)]
41pub enum Command {
42    /// 모든 연결을 종료하고 태스크를 중단하라는 명령.
43    Shutdown,
44    /// 채팅 참여자 명단을 요청합니다.
45    RequestParticipantList,
46}