예제 #1
0
        private void DoNoAuthLogin(INetworkConnection con, Packet pMsg)
        {
            try
            {
                PacketLoginRequest p = pMsg as PacketLoginRequest;
                ServerUser.AccountName  = Guid.NewGuid().ToString(); // assign random session name
                ServerUser.OwningServer = MyServer.ServerUserID;
                Log1.Logger("LoginServer.Inbound.Login").Info("No-auth assigned user name " + ServerUser.AccountName + " from " + RemoteIP + " is attempting login...");
                Log1.Logger("LoginServer.UserIPMap").Info("User [" + p.AccountName + "] from [" + RemoteIP + "] is attempting login.");
                string msg = "";

                PacketLoginResult result = CreateLoginResultPacket();
                if (result.ReplyCode == ReplyType.OK)
                {
                    ServerUser.AuthTicket      = Guid.NewGuid();
                    ServerUser.IsAuthenticated = true;
                    ServerUser.ID = Guid.NewGuid(); // generate random ID for this session

                    ServerUser.Profile.UserRoles = new string[0];
                    result.Parms.SetProperty("AccountName", ServerUser.AccountName);
                    result.Parms.SetProperty(-1, ServerUser.Profile.UserRoles);
                    result.Parms.SetProperty(-2, ServerUser.Profile.MaxCharacters);
                    ConnectionManager.AuthorizeUser(ServerUser);
                }
                pMsg.ReplyPacket = result;
                Log1.Logger("LoginServer.Inbound.Login").Info("Game client *" + ServerUser.AccountName + "* authentication: " + result.ReplyCode.ToString() + ". " + result.ReplyMessage);
            }
            catch (Exception e)
            {
                Log1.Logger("LoginServer.Inbound.Login").Error("Exception thrown whilst player attempted login. " + e.Message, e);
                KillConnection("Error logging in.");
            }
        }
예제 #2
0
        protected override void OnStart(string[] args)
        {
            Log1.Logger("Patcher").Info("Starting Patch server");
            Thread t = new Thread(new ThreadStart(StartAsync));

            t.Start();
        }
예제 #3
0
파일: Zeus.cs 프로젝트: Amitkapadi/WISP
        protected override void OnStart(string[] args)
        {
            Log1.Logger("Zeus.Service").Info("Starting Zeus server");
            Thread t = new Thread(new ThreadStart(StartAsync));

            t.Start();
        }
예제 #4
0
        // pass in the path of an XML file containing the socket policy
        public PolicyServer(string policyFile)
        {
            try
            {
                // Load the policy file
                m_policy = File.ReadAllBytes(policyFile);

                // Create the Listening Socket
                m_listener = new Socket(AddressFamily.InterNetworkV6, SocketType.Stream, ProtocolType.Tcp);

                // Put the socket into dual mode to allow a single socket
                // to accept both IPv4 and IPv6 connections
                // Otherwise, server needs to listen on two sockets,
                // one for IPv4 and one for IPv6
                // NOTE: dual-mode sockets are supported on Vista and later
                m_listener.SetSocketOption(SocketOptionLevel.IPv6, (SocketOptionName)27, 0);

                m_listener.Bind(new IPEndPoint(IPAddress.IPv6Any, 943));
                m_listener.Listen(25);
                m_listener.BeginAccept(new AsyncCallback(OnConnection), null);
                Log1.Logger("Network").Info("Silverlight Policy Server running on port 943.");
            }
            catch (Exception e)
            {
                Log1.Logger("Server.Network").Error("Error starting Silverlight Policy server on this process. " + e.Message, e);
            }
        }
예제 #5
0
파일: Service.cs 프로젝트: Amitkapadi/WISP
        public static string[] GetInstalledServices()
        {
            string[]    rsl = new string[0];
            RegistryKey key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Wisp\Servers");

            if (key == null)
            {
                return(rsl);
            }
            string[] servers = key.GetSubKeyNames();
            rsl = new string[servers.Length];
            for (int i = 0; i < servers.Length; i++)
            {
                try
                {
                    string       server     = servers[i];
                    string       serverName = (string)Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Wisp\Servers\" + server, "ServiceName", "");
                    string       desc       = (string)Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Wisp\Servers\" + server, "Description", "");
                    ServiceState state      = ServiceInstaller.GetServiceStatus(serverName);
                    rsl[i] = serverName + "|" + state.ToString() + "|" + desc;
                }
                catch (Exception e)
                {
                    Log1.Logger("Service").Error("Failed to get installed Wisp service info. " + e.Message);
                }
            }

            return(rsl);
        }
예제 #6
0
        protected override void OnStart(string[] args)
        {
            // Initialize the server in a worker thread, or the Windows Service system may abort the
            // application because it's taking too long to "start up"
            Log1.Logger("Server").Info("Starting server. Please wait...");
            Thread t = new Thread(new ThreadStart(StartAsync));

            t.Start();
        }
예제 #7
0
 protected override bool OnFileStreamComplete(string fileName, long totalFileLengthBytes, int subType, string arg)
 {
     PatchFileSent++;
     if (ServerUser != null && ServerUser.MyConnection != null)
     {
         Log1.Logger("Patch").Info("Sent [" + ((int)Util.ConvertBytesToMegabytes(totalFileLengthBytes)).ToString() + "MB] patch to " + ServerUser.MyConnection.RemoteEndPoint.ToString());
     }
     return(base.OnFileStreamComplete(fileName, totalFileLengthBytes, subType, arg));
 }
예제 #8
0
        protected override void OnStop()
        {
            if (m_Server == null)
            {
                return;
            }

            Log1.Logger("Patcher").Info("Stopping Patch server...");
            m_Server.StopServer();
        }
예제 #9
0
파일: Zeus.cs 프로젝트: Amitkapadi/WISP
        protected override void OnStop()
        {
            if (m_Server == null)
            {
                return;
            }

            Log1.Logger("Zeus.Service").Info("Stopping Zeus server...");
            m_Server.StopServer();
        }
예제 #10
0
        public WispServerProcess() : base()
        {
            try
            {
                //CharacterUtil.Instance.LoadCharacterTemplate();
                Factory.Instance.Register(typeof(WispConfigSettings), () => new WispConfigSettings());
                Factory.Instance.Register(typeof(WispUsersInfo), () => new WispUsersInfo());
                Factory.Instance.Register(typeof(WispUserDetail), () => new WispUserDetail());
                Factory.Instance.Register(typeof(WispCharacterDetail), () => new WispCharacterDetail(-1));
                Factory.Instance.Register(typeof(CommandData), delegate { return(new CommandData()); });

                NetworkConnection.RegisterPacketCreationDelegate((int)PacketType.PacketStream, 1, delegate { return(new PacketStream()); });

                //Roles.CreateRole("Administrator");
                //Membership.CreateUser("WispAdmin", "wisp123", "admin@home");
                //Roles.AddUserToRole("WispAdmin", "Administrator");

                AllowRemote = ConfigHelper.GetStringConfig("AllowRemoteConnections", "FALSE").ToUpper() == "TRUE";
                if (AllowRemote && !RequireAuthentication)
                {
                    Log1.Logger("Server").Warn("RequireAuthentication config was set to FALSE. This is not allowed for Zeus.  Disallowing remote connections.");
                    AllowRemote = false;
                }


                //PerfMon.TrackSystemCounter("% Processor Time", "Processor", "_Total");
                //for (int i = 0; i < Environment.ProcessorCount; i++)
                //{
                //    PerfMon.TrackSystemCounter("% Processor Time", "Processor", i.ToString());
                //}

                //PerfMon.TrackSystemCounter("% Processor Time", "Process", PerfMon.ProcessName);
                //PerfMon.TrackSystemCounter("Thread Count", "Process", PerfMon.ProcessName);
                //PerfMon.TrackSystemCounter("Private Bytes", "Process", PerfMon.ProcessName);
                //PerfMon.TrackSystemCounter("# Bytes in all Heaps", ".NET CLR Memory", PerfMon.ProcessName);
                //PerfMon.TrackSystemCounter("Available MBytes", "Memory", "");
                //PerfMon.TrackSystemCounter("Contention Rate / sec", ".NET CLR LocksAndThreads", PerfMon.ProcessName);
                //PerfMon.TrackSystemCounter("Total # of Contentions", ".NET CLR LocksAndThreads", PerfMon.ProcessName);

                //PerfMon.AddCustomCounter("Packets Out", "Number of packets sent per second.", System.Diagnostics.PerformanceCounterType.RateOfCountsPerSecond32);
                //PerfMon.AddCustomCounter("Packets In", "Number of packets received per second.", System.Diagnostics.PerformanceCounterType.RateOfCountsPerSecond32);
                //PerfMon.AddCustomCounter("Live Connections", "Number of connected sockets.", System.Diagnostics.PerformanceCounterType.NumberOfItems32);
                //PerfMon.AddCustomCounter("Bandwidth Out", "Number of bytes sent per second.", System.Diagnostics.PerformanceCounterType.RateOfCountsPerSecond32);
                //PerfMon.AddCustomCounter("Bandwidth In", "Number of bytes received per second.", System.Diagnostics.PerformanceCounterType.RateOfCountsPerSecond32);

                //PerfMon.InstallCustomCounters();

                //PerfMon.StartSamplingCounters();
            }
            catch (Exception e)
            {
                Log1.Logger("Server").Fatal("Zeus failed to initialize. ", e);
            }
        }
예제 #11
0
        /// <summary>
        /// Unzips a file to a directory.
        /// </summary>
        /// <param name="zipFile">the file to unzip</param>
        /// <returns></returns>
        public static bool UnzipFile(string zipFile, string targetDirectory)
        {
            try
            {
                using (ZipInputStream s = new ZipInputStream(File.OpenRead(zipFile)))
                {
                    ZipEntry theEntry;
                    while ((theEntry = s.GetNextEntry()) != null)
                    {
                        string path          = Path.Combine(targetDirectory, theEntry.Name);
                        string directoryName = Path.GetDirectoryName(path);
                        string fileName      = Path.GetFileName(path);

                        // create directory
                        if (directoryName.Length > 0 && !Directory.Exists(directoryName))
                        {
                            Directory.CreateDirectory(directoryName);
                        }

                        if (fileName != String.Empty)
                        {
                            using (FileStream streamWriter = File.Create(Path.GetFullPath(path)))
                            {
                                int    size = 2048;
                                byte[] data = new byte[2048];
                                while (true)
                                {
                                    size = s.Read(data, 0, data.Length);
                                    if (size > 0)
                                    {
                                        streamWriter.Write(data, 0, size);
                                    }
                                    else
                                    {
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Log1.Logger("Server").Error("Failed to unzip file [" + zipFile + "] to [" + targetDirectory + "].", e);
                return(false);
            }

            return(true);
        }
예제 #12
0
파일: Program.cs 프로젝트: Amitkapadi/WISP
 /// <summary>
 /// The main entry point for the application.
 /// </summary>
 static void Main(string[] args)
 {
     if (args.Length == 0 || args[0].ToLower().Trim() != "standalone")
     {
         ServiceBase[] ServicesToRun;
         ServicesToRun = new ServiceBase[]       { new Zeus() };
         Log1.Logger("Server").Info("Starting server. Please wait...");
         ServiceBase.Run(ServicesToRun);
     }
     else
     {
         // you will have to manually kill the process either through the
         // debugger or the task manager
         Zeus service = new Zeus();
         service.Setup();
         System.Threading.Thread.Sleep(System.Threading.Timeout.Infinite);
     }
 }
예제 #13
0
        // Called when we receive a connection from a client
        public void OnConnection(IAsyncResult res)
        {
            Socket client = null;

            try
            {
                client = m_listener.EndAccept(res);
            }
            catch (SocketException)
            {
                return;
            }

            Log1.Logger("Network").Info("Silverlight connection from " + client.RemoteEndPoint.ToString());
            // handle this policy request with a PolicyConnection
            PolicyConnection pc = new PolicyConnection(client, m_policy);

            // look for more connections
            m_listener.BeginAccept(new AsyncCallback(OnConnection), null);
        }
예제 #14
0
파일: Service.cs 프로젝트: Amitkapadi/WISP
        public static bool IsWispService(string name)
        {
            string[] services = GetInstalledServices();
            string[] parts;
            for (int i = 0; i < services.Length; i++)
            {
                parts = services[i].Split(char.Parse("|"));
                if (parts.Length != 3)
                {
                    Log1.Logger("Service").Error("GetInstalledServices array was malformed.  Wisp Registry entry may be corrupt => " + services[i]);
                    continue;
                }

                if (parts[0].ToLower() == name.ToLower())
                {
                    return(true);
                }
            }

            return(false);
        }
예제 #15
0
        private void OnClientMachineInfo(INetworkConnection con, Packet rep)
        {
            PacketReply   p  = rep as PacketReply;
            StringBuilder sb = new StringBuilder();
            string        ip = "";

            if (con.IsAlive)
            {
                ip = con.RemoteEndPoint.ToString();
            }
            sb.AppendLine("\r\n=-=-= Client Spec [" + ip + "] =-=-=");
            foreach (Property prop in p.Parms.AllProperties)
            {
                sb.AppendLine(prop.StringValue);
            }
            sb.Append("=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=");
            Log1.Logger("UserMetrics").Info(sb.ToString());

            // Let the client go.
            SendVersionIsCurrent();
        }
예제 #16
0
파일: Program.cs 프로젝트: Amitkapadi/WISP
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        static void Main(string[] args)
        {
            // Handle running the server service in standalone mode, i.e. outside of the
            // Windows Service sandbox.  Just start the process with the argument
            // "standalone" to run it as a regular application.  You can set this
            // argument in the "Project->Properties->Debug" options for easy debugging.

            if (args.Length == 0 || args[0].ToLower().Trim() != "standalone")
            {
                ServiceBase[] ServicesToRun;
                ServicesToRun = new ServiceBase[] { new WispService() };
                Log1.Logger("Server").Info("Starting server.");
                ServiceBase.Run(ServicesToRun);
            }
            else
            {
                // you will have to manually kill the process either through the
                // debugger or the task manager
                WispService service = new WispService();
                service.Setup();
                System.Threading.Thread.Sleep(System.Threading.Timeout.Infinite);
            }
        }
예제 #17
0
 static void Main(string[] args)
 {
     try
     {
         if (args.Length > 0)
         {
             if (args[0] == "/i")
             {
                 Log1.Logger("Patcher").Info("Installing PatchServer as service...");
                 InstallService(Assembly.GetExecutingAssembly().Location);
             }
             else if (args[0] == "/u")
             {
                 Log1.Logger("Patcher").Info("UnInstalling PatchServer as service...");
                 WispServiceTools.ServiceInstaller.Uninstall("Patchy");
             }
             else if (args[0] == "standalone")
             {
                 Log1.Logger("Patcher").Info("Running PatchServer in standalone...");
                 PatchServer MyService = new PatchServer();
                 MyService.Setup();
                 System.Threading.Thread.Sleep(System.Threading.Timeout.Infinite);
             }
         }
         else
         {
             ServiceBase[] ServicesToRun;
             ServicesToRun = new ServiceBase[] { new PatchServer() };
             Log1.Logger("Patcher").Info("Starting Patch server as service.");
             ServiceBase.Run(ServicesToRun);
         }
     }
     catch (Exception e)
     {
         Log1.Logger("Patcher").Info("Fatal error: " + e.Message);
     }
 }
예제 #18
0
파일: Service.cs 프로젝트: Amitkapadi/WISP
        public static string UninstallService(string serviceName)
        {
            if (!IsWispService(serviceName))
            {
                return(serviceName + " does not appear to be a known Wisp service.  Can't uninstall it.");
            }

            Log1.Logger("Service").Info("Checking for existing " + serviceName + " service.");
            ServiceState state       = ServiceInstaller.GetServiceStatus(serviceName);
            int          maxTries    = 10;
            int          tries       = 0;
            bool         uninstalled = false;

            try
            {
                do
                {
                    switch (state)
                    {
                    case ServiceState.NotFound:
                    case ServiceState.Unknown:
                        Registry.LocalMachine.DeleteSubKeyTree((@"SOFTWARE\Wisp\Servers\" + serviceName));
                        return(serviceName + " is no longer installed on this machine.");

                    case ServiceState.Running:
                        Log1.Logger("Service").Info("Stopping " + serviceName + " service...");
                        ServiceInstaller.StopService(serviceName);
                        break;

                    case ServiceState.Stopped:
                        Log1.Logger("Service").Info(serviceName + " service is stopped.");
                        object val = Registry.GetValue(@"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\" + serviceName, "ImagePath", "");
                        if (val != null)
                        {
                            uninstalled = ServiceInstaller.Uninstall(serviceName);
                            break;
                        }
                        break;

                    default:
                        Log1.Logger("Service").Info(serviceName + " service is " + state.ToString() + ". Waiting...");
                        break;
                    }
                    Thread.Sleep(500);
                    state = ServiceInstaller.GetServiceStatus(serviceName);
                    tries++;
                } while (!uninstalled && (tries < maxTries && state != ServiceState.Unknown && state != ServiceState.NotFound));

                if (state == ServiceState.Unknown || state == ServiceState.NotFound || uninstalled)
                {
                    Registry.LocalMachine.DeleteSubKeyTree((@"SOFTWARE\Wisp\Servers\" + serviceName));
                }

                string deployPath = (string)Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Wisp\", "TargetDir", Environment.CurrentDirectory);
                if (deployPath == null || deployPath.Length < 1)
                {
                    return("Uninstalled service, but unable to delete directory.  Deploy path is not set in the registry.");
                }

                string serverRoot = Path.Combine(deployPath, "Server", serviceName);
                if (Directory.Exists(serverRoot))
                {
                    Directory.Delete(serverRoot, true);
                }
            }
            catch (Exception e)
            {
                Log1.Logger("Service").Error("Error uninstalling " + serviceName + ". ", e);
                return("Error uninstalling " + serviceName + ". " + e.Message);
            }

            return(serviceName + " service Uninstalled");
        }
예제 #19
0
파일: Zeus.cs 프로젝트: Amitkapadi/WISP
 protected override void OnShutdown()
 {
     Log1.Logger("Zeus.Service").Info("Machine shutting down.");
 }
예제 #20
0
파일: Service.cs 프로젝트: Amitkapadi/WISP
        public static bool InstallService(string path, string serviceName, string description)
        {
            if (!File.Exists(path))
            {
                Log1.Logger("Service").Error("Error finding " + serviceName + " executable. After installation it should be in " + path + ", but it's not.");
                return(false);
            }

            Log1.Logger("Service").Info("Checking for existing " + serviceName + " service.");
            ServiceState state    = ServiceInstaller.GetServiceStatus(serviceName);
            int          maxTries = 20;
            int          tries    = 0;

            try
            {
                do
                {
                    switch (state)
                    {
                    case ServiceState.NotFound:
                    case ServiceState.Unknown:
                        Log1.Logger("Service").Info("Now installed instance of " + serviceName + " service found.");
                        Log1.Logger("Service").Info("Installing " + serviceName + " service.");
                        ServiceInstaller.InstallAndStart(serviceName, serviceName, path);
                        Registry.SetValue(@"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\" + serviceName, "Description", description);

                        Registry.SetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Wisp\Servers\" + serviceName, "ServiceName", serviceName);
                        Registry.SetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Wisp\Servers\" + serviceName, "Description", description);

                        break;

                    case ServiceState.Running:
                        Log1.Logger("Service").Info("Stopping " + serviceName + " service...");
                        ServiceInstaller.StopService(serviceName);
                        break;

                    case ServiceState.Stopped:
                        Log1.Logger("Service").Info(serviceName + " service is stopped. Restarting...");
                        object val = Registry.GetValue(@"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\" + serviceName, "ImagePath", "");
                        if (val == null)
                        {
                            ServiceInstaller.Uninstall(serviceName);
                            break;
                        }
                        ServiceInstaller.InstallAndStart(serviceName, serviceName, path);

                        break;

                    default:
                        Log1.Logger("Service").Info(serviceName + " service is " + state.ToString() + ". Waiting...");
                        break;
                    }

                    Thread.Sleep(500);
                    state = ServiceInstaller.GetServiceStatus(serviceName);
                    tries++;
                } while (tries < maxTries && state != ServiceState.Running);

                if (state != ServiceState.Running)
                {
                    return(false);
                }
            }
            catch (Exception e)
            {
                Log1.Logger("Service").Error("Error installing " + serviceName + ". ", e);
                return(false);
            }

            return(true);
        }
예제 #21
0
파일: Zeus.cs 프로젝트: Amitkapadi/WISP
 private void StartAsync()
 {
     m_Server = new WispServerProcess();
     m_Server.StartServer();
     Log1.Logger("Zeus.Service").Info("Ready.");
 }
예제 #22
0
 protected override void OnShutdown()
 {
     Log1.Logger("Patcher").Info("Machine shutting down.");
 }
예제 #23
0
 public void ReloadVersionsTxt(string executor)
 {
     Log1.Logger("Patcher").Info(executor + " is reloading Versions.txt.");
     PatchServerProcess.Instance.ReadPatchVersions();
 }
예제 #24
0
 private void StartAsync()
 {
     m_Server = new PatchServerProcess();
     m_Server.StartServer();
     Log1.Logger("Patcher").Info("Ready.");
 }
예제 #25
0
 public void ReloadPatchNotes(string executor)
 {
     Log1.Logger("Patcher").Info(executor + " is reloading PatchNotes.txt.");
     PatchServerProcess.Instance.ReadPatchNotes();
 }
예제 #26
0
        public void OnGetLatestVersion(INetworkConnection con, Packet nmsg)
        {
            PacketGenericMessage packet = nmsg as PacketGenericMessage;
            string version = packet.Parms.GetStringProperty("CurrentVersion");

            try
            {
                double curVersion = double.Parse(version);
                int    idx        = PatchServerProcess.Patches.IndexOfKey(curVersion);
                if (idx == -1)
                {
                    Log1.Logger("Server").Info("User reported being at version number [" + version + "]. Version not known as per Versions.txt. Dropping user connection.");
                    KillConnection("Unknown current version.");
                    return;
                }

                if (!m_SentPatchNotes)
                {
                    PropertyBag bag = new PropertyBag();
                    bag.SetProperty("notes", 1, PatchServerProcess.PatchNotes);
                    PacketGenericMessage p = (PacketGenericMessage)CreatePacket((int)PacketType.PacketGenericMessage, (int)GenericMessageType.Notes, false, false);
                    p.Parms            = bag;
                    p.NeedsDeliveryAck = true;
                    Send(p);
                    m_SentPatchNotes = true;
                }

                if (idx == (PatchServerProcess.Patches.Count - 1))
                {
                    // if the server is configured to collect client spec data, then we do it right before we tell the client they're current.
                    // if not, just send the iscurrent message now.
                    if (ShouldCollectClientSpecs())
                    {
                        RequestClientSpec();
                    }
                    else
                    {
                        SendVersionIsCurrent();
                    }
                    return;
                }

                // get next patch in line
                idx++;
                FileInfo fi = PatchServerProcess.Patches.Values[idx];
                try
                {
                    double newVersion = PatchServerProcess.Patches.Keys[idx];
                    SendFileStream(fi, newVersion.ToString());
                }
                catch (Exception se)
                {
                    Log1.Logger("Patcher").Error("Error sending patch to " + RemoteEndPoint.ToString(), se);
                }
            }
            catch (Exception e)
            {
                KillConnection("Malformed patch request. " + e.Message);
                return;
            }

            // we only send one patch file.  let client process that file, then call us back for next file.
            if (Transit.NumAcksWaitingFor < 1)
            {
                KillConnection("Patch sent.");
            }
            else
            {
                SetTimer(500);
            }
        }
예제 #27
0
파일: Commands.cs 프로젝트: Amitkapadi/WISP
 public void ExampleCommand(string executor)
 {
     Log1.Logger("Server").Info("Example command executed by " + executor);
 }
예제 #28
0
 protected override void OnShutdown()
 {
     Log1.Logger("Server").Info("Shutting down.");
 }
예제 #29
0
        private static bool InstallService(string exePath)
        {
            WispServiceTools.ServiceState state = WispServiceTools.ServiceInstaller.GetServiceStatus("Patchy");
            int maxTries = 20;
            int tries    = 0;

            try
            {
                do
                {
                    switch (state)
                    {
                    case WispServiceTools.ServiceState.NotFound:
                    case WispServiceTools.ServiceState.Unknown:
                        Log1.Logger("Patcher").Info("No installed instance of Patchy service found.");
                        Log1.Logger("Patcher").Info("Installing Patchy service.");
                        WispServiceTools.ServiceInstaller.InstallAndStart("Patchy", "Patchy", exePath);
                        Registry.SetValue(@"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\Patchy", "Description", "WISP Patch server.");

                        Registry.SetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Wisp\Servers\" + "Patchy", "ServiceName", "Patchy");
                        Registry.SetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Wisp\Servers\" + "Patchy", "Description", "WISP Patch server.");

                        break;

                    case WispServiceTools.ServiceState.Running:
                        Log1.Logger("Patcher").Info("Stopping Patchy service...");
                        WispServiceTools.ServiceInstaller.StopService("Patchy");
                        break;

                    case WispServiceTools.ServiceState.Stopped:
                        Log1.Logger("Patcher").Info("Patchy service is stopped.  Restarting...");
                        object val = Registry.GetValue(@"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\Patchy", "ImagePath", "");
                        if (val == null)
                        {
                            WispServiceTools.ServiceInstaller.Uninstall("Patchy");
                            break;
                        }

                        Log1.Logger("Patcher").Info("Starting service...");
                        WispServiceTools.ServiceInstaller.InstallAndStart("Patchy", "Patchy", exePath);
                        //ServiceInstaller.StartService("Zeus");
                        break;

                    default:
                        Log1.Logger("Patcher").Info("Patchy service is " + state.ToString() + ". Waiting...");
                        break;
                    }

                    Thread.Sleep(500);
                    state = WispServiceTools.ServiceInstaller.GetServiceStatus("Patchy");
                    tries++;
                } while (tries < maxTries && state != WispServiceTools.ServiceState.Running);

                if (state != WispServiceTools.ServiceState.Running)
                {
                    Log1.Logger("Patcher").Info("Unable to start Patch service.  Check the Windows Event Log for Application errors.");
                    return(false);
                }
            }
            catch (Exception e)
            {
                Log1.Logger("Patcher").Info("Error installing Patchy service. " + e.Message);
                return(false);
            }

            return(true);
        }
예제 #30
0
 private void StartAsync()
 {
     m_Server = new LobbyBeholderServer();
     m_Server.StartServer();
     Log1.Logger("Server").Info("Ready.");
 }