当前位置: 首页>>代码示例>>Golang>>正文


Golang NetCore.Client类代码示例

本文整理汇总了Golang中NetCore.Client的典型用法代码示例。如果您正苦于以下问题:Golang Client类的具体用法?Golang Client怎么用?Golang Client使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Client类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: handleClientLeaveRoom

func handleClientLeaveRoom(client *NetCore.Client, msg *NetCore.NetMsg) bool {
	client.RemoveCloseCB("leaveRoom")

	msg.Buf = ErrConf.GetEmptyRspBuffer(ErrConf.NO_ERR)
	client.SendMsg(msg)

	if room, ok := idRoomMap[client.Id]; ok {
		Logger.Info(LogConf.WorkerClientJob, client.Idx, "client leave room id: %d RoomId: %d", client.Id, room.Id)

		notify := &LeaveRoomNotify{
			Id: NetCore.ClientIDType(client.Id),
		}
		msg.Cmd = MsgConf.ClientLeaveRoomNotify
		if buf, err := json.Marshal(notify); err == nil {
			msg.Buf = buf
		} else {
			return false
		}

		delete(room.Guests, client.Id)

		if len(room.Guests) > 0 {
			for _, v := range room.Guests {
				v.SendMsg(msg)
			}
		} else {
			delete(rooms, room.Id)
		}
	}

	Logger.Info(LogConf.WorkerClientJob, client.Idx, "handleClientLeaveRoom client Idx: %d id: %d", client.Idx, client.Id)

	return true
}
开发者ID:cokeboL,项目名称:ZIM,代码行数:34,代码来源:Room.go

示例2: handleRegist

func handleRegist(client *NetCore.Client, msg *NetCore.NetMsg) {
	stype := binary.LittleEndian.Uint32(msg.Buf)
	NetCore.MarkServer(client, stype)
	addServerToMap(client)
	client.AddCloseCB("removeServer", removeServerFromMap)

	Logger.Info(LogConf.CourierServerJob, LogConf.SERVER, "Server Regist client idx: %d buf len: %d %d", client.GetIdx(), len(msg.Buf), stype)

	binary.LittleEndian.PutUint32(msg.Buf[0:4], NetConf.Courier)
	client.SendMsg(msg)
}
开发者ID:cokeboL,项目名称:GoWorld,代码行数:11,代码来源:handler.go

示例3: handleServerRegist

func handleServerRegist(client *NetCore.Client, msg *NetCore.NetMsg) bool {
	if client != courier {
		Logger.Warn(LogConf.Admin, LogConf.SERVER, "handleServerRegist error, %v %d!", courier, client.Idx)
		return false
	}
	client.CancelWaitRegist()

	Logger.Info(LogConf.Admin, LogConf.SERVER, "handleServerRegist OK, %v %d!", courier, client.Idx)

	NetCore.MarkServer(client, NetConf.Courier)

	return true
}
开发者ID:ccppluagopy,项目名称:Zebra,代码行数:13,代码来源:Handlers.go

示例4: handleClientRegist

func handleClientRegist(client *NetCore.Client, msg *NetCore.NetMsg) bool {
	var (
		req ClientRegistReq
	)

	if err := json.Unmarshal([]byte(msg.Buf), &req); err != nil {
		return false
	}

	id := req.Id

	client.CancelWaitRegist()

	msg.Buf = ErrConf.GetEmptyRspBuffer(ErrConf.NO_ERR)
	client.SendMsg(msg)

	NetCore.AddClientToManager(client, NetCore.ClientIDType(id))

	Logger.Info(LogConf.WorkerClientJob, client.Idx, "handleClientRegist client Idx: %d id: %d", client.Idx, id)

	return true
}
开发者ID:cokeboL,项目名称:ZIM,代码行数:22,代码来源:Regist.go

示例5: handleRegist

func handleRegist(client *NetCore.Client, msg *NetCore.NetMsg) bool {
	var ctype = binary.LittleEndian.Uint32(msg.Buf)
	client.CancelWaitRegist()

	if ctype == NetConf.Client {
		binary.LittleEndian.PutUint32(msg.Buf[0:4], NetConf.Worker)
		client.SendMsg(msg)
	} else {
		if client != courier {
			Logger.Warn(LogConf.WorkerServerJob, LogConf.SERVER, "handleServerRegist error, %v %d!", courier, client.Idx)
			return false
		}

		Logger.Info(LogConf.WorkerServerJob, LogConf.SERVER, "handleServerRegist OK, %v %d!", courier, client.Idx)

		NetCore.MarkServer(client, ctype)
	}

	Logger.Info(LogConf.WorkerServerJob, LogConf.SERVER, "handleRegist, type: %d %d!", ctype, client.Idx)

	return true
}
开发者ID:ccppluagopy,项目名称:Zebra,代码行数:22,代码来源:Handlers.go

示例6: handleClientEnterRoom

//要把房间user列表回复给它
func handleClientEnterRoom(client *NetCore.Client, msg *NetCore.NetMsg) bool {
	var (
		req  EnterRoomReq
		rsp  = &EnterRoomRsp{Ret: 0}
		room *Room
		ok   bool
	)
	Logger.Info(LogConf.WorkerClientJob, client.Idx, "handleClientEnterRoom 000")

	enterRoomRsp := func() {
		Logger.Info(LogConf.WorkerClientJob, client.Idx, "handleClientEnterRoom aaa %d", rsp.Ret)
		if rsp.Ret == 0 {
			rsp.Guests = make([]NetCore.ClientIDType, len(room.Guests)+1)
			rsp.Guests[0] = NetCore.ClientIDType(client.Id)
			Logger.Info(LogConf.WorkerClientJob, client.Idx, "handleClientEnterRoom bbb")

			n := 1
			for id, _ := range room.Guests {
				Logger.Info(LogConf.WorkerClientJob, client.Idx, "handleClientEnterRoom ccc %d %d", id, n)
				rsp.Guests[n] = NetCore.ClientIDType(id)
				n = n + 1
				Logger.Info(LogConf.WorkerClientJob, client.Idx, "handleClientEnterRoom ddd %d %d", id, len(rsp.Guests))
			}
		}
		Logger.Info(LogConf.WorkerClientJob, client.Idx, "handleClientEnterRoom ddd")
		if buf, err := json.Marshal(rsp); err == nil {
			rspMsg := &NetCore.NetMsg{
				Cmd: msg.Cmd,
				Buf: buf,
			}
			client.SendMsg(rspMsg)

			Logger.Info(LogConf.WorkerClientJob, client.Idx, "handleClientEnterRoom client Idx: %d id: %d RoomId: %d", client.Idx, client.Id, req.RoomId)
		} else {
			Logger.Info(LogConf.WorkerClientJob, client.Idx, "handleClientEnterRoom xxxx")
		}
	}

	if err := json.Unmarshal([]byte(msg.Buf), &req); err != nil {
		rsp.Ret = ErrConf.INVALID_JSON
		enterRoomRsp()
		return false
	}

	if room, ok = rooms[req.RoomId]; ok {
		if _, ok2 := room.Guests[client.Id]; ok2 {
			rsp.Ret = ErrConf.ID_HAS_BEEN_IN_ROOM
			enterRoomRsp()
			Logger.Info(LogConf.WorkerClientJob, client.Idx, "handleClientEnterRoom 111")
			return true
		}

		if req.Passwd != room.Passwd {
			rsp.Ret = ErrConf.ERROR_PASSWD_FOR_ROOM
			enterRoomRsp()
			Logger.Info(LogConf.WorkerClientJob, client.Idx, "handleClientEnterRoom 111")
			return true
		}

		Logger.Info(LogConf.WorkerClientJob, client.Idx, "handleClientEnterRoom 222")
		notify := &EnterRoomNotify{
			Id: NetCore.ClientIDType(client.Id),
		}
		notifyMsg := &NetCore.NetMsg{
			Cmd: MsgConf.ClientEnterRoomNotify,
		}
		if buf, err := json.Marshal(notify); err == nil {
			notifyMsg.Buf = buf
		} else {
			Logger.Info(LogConf.WorkerClientJob, client.Idx, "handleClientEnterRoom 333")
			return false
		}

		for _, v := range room.Guests {
			v.SendMsg(notifyMsg)
		}

		enterRoomRsp()

		Logger.Info(LogConf.WorkerClientJob, client.Idx, "handleClientEnterRoom 444")
		room.Guests[client.Id] = client
		idRoomMap[client.Id] = room

	} else {
		room = &Room{
			Id:     req.RoomId,
			Passwd: req.Passwd,
			Guests: make(map[NetCore.ClientIDType]*NetCore.Client),
		}

		enterRoomRsp()

		room.Guests[client.Id] = client
		idRoomMap[client.Id] = room

		rooms[req.RoomId] = room

		Logger.Info(LogConf.WorkerClientJob, client.Idx, "handleClientEnterRoom 555")
	}
//.........这里部分代码省略.........
开发者ID:cokeboL,项目名称:ZIM,代码行数:101,代码来源:Room.go

示例7: handleRegist

func handleRegist(client *NetCore.Client, msg *NetCore.NetMsg) bool {
	client.CancelWaitRegist()
	client.HeartBeat()
	return true
}
开发者ID:ccppluagopy,项目名称:Zebra,代码行数:5,代码来源:main.go

示例8: handleHeartBeat2

func handleHeartBeat2(client *NetCore.Client, msg *NetCore.NetMsg) bool {
	Logger.Info(LogConf.NetCoreCommen, client.Idx, "handleHeartBeat xx client Idx: %d cmd: %d", client.Idx, msg.Cmd)
	client.HeartBeat()
	return true
}
开发者ID:ccppluagopy,项目名称:Zebra,代码行数:5,代码来源:main.go

示例9: handleCourier

func handleCourier(client *NetCore.Client, msg *NetCore.NetMsg) bool {
	client.EchoMsg(msg)

	return true
}
开发者ID:cokeboL,项目名称:ZIM,代码行数:5,代码来源:handler.go

示例10: handleCourier

func handleCourier(client *NetCore.Client, msg *NetCore.NetMsg) {
	client.EchoMsg(msg)
}
开发者ID:cokeboL,项目名称:GoWorld,代码行数:3,代码来源:handler.go


注:本文中的NetCore.Client类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。