@@ -82,6 +82,33 @@ void PABotBaseConnection::send_message(const BotBaseMessage& message, bool is_re
8282}
8383
8484
85+ void PABotBaseConnection::push_error_byte (ErrorBatchType type, char byte){
86+ if (m_current_error_type == type){
87+ m_current_error_batch.push_back (byte);
88+ return ;
89+ }
90+
91+ switch (m_current_error_type){
92+ case ErrorBatchType::NO_ERROR_:
93+ break ;
94+ case ErrorBatchType::ZERO_BYTES:
95+ m_sniffer->log (" Skipped " + std::to_string (m_current_error_batch.size ()) + " zero byte(s)." );
96+ break ;
97+ case ErrorBatchType::FF_BYTES:
98+ m_sniffer->log (" Skipped " + std::to_string (m_current_error_batch.size ()) + " 0xff byte(s)." );
99+ break ;
100+ case ErrorBatchType::ASCII_BYTES:
101+ m_sniffer->log (" Received possible ASCII: " + m_current_error_batch);
102+ break ;
103+ case ErrorBatchType::OTHER:
104+ // m_sniffer->log("Skipped " + std::to_string(m_current_error_batch.size()) + " invalid length byte(s).");
105+ break ;
106+ }
107+
108+ m_current_error_batch.clear ();
109+ m_current_error_batch.push_back (byte);
110+ m_current_error_type = type;
111+ }
85112void PABotBaseConnection::on_recv (const void * data, size_t bytes){
86113 // Push into receive buffer.
87114 for (size_t c = 0 ; c < bytes; c++){
@@ -92,25 +119,32 @@ void PABotBaseConnection::on_recv(const void* data, size_t bytes){
92119 uint8_t length = ~m_recv_buffer[0 ];
93120
94121 if (m_recv_buffer[0 ] == 0 ){
95- m_sniffer->log (" Skipping zero byte." );
122+ // m_sniffer->log("Skipping zero byte.");
123+ push_error_byte (ErrorBatchType::ZERO_BYTES, 0 );
96124 m_recv_buffer.pop_front ();
97125 continue ;
98126 }
99127
100128 // Message is too short.
101129 if (length < PABB_PROTOCOL_OVERHEAD){
102- m_sniffer->log (" Message is too short: bytes = " + std::to_string (length));
130+ if (length == 0 ){
131+ push_error_byte (ErrorBatchType::FF_BYTES, ~length);
132+ }else {
133+ m_sniffer->log (" Message is too short: bytes = " + std::to_string (length));
134+ push_error_byte (ErrorBatchType::OTHER, ~length);
135+ }
103136 m_recv_buffer.pop_front ();
104137 continue ;
105138 }
106139
107140 // Message is too long.
108141 if (length > PABB_PROTOCOL_MAX_PACKET_SIZE){
109- char ascii = ~length;
110- std::string text = ascii < 32
111- ? " , ascii = " + std::to_string (ascii)
112- : std::string (" , char = " ) + ascii;
113- m_sniffer->log (" Message is too long: bytes = " + std::to_string (length) + text);
142+ // char ascii = ~length;
143+ // std::string text = ascii < 32
144+ // ? ", ascii = " + std::to_string(ascii)
145+ // : std::string(", char = ") + ascii;
146+ // m_sniffer->log("Message is too long: bytes = " + std::to_string(length) + text);
147+ push_error_byte (ErrorBatchType::ASCII_BYTES, ~length);
114148 m_recv_buffer.pop_front ();
115149 continue ;
116150 }
@@ -120,6 +154,9 @@ void PABotBaseConnection::on_recv(const void* data, size_t bytes){
120154 return ;
121155 }
122156
157+ m_current_error_type = ErrorBatchType::NO_ERROR_;
158+ m_current_error_batch.clear ();
159+
123160 std::string message (m_recv_buffer.begin (), m_recv_buffer.begin () + length);
124161
125162 // Verify checksum
0 commit comments