void GMTools::on_accmsg(msg_base& msg) { int gameid = ui->cmb_allgame->currentData(Qt::UserRole).toInt(); if (msg.head_.cmd_ == (GET_CLSID(msg_user_login_ret))) { state_ = 1; ui->btn_logingame->setText("login channel"); write_log("login account server succ"); } else if (msg.head_.cmd_ == GET_CLSID(msg_channel_server)) { write_log("get channel server succ, will login to channel server."); int ret = the_instance->connect_to_channel(); if (ret != 0) { write_log("can not connect to channel server."); return; } write_log("channel server connected, will send login info."); the_instance->net_login_to_channel(); } else if (msg.head_.cmd_ == GET_CLSID(msg_common_reply)) { msg_common_reply* pmsg = (msg_common_reply*)&msg; write_log("msg_common_reply, error=" + lx2s(pmsg->err_)); } else if (msg.head_.cmd_ == GET_CLSID(msg_game_data)) { ui->cmb_allgame->clear(); for each(auto it in the_instance->all_games) { ui->cmb_allgame->addItem(QString::fromUtf8(it.second->game_name_), it.second->id_); } }
void GMTools::on_chnmsg(msg_base& msg) { int gameid = ui->cmb_allgame->currentData(Qt::UserRole).toInt(); if (msg.head_.cmd_ == (GET_CLSID(msg_switch_game_server))) { write_log("get game server succ, will login to game."); int ret = the_instance->connect_to_game(); if (ret != 0) { write_log("can not connect to game server."); return; } write_log("game server connected, will send login info."); the_instance->net_login_to_game(); } else if (msg.head_.cmd_ == GET_CLSID(msg_common_reply)) { msg_common_reply* pmsg = (msg_common_reply*)&msg; if (pmsg->rp_cmd_ == GET_CLSID(msg_user_login_channel)) { if (pmsg->err_ == 0) { write_log("login channel server succ, will get game server."); the_instance->net_get_gameserver(gameid); } else { write_log("msg_common_reply, error=" + lx2s(pmsg->err_)); } } else write_log("msg_common_reply, error=" + lx2s(pmsg->err_)); } }
void GMTools::on_gamemsg(msg_base& msg) { if (msg.head_.cmd_ == GET_CLSID(msg_user_login_ret_game)) { ui->edt_logs->setPlainText(""); write_log("login game server succ, please enjoy the show."); ui->btn_logingame->setEnabled(false); } else if (msg.head_.cmd_ == GET_CLSID(msg_query_data_rsp)) { msg_query_data_rsp* pmsg = (msg_query_data_rsp*)&msg; write_log("cmd reply:" + pmsg->data_); } else if (msg.head_.cmd_ == GET_CLSID(msg_common_reply)) { msg_common_reply* pmsg = (msg_common_reply*)&msg; write_log("msg_common_reply, error=" + lx2s(pmsg->err_)); } }
int db_thread_func(db_delay_helper<std::string, int>* db_delay) { unsigned int idle = 0; while(!glb_exit) { bool busy = false; if(!db_delay->pop_and_execute(nullptr)) idle++; else {idle = 0;} msg_ptr pmsg; if(sub_thread_process_msg_lst_.pop_front(pmsg)){ int ret = error_success; if (pmsg->head_.cmd_ == GET_CLSID(msg_user_login) || pmsg->head_.cmd_ == GET_CLSID(msg_user_login_channel)){ ret = handle_user_login((msg_user_login*)pmsg.get()); if (ret != error_success){ pmsg->from_sock_->is_login_ = false; } } else if (pmsg->head_.cmd_ == GET_CLSID(msg_user_register)){ ret = handle_user_register((msg_user_register*)pmsg.get()); pmsg->from_sock_->is_register_ = false; } else if (pmsg->head_.cmd_ == GET_CLSID(msg_get_verify_code)){ ret = handle_get_verify_code((msg_get_verify_code*) pmsg.get()); } if (ret != error_success){ msg_common_reply<nosocket> msg; msg.rp_cmd_ = pmsg->head_.cmd_; msg.err_ = ret; send_msg(pmsg->from_sock_, msg); } busy = true; } if (!busy){ boost::posix_time::milliseconds ms(20); boost::this_thread::sleep(ms); } } return 0; };
int handle_user_register(msg_user_register* pregister) { int verify = verify_user_info(pregister); if (verify != error_success){ return verify; } Query q(*db_); std::string sql = "select count(*) from user_account where machine_mark = '" + std::string(pregister->machine_mark_) + "'"; if (q.get_result(sql) && q.fetch_row()){ if (q.getval() > 100){ return error_cannt_regist_more; } } q.free_result(); { boost::cmatch what; std::string number = pregister->acc_name_; if (pregister->type_ == 1){ boost::regex expr("^1[3578][0-9]{9}$"); bool matched = boost::regex_match(number.c_str(), what, expr); if (!matched){ return error_invalid_data; } } else if(pregister->type_ == 2){ boost::regex expr("^[a-zA-Z0-9]+@[a-zA-Z0-9]+\\.[a-zA-Z0-9]+$"); bool matched = boost::regex_match(number.c_str(), what, expr); if (!matched){ return error_invalid_data; } } else{ boost::regex expr("^[a-zA-Z0-9]{3,}$"); bool matched = boost::regex_match(number.c_str(), what, expr); if (!matched){ return error_invalid_data; } } } //用户名或邮箱注册,对应验证码 if (pregister->type_ == 0){ extern int func_check_verify_code(std::string vcode, koko_socket_ptr fromsock, bool is_check); int ret = func_check_verify_code(pregister->verify_code, pregister->from_sock_, false); if (ret != error_success){ return ret; } } char saccname[256] = {0}; int len = mysql_real_escape_string(&db_->grabdb()->mysql,saccname, pregister->acc_name_, strlen(pregister->acc_name_)); sql = "call register_user(" + boost::lexical_cast<std::string>(pregister->type_) + ", '" + saccname + "', '" + pregister->pwd_hash_ + "', '" + pregister->machine_mark_ + "','" + pregister->from_sock_->remote_ip() + "', @ret);select @ret"; if (!q.get_result(sql)) return error_sql_execute_error; //账号已存在 if (q.fetch_row()){ if (q.getval() != error_success){ return error_account_exist; } } q.free_result(); msg_common_reply<koko_socket_ptr> msg; msg.rp_cmd_ = GET_CLSID(msg_user_register); msg.err_ = 0; send_msg(pregister->from_sock_, msg); return error_success; }