2011-04-25 12:51:57 +02:00
|
|
|
/******************************************************************************\
|
2020-01-01 15:41:43 +01:00
|
|
|
* Copyright (c) 2004-2020
|
2011-04-25 12:51:57 +02:00
|
|
|
*
|
|
|
|
* Author(s):
|
|
|
|
* Volker Fischer
|
|
|
|
*
|
2020-06-10 20:04:09 +02:00
|
|
|
******************************************************************************
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it under
|
|
|
|
* the terms of the GNU General Public License as published by the Free Software
|
|
|
|
* Foundation; either version 2 of the License, or (at your option) any later
|
|
|
|
* version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
|
|
|
* details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with
|
|
|
|
* this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*
|
|
|
|
\******************************************************************************/
|
2011-04-25 12:51:57 +02:00
|
|
|
|
2020-06-10 20:04:09 +02:00
|
|
|
/*
|
2011-04-25 12:51:57 +02:00
|
|
|
Protocol message definition
|
|
|
|
---------------------------
|
|
|
|
|
|
|
|
- All messages received need to be acknowledged by an acknowledge packet (except
|
|
|
|
of connection less messages)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MAIN FRAME
|
|
|
|
----------
|
|
|
|
|
|
|
|
+-------------+------------+------------+------------------+ ...
|
|
|
|
| 2 bytes TAG | 2 bytes ID | 1 byte cnt | 2 bytes length n | ...
|
|
|
|
+-------------+------------+------------+------------------+ ...
|
|
|
|
... --------------+-------------+
|
|
|
|
... n bytes data | 2 bytes CRC |
|
|
|
|
... --------------+-------------+
|
|
|
|
|
|
|
|
- TAG is an all zero bit word to identify protocol messages
|
|
|
|
- message ID defined by the defines PROTMESSID_x
|
|
|
|
- cnt: counter which is increment for each message and wraps around at 255
|
|
|
|
- length n in bytes of the data
|
|
|
|
- actual data, dependent on message type
|
2015-12-06 16:20:40 +01:00
|
|
|
- 16 bits CRC, calculated over the entire message and is transmitted inverted
|
2011-04-25 12:51:57 +02:00
|
|
|
Generator polynom: G_16(x) = x^16 + x^12 + x^5 + 1, initial state: all ones
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-05-22 11:47:09 +02:00
|
|
|
MESSAGES (with connection)
|
|
|
|
--------------------------
|
2011-04-25 12:51:57 +02:00
|
|
|
|
|
|
|
- PROTMESSID_ACKN: Acknowledgement message
|
|
|
|
|
2015-12-06 16:20:40 +01:00
|
|
|
+------------------------------------------+
|
|
|
|
| 2 bytes ID of message to be acknowledged |
|
|
|
|
+------------------------------------------+
|
2011-04-25 12:51:57 +02:00
|
|
|
|
|
|
|
note: the cnt value is the same as of the message to be acknowledged
|
|
|
|
|
|
|
|
|
|
|
|
- PROTMESSID_JITT_BUF_SIZE: Jitter buffer size
|
|
|
|
|
|
|
|
+--------------------------+
|
|
|
|
| 2 bytes number of blocks |
|
|
|
|
+--------------------------+
|
|
|
|
|
|
|
|
|
|
|
|
- PROTMESSID_REQ_JITT_BUF_SIZE: Request jitter buffer size
|
|
|
|
|
|
|
|
note: does not have any data -> n = 0
|
|
|
|
|
|
|
|
|
2020-05-26 17:28:44 +02:00
|
|
|
- PROTMESSID_CLIENT_ID: Sends the current client ID to the client
|
|
|
|
|
|
|
|
+---------------------------------+
|
|
|
|
| 1 byte channel ID of the client |
|
|
|
|
+---------------------------------+
|
|
|
|
|
|
|
|
|
2011-04-25 12:51:57 +02:00
|
|
|
- PROTMESSID_CHANNEL_GAIN: Gain of channel
|
|
|
|
|
|
|
|
+-------------------+--------------+
|
|
|
|
| 1 byte channel ID | 2 bytes gain |
|
|
|
|
+-------------------+--------------+
|
|
|
|
|
|
|
|
|
2020-05-16 18:18:58 +02:00
|
|
|
- PROTMESSID_CHANNEL_PAN: Gain of channel
|
|
|
|
|
|
|
|
+-------------------+-----------------+
|
|
|
|
| 1 byte channel ID | 2 bytes panning |
|
|
|
|
+-------------------+-----------------+
|
|
|
|
|
|
|
|
|
2020-05-21 11:47:39 +02:00
|
|
|
- PROTMESSID_MUTE_STATE_CHANGED: Mute state of your signal at another client has changed
|
|
|
|
|
|
|
|
+-------------------+-----------------+
|
|
|
|
| 1 byte channel ID | 1 byte is muted |
|
|
|
|
+-------------------+-----------------+
|
|
|
|
|
|
|
|
|
2013-02-11 16:21:53 +01:00
|
|
|
- PROTMESSID_CONN_CLIENTS_LIST: Information about connected clients
|
2013-02-10 09:50:43 +01:00
|
|
|
|
|
|
|
for each connected client append following data:
|
|
|
|
|
|
|
|
+-------------------+-----------------+--------------------+ ...
|
|
|
|
| 1 byte channel ID | 2 bytes country | 4 bytes instrument | ...
|
|
|
|
+-------------------+-----------------+--------------------+ ...
|
2013-02-11 16:21:53 +01:00
|
|
|
... --------------------+--------------------+ ...
|
|
|
|
... 1 byte skill level | 4 bytes IP address | ...
|
|
|
|
... --------------------+--------------------+ ...
|
|
|
|
... ------------------+---------------------------+
|
|
|
|
... 2 bytes number n | n bytes UTF-8 string name |
|
|
|
|
... ------------------+---------------------------+
|
2013-02-10 09:50:43 +01:00
|
|
|
... ------------------+---------------------------+
|
|
|
|
... 2 bytes number n | n bytes UTF-8 string city |
|
|
|
|
... ------------------+---------------------------+
|
|
|
|
|
|
|
|
|
2011-04-25 12:51:57 +02:00
|
|
|
- PROTMESSID_REQ_CONN_CLIENTS_LIST: Request connected clients list
|
|
|
|
|
|
|
|
note: does not have any data -> n = 0
|
|
|
|
|
|
|
|
|
2013-02-11 16:21:53 +01:00
|
|
|
- PROTMESSID_CHANNEL_INFOS: Information about the channel
|
|
|
|
|
|
|
|
+-----------------+--------------------+ ...
|
|
|
|
| 2 bytes country | 4 bytes instrument | ...
|
|
|
|
+-----------------+--------------------+ ...
|
|
|
|
... --------------------+ ...
|
|
|
|
... 1 byte skill level | ...
|
|
|
|
... --------------------+ ...
|
|
|
|
... ------------------+---------------------------+ ...
|
|
|
|
... 2 bytes number n | n bytes UTF-8 string name | ...
|
|
|
|
... ------------------+---------------------------+ ...
|
|
|
|
... ------------------+---------------------------+
|
|
|
|
... 2 bytes number n | n bytes UTF-8 string city |
|
|
|
|
... ------------------+---------------------------+
|
|
|
|
|
|
|
|
|
|
|
|
- PROTMESSID_REQ_CHANNEL_INFOS: Request infos of the channel
|
2011-04-25 12:51:57 +02:00
|
|
|
|
|
|
|
note: does not have any data -> n = 0
|
|
|
|
|
|
|
|
|
|
|
|
- PROTMESSID_CHAT_TEXT: Chat text
|
|
|
|
|
|
|
|
+------------------+----------------------+
|
|
|
|
| 2 bytes number n | n bytes UTF-8 string |
|
|
|
|
+------------------+----------------------+
|
|
|
|
|
|
|
|
|
|
|
|
- PROTMESSID_NETW_TRANSPORT_PROPS: Properties for network transport
|
|
|
|
|
|
|
|
+------------------------+-------------------------+-----------------+ ...
|
|
|
|
| 4 bytes base netw size | 2 bytes block size fact | 1 byte num chan | ...
|
|
|
|
+------------------------+-------------------------+-----------------+ ...
|
|
|
|
... ------------------+-----------------------+ ...
|
|
|
|
... 4 bytes sam rate | 2 bytes audiocod type | ...
|
|
|
|
... ------------------+-----------------------+ ...
|
|
|
|
... -----------------+----------------------+
|
2020-06-10 20:04:09 +02:00
|
|
|
... 2 bytes version | 4 bytes audiocod arg |
|
2011-04-25 12:51:57 +02:00
|
|
|
... -----------------+----------------------+
|
|
|
|
|
|
|
|
- "base netw size": length of the base network packet (frame) in bytes
|
|
|
|
- "block size fact": block size factor
|
|
|
|
- "num chan": number of channels of the audio signal, e.g. "2" is
|
|
|
|
stereo
|
|
|
|
- "sam rate": sample rate of the audio stream
|
|
|
|
- "audiocod type": audio coding type, the following types are supported:
|
|
|
|
- 0: none, no audio coding applied
|
|
|
|
- 1: CELT
|
2013-02-16 19:01:51 +01:00
|
|
|
- 2: OPUS
|
2020-05-14 22:27:58 +02:00
|
|
|
- 3: OPUS64
|
2011-04-25 12:51:57 +02:00
|
|
|
- "version": version of the audio coder, if not used this value
|
|
|
|
shall be set to 0
|
|
|
|
- "audiocod arg": argument for the audio coder, if not used this value
|
|
|
|
shall be set to 0
|
|
|
|
|
|
|
|
|
|
|
|
- PROTMESSID_REQ_NETW_TRANSPORT_PROPS: Request properties for network transport
|
|
|
|
|
|
|
|
note: does not have any data -> n = 0
|
|
|
|
|
|
|
|
|
2015-01-18 22:23:47 +01:00
|
|
|
- PROTMESSID_LICENCE_REQUIRED: Licence required to connect to the server
|
|
|
|
|
|
|
|
+---------------------+
|
|
|
|
| 1 byte licence type |
|
|
|
|
+---------------------+
|
|
|
|
|
2020-05-26 17:28:44 +02:00
|
|
|
|
2020-05-18 19:00:56 +02:00
|
|
|
- PROTMESSID_REQ_CHANNEL_LEVEL_LIST: Opt in or out of the channel level list
|
2020-03-29 19:00:07 +02:00
|
|
|
|
|
|
|
+---------------+
|
|
|
|
| 1 byte option |
|
|
|
|
+---------------+
|
|
|
|
|
|
|
|
option is boolean, true to opt in, false to opt out
|
|
|
|
|
2020-05-26 17:28:44 +02:00
|
|
|
|
2020-05-18 19:00:56 +02:00
|
|
|
- PROTMESSID_VERSION_AND_OS: Version number and operating system
|
|
|
|
|
|
|
|
+-------------------------+------------------+------------------------------+
|
|
|
|
| 1 byte operating system | 2 bytes number n | n bytes UTF-8 string version |
|
|
|
|
+-------------------------+------------------+------------------------------+
|
|
|
|
|
2015-01-18 22:23:47 +01:00
|
|
|
|
2020-04-06 17:17:49 +02:00
|
|
|
// #### COMPATIBILITY OLD VERSION, TO BE REMOVED ####
|
|
|
|
- PROTMESSID_OPUS_SUPPORTED: Informs that OPUS codec is supported
|
|
|
|
|
|
|
|
note: does not have any data -> n = 0
|
|
|
|
|
|
|
|
|
2020-06-14 19:17:12 +02:00
|
|
|
- PROTMESSID_RECORDER_STATE: notifies of changes in the server jam recorder state
|
|
|
|
|
|
|
|
+--------------+
|
|
|
|
| 1 byte state |
|
|
|
|
+--------------+
|
|
|
|
|
|
|
|
state is a value from the enum ERecorderState:
|
|
|
|
- 0 undefined (not used by protocol messages)
|
|
|
|
- tbc
|
|
|
|
|
|
|
|
|
2011-04-25 12:51:57 +02:00
|
|
|
CONNECTION LESS MESSAGES
|
|
|
|
------------------------
|
|
|
|
|
|
|
|
- PROTMESSID_CLM_PING_MS: Connection less ping message (for measuring the ping
|
|
|
|
time)
|
|
|
|
|
2011-05-24 20:44:51 +02:00
|
|
|
+-----------------------------+
|
|
|
|
| 4 bytes transmit time in ms |
|
|
|
|
+-----------------------------+
|
2011-04-25 12:51:57 +02:00
|
|
|
|
|
|
|
|
|
|
|
- PROTMESSID_CLM_PING_MS_WITHNUMCLIENTS: Connection less ping message (for
|
|
|
|
measuring the ping time) with the
|
|
|
|
info about the current number of
|
|
|
|
connected clients
|
|
|
|
|
|
|
|
+-----------------------------+---------------------------------+
|
|
|
|
| 4 bytes transmit time in ms | 1 byte number connected clients |
|
|
|
|
+-----------------------------+---------------------------------+
|
|
|
|
|
|
|
|
|
2015-01-23 20:43:18 +01:00
|
|
|
- PROTMESSID_CLM_SERVER_FULL: Connection less server full message
|
2011-04-25 12:51:57 +02:00
|
|
|
|
|
|
|
note: does not have any data -> n = 0
|
|
|
|
|
|
|
|
|
|
|
|
- PROTMESSID_CLM_REGISTER_SERVER: Register a server, providing server
|
|
|
|
information
|
|
|
|
|
2020-04-12 14:26:21 +02:00
|
|
|
+------------------------------+ ...
|
|
|
|
| 2 bytes server internal port | ...
|
|
|
|
+------------------------------+ ...
|
2011-05-04 20:18:31 +02:00
|
|
|
... -----------------+----------------------------------+ ...
|
|
|
|
... 2 bytes country | 1 byte maximum connected clients | ...
|
|
|
|
... -----------------+----------------------------------+ ...
|
2020-04-09 20:06:34 +02:00
|
|
|
... ---------------------+ ...
|
|
|
|
... 1 byte is permanent | ...
|
|
|
|
... ---------------------+ ...
|
|
|
|
... ------------------+----------------------------------+ ...
|
|
|
|
... 2 bytes number n | n bytes UTF-8 string server name | ...
|
|
|
|
... ------------------+----------------------------------+ ...
|
2020-06-29 21:18:54 +02:00
|
|
|
... ------------------+----------------------------------------------+ ...
|
|
|
|
... 2 bytes number n | n bytes UTF-8 string server internal address | ...
|
|
|
|
... ------------------+----------------------------------------------+ ...
|
2011-04-25 12:51:57 +02:00
|
|
|
... ------------------+---------------------------+
|
|
|
|
... 2 bytes number n | n bytes UTF-8 string city |
|
|
|
|
... ------------------+---------------------------+
|
|
|
|
|
2020-04-09 20:06:34 +02:00
|
|
|
- "country" is according to "Common Locale Data Repository" which is used in
|
|
|
|
the QLocale class
|
2011-04-25 12:51:57 +02:00
|
|
|
- "maximum connected clients" is the maximum number of clients which can
|
|
|
|
be connected to the server at the same time
|
|
|
|
- "is permanent" is a flag which indicates if the server is permanent
|
|
|
|
online or not. If this value is any value <> 0 indicates that the server
|
|
|
|
is permanent online.
|
2020-06-29 21:18:54 +02:00
|
|
|
- "server internal address" represents the IPv4 address as a dotted quad to
|
2020-04-09 20:06:34 +02:00
|
|
|
be used by clients with the same external IP address as the server.
|
2020-04-12 14:26:21 +02:00
|
|
|
NOTE: In the PROTMESSID_CLM_SERVER_LIST list, this field will be empty
|
|
|
|
as only the initial IP address should be used by the client. Where
|
|
|
|
necessary, that value will contain the server internal address.
|
2011-04-25 12:51:57 +02:00
|
|
|
|
|
|
|
|
2011-05-03 22:37:06 +02:00
|
|
|
- PROTMESSID_CLM_UNREGISTER_SERVER: Unregister a server
|
|
|
|
|
|
|
|
note: does not have any data -> n = 0
|
|
|
|
|
|
|
|
|
2011-04-25 12:51:57 +02:00
|
|
|
- PROTMESSID_CLM_SERVER_LIST: Server list message
|
|
|
|
|
|
|
|
for each registered server append following data:
|
|
|
|
|
2015-12-06 16:20:40 +01:00
|
|
|
+--------------------+--------------------------------+
|
|
|
|
| 4 bytes IP address | PROTMESSID_CLM_REGISTER_SERVER |
|
|
|
|
+--------------------+--------------------------------+
|
2011-04-25 12:51:57 +02:00
|
|
|
|
|
|
|
- "PROTMESSID_CLM_REGISTER_SERVER" means that exactly the same message body
|
|
|
|
of the PROTMESSID_CLM_REGISTER_SERVER message is used
|
|
|
|
|
|
|
|
|
|
|
|
- PROTMESSID_CLM_REQ_SERVER_LIST: Request server list
|
|
|
|
|
|
|
|
note: does not have any data -> n = 0
|
|
|
|
|
|
|
|
|
|
|
|
- PROTMESSID_CLM_SEND_EMPTY_MESSAGE: Send "empty message" message
|
|
|
|
|
|
|
|
+--------------------+--------------+
|
|
|
|
| 4 bytes IP address | 2 bytes port |
|
|
|
|
+--------------------+--------------+
|
|
|
|
|
|
|
|
|
2011-05-22 11:47:09 +02:00
|
|
|
- PROTMESSID_CLM_DISCONNECTION: Disconnect message
|
|
|
|
|
|
|
|
note: does not have any data -> n = 0
|
|
|
|
|
|
|
|
|
2014-02-21 22:25:26 +01:00
|
|
|
- PROTMESSID_CLM_VERSION_AND_OS: Version number and operating system
|
|
|
|
|
|
|
|
+-------------------------+------------------+------------------------------+
|
|
|
|
| 1 byte operating system | 2 bytes number n | n bytes UTF-8 string version |
|
|
|
|
+-------------------------+------------------+------------------------------+
|
|
|
|
|
|
|
|
|
|
|
|
- PROTMESSID_CLM_REQ_VERSION_AND_OS: Request version number and operating system
|
|
|
|
|
|
|
|
note: does not have any data -> n = 0
|
|
|
|
|
2015-12-06 18:51:06 +01:00
|
|
|
|
|
|
|
- PROTMESSID_CLM_CONN_CLIENTS_LIST: Information about connected clients
|
|
|
|
|
|
|
|
for each connected client append the PROTMESSID_CONN_CLIENTS_LIST:
|
|
|
|
|
2015-12-09 16:50:30 +01:00
|
|
|
+------------------------------+------------------------------+ ...
|
|
|
|
| PROTMESSID_CONN_CLIENTS_LIST | PROTMESSID_CONN_CLIENTS_LIST | ...
|
|
|
|
+------------------------------+------------------------------+ ...
|
2015-12-06 18:51:06 +01:00
|
|
|
|
|
|
|
|
|
|
|
- PROTMESSID_CLM_REQ_CONN_CLIENTS_LIST: Request the connected clients list
|
|
|
|
|
2015-12-09 16:50:30 +01:00
|
|
|
note: does not have any data -> n = 0
|
2015-12-06 18:51:06 +01:00
|
|
|
|
2020-04-14 22:00:08 +02:00
|
|
|
|
2020-03-29 19:00:07 +02:00
|
|
|
- PROTMESSID_CLM_CHANNEL_LEVEL_LIST: The channel level list
|
|
|
|
|
|
|
|
+----------------------------------+
|
|
|
|
| ( ( n + 1 ) / 2 ) * 4 bit values |
|
|
|
|
+----------------------------------+
|
|
|
|
|
|
|
|
n is number of connected clients
|
|
|
|
|
|
|
|
the values are the maximum channel levels for a client frame converted
|
2020-06-21 20:09:13 +02:00
|
|
|
to the range of CLevelMeter in 4 bits, two entries per byte
|
2020-03-29 19:00:07 +02:00
|
|
|
with the earlier channel in the lower half of the byte
|
|
|
|
|
|
|
|
where an odd number of clients is connected, there will be four unused
|
|
|
|
upper bits in the final byte, containing 0xF (which is out of range)
|
|
|
|
|
2020-04-14 22:00:08 +02:00
|
|
|
the server may compute the message when any client has used
|
2020-03-29 19:00:07 +02:00
|
|
|
PROTMESSID_CLM_REQ_CHANNEL_LEVEL_LIST to opt in
|
|
|
|
|
2020-04-14 22:00:08 +02:00
|
|
|
the server should issue the message only to a client that has used
|
2020-03-29 19:00:07 +02:00
|
|
|
PROTMESSID_CLM_REQ_CHANNEL_LEVEL_LIST to opt in
|
|
|
|
|
2015-12-06 18:51:06 +01:00
|
|
|
|
2020-04-14 22:00:08 +02:00
|
|
|
- PROTMESSID_CLM_REGISTER_SERVER_RESP: result of registration request
|
|
|
|
|
|
|
|
+---------------+
|
|
|
|
| 1 byte status |
|
|
|
|
+---------------+
|
|
|
|
|
|
|
|
- "status":
|
|
|
|
Values of ESvrRegResult:
|
|
|
|
0 - success
|
|
|
|
1 - failed due to central server list being full
|
2020-06-23 17:28:19 +02:00
|
|
|
2 - your server version is too old
|
2020-06-23 17:51:47 +02:00
|
|
|
3 - registration requirements not fulfilled
|
2020-04-14 22:00:08 +02:00
|
|
|
|
|
|
|
Note: the central server may send this message in response to a
|
|
|
|
PROTMESSID_CLM_REGISTER_SERVER request.
|
|
|
|
Where not received, the registering server may only retry up to
|
|
|
|
five times for one registration request at 500ms intervals.
|
|
|
|
Beyond this, it should "ping" every 15 minutes
|
|
|
|
(standard re-registration timeout).
|
2020-06-10 20:04:09 +02:00
|
|
|
*/
|
2011-04-25 12:51:57 +02:00
|
|
|
|
|
|
|
#include "protocol.h"
|
|
|
|
|
|
|
|
|
|
|
|
/* Implementation *************************************************************/
|
|
|
|
CProtocol::CProtocol()
|
|
|
|
{
|
|
|
|
Reset();
|
|
|
|
|
|
|
|
|
|
|
|
// Connections -------------------------------------------------------------
|
2020-06-06 22:15:33 +02:00
|
|
|
QObject::connect ( &TimerSendMess, &QTimer::timeout,
|
|
|
|
this, &CProtocol::OnTimerSendMess );
|
2011-04-25 12:51:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CProtocol::Reset()
|
|
|
|
{
|
|
|
|
QMutexLocker locker ( &Mutex );
|
|
|
|
|
|
|
|
// prepare internal variables for initial protocol transfer
|
|
|
|
iCounter = 0;
|
|
|
|
iOldRecID = PROTMESSID_ILLEGAL;
|
|
|
|
iOldRecCnt = 0;
|
|
|
|
|
|
|
|
// delete complete "send message queue"
|
|
|
|
SendMessQueue.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CProtocol::EnqueueMessage ( CVector<uint8_t>& vecMessage,
|
|
|
|
const int iCnt,
|
|
|
|
const int iID )
|
|
|
|
{
|
|
|
|
bool bListWasEmpty;
|
|
|
|
|
|
|
|
Mutex.lock();
|
|
|
|
{
|
|
|
|
// check if list is empty so that we have to initiate a send process
|
|
|
|
bListWasEmpty = SendMessQueue.empty();
|
|
|
|
|
|
|
|
// create send message object for the queue
|
|
|
|
CSendMessage SendMessageObj ( vecMessage, iCnt, iID );
|
|
|
|
|
|
|
|
// we want to have a FIFO: we add at the end and take from the beginning
|
|
|
|
SendMessQueue.push_back ( SendMessageObj );
|
|
|
|
}
|
|
|
|
Mutex.unlock();
|
|
|
|
|
|
|
|
// if list was empty, initiate send process
|
|
|
|
if ( bListWasEmpty )
|
|
|
|
{
|
|
|
|
SendMessage();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CProtocol::SendMessage()
|
|
|
|
{
|
|
|
|
CVector<uint8_t> vecMessage;
|
|
|
|
bool bSendMess = false;
|
|
|
|
|
|
|
|
Mutex.lock();
|
|
|
|
{
|
|
|
|
// we have to check that list is not empty, since in another thread the
|
|
|
|
// last element of the list might have been erased
|
|
|
|
if ( !SendMessQueue.empty() )
|
|
|
|
{
|
|
|
|
vecMessage.Init ( SendMessQueue.front().vecMessage.Size() );
|
|
|
|
vecMessage = SendMessQueue.front().vecMessage;
|
|
|
|
|
|
|
|
bSendMess = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Mutex.unlock();
|
|
|
|
|
|
|
|
if ( bSendMess )
|
|
|
|
{
|
|
|
|
// send message
|
|
|
|
emit MessReadyForSending ( vecMessage );
|
|
|
|
|
|
|
|
// start time-out timer if not active
|
|
|
|
if ( !TimerSendMess.isActive() )
|
|
|
|
{
|
|
|
|
TimerSendMess.start ( SEND_MESS_TIMEOUT_MS );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// no message to send, stop timer
|
|
|
|
TimerSendMess.stop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CProtocol::CreateAndSendMessage ( const int iID,
|
|
|
|
const CVector<uint8_t>& vecData )
|
|
|
|
{
|
|
|
|
CVector<uint8_t> vecNewMessage;
|
|
|
|
int iCurCounter;
|
|
|
|
|
|
|
|
Mutex.lock();
|
|
|
|
{
|
|
|
|
// store current counter value
|
|
|
|
iCurCounter = iCounter;
|
|
|
|
|
|
|
|
// increase counter (wraps around automatically)
|
|
|
|
iCounter++;
|
|
|
|
}
|
|
|
|
Mutex.unlock();
|
|
|
|
|
|
|
|
// build complete message
|
|
|
|
GenMessageFrame ( vecNewMessage, iCurCounter, iID, vecData );
|
|
|
|
|
|
|
|
// enqueue message
|
|
|
|
EnqueueMessage ( vecNewMessage, iCurCounter, iID );
|
|
|
|
}
|
|
|
|
|
|
|
|
void CProtocol::CreateAndImmSendAcknMess ( const int& iID,
|
|
|
|
const int& iCnt )
|
|
|
|
{
|
|
|
|
CVector<uint8_t> vecAcknMessage;
|
|
|
|
CVector<uint8_t> vecData ( 2 ); // 2 bytes of data
|
|
|
|
int iPos = 0; // init position pointer
|
|
|
|
|
|
|
|
// build data vector
|
|
|
|
PutValOnStream ( vecData, iPos, static_cast<uint32_t> ( iID ), 2 );
|
|
|
|
|
|
|
|
// build complete message
|
|
|
|
GenMessageFrame ( vecAcknMessage, iCnt, PROTMESSID_ACKN, vecData );
|
|
|
|
|
|
|
|
// immediately send acknowledge message
|
|
|
|
emit MessReadyForSending ( vecAcknMessage );
|
|
|
|
}
|
|
|
|
|
|
|
|
void CProtocol::CreateAndImmSendConLessMessage ( const int iID,
|
|
|
|
const CVector<uint8_t>& vecData,
|
|
|
|
const CHostAddress& InetAddr )
|
|
|
|
{
|
|
|
|
CVector<uint8_t> vecNewMessage;
|
|
|
|
|
|
|
|
// build complete message (counter per definition=0 for connection less
|
|
|
|
// messages)
|
|
|
|
GenMessageFrame ( vecNewMessage, 0, iID, vecData );
|
|
|
|
|
|
|
|
// immediately send message
|
|
|
|
emit CLMessReadyForSending ( InetAddr, vecNewMessage );
|
|
|
|
}
|
|
|
|
|
2013-06-03 18:07:17 +02:00
|
|
|
bool CProtocol::ParseMessageBody ( const CVector<uint8_t>& vecbyMesBodyData,
|
|
|
|
const int iRecCounter,
|
|
|
|
const int iRecID )
|
2011-04-25 12:51:57 +02:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
return code: false -> ok; true -> error
|
|
|
|
*/
|
2013-06-03 18:07:17 +02:00
|
|
|
bool bRet = false;
|
|
|
|
bool bSendNextMess;
|
2011-04-25 12:51:57 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
// TEST channel implementation: randomly delete protocol messages (50 % loss)
|
|
|
|
if ( rand() < ( RAND_MAX / 2 ) ) return false;
|
|
|
|
*/
|
|
|
|
|
2013-06-03 18:07:17 +02:00
|
|
|
// In case we received a message and returned an answer but our answer
|
|
|
|
// did not make it to the receiver, he will resend his message. We check
|
|
|
|
// here if the message is the same as the old one, and if this is the
|
|
|
|
// case, just resend our old answer again
|
|
|
|
if ( ( iOldRecID == iRecID ) && ( iOldRecCnt == iRecCounter ) )
|
|
|
|
{
|
|
|
|
// acknowledgments are not acknowledged
|
|
|
|
if ( iRecID != PROTMESSID_ACKN )
|
2011-04-25 12:51:57 +02:00
|
|
|
{
|
2013-06-03 18:07:17 +02:00
|
|
|
// resend acknowledgement
|
|
|
|
CreateAndImmSendAcknMess ( iRecID, iRecCounter );
|
2011-04-25 12:51:57 +02:00
|
|
|
}
|
2013-06-03 18:07:17 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// special treatment for acknowledge messages
|
|
|
|
if ( iRecID == PROTMESSID_ACKN )
|
2011-04-25 12:51:57 +02:00
|
|
|
{
|
2020-05-28 03:01:20 +02:00
|
|
|
// check size
|
|
|
|
if ( vecbyMesBodyData.Size() != 2 )
|
|
|
|
{
|
|
|
|
return true; // return error code
|
|
|
|
}
|
|
|
|
|
2013-06-03 18:07:17 +02:00
|
|
|
// extract data from stream and emit signal for received value
|
|
|
|
int iPos = 0;
|
|
|
|
const int iData =
|
|
|
|
static_cast<int> ( GetValFromStream ( vecbyMesBodyData, iPos, 2 ) );
|
2011-04-25 12:51:57 +02:00
|
|
|
|
2013-06-03 18:07:17 +02:00
|
|
|
Mutex.lock();
|
|
|
|
{
|
|
|
|
// check if this is the correct acknowledgment
|
|
|
|
bSendNextMess = false;
|
|
|
|
if ( !SendMessQueue.empty() )
|
2011-04-25 12:51:57 +02:00
|
|
|
{
|
2013-06-03 18:07:17 +02:00
|
|
|
if ( ( SendMessQueue.front().iCnt == iRecCounter ) &&
|
|
|
|
( SendMessQueue.front().iID == iData ) )
|
2011-04-25 12:51:57 +02:00
|
|
|
{
|
2013-06-03 18:07:17 +02:00
|
|
|
// message acknowledged, remove from queue
|
|
|
|
SendMessQueue.pop_front();
|
|
|
|
|
|
|
|
// send next message in queue
|
|
|
|
bSendNextMess = true;
|
2011-04-25 12:51:57 +02:00
|
|
|
}
|
|
|
|
}
|
2013-06-03 18:07:17 +02:00
|
|
|
}
|
|
|
|
Mutex.unlock();
|
2011-04-25 12:51:57 +02:00
|
|
|
|
2013-06-03 18:07:17 +02:00
|
|
|
if ( bSendNextMess )
|
|
|
|
{
|
|
|
|
SendMessage();
|
2011-04-25 12:51:57 +02:00
|
|
|
}
|
2013-06-03 18:07:17 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// check which type of message we received and do action
|
|
|
|
switch ( iRecID )
|
2011-04-25 12:51:57 +02:00
|
|
|
{
|
2013-06-03 18:07:17 +02:00
|
|
|
case PROTMESSID_JITT_BUF_SIZE:
|
|
|
|
bRet = EvaluateJitBufMes ( vecbyMesBodyData );
|
|
|
|
break;
|
2011-04-25 12:51:57 +02:00
|
|
|
|
2013-06-03 18:07:17 +02:00
|
|
|
case PROTMESSID_REQ_JITT_BUF_SIZE:
|
|
|
|
bRet = EvaluateReqJitBufMes();
|
|
|
|
break;
|
2011-04-25 12:51:57 +02:00
|
|
|
|
2020-05-26 17:28:44 +02:00
|
|
|
case PROTMESSID_CLIENT_ID:
|
|
|
|
bRet = EvaluateClientIDMes ( vecbyMesBodyData );
|
|
|
|
break;
|
|
|
|
|
2013-06-03 18:07:17 +02:00
|
|
|
case PROTMESSID_CHANNEL_GAIN:
|
|
|
|
bRet = EvaluateChanGainMes ( vecbyMesBodyData );
|
|
|
|
break;
|
2011-04-25 12:51:57 +02:00
|
|
|
|
2020-04-26 00:55:28 +02:00
|
|
|
case PROTMESSID_CHANNEL_PAN:
|
|
|
|
bRet = EvaluateChanPanMes ( vecbyMesBodyData );
|
|
|
|
break;
|
|
|
|
|
2020-05-21 11:47:39 +02:00
|
|
|
case PROTMESSID_MUTE_STATE_CHANGED:
|
|
|
|
bRet = EvaluateMuteStateHasChangedMes ( vecbyMesBodyData );
|
|
|
|
break;
|
|
|
|
|
2013-06-03 18:07:17 +02:00
|
|
|
case PROTMESSID_CONN_CLIENTS_LIST:
|
|
|
|
bRet = EvaluateConClientListMes ( vecbyMesBodyData );
|
|
|
|
break;
|
2011-04-25 12:51:57 +02:00
|
|
|
|
2013-06-03 18:07:17 +02:00
|
|
|
case PROTMESSID_REQ_CONN_CLIENTS_LIST:
|
|
|
|
bRet = EvaluateReqConnClientsList();
|
|
|
|
break;
|
2011-04-25 12:51:57 +02:00
|
|
|
|
2013-06-03 18:07:17 +02:00
|
|
|
case PROTMESSID_CHANNEL_INFOS:
|
|
|
|
bRet = EvaluateChanInfoMes ( vecbyMesBodyData );
|
|
|
|
break;
|
2011-04-25 12:51:57 +02:00
|
|
|
|
2013-06-03 18:07:17 +02:00
|
|
|
case PROTMESSID_REQ_CHANNEL_INFOS:
|
|
|
|
bRet = EvaluateReqChanInfoMes();
|
|
|
|
break;
|
2011-04-25 12:51:57 +02:00
|
|
|
|
2013-06-03 18:07:17 +02:00
|
|
|
case PROTMESSID_CHAT_TEXT:
|
|
|
|
bRet = EvaluateChatTextMes ( vecbyMesBodyData );
|
|
|
|
break;
|
2011-04-25 12:51:57 +02:00
|
|
|
|
2013-06-03 18:07:17 +02:00
|
|
|
case PROTMESSID_NETW_TRANSPORT_PROPS:
|
|
|
|
bRet = EvaluateNetwTranspPropsMes ( vecbyMesBodyData );
|
|
|
|
break;
|
2011-04-25 12:51:57 +02:00
|
|
|
|
2013-06-03 18:07:17 +02:00
|
|
|
case PROTMESSID_REQ_NETW_TRANSPORT_PROPS:
|
|
|
|
bRet = EvaluateReqNetwTranspPropsMes();
|
|
|
|
break;
|
2013-02-16 19:01:51 +01:00
|
|
|
|
2015-01-18 22:23:47 +01:00
|
|
|
case PROTMESSID_LICENCE_REQUIRED:
|
|
|
|
bRet = EvaluateLicenceRequiredMes ( vecbyMesBodyData );
|
|
|
|
break;
|
2020-03-29 19:00:07 +02:00
|
|
|
|
|
|
|
case PROTMESSID_REQ_CHANNEL_LEVEL_LIST:
|
|
|
|
bRet = EvaluateReqChannelLevelListMes ( vecbyMesBodyData );
|
|
|
|
break;
|
2020-05-18 19:00:56 +02:00
|
|
|
|
|
|
|
case PROTMESSID_VERSION_AND_OS:
|
|
|
|
bRet = EvaluateVersionAndOSMes ( vecbyMesBodyData );
|
|
|
|
break;
|
2020-06-14 19:17:12 +02:00
|
|
|
|
|
|
|
case PROTMESSID_RECORDER_STATE:
|
|
|
|
bRet = EvaluateRecorderStateMes ( vecbyMesBodyData );
|
|
|
|
break;
|
2013-06-03 18:07:17 +02:00
|
|
|
}
|
2011-04-25 12:51:57 +02:00
|
|
|
|
2013-06-03 18:07:17 +02:00
|
|
|
// immediately send acknowledge message
|
|
|
|
CreateAndImmSendAcknMess ( iRecID, iRecCounter );
|
2011-04-25 12:51:57 +02:00
|
|
|
|
2013-06-03 18:07:17 +02:00
|
|
|
// save current message ID and counter to find out if message
|
|
|
|
// was resent
|
|
|
|
iOldRecID = iRecID;
|
|
|
|
iOldRecCnt = iRecCounter;
|
2011-04-25 12:51:57 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-03 18:07:17 +02:00
|
|
|
return bRet;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CProtocol::ParseConnectionLessMessageBody ( const CVector<uint8_t>& vecbyMesBodyData,
|
|
|
|
const int iRecID,
|
|
|
|
const CHostAddress& InetAddr )
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
return code: false -> ok; true -> error
|
|
|
|
*/
|
|
|
|
bool bRet = false;
|
2011-05-05 21:39:48 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
// TEST channel implementation: randomly delete protocol messages (50 % loss)
|
|
|
|
if ( rand() < ( RAND_MAX / 2 ) ) return false;
|
|
|
|
*/
|
|
|
|
|
2013-06-03 18:07:17 +02:00
|
|
|
if ( IsConnectionLessMessageID ( iRecID ) )
|
|
|
|
{
|
|
|
|
// check which type of message we received and do action
|
|
|
|
switch ( iRecID )
|
2011-04-25 12:51:57 +02:00
|
|
|
{
|
2013-06-03 18:07:17 +02:00
|
|
|
case PROTMESSID_CLM_PING_MS:
|
|
|
|
bRet = EvaluateCLPingMes ( InetAddr, vecbyMesBodyData );
|
|
|
|
break;
|
2011-04-25 12:51:57 +02:00
|
|
|
|
2013-06-03 18:07:17 +02:00
|
|
|
case PROTMESSID_CLM_PING_MS_WITHNUMCLIENTS:
|
|
|
|
bRet = EvaluateCLPingWithNumClientsMes ( InetAddr, vecbyMesBodyData );
|
|
|
|
break;
|
2011-04-25 12:51:57 +02:00
|
|
|
|
2013-06-03 18:07:17 +02:00
|
|
|
case PROTMESSID_CLM_SERVER_FULL:
|
|
|
|
bRet = EvaluateCLServerFullMes();
|
|
|
|
break;
|
2011-04-25 12:51:57 +02:00
|
|
|
|
2013-06-03 18:07:17 +02:00
|
|
|
case PROTMESSID_CLM_SERVER_LIST:
|
|
|
|
bRet = EvaluateCLServerListMes ( InetAddr, vecbyMesBodyData );
|
|
|
|
break;
|
2011-04-25 12:51:57 +02:00
|
|
|
|
2013-06-03 18:07:17 +02:00
|
|
|
case PROTMESSID_CLM_REQ_SERVER_LIST:
|
|
|
|
bRet = EvaluateCLReqServerListMes ( InetAddr );
|
|
|
|
break;
|
2011-04-25 12:51:57 +02:00
|
|
|
|
2013-06-03 18:07:17 +02:00
|
|
|
case PROTMESSID_CLM_SEND_EMPTY_MESSAGE:
|
|
|
|
bRet = EvaluateCLSendEmptyMesMes ( vecbyMesBodyData );
|
|
|
|
break;
|
2011-04-25 12:51:57 +02:00
|
|
|
|
2013-06-03 18:07:17 +02:00
|
|
|
case PROTMESSID_CLM_REGISTER_SERVER:
|
|
|
|
bRet = EvaluateCLRegisterServerMes ( InetAddr, vecbyMesBodyData );
|
|
|
|
break;
|
2011-05-03 22:37:06 +02:00
|
|
|
|
2013-06-03 18:07:17 +02:00
|
|
|
case PROTMESSID_CLM_UNREGISTER_SERVER:
|
|
|
|
bRet = EvaluateCLUnregisterServerMes ( InetAddr );
|
|
|
|
break;
|
2011-05-22 11:47:09 +02:00
|
|
|
|
2013-06-03 18:07:17 +02:00
|
|
|
case PROTMESSID_CLM_DISCONNECTION:
|
|
|
|
bRet = EvaluateCLDisconnectionMes ( InetAddr );
|
|
|
|
break;
|
2014-02-21 22:25:26 +01:00
|
|
|
|
|
|
|
case PROTMESSID_CLM_VERSION_AND_OS:
|
|
|
|
bRet = EvaluateCLVersionAndOSMes ( InetAddr, vecbyMesBodyData );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PROTMESSID_CLM_REQ_VERSION_AND_OS:
|
|
|
|
bRet = EvaluateCLReqVersionAndOSMes ( InetAddr );
|
|
|
|
break;
|
2015-12-06 18:51:06 +01:00
|
|
|
|
|
|
|
case PROTMESSID_CLM_CONN_CLIENTS_LIST:
|
|
|
|
bRet = EvaluateCLConnClientsListMes ( InetAddr, vecbyMesBodyData );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PROTMESSID_CLM_REQ_CONN_CLIENTS_LIST:
|
2015-12-09 16:50:30 +01:00
|
|
|
bRet = EvaluateCLReqConnClientsListMes ( InetAddr );
|
2015-12-06 18:51:06 +01:00
|
|
|
break;
|
2020-03-29 19:00:07 +02:00
|
|
|
|
|
|
|
case PROTMESSID_CLM_CHANNEL_LEVEL_LIST:
|
|
|
|
bRet = EvaluateCLChannelLevelListMes ( InetAddr, vecbyMesBodyData );
|
|
|
|
break;
|
2020-04-14 22:00:08 +02:00
|
|
|
|
|
|
|
case PROTMESSID_CLM_REGISTER_SERVER_RESP:
|
|
|
|
bRet = EvaluateCLRegisterServerResp ( InetAddr, vecbyMesBodyData );
|
|
|
|
break;
|
2011-04-25 12:51:57 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
bRet = true; // return error code
|
|
|
|
}
|
|
|
|
|
|
|
|
return bRet;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************************\
|
2011-05-25 22:00:54 +02:00
|
|
|
* Access functions for creating and parsing messages *
|
2011-04-25 12:51:57 +02:00
|
|
|
\******************************************************************************/
|
|
|
|
void CProtocol::CreateJitBufMes ( const int iJitBufSize )
|
|
|
|
{
|
|
|
|
CVector<uint8_t> vecData ( 2 ); // 2 bytes of data
|
|
|
|
int iPos = 0; // init position pointer
|
|
|
|
|
|
|
|
// build data vector
|
|
|
|
PutValOnStream ( vecData, iPos, static_cast<uint32_t> ( iJitBufSize ), 2 );
|
|
|
|
|
|
|
|
CreateAndSendMessage ( PROTMESSID_JITT_BUF_SIZE, vecData );
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CProtocol::EvaluateJitBufMes ( const CVector<uint8_t>& vecData )
|
|
|
|
{
|
|
|
|
int iPos = 0; // init position pointer
|
|
|
|
|
|
|
|
// check size
|
|
|
|
if ( vecData.Size() != 2 )
|
|
|
|
{
|
|
|
|
return true; // return error code
|
|
|
|
}
|
|
|
|
|
|
|
|
// extract jitter buffer size
|
2020-05-26 15:57:03 +02:00
|
|
|
const int iData = static_cast<int> ( GetValFromStream ( vecData, iPos, 2 ) );
|
2011-04-25 12:51:57 +02:00
|
|
|
|
2011-05-27 22:29:37 +02:00
|
|
|
if ( ( ( iData < MIN_NET_BUF_SIZE_NUM_BL ) ||
|
|
|
|
( iData > MAX_NET_BUF_SIZE_NUM_BL ) ) &&
|
|
|
|
( iData != AUTO_NET_BUF_SIZE_FOR_PROTOCOL ) )
|
2011-04-25 12:51:57 +02:00
|
|
|
{
|
|
|
|
return true; // return error code
|
|
|
|
}
|
|
|
|
|
|
|
|
// invoke message action
|
|
|
|
emit ChangeJittBufSize ( iData );
|
|
|
|
|
|
|
|
return false; // no error
|
|
|
|
}
|
|
|
|
|
|
|
|
void CProtocol::CreateReqJitBufMes()
|
|
|
|
{
|
|
|
|
CreateAndSendMessage ( PROTMESSID_REQ_JITT_BUF_SIZE,
|
|
|
|
CVector<uint8_t> ( 0 ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CProtocol::EvaluateReqJitBufMes()
|
|
|
|
{
|
|
|
|
// invoke message action
|
|
|
|
emit ReqJittBufSize();
|
|
|
|
|
|
|
|
return false; // no error
|
|
|
|
}
|
|
|
|
|
2020-05-26 17:28:44 +02:00
|
|
|
void CProtocol::CreateClientIDMes ( const int iChanID )
|
|
|
|
{
|
|
|
|
CVector<uint8_t> vecData ( 1 ); // 1 byte of data
|
|
|
|
int iPos = 0; // init position pointer
|
|
|
|
|
|
|
|
// build data vector
|
|
|
|
// channel ID
|
|
|
|
PutValOnStream ( vecData, iPos, static_cast<uint32_t> ( iChanID ), 1 );
|
|
|
|
|
|
|
|
CreateAndSendMessage ( PROTMESSID_CLIENT_ID, vecData );
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CProtocol::EvaluateClientIDMes ( const CVector<uint8_t>& vecData )
|
|
|
|
{
|
|
|
|
int iPos = 0; // init position pointer
|
|
|
|
|
|
|
|
// check size
|
|
|
|
if ( vecData.Size() != 1 )
|
|
|
|
{
|
|
|
|
return true; // return error code
|
|
|
|
}
|
|
|
|
|
|
|
|
// channel ID
|
|
|
|
const int iCurID = static_cast<int> ( GetValFromStream ( vecData, iPos, 1 ) );
|
|
|
|
|
|
|
|
// invoke message action
|
|
|
|
emit ClientIDReceived ( iCurID );
|
|
|
|
|
|
|
|
return false; // no error
|
|
|
|
}
|
|
|
|
|
2011-04-25 12:51:57 +02:00
|
|
|
void CProtocol::CreateChanGainMes ( const int iChanID, const double dGain )
|
|
|
|
{
|
|
|
|
CVector<uint8_t> vecData ( 3 ); // 3 bytes of data
|
|
|
|
int iPos = 0; // init position pointer
|
|
|
|
|
|
|
|
// build data vector
|
|
|
|
// channel ID
|
|
|
|
PutValOnStream ( vecData, iPos, static_cast<uint32_t> ( iChanID ), 1 );
|
|
|
|
|
|
|
|
// actual gain, we convert from double with range 0..1 to integer
|
|
|
|
const int iCurGain = static_cast<int> ( dGain * ( 1 << 15 ) );
|
|
|
|
|
|
|
|
PutValOnStream ( vecData, iPos, static_cast<uint32_t> ( iCurGain ), 2 );
|
|
|
|
|
|
|
|
CreateAndSendMessage ( PROTMESSID_CHANNEL_GAIN, vecData );
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CProtocol::EvaluateChanGainMes ( const CVector<uint8_t>& vecData )
|
|
|
|
{
|
|
|
|
int iPos = 0; // init position pointer
|
|
|
|
|
|
|
|
// check size
|
|
|
|
if ( vecData.Size() != 3 )
|
|
|
|
{
|
|
|
|
return true; // return error code
|
|
|
|
}
|
|
|
|
|
|
|
|
// channel ID
|
2020-05-18 20:46:46 +02:00
|
|
|
const int iCurID = static_cast<int> ( GetValFromStream ( vecData, iPos, 1 ) );
|
2011-04-25 12:51:57 +02:00
|
|
|
|
|
|
|
// gain (read integer value)
|
2020-05-18 20:46:46 +02:00
|
|
|
const int iData = static_cast<int> ( GetValFromStream ( vecData, iPos, 2 ) );
|
2011-04-25 12:51:57 +02:00
|
|
|
|
|
|
|
// we convert the gain from integer to double with range 0..1
|
|
|
|
const double dNewGain = static_cast<double> ( iData ) / ( 1 << 15 );
|
|
|
|
|
|
|
|
// invoke message action
|
|
|
|
emit ChangeChanGain ( iCurID, dNewGain );
|
|
|
|
|
|
|
|
return false; // no error
|
|
|
|
}
|
|
|
|
|
2020-05-18 20:46:46 +02:00
|
|
|
void CProtocol::CreateChanPanMes ( const int iChanID, const double dPan )
|
|
|
|
{
|
|
|
|
CVector<uint8_t> vecData ( 3 ); // 3 bytes of data
|
|
|
|
int iPos = 0; // init position pointer
|
|
|
|
|
|
|
|
// build data vector
|
|
|
|
// channel ID
|
|
|
|
PutValOnStream ( vecData, iPos, static_cast<uint32_t> ( iChanID ), 1 );
|
|
|
|
|
|
|
|
// actual gain, we convert from double with range 0..1 to integer
|
|
|
|
const int iCurPan = static_cast<int> ( dPan * ( 1 << 15 ) );
|
|
|
|
|
|
|
|
PutValOnStream ( vecData, iPos, static_cast<uint32_t> ( iCurPan ), 2 );
|
|
|
|
|
|
|
|
CreateAndSendMessage ( PROTMESSID_CHANNEL_PAN, vecData );
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CProtocol::EvaluateChanPanMes ( const CVector<uint8_t> &vecData )
|
2020-04-26 00:55:28 +02:00
|
|
|
{
|
|
|
|
int iPos = 0; // init position pointer
|
|
|
|
|
|
|
|
// check size
|
|
|
|
if ( vecData.Size() != 3 )
|
|
|
|
{
|
|
|
|
return true; // return error code
|
|
|
|
}
|
|
|
|
|
|
|
|
// channel ID
|
2020-05-18 20:46:46 +02:00
|
|
|
const int iCurID = static_cast<int> ( GetValFromStream ( vecData, iPos, 1 ) );
|
2020-04-26 00:55:28 +02:00
|
|
|
|
|
|
|
// pan (read integer value)
|
2020-05-18 20:46:46 +02:00
|
|
|
const int iData = static_cast<int> ( GetValFromStream ( vecData, iPos, 2 ) );
|
2020-04-26 00:55:28 +02:00
|
|
|
|
|
|
|
// we convert the gain from integer to double with range 0..1
|
|
|
|
const double dNewPan = static_cast<double> ( iData ) / ( 1 << 15 );
|
|
|
|
|
|
|
|
// invoke message action
|
|
|
|
emit ChangeChanPan ( iCurID, dNewPan );
|
|
|
|
|
|
|
|
return false; // no error
|
|
|
|
}
|
|
|
|
|
2020-05-21 11:47:39 +02:00
|
|
|
void CProtocol::CreateMuteStateHasChangedMes ( const int iChanID, const bool bIsMuted )
|
|
|
|
{
|
|
|
|
CVector<uint8_t> vecData ( 2 ); // 2 bytes of data
|
|
|
|
int iPos = 0; // init position pointer
|
|
|
|
|
|
|
|
// build data vector
|
|
|
|
// channel ID
|
|
|
|
PutValOnStream ( vecData, iPos, static_cast<uint32_t> ( iChanID ), 1 );
|
|
|
|
|
|
|
|
// mute state
|
|
|
|
PutValOnStream ( vecData, iPos, static_cast<uint32_t> ( bIsMuted ), 1 );
|
|
|
|
|
|
|
|
CreateAndSendMessage ( PROTMESSID_MUTE_STATE_CHANGED, vecData );
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CProtocol::EvaluateMuteStateHasChangedMes ( const CVector<uint8_t> &vecData )
|
|
|
|
{
|
|
|
|
int iPos = 0; // init position pointer
|
|
|
|
|
|
|
|
// check size
|
|
|
|
if ( vecData.Size() != 2 )
|
|
|
|
{
|
|
|
|
return true; // return error code
|
|
|
|
}
|
|
|
|
|
|
|
|
// channel ID
|
|
|
|
const int iCurID = static_cast<int> ( GetValFromStream ( vecData, iPos, 1 ) );
|
|
|
|
|
|
|
|
// mute state
|
|
|
|
const bool bIsMuted = static_cast<bool> ( GetValFromStream ( vecData, iPos, 1 ) );
|
|
|
|
|
|
|
|
// invoke message action
|
|
|
|
emit MuteStateHasChangedReceived ( iCurID, bIsMuted );
|
|
|
|
|
|
|
|
return false; // no error
|
|
|
|
}
|
|
|
|
|
2013-02-11 16:21:53 +01:00
|
|
|
void CProtocol::CreateConClientListMes ( const CVector<CChannelInfo>& vecChanInfo )
|
2013-02-10 09:50:43 +01:00
|
|
|
{
|
|
|
|
const int iNumClients = vecChanInfo.Size();
|
|
|
|
|
|
|
|
// build data vector
|
|
|
|
CVector<uint8_t> vecData ( 0 );
|
|
|
|
int iPos = 0; // init position pointer
|
|
|
|
|
|
|
|
for ( int i = 0; i < iNumClients; i++ )
|
|
|
|
{
|
2013-02-11 16:21:53 +01:00
|
|
|
// convert strings to utf-8
|
|
|
|
const QByteArray strUTF8Name = vecChanInfo[i].strName.toUtf8();
|
2013-02-10 09:50:43 +01:00
|
|
|
const QByteArray strUTF8City = vecChanInfo[i].strCity.toUtf8();
|
|
|
|
|
|
|
|
// size of current list entry
|
|
|
|
const int iCurListEntrLen =
|
|
|
|
1 /* chan ID */ + 2 /* country */ +
|
|
|
|
4 /* instrument */ + 1 /* skill level */ +
|
2013-02-11 16:21:53 +01:00
|
|
|
4 /* IP address */ +
|
|
|
|
2 /* utf-8 str. size */ + strUTF8Name.size() +
|
2013-02-10 09:50:43 +01:00
|
|
|
2 /* utf-8 str. size */ + strUTF8City.size();
|
|
|
|
|
|
|
|
// make space for new data
|
|
|
|
vecData.Enlarge ( iCurListEntrLen );
|
|
|
|
|
|
|
|
// channel ID (1 byte)
|
|
|
|
PutValOnStream ( vecData, iPos,
|
|
|
|
static_cast<uint32_t> ( vecChanInfo[i].iChanID ), 1 );
|
|
|
|
|
|
|
|
// country (2 bytes)
|
|
|
|
PutValOnStream ( vecData, iPos,
|
|
|
|
static_cast<uint32_t> ( vecChanInfo[i].eCountry ), 2 );
|
|
|
|
|
|
|
|
// instrument (4 bytes)
|
|
|
|
PutValOnStream ( vecData, iPos,
|
|
|
|
static_cast<uint32_t> ( vecChanInfo[i].iInstrument ), 4 );
|
|
|
|
|
|
|
|
// skill level (1 byte)
|
|
|
|
PutValOnStream ( vecData, iPos,
|
2013-02-11 16:21:53 +01:00
|
|
|
static_cast<uint32_t> ( vecChanInfo[i].eSkillLevel ), 1 );
|
|
|
|
|
|
|
|
// IP address (4 bytes)
|
|
|
|
PutValOnStream ( vecData, iPos,
|
|
|
|
static_cast<uint32_t> ( vecChanInfo[i].iIpAddr ), 4 );
|
|
|
|
|
|
|
|
// name
|
|
|
|
PutStringUTF8OnStream ( vecData, iPos, strUTF8Name );
|
2013-02-10 09:50:43 +01:00
|
|
|
|
|
|
|
// city
|
|
|
|
PutStringUTF8OnStream ( vecData, iPos, strUTF8City );
|
|
|
|
}
|
|
|
|
|
2013-02-11 16:21:53 +01:00
|
|
|
CreateAndSendMessage ( PROTMESSID_CONN_CLIENTS_LIST, vecData );
|
2013-02-10 09:50:43 +01:00
|
|
|
}
|
|
|
|
|
2013-02-11 16:21:53 +01:00
|
|
|
bool CProtocol::EvaluateConClientListMes ( const CVector<uint8_t>& vecData )
|
2013-02-10 09:50:43 +01:00
|
|
|
{
|
2013-02-11 16:21:53 +01:00
|
|
|
int iPos = 0; // init position pointer
|
|
|
|
const int iDataLen = vecData.Size();
|
|
|
|
CVector<CChannelInfo> vecChanInfo ( 0 );
|
2013-02-10 09:50:43 +01:00
|
|
|
|
|
|
|
while ( iPos < iDataLen )
|
|
|
|
{
|
2013-02-11 16:21:53 +01:00
|
|
|
// check size (the next 12 bytes)
|
|
|
|
if ( ( iDataLen - iPos ) < 12 )
|
2013-02-10 09:50:43 +01:00
|
|
|
{
|
|
|
|
return true; // return error code
|
|
|
|
}
|
|
|
|
|
|
|
|
// channel ID (1 byte)
|
|
|
|
const int iChanID =
|
|
|
|
static_cast<int> ( GetValFromStream ( vecData, iPos, 1 ) );
|
|
|
|
|
|
|
|
// country (2 bytes)
|
|
|
|
const QLocale::Country eCountry =
|
|
|
|
static_cast<QLocale::Country> ( GetValFromStream ( vecData, iPos, 2 ) );
|
|
|
|
|
|
|
|
// instrument (4 bytes)
|
|
|
|
const int iInstrument =
|
|
|
|
static_cast<int> ( GetValFromStream ( vecData, iPos, 4 ) );
|
|
|
|
|
|
|
|
// skill level (1 byte)
|
2013-02-11 16:21:53 +01:00
|
|
|
const ESkillLevel eSkillLevel =
|
|
|
|
static_cast<ESkillLevel> ( GetValFromStream ( vecData, iPos, 1 ) );
|
|
|
|
|
|
|
|
// IP address (4 bytes)
|
|
|
|
const int iIpAddr =
|
|
|
|
static_cast<int> ( GetValFromStream ( vecData, iPos, 4 ) );
|
|
|
|
|
|
|
|
// name
|
|
|
|
QString strCurName;
|
|
|
|
if ( GetStringFromStream ( vecData,
|
|
|
|
iPos,
|
|
|
|
MAX_LEN_FADER_TAG,
|
|
|
|
strCurName ) )
|
|
|
|
{
|
|
|
|
return true; // return error code
|
|
|
|
}
|
2013-02-10 09:50:43 +01:00
|
|
|
|
|
|
|
// city
|
2013-02-11 16:21:53 +01:00
|
|
|
QString strCurCity;
|
2013-02-10 09:50:43 +01:00
|
|
|
if ( GetStringFromStream ( vecData,
|
|
|
|
iPos,
|
|
|
|
MAX_LEN_SERVER_CITY,
|
2013-02-11 16:21:53 +01:00
|
|
|
strCurCity ) )
|
2013-02-10 09:50:43 +01:00
|
|
|
{
|
|
|
|
return true; // return error code
|
|
|
|
}
|
|
|
|
|
|
|
|
// add channel information to vector
|
2013-02-11 16:21:53 +01:00
|
|
|
vecChanInfo.Add ( CChannelInfo ( iChanID,
|
|
|
|
iIpAddr,
|
|
|
|
strCurName,
|
|
|
|
eCountry,
|
|
|
|
strCurCity,
|
|
|
|
iInstrument,
|
|
|
|
eSkillLevel ) );
|
2013-02-10 09:50:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// check size: all data is read, the position must now be at the end
|
|
|
|
if ( iPos != iDataLen )
|
|
|
|
{
|
|
|
|
return true; // return error code
|
|
|
|
}
|
|
|
|
|
|
|
|
// invoke message action
|
2013-02-11 16:21:53 +01:00
|
|
|
emit ConClientListMesReceived ( vecChanInfo );
|
2013-02-10 09:50:43 +01:00
|
|
|
|
|
|
|
return false; // no error
|
|
|
|
}
|
|
|
|
|
2011-04-25 12:51:57 +02:00
|
|
|
void CProtocol::CreateReqConnClientsList()
|
|
|
|
{
|
|
|
|
CreateAndSendMessage ( PROTMESSID_REQ_CONN_CLIENTS_LIST, CVector<uint8_t> ( 0 ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CProtocol::EvaluateReqConnClientsList()
|
|
|
|
{
|
|
|
|
// invoke message action
|
|
|
|
emit ReqConnClientsList();
|
|
|
|
|
|
|
|
return false; // no error
|
|
|
|
}
|
|
|
|
|
2013-02-11 16:21:53 +01:00
|
|
|
void CProtocol::CreateChanInfoMes ( const CChannelCoreInfo ChanInfo )
|
|
|
|
{
|
|
|
|
int iPos = 0; // init position pointer
|
|
|
|
|
|
|
|
// convert strings to utf-8
|
|
|
|
const QByteArray strUTF8Name = ChanInfo.strName.toUtf8();
|
|
|
|
const QByteArray strUTF8City = ChanInfo.strCity.toUtf8();
|
|
|
|
|
|
|
|
// size of current list entry
|
|
|
|
const int iEntrLen =
|
|
|
|
2 /* country */ +
|
|
|
|
4 /* instrument */ + 1 /* skill level */ +
|
|
|
|
2 /* utf-8 str. size */ + strUTF8Name.size() +
|
|
|
|
2 /* utf-8 str. size */ + strUTF8City.size();
|
|
|
|
|
|
|
|
// build data vector
|
|
|
|
CVector<uint8_t> vecData ( iEntrLen );
|
|
|
|
|
|
|
|
// country (2 bytes)
|
2020-05-26 15:57:03 +02:00
|
|
|
PutValOnStream ( vecData, iPos, static_cast<uint32_t> ( ChanInfo.eCountry ), 2 );
|
2013-02-11 16:21:53 +01:00
|
|
|
|
|
|
|
// instrument (4 bytes)
|
2020-05-26 15:57:03 +02:00
|
|
|
PutValOnStream ( vecData, iPos, static_cast<uint32_t> ( ChanInfo.iInstrument ), 4 );
|
2013-02-11 16:21:53 +01:00
|
|
|
|
|
|
|
// skill level (1 byte)
|
2020-05-26 15:57:03 +02:00
|
|
|
PutValOnStream ( vecData, iPos, static_cast<uint32_t> ( ChanInfo.eSkillLevel ), 1 );
|
2013-02-11 16:21:53 +01:00
|
|
|
|
|
|
|
// name
|
|
|
|
PutStringUTF8OnStream ( vecData, iPos, strUTF8Name );
|
|
|
|
|
|
|
|
// city
|
|
|
|
PutStringUTF8OnStream ( vecData, iPos, strUTF8City );
|
|
|
|
|
|
|
|
CreateAndSendMessage ( PROTMESSID_CHANNEL_INFOS, vecData );
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CProtocol::EvaluateChanInfoMes ( const CVector<uint8_t>& vecData )
|
|
|
|
{
|
|
|
|
int iPos = 0; // init position pointer
|
|
|
|
const int iDataLen = vecData.Size();
|
|
|
|
CChannelCoreInfo ChanInfo;
|
|
|
|
|
|
|
|
// check size (the first 7 bytes)
|
|
|
|
if ( iDataLen < 7 )
|
|
|
|
{
|
|
|
|
return true; // return error code
|
|
|
|
}
|
|
|
|
|
|
|
|
// country (2 bytes)
|
2020-05-26 15:57:03 +02:00
|
|
|
ChanInfo.eCountry = static_cast<QLocale::Country> ( GetValFromStream ( vecData, iPos, 2 ) );
|
2013-02-11 16:21:53 +01:00
|
|
|
|
|
|
|
// instrument (4 bytes)
|
2020-05-26 15:57:03 +02:00
|
|
|
ChanInfo.iInstrument = static_cast<int> ( GetValFromStream ( vecData, iPos, 4 ) );
|
2013-02-11 16:21:53 +01:00
|
|
|
|
|
|
|
// skill level (1 byte)
|
2020-05-26 15:57:03 +02:00
|
|
|
ChanInfo.eSkillLevel = static_cast<ESkillLevel> ( GetValFromStream ( vecData, iPos, 1 ) );
|
2013-02-11 16:21:53 +01:00
|
|
|
|
|
|
|
// name
|
|
|
|
if ( GetStringFromStream ( vecData,
|
|
|
|
iPos,
|
|
|
|
MAX_LEN_FADER_TAG,
|
|
|
|
ChanInfo.strName ) )
|
|
|
|
{
|
|
|
|
return true; // return error code
|
|
|
|
}
|
|
|
|
|
|
|
|
// city
|
|
|
|
if ( GetStringFromStream ( vecData,
|
|
|
|
iPos,
|
|
|
|
MAX_LEN_SERVER_CITY,
|
|
|
|
ChanInfo.strCity ) )
|
|
|
|
{
|
|
|
|
return true; // return error code
|
|
|
|
}
|
|
|
|
|
|
|
|
// check size: all data is read, the position must now be at the end
|
|
|
|
if ( iPos != iDataLen )
|
|
|
|
{
|
|
|
|
return true; // return error code
|
|
|
|
}
|
|
|
|
|
|
|
|
// invoke message action
|
|
|
|
emit ChangeChanInfo ( ChanInfo );
|
|
|
|
|
|
|
|
return false; // no error
|
|
|
|
}
|
|
|
|
|
|
|
|
void CProtocol::CreateReqChanInfoMes()
|
2011-04-25 12:51:57 +02:00
|
|
|
{
|
2013-02-11 16:21:53 +01:00
|
|
|
CreateAndSendMessage ( PROTMESSID_REQ_CHANNEL_INFOS, CVector<uint8_t> ( 0 ) );
|
2011-04-25 12:51:57 +02:00
|
|
|
}
|
|
|
|
|
2013-02-11 16:21:53 +01:00
|
|
|
bool CProtocol::EvaluateReqChanInfoMes()
|
2011-04-25 12:51:57 +02:00
|
|
|
{
|
|
|
|
// invoke message action
|
2013-02-11 16:21:53 +01:00
|
|
|
emit ReqChanInfo();
|
2011-04-25 12:51:57 +02:00
|
|
|
|
|
|
|
return false; // no error
|
|
|
|
}
|
|
|
|
|
|
|
|
void CProtocol::CreateChatTextMes ( const QString strChatText )
|
|
|
|
{
|
2013-01-13 20:56:50 +01:00
|
|
|
int iPos = 0; // init position pointer
|
|
|
|
|
|
|
|
// convert chat text string to utf-8
|
|
|
|
const QByteArray strUTF8ChatText = strChatText.toUtf8();
|
|
|
|
|
|
|
|
const int iStrUTF8Len = strUTF8ChatText.size(); // get utf-8 string size
|
2011-04-25 12:51:57 +02:00
|
|
|
|
|
|
|
// size of message body
|
2013-01-13 20:56:50 +01:00
|
|
|
const int iEntrLen = 2 /* utf-8 string size */ + iStrUTF8Len;
|
2011-04-25 12:51:57 +02:00
|
|
|
|
|
|
|
// build data vector
|
|
|
|
CVector<uint8_t> vecData ( iEntrLen );
|
|
|
|
|
|
|
|
// chat text
|
2013-01-13 20:56:50 +01:00
|
|
|
PutStringUTF8OnStream ( vecData, iPos, strUTF8ChatText );
|
2011-04-25 12:51:57 +02:00
|
|
|
|
|
|
|
CreateAndSendMessage ( PROTMESSID_CHAT_TEXT, vecData );
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CProtocol::EvaluateChatTextMes ( const CVector<uint8_t>& vecData )
|
|
|
|
{
|
|
|
|
int iPos = 0; // init position pointer
|
|
|
|
|
|
|
|
// chat text
|
|
|
|
QString strChatText;
|
|
|
|
if ( GetStringFromStream ( vecData,
|
|
|
|
iPos,
|
|
|
|
MAX_LEN_CHAT_TEXT_PLUS_HTML,
|
|
|
|
strChatText ) )
|
|
|
|
{
|
|
|
|
return true; // return error code
|
|
|
|
}
|
|
|
|
|
|
|
|
// check size: all data is read, the position must now be at the end
|
|
|
|
if ( iPos != vecData.Size() )
|
|
|
|
{
|
|
|
|
return true; // return error code
|
|
|
|
}
|
|
|
|
|
|
|
|
// invoke message action
|
|
|
|
emit ChatTextReceived ( strChatText );
|
|
|
|
|
|
|
|
return false; // no error
|
|
|
|
}
|
|
|
|
|
|
|
|
void CProtocol::CreateNetwTranspPropsMes ( const CNetworkTransportProps& NetTrProps )
|
|
|
|
{
|
|
|
|
int iPos = 0; // init position pointer
|
|
|
|
|
|
|
|
// size of current message body
|
|
|
|
const int iEntrLen =
|
|
|
|
4 /* netw size */ +
|
|
|
|
2 /* block size fact */ +
|
|
|
|
1 /* num chan */ +
|
|
|
|
4 /* sam rate */ +
|
|
|
|
2 /* audiocod type */ +
|
|
|
|
2 /* version */ +
|
|
|
|
4 /* audiocod arg */;
|
|
|
|
|
|
|
|
// build data vector
|
|
|
|
CVector<uint8_t> vecData ( iEntrLen );
|
|
|
|
|
|
|
|
// length of the base network packet (frame) in bytes (4 bytes)
|
2020-05-26 15:57:03 +02:00
|
|
|
PutValOnStream ( vecData, iPos, static_cast<uint32_t> ( NetTrProps.iBaseNetworkPacketSize ), 4 );
|
2011-04-25 12:51:57 +02:00
|
|
|
|
|
|
|
// block size factor (2 bytes)
|
2020-05-26 15:57:03 +02:00
|
|
|
PutValOnStream ( vecData, iPos, static_cast<uint32_t> ( NetTrProps.iBlockSizeFact ), 2 );
|
2011-04-25 12:51:57 +02:00
|
|
|
|
|
|
|
// number of channels of the audio signal, e.g. "2" is stereo (1 byte)
|
2020-05-26 15:57:03 +02:00
|
|
|
PutValOnStream ( vecData, iPos, static_cast<uint32_t> ( NetTrProps.iNumAudioChannels ), 1 );
|
2011-04-25 12:51:57 +02:00
|
|
|
|
|
|
|
// sample rate of the audio stream (4 bytes)
|
2020-05-26 15:57:03 +02:00
|
|
|
PutValOnStream ( vecData, iPos, static_cast<uint32_t> ( NetTrProps.iSampleRate ), 4 );
|
2011-04-25 12:51:57 +02:00
|
|
|
|
|
|
|
// audio coding type (2 bytes)
|
2020-05-26 15:57:03 +02:00
|
|
|
PutValOnStream ( vecData, iPos, static_cast<uint32_t> ( NetTrProps.eAudioCodingType ), 2 );
|
2011-04-25 12:51:57 +02:00
|
|
|
|
|
|
|
// version (2 bytes)
|
2020-05-26 15:57:03 +02:00
|
|
|
PutValOnStream ( vecData, iPos, static_cast<uint32_t> ( NetTrProps.iVersion ), 2 );
|
2011-04-25 12:51:57 +02:00
|
|
|
|
|
|
|
// argument for the audio coder (4 bytes)
|
2020-05-26 15:57:03 +02:00
|
|
|
PutValOnStream ( vecData, iPos, static_cast<uint32_t> ( NetTrProps.iAudioCodingArg ), 4 );
|
2011-04-25 12:51:57 +02:00
|
|
|
|
|
|
|
CreateAndSendMessage ( PROTMESSID_NETW_TRANSPORT_PROPS, vecData );
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CProtocol::EvaluateNetwTranspPropsMes ( const CVector<uint8_t>& vecData )
|
|
|
|
{
|
|
|
|
int iPos = 0; // init position pointer
|
|
|
|
CNetworkTransportProps ReceivedNetwTranspProps;
|
|
|
|
|
|
|
|
// size of current message body
|
|
|
|
const int iEntrLen =
|
|
|
|
4 /* netw size */ +
|
|
|
|
2 /* block size fact */ +
|
|
|
|
1 /* num chan */ +
|
|
|
|
4 /* sam rate */ +
|
|
|
|
2 /* audiocod type */ +
|
|
|
|
2 /* version */ +
|
|
|
|
4 /* audiocod arg */;
|
|
|
|
|
|
|
|
// check size
|
|
|
|
if ( vecData.Size() != iEntrLen )
|
|
|
|
{
|
|
|
|
return true; // return error code
|
|
|
|
}
|
|
|
|
|
|
|
|
// length of the base network packet (frame) in bytes (4 bytes)
|
|
|
|
ReceivedNetwTranspProps.iBaseNetworkPacketSize =
|
|
|
|
static_cast<uint32_t> ( GetValFromStream ( vecData, iPos, 4 ) );
|
|
|
|
|
2013-02-12 16:32:43 +01:00
|
|
|
// at least CELT_MINIMUM_NUM_BYTES bytes are required for the CELC codec
|
|
|
|
if ( ( ReceivedNetwTranspProps.iBaseNetworkPacketSize < CELT_MINIMUM_NUM_BYTES ) ||
|
2011-04-25 12:51:57 +02:00
|
|
|
( ReceivedNetwTranspProps.iBaseNetworkPacketSize > MAX_SIZE_BYTES_NETW_BUF ) )
|
|
|
|
{
|
|
|
|
return true; // return error code
|
|
|
|
}
|
|
|
|
|
|
|
|
// block size factor (2 bytes)
|
|
|
|
ReceivedNetwTranspProps.iBlockSizeFact =
|
|
|
|
static_cast<uint16_t> ( GetValFromStream ( vecData, iPos, 2 ) );
|
|
|
|
|
|
|
|
if ( ( ReceivedNetwTranspProps.iBlockSizeFact != FRAME_SIZE_FACTOR_PREFERRED ) &&
|
|
|
|
( ReceivedNetwTranspProps.iBlockSizeFact != FRAME_SIZE_FACTOR_DEFAULT ) &&
|
|
|
|
( ReceivedNetwTranspProps.iBlockSizeFact != FRAME_SIZE_FACTOR_SAFE ) )
|
|
|
|
{
|
|
|
|
return true; // return error code
|
|
|
|
}
|
|
|
|
|
|
|
|
// number of channels of the audio signal, only mono (1 channel) or
|
|
|
|
// stereo (2 channels) allowed (1 byte)
|
|
|
|
ReceivedNetwTranspProps.iNumAudioChannels =
|
|
|
|
static_cast<uint32_t> ( GetValFromStream ( vecData, iPos, 1 ) );
|
|
|
|
|
|
|
|
if ( ( ReceivedNetwTranspProps.iNumAudioChannels != 1 ) &&
|
|
|
|
( ReceivedNetwTranspProps.iNumAudioChannels != 2 ) )
|
|
|
|
{
|
|
|
|
return true; // return error code
|
|
|
|
}
|
|
|
|
|
|
|
|
// sample rate of the audio stream (4 bytes)
|
|
|
|
ReceivedNetwTranspProps.iSampleRate =
|
|
|
|
static_cast<uint32_t> ( GetValFromStream ( vecData, iPos, 4 ) );
|
|
|
|
|
|
|
|
// audio coding type (2 bytes) with error check
|
|
|
|
const int iRecCodingType =
|
|
|
|
static_cast<int> ( GetValFromStream ( vecData, iPos, 2 ) );
|
|
|
|
|
2014-07-26 07:58:01 +02:00
|
|
|
// note that CT_NONE is not a valid setting but only used for server
|
|
|
|
// initialization
|
|
|
|
if ( ( iRecCodingType != CT_CELT ) &&
|
2020-03-28 16:27:45 +01:00
|
|
|
( iRecCodingType != CT_OPUS ) &&
|
|
|
|
( iRecCodingType != CT_OPUS64 ) )
|
2011-04-25 12:51:57 +02:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
ReceivedNetwTranspProps.eAudioCodingType =
|
|
|
|
static_cast<EAudComprType> ( iRecCodingType );
|
|
|
|
|
|
|
|
// version (2 bytes)
|
|
|
|
ReceivedNetwTranspProps.iVersion =
|
|
|
|
static_cast<uint32_t> ( GetValFromStream ( vecData, iPos, 2 ) );
|
|
|
|
|
|
|
|
// argument for the audio coder (4 bytes)
|
|
|
|
ReceivedNetwTranspProps.iAudioCodingArg =
|
|
|
|
static_cast<int32_t> ( GetValFromStream ( vecData, iPos, 4 ) );
|
|
|
|
|
|
|
|
// invoke message action
|
|
|
|
emit NetTranspPropsReceived ( ReceivedNetwTranspProps );
|
|
|
|
|
|
|
|
return false; // no error
|
|
|
|
}
|
|
|
|
|
|
|
|
void CProtocol::CreateReqNetwTranspPropsMes()
|
|
|
|
{
|
|
|
|
CreateAndSendMessage ( PROTMESSID_REQ_NETW_TRANSPORT_PROPS,
|
|
|
|
CVector<uint8_t> ( 0 ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CProtocol::EvaluateReqNetwTranspPropsMes()
|
|
|
|
{
|
|
|
|
// invoke message action
|
|
|
|
emit ReqNetTranspProps();
|
|
|
|
|
2013-02-16 19:01:51 +01:00
|
|
|
return false; // no error
|
|
|
|
}
|
|
|
|
|
2015-01-18 22:23:47 +01:00
|
|
|
void CProtocol::CreateLicenceRequiredMes ( const ELicenceType eLicenceType )
|
|
|
|
{
|
|
|
|
CVector<uint8_t> vecData ( 1 ); // 1 bytes of data
|
|
|
|
int iPos = 0; // init position pointer
|
|
|
|
|
|
|
|
// build data vector
|
|
|
|
PutValOnStream ( vecData, iPos, static_cast<uint32_t> ( eLicenceType ), 1 );
|
|
|
|
|
|
|
|
CreateAndSendMessage ( PROTMESSID_LICENCE_REQUIRED, vecData );
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CProtocol::EvaluateLicenceRequiredMes ( const CVector<uint8_t>& vecData )
|
|
|
|
{
|
|
|
|
int iPos = 0; // init position pointer
|
|
|
|
|
|
|
|
// check size
|
|
|
|
if ( vecData.Size() != 1 )
|
|
|
|
{
|
|
|
|
return true; // return error code
|
|
|
|
}
|
|
|
|
|
|
|
|
// extract licence type
|
|
|
|
const ELicenceType eLicenceType =
|
|
|
|
static_cast<ELicenceType> ( GetValFromStream ( vecData, iPos, 1 ) );
|
|
|
|
|
2015-01-23 20:43:18 +01:00
|
|
|
if ( ( eLicenceType != LT_CREATIVECOMMONS ) &&
|
|
|
|
( eLicenceType != LT_NO_LICENCE ) )
|
2015-01-18 22:23:47 +01:00
|
|
|
{
|
|
|
|
return true; // return error code
|
|
|
|
}
|
|
|
|
|
|
|
|
// invoke message action
|
|
|
|
emit LicenceRequired ( eLicenceType );
|
|
|
|
|
|
|
|
return false; // no error
|
|
|
|
}
|
|
|
|
|
2020-04-06 17:17:49 +02:00
|
|
|
void CProtocol::CreateOpusSupportedMes()
|
|
|
|
{
|
2020-05-26 15:57:03 +02:00
|
|
|
CreateAndSendMessage ( PROTMESSID_OPUS_SUPPORTED, CVector<uint8_t> ( 0 ) );
|
2020-04-06 17:17:49 +02:00
|
|
|
}
|
|
|
|
|
2020-03-29 19:00:07 +02:00
|
|
|
void CProtocol::CreateReqChannelLevelListMes ( const bool bRCL )
|
|
|
|
{
|
|
|
|
CVector<uint8_t> vecData ( 1 ); // 1 byte of data
|
|
|
|
int iPos = 0; // init position pointer
|
|
|
|
PutValOnStream ( vecData, iPos,
|
|
|
|
static_cast<uint32_t> ( bRCL ), 1 );
|
|
|
|
|
|
|
|
CreateAndSendMessage ( PROTMESSID_REQ_CHANNEL_LEVEL_LIST, vecData );
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CProtocol::EvaluateReqChannelLevelListMes ( const CVector<uint8_t>& vecData )
|
|
|
|
{
|
|
|
|
int iPos = 0; // init position pointer
|
|
|
|
|
|
|
|
// check size
|
|
|
|
if ( vecData.Size() != 1 )
|
|
|
|
{
|
|
|
|
return true; // return error code
|
|
|
|
}
|
|
|
|
|
|
|
|
// extract opt in / out for channel levels
|
|
|
|
uint32_t val = GetValFromStream ( vecData, iPos, 1 );
|
|
|
|
|
|
|
|
if ( val != 0 && val != 1 )
|
|
|
|
{
|
|
|
|
return true; // return error code
|
|
|
|
}
|
|
|
|
|
|
|
|
// invoke message action
|
|
|
|
emit ReqChannelLevelList ( static_cast<bool> ( val ) );
|
|
|
|
|
|
|
|
return false; // no error
|
|
|
|
}
|
|
|
|
|
2020-05-18 19:00:56 +02:00
|
|
|
void CProtocol::CreateVersionAndOSMes()
|
|
|
|
{
|
|
|
|
int iPos = 0; // init position pointer
|
|
|
|
|
|
|
|
// get the version number string
|
|
|
|
const QString strVerion = VERSION;
|
|
|
|
|
|
|
|
// convert version string to utf-8
|
|
|
|
const QByteArray strUTF8Version = strVerion.toUtf8();
|
|
|
|
|
|
|
|
// size of current message body
|
|
|
|
const int iEntrLen =
|
|
|
|
1 /* operating system */ +
|
|
|
|
2 /* version utf-8 string size */ + strUTF8Version.size();
|
|
|
|
|
|
|
|
// build data vector
|
|
|
|
CVector<uint8_t> vecData ( iEntrLen );
|
|
|
|
|
|
|
|
// operating system (1 byte)
|
|
|
|
PutValOnStream ( vecData, iPos,
|
|
|
|
static_cast<uint32_t> ( COSUtil::GetOperatingSystem() ), 1 );
|
|
|
|
|
|
|
|
// version
|
|
|
|
PutStringUTF8OnStream ( vecData, iPos, strUTF8Version );
|
|
|
|
|
|
|
|
CreateAndSendMessage ( PROTMESSID_VERSION_AND_OS, vecData );
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CProtocol::EvaluateVersionAndOSMes ( const CVector<uint8_t>& vecData )
|
|
|
|
{
|
|
|
|
int iPos = 0; // init position pointer
|
|
|
|
const int iDataLen = vecData.Size();
|
|
|
|
|
|
|
|
// check size (the first 1 byte)
|
|
|
|
if ( iDataLen < 1 )
|
|
|
|
{
|
|
|
|
return true; // return error code
|
|
|
|
}
|
|
|
|
|
|
|
|
// operating system (1 byte)
|
|
|
|
const COSUtil::EOpSystemType eOSType =
|
|
|
|
static_cast<COSUtil::EOpSystemType> ( GetValFromStream ( vecData, iPos, 1 ) );
|
|
|
|
|
|
|
|
// version text
|
|
|
|
QString strVersion;
|
|
|
|
if ( GetStringFromStream ( vecData,
|
|
|
|
iPos,
|
|
|
|
MAX_LEN_VERSION_TEXT,
|
|
|
|
strVersion ) )
|
|
|
|
{
|
|
|
|
return true; // return error code
|
|
|
|
}
|
|
|
|
|
|
|
|
// check size: all data is read, the position must now be at the end
|
|
|
|
if ( iPos != iDataLen )
|
|
|
|
{
|
|
|
|
return true; // return error code
|
|
|
|
}
|
|
|
|
|
|
|
|
// invoke message action
|
|
|
|
emit VersionAndOSReceived ( eOSType, strVersion );
|
|
|
|
|
|
|
|
return false; // no error
|
|
|
|
}
|
|
|
|
|
2020-06-14 19:17:12 +02:00
|
|
|
void CProtocol::CreateRecorderStateMes ( const ERecorderState eRecorderState )
|
|
|
|
{
|
|
|
|
CVector<uint8_t> vecData ( 1 ); // 1 byte of data
|
|
|
|
int iPos = 0; // init position pointer
|
|
|
|
|
|
|
|
// build data vector
|
2020-06-14 21:00:19 +02:00
|
|
|
// server jam recorder state (1 byte)
|
2020-06-14 19:17:12 +02:00
|
|
|
PutValOnStream ( vecData, iPos, static_cast<uint32_t> ( eRecorderState ), 1 );
|
|
|
|
|
|
|
|
CreateAndSendMessage ( PROTMESSID_RECORDER_STATE, vecData );
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CProtocol::EvaluateRecorderStateMes(const CVector<uint8_t>& vecData)
|
|
|
|
{
|
|
|
|
int iPos = 0; // init position pointer
|
|
|
|
|
|
|
|
// check size
|
|
|
|
if ( vecData.Size() != 1 )
|
|
|
|
{
|
|
|
|
return true; // return error code
|
|
|
|
}
|
|
|
|
|
2020-06-14 21:00:19 +02:00
|
|
|
// server jam recorder state (1 byte)
|
|
|
|
const int iRecorderState =
|
|
|
|
static_cast<int> ( GetValFromStream ( vecData, iPos, 1 ) );
|
|
|
|
|
2020-06-15 21:48:30 +02:00
|
|
|
// note that RS_UNDEFINED is only internally used
|
|
|
|
if ( ( iRecorderState != RS_NOT_INITIALISED ) &&
|
2020-06-15 17:29:17 +02:00
|
|
|
( iRecorderState != RS_NOT_ENABLED ) &&
|
|
|
|
( iRecorderState != RS_RECORDING ) )
|
2020-06-14 21:00:19 +02:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2020-06-14 19:17:12 +02:00
|
|
|
|
|
|
|
// invoke message action
|
2020-06-14 21:00:19 +02:00
|
|
|
emit RecorderStateReceived ( static_cast<ERecorderState> ( iRecorderState ) );
|
2020-06-14 19:17:12 +02:00
|
|
|
|
|
|
|
return false; // no error
|
|
|
|
}
|
|
|
|
|
2011-04-25 12:51:57 +02:00
|
|
|
|
|
|
|
// Connection less messages ----------------------------------------------------
|
|
|
|
void CProtocol::CreateCLPingMes ( const CHostAddress& InetAddr, const int iMs )
|
|
|
|
{
|
|
|
|
int iPos = 0; // init position pointer
|
|
|
|
|
|
|
|
// build data vector (4 bytes long)
|
|
|
|
CVector<uint8_t> vecData ( 4 );
|
|
|
|
|
|
|
|
// transmit time (4 bytes)
|
|
|
|
PutValOnStream ( vecData, iPos, static_cast<uint32_t> ( iMs ), 4 );
|
|
|
|
|
|
|
|
CreateAndImmSendConLessMessage ( PROTMESSID_CLM_PING_MS,
|
|
|
|
vecData,
|
|
|
|
InetAddr );
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CProtocol::EvaluateCLPingMes ( const CHostAddress& InetAddr,
|
|
|
|
const CVector<uint8_t>& vecData )
|
|
|
|
{
|
|
|
|
int iPos = 0; // init position pointer
|
|
|
|
|
|
|
|
// check size
|
|
|
|
if ( vecData.Size() != 4 )
|
|
|
|
{
|
|
|
|
return true; // return error code
|
|
|
|
}
|
|
|
|
|
|
|
|
// invoke message action
|
|
|
|
emit CLPingReceived ( InetAddr,
|
|
|
|
static_cast<int> ( GetValFromStream ( vecData, iPos, 4 ) ) );
|
|
|
|
|
|
|
|
return false; // no error
|
|
|
|
}
|
|
|
|
|
|
|
|
void CProtocol::CreateCLPingWithNumClientsMes ( const CHostAddress& InetAddr,
|
|
|
|
const int iMs,
|
|
|
|
const int iNumClients )
|
|
|
|
{
|
|
|
|
int iPos = 0; // init position pointer
|
|
|
|
|
|
|
|
// build data vector (5 bytes long)
|
|
|
|
CVector<uint8_t> vecData ( 5 );
|
|
|
|
|
|
|
|
// transmit time (4 bytes)
|
|
|
|
PutValOnStream ( vecData, iPos, static_cast<uint32_t> ( iMs ), 4 );
|
|
|
|
|
|
|
|
// current number of connected clients (1 byte)
|
|
|
|
PutValOnStream ( vecData, iPos, static_cast<uint32_t> ( iNumClients ), 1 );
|
|
|
|
|
|
|
|
CreateAndImmSendConLessMessage ( PROTMESSID_CLM_PING_MS_WITHNUMCLIENTS,
|
|
|
|
vecData,
|
|
|
|
InetAddr );
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CProtocol::EvaluateCLPingWithNumClientsMes ( const CHostAddress& InetAddr,
|
|
|
|
const CVector<uint8_t>& vecData )
|
|
|
|
{
|
|
|
|
int iPos = 0; // init position pointer
|
|
|
|
|
|
|
|
// check size
|
|
|
|
if ( vecData.Size() != 5 )
|
|
|
|
{
|
|
|
|
return true; // return error code
|
|
|
|
}
|
|
|
|
|
|
|
|
// transmit time
|
2020-05-26 15:57:03 +02:00
|
|
|
const int iCurMs = static_cast<int> ( GetValFromStream ( vecData, iPos, 4 ) );
|
2011-04-25 12:51:57 +02:00
|
|
|
|
|
|
|
// current number of connected clients
|
2020-05-26 15:57:03 +02:00
|
|
|
const int iCurNumClients = static_cast<int> ( GetValFromStream ( vecData, iPos, 1 ) );
|
2011-04-25 12:51:57 +02:00
|
|
|
|
|
|
|
// invoke message action
|
|
|
|
emit CLPingWithNumClientsReceived ( InetAddr, iCurMs, iCurNumClients );
|
|
|
|
|
|
|
|
return false; // no error
|
|
|
|
}
|
|
|
|
|
|
|
|
void CProtocol::CreateCLServerFullMes ( const CHostAddress& InetAddr )
|
|
|
|
{
|
|
|
|
CreateAndImmSendConLessMessage ( PROTMESSID_CLM_SERVER_FULL,
|
|
|
|
CVector<uint8_t> ( 0 ),
|
|
|
|
InetAddr );
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CProtocol::EvaluateCLServerFullMes()
|
|
|
|
{
|
|
|
|
// invoke message action
|
|
|
|
emit ServerFullMesReceived();
|
|
|
|
|
|
|
|
return false; // no error
|
|
|
|
}
|
|
|
|
|
|
|
|
void CProtocol::CreateCLRegisterServerMes ( const CHostAddress& InetAddr,
|
2020-04-09 20:06:34 +02:00
|
|
|
const CHostAddress& LInetAddr,
|
2011-04-25 12:51:57 +02:00
|
|
|
const CServerCoreInfo& ServerInfo )
|
|
|
|
{
|
|
|
|
int iPos = 0; // init position pointer
|
|
|
|
|
2013-01-13 20:56:50 +01:00
|
|
|
// convert server info strings to utf-8
|
2020-04-09 20:06:34 +02:00
|
|
|
const QByteArray strUTF8LInetAddr = LInetAddr.InetAddr.toString().toUtf8();
|
|
|
|
const QByteArray strUTF8Name = ServerInfo.strName.toUtf8();
|
|
|
|
const QByteArray strUTF8City = ServerInfo.strCity.toUtf8();
|
2013-01-13 20:56:50 +01:00
|
|
|
|
2011-04-25 12:51:57 +02:00
|
|
|
// size of current message body
|
|
|
|
const int iEntrLen =
|
2020-04-12 14:26:21 +02:00
|
|
|
2 /* server internal port number */ +
|
2011-04-25 12:51:57 +02:00
|
|
|
2 /* country */ +
|
|
|
|
1 /* maximum number of connected clients */ +
|
|
|
|
1 /* is permanent flag */ +
|
2013-01-13 20:56:50 +01:00
|
|
|
2 /* name utf-8 string size */ + strUTF8Name.size() +
|
2020-04-09 20:06:34 +02:00
|
|
|
2 /* server internal address utf-8 string size */ + strUTF8LInetAddr.size() +
|
2013-01-13 20:56:50 +01:00
|
|
|
2 /* city utf-8 string size */ + strUTF8City.size();
|
2011-04-25 12:51:57 +02:00
|
|
|
|
|
|
|
// build data vector
|
|
|
|
CVector<uint8_t> vecData ( iEntrLen );
|
|
|
|
|
2011-05-04 20:18:31 +02:00
|
|
|
// port number (2 bytes)
|
2020-05-26 15:57:03 +02:00
|
|
|
PutValOnStream ( vecData, iPos, static_cast<uint32_t> ( LInetAddr.iPort ), 2 );
|
2011-05-04 20:18:31 +02:00
|
|
|
|
2011-04-25 12:51:57 +02:00
|
|
|
// country (2 bytes)
|
2020-05-26 15:57:03 +02:00
|
|
|
PutValOnStream ( vecData, iPos, static_cast<uint32_t> ( ServerInfo.eCountry ), 2 );
|
2011-04-25 12:51:57 +02:00
|
|
|
|
|
|
|
// maximum number of connected clients (1 byte)
|
2020-05-26 15:57:03 +02:00
|
|
|
PutValOnStream ( vecData, iPos, static_cast<uint32_t> ( ServerInfo.iMaxNumClients ), 1 );
|
2011-04-25 12:51:57 +02:00
|
|
|
|
|
|
|
// "is permanent" flag (1 byte)
|
2020-05-26 15:57:03 +02:00
|
|
|
PutValOnStream ( vecData, iPos, static_cast<uint32_t> ( ServerInfo.bPermanentOnline ), 1 );
|
2011-04-25 12:51:57 +02:00
|
|
|
|
|
|
|
// name
|
2013-01-13 20:56:50 +01:00
|
|
|
PutStringUTF8OnStream ( vecData, iPos, strUTF8Name );
|
2011-04-25 12:51:57 +02:00
|
|
|
|
2020-04-09 20:06:34 +02:00
|
|
|
// server internal address (formerly unused topic)
|
|
|
|
PutStringUTF8OnStream ( vecData, iPos, strUTF8LInetAddr );
|
2011-04-25 12:51:57 +02:00
|
|
|
|
|
|
|
// city
|
2013-01-13 20:56:50 +01:00
|
|
|
PutStringUTF8OnStream ( vecData, iPos, strUTF8City );
|
2011-04-25 12:51:57 +02:00
|
|
|
|
|
|
|
CreateAndImmSendConLessMessage ( PROTMESSID_CLM_REGISTER_SERVER,
|
|
|
|
vecData,
|
|
|
|
InetAddr );
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CProtocol::EvaluateCLRegisterServerMes ( const CHostAddress& InetAddr,
|
|
|
|
const CVector<uint8_t>& vecData )
|
|
|
|
{
|
|
|
|
int iPos = 0; // init position pointer
|
|
|
|
const int iDataLen = vecData.Size();
|
2020-04-09 20:06:34 +02:00
|
|
|
QString sLocHost; // temp string for server internal address
|
|
|
|
CHostAddress LInetAddr;
|
2011-04-25 12:51:57 +02:00
|
|
|
CServerCoreInfo RecServerInfo;
|
|
|
|
|
2011-05-04 20:18:31 +02:00
|
|
|
// check size (the first 6 bytes)
|
|
|
|
if ( iDataLen < 6 )
|
2011-04-25 12:51:57 +02:00
|
|
|
{
|
|
|
|
return true; // return error code
|
|
|
|
}
|
|
|
|
|
2011-05-04 20:18:31 +02:00
|
|
|
// port number (2 bytes)
|
2020-05-26 15:57:03 +02:00
|
|
|
LInetAddr.iPort = static_cast<quint16> ( GetValFromStream ( vecData, iPos, 2 ) );
|
2011-05-04 20:18:31 +02:00
|
|
|
|
2011-04-25 12:51:57 +02:00
|
|
|
// country (2 bytes)
|
2020-05-26 15:57:03 +02:00
|
|
|
RecServerInfo.eCountry = static_cast<QLocale::Country> ( GetValFromStream ( vecData, iPos, 2 ) );
|
2011-04-25 12:51:57 +02:00
|
|
|
|
|
|
|
// maximum number of connected clients (1 byte)
|
2020-05-26 15:57:03 +02:00
|
|
|
RecServerInfo.iMaxNumClients = static_cast<int> ( GetValFromStream ( vecData, iPos, 1 ) );
|
2011-04-25 12:51:57 +02:00
|
|
|
|
|
|
|
// "is permanent" flag (1 byte)
|
2020-05-26 15:57:03 +02:00
|
|
|
RecServerInfo.bPermanentOnline = static_cast<bool> ( GetValFromStream ( vecData, iPos, 1 ) );
|
2011-04-25 12:51:57 +02:00
|
|
|
|
|
|
|
// server name
|
|
|
|
if ( GetStringFromStream ( vecData,
|
|
|
|
iPos,
|
|
|
|
MAX_LEN_SERVER_NAME,
|
|
|
|
RecServerInfo.strName ) )
|
|
|
|
{
|
|
|
|
return true; // return error code
|
|
|
|
}
|
|
|
|
|
2020-04-09 20:06:34 +02:00
|
|
|
// server internal address
|
2011-04-25 12:51:57 +02:00
|
|
|
if ( GetStringFromStream ( vecData,
|
|
|
|
iPos,
|
2020-04-09 20:06:34 +02:00
|
|
|
MAX_LEN_IP_ADDRESS,
|
|
|
|
sLocHost ) )
|
|
|
|
{
|
|
|
|
return true; // return error code
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( sLocHost.isEmpty() )
|
|
|
|
{
|
2020-04-11 19:52:53 +02:00
|
|
|
// old server, empty "topic", register as local host
|
|
|
|
LInetAddr.InetAddr.setAddress ( QHostAddress::LocalHost );
|
2020-04-09 20:06:34 +02:00
|
|
|
}
|
2020-04-11 19:52:53 +02:00
|
|
|
else if ( !LInetAddr.InetAddr.setAddress ( sLocHost ) )
|
2011-04-25 12:51:57 +02:00
|
|
|
{
|
|
|
|
return true; // return error code
|
|
|
|
}
|
|
|
|
|
|
|
|
// server city
|
|
|
|
if ( GetStringFromStream ( vecData,
|
|
|
|
iPos,
|
|
|
|
MAX_LEN_SERVER_CITY,
|
|
|
|
RecServerInfo.strCity ) )
|
|
|
|
{
|
|
|
|
return true; // return error code
|
|
|
|
}
|
|
|
|
|
|
|
|
// check size: all data is read, the position must now be at the end
|
|
|
|
if ( iPos != iDataLen )
|
|
|
|
{
|
|
|
|
return true; // return error code
|
|
|
|
}
|
|
|
|
|
|
|
|
// invoke message action
|
2020-04-09 20:06:34 +02:00
|
|
|
emit CLRegisterServerReceived ( InetAddr, LInetAddr, RecServerInfo );
|
2011-04-25 12:51:57 +02:00
|
|
|
|
|
|
|
return false; // no error
|
|
|
|
}
|
|
|
|
|
2011-05-03 22:37:06 +02:00
|
|
|
void CProtocol::CreateCLUnregisterServerMes ( const CHostAddress& InetAddr )
|
|
|
|
{
|
|
|
|
CreateAndImmSendConLessMessage ( PROTMESSID_CLM_UNREGISTER_SERVER,
|
|
|
|
CVector<uint8_t> ( 0 ),
|
|
|
|
InetAddr );
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CProtocol::EvaluateCLUnregisterServerMes ( const CHostAddress& InetAddr )
|
|
|
|
{
|
|
|
|
// invoke message action
|
|
|
|
emit CLUnregisterServerReceived ( InetAddr );
|
|
|
|
|
|
|
|
return false; // no error
|
|
|
|
}
|
2011-04-25 12:51:57 +02:00
|
|
|
|
|
|
|
void CProtocol::CreateCLServerListMes ( const CHostAddress& InetAddr,
|
|
|
|
const CVector<CServerInfo> vecServerInfo )
|
|
|
|
{
|
|
|
|
const int iNumServers = vecServerInfo.Size();
|
|
|
|
|
|
|
|
// build data vector
|
|
|
|
CVector<uint8_t> vecData ( 0 );
|
|
|
|
int iPos = 0; // init position pointer
|
|
|
|
|
|
|
|
for ( int i = 0; i < iNumServers; i++ )
|
|
|
|
{
|
2013-01-13 20:56:50 +01:00
|
|
|
// convert server list strings to utf-8
|
2020-04-12 14:26:21 +02:00
|
|
|
const QByteArray strUTF8Name = vecServerInfo[i].strName.toUtf8();
|
2020-04-12 16:03:38 +02:00
|
|
|
const QByteArray strUTF8Empty = QString ( "" ).toUtf8();
|
2020-04-12 14:26:21 +02:00
|
|
|
const QByteArray strUTF8City = vecServerInfo[i].strCity.toUtf8();
|
2013-01-13 20:56:50 +01:00
|
|
|
|
2011-04-25 12:51:57 +02:00
|
|
|
// size of current list entry
|
|
|
|
const int iCurListEntrLen =
|
|
|
|
4 /* IP address */ +
|
|
|
|
2 /* port number */ +
|
|
|
|
2 /* country */ +
|
|
|
|
1 /* maximum number of connected clients */ +
|
|
|
|
1 /* is permanent flag */ +
|
2013-01-13 20:56:50 +01:00
|
|
|
2 /* name utf-8 string size */ + strUTF8Name.size() +
|
2020-04-12 14:26:21 +02:00
|
|
|
2 /* empty string */ +
|
2013-01-13 20:56:50 +01:00
|
|
|
2 /* city utf-8 string size */ + strUTF8City.size();
|
2011-04-25 12:51:57 +02:00
|
|
|
|
|
|
|
// make space for new data
|
|
|
|
vecData.Enlarge ( iCurListEntrLen );
|
|
|
|
|
|
|
|
// IP address (4 bytes)
|
2020-04-12 14:26:21 +02:00
|
|
|
// note the Server List manager has put the internal details in HostAddr where required
|
2011-04-25 12:51:57 +02:00
|
|
|
PutValOnStream ( vecData, iPos, static_cast<uint32_t> (
|
|
|
|
vecServerInfo[i].HostAddr.InetAddr.toIPv4Address() ), 4 );
|
|
|
|
|
|
|
|
// port number (2 bytes)
|
2020-04-12 14:26:21 +02:00
|
|
|
// note the Server List manager has put the internal details in HostAddr where required
|
2011-04-25 12:51:57 +02:00
|
|
|
PutValOnStream ( vecData, iPos,
|
|
|
|
static_cast<uint32_t> ( vecServerInfo[i].HostAddr.iPort ), 2 );
|
|
|
|
|
|
|
|
// country (2 bytes)
|
|
|
|
PutValOnStream ( vecData, iPos,
|
|
|
|
static_cast<uint32_t> ( vecServerInfo[i].eCountry ), 2 );
|
|
|
|
|
|
|
|
// maximum number of connected clients (1 byte)
|
|
|
|
PutValOnStream ( vecData, iPos,
|
|
|
|
static_cast<uint32_t> ( vecServerInfo[i].iMaxNumClients ), 1 );
|
|
|
|
|
|
|
|
// "is permanent" flag (1 byte)
|
|
|
|
PutValOnStream ( vecData, iPos,
|
|
|
|
static_cast<uint32_t> ( vecServerInfo[i].bPermanentOnline ), 1 );
|
|
|
|
|
|
|
|
// name
|
2013-01-13 20:56:50 +01:00
|
|
|
PutStringUTF8OnStream ( vecData, iPos, strUTF8Name );
|
2011-04-25 12:51:57 +02:00
|
|
|
|
2020-04-12 14:26:21 +02:00
|
|
|
// empty string
|
|
|
|
PutStringUTF8OnStream ( vecData, iPos, strUTF8Empty );
|
2011-04-25 12:51:57 +02:00
|
|
|
|
|
|
|
// city
|
2013-01-13 20:56:50 +01:00
|
|
|
PutStringUTF8OnStream ( vecData, iPos, strUTF8City );
|
2011-04-25 12:51:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CreateAndImmSendConLessMessage ( PROTMESSID_CLM_SERVER_LIST,
|
|
|
|
vecData,
|
|
|
|
InetAddr );
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CProtocol::EvaluateCLServerListMes ( const CHostAddress& InetAddr,
|
|
|
|
const CVector<uint8_t>& vecData )
|
|
|
|
{
|
|
|
|
int iPos = 0; // init position pointer
|
|
|
|
const int iDataLen = vecData.Size();
|
|
|
|
CVector<CServerInfo> vecServerInfo ( 0 );
|
|
|
|
|
|
|
|
while ( iPos < iDataLen )
|
|
|
|
{
|
|
|
|
// check size (the next 10 bytes)
|
|
|
|
if ( ( iDataLen - iPos ) < 10 )
|
|
|
|
{
|
|
|
|
return true; // return error code
|
|
|
|
}
|
|
|
|
|
|
|
|
// IP address (4 bytes)
|
2020-05-26 15:57:03 +02:00
|
|
|
const quint32 iIpAddr = static_cast<quint32> ( GetValFromStream ( vecData, iPos, 4 ) );
|
2011-04-25 12:51:57 +02:00
|
|
|
|
|
|
|
// port number (2 bytes)
|
2020-05-26 15:57:03 +02:00
|
|
|
const quint16 iPort = static_cast<quint16> ( GetValFromStream ( vecData, iPos, 2 ) );
|
2011-04-25 12:51:57 +02:00
|
|
|
|
|
|
|
// country (2 bytes)
|
2020-05-26 15:57:03 +02:00
|
|
|
const QLocale::Country eCountry = static_cast<QLocale::Country> ( GetValFromStream ( vecData, iPos, 2 ) );
|
2011-04-25 12:51:57 +02:00
|
|
|
|
|
|
|
// maximum number of connected clients (1 byte)
|
2020-05-26 15:57:03 +02:00
|
|
|
const int iMaxNumClients = static_cast<int> ( GetValFromStream ( vecData, iPos, 1 ) );
|
2011-04-25 12:51:57 +02:00
|
|
|
|
|
|
|
// "is permanent" flag (1 byte)
|
2020-05-26 15:57:03 +02:00
|
|
|
const bool bPermanentOnline = static_cast<bool> ( GetValFromStream ( vecData, iPos, 1 ) );
|
2011-04-25 12:51:57 +02:00
|
|
|
|
|
|
|
// server name
|
|
|
|
QString strName;
|
|
|
|
if ( GetStringFromStream ( vecData,
|
|
|
|
iPos,
|
|
|
|
MAX_LEN_SERVER_NAME,
|
|
|
|
strName ) )
|
|
|
|
{
|
|
|
|
return true; // return error code
|
|
|
|
}
|
|
|
|
|
2020-04-12 14:26:21 +02:00
|
|
|
// empty
|
|
|
|
QString strEmpty;
|
2011-04-25 12:51:57 +02:00
|
|
|
if ( GetStringFromStream ( vecData,
|
|
|
|
iPos,
|
2020-04-09 20:06:34 +02:00
|
|
|
MAX_LEN_IP_ADDRESS,
|
2020-04-12 14:26:21 +02:00
|
|
|
strEmpty ) )
|
2011-04-25 12:51:57 +02:00
|
|
|
{
|
|
|
|
return true; // return error code
|
|
|
|
}
|
|
|
|
|
|
|
|
// server city
|
|
|
|
QString strCity;
|
|
|
|
if ( GetStringFromStream ( vecData,
|
|
|
|
iPos,
|
|
|
|
MAX_LEN_SERVER_CITY,
|
|
|
|
strCity ) )
|
|
|
|
{
|
|
|
|
return true; // return error code
|
|
|
|
}
|
|
|
|
|
|
|
|
// add server information to vector
|
|
|
|
vecServerInfo.Add (
|
|
|
|
CServerInfo ( CHostAddress ( QHostAddress ( iIpAddr ), iPort ),
|
2020-04-12 14:26:21 +02:00
|
|
|
CHostAddress ( QHostAddress ( iIpAddr ), iPort ),
|
2011-04-25 12:51:57 +02:00
|
|
|
strName,
|
|
|
|
eCountry,
|
|
|
|
strCity,
|
|
|
|
iMaxNumClients,
|
|
|
|
bPermanentOnline ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
// check size: all data is read, the position must now be at the end
|
|
|
|
if ( iPos != iDataLen )
|
|
|
|
{
|
|
|
|
return true; // return error code
|
|
|
|
}
|
|
|
|
|
|
|
|
// invoke message action
|
|
|
|
emit CLServerListReceived ( InetAddr, vecServerInfo );
|
|
|
|
|
|
|
|
return false; // no error
|
|
|
|
}
|
|
|
|
|
|
|
|
void CProtocol::CreateCLReqServerListMes ( const CHostAddress& InetAddr )
|
|
|
|
{
|
|
|
|
CreateAndImmSendConLessMessage ( PROTMESSID_CLM_REQ_SERVER_LIST,
|
|
|
|
CVector<uint8_t> ( 0 ),
|
|
|
|
InetAddr );
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CProtocol::EvaluateCLReqServerListMes ( const CHostAddress& InetAddr )
|
|
|
|
{
|
|
|
|
// invoke message action
|
|
|
|
emit CLReqServerList ( InetAddr );
|
|
|
|
|
|
|
|
return false; // no error
|
|
|
|
}
|
|
|
|
|
|
|
|
void CProtocol::CreateCLSendEmptyMesMes ( const CHostAddress& InetAddr,
|
|
|
|
const CHostAddress& TargetInetAddr )
|
|
|
|
{
|
|
|
|
int iPos = 0; // init position pointer
|
|
|
|
|
|
|
|
// build data vector (6 bytes long)
|
|
|
|
CVector<uint8_t> vecData ( 6 );
|
|
|
|
|
|
|
|
// IP address (4 bytes)
|
|
|
|
PutValOnStream ( vecData, iPos, static_cast<uint32_t> (
|
|
|
|
TargetInetAddr.InetAddr.toIPv4Address() ), 4 );
|
|
|
|
|
|
|
|
// port number (2 bytes)
|
|
|
|
PutValOnStream ( vecData, iPos,
|
|
|
|
static_cast<uint32_t> ( TargetInetAddr.iPort ), 2 );
|
|
|
|
|
|
|
|
CreateAndImmSendConLessMessage ( PROTMESSID_CLM_SEND_EMPTY_MESSAGE,
|
|
|
|
vecData,
|
|
|
|
InetAddr );
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CProtocol::EvaluateCLSendEmptyMesMes ( const CVector<uint8_t>& vecData )
|
|
|
|
{
|
|
|
|
int iPos = 0; // init position pointer
|
|
|
|
|
|
|
|
// check size
|
|
|
|
if ( vecData.Size() != 6 )
|
|
|
|
{
|
|
|
|
return true; // return error code
|
|
|
|
}
|
|
|
|
|
|
|
|
// IP address (4 bytes)
|
2020-05-26 15:57:03 +02:00
|
|
|
const quint32 iIpAddr = static_cast<int> ( GetValFromStream ( vecData, iPos, 4 ) );
|
2011-04-25 12:51:57 +02:00
|
|
|
|
|
|
|
// port number (2 bytes)
|
2020-05-26 15:57:03 +02:00
|
|
|
const quint16 iPort = static_cast<int> ( GetValFromStream ( vecData, iPos, 2 ) );
|
2011-04-25 12:51:57 +02:00
|
|
|
|
|
|
|
// invoke message action
|
|
|
|
emit CLSendEmptyMes ( CHostAddress ( QHostAddress ( iIpAddr ), iPort ) );
|
|
|
|
|
|
|
|
return false; // no error
|
|
|
|
}
|
|
|
|
|
|
|
|
void CProtocol::CreateCLEmptyMes ( const CHostAddress& InetAddr )
|
|
|
|
{
|
2011-05-22 11:47:09 +02:00
|
|
|
// special message: for this message there exist no Evaluate
|
|
|
|
// function
|
2011-04-25 12:51:57 +02:00
|
|
|
CreateAndImmSendConLessMessage ( PROTMESSID_CLM_EMPTY_MESSAGE,
|
|
|
|
CVector<uint8_t> ( 0 ),
|
|
|
|
InetAddr );
|
|
|
|
}
|
|
|
|
|
2011-05-22 11:47:09 +02:00
|
|
|
void CProtocol::CreateCLDisconnection ( const CHostAddress& InetAddr )
|
|
|
|
{
|
|
|
|
CreateAndImmSendConLessMessage ( PROTMESSID_CLM_DISCONNECTION,
|
|
|
|
CVector<uint8_t> ( 0 ),
|
|
|
|
InetAddr );
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CProtocol::EvaluateCLDisconnectionMes ( const CHostAddress& InetAddr )
|
|
|
|
{
|
|
|
|
// invoke message action
|
|
|
|
emit CLDisconnection ( InetAddr );
|
|
|
|
|
|
|
|
return false; // no error
|
|
|
|
}
|
|
|
|
|
2014-02-21 22:25:26 +01:00
|
|
|
void CProtocol::CreateCLVersionAndOSMes ( const CHostAddress& InetAddr )
|
|
|
|
{
|
|
|
|
int iPos = 0; // init position pointer
|
|
|
|
|
|
|
|
// get the version number string
|
|
|
|
const QString strVerion = VERSION;
|
|
|
|
|
|
|
|
// convert version string to utf-8
|
|
|
|
const QByteArray strUTF8Version = strVerion.toUtf8();
|
|
|
|
|
|
|
|
// size of current message body
|
|
|
|
const int iEntrLen =
|
|
|
|
1 /* operating system */ +
|
|
|
|
2 /* version utf-8 string size */ + strUTF8Version.size();
|
|
|
|
|
|
|
|
// build data vector
|
|
|
|
CVector<uint8_t> vecData ( iEntrLen );
|
|
|
|
|
|
|
|
// operating system (1 byte)
|
|
|
|
PutValOnStream ( vecData, iPos,
|
|
|
|
static_cast<uint32_t> ( COSUtil::GetOperatingSystem() ), 1 );
|
|
|
|
|
|
|
|
// version
|
|
|
|
PutStringUTF8OnStream ( vecData, iPos, strUTF8Version );
|
|
|
|
|
|
|
|
CreateAndImmSendConLessMessage ( PROTMESSID_CLM_VERSION_AND_OS,
|
|
|
|
vecData,
|
|
|
|
InetAddr );
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CProtocol::EvaluateCLVersionAndOSMes ( const CHostAddress& InetAddr,
|
|
|
|
const CVector<uint8_t>& vecData )
|
|
|
|
{
|
|
|
|
int iPos = 0; // init position pointer
|
|
|
|
const int iDataLen = vecData.Size();
|
|
|
|
|
|
|
|
// check size (the first 1 byte)
|
|
|
|
if ( iDataLen < 1 )
|
|
|
|
{
|
|
|
|
return true; // return error code
|
|
|
|
}
|
|
|
|
|
|
|
|
// operating system (1 byte)
|
|
|
|
const COSUtil::EOpSystemType eOSType =
|
|
|
|
static_cast<COSUtil::EOpSystemType> ( GetValFromStream ( vecData, iPos, 1 ) );
|
|
|
|
|
|
|
|
// version text
|
|
|
|
QString strVersion;
|
|
|
|
if ( GetStringFromStream ( vecData,
|
|
|
|
iPos,
|
|
|
|
MAX_LEN_VERSION_TEXT,
|
|
|
|
strVersion ) )
|
|
|
|
{
|
|
|
|
return true; // return error code
|
|
|
|
}
|
|
|
|
|
|
|
|
// check size: all data is read, the position must now be at the end
|
|
|
|
if ( iPos != iDataLen )
|
|
|
|
{
|
|
|
|
return true; // return error code
|
|
|
|
}
|
|
|
|
|
|
|
|
// invoke message action
|
|
|
|
emit CLVersionAndOSReceived ( InetAddr, eOSType, strVersion );
|
|
|
|
|
|
|
|
return false; // no error
|
|
|
|
}
|
|
|
|
|
|
|
|
void CProtocol::CreateCLReqVersionAndOSMes ( const CHostAddress& InetAddr )
|
|
|
|
{
|
|
|
|
CreateAndImmSendConLessMessage ( PROTMESSID_CLM_REQ_VERSION_AND_OS,
|
|
|
|
CVector<uint8_t> ( 0 ),
|
|
|
|
InetAddr );
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CProtocol::EvaluateCLReqVersionAndOSMes ( const CHostAddress& InetAddr )
|
|
|
|
{
|
|
|
|
// invoke message action
|
|
|
|
emit CLReqVersionAndOS ( InetAddr );
|
|
|
|
|
|
|
|
return false; // no error
|
|
|
|
}
|
|
|
|
|
2015-12-06 18:51:06 +01:00
|
|
|
void CProtocol::CreateCLConnClientsListMes ( const CHostAddress& InetAddr,
|
|
|
|
const CVector<CChannelInfo>& vecChanInfo )
|
|
|
|
{
|
|
|
|
const int iNumClients = vecChanInfo.Size();
|
|
|
|
|
|
|
|
// build data vector
|
2015-12-09 16:50:30 +01:00
|
|
|
CVector<uint8_t> vecData ( 0 );
|
2015-12-06 18:51:06 +01:00
|
|
|
int iPos = 0; // init position pointer
|
|
|
|
|
|
|
|
for ( int i = 0; i < iNumClients; i++ )
|
|
|
|
{
|
|
|
|
// convert strings to utf-8
|
|
|
|
const QByteArray strUTF8Name = vecChanInfo[i].strName.toUtf8();
|
|
|
|
const QByteArray strUTF8City = vecChanInfo[i].strCity.toUtf8();
|
|
|
|
|
|
|
|
// size of current list entry
|
|
|
|
const int iCurListEntrLen =
|
|
|
|
1 /* chan ID */ + 2 /* country */ +
|
|
|
|
4 /* instrument */ + 1 /* skill level */ +
|
|
|
|
4 /* IP address */ +
|
|
|
|
2 /* utf-8 str. size */ + strUTF8Name.size() +
|
|
|
|
2 /* utf-8 str. size */ + strUTF8City.size();
|
|
|
|
|
|
|
|
// make space for new data
|
|
|
|
vecData.Enlarge ( iCurListEntrLen );
|
|
|
|
|
|
|
|
// channel ID (1 byte)
|
2020-05-26 15:57:03 +02:00
|
|
|
PutValOnStream ( vecData, iPos, static_cast<uint32_t> ( vecChanInfo[i].iChanID ), 1 );
|
2015-12-06 18:51:06 +01:00
|
|
|
|
|
|
|
// country (2 bytes)
|
2020-05-26 15:57:03 +02:00
|
|
|
PutValOnStream ( vecData, iPos, static_cast<uint32_t> ( vecChanInfo[i].eCountry ), 2 );
|
2015-12-06 18:51:06 +01:00
|
|
|
|
|
|
|
// instrument (4 bytes)
|
2020-05-26 15:57:03 +02:00
|
|
|
PutValOnStream ( vecData, iPos, static_cast<uint32_t> ( vecChanInfo[i].iInstrument ), 4 );
|
2015-12-06 18:51:06 +01:00
|
|
|
|
|
|
|
// skill level (1 byte)
|
2020-05-26 15:57:03 +02:00
|
|
|
PutValOnStream ( vecData, iPos, static_cast<uint32_t> ( vecChanInfo[i].eSkillLevel ), 1 );
|
2015-12-06 18:51:06 +01:00
|
|
|
|
|
|
|
// IP address (4 bytes)
|
2020-05-26 15:57:03 +02:00
|
|
|
PutValOnStream ( vecData, iPos, static_cast<uint32_t> ( vecChanInfo[i].iIpAddr ), 4 );
|
2015-12-06 18:51:06 +01:00
|
|
|
|
|
|
|
// name
|
|
|
|
PutStringUTF8OnStream ( vecData, iPos, strUTF8Name );
|
|
|
|
|
|
|
|
// city
|
|
|
|
PutStringUTF8OnStream ( vecData, iPos, strUTF8City );
|
|
|
|
}
|
|
|
|
|
|
|
|
CreateAndImmSendConLessMessage ( PROTMESSID_CLM_CONN_CLIENTS_LIST,
|
|
|
|
vecData,
|
|
|
|
InetAddr );
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CProtocol::EvaluateCLConnClientsListMes ( const CHostAddress& InetAddr,
|
|
|
|
const CVector<uint8_t>& vecData )
|
|
|
|
{
|
|
|
|
int iPos = 0; // init position pointer
|
|
|
|
const int iDataLen = vecData.Size();
|
|
|
|
CVector<CChannelInfo> vecChanInfo ( 0 );
|
|
|
|
|
|
|
|
while ( iPos < iDataLen )
|
|
|
|
{
|
|
|
|
// check size (the next 12 bytes)
|
|
|
|
if ( ( iDataLen - iPos ) < 12 )
|
|
|
|
{
|
|
|
|
return true; // return error code
|
|
|
|
}
|
|
|
|
|
|
|
|
// channel ID (1 byte)
|
2020-05-26 15:57:03 +02:00
|
|
|
const int iChanID = static_cast<int> ( GetValFromStream ( vecData, iPos, 1 ) );
|
2015-12-06 18:51:06 +01:00
|
|
|
|
|
|
|
// country (2 bytes)
|
2020-05-26 15:57:03 +02:00
|
|
|
const QLocale::Country eCountry = static_cast<QLocale::Country> ( GetValFromStream ( vecData, iPos, 2 ) );
|
2015-12-06 18:51:06 +01:00
|
|
|
|
|
|
|
// instrument (4 bytes)
|
2020-05-26 15:57:03 +02:00
|
|
|
const int iInstrument = static_cast<int> ( GetValFromStream ( vecData, iPos, 4 ) );
|
2015-12-06 18:51:06 +01:00
|
|
|
|
|
|
|
// skill level (1 byte)
|
2020-05-26 15:57:03 +02:00
|
|
|
const ESkillLevel eSkillLevel = static_cast<ESkillLevel> ( GetValFromStream ( vecData, iPos, 1 ) );
|
2015-12-06 18:51:06 +01:00
|
|
|
|
|
|
|
// IP address (4 bytes)
|
2020-05-26 15:57:03 +02:00
|
|
|
const int iIpAddr = static_cast<int> ( GetValFromStream ( vecData, iPos, 4 ) );
|
2015-12-06 18:51:06 +01:00
|
|
|
|
|
|
|
// name
|
|
|
|
QString strCurName;
|
|
|
|
if ( GetStringFromStream ( vecData,
|
|
|
|
iPos,
|
|
|
|
MAX_LEN_FADER_TAG,
|
|
|
|
strCurName ) )
|
|
|
|
{
|
|
|
|
return true; // return error code
|
|
|
|
}
|
|
|
|
|
|
|
|
// city
|
|
|
|
QString strCurCity;
|
|
|
|
if ( GetStringFromStream ( vecData,
|
|
|
|
iPos,
|
|
|
|
MAX_LEN_SERVER_CITY,
|
|
|
|
strCurCity ) )
|
|
|
|
{
|
|
|
|
return true; // return error code
|
|
|
|
}
|
|
|
|
|
|
|
|
// add channel information to vector
|
|
|
|
vecChanInfo.Add ( CChannelInfo ( iChanID,
|
|
|
|
iIpAddr,
|
|
|
|
strCurName,
|
|
|
|
eCountry,
|
|
|
|
strCurCity,
|
|
|
|
iInstrument,
|
|
|
|
eSkillLevel ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
// check size: all data is read, the position must now be at the end
|
|
|
|
if ( iPos != iDataLen )
|
|
|
|
{
|
|
|
|
return true; // return error code
|
|
|
|
}
|
|
|
|
|
|
|
|
// invoke message action
|
2015-12-09 16:50:30 +01:00
|
|
|
emit CLConnClientsListMesReceived ( InetAddr, vecChanInfo );
|
2015-12-06 18:51:06 +01:00
|
|
|
|
|
|
|
return false; // no error
|
|
|
|
}
|
|
|
|
|
2015-12-09 16:50:30 +01:00
|
|
|
void CProtocol::CreateCLReqConnClientsListMes ( const CHostAddress& InetAddr )
|
2015-12-06 18:51:06 +01:00
|
|
|
{
|
|
|
|
CreateAndImmSendConLessMessage ( PROTMESSID_CLM_REQ_CONN_CLIENTS_LIST,
|
2015-12-09 16:50:30 +01:00
|
|
|
CVector<uint8_t> ( 0 ),
|
2015-12-06 18:51:06 +01:00
|
|
|
InetAddr );
|
|
|
|
}
|
|
|
|
|
2015-12-09 16:50:30 +01:00
|
|
|
bool CProtocol::EvaluateCLReqConnClientsListMes ( const CHostAddress& InetAddr )
|
2015-12-06 18:51:06 +01:00
|
|
|
{
|
|
|
|
// invoke message action
|
2015-12-09 16:50:30 +01:00
|
|
|
emit CLReqConnClientsList ( InetAddr );
|
2015-12-06 18:51:06 +01:00
|
|
|
|
|
|
|
return false; // no error
|
|
|
|
}
|
|
|
|
|
2020-03-29 19:00:07 +02:00
|
|
|
void CProtocol::CreateCLChannelLevelListMes ( const CHostAddress& InetAddr,
|
|
|
|
const CVector<uint16_t>& vecLevelList,
|
|
|
|
const int iNumClients )
|
|
|
|
{
|
|
|
|
// This must be a multiple of bytes at four bits per client
|
|
|
|
const int iNumBytes = ( iNumClients + 1 ) / 2;
|
|
|
|
CVector<uint8_t> vecData( iNumBytes );
|
|
|
|
int iPos = 0; // init position pointer
|
|
|
|
|
|
|
|
for ( int i = 0, j = 0; i < iNumClients; i += 2 /* pack two per byte */, j++ )
|
|
|
|
{
|
|
|
|
uint16_t levelLo = vecLevelList[i] & 0x0F;
|
|
|
|
uint16_t levelHi = ( i + 1 < iNumClients ) ? vecLevelList[i + 1] & 0x0F : 0x0F;
|
|
|
|
uint8_t byte = static_cast<uint8_t> ( levelLo | ( levelHi << 4 ) );
|
|
|
|
|
2020-05-26 15:57:03 +02:00
|
|
|
PutValOnStream ( vecData, iPos, static_cast<uint32_t> ( byte ), 1 );
|
2020-03-29 19:00:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CreateAndImmSendConLessMessage ( PROTMESSID_CLM_CHANNEL_LEVEL_LIST,
|
|
|
|
vecData,
|
|
|
|
InetAddr );
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CProtocol::EvaluateCLChannelLevelListMes ( const CHostAddress& InetAddr,
|
|
|
|
const CVector<uint8_t>& vecData )
|
|
|
|
{
|
|
|
|
int iPos = 0; // init position pointer
|
|
|
|
const int iDataLen = vecData.Size(); // four bits per channel, 2 channels per byte
|
|
|
|
// may have one too many entries, last being 0xF
|
|
|
|
int iVecLen = iDataLen * 2; // one ushort per channel
|
|
|
|
|
2020-04-04 23:57:16 +02:00
|
|
|
if ( iVecLen > MAX_NUM_CHANNELS )
|
|
|
|
{
|
|
|
|
return true; // return error code
|
|
|
|
}
|
|
|
|
|
2020-03-29 19:00:07 +02:00
|
|
|
CVector<uint16_t> vecLevelList ( iVecLen );
|
|
|
|
|
|
|
|
for (int i = 0, j = 0; i < iDataLen; i++, j += 2 )
|
|
|
|
{
|
|
|
|
uint8_t byte = static_cast<uint8_t> ( GetValFromStream ( vecData, iPos, 1 ) );
|
|
|
|
uint16_t levelLo = byte & 0x0F;
|
|
|
|
uint16_t levelHi = ( byte >> 4 ) & 0x0F;
|
|
|
|
|
|
|
|
vecLevelList[j] = levelLo;
|
|
|
|
|
|
|
|
if ( levelHi != 0x0F )
|
|
|
|
{
|
|
|
|
vecLevelList[j + 1] = levelHi;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
vecLevelList.resize ( iVecLen - 1 );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// invoke message action
|
|
|
|
emit CLChannelLevelListReceived ( InetAddr, vecLevelList );
|
|
|
|
|
|
|
|
return false; // no error
|
|
|
|
}
|
|
|
|
|
2020-04-14 22:00:08 +02:00
|
|
|
void CProtocol::CreateCLRegisterServerResp ( const CHostAddress& InetAddr,
|
|
|
|
const ESvrRegResult eResult )
|
|
|
|
{
|
|
|
|
int iPos = 0; // init position pointer
|
|
|
|
CVector<uint8_t> vecData( 1 );
|
|
|
|
|
2020-05-26 15:57:03 +02:00
|
|
|
PutValOnStream ( vecData, iPos, static_cast<uint32_t> ( eResult ), 1 );
|
2020-04-14 22:00:08 +02:00
|
|
|
|
|
|
|
CreateAndImmSendConLessMessage ( PROTMESSID_CLM_REGISTER_SERVER_RESP,
|
|
|
|
vecData,
|
|
|
|
InetAddr );
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CProtocol::EvaluateCLRegisterServerResp ( const CHostAddress& InetAddr,
|
|
|
|
const CVector<uint8_t>& vecData )
|
|
|
|
{
|
|
|
|
int iPos = 0; // init position pointer
|
|
|
|
const int iDataLen = vecData.Size();
|
|
|
|
|
|
|
|
if ( iDataLen != 1 )
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-06-23 17:22:01 +02:00
|
|
|
// server registration result (1 byte)
|
|
|
|
const int iSvrRegResult = static_cast<int> ( GetValFromStream ( vecData, iPos, 1 ) );
|
|
|
|
|
|
|
|
if ( ( iSvrRegResult != SRR_REGISTERED ) &&
|
|
|
|
( iSvrRegResult != SRR_CENTRAL_SVR_FULL ) &&
|
2020-06-23 17:51:47 +02:00
|
|
|
( iSvrRegResult != SRR_VERSION_TOO_OLD ) &&
|
|
|
|
( iSvrRegResult != SRR_NOT_FULFILL_REQIREMENTS ) )
|
2020-06-23 17:22:01 +02:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2020-04-14 22:00:08 +02:00
|
|
|
|
|
|
|
// invoke message action
|
2020-06-23 17:22:01 +02:00
|
|
|
emit CLRegisterServerResp ( InetAddr, static_cast<ESvrRegResult> ( iSvrRegResult ) );
|
2020-04-14 22:00:08 +02:00
|
|
|
|
|
|
|
return false; // no error
|
|
|
|
}
|
2011-04-25 12:51:57 +02:00
|
|
|
|
|
|
|
/******************************************************************************\
|
|
|
|
* Message generation and parsing *
|
|
|
|
\******************************************************************************/
|
2013-06-03 18:07:17 +02:00
|
|
|
bool CProtocol::ParseMessageFrame ( const CVector<uint8_t>& vecbyData,
|
2011-04-25 12:51:57 +02:00
|
|
|
const int iNumBytesIn,
|
2013-06-03 18:07:17 +02:00
|
|
|
CVector<uint8_t>& vecbyMesBodyData,
|
2011-04-25 12:51:57 +02:00
|
|
|
int& iCnt,
|
2013-06-03 18:07:17 +02:00
|
|
|
int& iID )
|
2011-04-25 12:51:57 +02:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int iCurPos;
|
|
|
|
|
|
|
|
// vector must be at least "MESS_LEN_WITHOUT_DATA_BYTE" bytes long
|
|
|
|
if ( iNumBytesIn < MESS_LEN_WITHOUT_DATA_BYTE )
|
|
|
|
{
|
|
|
|
return true; // return error code
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Decode header -----------------------------------------------------------
|
|
|
|
iCurPos = 0; // start from beginning
|
|
|
|
|
|
|
|
// 2 bytes TAG
|
2013-06-03 18:07:17 +02:00
|
|
|
const int iTag = static_cast<int> ( GetValFromStream ( vecbyData, iCurPos, 2 ) );
|
2011-04-25 12:51:57 +02:00
|
|
|
|
|
|
|
// check if tag is correct
|
|
|
|
if ( iTag != 0 )
|
|
|
|
{
|
|
|
|
return true; // return error code
|
|
|
|
}
|
|
|
|
|
|
|
|
// 2 bytes ID
|
2013-06-03 18:07:17 +02:00
|
|
|
iID = static_cast<int> ( GetValFromStream ( vecbyData, iCurPos, 2 ) );
|
2011-04-25 12:51:57 +02:00
|
|
|
|
|
|
|
// 1 byte cnt
|
2013-06-03 18:07:17 +02:00
|
|
|
iCnt = static_cast<int> ( GetValFromStream ( vecbyData, iCurPos, 1 ) );
|
2011-04-25 12:51:57 +02:00
|
|
|
|
|
|
|
// 2 bytes length
|
2014-02-14 23:00:31 +01:00
|
|
|
const int iLenBy = static_cast<int> ( GetValFromStream ( vecbyData, iCurPos, 2 ) );
|
2011-04-25 12:51:57 +02:00
|
|
|
|
|
|
|
// make sure the length is correct
|
|
|
|
if ( iLenBy != iNumBytesIn - MESS_LEN_WITHOUT_DATA_BYTE )
|
|
|
|
{
|
|
|
|
return true; // return error code
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Now check CRC -----------------------------------------------------------
|
|
|
|
CCRC CRCObj;
|
2013-01-13 20:56:50 +01:00
|
|
|
|
2011-04-25 12:51:57 +02:00
|
|
|
const int iLenCRCCalc = MESS_HEADER_LENGTH_BYTE + iLenBy;
|
|
|
|
|
|
|
|
iCurPos = 0; // start from the beginning
|
2013-01-13 20:56:50 +01:00
|
|
|
|
2011-04-25 12:51:57 +02:00
|
|
|
for ( i = 0; i < iLenCRCCalc; i++ )
|
|
|
|
{
|
2020-05-26 15:57:03 +02:00
|
|
|
CRCObj.AddByte ( static_cast<uint8_t> ( GetValFromStream ( vecbyData, iCurPos, 1 ) ) );
|
2011-04-25 12:51:57 +02:00
|
|
|
}
|
|
|
|
|
2013-06-03 18:07:17 +02:00
|
|
|
if ( CRCObj.GetCRC () != GetValFromStream ( vecbyData, iCurPos, 2 ) )
|
2011-04-25 12:51:57 +02:00
|
|
|
{
|
|
|
|
return true; // return error code
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Extract actual data -----------------------------------------------------
|
2014-02-14 23:00:31 +01:00
|
|
|
|
|
|
|
// TODO this memory allocation is done in the real time thread but should be
|
2014-07-15 21:22:08 +02:00
|
|
|
// done in the low priority protocol management thread
|
2014-02-14 23:00:31 +01:00
|
|
|
|
2013-06-03 18:07:17 +02:00
|
|
|
vecbyMesBodyData.Init ( iLenBy );
|
2013-01-13 20:56:50 +01:00
|
|
|
|
2011-04-25 12:51:57 +02:00
|
|
|
iCurPos = MESS_HEADER_LENGTH_BYTE; // start from beginning of data
|
2013-01-13 20:56:50 +01:00
|
|
|
|
2011-04-25 12:51:57 +02:00
|
|
|
for ( i = 0; i < iLenBy; i++ )
|
|
|
|
{
|
2020-05-26 15:57:03 +02:00
|
|
|
vecbyMesBodyData[i] = static_cast<uint8_t> ( GetValFromStream ( vecbyData, iCurPos, 1 ) );
|
2011-04-25 12:51:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return false; // no error
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t CProtocol::GetValFromStream ( const CVector<uint8_t>& vecIn,
|
|
|
|
int& iPos,
|
|
|
|
const int iNumOfBytes )
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
note: iPos is automatically incremented in this function
|
|
|
|
*/
|
|
|
|
// 4 bytes maximum since we return uint32
|
|
|
|
Q_ASSERT ( ( iNumOfBytes > 0 ) && ( iNumOfBytes <= 4 ) );
|
|
|
|
Q_ASSERT ( vecIn.Size() >= iPos + iNumOfBytes );
|
|
|
|
|
|
|
|
uint32_t iRet = 0;
|
2013-01-13 20:56:50 +01:00
|
|
|
|
2011-04-25 12:51:57 +02:00
|
|
|
for ( int i = 0; i < iNumOfBytes; i++ )
|
|
|
|
{
|
|
|
|
iRet |= vecIn[iPos] << ( i * 8 /* size of byte */ );
|
|
|
|
iPos++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return iRet;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CProtocol::GetStringFromStream ( const CVector<uint8_t>& vecIn,
|
|
|
|
int& iPos,
|
|
|
|
const int iMaxStringLen,
|
|
|
|
QString& strOut )
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
note: iPos is automatically incremented in this function
|
|
|
|
*/
|
|
|
|
const int iInLen = vecIn.Size();
|
2013-01-13 20:56:50 +01:00
|
|
|
|
|
|
|
// check if at least two bytes are available
|
2011-04-25 12:51:57 +02:00
|
|
|
if ( ( iInLen - iPos ) < 2 )
|
|
|
|
{
|
|
|
|
return true; // return error code
|
|
|
|
}
|
|
|
|
|
2013-01-13 20:56:50 +01:00
|
|
|
// number of bytes for utf-8 string (2 bytes)
|
2020-05-26 15:57:03 +02:00
|
|
|
const int iStrUTF8Len = static_cast<int> ( GetValFromStream ( vecIn, iPos, 2 ) );
|
2011-04-25 12:51:57 +02:00
|
|
|
|
2013-01-13 20:56:50 +01:00
|
|
|
// (note that iPos was incremented by 2 in the above code!)
|
|
|
|
if ( ( iInLen - iPos ) < iStrUTF8Len )
|
2011-04-25 12:51:57 +02:00
|
|
|
{
|
|
|
|
return true; // return error code
|
|
|
|
}
|
|
|
|
|
|
|
|
// string (n bytes)
|
2013-01-13 20:56:50 +01:00
|
|
|
QByteArray sStringUTF8;
|
|
|
|
|
|
|
|
for ( int i = 0; i < iStrUTF8Len; i++ )
|
2011-04-25 12:51:57 +02:00
|
|
|
{
|
|
|
|
// byte-by-byte copying of the string data
|
2013-01-13 20:56:50 +01:00
|
|
|
sStringUTF8.append ( static_cast<char> ( GetValFromStream ( vecIn, iPos, 1 ) ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
// convert utf-8 byte array in the return string
|
|
|
|
strOut = QString::fromUtf8 ( sStringUTF8 );
|
|
|
|
|
|
|
|
// check length of actual string
|
|
|
|
if ( strOut.size() > iMaxStringLen )
|
|
|
|
{
|
|
|
|
return true; // return error code
|
2011-04-25 12:51:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return false; // no error
|
|
|
|
}
|
|
|
|
|
|
|
|
void CProtocol::GenMessageFrame ( CVector<uint8_t>& vecOut,
|
|
|
|
const int iCnt,
|
|
|
|
const int iID,
|
|
|
|
const CVector<uint8_t>& vecData )
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
// query length of data vector
|
|
|
|
const int iDataLenByte = vecData.Size();
|
|
|
|
|
|
|
|
// total length of message
|
|
|
|
const int iTotLenByte = MESS_LEN_WITHOUT_DATA_BYTE + iDataLenByte;
|
|
|
|
|
|
|
|
// init message vector
|
|
|
|
vecOut.Init ( iTotLenByte );
|
|
|
|
|
|
|
|
|
|
|
|
// Encode header -----------------------------------------------------------
|
|
|
|
int iCurPos = 0; // init position pointer
|
|
|
|
|
|
|
|
// 2 bytes TAG (all zero bits)
|
2020-05-26 15:57:03 +02:00
|
|
|
PutValOnStream ( vecOut, iCurPos, static_cast<uint32_t> ( 0 ), 2 );
|
2011-04-25 12:51:57 +02:00
|
|
|
|
|
|
|
// 2 bytes ID
|
2020-05-26 15:57:03 +02:00
|
|
|
PutValOnStream ( vecOut, iCurPos, static_cast<uint32_t> ( iID ), 2 );
|
2011-04-25 12:51:57 +02:00
|
|
|
|
|
|
|
// 1 byte cnt
|
2020-05-26 15:57:03 +02:00
|
|
|
PutValOnStream ( vecOut, iCurPos, static_cast<uint32_t> ( iCnt ), 1 );
|
2011-04-25 12:51:57 +02:00
|
|
|
|
|
|
|
// 2 bytes length
|
2020-05-26 15:57:03 +02:00
|
|
|
PutValOnStream ( vecOut, iCurPos, static_cast<uint32_t> ( iDataLenByte ), 2 );
|
2011-04-25 12:51:57 +02:00
|
|
|
|
|
|
|
// encode data -----
|
|
|
|
for ( i = 0; i < iDataLenByte; i++ )
|
|
|
|
{
|
2020-05-26 15:57:03 +02:00
|
|
|
PutValOnStream ( vecOut, iCurPos, static_cast<uint32_t> ( vecData[i] ), 1 );
|
2011-04-25 12:51:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Encode CRC --------------------------------------------------------------
|
|
|
|
CCRC CRCObj;
|
2013-01-13 20:56:50 +01:00
|
|
|
|
2011-04-25 12:51:57 +02:00
|
|
|
iCurPos = 0; // start from beginning
|
|
|
|
|
|
|
|
const int iLenCRCCalc = MESS_HEADER_LENGTH_BYTE + iDataLenByte;
|
2013-01-13 20:56:50 +01:00
|
|
|
|
2011-04-25 12:51:57 +02:00
|
|
|
for ( i = 0; i < iLenCRCCalc; i++ )
|
|
|
|
{
|
2020-05-26 15:57:03 +02:00
|
|
|
CRCObj.AddByte ( static_cast<uint8_t> ( GetValFromStream ( vecOut, iCurPos, 1 ) ) );
|
2011-04-25 12:51:57 +02:00
|
|
|
}
|
|
|
|
|
2020-05-26 15:57:03 +02:00
|
|
|
PutValOnStream ( vecOut, iCurPos, static_cast<uint32_t> ( CRCObj.GetCRC() ), 2 );
|
2011-04-25 12:51:57 +02:00
|
|
|
}
|
|
|
|
|
2020-05-26 15:57:03 +02:00
|
|
|
void CProtocol::PutValOnStream ( CVector<uint8_t>& vecIn,
|
|
|
|
int& iPos,
|
|
|
|
const uint32_t iVal,
|
|
|
|
const int iNumOfBytes )
|
2011-04-25 12:51:57 +02:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
note: iPos is automatically incremented in this function
|
|
|
|
*/
|
|
|
|
// 4 bytes maximum since we use uint32
|
|
|
|
Q_ASSERT ( ( iNumOfBytes > 0 ) && ( iNumOfBytes <= 4 ) );
|
|
|
|
Q_ASSERT ( vecIn.Size() >= iPos + iNumOfBytes );
|
|
|
|
|
|
|
|
for ( int i = 0; i < iNumOfBytes; i++ )
|
|
|
|
{
|
2020-05-26 15:57:03 +02:00
|
|
|
vecIn[iPos] = ( iVal >> ( i * 8 /* size of byte */ ) ) & 255 /* 11111111 */;
|
2011-04-25 12:51:57 +02:00
|
|
|
iPos++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-13 20:56:50 +01:00
|
|
|
void CProtocol::PutStringUTF8OnStream ( CVector<uint8_t>& vecIn,
|
|
|
|
int& iPos,
|
|
|
|
const QByteArray& sStringUTF8 )
|
2011-04-25 12:51:57 +02:00
|
|
|
{
|
2013-01-13 20:56:50 +01:00
|
|
|
// get the utf-8 string size
|
|
|
|
const int iStrUTF8Len = sStringUTF8.size();
|
2011-04-25 12:51:57 +02:00
|
|
|
|
2013-01-13 20:56:50 +01:00
|
|
|
// number of bytes for utf-8 string (2 bytes)
|
2020-05-26 15:57:03 +02:00
|
|
|
PutValOnStream ( vecIn, iPos, static_cast<uint32_t> ( iStrUTF8Len ), 2 );
|
2011-04-25 12:51:57 +02:00
|
|
|
|
2013-01-13 20:56:50 +01:00
|
|
|
// actual utf-8 string (n bytes)
|
|
|
|
for ( int j = 0; j < iStrUTF8Len; j++ )
|
2011-04-25 12:51:57 +02:00
|
|
|
{
|
2013-01-13 20:56:50 +01:00
|
|
|
// byte-by-byte copying of the utf-8 string data
|
2020-05-26 15:57:03 +02:00
|
|
|
PutValOnStream ( vecIn, iPos, static_cast<uint32_t> ( sStringUTF8[j] ), 1 );
|
2011-04-25 12:51:57 +02:00
|
|
|
}
|
|
|
|
}
|