本文整理汇总了Golang中github.com/colefan/gsgo/netio.ConnInf类的典型用法代码示例。如果您正苦于以下问题:Golang ConnInf类的具体用法?Golang ConnInf怎么用?Golang ConnInf使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ConnInf类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: SessionOpen
func (n *NodeService) SessionOpen(conn netio.ConnInf) {
//TODO
if conn == nil {
panic("NodeService.SessionOpen(conn) error, conn is nil")
}
conn.SetBsStatus(BS_STATUS_OPENED)
ProxyLog.Info("NodeService received a session: %q", conn.GetRemoteIp())
}
示例3: HandleMsg
func (this *GameServer) HandleMsg(cmdId uint16, pack *packet.Packet, conn netio.ConnInf) {
msgType := cmdId >> 8
h := this.handlers[msgType]
if h == nil {
Log.Warn("msg has no handler ,cmdid = ", cmdId, ", msgtype = ", msgType)
//TODO 是否需要断掉
conn.Close()
} else {
h.HandleMsg(cmdId, pack, conn)
}
}
示例4: HandleMsg
func (this *MyServer) HandleMsg(cmdid uint16, pack *packet.Packet, conn netio.ConnInf) {
//fmt.Println("[S]...read a msg, id = ", cmdid)
buf := iobuffer.NewOutBuffer(int(pack.PackLen + packet.PACKET_PROXY_HEADER_LEN))
buf = pack.Header.Encode(buf)
for _, tmp := range pack.RawData {
buf.PutByte(tmp)
}
nPackLen := buf.GetLen() - packet.PACKET_PROXY_HEADER_LEN
buf.SetUint16(uint16(nPackLen), 0)
if conn != nil {
conn.Write(buf.GetData())
}
}
示例5: errorResponse
//包内通用函数
func errorResponse(cmdId uint16, errCode uint16, userId uint32, conn netio.ConnInf) {
if conn == nil {
ProxyLog.Error("send error msg error,physical link is nil,req-cmd-id = ", cmdId)
return
}
resp := &protocol_comm.ServerErrorNt{}
resp.Packet = packet.NewEmptyPacket()
resp.CmdID = protocol_comm.CMD_S_C_ERROR_NT
resp.ID = userId
resp.FSID = NODE_TYPE_PROXY
resp.ReqCmdID = cmdId
resp.ErrCode = errCode
buf := resp.EncodePacket(64)
conn.Write(buf.GetData())
}
示例6: SessionClose
func (n *NodeService) SessionClose(conn netio.ConnInf) {
//TODO
if conn.GetBsStatus() == BS_STATUS_AUTHED {
NodeManagerInst.UnRegNodeConnection(conn.GetConnID())
}
conn.SetBsStatus(BS_STATUS_CLOSED)
}
示例7: UnHandledMsg
func (h *BaseHandler) UnHandledMsg(cmdid uint16, conn netio.ConnInf) {
Log.Warn("unknow msg in this module, msgtype :", h.GetModuleId(), ", cmdid : ", cmdid, ", userid : ", conn.GetUID())
}
示例8: HandleMsg
//收到来自各服务节点的消息
func (n *NodeService) HandleMsg(cmdID uint16, pack *packet.Packet, conn netio.ConnInf) {
if conn == nil {
panic("NodeService.HandleMsg error,conn is nil ")
}
switch conn.GetBsStatus() {
case 0, BS_STATUS_OPENED:
//需要先判断节点是已经通过了验证
if protocol_proxy.CMD_S_P_REG_REQ == cmdID {
node := NewServerNode()
var regReq protocol_proxy.NodeRegReq
regReq.Packet = pack
if !regReq.DecodePacket() {
ProxyLog.Error("invalid CMD_S_S_REG_REQ,Packet decode failed")
conn.Close()
} else {
node.NodeType = regReq.NodeType
node.GameId = regReq.GameId
node.GameAreaId = regReq.GameAreaId
node.GameServerId = regReq.GameServerId
node.GameServerName = regReq.GameServerName
node.GameServerDesc = regReq.GameServerDesc
node.Ip = conn.GetRemoteIp()
nRetCode := NodeManagerInst.RegNodeConnection(node)
if 0 == nRetCode {
node.SetPhysicalLink(conn)
conn.SetBsStatus(BS_STATUS_AUTHED)
} else {
ProxyLog.Info("server node register failed, ip = ", conn.GetRemoteIp(), " NodeType = ", node.NodeType, " IP = ", node.Ip, " errcode = ", nRetCode)
}
resp := protocol_proxy.NodeRegResp{}
resp.Packet = packet.NewEmptyPacket()
resp.Code = uint16(nRetCode)
resp.CmdID = protocol_proxy.CMD_S_P_REG_RESP
buf := resp.EncodePacket(256)
conn.Write(buf.GetData())
}
} else {
//不合法的请求,将其关闭
ProxyLog.Error("invalid request ,cmdid = ", cmdID, " before server node is authed.")
conn.Close()
}
case BS_STATUS_AUTHED:
//请进入转发模式
if pack.FSID == NODE_TYPE_LS {
lsForwarderInst.FowardToClient(cmdID, pack, conn)
} else if pack.FSID == NODE_TYPE_HS {
hsForwarderInst.FowardToClient(cmdID, pack, conn)
} else if pack.FSID == NODE_TYPE_GS {
gsForwarderInst.FowardToClient(cmdID, pack, conn)
} else {
ProxyLog.Error("unknow server node type :", pack.FSID)
}
//fowardrule::: TODO
default:
ProxyLog.Error("unknown server status : ", conn.GetBsStatus())
}
}