Skip to content

Commit 23ab1c4

Browse files
committed
feat: 매칭 취소 구현
1 parent 700c53e commit 23ab1c4

13 files changed

Lines changed: 522 additions & 108 deletions

File tree

client/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ add_executable(client
2222
handlers/ping.c
2323
handlers/echo.c
2424
handlers/match.c
25+
handlers/cancel_match.c
2526
handlers/chat.c
2627
handlers/error.c
2728
handlers/disconnect.c

client/client_network.c

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,8 +269,26 @@ void start_matching() {
269269
void cancel_matching() {
270270
LOG_INFO("Cancelling matchmaking");
271271
client_state_t *client = get_client_state();
272+
273+
// 서버에 매칭 취소 요청 전송
274+
if (client->connected) {
275+
LOG_INFO("Sending cancel match request for player: %s", client->username);
276+
ClientMessage cancel_msg = CLIENT_MESSAGE__INIT;
277+
CancelMatchRequest cancel_req = CANCEL_MATCH_REQUEST__INIT;
278+
cancel_req.player_id = client->username;
279+
cancel_msg.msg_case = CLIENT_MESSAGE__MSG_CANCEL_MATCH;
280+
cancel_msg.cancel_match = &cancel_req;
281+
282+
if (send_client_message(client->socket_fd, &cancel_msg) < 0) {
283+
LOG_ERROR("Failed to send cancel match request");
284+
} else {
285+
LOG_INFO("Cancel match request sent successfully");
286+
}
287+
} else {
288+
LOG_WARN("Cannot send cancel match request: not connected to server");
289+
}
290+
272291
client->current_screen = SCREEN_MAIN;
273-
// TODO: 서버에 매칭 취소 요청 전송 (필요시 구현)
274292
}
275293

276294
// 네트워크 정리

client/handlers/cancel_match.c

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#include <pthread.h>
2+
#include <stdio.h>
3+
#include <string.h>
4+
5+
#include "../client_state.h"
6+
#include "handlers.h"
7+
#include "logger.h"
8+
9+
int handle_cancel_match_response(ServerMessage *msg) {
10+
if (msg->msg_case != SERVER_MESSAGE__MSG_CANCEL_MATCH_RES) {
11+
LOG_ERROR("Invalid message type for cancel match response handler");
12+
return -1;
13+
}
14+
15+
if (msg->cancel_match_res) {
16+
if (msg->cancel_match_res->success) {
17+
LOG_INFO("Matching cancelled successfully: %s",
18+
msg->cancel_match_res->message ? msg->cancel_match_res->message : "no message");
19+
20+
add_chat_message_safe("System", "Matching cancelled successfully");
21+
} else {
22+
LOG_WARN("Matching cancellation failed: %s",
23+
msg->cancel_match_res->message ? msg->cancel_match_res->message : "no reason provided");
24+
25+
add_chat_message_safe("System", msg->cancel_match_res->message ? msg->cancel_match_res->message : "Matching cancellation failed");
26+
}
27+
28+
// 어떤 경우든 메인 화면으로 이동 (이미 cancel_matching()에서 처리됨)
29+
// client_state_t *client = get_client_state();
30+
// client->current_screen = SCREEN_MAIN;
31+
} else {
32+
LOG_ERROR("Received cancel match response but no response data");
33+
add_chat_message_safe("System", "Invalid server response");
34+
}
35+
36+
return 0;
37+
}

client/handlers/dispatcher.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ int dispatch_server_message(ServerMessage *msg) {
2323
case SERVER_MESSAGE__MSG_MATCH_GAME_RES:
2424
return handle_match_game_response(msg);
2525

26+
case SERVER_MESSAGE__MSG_CANCEL_MATCH_RES:
27+
return handle_cancel_match_response(msg);
28+
2629
case SERVER_MESSAGE__MSG_CHAT_BROADCAST:
2730
return handle_chat_broadcast(msg);
2831

client/handlers/handlers.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ typedef int (*server_message_handler_t)(ServerMessage *msg);
1010
int handle_ping_response(ServerMessage *msg);
1111
int handle_echo_response(ServerMessage *msg);
1212
int handle_match_game_response(ServerMessage *msg);
13+
int handle_cancel_match_response(ServerMessage *msg);
1314
int handle_chat_broadcast(ServerMessage *msg);
1415
int handle_game_end_broadcast(ServerMessage *msg);
1516
int handle_error_response(ServerMessage *msg);

common/config.h

Lines changed: 1 addition & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,10 @@
11
#ifndef COMMON_CONFIG_H
22
#define COMMON_CONFIG_H
33

4-
#include <stdbool.h>
5-
#include <stdint.h>
6-
74
// ===================================================================
8-
// 공통 설정 관리 시스템
5+
// 공통 설정 상수
96
// ===================================================================
107

11-
// 설정 타입
12-
typedef enum {
13-
CONFIG_TYPE_STRING,
14-
CONFIG_TYPE_INT,
15-
CONFIG_TYPE_BOOL,
16-
CONFIG_TYPE_FLOAT
17-
} config_type_t;
18-
19-
// 설정 항목 구조체
20-
typedef struct {
21-
const char *key; // 설정 키
22-
config_type_t type; // 설정 타입
23-
void *value; // 설정 값 포인터
24-
void *default_value; // 기본값 포인터
25-
const char *description; // 설정 설명
26-
} config_item_t;
27-
288
// 기본 네트워크 설정
299
#define DEFAULT_SERVER_HOST "127.0.0.1"
3010
#define DEFAULT_SERVER_PORT 8080
@@ -36,35 +16,4 @@ typedef struct {
3616
#define DEFAULT_MAX_CHAT_MESSAGES 50
3717
#define DEFAULT_CHAT_MESSAGE_LENGTH 256
3818

39-
// 기본 UI 설정
40-
#define DEFAULT_ANIMATION_ENABLED true
41-
#define DEFAULT_SOUND_ENABLED false
42-
#define DEFAULT_AUTO_SAVE_ENABLED true
43-
44-
// 설정 관리 함수들
45-
int config_init(const char *config_file_path);
46-
void config_cleanup(void);
47-
48-
// 설정 값 읽기
49-
const char *config_get_string(const char *key, const char *default_value);
50-
int config_get_int(const char *key, int default_value);
51-
bool config_get_bool(const char *key, bool default_value);
52-
float config_get_float(const char *key, float default_value);
53-
54-
// 설정 값 쓰기
55-
int config_set_string(const char *key, const char *value);
56-
int config_set_int(const char *key, int value);
57-
int config_set_bool(const char *key, bool value);
58-
int config_set_float(const char *key, float value);
59-
60-
// 설정 파일 저장/로드
61-
int config_save(void);
62-
int config_load(void);
63-
64-
// 설정 초기화 (기본값으로 복원)
65-
void config_reset_to_defaults(void);
66-
67-
// 설정 목록 출력 (디버그용)
68-
void config_print_all(void);
69-
7019
#endif // COMMON_CONFIG_H

0 commit comments

Comments
 (0)