示例#1
0
        public static byte[] SerializeConfigurationToken_v1(this ConfigurationTokenService service, Model.ExtensionConfiguration configuration)
        {
            // Generate the Flatbuffer token payload
            var builder = new FlatBufferBuilder(512);

            var fbConfiguration = new TwitchAchievementTracker.Flatbuffer.v1.Configuration();

            fbConfiguration.version = configuration.Version;


            var xConfig     = configuration.XBoxLiveConfig as Model.XApiConfiguration;
            var steamConfig = configuration.SteamConfig as Model.SteamConfiguration;

            switch (configuration.ActiveConfig)
            {
            case Model.ActiveConfig.XBoxLive:

                var flatBufferXBoxConfig = new XApiConfiguration();
                flatBufferXBoxConfig.xApiKey      = xConfig.XApiKey;
                flatBufferXBoxConfig.streamerXuid = string.IsNullOrEmpty(xConfig.StreamerXuid) ? 0 : UInt64.Parse(xConfig.StreamerXuid);
                flatBufferXBoxConfig.titleId      = string.IsNullOrEmpty(xConfig.TitleId) ? 0 : UInt32.Parse(xConfig.TitleId);
                flatBufferXBoxConfig.locale       = xConfig.Locale ?? "en-US";
                fbConfiguration.config            = new FlatBufferUnion <XApiConfiguration, SteamConfiguration>(flatBufferXBoxConfig);

                break;

            case Model.ActiveConfig.Steam:
                var webKeyString          = builder.CreateString(steamConfig.WebApiKey);
                var steamId               = UInt64.Parse(steamConfig.SteamId);
                var appId                 = steamConfig.AppId;
                var steamLocale           = builder.CreateString(steamConfig.Locale ?? "english");
                var flatBufferSteamConfig = new SteamConfiguration();
                flatBufferSteamConfig.webApiKey = steamConfig.WebApiKey;
                flatBufferSteamConfig.steamId   = string.IsNullOrEmpty(steamConfig.SteamId) ? 0 : UInt64.Parse(steamConfig.SteamId);
                flatBufferSteamConfig.appId     = string.IsNullOrEmpty(steamConfig.AppId) ? 0 : UInt32.Parse(steamConfig.AppId);
                fbConfiguration.config          = new FlatBufferUnion <XApiConfiguration, SteamConfiguration>(flatBufferSteamConfig);

                break;

            default:
                throw new NotSupportedException("Unknown configuration platform");
            }

            int maxBytesNeeded = FlatBufferSerializer.Default.GetMaxSize(fbConfiguration);

            byte[] outBuffer    = new byte[maxBytesNeeded];
            int    bytesWritten = FlatBufferSerializer.Default.Serialize(fbConfiguration, outBuffer);

            return(new ArraySegment <byte>(outBuffer, 0, bytesWritten).ToArray());
        }
示例#2
0
        public static byte[] EncodeConfigurationToken_v1(this ConfigurationTokenService service, Model.ExtensionConfiguration configuration)
        {
            byte[] payload = service.SerializeConfigurationToken_v1(configuration);

            // Encrypt the token
            return(service.Encrypt(payload));
        }