int32_t super_processpacket(msgdisp_t disp,rpacket_t rpk) { uint16_t cmd = rpk_peek_uint16(rpk); if(cmd >= CMD_C2GAME && cmd <= CMD_C2GAME_END) { if(cmd > CMD_C2BATTLE && cmd < CMD_C2BATTLE_END) { //将消息转发到battleservice uint8_t battleserid = reverse_read_uint8(rpk); battleservice_t battle = get_battle_by_index(battleserid); if(battle && 0 == send_msg(NULL,battle->msgdisp,(msg_t)rpk)) return 0;//不销毁rpk,由battleservice负责销毁*/ }else{ ident _ident= reverse_read_ident(rpk); player_t ply = (player_t)cast_2_refbase(_ident); if(ply && ply->_status == normal){ if(super_cmd_handlers[cmd]){ rpk_read_uint16(rpk);//丢弃cmd call_handler(super_cmd_handlers[cmd],rpk,ply); }else{ SYS_LOG(LOG_INFO,"unknow cmd:%d\n",cmd); } } if(ply) ref_decrease((struct refbase*)ply); } } return 1; }
static int _read_int16(lua_State *L){ lua_packet_t p = lua_getluapacket(L,1); if(p->_packet->type != RPACKET) return luaL_error(L,"invaild opration"); rpacket_t rpk = (rpacket_t)p->_packet; lua_pushinteger(L,(int16_t)rpk_read_uint16(rpk)); return 1; }
int32_t agent_processpacket(msgdisp_t disp,rpacket_t rpk) { uint16_t cmd = rpk_peek_uint16(rpk); if(cmd == CMD_PLY_CONNECTING) { //绑定到asynnet service->msgdisp->bind(service->msgdisp,0,sock,0,30*1000,0);//由系统选择poller }else { if(cmd >= CMD_CLIENT2GATE && cmd < CMD_CLIENT2GATE_END){ rpk_read_uint16(rpk);//丢掉命令码 }else if(cmd >= CMD_GAME2CLIENT && cmd < CMD_GAME2CLIENT_END){ uint16_t size = reverse_read_uint16(rpk);//这个包需要发给多少个客户端 //在栈上创建一个rpacket_t用于读取需要广播的客户端 rpacket_t r = rpk_create_skip(rpk,size*sizeof(agentsession)+sizeof(size)); //将rpk中用于广播的信息丢掉 rpk_dropback(rpk,size*sizeof(agentsession)+sizeof(size)); int i = 0; wpacket_t wpk = wpk_create_by_rpacket(rpk); //发送给所有需要接收的客户端 for( ; i < size; ++i) { agentsession session; session.data = rpk_read_uint32(r); agentplayer_t ply = get_agentplayer(service,session); if(ply) asyn_send(ply->con,wpk); } rpk_destroy(&r); }else{ agentservice_t service = get_thd_agentservice(); sock_ident sock = CAST_2_SOCK(sender); agentsession session; session.data = (uint32_t)asynsock_get_ud(sock); agentplayer_t ply = get_agentplayer(service,session); if(ply && ply->status == agent_playing) { //转发到gameserver send2game(wpk_create_by_rpacket(rpk)); } } } return 1; }
static int on_gate_packet(kn_stream_conn_t conn,rpacket_t rpk){ uint16_t cmd = rpk_read_uint16(rpk); process_cmd(cmd,conn,rpk); return 1; }