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