|
47 | 47 |
|
48 | 48 | #include "serverrpc.h" |
49 | 49 |
|
| 50 | +/* Definitions ****************************************************************/ |
| 51 | +#define INVALID_CLIENT_ID -1 |
| 52 | + |
50 | 53 | CServerRpc::CServerRpc ( CServer* pServer, CRpcServer* pRpcServer, QObject* parent ) : QObject ( parent ) |
51 | 54 | { |
52 | 55 | // API doc already part of CClientRpc |
@@ -299,15 +302,17 @@ CServerRpc::CServerRpc ( CServer* pServer, CRpcServer* pRpcServer, QObject* pare |
299 | 302 | /// @param {number} params.id - The client's channel id. |
300 | 303 | /// @result {string} result - Always "ok". |
301 | 304 | pRpcServer->HandleMethod ( "jamulusserver/privateChatMessage", [=] ( const QJsonObject& params, QJsonObject& response ) { |
302 | | - auto jsonChatMessage = params["chatMessage"]; |
303 | | - const int id = params["id"].toInt(); |
304 | | - if ( !jsonChatMessage.isString() ) |
| 305 | + auto jsonChatMessage = params["chatMessage"]; |
| 306 | + const int id = params["id"].toInt ( INVALID_CLIENT_ID ); |
| 307 | + const QString chatMessage = jsonChatMessage.toString(); |
| 308 | + if ( chatMessage.isEmpty() || chatMessage.size() > MAX_LEN_CHAT_TEXT ) |
305 | 309 | { |
306 | | - response["error"] = CRpcServer::CreateJsonRpcError ( CRpcServer::iErrInvalidParams, "Invalid params: chatMessage is not a string" ); |
| 310 | + response["error"] = |
| 311 | + CRpcServer::CreateJsonRpcError ( CRpcServer::iErrInvalidParams, "Invalid params: chatMessage is not a string or malformed" ); |
307 | 312 | return; |
308 | 313 | } |
309 | 314 |
|
310 | | - if ( pServer->SendChatTextToConChannel ( id, jsonChatMessage.toString() ) ) |
| 315 | + if ( pServer->SendChatTextToConChannel ( id, chatMessage ) ) |
311 | 316 | { |
312 | 317 | response["error"] = "invalid channel ID"; |
313 | 318 | return; |
|
0 commit comments