當前位置: 首頁>>代碼示例>>Golang>>正文


Golang packet.Packet類代碼示例

本文整理匯總了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 {
		//非平台接入模式,隻要查看自己的登錄信息即可
	}

}
開發者ID:colefan,項目名稱:gsgo-hgame,代碼行數:33,代碼來源:login.go

示例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)
	}

}
開發者ID:dulumao,項目名稱:gsgo,代碼行數:14,代碼來源:GsForwardRule.go

示例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())
	}

}
開發者ID:dulumao,項目名稱:gsgo,代碼行數:46,代碼來源:LsForwardRule.go

示例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())
}
開發者ID:dulumao,項目名稱:gsgo,代碼行數:17,代碼來源:GsForwardRule.go

示例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 沒有必要,但留有接口

}
開發者ID:dulumao,項目名稱:gsgo,代碼行數:24,代碼來源:LsForwardRule.go


注:本文中的github.com/colefan/gsgo/netio/packet.Packet類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。