void msg_server::handle_accept(tcp_session_ptr new_connection,acceptor_pointer ap,const boost::system::error_code& error) { if(_is_stop) return; if (!error) { _map_client[new_connection->get_net_id()] = new_connection; //LogT<< "new gate server[" << new_connection->get_net_id() << "] connected ..." << LogEnd; new_connection->start(new_connection->get_net_id(),shared_from_this()); on_connect(new_connection->get_net_id(),new_connection); start_accept(ap); } }
void msg_server::recv_client_handler( tcp_session_ptr session,const char* data_ptr,int len ) { if(len < (int)sizeof(na::msg::msg_base)) return; na::msg::msg_json::ptr p = na::msg::msg_json::create(data_ptr,len); if(p->_net_id == 0) // for python socket msg p->_net_id = session->get_net_id(); //time_logger l(boost::lexical_cast<string,short>(p->_type).c_str()); // lock lock lock !!!! boost::mutex::scoped_lock lock(_queue_mutex); _msg_queue.push(p); }
void login_server::handle_connect(tcp_session_ptr connector,const boost::system::error_code& error) { if (!error) { connector->set_session_status(gs_game); connector->socket().non_blocking(true); connector->start(connector->get_net_id(),shared_from_this()); if(connector->get_net_id() == LOG_SVR_NET_ID) LogS << "mysql server connected ..." << LogEnd; //else // LogS << "fee server connected ..." << LogEnd; // //if(connector->get_net_id() == FEE_SVR_NET_ID) //{ // int server_id = config_ins.get_config_prame("server_id").asInt(); // LogS << "connecting to fee server ..." << Green << "[" << server_id <<"]" << White << LogEnd; // connector->write((const char*)&server_id,4); //} //test team battle // Json::Value team; //for (int i=0;i<6;++i) // team.append(i+98); // team.append(4539); // team.append(95); //Json::Value _mfd_data; //_mfd_data["ai"] = Json::arrayValue; //for (int i = 0;i<(int)team.size();i++) //{ // Json::Value temp; // //temp["na"] = "player" + ; // //temp["kid"] = 0; // //temp["lv"] = i; // temp["mw"] = 4; // temp["idm"] = i; // temp["wn"] = 0; // _mfd_data["ai"][0u].append(temp); //} //battle_system.team_VS(team,1021,_mfd_data); //battle_system.send_team_battle_result(1000); } else { if(error == boost::asio::error::would_block) { LogE << "************* server is blocking *********" << LogEnd; return; } //mysql_state = 1; connector->set_session_status(gs_null); LogE << "************* can not connect to server, net_id: " << connector->get_net_id() << " retry ... *********" << LogEnd; //if(connector->get_net_id() == FEE_SVR_NET_ID) //{ // na::time_helper::sleep(1000000); // connect_to_fee_svr(); //} } }
void msg_server::client_connect_handler( tcp_session_ptr session,int error_value ) { on_disconnect(session->get_net_id(),session); session->stop(); }