本文整理汇总了Golang中gk/game/ses.SingleSessionDef类的典型用法代码示例。如果您正苦于以下问题:Golang SingleSessionDef类的具体用法?Golang SingleSessionDef怎么用?Golang SingleSessionDef使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SingleSessionDef类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
}
开发者ID:gk-turnip,项目名称:server,代码行数:25,代码来源:fieldContext.go
示例2: removeAvatarBySessionId
func (fieldContext *FieldContextDef) removeAvatarBySessionId(sessionId string) *gkerr.GkErrDef {
var websocketConnectionContext *websocketConnectionContextDef
var gkErr *gkerr.GkErrDef
var singleSession *ses.SingleSessionDef
singleSession = fieldContext.sessionContext.GetSessionFromId(sessionId)
var podId int32 = singleSession.GetCurrentPodId()
websocketConnectionContext, gkErr = fieldContext.getWebsocketConnectionContextById(sessionId)
if gkErr != nil {
return gkErr
}
var fieldObject *fieldObjectDef
var ok bool
fieldObject, ok = fieldContext.podMap[podId].avatarMap[websocketConnectionContext.avatarId]
if ok {
fieldContext.sendAllRemoveMessageForObject(websocketConnectionContext.sessionId, fieldObject)
}
if websocketConnectionContext.avatarId != "" {
delete(fieldContext.podMap[podId].avatarMap, websocketConnectionContext.avatarId)
}
return nil
}
开发者ID:gk-turnip,项目名称:server,代码行数:26,代码来源:fieldContext.go
示例3: 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
}
开发者ID:gk-turnip,项目名称:server,代码行数:25,代码来源:fieldContext.go
示例4: handleGetAvatarSvgReq
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
}
开发者ID:gk-turnip,项目名称:server,代码行数:55,代码来源:handleGetSvgReq.go
示例5: sendAllRemoveMessageForObject
func (fieldContext *FieldContextDef) sendAllRemoveMessageForObject(sessionId string, fieldObject *fieldObjectDef) {
var messageToClient *message.MessageToClientDef = new(message.MessageToClientDef)
var singleSession *ses.SingleSessionDef
singleSession = fieldContext.sessionContext.GetSessionFromId(sessionId)
var podId int32 = singleSession.GetCurrentPodId()
messageToClient.Command = message.DelSvgReq
messageToClient.JsonData = []byte(fmt.Sprintf("{ \"id\": \"%s\"}", fieldObject.id))
for _, websocketConnectionContext := range fieldContext.podMap[podId].websocketConnectionMap {
fieldContext.queueMessageToClient(websocketConnectionContext.sessionId, messageToClient)
}
}
开发者ID:gk-turnip,项目名称:server,代码行数:13,代码来源:fieldContext.go
示例6: doTerrainSvg
func (fieldContext *FieldContextDef) doTerrainSvg(websocketConnectionContext *websocketConnectionContextDef) *gkerr.GkErrDef {
var terrainSentMap map[string]string = make(map[string]string)
var gkErr *gkerr.GkErrDef
var singleSession *ses.SingleSessionDef
singleSession = fieldContext.sessionContext.GetSessionFromId(websocketConnectionContext.sessionId)
var terrainJson *terrainJsonDef
terrainJson = fieldContext.podMap[singleSession.GetCurrentPodId()].terrainJson
for i := 0; i < len(terrainJson.jsonMapData.TileList); i++ {
var terrain string = terrainJson.jsonMapData.TileList[i].Terrain
var ok bool
if terrain != "" {
_, ok = terrainSentMap[terrain]
if !ok {
var messageToClient *message.MessageToClientDef = new(message.MessageToClientDef)
gkErr = messageToClient.BuildSvgMessageToClient(fieldContext.terrainSvgDir, message.SetTerrainSvgReq, terrain, nil)
if gkErr != nil {
return gkErr
}
fieldContext.queueMessageToClient(websocketConnectionContext.sessionId, messageToClient)
terrainSentMap[terrain] = terrain
}
}
}
for i := 0; i < len(terrainJson.jsonMapData.ObjectList); i++ {
var terrain string = terrainJson.jsonMapData.ObjectList[i].Object
var ok bool
_, ok = terrainSentMap[terrain]
if !ok {
var messageToClient *message.MessageToClientDef = new(message.MessageToClientDef)
gkErr = messageToClient.BuildSvgMessageToClient(fieldContext.terrainSvgDir, message.SetTerrainSvgReq, terrain, nil)
if gkErr != nil {
return gkErr
}
fieldContext.queueMessageToClient(websocketConnectionContext.sessionId, messageToClient)
terrainSentMap[terrain] = terrain
}
}
return nil
}
开发者ID:gk-turnip,项目名称:server,代码行数:50,代码来源:fieldContext.go
示例7: handleGameInitial
func (httpContext *httpContextDef) handleGameInitial(res http.ResponseWriter, req *http.Request) {
var gameData gameDataDef
var gkErr *gkerr.GkErrDef
var singleSession *ses.SingleSessionDef
var token string
token = req.Form.Get(_tokenParam)
gklog.LogTrace("got token: " + token)
var userName string
userName = httpContext.tokenContext.getUserFromToken(token)
gklog.LogTrace("got username: " + userName)
if len(userName) < 3 {
httpContext.redirectToError("not valid token", res, req)
return
}
var lastPodId int32
lastPodId, gkErr = httpContext.persistenceContext.GetLastPodId(userName)
if gkErr != nil {
errorMessage := "persistenceContext.getLastPodName"
gklog.LogGkErr(errorMessage, gkErr)
httpContext.redirectToError(errorMessage, res, req)
return
}
singleSession = httpContext.sessionContext.NewSingleSession(userName, lastPodId, req.RemoteAddr)
gameData.Title = "game"
gameData.WebAddressPrefix = httpContext.gameConfig.WebAddressPrefix
gameData.WebsocketAddressPrefix = httpContext.gameConfig.WebsocketAddressPrefix
gameData.AudioAddressPrefix = httpContext.gameConfig.AudioAddressPrefix
gameData.WebsocketPath = httpContext.gameConfig.WebsocketPath
gameData.SessionId = singleSession.GetSessionId()
gkErr = _gameTemplate.Build(gameData)
if gkErr != nil {
errorMessage := "_gameTemplate.Build"
gklog.LogGkErr(errorMessage, gkErr)
httpContext.redirectToError(errorMessage, res, req)
return
}
gkErr = _gameTemplate.Send(res, req)
if gkErr != nil {
gklog.LogGkErr("_gameTemplate.Send", gkErr)
return
}
}
开发者ID:gk-turnip,项目名称:server,代码行数:49,代码来源:httpContext.go
示例8: doTerrainMap
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
}
开发者ID:gk-turnip,项目名称:server,代码行数:31,代码来源:fieldContext.go
示例9: getWebsocketConnectionContextById
func (fieldContext *FieldContextDef) getWebsocketConnectionContextById(sessionId string) (*websocketConnectionContextDef, *gkerr.GkErrDef) {
var websocketConnectionContext *websocketConnectionContextDef = nil
var gkErr *gkerr.GkErrDef
var ok bool
var singleSession *ses.SingleSessionDef
singleSession = fieldContext.sessionContext.GetSessionFromId(sessionId)
var podId int32 = singleSession.GetCurrentPodId()
websocketConnectionContext, ok = fieldContext.podMap[podId].websocketConnectionMap[sessionId]
if !ok {
gkErr = gkerr.GenGkErr("getWebsocketConnectionContextById", nil, ERROR_ID_COULD_NOT_GET_WEBSOCKET_CONNECTION_CONTEXT)
return nil, gkErr
}
return websocketConnectionContext, nil
}
开发者ID:gk-turnip,项目名称:server,代码行数:17,代码来源:fieldContext.go
示例10: 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
}
开发者ID:gk-turnip,项目名称:server,代码行数:46,代码来源:handleWebsocketOpened.go
示例11: setAllAvatars
func (fieldContext *FieldContextDef) setAllAvatars(sessionId string, fieldObject *fieldObjectDef) {
var messageToClient *message.MessageToClientDef = new(message.MessageToClientDef)
messageToClient.Command = message.SetSvgReq
messageToClient.JsonData = []byte(fmt.Sprintf("{ \"id\": \"%s\", \"x\": %d, \"y\": %d, \"z\": %d }", fieldObject.id, fieldObject.isoXYZ.X, fieldObject.isoXYZ.Y, fieldObject.isoXYZ.Z))
var singleSession *ses.SingleSessionDef
singleSession = fieldContext.sessionContext.GetSessionFromId(sessionId)
var podId int32 = singleSession.GetCurrentPodId()
for _, websocketConnectionContext := range fieldContext.podMap[podId].websocketConnectionMap {
gklog.LogTrace("compare session " + websocketConnectionContext.sessionId + " " + sessionId)
if websocketConnectionContext.sessionId != sessionId {
gklog.LogTrace("Trace about to queue up move command")
fieldContext.queueMessageToClient(websocketConnectionContext.sessionId, messageToClient)
}
}
}
开发者ID:gk-turnip,项目名称:server,代码行数:20,代码来源:handleSetSvgReq.go
示例12: handleSetAvatarSvgReq
func (fieldContext *FieldContextDef) handleSetAvatarSvgReq(messageFromClient *message.MessageFromClientDef) *gkerr.GkErrDef {
var gkErr *gkerr.GkErrDef
var err error
var setSvg setSvgDef
gklog.LogTrace("json raw: " + string(messageFromClient.JsonData))
err = json.Unmarshal(messageFromClient.JsonData, &setSvg)
if err != nil {
gkErr = gkerr.GenGkErr("json.Unmarshal", err, ERROR_ID_JSON_UNMARSHAL)
return gkErr
}
var singleSession *ses.SingleSessionDef
singleSession = fieldContext.sessionContext.GetSessionFromId(messageFromClient.SessionId)
var podId int32 = singleSession.GetCurrentPodId()
var fieldObject *fieldObjectDef
var ok bool
fieldObject, ok = fieldContext.podMap[podId].avatarMap[setSvg.Id]
if ok {
var cord int
cord, _ = strconv.Atoi(setSvg.X)
fieldObject.isoXYZ.X = int16(cord)
cord, _ = strconv.Atoi(setSvg.Y)
fieldObject.isoXYZ.Y = int16(cord)
cord, _ = strconv.Atoi(setSvg.Z)
fieldObject.isoXYZ.Z = int16(cord)
gklog.LogTrace("one")
fieldContext.setAllAvatars(messageFromClient.SessionId, fieldObject)
} else {
gkErr = gkerr.GenGkErr("move object", nil, ERROR_ID_COULD_NOT_FIND_OBJECT_TO_MOVE)
gklog.LogGkErr("", gkErr)
}
return nil
}
开发者ID:gk-turnip,项目名称:server,代码行数:39,代码来源:handleSetSvgReq.go
示例13: removeAllAvatarBySessionId
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)
}
}
}
开发者ID:gk-turnip,项目名称:server,代码行数:23,代码来源:fieldContext.go
示例14: 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
}
开发者ID:gk-turnip,项目名称:server,代码行数:25,代码来源:handleUserPrefReq.go
示例15: handleNewPodReq
// websocketConnectionContext entry must be moved from old pod to new pod
func (fieldContext *FieldContextDef) handleNewPodReq(messageFromClient *message.MessageFromClientDef) *gkerr.GkErrDef {
var newPodReq newPodReqDef
var gkErr *gkerr.GkErrDef
var err error
err = json.Unmarshal(messageFromClient.JsonData, &newPodReq)
if err != nil {
gkErr = gkerr.GenGkErr("json.Unmarshal", err, ERROR_ID_JSON_UNMARSHAL)
return gkErr
}
var destinationX, destinationY, destinationZ int
destinationX, _ = strconv.Atoi(newPodReq.X)
destinationY, _ = strconv.Atoi(newPodReq.Y)
destinationZ, _ = strconv.Atoi(newPodReq.Z)
var websocketConnectionContext *websocketConnectionContextDef
websocketConnectionContext, gkErr = fieldContext.getWebsocketConnectionContextById(messageFromClient.SessionId)
if gkErr != nil {
return gkErr
}
var singleSession *ses.SingleSessionDef
singleSession = fieldContext.sessionContext.GetSessionFromId(websocketConnectionContext.sessionId)
var oldPodId int32 = singleSession.GetCurrentPodId()
var newPodId int64
newPodId, _ = strconv.ParseInt(newPodReq.PodId, 10, 32)
if (fieldContext.isPodIdValid(int32(newPodId))) && (oldPodId != int32(newPodId)) {
gkErr = fieldContext.moveAllAvatarBySessionId(messageFromClient.SessionId, oldPodId, int32(newPodId), int16(destinationX), int16(destinationY), int16(destinationZ))
if gkErr != nil {
gklog.LogGkErr("", gkErr)
return gkErr
}
delete(fieldContext.podMap[oldPodId].websocketConnectionMap, messageFromClient.SessionId)
singleSession.SetCurrentPodId(int32(newPodId))
fieldContext.podMap[int32(newPodId)].websocketConnectionMap[messageFromClient.SessionId] = websocketConnectionContext
gkErr = fieldContext.uploadNewPodInfo(websocketConnectionContext, int32(newPodId))
if gkErr != nil {
gklog.LogGkErr("", gkErr)
return gkErr
}
gkErr = fieldContext.reAddAvatarBySessionId(messageFromClient.SessionId, int32(newPodId))
if gkErr != nil {
gklog.LogGkErr("", gkErr)
return gkErr
}
} else {
gkErr = gkerr.GenGkErr(fmt.Sprintf("invalid podId: %d", newPodId), nil, ERROR_ID_INVALID_POD_ID)
gklog.LogGkErr("", gkErr)
return gkErr
}
return nil
}
开发者ID:Earth4,项目名称:server,代码行数:66,代码来源:handleNewPodReq.go
注:本文中的gk/game/ses.SingleSessionDef类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论