Exemple #1
0
func (this *Callback) OnMessage(c *gametcp.Conn, p protocol.Packet) bool {
	packet := &p

	reqBytes := packet.GetBody()
	msgId := packet.GetMsgId()
	methodName := protos.GetFuncName(msgId)
	reflectData, err := funcs.Call(methodName, reqBytes)
	checkError(err)
	i := reflectData[0].Interface()
	rspBytes := i.([]byte)
	rspPacket := protocol.NewPacket(rspBytes, msgId+1, false)
	err = c.AsyncWritePacket(rspPacket, time.Second)
	checkError(err)
	return true
}
Exemple #2
0
func (this *Callback) OnClose(c *gametcp.Conn) {
	alog.Info("OnClose:" + c.GetExtraData().(net.Addr).String())
}
Exemple #3
0
func (this *Callback) OnConnect(c *gametcp.Conn) bool {
	addr := c.GetRawConn().RemoteAddr()
	c.PutExtraData(addr)
	alog.Info("OnConnect:" + addr.String())
	return true
}