static int tc_process_server_msg(tc_event_t *rev) { #if (TCPCOPY_DR) int i, j; connections_t *connections; #endif #if (!TCPCOPY_COMBINED) int len; msg_server_t msg; #else int num, k; unsigned char *p, aggr_resp[COMB_LENGTH + sizeof(uint16_t)]; #endif #if (!TCPCOPY_COMBINED) len = MSG_SERVER_SIZE; #endif #if (!TCPCOPY_COMBINED) if (tc_socket_recv(rev->fd, (char *) &msg, len) == TC_ERROR) #else if (tc_socket_cmb_recv(rev->fd, &num, (char *) aggr_resp) == TC_ERROR) #endif { tc_log_info(LOG_ERR, 0, "Recv socket(%d)error", rev->fd); tc_log_info(LOG_ERR, 0, "server may be closed or"); tc_log_info(LOG_ERR, 0, "backend TCP/IP kernel memeory is too low or"); tc_log_info(LOG_ERR, 0, "the version of intercept may not be equal to the version of tcpcopy"); #if (TCPCOPY_DR) for (i = 0; i < clt_settings.real_servers.num; i++) { connections = &(clt_settings.real_servers.connections[i]); for (j = 0; j < connections->num; j++) { if (connections->fds[j] == rev->fd) { tc_socket_close(rev->fd); tc_log_info(LOG_NOTICE, 0, "close sock:%d", rev->fd); tc_event_del(rev->loop, rev, TC_EVENT_READ); connections->num--; if (connections->num == 0 && clt_settings.real_servers.active[i]) { clt_settings.real_servers.active[i] = 0; clt_settings.real_servers.active_num--; } break; } } } if (clt_settings.real_servers.active_num == 0) { return TC_ERR_EXIT; } else { return TC_OK; } #else return TC_ERR_EXIT; #endif } #if (!TCPCOPY_COMBINED) process_out((unsigned char *) &msg); #else tc_log_debug1(LOG_DEBUG, 0, "resp packets:%d", num); p = aggr_resp + sizeof(uint16_t); for (k = 0; k < num; k++) { process_out(p); p = p + MSG_SERVER_SIZE; } #endif return TC_OK; }
void BaseBot::process_diplomacy_message( char *message, int message_length ) { Token *message_tokens; // The tokens in the incoming message TokenMessage incoming_message; // The incoming message Token lead_token; // The first token of the message message_tokens = (Token *)( message ); if ( message_tokens[ 0 ] == TOKEN_COMMAND_PRN ) { process_prn_message( message_tokens, message_length ); } else { incoming_message.set_message( message_tokens, message_length / 2 ); log_tcpip_comms( true, incoming_message ); // If the first subtoken is a single message if ( incoming_message.submessage_is_single_token( 0 ) ) { // Act on that token lead_token = incoming_message.get_token( 0 ); // Messages that BaseBot handles initially if ( lead_token == TOKEN_COMMAND_HLO ) { process_hlo( incoming_message ); } else if ( lead_token == TOKEN_COMMAND_MAP ) { process_map( incoming_message ); } else if ( lead_token == TOKEN_COMMAND_MDF ) { process_mdf( incoming_message ); } else if ( lead_token == TOKEN_COMMAND_NOW ) { process_now( incoming_message ); } else if ( lead_token == TOKEN_COMMAND_ORD ) { process_ord( incoming_message ); } else if ( lead_token == TOKEN_COMMAND_SCO ) { process_sco( incoming_message ); } // Messages which are broken down further before being passed on else if ( lead_token == TOKEN_COMMAND_NOT ) { process_not( incoming_message ); } else if ( lead_token == TOKEN_COMMAND_REJ ) { process_rej( incoming_message ); } else if ( lead_token == TOKEN_COMMAND_YES ) { process_yes( incoming_message ); } // Messages to be handled by Bot immediately else if ( lead_token == TOKEN_COMMAND_CCD ) { process_ccd( incoming_message ); } else if ( lead_token == TOKEN_COMMAND_DRW ) { process_drw( incoming_message ); } else if ( lead_token == TOKEN_COMMAND_FRM ) { process_frm_message( incoming_message ); } else if ( lead_token == TOKEN_COMMAND_HUH ) { process_huh_message( incoming_message ); } else if ( lead_token == TOKEN_COMMAND_LOD ) { process_lod_message( incoming_message ); } else if ( lead_token == TOKEN_COMMAND_MIS ) { process_mis_message( incoming_message ); } else if ( lead_token == TOKEN_COMMAND_OFF ) { process_off_message( incoming_message ); } else if ( lead_token == TOKEN_COMMAND_OUT ) { process_out( incoming_message ); } else if ( lead_token == TOKEN_COMMAND_SLO ) { process_slo( incoming_message ); } else if ( lead_token == TOKEN_COMMAND_SMR ) { process_smr_message( incoming_message ); } else if ( lead_token == TOKEN_COMMAND_SVE ) { process_sve_message( incoming_message ); } else if ( lead_token == TOKEN_COMMAND_THX ) { process_thx_message( incoming_message ); } else if ( lead_token == TOKEN_COMMAND_TME ) { process_tme_message( incoming_message ); } else if ( lead_token == TOKEN_COMMAND_ADM ) { process_adm_message( incoming_message ); } /* ADDED BY ME */ else if ( lead_token == TOKEN_PRESS_PRP ) { process_prp_message( incoming_message ); } else { log_error("Unexpected first token in message : %s", incoming_message.get_message_as_text().c_str() ); } } else { log_error("Illegal message received"); } } }