本文整理汇总了Golang中gk/gklog.LogTrace函数的典型用法代码示例。如果您正苦于以下问题:Golang LogTrace函数的具体用法?Golang LogTrace怎么用?Golang LogTrace使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了LogTrace函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: 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
}
示例2: getUserFromToken
func (tokenContext *tokenContextDef) getUserFromToken(token string) string {
var ok bool
var tokenEntry *tokenEntryDef
tokenContext.purgeOldTokenEntries()
tokenContext.tokenMutex.Lock()
defer tokenContext.tokenMutex.Unlock()
gklog.LogTrace(fmt.Sprintf("getting token entry: %+v", token))
tokenEntry, ok = tokenContext.tokenMap[token]
if !ok {
gklog.LogTrace("did not find")
return ""
}
var userName string
userName = tokenEntry.userName
gklog.LogTrace("found " + userName)
// token cannot be reused
// but for now we allow it to be reused :)
//delete(tokenContext.tokenMap,tokenEntry.tokenId)
return userName
}
示例3: moveAllAvatarBySessionId
// an avatar is moving from one pod to another
// so delete any object matching by sessionId from old pod
// then add them to the new pod
func (fieldContext *FieldContextDef) moveAllAvatarBySessionId(sessionId string, oldPodId int32, newPodId int32, destinationX int16, destinationY int16, destinationZ int16) *gkerr.GkErrDef {
gklog.LogTrace("moving all object by session id")
var gkErr *gkerr.GkErrDef
for _, fieldObject := range fieldContext.podMap[oldPodId].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)
for _, websocketConnectionContext := range fieldContext.podMap[oldPodId].websocketConnectionMap {
if sessionId == websocketConnectionContext.sessionId {
fieldObject.isoXYZ.X = destinationX
fieldObject.isoXYZ.Y = destinationY
fieldObject.isoXYZ.Z = destinationZ
gklog.LogTrace(fmt.Sprintf("moveAllAvatarBySessionId new destination: %d,%d,%d", fieldObject.isoXYZ.X, fieldObject.isoXYZ.Y, fieldObject.isoXYZ.Z))
}
fieldContext.queueMessageToClient(websocketConnectionContext.sessionId, messageToClient)
}
for _, websocketConnectionContext := range fieldContext.podMap[newPodId].websocketConnectionMap {
gkErr = fieldContext.sendSingleAvatarObject(websocketConnectionContext, fieldObject)
if gkErr != nil {
return gkErr
}
}
delete(fieldContext.podMap[oldPodId].avatarMap, fieldObject.id)
fieldContext.podMap[newPodId].avatarMap[fieldObject.id] = fieldObject
}
}
return nil
}
示例4: 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
}
}
示例5: ServeHTTP
func (tokenContext *tokenContextDef) ServeHTTP(res http.ResponseWriter, req *http.Request) {
path := req.URL.Path
gklog.LogTrace(req.Method)
gklog.LogTrace(path)
if req.Method == _methodGet || req.Method == _methodPost {
if gknet.RequestMatches(path, _tokenRequest) {
tokenContext.handleTokenRequest(res, req)
} else {
http.NotFound(res, req)
}
} else {
http.NotFound(res, req)
}
}
示例6: queueMessageToClient
func (fieldContext *FieldContextDef) queueMessageToClient(sessionId string, messageToClient *message.MessageToClientDef) {
var websocketConnectionContext *websocketConnectionContextDef
var gkErr *gkerr.GkErrDef
gklog.LogTrace("queu up message " + messageToClient.Command)
websocketConnectionContext, gkErr =
fieldContext.getWebsocketConnectionContextById(sessionId)
if gkErr != nil {
gklog.LogGkErr("", gkErr)
} else {
var localSize int
websocketConnectionContext.toClientQueue.mutex.Lock()
localSize = websocketConnectionContext.toClientQueue.queueSize
websocketConnectionContext.toClientQueue.mutex.Unlock()
if localSize > MAX_MESSAGES_TO_CLIENT_QUEUE {
gkErr = gkerr.GenGkErr("messageToClient queue overflow, dropping message", nil, ERROR_ID_MESSAGE_TO_CLIENT_QUEUE_OVERFLOW)
gklog.LogGkErr("", gkErr)
} else {
websocketConnectionContext.toClientQueue.mutex.Lock()
websocketConnectionContext.toClientQueue.queueSize += 1
websocketConnectionContext.toClientQueue.mutex.Unlock()
websocketConnectionContext.toClientQueue.messagesChan <- messageToClient
}
}
}
示例7: runQueue
func (websocketConnectionContext *websocketConnectionContextDef) runQueue() {
var done bool
done = false
for !done {
var messageToClient *message.MessageToClientDef
select {
case messageToClient = <-websocketConnectionContext.toClientQueue.messagesChan:
case done = <-websocketConnectionContext.toClientQueue.doneChan:
}
if !done {
gklog.LogTrace("got message to send: " + messageToClient.Command)
select {
case websocketConnectionContext.messageToClientChan <- messageToClient:
case done = <-websocketConnectionContext.toClientQueue.doneChan:
}
if !done {
websocketConnectionContext.toClientQueue.mutex.Lock()
websocketConnectionContext.toClientQueue.queueSize -= 1
websocketConnectionContext.toClientQueue.mutex.Unlock()
}
}
}
}
示例8: checkTokenExpire
// purge any expired tokens
func checkTokenExpire() {
expireTime := time.Now().Add(time.Duration(-1) * _tokenExpiry)
for k, v := range _tokenMap {
if expireTime.After(v.createdDate) {
gklog.LogTrace(fmt.Sprintf("removing map entry (timeout) k: %+v v: %+v", k, v))
delete(_tokenMap, k)
}
}
}
示例9: NewTemplate
func NewTemplate(templateDir string, templateName string) (*TemplateDef, *gkerr.GkErrDef) {
var gkTemplate *TemplateDef = new(TemplateDef)
gkTemplate.tmpl = template.New(templateName)
var file *os.File
var templateListFileName string
var err error
templateListFileName = templateDir + string(os.PathSeparator) + templateName + ".txt"
file, err = os.Open(templateListFileName)
if err != nil {
return nil, gkerr.GenGkErr("os.Open", err, ERROR_ID_OPEN_TEMPLATE_LIST)
}
defer file.Close()
var br *bufio.Reader
localFileNames := make([]string, 0, 0)
br = bufio.NewReader(file)
for {
var line string
line, err = br.ReadString('\n')
line = strings.Trim(line, "\r\n\t ")
if line != "" {
localFileNames = append(localFileNames, templateDir+string(os.PathSeparator)+line)
}
if err != nil {
if err == io.EOF {
break
}
return nil, gkerr.GenGkErr("br.ReadString", err, ERROR_ID_READ_TEMPLATE_LIST)
}
}
// localFileNames = make([]string, len(fileNames), len(fileNames))
// for i := 0; i < len(fileNames); i++ {
// localFileNames[i] = templateDir + string(os.PathSeparator) + fileNames[i] + ".html"
// }
gklog.LogTrace(fmt.Sprintf("localFileNames: %+v", localFileNames))
_, err = gkTemplate.tmpl.ParseFiles(localFileNames...)
if err != nil {
return nil, gkerr.GenGkErr("tmpl.ParseFiles", err, ERROR_ID_PARSE_FILES)
}
return gkTemplate, nil
}
示例10: CheckToken
// check if the token / userName is valid
func CheckToken(token string, userName string) bool {
_tokenMapMutex.Lock()
defer _tokenMapMutex.Unlock()
checkTokenExpire()
var tokenEntry tokenEntryDef
var ok bool
tokenEntry, ok = _tokenMap[token]
gklog.LogTrace(fmt.Sprintf("check map entry k: %+v v: %+v", token, ok))
if ok {
gklog.LogTrace(fmt.Sprintf("check map entry k: %+v v: %+v", token, tokenEntry))
if tokenEntry.userName == userName {
return true
}
}
return false
}
示例11: ServeHTTP
func (httpContext *httpContextDef) ServeHTTP(res http.ResponseWriter, req *http.Request) {
if _gameTemplate == nil {
gklog.LogError("missing call to gameInit")
}
path := req.URL.Path
gklog.LogTrace(req.Method)
gklog.LogTrace(path)
if req.Method == _methodGet || req.Method == _methodPost {
if gknet.RequestMatches(path, _gameRequest) {
httpContext.handleGameRequest(res, req)
} else {
http.NotFound(res, req)
}
} else {
http.NotFound(res, req)
}
}
示例12: 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)
}
}
}
示例13: purgeOldTokenEntries
func (tokenContext *tokenContextDef) purgeOldTokenEntries() {
tokenContext.tokenMutex.Lock()
defer tokenContext.tokenMutex.Unlock()
for tokenId, tokenEntry := range tokenContext.tokenMap {
if tokenEntry.createdDate.Add(time.Second * _tokenTimeoutSeconds).Before(time.Now()) {
gklog.LogTrace(fmt.Sprintf("purge token entry: %+v", tokenEntry))
delete(tokenContext.tokenMap, tokenId)
}
}
}
示例14: ServeHTTP
func (loginConfig *loginConfigDef) ServeHTTP(res http.ResponseWriter, req *http.Request) {
if _loginTemplate == nil {
gklog.LogError("missing call to loginInit")
}
path := req.URL.Path
gklog.LogTrace(req.Method)
gklog.LogTrace(path)
if req.Method == _methodGet || req.Method == _methodPost {
if gknet.RequestMatches(path, _loginServer) {
handleLogin(loginConfig, res, req)
} else {
http.NotFound(res, req)
}
} else {
http.NotFound(res, req)
}
}
示例15: 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
}