/** * \brief 当第一次呼叫失败, 开始尝试继续呼叫 * * \param repeat_call_out true 当语音卡通道繁忙导致无法呼叫, 会循环反复呼叫,直到超时 * false 当第一次呼叫失败了,会尝试第二次呼叫, 提高成功率,避免因通道问题造成呼叫失败 */ void voice_card_control::cti_callout_again(boost::shared_ptr<cti_call_out_param> cti_call_out_param_) { BOOST_LOG_SEV(cia_g_logger, Debug) << "业务流水:" << cti_call_out_param_->m_transId << ", 重复呼叫,已经历时:" << cti_call_out_param_->cti_call_out_elapsed_milliseconds(); if (cti_call_out_param_->cti_call_out_elapsed_milliseconds() > 25000) //TODO 将此配置放在config_server对象中 { BOOST_LOG_SEV(cia_g_logger, RuntimeInfo) << "业务流水:" << cti_call_out_param_->m_transId << " 呼叫请求超时"; ciaMessage msg; msg.set_type(CIA_CALL_RESPONSE); msg.set_transid(cti_call_out_param_->m_transId); msg.set_status(CIA_CALL_TIMEOUT); cti_call_out_param_->m_base_client->do_write(chat_message(msg)); return; } if (cti_call_out_param_->m_repeat_call_out_timer == nullptr) { cti_call_out_param_->m_repeat_call_out_timer = boost::make_shared<boost::asio::deadline_timer>(m_io_service_); cti_call_out_param_->m_repeat_call_out_timer->expires_from_now(boost::posix_time::millisec(2000)); //TODO 将此配置放在config_server对象中 } cti_call_out_param_->m_repeat_call_out_timer->async_wait([this, cti_call_out_param_](const boost::system::error_code& ec){ if (!ec) { BOOST_LOG_SEV(cia_g_logger, RuntimeInfo) << "业务流水:" << cti_call_out_param_->m_transId << ", 开始重复呼叫"; cti_callout(cti_call_out_param_); } else { BOOST_LOG_SEV(cia_g_logger, RuntimeInfo) << "业务流水:" << cti_call_out_param_->m_transId << ", 重新呼叫的timer出现异常, 异常码:" << ec; } }); }
void voice_card_control::cti_callout(boost::shared_ptr<cti_call_out_param> cti_call_out_param_) { std::size_t chID; try { chID = m_channel_queue.take(); } catch (std::out_of_range) { BOOST_LOG_SEV(cia_g_logger, RuntimeInfo) << "业务流水:" << cti_call_out_param_->m_transId << " 获取通道失败, 通道全部繁忙"; //继续下一次呼叫 cti_callout_again(cti_call_out_param_); return; } BOOST_LOG_SEV(cia_g_logger, RuntimeInfo) << "业务流水:" << cti_call_out_param_->m_transId << " 获取到得通道状态为:" << SsmChkAutoDial(chID) << ", 通道号码:" << chID; SsmSetTxCallerId(chID, cti_call_out_param_->m_authCode.c_str()); if (SsmAutoDial(chID, cti_call_out_param_->m_pn.c_str()) == 0){ BOOST_LOG_SEV(cia_g_logger, RuntimeInfo) << "业务流水:" << cti_call_out_param_->m_transId << " 已发送请求, 已将此通道对应状态清空, 通道号码:" << chID; boost::shared_ptr<trunk> t = m_trunk_vector.at(chID); boost::unique_lock<boost::mutex> unique_lock_(t->m_trunk_mutex, boost::defer_lock); if (unique_lock_.try_lock()) { t->m_client_socket = cti_call_out_param_->m_base_client; t->m_transId = cti_call_out_param_->m_transId; t->m_caller_id = cti_call_out_param_->m_authCode; t->m_called_id = cti_call_out_param_->m_pn; t->m_hungup_by_echo_tone = cti_call_out_param_->m_hungup_by_echo_tone; t->m_step = TRK_CALLOUT_DAIL; t->m_callTime.restart(); } else { BOOST_LOG_SEV(cia_g_logger, Critical) << "业务流水:" << cti_call_out_param_->m_transId << ", 严重异常, 被分配的语音通道处于占用状态, 请程序猿通宵解决问题"; } } else { m_channel_queue.put(chID); //上一次呼叫失败,继续呼叫 if (cti_call_out_param_->m_repeat_call_out) { cti_call_out_param_->m_repeat_call_out = false; BOOST_LOG_SEV(cia_g_logger, RuntimeInfo) << "业务流水:" << cti_call_out_param_->m_transId << "上一次呼叫失败,继续呼叫"; cti_callout_again(cti_call_out_param_); } //已经连续两次呼叫失败, 直接返回失败 else { BOOST_LOG_SEV(cia_g_logger, RuntimeInfo) << "业务流水:" << cti_call_out_param_->m_transId << "已经连续两次呼叫失败, 直接返回失败"; ciaMessage msg; msg.set_type(CIA_CALL_RESPONSE); msg.set_transid(cti_call_out_param_->m_transId); msg.set_status(CIA_CALL_FAIL); cti_call_out_param_->m_base_client->do_write(chat_message(msg)); return; } } }
bool luaW_pcall(lua_State *L, int nArgs, int nRets, bool allow_wml_error) { int res = luaW_pcall_internal(L, nArgs, nRets); if (res) { /* * When an exception is thrown which doesn't derive from * std::exception m will be nullptr pointer. */ char const *m = lua_tostring(L, -1); if(m) { if (allow_wml_error && strncmp(m, "~wml:", 5) == 0) { m += 5; char const *e = strstr(m, "stack traceback"); lg::wml_error() << std::string(m, e ? e - m : strlen(m)); } else if (allow_wml_error && strncmp(m, "~lua:", 5) == 0) { m += 5; char const *e = nullptr, *em = m; while (em[0] && ((em = strstr(em + 1, "stack traceback")))) #ifdef _MSC_VER #pragma warning (pop) #endif e = em; chat_message("Lua error", std::string(m, e ? e - m : strlen(m))); } else { ERR_LUA << m << '\n'; chat_message("Lua error", m); } } else { chat_message("Lua caught unknown exception", ""); } lua_pop(L, 1); return false; } return true; }
int voice_card_control::cti_hangUp(std::size_t channelID, std::string status) { int retVal = 0; boost::shared_ptr<trunk> t = m_trunk_vector.at(channelID); boost::unique_lock<boost::mutex> unique_lock_(t->m_trunk_mutex, boost::defer_lock); if (!unique_lock_.try_lock()) { BOOST_LOG_SEV(cia_g_logger, Warning) << "业务流水:" << t->m_transId << "cti_hangUp函数尝试锁定通道失败, 放弃挂机, 当前通道Step值为:" << t->m_step; return -1; } else { if (!t->m_hungup_by_echo_tone) { BOOST_LOG_SEV(cia_g_logger, CalloutMsg) << "业务流水:" << t->m_transId << " 由于设置非响一声挂断, 未挂断本次呼叫请求, 通道号码:" << channelID; return -1; } switch (t->m_step) { case TRK_IDLE: BOOST_LOG_SEV(cia_g_logger, Warning) << "业务流水:" << t->m_transId << " 依据当前通道状态判断可能出现重复挂机, 请在后续版本调查原因, 通道号码:" << channelID; return -1; case TRK_SLEEP: BOOST_LOG_SEV(cia_g_logger, Warning) << "业务流水:" << t->m_transId << " 当前通道正在延迟挂机, 通道号码:" << channelID; return -1; default: break; } retVal = SsmHangup(channelID); if (retVal == -1){ show_error(); BOOST_LOG_SEV(cia_g_logger, Warning) << "业务流水:" << t->m_transId << " 挂机失败, 请在后续版本调查原因, 通道号码:" << channelID; } else{ BOOST_LOG_SEV(cia_g_logger, CalloutMsg) << "业务流水:" << t->m_transId << " 已挂断本次呼叫请求, 通道号码:" << channelID; } ciaMessage msg; msg.set_type(CIA_CALL_RESPONSE); msg.set_transid(t->m_transId); msg.set_status(status); t->m_client_socket->do_write(chat_message(msg)); t->realseTrunk(); m_channel_queue.put(channelID); } return retVal; }
void DnDController::chat_message (DnDClient*, Uuid src_uuid, Uuid dst_uuid, const QString& message, int flags) { if (_player_map.count (src_uuid) == 0) return; PlayerPointer src = _player_map[src_uuid]; PlayerPointer dst; if (!(flags & CHAT_BROADCAST)) { if (_player_map.count (dst_uuid) == 0) return; dst = _player_map[dst_uuid]; } chat_message (src, dst, message); }
void chat_log::add_message(const time_t& timestamp, const std::string& user, const std::string& message) { history_.push_back(chat_message(timestamp, user, message)); }
//--------------------------------------------------------------------------- void ribi::gtst::Test::TestParticipant() { //Create a GroupAssigner const int expected_group = 1 + (std::rand() % 256); boost::shared_ptr<GroupAssigner> group_assigner( new GroupAssignerPredetermined(expected_group)); { //Test the GroupAssigner /* for (int i=0; i!=10; ++i) { const int dummy_id = std::rand(); assert(group_assigner->Assign(dummy_id) == expected_group && "Assume GroupAssignerPredetermined always produces the same integer"); } */ } boost::shared_ptr<Participant> p( new Participant( //chat_tag, group_assigner,m_server)); { //assert(!p->CanGetGroup()); assert(!p->CanGetId()); assert(p->GetActions().empty()); assert(p->GetVotes().empty()); assert(!p->CanGetIpAddress()); } //Assign an ID { const int id = 1 + (std::rand() % 256); p->AssignId(id); assert(p->CanGetId()); assert(p->GetId() == id); } //Assign an IP address { boost::shared_ptr<SafeIpAddress> ip_address( new SafeIpAddress("123.123.123.123")); p->SetIpAddress(ip_address); assert(p->CanGetIpAddress()); assert(p->GetIpAddress()->Get() == ip_address.get()->Get()); } //Assign a group { //p->AssignGroup(); //assert(p->CanGetGroup()); //assert(p->GetGroup() == expected_group); } //Chat #1 { boost::shared_ptr<ChatMessage> chat_message( new ChatMessage( p, std::string("chat") + std::to_string(std::rand()))); assert(p->GetChatLog().empty()); //std::clog << "p has not yet chatted, not even close\n"; //assert(!p->HasChatted()); p->StartChat(); assert(!p->GetChatLog().empty()); assert(p->GetChatLog().back().empty()); //assert(!p->CanGetLastChat()); //std::clog << "p has not yet chatted\n"; //assert(!p->HasChatted()); p->AppendChat(chat_message); //assert(p->CanGetLastChat()); //std::clog << "p has chatted\n"; assert(!p->GetChatLog().empty()); assert(!p->GetChatLog().back().empty()); //assert(p->HasChatted()); //std::clog << "p should not have an empty chat log\n"; //assert(!p->GetLastChat().empty()); //std::clog << "p should not have a chat log with one message\n"; assert(p->GetChatLog().back().size() == 1); //std::clog << "p should not have a chat log with the one message chatted\n"; assert(p->GetChatLog().back()[0] == chat_message); } //Voting #1 { //const int vote = std::rand(); //assert(!p->CanGetLastVote()); //std::clog << "p has not yet voted, not even close\n"; //assert(p->HasVoted()); //p->StartVoting(); //assert(!p->CanGetLastVote()); //assert(!p->HasVoted()); assert(p->GetVotes().empty()); p->Vote(boost::shared_ptr<VotingOption>( new VotingOption(0.5,0.1,"Test"))); assert(!p->GetVotes().empty()); //assert(p->CanGetLastVote()); //assert(p->HasVoted()); //assert(p->GetLastVote() == vote); } //Choose action #1 /* { const int action = std::rand(); //assert(!p->CanGetLastAction()); //assert(p->HasChosenAction()); //p->StartChooseAction(); //assert(!p->CanGetLastAction()); //assert(!p->HasChosenAction()); assert(p->GetActions().empty()); p->ChooseAction(action); assert(!p->GetActions().empty()); //assert(p->CanGetLastAction()); //assert(p->HasChosenAction()); //assert(p->GetLastChosenAction() == action); } */ //Voting #2 { //const int vote = std::rand(); //assert(p->CanGetLastVote()); //assert(p->HasVoted()); //p->StartVoting(); //assert(p->CanGetLastVote()); //assert(!p->HasVoted()); p->Vote(boost::shared_ptr<VotingOption>( new VotingOption(0.5,0.1,"Test2"))); assert(p->GetVotes().size() == 2); //assert(p->CanGetLastVote()); //assert(p->HasVoted()); //assert(p->GetLastVote() == vote); } //Choose action #2 /* { const int action = std::rand(); //assert(p->CanGetLastAction()); //assert(p->HasChosenAction()); //p->StartChooseAction(); //assert(p->CanGetLastAction()); //assert(!p->HasChosenAction()); p->ChooseAction(action); assert(p->GetActions().size() == 2); //assert(p->CanGetLastAction()); //assert(p->HasChosenAction()); //assert(p->GetLastChosenAction() == action); } */ //Chat #2 { boost::shared_ptr<ChatMessage> chat_message( new ChatMessage( p, std::string("chat") + std::to_string(std::rand()))); //assert(p->CanGetLastChat()); //assert(p->HasChatted()); assert(p->GetChatLog().size() == 1); p->StartChat(); assert(p->GetChatLog().size() == 2); assert(p->GetChatLog().back().empty()); //assert(!p->CanGetLastChat()); //assert(!p->HasChatted()); p->AppendChat(chat_message); assert(!p->GetChatLog().back().empty()); //assert(p->CanGetLastChat()); //assert(p->HasChatted()); //assert(!p->GetLastChat().empty()); //assert(p->GetLastChat().size() == 1); assert(p->GetChatLog().back()[0] == chat_message); } ///Check the default Participant creation { boost::shared_ptr<Parameters> parameters( new Parameters(m_server)); boost::shared_ptr<Participant> p1 = parameters->CreateDefaultParticipant(); boost::shared_ptr<Participant> p2 = parameters->CreateDefaultParticipant(); assert(p1->GetChatShape() != p2->GetChatShape()); } }
void * chatclient(void *data) { int sockfd = *(int *)data; free(data); peer_info_t *peer_info; char line[LINESIZE]; char buffer[BUFFSIZE]; int nbytes; char *command; char *id; int identified = 0; #ifdef DEBUG struct sockaddr_storage peeraddr_stor; socklen_t peeraddr_storl = sizeof(peeraddr_stor); struct sockaddr_in *peeraddr; char peeraddrs[INET_ADDRSTRLEN]; int port; getpeername(sockfd, (struct sockaddr *)&peeraddr_stor, &peeraddr_storl); peeraddr = (struct sockaddr_in *)&peeraddr_stor; inet_ntop(AF_INET, &peeraddr->sin_addr, peeraddrs, sizeof(peeraddrs)); port = ntohs(peeraddr->sin_port); snprintf(line, LINESIZE, "accepted tcp connection from anon@%s:%d, waiting for id", peeraddrs, port); chat_writeln(TRUE, LOG_DEBUG, line); #endif while ((nbytes = read(sockfd, buffer, BUFFSIZE)) > 0) { buffer[nbytes] = '\0'; if (buffer[nbytes - 1] == '\n') buffer[nbytes - 1] = '\0'; if (!identified && strstr(buffer, "id") == buffer) { id = buffer + 3; peer_info = g_hash_table_lookup(peers_by_id, id); if (peer_info) { if (peer_info->client_tid && pthread_kill(peer_info->client_tid, 0) == 0) { snprintf(line, LINESIZE, "%s is already connected\n", id); write(sockfd, line, strlen(line)); identified = 0; return NULL; } identified = 1; peer_info->sockfd_tcp_in = sockfd; peer_info->client_tid = pthread_self(); update_peer_status(peer_info, TRUE); #ifdef DEBUG snprintf(line, LINESIZE, "tcp connection from %s:%d identified itself as %s", peeraddrs, port, peer_info->id); chat_writeln(TRUE, LOG_DEBUG, line); #endif continue; } else { snprintf(line, LINESIZE, "unregistered id %s\n", id); write(sockfd, line, strlen(line)); identified = 0; } } if (!identified) { snprintf(line, LINESIZE, "please identify by sending: id <name>\n"); write(sockfd, line, strlen(line)); continue; } if (strstr(buffer, "leave") == buffer) { shutdown(sockfd, 2); break; } else if (strstr(buffer, "exec") == buffer) { command = buffer + 5; snprintf(line, LINESIZE, "exec %s", command); chat_writeln(TRUE, LOG_NOTICE, line); exec_command(command); } else { chat_message(MSGDIR_IN, peer_info->id, buffer); } } #ifdef DEBUG snprintf(line, LINESIZE, "closing tcp connection from %s@%s:%d", identified ? peer_info->id : "anon", peeraddrs, port); chat_writeln(TRUE, LOG_DEBUG, line); #endif if (peer_info) update_peer_status(peer_info, FALSE); return NULL; }
void hud_cmd(char **words, MCPacketQueue *sq, MCPacketQueue *cq) { hud_prune(); char reply[32768]; reply[0] = 0; int rpos = 0; int bind_needed = 1; char *cmd = words[1]; words+=2; arg_defaults ad; int ARG_NOTFOUND=0; if (!cmd || !strcmp(cmd,"toggle")) { if (hud_id<0) { bind_needed = 1; } else { hud_unbind(reply, cq); bind_needed = 0; } } else if (!strcmp(cmd,"test")) { hud_mode = HUDMODE_TEST; } else if (!strcmp(cmd,"info")) { hud_mode = HUDMODE_INFO; } else if (!strcmp(cmd,"tunnel") || !strcmp(cmd,"tun")) { hud_mode = HUDMODE_TUNNEL; } else if (!strcmp(cmd,"build")) { hud_mode = HUDMODE_BUILD; hud_build_plan = argflag(words, WORDLIST("plan","p")); ARGDEF(page, NULL, hud_build_page, 1); } else if (!strcmp(cmd,"map")) { hud_mode = HUDMODE_MAP; } else if (!strcmp(cmd,"help")) { hud_mode = HUDMODE_HELP; hud_help_page[0] = 0; if (words[0]) sprintf(hud_help_page, "%s", words[0]); } else { bind_needed = 0; goto Error; } if (bind_needed && hud_id<0) { int id = hud_new(reply, cq); if (id < 0) goto Error; hud_bind(reply, id); } hud_inv = HUDINV_ANY; Error: if (reply[0]) chat_message(reply, cq, "green", rpos); }