• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang message.MessageToClientDef类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: moveAllAvatarBySessionId

// an avatar is moving from one pod to another
// so delete any object matching by sessionId from old pod
// then add them to the new pod
func (fieldContext *FieldContextDef) moveAllAvatarBySessionId(sessionId string, oldPodId int32, newPodId int32, destinationX int16, destinationY int16, destinationZ int16) *gkerr.GkErrDef {
	gklog.LogTrace("moving all object by session id")
	var gkErr *gkerr.GkErrDef

	for _, fieldObject := range fieldContext.podMap[oldPodId].avatarMap {
		if fieldObject.sourceSessionId == sessionId {
			var messageToClient *message.MessageToClientDef = new(message.MessageToClientDef)

			messageToClient.Command = message.DelSvgReq
			messageToClient.JsonData = []byte(fmt.Sprintf("{ \"id\": \"%s\"}", fieldObject.id))
			messageToClient.Data = make([]byte, 0, 0)

			for _, websocketConnectionContext := range fieldContext.podMap[oldPodId].websocketConnectionMap {
				if sessionId == websocketConnectionContext.sessionId {
					fieldObject.isoXYZ.X = destinationX
					fieldObject.isoXYZ.Y = destinationY
					fieldObject.isoXYZ.Z = destinationZ
					gklog.LogTrace(fmt.Sprintf("moveAllAvatarBySessionId new destination: %d,%d,%d", fieldObject.isoXYZ.X, fieldObject.isoXYZ.Y, fieldObject.isoXYZ.Z))
				}
				fieldContext.queueMessageToClient(websocketConnectionContext.sessionId, messageToClient)
			}

			for _, websocketConnectionContext := range fieldContext.podMap[newPodId].websocketConnectionMap {
				gkErr = fieldContext.sendSingleAvatarObject(websocketConnectionContext, fieldObject)
				if gkErr != nil {
					return gkErr
				}
			}

			delete(fieldContext.podMap[oldPodId].avatarMap, fieldObject.id)
			fieldContext.podMap[newPodId].avatarMap[fieldObject.id] = fieldObject
		}
	}
	return nil
}
开发者ID:gk-turnip,项目名称:server,代码行数:38,代码来源:fieldContext.go


示例2: sendSingleAvatarObject

func (fieldContext *FieldContextDef) sendSingleAvatarObject(websocketConnectionContext *websocketConnectionContextDef, fieldObject *fieldObjectDef) *gkerr.GkErrDef {
	var gkErr *gkerr.GkErrDef

	var svgJsonData *message.SvgJsonDataDef = new(message.SvgJsonDataDef)

	svgJsonData.Id = fieldObject.id
	svgJsonData.IsoXYZ = fieldObject.isoXYZ
	gklog.LogTrace("sourceSessionId: " + fieldObject.sourceSessionId)
	if fieldObject.sourceSessionId != websocketConnectionContext.sessionId {
		var singleSession *ses.SingleSessionDef
		singleSession = fieldContext.sessionContext.GetSessionFromId(fieldObject.sourceSessionId)
		svgJsonData.UserName = singleSession.GetUserName()
		gklog.LogTrace("going to send to ws userName: " + singleSession.GetUserName())
	}

	var messageToClient *message.MessageToClientDef = new(message.MessageToClientDef)
	gkErr = messageToClient.BuildSvgMessageToClient(fieldContext.avatarSvgDir, message.AddSvgReq, fieldObject.fileName, svgJsonData)
	if gkErr != nil {
		return gkErr
	}

	fieldContext.queueMessageToClient(websocketConnectionContext.sessionId, messageToClient)

	return nil
}
开发者ID:gk-turnip,项目名称:server,代码行数:25,代码来源:fieldContext.go


示例3: doTerrainMap

func (fieldContext *FieldContextDef) doTerrainMap(websocketConnectionContext *websocketConnectionContextDef) *gkerr.GkErrDef {

	var gkErr *gkerr.GkErrDef

	var singleSession *ses.SingleSessionDef
	singleSession = fieldContext.sessionContext.GetSessionFromId(websocketConnectionContext.sessionId)

	var messageToClient *message.MessageToClientDef = new(message.MessageToClientDef)
	messageToClient.Command = message.SetTerrainMapReq
	var jsonFileName string = fieldContext.terrainSvgDir + string(os.PathSeparator) + "map_terrain_" + strconv.FormatInt(int64(singleSession.GetCurrentPodId()), 10) + ".json"
	messageToClient.JsonData, gkErr = gkcommon.GetFileContents(jsonFileName)
	if gkErr != nil {
		return gkErr
	}
	var lf []byte = []byte("\n")
	var tb []byte = []byte("\t")
	var sp []byte = []byte(" ")
	var nl []byte = []byte("")
	var te []byte = []byte("errain")
	var bj []byte = []byte("bject")
	//	Not typos

	messageToClient.JsonData = bytes.Replace(messageToClient.JsonData, lf, nl, -1)
	messageToClient.JsonData = bytes.Replace(messageToClient.JsonData, sp, nl, -1)
	messageToClient.JsonData = bytes.Replace(messageToClient.JsonData, tb, nl, -1)
	messageToClient.JsonData = bytes.Replace(messageToClient.JsonData, te, nl, -1)
	messageToClient.JsonData = bytes.Replace(messageToClient.JsonData, bj, nl, -1)
	fieldContext.queueMessageToClient(websocketConnectionContext.sessionId, messageToClient)

	return nil
}
开发者ID:gk-turnip,项目名称:server,代码行数:31,代码来源:fieldContext.go


示例4: sendUserName

// I think this should be (mostly) moved to the message package
func (fieldContext *FieldContextDef) sendUserName(websocketConnectionContext *websocketConnectionContextDef, userName string) *gkerr.GkErrDef {

	var messageToClient *message.MessageToClientDef = new(message.MessageToClientDef)
	messageToClient.Command = message.UserNameReq
	messageToClient.JsonData = []byte("{ \"userName\": \"" + userName + "\" }")
	fieldContext.queueMessageToClient(websocketConnectionContext.sessionId, messageToClient)

	return nil
}
开发者ID:gk-turnip,项目名称:server,代码行数:10,代码来源:fieldContext.go


示例5: doTerrainClear

func (fieldContext *FieldContextDef) doTerrainClear(websocketConnectionContext *websocketConnectionContextDef) *gkerr.GkErrDef {

	var messageToClient *message.MessageToClientDef = new(message.MessageToClientDef)
	messageToClient.Command = message.ClearTerrainReq
	messageToClient.JsonData = []byte("{}")
	messageToClient.Data = make([]byte, 0, 0)
	fieldContext.queueMessageToClient(websocketConnectionContext.sessionId, messageToClient)

	return nil
}
开发者ID:gk-turnip,项目名称:server,代码行数:10,代码来源:fieldContext.go


示例6: handleGetAvatarSvgReq

func (fieldContext *FieldContextDef) handleGetAvatarSvgReq(messageFromClient *message.MessageFromClientDef) *gkerr.GkErrDef {

	var messageToClient *message.MessageToClientDef = new(message.MessageToClientDef)
	var getSvg getSvgDef
	var gkErr *gkerr.GkErrDef
	var err error

	err = json.Unmarshal(messageFromClient.JsonData, &getSvg)
	if err != nil {
		gkErr = gkerr.GenGkErr("json.Unmarshal", err, ERROR_ID_JSON_UNMARSHAL)
		return gkErr
	}

	var randomByte byte
	randomByte = fieldContext.sessionContext.RandContext.GetRandomByte()
	var svgJsonData *message.SvgJsonDataDef = new(message.SvgJsonDataDef)
	svgJsonData.Id = fieldContext.getNextObjectId()
	svgJsonData.IsoXYZ.X = int16((randomByte&0x07)*3) - 10
	svgJsonData.IsoXYZ.Y = int16(((randomByte>>4)&0x07)*3) - 10

	gkErr = messageToClient.BuildSvgMessageToClient(fieldContext.avatarSvgDir, message.GetAvatarSvgRes, getSvg.SvgName, svgJsonData)
	if gkErr != nil {
		return gkErr
	}

	var singleSession *ses.SingleSessionDef
	singleSession = fieldContext.sessionContext.GetSessionFromId(messageFromClient.SessionId)
	var podId int32 = singleSession.GetCurrentPodId()

	fieldContext.queueMessageToClient(messageFromClient.SessionId, messageToClient)

	var fieldObject *fieldObjectDef = new(fieldObjectDef)
	fieldObject.id = svgJsonData.Id
	fieldObject.fileName = getSvg.SvgName
	fieldObject.isoXYZ = svgJsonData.IsoXYZ
	fieldObject.sourceSessionId = messageFromClient.SessionId
	fieldContext.addAvatarObject(podId, fieldObject)

	var websocketConnectionContext *websocketConnectionContextDef

	websocketConnectionContext, gkErr = fieldContext.getWebsocketConnectionContextById(messageFromClient.SessionId)

	if gkErr != nil {
		return gkErr
	}

	websocketConnectionContext.avatarId = fieldObject.id

	gkErr = fieldContext.sendNewAvatarToAll(podId, messageFromClient.SessionId, fieldObject.id)
	if gkErr != nil {
		return gkErr
	}

	return nil
}
开发者ID:gk-turnip,项目名称:server,代码行数:55,代码来源:handleGetSvgReq.go


示例7: sendAllRemoveMessageForObject

func (fieldContext *FieldContextDef) sendAllRemoveMessageForObject(sessionId string, fieldObject *fieldObjectDef) {
	var messageToClient *message.MessageToClientDef = new(message.MessageToClientDef)

	var singleSession *ses.SingleSessionDef
	singleSession = fieldContext.sessionContext.GetSessionFromId(sessionId)
	var podId int32 = singleSession.GetCurrentPodId()

	messageToClient.Command = message.DelSvgReq
	messageToClient.JsonData = []byte(fmt.Sprintf("{ \"id\": \"%s\"}", fieldObject.id))
	for _, websocketConnectionContext := range fieldContext.podMap[podId].websocketConnectionMap {
		fieldContext.queueMessageToClient(websocketConnectionContext.sessionId, messageToClient)
	}
}
开发者ID:gk-turnip,项目名称:server,代码行数:13,代码来源:fieldContext.go


示例8: sendAllPastChat

func (fieldContext *FieldContextDef) sendAllPastChat(websocketConnectionContext *websocketConnectionContextDef) *gkerr.GkErrDef {

	var messageToClient *message.MessageToClientDef = new(message.MessageToClientDef)
	var gkErr *gkerr.GkErrDef

	messageToClient.Command = message.SendPastChatReq
	messageToClient.JsonData, gkErr = fieldContext.getPastChatJsonData()
	if gkErr != nil {
		return gkErr
	}
	messageToClient.Data = make([]byte, 0, 0)

	fieldContext.queueMessageToClient(websocketConnectionContext.sessionId, messageToClient)

	return nil
}
开发者ID:gk-turnip,项目名称:server,代码行数:16,代码来源:fieldContext.go


示例9: sendUserPrefRestore

func (fieldContext *FieldContextDef) sendUserPrefRestore(websocketConnectionContext *websocketConnectionContextDef) *gkerr.GkErrDef {

	var messageToClient *message.MessageToClientDef = new(message.MessageToClientDef)
	var gkErr *gkerr.GkErrDef

	messageToClient.Command = message.UserPrefRestoreReq
	messageToClient.JsonData, gkErr = fieldContext.getUserPrefJsonData(websocketConnectionContext)
	if gkErr != nil {
		return gkErr
	}
	messageToClient.Data = make([]byte, 0, 0)

	fieldContext.queueMessageToClient(websocketConnectionContext.sessionId, messageToClient)

	return nil
}
开发者ID:gk-turnip,项目名称:server,代码行数:16,代码来源:fieldContext.go


示例10: sendEveryoneRainEvent

func (fieldContext *FieldContextDef) sendEveryoneRainEvent() {
	var rainCommand string

	if fieldContext.rainContext.rainCurrentlyOn {
		rainCommand = message.TurnOnRainReq
	} else {
		rainCommand = message.TurnOffRainReq
	}
	var podId int32 = firstPodId // rain only in the first pod

	for _, websocketConnectionContext := range fieldContext.podMap[podId].websocketConnectionMap {
		var messageToClient *message.MessageToClientDef = new(message.MessageToClientDef)
		messageToClient.Command = rainCommand
		fieldContext.queueMessageToClient(websocketConnectionContext.sessionId, messageToClient)
	}
}
开发者ID:gk-turnip,项目名称:server,代码行数:16,代码来源:handleRain.go


示例11: removeDandelion

func (fieldContext *FieldContextDef) removeDandelion() {

	var messageToClient *message.MessageToClientDef = new(message.MessageToClientDef)
	var fileName = "dandelion"

	messageToClient.Command = message.DelSvgReq

	for podId, podEntry := range fieldContext.podMap {
		for _, fieldObject := range podEntry.objectMap {
			if fieldObject.fileName == fileName {
				messageToClient.JsonData = []byte(fmt.Sprintf("{ \"id\": \"%s\"}", fieldObject.id))
				for _, websocketConnectionContext := range podEntry.websocketConnectionMap {
					fieldContext.queueMessageToClient(websocketConnectionContext.sessionId, messageToClient)
				}
				fieldContext.delTerrainObject(podId, fieldObject)
				break
			}
		}
	}
}
开发者ID:gk-turnip,项目名称:server,代码行数:20,代码来源:handleDandelions.go


示例12: setAllAvatars

func (fieldContext *FieldContextDef) setAllAvatars(sessionId string, fieldObject *fieldObjectDef) {

	var messageToClient *message.MessageToClientDef = new(message.MessageToClientDef)

	messageToClient.Command = message.SetSvgReq
	messageToClient.JsonData = []byte(fmt.Sprintf("{ \"id\": \"%s\", \"x\": %d, \"y\": %d, \"z\": %d }", fieldObject.id, fieldObject.isoXYZ.X, fieldObject.isoXYZ.Y, fieldObject.isoXYZ.Z))

	var singleSession *ses.SingleSessionDef
	singleSession = fieldContext.sessionContext.GetSessionFromId(sessionId)
	var podId int32 = singleSession.GetCurrentPodId()

	for _, websocketConnectionContext := range fieldContext.podMap[podId].websocketConnectionMap {
		gklog.LogTrace("compare session " + websocketConnectionContext.sessionId + " " + sessionId)

		if websocketConnectionContext.sessionId != sessionId {
			gklog.LogTrace("Trace about to queue up move command")
			fieldContext.queueMessageToClient(websocketConnectionContext.sessionId, messageToClient)
		}
	}
}
开发者ID:gk-turnip,项目名称:server,代码行数:20,代码来源:handleSetSvgReq.go


示例13: handlePingReq

func (fieldContext *FieldContextDef) handlePingReq(messageFromClient *message.MessageFromClientDef) *gkerr.GkErrDef {

	var messageToClient *message.MessageToClientDef = new(message.MessageToClientDef)
	var pingReq pingReqDef
	var gkErr *gkerr.GkErrDef
	var err error

	err = json.Unmarshal(messageFromClient.JsonData, &pingReq)
	if err != nil {
		gkErr = gkerr.GenGkErr("json.Unmarshal", err, ERROR_ID_JSON_UNMARSHAL)
		return gkErr
	}

	messageToClient.Command = message.PingRes
	messageToClient.JsonData = []byte(fmt.Sprintf("{ \"pingId\": \"%s\" }", pingReq.PingId))

	fieldContext.queueMessageToClient(messageFromClient.SessionId, messageToClient)

	return nil
}
开发者ID:gk-turnip,项目名称:server,代码行数:20,代码来源:handlePingReq.go


示例14: addDandelion

func (fieldContext *FieldContextDef) addDandelion() {

	var messageToClient *message.MessageToClientDef = new(message.MessageToClientDef)
	var svgJsonData *message.SvgJsonDataDef = new(message.SvgJsonDataDef)
	var fileName = "dandelion"

	svgJsonData.Id = fieldContext.getNextObjectId()
	//	svgJsonData.IsoXYZ.X = int16(rand.Int31n(50))
	//	svgJsonData.IsoXYZ.Y = int16(rand.Int31n(50))

	var podId int32 = firstPodId // dandelions are only in the first pod

	for _, websocketConnectionContext := range fieldContext.podMap[podId].websocketConnectionMap {
		//		var singleSession *ses.SingleSessionDef
		//		singleSession = fieldContext.sessionContext.GetSessionFromId(websocketConnectionContext.sessionId)
		var terrainJson *terrainJsonDef
		terrainJson = fieldContext.podMap[podId].terrainJson

		var index = rand.Int31n(int32(len(terrainJson.jsonMapData.TileList)))

		if terrainJson.jsonMapData.TileList[index].Terrain == "grass" {

			svgJsonData.IsoXYZ.X = int16(terrainJson.jsonMapData.TileList[index].X)
			svgJsonData.IsoXYZ.Y = int16(terrainJson.jsonMapData.TileList[index].Y)
			//svgJsonData.IsoXYZ.Z = int16(terrainJson.jsonMapData.TileList[index].Z)
			svgJsonData.IsoXYZ.Z = 0

			messageToClient.BuildSvgMessageToClient(fieldContext.terrainSvgDir, message.AddSvgReq, fileName, svgJsonData)

			fieldContext.queueMessageToClient(websocketConnectionContext.sessionId, messageToClient)

			var fieldObject *fieldObjectDef = new(fieldObjectDef)
			fieldObject.id = svgJsonData.Id
			fieldObject.fileName = fileName
			fieldObject.isoXYZ = svgJsonData.IsoXYZ
			fieldContext.addTerrainObject(fieldObject, podId)
		}
	}
}
开发者ID:gk-turnip,项目名称:server,代码行数:39,代码来源:handleDandelions.go


示例15: removeAllAvatarBySessionId

func (fieldContext *FieldContextDef) removeAllAvatarBySessionId(sessionId string) {
	gklog.LogTrace("removing all object by session id")

	var singleSession *ses.SingleSessionDef
	singleSession = fieldContext.sessionContext.GetSessionFromId(sessionId)
	var podId int32 = singleSession.GetCurrentPodId()

	for _, fieldObject := range fieldContext.podMap[podId].avatarMap {
		if fieldObject.sourceSessionId == sessionId {
			var messageToClient *message.MessageToClientDef = new(message.MessageToClientDef)

			messageToClient.Command = message.DelSvgReq
			messageToClient.JsonData = []byte(fmt.Sprintf("{ \"id\": \"%s\"}", fieldObject.id))
			messageToClient.Data = make([]byte, 0, 0)

			//fieldContext.removeSendRemoveAvatarBySessionId(podId, messageToClient)
			for _, websocketConnectionContext := range fieldContext.podMap[podId].websocketConnectionMap {
				fieldContext.queueMessageToClient(websocketConnectionContext.sessionId, messageToClient)
			}
			delete(fieldContext.podMap[podId].avatarMap, fieldObject.id)
		}
	}
}
开发者ID:gk-turnip,项目名称:server,代码行数:23,代码来源:fieldContext.go


示例16: uploadNewPodInfo

func (fieldContext *FieldContextDef) uploadNewPodInfo(websocketConnectionContext *websocketConnectionContextDef, podId int32) *gkerr.GkErrDef {

	var gkErr *gkerr.GkErrDef

	gkErr = fieldContext.loadTerrain(websocketConnectionContext)
	if gkErr != nil {
		return gkErr
	}

	gkErr = fieldContext.sendAllAvatarObjects(podId, websocketConnectionContext)
	if gkErr != nil {
		return gkErr
	}

	var messageToClient *message.MessageToClientDef = new(message.MessageToClientDef)
	var podTitle string = fieldContext.podMap[podId].title
	messageToClient.Command = message.NewPodTitleReq
	messageToClient.JsonData = []byte(fmt.Sprintf("{ \"podTitle\": \"%s\" }", podTitle))
	messageToClient.Data = make([]byte, 0, 0)

	fieldContext.queueMessageToClient(websocketConnectionContext.sessionId, messageToClient)

	return nil
}
开发者ID:Earth4,项目名称:server,代码行数:24,代码来源:handleNewPodReq.go


示例17: doTerrainSvg

func (fieldContext *FieldContextDef) doTerrainSvg(websocketConnectionContext *websocketConnectionContextDef) *gkerr.GkErrDef {

	var terrainSentMap map[string]string = make(map[string]string)
	var gkErr *gkerr.GkErrDef

	var singleSession *ses.SingleSessionDef
	singleSession = fieldContext.sessionContext.GetSessionFromId(websocketConnectionContext.sessionId)

	var terrainJson *terrainJsonDef

	terrainJson = fieldContext.podMap[singleSession.GetCurrentPodId()].terrainJson

	for i := 0; i < len(terrainJson.jsonMapData.TileList); i++ {
		var terrain string = terrainJson.jsonMapData.TileList[i].Terrain
		var ok bool

		if terrain != "" {
			_, ok = terrainSentMap[terrain]
			if !ok {
				var messageToClient *message.MessageToClientDef = new(message.MessageToClientDef)
				gkErr = messageToClient.BuildSvgMessageToClient(fieldContext.terrainSvgDir, message.SetTerrainSvgReq, terrain, nil)
				if gkErr != nil {
					return gkErr
				}
				fieldContext.queueMessageToClient(websocketConnectionContext.sessionId, messageToClient)

				terrainSentMap[terrain] = terrain
			}
		}
	}

	for i := 0; i < len(terrainJson.jsonMapData.ObjectList); i++ {
		var terrain string = terrainJson.jsonMapData.ObjectList[i].Object
		var ok bool

		_, ok = terrainSentMap[terrain]
		if !ok {
			var messageToClient *message.MessageToClientDef = new(message.MessageToClientDef)
			gkErr = messageToClient.BuildSvgMessageToClient(fieldContext.terrainSvgDir, message.SetTerrainSvgReq, terrain, nil)
			if gkErr != nil {
				return gkErr
			}
			fieldContext.queueMessageToClient(websocketConnectionContext.sessionId, messageToClient)

			terrainSentMap[terrain] = terrain
		}
	}

	return nil
}
开发者ID:gk-turnip,项目名称:server,代码行数:50,代码来源:fieldContext.go



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang ses.SingleSessionDef类代码示例发布时间:2022-05-28
下一篇:
Golang user.User类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap