static int _write_uint16(lua_State *L){ lua_packet_t p = lua_getluapacket(L,1); if(!p->_packet || p->_packet->type != WPACKET) return luaL_error(L,"invaild opration"); if(lua_type(L,2) != LUA_TNUMBER) return luaL_error(L,"invaild arg2"); uint16_t v = (uint16_t)lua_tointeger(L,2); wpacket_t wpk = (wpacket_t)p->_packet; wpk_write_uint16(wpk,v); return 0; }
static void agent_connected(msgdisp_t disp,sock_ident sock,const char *ip,int32_t port) { agentservice_t service = get_thd_agentservice(); agentplayer_t ply = new_agentplayer(service); if(!ply) { //发送一个消息,通知系统繁忙然后关闭连接 wpacket_t wpk = wpk_create(64,0); wpk_write_uint16(wpk,CMD_GAME_BUSY); asyn_send(sock,wpk); asynsock_close(sock); }else { asynsock_set_ud(sock,(void*)ply->session.data); } }
void on_connect(SOCK s,struct sockaddr_in *addr_remote, void *ud,int err) { if(s != INVALID_SOCK){ struct connection * con = new_conn(s,0); struct netservice *tcpclient = (struct netservice *)ud; tcpclient->bind(tcpclient,con,65536,on_process_packet,NULL ,0,NULL,0,NULL); //发送登录请求 wpacket_t wpk = NEW_WPK(64); wpk_write_uint16(wpk,CMD_C2GATE_LOGIN); wpk_write_string(wpk,"huangwei"); wpk_write_string(wpk,"198272"); send_packet(con,wpk); //wpk_write_binary(wpk,(void*)msg,send_size); //send_packet(con,wpk); } }
//向gate发送短通告消息 void shortmsg2gate(uint16_t cmd,uint32_t gateident){ wpacket_t wpk = wpk_create(64,0); wpk_write_uint16(wpk,cmd); wpk_write_uint32(wpk,gateident); send2gate(wpk); }