Ejemplo n.º 1
0
        // TO DO: Better error reporting on this method.
        public void Shutdown()
        {
            try
            {
                lock (ShutdownConnectionLock)
                {
                    if (NetworkStream != null)
                    {
                        NetworkStream.Close();
                        NetworkStream.Dispose();
                        NetworkStream = null;
                    }
                    if (Client != null)
                    {
                        Client.Close();
                        Client = null;
                    }

                    this.OnConnectionClosed();
                }
            }
            catch (SocketException)
            {
                // TO DO: Error reporting, possibly in a log file.
            }
            catch (Exception e)
            {
                FrostbiteConnection.LogError("FrostbiteLayerConnection.Shutdown", "catch (Exception e)", e);
            }
            finally
            {
                this.NullActions();
            }
        }
Ejemplo n.º 2
0
        private Enum GenerateEnum(string enumName, string[] literals)
        {
            Enum returnEnum = null;

            try {
                if (this.m_dicGeneratedEnums.ContainsKey(enumName) == false)
                {
                    EnumBuilder enumBuilder = m_modBuilder.DefineEnum(enumName, TypeAttributes.Public, typeof(System.Int32));
                    //string[] al = { "en-US", "en-UK", "ar-SA", "da-DK", "French", "Cantonese" };
                    for (int i = 0; i < literals.Length; i++)
                    {
                        // here al is an array list with a list of string values
                        if (literals[i].ToString().Length > 0)
                        {
                            enumBuilder.DefineLiteral(literals[i].ToString(), i);
                        }
                    }

                    Type enumType = enumBuilder.CreateType();
                    returnEnum = (Enum)Activator.CreateInstance(enumType);

                    this.m_dicGeneratedEnums.Add(enumName, returnEnum);
                }
                else
                {
                    returnEnum = this.m_dicGeneratedEnums[enumName];
                }
            }
            catch (Exception e) {
                FrostbiteConnection.LogError("uscPluginPanel.GenerateEnum", enumName + " " + String.Join("|", literals), e);
            }

            return(returnEnum);
        }
Ejemplo n.º 3
0
        // TO DO: Better error reporting on this method.
        public void Shutdown()
        {
            if (Client != null)
            {
                try {
                    lock (ShutdownConnectionLock) {
                        if (NetworkStream != null)
                        {
                            NetworkStream.Close();
                            NetworkStream.Dispose();
                            NetworkStream = null;
                        }

                        Client.Close();
                        Client = null;

                        if (ConnectionClosed != null)
                        {
                            FrostbiteConnection.RaiseEvent(ConnectionClosed.GetInvocationList(), this);
                        }
                    }
                }
                catch (SocketException) {
                    // TO DO: Error reporting, possibly in a log file.
                }
                catch (Exception e) {
                    FrostbiteConnection.LogError("FrostbiteLayerConnection.Shutdown", "catch (Exception e)", e);
                }
            }
        }
Ejemplo n.º 4
0
        // string strLocalizationFilePath,
        public CLocalization(string strLocalizationFilePath, string strLocalizationFileName)
        {
            this.m_strLocalizationFileName = strLocalizationFileName;
            this.m_strLocalizationFilePath = strLocalizationFilePath;
            this.m_dicLocalizedStrings     = new Dictionary <string, string>();

            try {
                string strFullLocalizationFile = Encoding.Unicode.GetString(File.ReadAllBytes(this.m_strLocalizationFilePath));

                MatchCollection mtcAllVariables = Regex.Matches(strFullLocalizationFile, "^(.*?)=(.*?)[\\r]?$", RegexOptions.Multiline);

                foreach (Match mtVariable in mtcAllVariables)
                {
                    if (this.m_dicLocalizedStrings.ContainsKey(mtVariable.Groups[1].Value) == false)
                    {
                        this.m_dicLocalizedStrings.Add(mtVariable.Groups[1].Value, mtVariable.Groups[2].Value);
                    }
                    else
                    {
                        this.m_dicLocalizedStrings[mtVariable.Groups[1].Value] = mtVariable.Groups[2].Value;
                    }
                }
            }
            catch (Exception e) {
                FrostbiteConnection.LogError("CLocalization", String.Empty, e);
                // TO DO: Nice error message for loading localization file error.
            }
        }
Ejemplo n.º 5
0
        private static void ListenIncommingLayerConnections(IAsyncResult ar)
        {
            PRoConLayer plLayer = (PRoConLayer)ar.AsyncState;

            if (plLayer.m_tclLayerListener != null)
            {
                try {
                    TcpClient tcpNewConnection = plLayer.m_tclLayerListener.EndAcceptTcpClient(ar);

                    PRoConLayerClient cplcNewConnection = new PRoConLayerClient(new FrostbiteLayerConnection(tcpNewConnection), plLayer.m_praApplication, plLayer.m_prcClient);

                    plLayer.LayerClients.Add(cplcNewConnection);

                    if (plLayer.ClientConnected != null)
                    {
                        FrostbiteConnection.RaiseEvent(plLayer.ClientConnected.GetInvocationList(), cplcNewConnection);
                    }

                    plLayer.m_tclLayerListener.BeginAcceptTcpClient(plLayer.m_asyncAcceptCallback, plLayer);
                }
                catch (SocketException exception) {
                    if (plLayer.LayerSocketError != null)
                    {
                        FrostbiteConnection.RaiseEvent(plLayer.LayerSocketError.GetInvocationList(), exception);
                    }

                    plLayer.ShutdownLayerListener();

                    //cbfAccountsPanel.OnLayerServerSocketError(skeError);
                }
                catch (Exception e) {
                    FrostbiteConnection.LogError("ListenIncommingLayerConnections", "catch (Exception e)", e);
                }
            }
        }
Ejemplo n.º 6
0
 protected void WriteLogLine(string strFormat, params object[] a_objArguments)
 {
     if (this.Logging == true && this.m_stwFileWriter != null)
     {
         try {
             this.m_stwFileWriter.WriteLine(Loggable.RemoveCaretCodes.Replace(String.Format(strFormat, a_objArguments), ""));
             this.m_stwFileWriter.Flush();
         }
         catch (Exception e) {
             FrostbiteConnection.LogError("WriteLogLine error", strFormat, e);
         }
     }
 }
Ejemplo n.º 7
0
        static void Main(string[] args)
        {
            PRoConApplication application = null;

            if (PRoConApplication.IsProcessOpen() == false)
            {
                try {
                    application = new PRoConApplication(true, args);

                    // Note: The license states usage data must be enabled for procon.console.exe support
                    application.OptionsSettings.AllowAnonymousUsageData = true;

                    System.Console.WriteLine("Procon Frostbite");
                    System.Console.WriteLine("================");
                    System.Console.WriteLine("By executing this application you agree to the license available at:");
                    System.Console.WriteLine("\thttp://myrcon.com/licenses/myrcon.pdf");
                    System.Console.WriteLine("If you do not agree you must immediately exit this application.");
                    System.Console.WriteLine("================");
                    System.Console.WriteLine("This is a cut down version of PRoCon.exe to be used by GSPs and PRoCon Hosts.");
                    System.Console.WriteLine("Executing this file is the same as \"PRoCon.exe -console 1\"");
                    System.Console.WriteLine("No output is given.  This is as cut down as we're gunno get..");
                    System.Console.WriteLine("\nExecuting procon...");
                    application.Execute();

                    GC.Collect();
                    System.Console.WriteLine("Running... (Press any key to shutdown)");
                    System.Console.ReadKey();
                }
                catch (Exception e) {
                    FrostbiteConnection.LogError("PRoCon.Console.exe", "", e);
                }
                finally {
                    if (application != null)
                    {
                        application.Shutdown();
                    }
                }
            }
            else
            {
                // Possible prevention of a cpu consumption bug I can see at the time of writing.
                // TCAdmin: Start procon.exe
                // procon.exe has an update to install
                // procon.exe loads proconupdater.exe
                // procon.exe unloads
                // proconupdater.exe begins update
                // TCAdmin detects procon.exe shutdown - attempts to reload
                System.Console.WriteLine("Already running - shutting down");
                Thread.Sleep(50);
            }
        }
Ejemplo n.º 8
0
        private void ListenIncommingLayerConnections(IAsyncResult ar)
        {
            lock (this.LayerListenerLock)
            {
                if (this._layerListener != null)
                {
                    try
                    {
                        TcpClient tcpClient = this._layerListener.EndAcceptTcpClient(ar);

                        ILayerClient client = new LayerClient(this, new LayerConnection(tcpClient), this._application, this._client);

                        // Issue #24. Somewhere the end port connection+port isn't being removed.
                        if (this.Clients.ContainsKey(client.IPPort) == true)
                        {
                            this.Clients[client.IPPort].Shutdown();

                            // If, for some reason, the client wasn't removed during shutdown..
                            if (this.Clients.ContainsKey(client.IPPort) == true)
                            {
                                this.Clients.Remove(client.IPPort);
                            }
                        }

                        this.Clients.Add(client.IPPort, client);


                        this.OnClientConnected(client);

                        this._layerListener.BeginAcceptTcpClient(this.ListenIncommingLayerConnections, this);
                    }
                    catch (SocketException exception)
                    {
                        this.OnSocketError(exception);

                        this.Shutdown();

                        //cbfAccountsPanel.OnLayerServerSocketError(skeError);
                    }
                    catch (Exception e)
                    {
                        FrostbiteConnection.LogError("ListenIncommingLayerConnections", "catch (Exception e)", e);
                    }
                }
            }
        }
Ejemplo n.º 9
0
        // string strLocalizationFilePath,
        public CLocalization(string filePath, string fileName)
        {
            this.FileName         = fileName;
            this.FilePath         = filePath;
            this.LocalizedStrings = new Dictionary <string, string>();

            try {
                this.LocalizedStrings = File.ReadAllText(this.FilePath).Split(new[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries)
                                        .Select(line => line.Split(new[] { '=' }, 2, StringSplitOptions.RemoveEmptyEntries))
                                        .Where(items => items.Length == 2)
                                        .Distinct(new LocalizationKeyComparer())
                                        .ToDictionary(items => items[0], items => items[1]);
            }
            catch (Exception e) {
                FrostbiteConnection.LogError("CLocalization", String.Empty, e);
                // TO DO: Nice error message for loading localization file error.
            }
        }
Ejemplo n.º 10
0
        public void Write(string strFormat, params object[] arguments)
        {
            DateTime dtLoggedTime = DateTime.UtcNow.ToUniversalTime().AddHours(Client.Game.UtcOffset).ToLocalTime();
            string   text         = "";

            try {
                text = String.Format(strFormat, arguments);
            }
            catch (Exception e) {
                FrostbiteConnection.LogError(String.Join(", ", new[] { strFormat, }), "", e);
                text = "";
            }

            WriteLogLine(String.Format("[{0}] {1}", dtLoggedTime.ToString("HH:mm:ss"), text.Replace("{", "{{").Replace("}", "}}")));

            if (WriteConsole != null)
            {
                this.WriteConsole(dtLoggedTime, text);
            }
        }
Ejemplo n.º 11
0
        protected static string GetDebugPacket(string connectionPrefix, string packetColour, Packet packet, Packet requestPacket)
        {
            string debugString = String.Empty;

            try {
                debugString = string.Format("{0,10}: {1,-12} S: {2,-6} {3}{4}", connectionPrefix, GetRequestResponseColour(packet), packet.SequenceNumber, packetColour, packet.ToDebugString().Replace("\r", "").Replace("\n", ""));

                if (requestPacket != null)
                {
                    debugString = String.Format("{0} ^0(RE: ^2{1}^0)", debugString, requestPacket.ToDebugString().TrimEnd('\r', '\n'));
                }

                debugString = debugString.Replace("{", "{{").Replace("}", "}}");
            }
            catch (Exception e) {
                FrostbiteConnection.LogError(String.Join(", ", new[] { connectionPrefix, packetColour, packet.ToString(), requestPacket != null ? requestPacket.ToString() : "" }), "", e);
                debugString = "";
            }

            return(debugString);
        }
Ejemplo n.º 12
0
 protected override void OnStart(string[] args)
 {
     //Setting the Evironment back to the Basedirectory
     //because Windows changes it to c://windows/system32 when running as service.
     Environment.CurrentDirectory = AppDomain.CurrentDomain.BaseDirectory;
     System.Console.WriteLine(Environment.CurrentDirectory);
     if (PRoConApplication.IsProcessOpen() == false)
     {
         try
         {
             application = new PRoConApplication(true, args);
             // Note: The license states usage data must be enabled for procon.console.exe support
             application.OptionsSettings.AllowAnonymousUsageData = true;
             application.Execute();
             GC.Collect();
         }
         catch (Exception e)
         {
             FrostbiteConnection.LogError("PRoCon.Service.exe", "", e);
         }
     }
 }
Ejemplo n.º 13
0
        protected override void OnStart(string[] args)
        {
            //Setting the Evironment back to the Basedirectory
            //because Windows changes it to c://windows/system32 when running as service.
            Environment.CurrentDirectory = AppDomain.CurrentDomain.BaseDirectory;
            System.Console.WriteLine(Environment.CurrentDirectory);

            int iValue;

            if (args != null && args.Length >= 2)
            {
                for (int i = 0; i < args.Length; i = i + 2)
                {
                    if (String.Compare("-use_core", args[i], true) == 0 && int.TryParse(args[i + 1], out iValue) == true && iValue > 0)
                    {
                        System.Diagnostics.Process.GetCurrentProcess().ProcessorAffinity = (System.IntPtr)iValue;
                    }
                }
            }

            if (PRoConApplication.IsProcessOpen() == false)
            {
                try
                {
                    application = new PRoConApplication(true, args);
                    // Note: The license states usage data must be enabled for procon.console.exe support
                    //application.OptionsSettings.AllowAnonymousUsageData = true;
                    application.Execute();
                    GC.Collect();
                }
                catch (Exception e)
                {
                    FrostbiteConnection.LogError("PRoCon.Service.exe", "", e);
                }
            }
        }
Ejemplo n.º 14
0
        static void Main(string[] args)
        {
            Program.Args = args;

            bool dotNetCheck = CheckNetVersion("3.5");

            if (PRoConApplication.IsProcessOpen() == false && dotNetCheck == true)
            {
                if (Directory.Exists(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Updates")) == true)
                {
                    AutoUpdater.Arguments = args;
                    AutoUpdater.BeginUpdateProcess(null);
                }
                else
                {
                    try
                    {
                        bool isBasicConsole = false;
                        bool isGspUpdater   = false;

                        if (args != null && args.Length >= 2)
                        {
                            for (int i = 0; i < args.Length; i = i + 2)
                            {
                                int value;

                                if (String.Compare("-console", args[i], System.StringComparison.OrdinalIgnoreCase) == 0 && int.TryParse(args[i + 1], out value) == true && value == 1)
                                {
                                    isBasicConsole = true;
                                }
                                if (String.Compare("-gspupdater", args[i], System.StringComparison.OrdinalIgnoreCase) == 0 && int.TryParse(args[i + 1], out value) == true && value == 1)
                                {
                                    isGspUpdater = true;
                                }
                                if (String.Compare("-use_core", args[i], System.StringComparison.OrdinalIgnoreCase) == 0 && int.TryParse(args[i + 1], out value) == true && value > 0)
                                {
                                    System.Diagnostics.Process.GetCurrentProcess().ProcessorAffinity = (System.IntPtr)value;
                                }
                            }
                        }

                        Application.EnableVisualStyles();
                        Application.SetCompatibleTextRenderingDefault(false);

                        if (isGspUpdater == true)
                        {
                            Application.Run(new GspUpdater());
                        }
                        else
                        {
                            if (isBasicConsole == true)
                            {
                                BasicConsole basicWindow = new BasicConsole();
                                basicWindow.WindowLoaded += new BasicConsole.WindowLoadedHandler(procon_WindowLoaded);

                                Application.Run(basicWindow);
                            }
                            else
                            {
                                frmMain mainWindow = new frmMain(args);
                                mainWindow.WindowLoaded += new frmMain.WindowLoadedHandler(procon_WindowLoaded);
                                Application.Run(mainWindow);
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        FrostbiteConnection.LogError("Application error", String.Empty, e);
                        MessageBox.Show("Procon ran into a critical error, but hopefully it logged that error in DEBUG.txt. Please post this to the forums at https://myrcon.net/");
                    }
                    finally
                    {
                        if (Program.ProconApplication != null)
                        {
                            Program.ProconApplication.Shutdown();
                        }
                    }
                }
            }
            else
            {
                // Possible prevention of a cpu consumption bug I can see at the time of writing.
                // TCAdmin: Start procon.exe
                // procon.exe has an update to install
                // procon.exe loads proconupdater.exe
                // procon.exe unloads
                // proconupdater.exe begins update
                // TCAdmin detects procon.exe shutdown - attempts to reload
                Thread.Sleep(50);
            }
        }
Ejemplo n.º 15
0
        static void Main(string[] args)
        {
            int iValue;

            if (args != null && args.Length >= 2)
            {
                for (int i = 0; i < args.Length; i = i + 2)
                {
                    if (String.Compare("-use_core", args[i], true) == 0 && int.TryParse(args[i + 1], out iValue) == true && iValue > 0)
                    {
                        System.Diagnostics.Process.GetCurrentProcess().ProcessorAffinity = (System.IntPtr)iValue;
                    }
                }
            }

            PRoConApplication application = null;

            if (PRoConApplication.IsProcessOpen() == false)
            {
                try
                {
                    application = new PRoConApplication(true, args);

                    System.Console.WriteLine("Procon Frostbite");
                    System.Console.WriteLine("================");
                    System.Console.WriteLine("By executing this application you agree to the license available at:");
                    System.Console.WriteLine("\thttps://myrcon.net/licenses/myrcon.pdf");
                    System.Console.WriteLine("If you do not agree you must immediately exit this application.");
                    System.Console.WriteLine("================");
                    System.Console.WriteLine("This is a cut down version of PRoCon.exe to be used by GSPs and PRoCon Hosts.");
                    System.Console.WriteLine("Executing this file is the same as \"PRoCon.exe -console 1\"");
                    System.Console.WriteLine("No output is given.  This is as cut down as we're gunno get..");
                    System.Console.WriteLine("\nExecuting procon...");
                    application.Execute();

                    GC.Collect();
                    System.Console.WriteLine("Running... (Press any key to shutdown)");
                    System.Console.ReadKey();
                }
                catch (Exception e)
                {
                    FrostbiteConnection.LogError("PRoCon.Console.exe", "", e);
                }
                finally
                {
                    if (application != null)
                    {
                        application.Shutdown();
                    }
                }
            }
            else
            {
                // Possible prevention of a cpu consumption bug I can see at the time of writing.
                // TCAdmin: Start procon.exe
                // procon.exe has an update to install
                // procon.exe loads proconupdater.exe
                // procon.exe unloads
                // proconupdater.exe begins update
                // TCAdmin detects procon.exe shutdown - attempts to reload
                System.Console.WriteLine("Already running - shutting down");
                Thread.Sleep(50);
            }
        }
Ejemplo n.º 16
0
        static void Main(string[] args)
        {
            Program.m_Args = args;

            if (PRoConApplication.IsProcessOpen() == false)
            {
                if (Directory.Exists(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Updates")) == true)
                {
                    AutoUpdater.m_strArgs = args;
                    AutoUpdater.BeginUpdateProcess(null);
                }
                else
                {
                    //PRoConApplication paProcon = null;

                    try {
                        bool blBasicConsole = false;
                        bool blGspUpdater   = false;

                        int iValue;
                        if (args != null && args.Length >= 2)
                        {
                            for (int i = 0; i < args.Length; i = i + 2)
                            {
                                if (String.Compare("-console", args[i], true) == 0 && int.TryParse(args[i + 1], out iValue) == true && iValue == 1)
                                {
                                    blBasicConsole = true;
                                }
                                if (String.Compare("-gspupdater", args[i], true) == 0 && int.TryParse(args[i + 1], out iValue) == true && iValue == 1)
                                {
                                    blGspUpdater = true;
                                }
                            }
                        }

                        //Thread.Sleep(5000);
                        Application.EnableVisualStyles();
                        Application.SetCompatibleTextRenderingDefault(false);

                        if (blGspUpdater == true)
                        {
                            Application.Run(new GspUpdater());
                        }
                        else
                        {
                            if (blBasicConsole == true)
                            {
                                BasicConsole basicWindow = new BasicConsole();
                                basicWindow.WindowLoaded += new BasicConsole.WindowLoadedHandler(procon_WindowLoaded);

                                Application.Run(basicWindow);
                            }
                            else
                            {
                                frmMain mainWindow = new frmMain(args);
                                mainWindow.WindowLoaded += new frmMain.WindowLoadedHandler(procon_WindowLoaded);
                                Application.Run(mainWindow);
                            }
                        }
                    }
                    catch (Exception e) {
                        FrostbiteConnection.LogError("Application error", String.Empty, e);
                        MessageBox.Show("PRoCon ran into a critical error, but hopefully it logged that error in DEBUG.txt.  Please post/pm/email this to phogue at www.phogue.net.");
                    }
                    finally {
                        if (Program.m_application != null)
                        {
                            Program.m_application.Shutdown();
                        }
                    }
                }
            }
            else
            {
                // Possible prevention of a cpu consumption bug I can see at the time of writing.
                // TCAdmin: Start procon.exe
                // procon.exe has an update to install
                // procon.exe loads proconupdater.exe
                // procon.exe unloads
                // proconupdater.exe begins update
                // TCAdmin detects procon.exe shutdown - attempts to reload
                Thread.Sleep(50);
            }
        }