本文整理汇总了Golang中github.com/colefan/gsgo/netio/packet.Packet类的典型用法代码示例。如果您正苦于以下问题:Golang Packet类的具体用法?Golang Packet怎么用?Golang Packet使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Packet类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: loginReq
func (this *LoginHandler) loginReq(pack *packet.Packet, conn netio.ConnInf) {
//TODO
if conn.GetBindObj() != nil {
//登录后在发登录请求,这是不对的。应该剔除
Log.Error("第一次消息请求时,应该没有已经绑定的对象,说明用户已经有绑定的对象了,是个错误的请求")
return
}
if pack.DecodePacket() == false {
}
var loginReq p_login.PlayerLoginReq
loginReq.Packet = pack
if false == loginReq.DecodePacket() {
Log.Error("解析包错误,应该断开连接")
conn.Close()
return
}
var uid uint64
var account string
var superpwd string
uid = loginReq.UserID
account = loginReq.UserName
superpwd = loginReq.UserPwd
if config.GetServerConfig().GetXmlConf().Server.AccessPtMode == 1 {
//平台接入模式,要查看平台登录信息
} else {
//非平台接入模式,只要查看自己的登录信息即可
}
}
示例2: FowardToClient
func (rule *GsForwardRule) FowardToClient(cmdId uint16, pack *packet.Packet, conn netio.ConnInf) {
clientID := pack.ID
client := ClientManagerInst.FindClientByUserID(clientID)
if client != nil {
if cmdId == protocol_proxy.CMD_C_P_USER_OFFLINE_REQ {
client.GetPhysicalLink().Close()
} else {
client.GetPhysicalLink().Write(pack.GetClientFromRawData())
}
} else {
ProxyLog.Error("GS msg can't find physical net conn ,user_id = ", clientID)
}
}
示例3: FowardToClient
func (rule *LsForwardRule) FowardToClient(cmdID uint16, pack *packet.Packet, conn netio.ConnInf) {
clientID := pack.ID
var client *ProxyClient
if cmdID <= protocol_login.CMD_C_LOGIN_VALID_RESP {
client = ClientManagerInst.FindClientByConnID(clientID)
} else {
client = ClientManagerInst.FindClientByUserID(clientID)
}
if client == nil {
ProxyLog.Error("LS msg can't find physical conn,conn_id = ", clientID, " cmd_id = ", cmdID)
return
}
switch cmdID {
case protocol_proxy.CMD_C_P_USER_OFFLINE_REQ:
client.GetPhysicalLink().Close()
case protocol_login.CMD_C_LOGIN_VALID_RESP:
if pack.ErrCode == 0 {
loginValid := &protocol_login.LoginValidResp{}
loginValid.Packet = pack
if loginValid.DecodePacket() {
client.GetPhysicalLink().SetBsStatus(BS_STATUS_AUTHED)
client.GetPhysicalLink().SetUID(loginValid.UserId)
oldClient := ClientManagerInst.ChangeClientFromConnIDtoUserID(client)
if oldClient != nil && oldClient.GetPhysicalLink() != nil {
oldClient.GetPhysicalLink().Close()
}
} else {
loginValid.Packet = packet.NewEmptyPacket()
loginValid.ErrCode = PROXY_FORWARD_DECODE_ERR
loginValid.CmdID = protocol_login.CMD_C_LOGIN_VALID_RESP
buf := loginValid.EncodePacket(128)
client.GetPhysicalLink().Write(buf.GetData())
}
} else {
client.GetPhysicalLink().Write(pack.GetClientFromRawData())
}
default:
client.GetPhysicalLink().Write(pack.GetClientFromRawData())
}
}
示例4: FowardToServer
func (rule *GsForwardRule) FowardToServer(client *ProxyClient, cmdId uint16, pack *packet.Packet, conn netio.ConnInf) {
server := client.GetGsRoute()
if server == nil {
errorResponse(cmdId, EC_GSROUTE_IS_NIL, pack.ID, conn)
return
}
serverLink := client.GetPhysicalLink()
if serverLink == nil {
errorResponse(cmdId, EC_GSROUTE_IS_NIL, pack.ID, conn)
return
}
if serverLink.GetBsStatus() != BS_STATUS_AUTHED {
errorResponse(cmdId, EC_GSROUTE_IS_UNAUTHED, pack.ID, conn)
return
}
serverLink.Write(pack.GetClientFromRawData())
}
示例5: FowardToServer
func (rule *LsForwardRule) FowardToServer(client *ProxyClient, cmdID uint16, pack *packet.Packet, conn netio.ConnInf) {
if code := rule.preRule(pack); code != 0 {
errorResponse(cmdID, uint16(code), pack.ID, conn)
return
}
server := client.GetLsRoute()
if server == nil {
errorResponse(cmdID, EC_LSROUTE_IS_NIL, pack.ID, conn)
return
}
serverLink := server.GetPhysicalLink()
if serverLink == nil {
errorResponse(cmdID, EC_LSROUTE_IS_NIL, pack.ID, conn)
return
}
if serverLink.GetBsStatus() != BS_STATUS_AUTHED {
errorResponse(cmdID, EC_LSROUTE_IS_UNAUTHED, pack.ID, conn)
return
}
serverLink.Write(pack.GetClientFromRawData())
//rule.postRule(pack)//TODO 没有必要,但留有接口
}