Skip to content

Commit

Permalink
ranklist完善,主要是nsp_client与nsp_server的完善
Browse files Browse the repository at this point in the history
未完成:tdb_brief 离线简要数据,需要一开始就汇入到服务器内存 (明天去实现)
  • Loading branch information
NingLeixueR committed Dec 11, 2024
1 parent 916581c commit 7350f7b
Show file tree
Hide file tree
Showing 13 changed files with 1,336 additions and 599 deletions.
4 changes: 2 additions & 2 deletions bin/proto/db.proto
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,8 @@ message db_notice

enum eranklist
{
lv = 0; // 等级排行
count = 1;
lv = 0; // 等级排行
count = 1;
}

message rankitem
Expand Down
15 changes: 11 additions & 4 deletions bin/proto/net.proto
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ package pbnet;
//option optimize_for = LITE_RUNTIME; //不支持反射,代码和性能会提高不少
option optimize_for = SPEED;

// [回复] 服务器用来回复端,一般用于cmd协议,用来返回一个字符串回显
message PROBUFF_NET_MSG_RESPONSE
{
optional string m_msg = 1;
};

// [请求]心跳协议
message PROBUFF_NET_HEARTBEAT
{
Expand Down Expand Up @@ -167,9 +173,9 @@ message PROBUFF_NET_CMD
// [请求]聊天
enum enum_logic_chat
{
get_chat_list = 0;
chat_speak = 1;
updata_speck = 2;
get_chat_list = 0; // 获取聊天列表
chat_speak = 1; // 发言
updata_speck = 2; // 更新聊天
};

enum enum_chat_channel
Expand Down Expand Up @@ -651,7 +657,8 @@ message PROBUFF_NET_REWARD_ITEM_RESPONSE
// [请求]获取排行榜
message PROBUFF_NET_RANKLIST
{
optional pbdb.eranklist m_type = 1;
optional bool m_iscross = 1;
optional pbdb.eranklist m_type = 2;
};

// [回复]获取排行榜
Expand Down
81 changes: 81 additions & 0 deletions bin/robot_cmd.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@

��ȡ��ǰ������ʱ��
/time

������
/name ������

�޸���ҵȼ�
/lv �ȼ�����(����Ϊ����)

�޸���ҽ������
/gold �������(��������)

�޸������������
/silver ��������(��������)

����������Ϣ
������
enum enum_logic_chat
{
get_chat_list = 0; // ��ȡ�����б�
chat_speak = 1; // ����
updata_speck = 2; // ��������
};
��������:
enum enum_chat_channel
{
enum_chat_zero = 0;
enum_chat_ordinary = 1; // ����
enum_chat_cross_ordinary= 2; // ���
enum_chat_none = 3; // ����
};
/chat ���� �������� (����Ϊ1����Ҫ�����������������)

actor�л�game����
/switch ��·id

����һ��������
/createorder ��ֵid

��ȡ����
/notices

��ȡ�ʼ��б�
/mails

��������
/create_family ��������

��ȡ�����б�
/family

�������
/join_family ����id

ȡ���������
/cancel_join_family ����id

��׼�������
/ratify_family

�ܾ���Ҽ������
/cede_family ���id

�뿪����
/leave_family ����id

�޸ľ�������
/change_familyname ����id ������

����ǩ��
/sign_family ����id

��ȡ���а��б�
�������
enum eranklist
{
lv = 0; // �ȼ�����
count = 1;
}
/ranklist ����/���(0/1) �������
9 changes: 9 additions & 0 deletions public/cpp/actor/actor_logic/game/actor_role.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ namespace ngl
return ecross_none;
}

// ranklist的转发类型
ecross forward_type(const pbnet::PROBUFF_NET_RANKLIST& adata)
{
return adata.m_iscross() ? ecross_cross_ordinary : ecross_ordinary;
}

//# 重载forward_before来指定转发前事件
template <typename T>
bool forward_before(const T& adata)
Expand Down Expand Up @@ -184,6 +190,9 @@ namespace ngl

//# 定时器
bool timer_handle(const message<timerparm>& adata);

//# 回显给客户端一个字符串
void echo_msg(const char* amsg);
};
}//namespace ngl

38 changes: 25 additions & 13 deletions public/cpp/actor/actor_logic/game/actor_role_cmd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@

namespace ngl
{
void actor_role::echo_msg(const char* amsg)
{
auto pro = std::make_shared<pbnet::PROBUFF_NET_MSG_RESPONSE>();
pro->set_m_msg(amsg);
send_client(id_guid(), pro);
}
bool actor_role::handle(const message<pbnet::PROBUFF_NET_CMD>& adata)
{
const pbnet::PROBUFF_NET_CMD& lparm = *adata.get_data();
Expand Down Expand Up @@ -65,18 +71,6 @@ namespace ngl
}
}
);
handle_cmd::push("/chatlist", [](actor_role* role, [[maybe_unused]] const char* aparm)
{
auto pro = std::make_shared<pbnet::PROBUFF_NET_CHAT>();
pro->set_m_type(pbnet::enum_logic_chat::get_chat_list);
int lchannelid = 0;
if (tools::splite(aparm, "*", lchannelid) == false)
return;
pro->set_m_channelid(lchannelid);
message lmessage(0, nullptr, pro);
role->handle_forward<ACTOR_CHAT>(lmessage);
}
);
handle_cmd::push("/switch", [](actor_role* role, [[maybe_unused]] const char* aparm)
{
auto pro = std::make_shared<pbnet::PROBUFF_NET_SWITCH_LINE>();
Expand All @@ -95,8 +89,12 @@ namespace ngl
);
handle_cmd::push("/createorder", [](actor_role* role, [[maybe_unused]] const char* aparm)
{
int32_t lrechargeid = 0;
if (tools::splite(aparm, "*", lrechargeid) == false)
return;
std::string lorderid;
role->createorder(lorderid, 1989);
role->createorder(lorderid, lrechargeid);
role->echo_msg(lorderid.c_str());
}
);
handle_cmd::push("/notices", [](actor_role* role, [[maybe_unused]] const char* aparm)
Expand Down Expand Up @@ -206,6 +204,20 @@ namespace ngl
role->handle_forward<ACTOR_FAMILY>(lmessage);
}
);
handle_cmd::push("/ranklist", [](actor_role* role, [[maybe_unused]] const char* aparm)
{
auto pro = std::make_shared<pbnet::PROBUFF_NET_RANKLIST>();
bool liscross = true;
int32_t ltype = 0;
if (tools::splite(aparm, "*", liscross, ltype) == false)
return;
pro->set_m_iscross(liscross);
pro->set_m_type((pbdb::eranklist)ltype);
message lmessage(1, nullptr, pro);
role->handle_forward<ACTOR_RANKLIST>(lmessage);
}
);

}

std::string& lcmd = lvec[0];
Expand Down
6 changes: 6 additions & 0 deletions public/cpp/actor/actor_logic/robot/actor_robot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,12 @@ namespace ngl
return true;
}

bool actor_robot::handle(const message<pbnet::PROBUFF_NET_MSG_RESPONSE>& adata)
{
log_error()->print("pbnet::PROBUFF_NET_MSG_RESPONSE ####### MSG:{}", adata.get_data()->m_msg());
return true;
}

void actor_manage_robot::nregister()
{
register_handle_custom<actor_manage_robot>::func<
Expand Down
1 change: 1 addition & 0 deletions public/cpp/actor/actor_logic/robot/actor_robot.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ namespace ngl
bool handle(const message<pbnet::PROBUFF_NET_RATIFY_ADDFRIEND_RESPONSE>& adata);
bool handle(const message<pbnet::PROBUFF_NET_ERASEFRIEND_RESPONSE>& adata);
bool handle(const message<pbnet::PROBUFF_NET_ROLESTAT>& adata);
bool handle(const message<pbnet::PROBUFF_NET_MSG_RESPONSE>& adata);
};

class actor_manage_robot : public actor
Expand Down
1 change: 1 addition & 0 deletions public/cpp/actor/nprotocol_g2c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ namespace ngl
, pbnet::PROBUFF_NET_RATIFY_ADDFRIEND_RESPONSE
, pbnet::PROBUFF_NET_ERASEFRIEND_RESPONSE
, pbnet::PROBUFF_NET_ROLESTAT
, pbnet::PROBUFF_NET_MSG_RESPONSE
>();
}
}//namespace ngl
3 changes: 2 additions & 1 deletion public/cpp/logic/public/public/family/family.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ namespace ngl

pbdb::db_familyer* add_familyer(i64_actorid aroleid)
{
if (pbdb::db_familyer* lpfamilyer = get_familyer(aroleid); lpfamilyer == nullptr)
pbdb::db_familyer* lpfamilyer = get_familyer(aroleid);
if (lpfamilyer == nullptr)
{
return lpfamilyer;
}
Expand Down
4 changes: 4 additions & 0 deletions public/cpp/logic/public/public/ranklist/actor_ranklist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ namespace ngl
mforward<np_gm>
>(true);

register_handle_proto<actor_ranklist>::func<
mforward<pbnet::PROBUFF_NET_RANKLIST>
>(true);

}

bool actor_ranklist::handle(const message<mforward<pbnet::PROBUFF_NET_RANKLIST>>& adata)
Expand Down
42 changes: 41 additions & 1 deletion public/cpp/logic/public/public/ranklist/ranklist.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,22 @@ namespace ngl
return &data();
}


const pbdb::db_ranklist* get_constrank(i64_actorid aroleid)
{
auto itor = data().find(aroleid);
if (itor == data().end())
return nullptr;
return &itor->second.getconst();
}

pbdb::db_ranklist* get_rank(i64_actorid aroleid, bool achange = true)
{
auto itor = data().find(aroleid);
if (itor == data().end())
return nullptr;
return &itor->second.get(achange);
}

bool update_value(pbdb::eranklist atype, rank_item& litem, const pbdb::db_brief& abrief)
{
const pbdb::db_ranklist* lpdata = find(abrief.m_id());
Expand All @@ -186,6 +201,30 @@ namespace ngl
virtual void initdata()
{
log_error()->print("actor_ranklist###loaddb_finish");
rank_set_base& lrank = *m_ranks[pbdb::eranklist::lv].get();

for (const std::pair<const nguid, data_modified<pbdb::db_ranklist>>& item : data())
{
const pbdb::db_ranklist& ltemp = item.second.getconst();
rank_item& ltempitem = m_data[item.first];
ltempitem.m_actorid = item.first;

for (const std::pair<const int32_t, pbdb::rankitem>& ritem :ltemp.m_items())
{

ltempitem.m_time[(pbdb::eranklist)ritem.first] = ritem.second.m_time();
ltempitem.m_values[(pbdb::eranklist)ritem.first] = ritem.second.m_value();
}

for (int32_t i = 0; i < pbdb::eranklist::count; ++i)
{
rank_set_base& lrank = *m_ranks[i].get();
lrank.insert(&ltempitem);
}
}



tdb_brief::nsp_cli<actor_ranklist>::set_recv_data_finish([this](const pbdb::db_brief& abrief)
{
std::map<i64_actorid, pbdb::db_brief>& ldata = tdb_brief::nsp_cli<actor_ranklist>::m_data;
Expand Down Expand Up @@ -249,6 +288,7 @@ namespace ngl
pro->set_m_type(atype);
m_ranks[atype]->foreach([&pro](int32_t aindex, const rank_item* aitem)
{
// tdb_brief 离线简要数据,需要一开始就汇入到服务器内存 (去实现)
const pbdb::db_brief* lpbrief = tdb_brief::nsp_cli<actor_ranklist>::getconst(aitem->m_actorid);
*pro->add_m_items() = *lpbrief;
});
Expand Down
Loading

0 comments on commit 7350f7b

Please sign in to comment.