Beispiel #1
0
void Player::SendServerKickOffNotify()
{
    LOG(INFO) << "SendServerKickOffNotify";
    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, conn_fd(), GetPlayerIdx());
}
Beispiel #2
0
void Player::SendOkCsLoginRes(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, conn_fd(), GetPlayerIdx());
}
Beispiel #3
0
void Player::SendRoleInfoNotify()
{
    LOG(INFO) << "SendRoleInfoNotify";
    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(money_);
    role_info_ntf->set_level(level_);

    msg_module->SendProcToConnsvr(&msg, conn_fd(), GetPlayerIdx());
}
Beispiel #4
0
void Player::SendFailedCsRes(uint64_t seq, int32_t cmd, int32_t err_ret)
{
    LOG(INFO) << "SendFailedCsRes";
    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, conn_fd(), GetPlayerIdx());
    else 
        msg_module->SendStartToConnsvr(&msg, conn_fd(), GetPlayerIdx());
}
Beispiel #5
0
void Player::SendOkCsNormalRegRes(uint64_t seq, const char* account, const char* password)
{
    LOG(INFO) << "SendOkNormalRegRes";
    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, conn_fd(), GetPlayerIdx());
}
Beispiel #6
0
void Player::SendOkCsQuickRegRes(uint64_t seq, uint64_t uid, const char* password)
{
    LOG(INFO) << "SendOkCsQuickRegRes";
    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, conn_fd(), GetPlayerIdx());
}
Beispiel #7
0
void MsgModule::Run()
{
    ObjMgrModule* obj_mgr_module = FindModule<ObjMgrModule>(app_);
    
    int32_t loop_times = 1000;
    static char buf[PKG_BUF_SIZE];
    int32_t len = 0;
    while (loop_times--) {
        // 处理connsvr消息
        len = zmq_recv(connsvr_zmq_sock_, buf, 1024, ZMQ_DONTWAIT);
        if (len > 0) {
            static ConnData conn_data;
            memcpy((void*)&conn_data, buf, CONN_DATA_SIZE);

            const char* msg_buf = Utils::GetMsgFromConn(buf);
            int32_t msg_len = Utils::GetMsgLenFromConn(len);

            if (conn_data.conn_cmd == CONN_START) {
                // 分配内存对象 
                LOG(INFO) << "CONN_START";
                int32_t player_idx = obj_mgr_module->add_player();
                Player* player =  obj_mgr_module->get_player(player_idx);
                if (player == NULL) {
                    // 内存池满了
                    LOG(ERROR) << "create_player error!"; 

                    static ProtoCs::Msg msg;        
                    msg.Clear();
                    if (msg.ParseFromArray(msg_buf, msg_len) == false) {
                        LOG(ERROR)
                            << "protobuf parse error!";
                        return;
                    } 

                    int32_t cmd = msg.head().cmd();
                    if (cmd == ProtoCs::Msg::kLoginReqFieldNumber) {
                        msg.mutable_head()->set_cmd(ProtoCs::Msg::kLoginResFieldNumber);
                        msg.mutable_head()->set_ret(ProtoCs::RET_LOGIN_GAMESVR_FULL);
                    } else if (cmd == ProtoCs::Msg::kQuickRegReqFieldNumber) {
                        msg.mutable_head()->set_cmd(ProtoCs::Msg::kQuickRegResFieldNumber);
                        msg.mutable_head()->set_ret(ProtoCs::RET_QUICK_REG_GAMESVR_FULL);
                    } else if (cmd == ProtoCs::Msg::kNormalRegReqFieldNumber) {
                        msg.mutable_head()->set_cmd(ProtoCs::Msg::kNormalRegResFieldNumber);
                        msg.mutable_head()->set_ret(ProtoCs::RET_NORMAL_REG_GAMESVR_FULL);
                    }

                    SendCloseToConnsvr(&msg, conn_data.conn_fd, 0);
                    return;
                }
                conn_data.player_idx = player_idx;
                player->set_conn_fd(conn_data.conn_fd);
            } else if (conn_data.conn_cmd == CONN_STOP) {
                LOG(INFO) << "CONN_STOP";
                LOG(INFO)
                    << "player_idx[" << conn_data.player_idx
                    << "] client disconnected";
                Player* player =  obj_mgr_module->get_player(conn_data.player_idx);
                if (player != NULL) {
                    LOG(INFO) << "update_player_data";
                    player->do_update_player_data();
                } else {
                    LOG(ERROR) << "update_player_data get_player error";
                }
                obj_mgr_module->del_player(conn_data.player_idx);
                return;
            } else if (conn_data.conn_cmd == CONN_PROC) {
                LOG(INFO) << "CONN_PROC";
            }

            HandleRequest<ProtoCs::Msg>(msg_buf, msg_len, &conn_data);
        }
        // 处理datasvr消息
        len = zmq_recv(datasvr_zmq_sock_, buf, 1024, ZMQ_DONTWAIT);
        if (len > 0) {
            HandleRequest<ProtoSs::Msg>(buf, len, NULL);
        }
    }
}