// 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 }
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 }
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 }
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 }
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) } } }
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 }