func (messageToClient *MessageToClientDef) BuildSvgMessageToClient(svgDir string, command string, fileName string, svgJsonData *SvgJsonDataDef) *gkerr.GkErrDef { var gkErr *gkerr.GkErrDef if !validateSvgFileName(fileName) { gkErr = gkerr.GenGkErr("invalid svg fileName", nil, ERROR_ID_INVALID_SVG_FILENAME) return gkErr } messageToClient.Command = command jsonFileName := svgDir + string(os.PathSeparator) + fileName + ".json" svgFileName := svgDir + string(os.PathSeparator) + fileName + ".svg" messageToClient.JsonData, gkErr = gkcommon.GetFileContents(jsonFileName) if gkErr != nil { return gkErr } messageToClient.Data, gkErr = gkcommon.GetFileContents(svgFileName) if gkErr != nil { return gkErr } messageToClient.Data, gkErr = gksvg.FixSvgData(messageToClient.Data, fileName) if gkErr != nil { return gkErr } if svgJsonData != nil { messageToClient.JsonData, gkErr = templateTranslateJsonData(messageToClient.JsonData, svgJsonData) if gkErr != nil { return gkErr } } return nil }
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 }