Пример #1
0
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
}
Пример #2
0
// 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
}
Пример #3
0
// I think this should be (mostly) moved to the message package
func (fieldContext *FieldContextDef) sendUserName(websocketConnectionContext *websocketConnectionContextDef, userName string) *gkerr.GkErrDef {

	var messageToClient *message.MessageToClientDef = new(message.MessageToClientDef)
	messageToClient.Command = message.UserNameReq
	messageToClient.JsonData = []byte("{ \"userName\": \"" + userName + "\" }")
	fieldContext.queueMessageToClient(websocketConnectionContext.sessionId, messageToClient)

	return nil
}
Пример #4
0
func (fieldContext *FieldContextDef) doTerrainClear(websocketConnectionContext *websocketConnectionContextDef) *gkerr.GkErrDef {

	var messageToClient *message.MessageToClientDef = new(message.MessageToClientDef)
	messageToClient.Command = message.ClearTerrainReq
	messageToClient.JsonData = []byte("{}")
	messageToClient.Data = make([]byte, 0, 0)
	fieldContext.queueMessageToClient(websocketConnectionContext.sessionId, messageToClient)

	return nil
}
Пример #5
0
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)
	}
}
Пример #6
0
func (fieldContext *FieldContextDef) sendAllPastChat(websocketConnectionContext *websocketConnectionContextDef) *gkerr.GkErrDef {

	var messageToClient *message.MessageToClientDef = new(message.MessageToClientDef)
	var gkErr *gkerr.GkErrDef

	messageToClient.Command = message.SendPastChatReq
	messageToClient.JsonData, gkErr = fieldContext.getPastChatJsonData()
	if gkErr != nil {
		return gkErr
	}
	messageToClient.Data = make([]byte, 0, 0)

	fieldContext.queueMessageToClient(websocketConnectionContext.sessionId, messageToClient)

	return nil
}
Пример #7
0
func (fieldContext *FieldContextDef) sendUserPrefRestore(websocketConnectionContext *websocketConnectionContextDef) *gkerr.GkErrDef {

	var messageToClient *message.MessageToClientDef = new(message.MessageToClientDef)
	var gkErr *gkerr.GkErrDef

	messageToClient.Command = message.UserPrefRestoreReq
	messageToClient.JsonData, gkErr = fieldContext.getUserPrefJsonData(websocketConnectionContext)
	if gkErr != nil {
		return gkErr
	}
	messageToClient.Data = make([]byte, 0, 0)

	fieldContext.queueMessageToClient(websocketConnectionContext.sessionId, messageToClient)

	return nil
}
Пример #8
0
func (fieldContext *FieldContextDef) sendEveryoneRainEvent() {
	var rainCommand string

	if fieldContext.rainContext.rainCurrentlyOn {
		rainCommand = message.TurnOnRainReq
	} else {
		rainCommand = message.TurnOffRainReq
	}
	var podId int32 = firstPodId // rain only in the first pod

	for _, websocketConnectionContext := range fieldContext.podMap[podId].websocketConnectionMap {
		var messageToClient *message.MessageToClientDef = new(message.MessageToClientDef)
		messageToClient.Command = rainCommand
		fieldContext.queueMessageToClient(websocketConnectionContext.sessionId, messageToClient)
	}
}
Пример #9
0
func (fieldContext *FieldContextDef) handlePingReq(messageFromClient *message.MessageFromClientDef) *gkerr.GkErrDef {

	var messageToClient *message.MessageToClientDef = new(message.MessageToClientDef)
	var pingReq pingReqDef
	var gkErr *gkerr.GkErrDef
	var err error

	err = json.Unmarshal(messageFromClient.JsonData, &pingReq)
	if err != nil {
		gkErr = gkerr.GenGkErr("json.Unmarshal", err, ERROR_ID_JSON_UNMARSHAL)
		return gkErr
	}

	messageToClient.Command = message.PingRes
	messageToClient.JsonData = []byte(fmt.Sprintf("{ \"pingId\": \"%s\" }", pingReq.PingId))

	fieldContext.queueMessageToClient(messageFromClient.SessionId, messageToClient)

	return nil
}
Пример #10
0
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)
		}
	}
}
Пример #11
0
func (fieldContext *FieldContextDef) removeDandelion() {

	var messageToClient *message.MessageToClientDef = new(message.MessageToClientDef)
	var fileName = "dandelion"

	messageToClient.Command = message.DelSvgReq

	for podId, podEntry := range fieldContext.podMap {
		for _, fieldObject := range podEntry.objectMap {
			if fieldObject.fileName == fileName {
				messageToClient.JsonData = []byte(fmt.Sprintf("{ \"id\": \"%s\"}", fieldObject.id))
				for _, websocketConnectionContext := range podEntry.websocketConnectionMap {
					fieldContext.queueMessageToClient(websocketConnectionContext.sessionId, messageToClient)
				}
				fieldContext.delTerrainObject(podId, fieldObject)
				break
			}
		}
	}
}
Пример #12
0
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)
		}
	}
}
Пример #13
0
func (fieldContext *FieldContextDef) uploadNewPodInfo(websocketConnectionContext *websocketConnectionContextDef, podId int32) *gkerr.GkErrDef {

	var gkErr *gkerr.GkErrDef

	gkErr = fieldContext.loadTerrain(websocketConnectionContext)
	if gkErr != nil {
		return gkErr
	}

	gkErr = fieldContext.sendAllAvatarObjects(podId, websocketConnectionContext)
	if gkErr != nil {
		return gkErr
	}

	var messageToClient *message.MessageToClientDef = new(message.MessageToClientDef)
	var podTitle string = fieldContext.podMap[podId].title
	messageToClient.Command = message.NewPodTitleReq
	messageToClient.JsonData = []byte(fmt.Sprintf("{ \"podTitle\": \"%s\" }", podTitle))
	messageToClient.Data = make([]byte, 0, 0)

	fieldContext.queueMessageToClient(websocketConnectionContext.sessionId, messageToClient)

	return nil
}