GCMsgProcessor_ProcessNetMsg函数探秘

# GCMsgProcessor_ProcessNetMsg函数探秘

标签(空格分隔): C++ 服务器

---

### 简介

GCMsgProcessor_ProcessNetMsg是游戏服务器中网络守护进程,主要用来监听客户端发过来的序列消息(`protobuf`)。传入的参数为`zmq::message_t`类型的`*msg`。

### 执行流程图

```flow

st=>start: GCMsgProcessor_ProcessNetMsg(zmq::message_t *msg)

op0=>operation: return

op01=>operation: return

op02=>operation: return

op03=>operation: return

op04=>operation: return

op05=>operation: return

op06=>operation: return

op1=>operation: ProcessLocalOrder(msg)

op6=>operation: !ExtraNetMsgHeader(msg, &id, &groupID, &unitID, &data, &size)

op2=>operation: Event_ForbidMessage(groupID, unitID)

op3=>operation: player != NULL

op5=>operation: switch(groupID)

op4=>operation: PlayerEntity_AddMsgSt(player, groupID, unitID) > 0

op10=>operation: case NetProto_XXXX::GROUPID:

op100=>operation: switch(unitID)

op101=>operation: case NetProto_ClientException::UNITID:

op102=>operation: break

op11=>operation: break

op07=>operation: return

cond=>condition: true or false?

cond1=>condition: true or false?

cond2=>condition: true or false?

cond3=>condition: true or false?

cond4=>condition: true or false?

cond5=>condition: true or false?

cond6=>condition: true or false?

cond7=>condition: true or false?

e=>end

st->op1->cond

cond(yes)->op0

cond(no)->op6->cond2

cond2(yes)->op01

cond2(no)->op2->cond3

cond3(yes)->op02

cond3(no)->op3->cond4

cond4(yes)->op4->cond5

cond5(yes)->op03

cond4(no)->op5

cond5(no)->op5

op5->op10->cond6

cond6(yes)->op100->op101->cond7

cond6(no)->op10

cond7(yes)->op102->op11->op07->e

cond7(no)->op101

```

### 重要函数以及变量

```c++

//---------重要变量----------

/*

玩家id

*/

int32_t id = -1;

/*

功能序列的组ID和单元ID,

*/

u_int8_t groupID = 0, unitID = 0;

/*

data 为指向消息序列中数据的指针

*/

void *data = NULL;

/*

size 为消息序列的大小

*/

size_t size = 0;

//--------重要函数-------------

/*

PlayerEntity_Player()函数通过id找到玩家实体,并使player指针指向玩家实体

*/

PlayerEntity *player = PlayerEntity_Player(id);

/*

验证此消息是否是本地消息

*/

ProcessLocalOrder(msg)

/*

解析消息,然后给id、groupID、unitID、data赋值,成功则返回true,失败返回false

*/

ExtraNetMsgHeader(msg, &id, &groupID, &unitID, &data, &size)

/*

验证消息所请求的功能是否是被禁止的,禁止返回true,不禁止返回false

*/

Event_ForbidMessage(groupID, unitID)

/*

验证玩家实体和消息序列的ID

该函数定义在PlayerEntity.cc(137)

*/

PlayerEntity_AddMsgSt(player, groupID, unitID) > 0

```

你可能感兴趣的:(GCMsgProcessor_ProcessNetMsg函数探秘)