本文整理汇总了Golang中gk/game/ses.SingleSessionDef.GetUserName方法的典型用法代码示例。如果您正苦于以下问题:Golang SingleSessionDef.GetUserName方法的具体用法?Golang SingleSessionDef.GetUserName怎么用?Golang SingleSessionDef.GetUserName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gk/game/ses.SingleSessionDef
的用法示例。
在下文中一共展示了SingleSessionDef.GetUserName方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: getUserPrefJsonData
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
}
示例2: sendSingleAvatarObject
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
}
示例3: handleWebsocketOpened
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
}
示例4: handleUserPrefReq
// 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
}