func (fieldContext *FieldContextDef) getUserPrefJsonData(websocketConnectionContext *websocketConnectionContextDef) ([]byte, *gkerr.GkErrDef) { var singleSession *ses.SingleSessionDef var userPrefsList []database.DbUserPrefDef var gkErr *gkerr.GkErrDef singleSession = fieldContext.sessionContext.GetSessionFromId(websocketConnectionContext.sessionId) userPrefsList, gkErr = fieldContext.persistenceContext.GetUserPrefsList(singleSession.GetUserName()) var jsonData []byte = make([]byte, 0, 512) jsonData = append(jsonData, []byte("{\"userPrefList\":[")...) for i, e := range userPrefsList { if i > 0 { jsonData = append(jsonData, ',') } jsonData = append(jsonData, []byte(fmt.Sprintf("{\"prefName\": \"%s\", \"prefValue\": \"%s\"}", e.PrefName, e.PrefValue))...) } jsonData = append(jsonData, ']') jsonData = append(jsonData, '}') return jsonData, gkErr }
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) handleWebsocketOpened(websocketOpenedMessage WebsocketOpenedMessageDef) *gkerr.GkErrDef { var singleSession *ses.SingleSessionDef singleSession = fieldContext.sessionContext.GetSessionFromId(websocketOpenedMessage.SessionId) var podId int32 = singleSession.GetCurrentPodId() var websocketConnectionContext *websocketConnectionContextDef var gkErr *gkerr.GkErrDef var ok bool websocketConnectionContext, ok = fieldContext.podMap[podId].websocketConnectionMap[websocketOpenedMessage.SessionId] if ok { gkErr = gkerr.GenGkErr("opening already opened session", nil, ERROR_ID_OPENING_ALREADY_OPEN_SESSION) return gkErr } websocketConnectionContext = new(websocketConnectionContextDef) websocketConnectionContext.sessionId = websocketOpenedMessage.SessionId websocketConnectionContext.messageToClientChan = websocketOpenedMessage.MessageToClientChan websocketConnectionContext.initQueue() fieldContext.podMap[podId].websocketConnectionMap[websocketOpenedMessage.SessionId] = websocketConnectionContext var userName string = singleSession.GetUserName() gkErr = fieldContext.sendUserName(websocketConnectionContext, userName) if gkErr != nil { return gkErr } gkErr = fieldContext.uploadNewPodInfo(websocketConnectionContext, 1) gkErr = fieldContext.sendAllPastChat(websocketConnectionContext) if gkErr != nil { return gkErr } gkErr = fieldContext.sendUserPrefRestore(websocketConnectionContext) if gkErr != nil { return gkErr } return nil }
// websocketConnectionContext entry must be moved from old pod to new pod func (fieldContext *FieldContextDef) handleUserPrefReq(messageFromClient *message.MessageFromClientDef) *gkerr.GkErrDef { var userPrefReq userPrefReqDef var gkErr *gkerr.GkErrDef var err error var singleSession *ses.SingleSessionDef singleSession = fieldContext.sessionContext.GetSessionFromId(messageFromClient.SessionId) err = json.Unmarshal(messageFromClient.JsonData, &userPrefReq) if err != nil { gkErr = gkerr.GenGkErr("json.Unmarshal", err, ERROR_ID_JSON_UNMARSHAL) return gkErr } gkErr = fieldContext.persistenceContext.SetUserPref(singleSession.GetUserName(), userPrefReq.PrefName, userPrefReq.PrefValue) if gkErr != nil { // inserting user preferences is non critical // so just log the error gklog.LogGkErr("fieldContext.persistenceContext.SetUserPref", gkErr) } return nil }