comparison seobeo/s_websocket_server.c @ 125:f236c895604e

[MrJuneJune] Added web socket for chat to this.
author June Park <parkjune1995@gmail.com>
date Thu, 08 Jan 2026 08:46:49 -0800
parents 7b1719fa918c
children 893d87124d16
comparison
equal deleted inserted replaced
124:dbf14f84d51c 125:f236c895604e
118 Seobeo_WebSocket_Server_Handle_Connection(p_conn); 118 Seobeo_WebSocket_Server_Handle_Connection(p_conn);
119 119
120 return TRUE; 120 return TRUE;
121 } 121 }
122 122
123 static void Seobeo_WebSocket_Unmask_Data(uint8 *data, size_t length, const uint8 *mask) 123 // Seobeo_WebSocket_Unmask_Data removed - using Seobeo_WebSocket_Mask_Data from s_websocket_common.c (XOR is symmetric)
124 {
125 for (size_t i = 0; i < length; i++)
126 data[i] ^= mask[i % 4];
127 }
128 124
129 static int32 Seobeo_WebSocket_Server_Send_Frame(Seobeo_WebSocket_Server_Connection *p_conn, Seobeo_WebSocket_Opcode opcode, const uint8 *payload, size_t payload_length, boolean fin) 125 static int32 Seobeo_WebSocket_Server_Send_Frame(Seobeo_WebSocket_Server_Connection *p_conn, Seobeo_WebSocket_Opcode opcode, const uint8 *payload, size_t payload_length, boolean fin)
130 { 126 {
131 if (!p_conn || !p_conn->is_active) 127 if (!p_conn || !p_conn->is_active)
132 return -1; 128 return -1;
283 { 279 {
284 payload = malloc(payload_len); 280 payload = malloc(payload_len);
285 memcpy(payload, buf + header_len, payload_len); 281 memcpy(payload, buf + header_len, payload_len);
286 282
287 if (masked) 283 if (masked)
288 Seobeo_WebSocket_Unmask_Data(payload, payload_len, mask_key); 284 Seobeo_WebSocket_Mask_Data(payload, payload_len, mask_key);
289 } 285 }
290 286
291 Seobeo_Handle_Consume(p_conn->p_handle, (uint32)(header_len + payload_len)); 287 Seobeo_Handle_Consume(p_conn->p_handle, (uint32)(header_len + payload_len));
292 288
293 if (opcode == SEOBEO_WS_OPCODE_PING) 289 if (opcode == SEOBEO_WS_OPCODE_PING)
412 } 408 }
413 409
414 Seobeo_WebSocket_Server_Connection_Destroy(p_conn); 410 Seobeo_WebSocket_Server_Connection_Destroy(p_conn);
415 } 411 }
416 412
417 void Seobeo_WebSocket_Server_Broadcast_Text(const char *text) 413 void Seobeo_WebSocket_Server_Broadcast_Text(const char *text, Seobeo_WebSocket_Server_Connection *origin_p_conn)
418 { 414 {
419 if (!text) 415 if (!text)
420 return; 416 return;
421 417
422 Seobeo_WebSocket_Server_Connection *p_conn = g_ws_connections; 418 Seobeo_WebSocket_Server_Connection *p_conn = g_ws_connections;
423 while (p_conn) 419 while (p_conn)
424 { 420 {
425 if (p_conn->is_active) 421 if (p_conn->is_active && p_conn != origin_p_conn)
426 Seobeo_WebSocket_Server_Send_Text(p_conn, text); 422 Seobeo_WebSocket_Server_Send_Text(p_conn, text);
427 423
428 p_conn = p_conn->next; 424 p_conn = p_conn->next;
429 } 425 }
430 } 426 }