private void forceTearDown(object sfsToTeardown) { if (!object.ReferenceEquals(mt.smartFoxRef, sfsToTeardown)) { return; } string text = mt.ClientRoomName; mt.teardown(); if (mt.TryClearSfsRoomToLeave(out var room)) { if (text == null) { text = room.Name; } mt.triggerEvent(GameServerEvent.ROOM_LEAVE, text); } }
private void onExtensionResponse(BaseEvent evt) { try { ISFSObject iSFSObject = (ISFSObject)evt.Params["params"]; if (mt.SmartFoxEncryptor != null) { mt.SmartFoxEncryptor.DecryptParameters(iSFSObject); } int?userId = null; if (iSFSObject.ContainsKey("senderId")) { userId = iSFSObject.GetInt("senderId"); } SmartfoxCommand?smartfoxCommand = SmartFoxCommand.FromString((string)evt.Params["cmd"]); if (!smartfoxCommand.HasValue) { return; } object data = null; GameServerEvent?gameServerEvent = null; switch (smartfoxCommand.Value) { case SmartfoxCommand.CHAT_ACTIVITY: gameServerEvent = GameServerEvent.CHAT_ACTIVITY_RECEIVED; data = getSessionId(userId); break; case SmartfoxCommand.CHAT_ACTIVITY_CANCEL: gameServerEvent = GameServerEvent.CHAT_ACTIVITY_CANCEL_RECEIVED; data = getSessionId(userId); break; case SmartfoxCommand.CHAT: gameServerEvent = GameServerEvent.CHAT_MESSAGE_RECEIVED; data = mt.JsonService.Deserialize <ReceivedChatMessage>(iSFSObject.GetUtfString("msg")); break; case SmartfoxCommand.GET_SERVER_TIME: timeStampRecieved(iSFSObject.GetLong("ct"), iSFSObject.GetLong("st")); break; case SmartfoxCommand.SERVER_TIME_ERROR: fetchServerTimestamp(fetchEncryptionKeyAfterwards: false); break; case SmartfoxCommand.GET_ROOM_ENCRYPTION_KEY: encryptionKeyReceived(iSFSObject.GetUtfString("ek")); break; case SmartfoxCommand.ENCRYPTION_KEY_ERROR: Log.LogError(this, "Failed to get room encryption key."); mt.teardown(); gameServerEvent = GameServerEvent.ROOM_JOIN_ERROR; data = null; break; case SmartfoxCommand.LOCOMOTION_ACTION: gameServerEvent = GameServerEvent.USER_LOCO_ACTION; data = locomotionActionEventFromProps(userId.Value, iSFSObject); break; case SmartfoxCommand.PROTOTYPE: { gameServerEvent = GameServerEvent.PROTOTYPE_ACTION; PrototypeAction prototypeAction = default(PrototypeAction); prototypeAction.userid = getSessionId(userId); prototypeAction.data = JsonMapper.ToObject(iSFSObject.GetUtfString("data")); data = prototypeAction; break; } case SmartfoxCommand.SERVER_OBJECTIVE_COMPLETED: gameServerEvent = GameServerEvent.QUEST_OBJECTIVES_UPDATED; data = mt.JsonService.Deserialize <SignedResponse <QuestObjectives> >(iSFSObject.GetUtfString("data")); break; case SmartfoxCommand.SERVER_QUEST_ERROR: gameServerEvent = GameServerEvent.QUEST_ERROR; data = null; break; case SmartfoxCommand.SET_QUEST_STATES: gameServerEvent = GameServerEvent.QUEST_DATA_SYNCED; data = null; break; case SmartfoxCommand.USE_CONSUMABLE: { gameServerEvent = GameServerEvent.CONSUMABLE_USED; ConsumableEvent consumableEvent = default(ConsumableEvent); consumableEvent.SessionId = getSessionId(userId); consumableEvent.Type = iSFSObject.GetUtfString("type"); data = consumableEvent; break; } case SmartfoxCommand.REUSE_FAILED: { gameServerEvent = GameServerEvent.CONSUMABLE_REUSE_FAILED; ConsumableUseFailureEvent consumableUseFailureEvent = default(ConsumableUseFailureEvent); consumableUseFailureEvent.Type = iSFSObject.GetUtfString("type"); consumableUseFailureEvent.Properties = JsonMapper.ToObject(iSFSObject.GetUtfString("prop")); data = consumableUseFailureEvent; break; } case SmartfoxCommand.CONSUMABLE_MMO_DEPLOYED: if (iSFSObject.ContainsKey("ownerId") && iSFSObject.ContainsKey("senderId")) { gameServerEvent = GameServerEvent.CONSUMABLE_MMO_DEPLOYED; ConsumableMMODeployedEvent consumableMMODeployedEvent = default(ConsumableMMODeployedEvent); consumableMMODeployedEvent.SessionId = getSessionId(iSFSObject.GetInt("ownerId")); consumableMMODeployedEvent.ExperienceId = iSFSObject.GetInt("senderId"); data = consumableMMODeployedEvent; } break; case SmartfoxCommand.SET_CONSUMABLE_PARTIAL_COUNT: gameServerEvent = GameServerEvent.COMSUMBLE_PARTIAL_COUNT_SET; data = mt.JsonService.Deserialize <SignedResponse <UsedConsumable> >(iSFSObject.GetUtfString("data")); break; case SmartfoxCommand.RECEIVED_REWARDS: gameServerEvent = GameServerEvent.RECEIVED_REWARDS; data = mt.JsonService.Deserialize <SignedResponse <RewardedUserCollectionJsonHelper> >(iSFSObject.GetUtfString("reward")); break; case SmartfoxCommand.RECEIVED_REWARDS_DELAYED: gameServerEvent = GameServerEvent.RECEIVED_REWARDS_DELAYED; data = mt.JsonService.Deserialize <SignedResponse <RewardedUserCollectionJsonHelper> >(iSFSObject.GetUtfString("reward")); break; case SmartfoxCommand.RECEIVED_ROOOM_REWARDS: gameServerEvent = GameServerEvent.RECEIVED_ROOOM_REWARDS; data = mt.JsonService.Deserialize <SignedResponse <InRoomRewards> >(iSFSObject.GetUtfString("reward")); break; case SmartfoxCommand.PROGRESSION_LEVELUP: { gameServerEvent = GameServerEvent.LEVELUP; UserLevelUpEvent userLevelUpEvent = default(UserLevelUpEvent); userLevelUpEvent.SessionId = getSessionId(userId); userLevelUpEvent.Level = iSFSObject.GetInt("level"); data = userLevelUpEvent; break; } case SmartfoxCommand.ROOM_TRANSIENT_DATA: mt.LastRoomTransientData = mt.JsonService.Deserialize <SignedResponse <TransientData> >(iSFSObject.GetUtfString("d")); break; case SmartfoxCommand.TASK_COUNT: { gameServerEvent = GameServerEvent.TASK_COUNT_UPDATED; TaskProgress taskProgress = default(TaskProgress); taskProgress.taskId = iSFSObject.GetUtfString("t"); taskProgress.counter = iSFSObject.GetInt("c"); data = taskProgress; break; } case SmartfoxCommand.TASK_PROGRESS: gameServerEvent = GameServerEvent.TASK_PROGRESS_UPDATED; data = mt.JsonService.Deserialize <SignedResponse <TaskProgress> >(iSFSObject.GetUtfString("d")); break; case SmartfoxCommand.GET_SIGNED_STATE: gameServerEvent = GameServerEvent.STATE_SIGNED; data = mt.JsonService.Deserialize <SignedResponse <InWorldState> >(iSFSObject.GetUtfString("data")); break; case SmartfoxCommand.GET_PLAYER_LOCATION: gameServerEvent = GameServerEvent.PLAYER_LOCATION_RECEIVED; data = SmartFoxGameServerClientShared.deserializeVec3(iSFSObject, "pos"); break; case SmartfoxCommand.PLAYER_NOT_FOUND: gameServerEvent = GameServerEvent.PLAYER_NOT_FOUND; break; case SmartfoxCommand.PARTY_GAME_START: gameServerEvent = GameServerEvent.PARTY_GAME_START; data = partyGameStartEventFromProps(iSFSObject); break; case SmartfoxCommand.PARTY_GAME_START_V2: gameServerEvent = GameServerEvent.PARTY_GAME_START_V2; data = partyGameStartEventV2FromProps(iSFSObject); break; case SmartfoxCommand.PARTY_GAME_END: gameServerEvent = GameServerEvent.PARTY_GAME_END; data = partyGameEndEventFromProps(iSFSObject); break; case SmartfoxCommand.PARTY_GAME_MESSAGE: gameServerEvent = GameServerEvent.PARTY_GAME_MESSAGE; data = partyGameMessageEventFromProps(iSFSObject); break; case SmartfoxCommand.IGLOO_UPDATED: gameServerEvent = GameServerEvent.IGLOO_UPDATED; data = iSFSObject.GetUtfString("igloo_id"); break; case SmartfoxCommand.FORCE_LEAVE: gameServerEvent = GameServerEvent.FORCE_LEAVE; data = mt.JsonService.Deserialize <ZoneId>(iSFSObject.GetUtfString("zone_id")); break; } if (gameServerEvent.HasValue) { mt.triggerEvent(gameServerEvent.Value, data); } } catch (JsonException ex) { Log.LogNetworkError(this, "Error occurred getting data from SFS: " + ex.Message); } }