示例#1
0
        //Temporarily store group visibility information for LoadDeck. //bug (google) #20

        public void LoadDeck(IDeck deck, bool limited)
        {
            var def    = Program.GameEngine.Definition;
            int nCards = deck.CardCount();
            var ids    = new int[nCards];
            var keys   = new Guid[nCards];
            var cards  = new Card[nCards];
            var groups = new Play.Group[nCards];
            var sizes  = new string[nCards];
            var gtmps  = new List <GrpTmp>(); //for temp groups visibility
            int j      = 0;

            foreach (var section in deck.Sections)
            {
                { // Add cards to LoadedCards deck
                    if (!LoadedCards.Sections.Any(x => x.Name == section.Name))
                    {
                        // Add section
                        ((ObservableCollection <ObservableSection>)LoadedCards.Sections).Add(new ObservableSection()
                        {
                            Name   = section.Name,
                            Shared = section.Shared,
                            Cards  = new ObservableCollection <ObservableMultiCard>()
                        });
                    }

                    var loadedCardsSection = LoadedCards.Sections.Single(x => x.Name == section.Name);

                    foreach (var card in section.Cards)
                    {
                        var existingCard = loadedCardsSection.Cards.FirstOrDefault(x => x.Id == card.Id);
                        if (existingCard != null)
                        {
                            existingCard.Quantity += card.Quantity;
                        }
                        else
                        {
                            var newCard = new ObservableMultiCard(card);
                            loadedCardsSection.Cards.AddCard(newCard);
                        }
                    }
                }

                DeckSection sectionDef = null;
                sectionDef = section.Shared ? def.SharedDeckSections[section.Name] : def.DeckSections[section.Name];
                if (sectionDef == null)
                {
                    throw new InvalidFileFormatException("Invalid section '" + section.Name + "' in deck file.");
                }
                var        player = section.Shared ? Player.GlobalPlayer : Player.LocalPlayer;
                Play.Group group  = player.Groups.First(x => x.Name == sectionDef.Group.Name); //TODO: match directly to SectionDef Group instead of name matching

                //In order to make the clients know what the card is (if visibility is set so that they can see it),
                //we have to set the visibility to Nobody, and then after the cards are sent, set the visibility back
                //to what it was. //bug (google) #20
                var gt = new GrpTmp(group, group.Visibility, group.Viewers.ToList());
                if (!gtmps.Contains(gt))
                {
                    gtmps.Add(gt);
                    group.SetVisibility(false, false);
                }

                foreach (IMultiCard element in section.Cards)
                {
                    //DataNew.Entities.Card mod = Definition.GetCardById(element.Id);
                    for (int i = 0; i < element.Quantity; i++)
                    {
                        //for every card in the deck, generate a unique key for it, ID for it
                        var id   = element.GenerateCardId();
                        var card = new Card(player, id, new DataNew.Entities.Card(element), true, element.Size.Name);
                        //   var card = element.ToPlayCard(player);
                        ids[j]  = card.Id;
                        keys[j] = card.Type.Model.Id;
                        //keys[j] = card.GetEncryptedKey();
                        groups[j]  = group;
                        sizes[j]   = card.Size.Name;
                        cards[j++] = card;
                        group.AddAt(card, group.Count);

                        DeckStats.AddCard(card);
                    }

                    // Load images in the background
                    string pictureUri = element.GetPicture();
                    Dispatcher.CurrentDispatcher.BeginInvoke(
                        new Func <string, BitmapImage>(ImageUtils.CreateFrozenBitmap),
                        DispatcherPriority.Background, pictureUri);
                }
            }

            string sleeveString = null;

            if (deck.Sleeve != null)
            {
                try {
                    var loadSleeve = true;

                    if (!IsLocal)
                    {
                        var isSubscriber = SubscriptionModule.Get().IsSubscribed;

                        if (isSubscriber == null)
                        {
                            loadSleeve = false;

                            Log.Warn("Can't set deck sleeve, unable to determin if user is a subscriber.");

                            Program.GameMess.Warning($"Deck sleeve can not be loaded, subscriber status is unknown.");
                        }
                        else if (isSubscriber == false)
                        {
                            loadSleeve = false;

                            Log.Warn("Not authorized to use deck sleeve.");

                            Program.GameMess.Warning($"Deck sleeve can not be used, you're not a subscriber.");
                        }
                    }

                    if (loadSleeve)
                    {
                        Player.LocalPlayer.SetSleeve(deck.Sleeve);

                        sleeveString = Sleeve.ToString(deck.Sleeve);
                    }
                    else
                    {
                        Log.Info("Sleeve will not be loaded.");
                    }
                } catch (Exception ex) {
                    Log.Warn(ex.Message, ex);

                    Program.GameMess.Warning($"There was an error loading the decks sleeve.");
                }
            }

            Program.Client.Rpc.LoadDeck(ids, keys, groups, sizes, sleeveString ?? string.Empty, limited);
            //reset the visibility to what it was before pushing the deck to everybody. //bug (google) #20
            foreach (GrpTmp g in gtmps)
            {
                switch (g.Visibility)
                {
                case GroupVisibility.Everybody:
                    g.Group.SetVisibility(true, false);
                    break;

                case GroupVisibility.Nobody:
                    g.Group.SetVisibility(false, false);
                    break;

                default:
                    foreach (Player p in g.Viewers)
                    {
                        g.Group.AddViewer(p, false);
                    }
                    break;
                }
            }
            gtmps.Clear();
            gtmps.TrimExcess();
        }
示例#2
0
文件: Program.cs 项目: wlk0/OCTGN
        internal static void Start(string[] args, bool isTestRelease)
        {
            Log.Info("Start");
            IsReleaseTest           = isTestRelease;
            GameMessage.MuteChecker = () =>
            {
                if (Program.Client == null)
                {
                    return(false);
                }
                return(Program.Client.Muted != 0);
            };

            Log.Info("Setting SSL Validation Helper");
            SSLHelper = new SSLValidationHelper();

            Log.Info("Setting api path");
            Octgn.Site.Api.ApiClient.DefaultUrl = new Uri(AppConfig.WebsitePath);
            try
            {
                Log.Debug("Setting rendering mode.");
                RenderOptions.ProcessRenderMode = Prefs.UseHardwareRendering ? RenderMode.Default : RenderMode.SoftwareOnly;
            }
            catch (Exception)
            {
                // if the system gets mad, best to leave it alone.
            }

            Log.Info("Setting temp main window");
            Application.Current.MainWindow = new Window();
            try
            {
                Log.Info("Checking if admin");
                var isAdmin = UacHelper.IsProcessElevated && UacHelper.IsUacEnabled;
                if (isAdmin)
                {
                    MessageBox.Show(
                        "You are currently running OCTGN as Administrator. It is recommended that you run as a standard user, or you will most likely run into problems. Please exit OCTGN and run as a standard user.",
                        "WARNING",
                        MessageBoxButton.OK,
                        MessageBoxImage.Exclamation);
                }
            }
            catch (Exception e)
            {
                Log.Warn("Couldn't check if admin", e);
            }

            Log.Info("Creating Lobby Client");
            var handshaker        = new DefaultHandshaker();
            var connectionCreator = new TcpConnectionCreator(handshaker);
            var lobbyClientConfig = new LibraryCommunicationClientConfig(connectionCreator);

            LobbyClient = new Octgn.Library.Communication.Client(lobbyClientConfig, typeof(Program).Assembly.GetName().Version);

            //Log.Info("Adding trace listeners");
            //Debug.Listeners.Add(DebugListener);
            //DebugTrace.Listeners.Add(DebugListener);
            //Trace.Listeners.Add(DebugListener);
            //ChatLog = new CacheTraceListener();
            //Trace.Listeners.Add(ChatLog);
            Log.Info("Creating Game Message Dispatcher");
            GameMess = new GameMessageDispatcher();
            GameMess.ProcessMessage(
                x =>
            {
                for (var i = 0; i < x.Arguments.Length; i++)
                {
                    var arg       = x.Arguments[i];
                    var cardModel = arg as DataNew.Entities.Card;
                    var cardId    = arg as CardIdentity;
                    var card      = arg as Card;
                    if (card != null && (card.FaceUp || card.MayBeConsideredFaceUp))
                    {
                        cardId = card.Type;
                    }

                    if (cardId != null || cardModel != null)
                    {
                        ChatCard chatCard = null;
                        if (cardId != null)
                        {
                            chatCard = new ChatCard(cardId);
                        }
                        else
                        {
                            chatCard = new ChatCard(cardModel);
                        }
                        if (card != null)
                        {
                            chatCard.SetGameCard(card);
                        }
                        x.Arguments[i] = chatCard;
                    }
                    else
                    {
                        x.Arguments[i] = arg == null ? "[?]" : arg.ToString();
                    }
                }
                return(x);
            });

            Log.Info("Registering versioned stuff");

            //BasePath = Path.GetDirectoryName(typeof (Program).Assembly.Location) + '\\';
            Log.Info("Setting Games Path");
            GameSettings = new GameSettings();
            if (shutDown)
            {
                Log.Info("Shutdown Time");
                if (Application.Current.MainWindow != null)
                {
                    Application.Current.MainWindow.Close();
                }
                return;
            }

            Log.Info("Decide to ask about wine");
            if (Prefs.AskedIfUsingWine == false)
            {
                Log.Info("Asking about wine");
                var res = MessageBox.Show("Are you running OCTGN on Linux or a Mac using Wine?", "Using Wine",
                                          MessageBoxButton.YesNo, MessageBoxImage.Question);
                if (res == MessageBoxResult.Yes)
                {
                    Prefs.AskedIfUsingWine      = true;
                    Prefs.UsingWine             = true;
                    Prefs.UseHardwareRendering  = false;
                    Prefs.UseGameFonts          = false;
                    Prefs.UseWindowTransparency = false;
                }
                else if (res == MessageBoxResult.No)
                {
                    Prefs.AskedIfUsingWine      = true;
                    Prefs.UsingWine             = false;
                    Prefs.UseHardwareRendering  = true;
                    Prefs.UseGameFonts          = true;
                    Prefs.UseWindowTransparency = true;
                }
            }
            // Check for desktop experience
            if (Prefs.UsingWine == false)
            {
                try
                {
                    Log.Debug("Checking for Desktop Experience");
                    var objMC = new ManagementClass("Win32_ServerFeature");
                    // Expected Exception: System.Management.ManagementException
                    // Additional information: Not found
                    var  objMOC = objMC.GetInstances();
                    bool gotIt  = false;
                    foreach (var objMO in objMOC)
                    {
                        if ((UInt32)objMO["ID"] == 35)
                        {
                            Log.Debug("Found Desktop Experience");
                            gotIt = true;
                            break;
                        }
                    }
                    if (!gotIt)
                    {
                        var res =
                            MessageBox.Show(
                                "You are running OCTGN without the windows Desktop Experience installed. This WILL cause visual, gameplay, and sound issues. Though it isn't required, it is HIGHLY recommended. \n\nWould you like to be shown a site to tell you how to turn it on?",
                                "Windows Desktop Experience Missing", MessageBoxButton.YesNo,
                                MessageBoxImage.Exclamation);
                        if (res == MessageBoxResult.Yes)
                        {
                            LaunchUrl(
                                "http://blogs.msdn.com/b/findnavish/archive/2012/06/01/enabling-win-7-desktop-experience-on-windows-server-2008.aspx");
                        }
                        else
                        {
                            MessageBox.Show("Ok, but you've been warned...", "Warning", MessageBoxButton.OK,
                                            MessageBoxImage.Warning);
                        }
                    }
                }
                catch (Exception e)
                {
                    Log.Warn(
                        "Check desktop experience error. An error like 'Not Found' is normal and shouldn't be worried about",
                        e);
                }
            }
            // Send off user/computer stats
            try
            {
                var osver    = System.Environment.OSVersion.VersionString;
                var osBit    = Win32.Is64BitOperatingSystem;
                var procBit  = Win32.Is64BitProcess;
                var issubbed = SubscriptionModule.Get().IsSubscribed;
                var iswine   = Prefs.UsingWine;
                // Use the API to submit info
            }
            catch (Exception e)
            {
                Log.Warn("Sending stats error", e);
            }
            //var win = new ShareDeck();
            //win.ShowDialog();
            //return;
            Log.Info("Getting Launcher");
            Launchers.ILauncher launcher = CommandLineHandler.Instance.HandleArguments(Environment.GetCommandLineArgs());
            DeveloperMode = CommandLineHandler.Instance.DevMode;

            Versioned.Setup(Program.DeveloperMode);
            /* This section is automatically generated from the file Scripting/ApiVersions.xml. So, if you enjoy not getting pissed off, don't modify it.*/
            //START_REPLACE_API_VERSION
            Versioned.RegisterVersion(Version.Parse("3.1.0.0"), DateTime.Parse("2014-1-12"), ReleaseMode.Live);
            Versioned.RegisterVersion(Version.Parse("3.1.0.1"), DateTime.Parse("2014-1-22"), ReleaseMode.Live);
            Versioned.RegisterVersion(Version.Parse("3.1.0.2"), DateTime.Parse("2015-8-26"), ReleaseMode.Live);
            Versioned.RegisterFile("PythonApi", "pack://application:,,,/Scripting/Versions/3.1.0.0.py", Version.Parse("3.1.0.0"));
            Versioned.RegisterFile("PythonApi", "pack://application:,,,/Scripting/Versions/3.1.0.1.py", Version.Parse("3.1.0.1"));
            Versioned.RegisterFile("PythonApi", "pack://application:,,,/Scripting/Versions/3.1.0.2.py", Version.Parse("3.1.0.2"));
            //END_REPLACE_API_VERSION
            Versioned.Register <ScriptApi>();

            launcher.Launch().Wait();

            if (launcher.Shutdown)
            {
                if (Application.Current.MainWindow != null)
                {
                    Application.Current.MainWindow.Close();
                }
                return;
            }
        }
示例#3
0
        internal static void Start(string[] args, bool isTestRelease)
        {
            Log.Info("Start");
            IsReleaseTest = isTestRelease;

            Log.Info("Setting SSL Validation Helper");
            SSLHelper = new SSLValidationHelper();

            Log.Info("Setting api path");
            Octgn.Site.Api.ApiClient.DefaultUrl = new Uri(AppConfig.WebsitePath);

            JodsEngine = new JodsEngineIntegration();

            Log.Info("Configuring game feeds");
            ConfigureGameFeedTimeout();

            try
            {
                Log.Debug("Setting rendering mode.");
                RenderOptions.ProcessRenderMode = Prefs.UseHardwareRendering ? RenderMode.Default : RenderMode.SoftwareOnly;
            }
            catch (Exception)
            {
                // if the system gets mad, best to leave it alone.
            }

            Log.Info("Setting temp main window");
            Application.Current.MainWindow = new Window();
            try
            {
                Log.Info("Checking if admin");
                var isAdmin = UacHelper.IsProcessElevated && UacHelper.IsUacEnabled;
                if (isAdmin)
                {
                    MessageBox.Show(
                        "You are currently running OCTGN as Administrator. It is recommended that you run as a standard user, or you will most likely run into problems. Please exit OCTGN and run as a standard user.",
                        "WARNING",
                        MessageBoxButton.OK,
                        MessageBoxImage.Exclamation);
                }
            }
            catch (Exception e)
            {
                Log.Warn("Couldn't check if admin", e);
            }

            Log.Info("Creating Lobby Client");
            var handshaker        = new DefaultHandshaker();
            var connectionCreator = new TcpConnectionCreator(handshaker);
            var lobbyClientConfig = new LibraryCommunicationClientConfig(connectionCreator);

            LobbyClient = new Octgn.Library.Communication.Client(
                lobbyClientConfig,
                typeof(Program).Assembly.GetName().Version
                );

            //Log.Info("Adding trace listeners");
            //Debug.Listeners.Add(DebugListener);
            //DebugTrace.Listeners.Add(DebugListener);
            //Trace.Listeners.Add(DebugListener);
            //ChatLog = new CacheTraceListener();
            //Trace.Listeners.Add(ChatLog);

            Log.Info("Setting Games Path");
            GameSettings = new GameSettings();
            if (shutDown)
            {
                Log.Info("Shutdown Time");
                if (Application.Current.MainWindow != null)
                {
                    Application.Current.MainWindow.Close();
                }
                return;
            }

            Log.Info("Decide to ask about wine");
            if (Prefs.AskedIfUsingWine == false)
            {
                Log.Info("Asking about wine");
                var res = MessageBox.Show("Are you running OCTGN on Linux or a Mac using Wine?", "Using Wine",
                                          MessageBoxButton.YesNo, MessageBoxImage.Question);
                if (res == MessageBoxResult.Yes)
                {
                    Prefs.AskedIfUsingWine      = true;
                    Prefs.UsingWine             = true;
                    Prefs.UseHardwareRendering  = false;
                    Prefs.UseGameFonts          = false;
                    Prefs.UseWindowTransparency = false;
                }
                else if (res == MessageBoxResult.No)
                {
                    Prefs.AskedIfUsingWine      = true;
                    Prefs.UsingWine             = false;
                    Prefs.UseHardwareRendering  = true;
                    Prefs.UseGameFonts          = true;
                    Prefs.UseWindowTransparency = true;
                }
            }
            // Check for desktop experience
            if (Prefs.UsingWine == false)
            {
                try
                {
                    Log.Debug("Checking for Desktop Experience");
                    var objMC = new ManagementClass("Win32_ServerFeature");
                    // Expected Exception: System.Management.ManagementException
                    // Additional information: Not found
                    var  objMOC = objMC.GetInstances();
                    bool gotIt  = false;
                    foreach (var objMO in objMOC)
                    {
                        if ((UInt32)objMO["ID"] == 35)
                        {
                            Log.Debug("Found Desktop Experience");
                            gotIt = true;
                            break;
                        }
                    }
                    if (!gotIt)
                    {
                        var res =
                            MessageBox.Show(
                                "You are running OCTGN without the windows Desktop Experience installed. This WILL cause visual, gameplay, and sound issues. Though it isn't required, it is HIGHLY recommended. \n\nWould you like to be shown a site to tell you how to turn it on?",
                                "Windows Desktop Experience Missing", MessageBoxButton.YesNo,
                                MessageBoxImage.Exclamation);
                        if (res == MessageBoxResult.Yes)
                        {
                            LaunchUrl(
                                "http://blogs.msdn.com/b/findnavish/archive/2012/06/01/enabling-win-7-desktop-experience-on-windows-server-2008.aspx");
                        }
                        else
                        {
                            MessageBox.Show("Ok, but you've been warned...", "Warning", MessageBoxButton.OK,
                                            MessageBoxImage.Warning);
                        }
                    }
                }
                catch (Exception e)
                {
                    Log.Warn(
                        "Check desktop experience error. An error like 'Not Found' is normal and shouldn't be worried about",
                        e);
                }
            }
            // Send off user/computer stats
            try
            {
                var osver    = System.Environment.OSVersion.VersionString;
                var osBit    = Win32.Is64BitOperatingSystem;
                var procBit  = Win32.Is64BitProcess;
                var issubbed = SubscriptionModule.Get().IsSubscribed;
                var iswine   = Prefs.UsingWine;
                // Use the API to submit info
            }
            catch (Exception e)
            {
                Log.Warn("Sending stats error", e);
            }

            Log.Info("Getting Launcher");
            Launchers.ILauncher launcher = CommandLineHandler.Instance.HandleArguments(Environment.GetCommandLineArgs());
            DeveloperMode = CommandLineHandler.Instance.DevMode;

            launcher.Launch().Wait();

            if (launcher.Shutdown)
            {
                if (Application.Current.MainWindow != null)
                {
                    Application.Current.MainWindow.Close();
                }
                return;
            }
        }
示例#4
0
 public static SubscriptionModule Get()
 {
     lock (SubscriptionModuleSingletonLocker) return SingletonContext ?? (SingletonContext = new SubscriptionModule());
 }
示例#5
0
 public static SubscriptionModule Get()
 {
     lock (SubscriptionModuleSingletonLocker) return(SingletonContext ?? (SingletonContext = new SubscriptionModule()));
 }