void Player::send_failed_cs_res(uint64_t seq, int32_t cmd, int32_t err_ret) { LOG(INFO) << "send_failed_cs_res"; MsgModule* msg_module = FindModule<MsgModule>(App::GetInstance()); ProtoCs::Msg msg; ProtoCs::Head* head = msg.mutable_head(); head->set_cmd(cmd); head->set_ret(err_ret); head->set_seq(seq); if (cmd == ProtoCs::Msg::kLoginResFieldNumber) msg_module->SendCloseToConnsvr(&msg, get_conn_fd(), get_player_idx()); else msg_module->SendStartToConnsvr(&msg, get_conn_fd(), get_player_idx()); }
/* * process_broadcast_mse(): deal with all broadcast message and forward * */ void process_broadcast_msg(message_header *mh, char* msg, int cid) { char in_token[11] = { '\0' }; memcpy(in_token, msg, TOKEN_LENTH); printf("\tReceived peer_token: %s\n", in_token); char source_token[TOKEN_LENTH + 1] = {'\0'};uint32_t source_ip = 0; uint16_t source_udp_port = 0; memcpy(source_token, msg, TOKEN_LENTH); memcpy(&source_ip, msg + TOKEN_LENTH, 4); memcpy(&source_udp_port, msg + TOKEN_LENTH + 4, 2); char remote_port[MAXLINE] = { '\0' }; char temp_ip[MAXLINE] = { '\0' }; //use connection id to get ip and remote port get_connection_info(cid, temp_ip, remote_port); add_peer_token_to_container(source_token, source_udp_port, source_ip, remote_port); //send out broadcast message int i, sock_fd = -1; for (i = 0; i < MAX_CONNECTIONS; i++) { if (i != cid) { sock_fd = get_conn_fd(i); if (sock_fd != -1) { char package[TOKEN_LENTH + 7] = {'\0'};memcpy(package, source_token, TOKEN_LENTH); memcpy(package + TOKEN_LENTH, &network_ip, 4); memcpy(package + TOKEN_LENTH + 4, &self_peer_msg.udp_port, 2); send_message(sock_fd, mh, msg); } } } }
void Player::send_server_kick_off_notify() { LOG(INFO) << "send_server_kick_off_notify"; MsgModule* msg_module = FindModule<MsgModule>(App::GetInstance()); ProtoCs::Msg msg; ProtoCs::Head* head = msg.mutable_head(); head->set_cmd(ProtoCs::Msg::kServerKickOffNtfFieldNumber); head->set_ret(0); head->set_seq(0); msg_module->SendCloseToConnsvr(&msg, get_conn_fd(), get_player_idx()); }
void Player::send_ok_cs_login_res(uint64_t seq) { MsgModule* msg_module = FindModule<MsgModule>(App::GetInstance()); ProtoCs::Msg msg; ProtoCs::Head* head = msg.mutable_head(); head->set_cmd(ProtoCs::Msg::kLoginResFieldNumber); head->set_ret(0); head->set_seq(seq); ProtoCs::LoginRes* login_res = msg.mutable_login_res(); login_res->set_numb(1222); msg_module->SendStartToConnsvr(&msg, get_conn_fd(), get_player_idx()); }
void Player::send_role_info_notify() { LOG(INFO) << "send_role_info_notify"; MsgModule* msg_module = FindModule<MsgModule>(App::GetInstance()); ProtoCs::Msg msg; ProtoCs::Head* head = msg.mutable_head(); head->set_cmd(ProtoCs::Msg::kRoleInfoNtfFieldNumber); head->set_ret(0); head->set_seq(0); ProtoCs::RoleInfoNtf* role_info_ntf = msg.mutable_role_info_ntf(); role_info_ntf->set_money(m_money); role_info_ntf->set_level(m_level); msg_module->SendProcToConnsvr(&msg, get_conn_fd(), get_player_idx()); }
void Player::send_ok_cs_normal_reg_res(uint64_t seq, const char* account, const char* password) { LOG(INFO) << "send_ok_cs_normal_reg_res"; MsgModule* msg_module = FindModule<MsgModule>(App::GetInstance()); ProtoCs::Msg msg; ProtoCs::Head* head = msg.mutable_head(); head->set_cmd(ProtoCs::Msg::kNormalRegResFieldNumber); head->set_ret(0); head->set_seq(seq); ProtoCs::NormalRegRes* normal_reg_res = msg.mutable_normal_reg_res(); normal_reg_res->set_account(account); normal_reg_res->set_password(password); msg_module->SendStartToConnsvr(&msg, get_conn_fd(), get_player_idx()); }
void Player::send_ok_cs_quick_reg_res(uint64_t seq, uint64_t uid, const char* password) { LOG(INFO) << "send_ok_cs_quick_reg_res"; MsgModule* msg_module = FindModule<MsgModule>(App::GetInstance()); ProtoCs::Msg msg; ProtoCs::Head* head = msg.mutable_head(); head->set_cmd(ProtoCs::Msg::kQuickRegResFieldNumber); head->set_ret(0); head->set_seq(seq); ProtoCs::QuickRegRes* quick_reg_res = msg.mutable_quick_reg_res(); std::string uid_str; Utils::ToString(uid_str, uid); quick_reg_res->set_account(uid_str); quick_reg_res->set_password(password); msg_module->SendStartToConnsvr(&msg, get_conn_fd(), get_player_idx()); }
void send_udp_message() { // double check for network variables inet_pton(AF_INET, local_ip, &network_ip); self_peer_msg.ip = network_ip; printf("sender ip: %s", local_ip); self_peer_msg.udp_port = network_udp_port; add_peer_token_to_container(self_peer_msg.peer_token, self_peer_msg.udp_port, self_peer_msg.ip, tcp_port); //message body char package[TOKEN_LENTH + 7] = {'\0'};memcpy (package, self_peer_msg.peer_token, TOKEN_LENTH); memcpy(package + TOKEN_LENTH, &network_ip, 4); memcpy(package + TOKEN_LENTH + 4, &self_peer_msg.udp_port, 2); /* begin broadcasting */ int i, sock_fd = -1; for (i = 0; i < MAX_CONNECTIONS; i++) { sock_fd = get_conn_fd(i); if (sock_fd != -1) { /* construct message header */ message_header mh; init_header(&mh); generate_message_id(mh.id); mh.type = BROADCAST; mh.payload_length = htons(strlen(package) + 1); if (sizeof(mh) != 12) { printf("mh length is %d\n", sizeof(mh)); throw_exception(ERROR, "sizeof(mh) != 12\n"); } send_message(sock_fd, &mh, package); /* add msg_id to msg_bag */ if (is_new_msg(mh.id)) add_msg_to_container(mh.id); } } }