Skip to content

Commit 45b80ac

Browse files
committed
modify:websocket close and ping message protocol support
1 parent 8f59def commit 45b80ac

File tree

1 file changed

+27
-9
lines changed

1 file changed

+27
-9
lines changed

XEngine_Source/XEngine_APPService/XEngine_AuthorizeService/Authorize_WSTask.cpp

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,19 +52,37 @@ bool XEngine_Client_WSTask(LPCXSTR lpszClientAddr, LPCXSTR lpszMsgBuffer, int nM
5252
XENGINE_PROTOCOLHDR st_ProtocolHdr;
5353
memset(&st_ProtocolHdr, '\0', sizeof(XENGINE_PROTOCOLHDR));
5454

55-
if (!Protocol_Parse_WSHdr(lpszMsgBuffer, nMsgLen, &st_ProtocolHdr))
55+
if (ENUM_XENGINE_RFCOMPONENTS_WEBSOCKET_OPCODE_CLOSE == enOPCode)
5656
{
57-
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _X("WS客户端:%s,协议错误"), lpszClientAddr);
58-
return false;
57+
int nSDLen = 0;
58+
XCHAR tszMSGBuffer[MAX_PATH] = {};
59+
RfcComponents_WSCodec_EncodeMsg(NULL, tszMSGBuffer, &nSDLen, ENUM_XENGINE_RFCOMPONENTS_WEBSOCKET_OPCODE_CLOSE);
60+
NetCore_TCPXCore_SendEx(xhWSSocket, lpszClientAddr, tszMSGBuffer, nSDLen);
5961
}
60-
61-
if (XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_AUTH_REQLOGIN == st_ProtocolHdr.unOperatorCode)
62+
else if (ENUM_XENGINE_RFCOMPONENTS_WEBSOCKET_OPCODE_PING == enOPCode)
63+
{
64+
int nSDLen = 0;
65+
XCHAR tszMSGBuffer[MAX_PATH] = {};
66+
RfcComponents_WSCodec_EncodeMsg(NULL, tszMSGBuffer, &nSDLen, ENUM_XENGINE_RFCOMPONENTS_WEBSOCKET_OPCODE_PONG);
67+
NetCore_TCPXCore_SendEx(xhWSSocket, lpszClientAddr, tszMSGBuffer, nSDLen);
68+
}
69+
else
6270
{
63-
XENGINE_PROTOCOL_USERAUTH st_UserAuth;
64-
memset(&st_UserAuth, '\0', sizeof(XENGINE_PROTOCOL_USERAUTH));
71+
if (!Protocol_Parse_WSHdr(lpszMsgBuffer, nMsgLen, &st_ProtocolHdr))
72+
{
73+
XLOG_PRINT(xhLog, XENGINE_HELPCOMPONENTS_XLOG_IN_LOGLEVEL_ERROR, _X("WS客户端:%s,协议错误"), lpszClientAddr);
74+
return false;
75+
}
76+
77+
if (XENGINE_COMMUNICATION_PROTOCOL_OPERATOR_CODE_AUTH_REQLOGIN == st_ProtocolHdr.unOperatorCode)
78+
{
79+
XENGINE_PROTOCOL_USERAUTH st_UserAuth;
80+
memset(&st_UserAuth, '\0', sizeof(XENGINE_PROTOCOL_USERAUTH));
6581

66-
Protocol_Parse_HttpParseAuth(lpszMsgBuffer, nMsgLen, &st_UserAuth);
67-
XEngine_Client_TCPTask(lpszClientAddr, (LPCXSTR)&st_UserAuth, sizeof(XENGINE_PROTOCOL_USERAUTH), &st_ProtocolHdr, XENGINE_AUTH_APP_NETTYPE_WS);
82+
Protocol_Parse_HttpParseAuth(lpszMsgBuffer, nMsgLen, &st_UserAuth);
83+
XEngine_Client_TCPTask(lpszClientAddr, (LPCXSTR)&st_UserAuth, sizeof(XENGINE_PROTOCOL_USERAUTH), &st_ProtocolHdr, XENGINE_AUTH_APP_NETTYPE_WS);
84+
}
6885
}
86+
6987
return true;
7088
}

0 commit comments

Comments
 (0)