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


Golang SingleSessionDef.SetCurrentPodId方法代码示例

本文整理汇总了Golang中gk/game/ses.SingleSessionDef.SetCurrentPodId方法的典型用法代码示例。如果您正苦于以下问题:Golang SingleSessionDef.SetCurrentPodId方法的具体用法?Golang SingleSessionDef.SetCurrentPodId怎么用?Golang SingleSessionDef.SetCurrentPodId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在gk/game/ses.SingleSessionDef的用法示例。


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

示例1: handleNewPodReq

// websocketConnectionContext entry must be moved from old pod to new pod
func (fieldContext *FieldContextDef) handleNewPodReq(messageFromClient *message.MessageFromClientDef) *gkerr.GkErrDef {

	var newPodReq newPodReqDef
	var gkErr *gkerr.GkErrDef
	var err error

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

	var destinationX, destinationY, destinationZ int

	destinationX, _ = strconv.Atoi(newPodReq.X)
	destinationY, _ = strconv.Atoi(newPodReq.Y)
	destinationZ, _ = strconv.Atoi(newPodReq.Z)

	var websocketConnectionContext *websocketConnectionContextDef

	websocketConnectionContext, gkErr = fieldContext.getWebsocketConnectionContextById(messageFromClient.SessionId)
	if gkErr != nil {
		return gkErr
	}

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

	var oldPodId int32 = singleSession.GetCurrentPodId()

	var newPodId int64
	newPodId, _ = strconv.ParseInt(newPodReq.PodId, 10, 32)

	if (fieldContext.isPodIdValid(int32(newPodId))) && (oldPodId != int32(newPodId)) {

		gkErr = fieldContext.moveAllAvatarBySessionId(messageFromClient.SessionId, oldPodId, int32(newPodId), int16(destinationX), int16(destinationY), int16(destinationZ))
		if gkErr != nil {
			gklog.LogGkErr("", gkErr)
			return gkErr
		}
		delete(fieldContext.podMap[oldPodId].websocketConnectionMap, messageFromClient.SessionId)

		singleSession.SetCurrentPodId(int32(newPodId))

		fieldContext.podMap[int32(newPodId)].websocketConnectionMap[messageFromClient.SessionId] = websocketConnectionContext

		gkErr = fieldContext.uploadNewPodInfo(websocketConnectionContext, int32(newPodId))
		if gkErr != nil {
			gklog.LogGkErr("", gkErr)
			return gkErr
		}

		gkErr = fieldContext.reAddAvatarBySessionId(messageFromClient.SessionId, int32(newPodId))
		if gkErr != nil {
			gklog.LogGkErr("", gkErr)
			return gkErr
		}
	} else {
		gkErr = gkerr.GenGkErr(fmt.Sprintf("invalid podId: %d", newPodId), nil, ERROR_ID_INVALID_POD_ID)
		gklog.LogGkErr("", gkErr)
		return gkErr
	}

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


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