static void Main(string[] args) { if (args.Length != 0 && args[0].ToLower().Trim() == "/i") { Log1.Logger("Server").Info("Installing server. Please wait..."); WispServices.InstallService(Application.ExecutablePath, "WISPLogin", "Wisp Login Server"); } else if (args.Length != 0 && args[0].ToLower().Trim() == "/u") { Log1.Logger("Server").Info("Uninstalling server. Please wait..."); WispServices.UninstallService("WISPLogin"); } else if (args.Length == 0) { ServiceBase[] ServicesToRun; ServicesToRun = new ServiceBase[] { new LoginServerProc() }; 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 LoginServerProc service = new LoginServerProc(); service.Setup(); System.Threading.Thread.Sleep(System.Threading.Timeout.Infinite); } }
private void OnServiceOverviewRequest(INetworkConnection con, Packet r) { Log1.Logger("Zeus").Debug("Service overview request from " + ServerUser.AccountName + "."); PacketGenericMessage msg = r as PacketGenericMessage; r.ReplyPacket = CreateStandardReply(r, ReplyType.OK, ""); string[] services = WispServices.GetInstalledServices(); msg.ReplyPacket.Parms.SetProperty(2, services); }
private void OnChangeServiceStateRequest(INetworkConnection con, Packet r) { Log1.Logger("Zeus").Debug("Service state change request from " + ServerUser.AccountName + "."); if (!ServerUser.Profile.IsUserInRole("Administrator")) { Log1.Logger("Zeus").Warn("[" + ServerUser.AccountName + "] has insufficient permissions to change service state."); r.ReplyPacket = CreateStandardReply(r, ReplyType.Failure, "Insufficient permissions. Only Administrators can change service states."); return; } PacketGenericMessage msg = r as PacketGenericMessage; r.ReplyPacket = CreateStandardReply(r, ReplyType.OK, ""); string service = msg.Parms.GetStringProperty(2); string targetState = msg.Parms.GetStringProperty(3); string result = ""; Log1.Logger("Zeus").Debug(ServerUser.AccountName + " requested that [" + service + "] change state to [" + targetState + "]."); if (targetState.ToLower() == "start") { result = WispServices.StartWispService(service); } else if (targetState.ToLower() == "stop") { result = WispServices.StopWispService(service); } else if (targetState.ToLower() == "uninstall") { result = WispServices.UninstallService(service); //int idx = MyServer.OutboundServerGroups["Default"].OutboundServers.Find(s=>s.n } r.ReplyPacket.ReplyMessage = result; Log1.Logger("Zeus").Debug(ServerUser.AccountName + " requested service state change for [" + service + "] to state [" + targetState + "] result: [" + result + "]."); string[] services = WispServices.GetInstalledServices(); msg.ReplyPacket.Parms.SetProperty(2, services); }
protected override bool OnFileStreamComplete(string fileName, long totalFileLengthBytes, int subType, string arg) { if (!ServerUser.Profile.IsUserInRole("Administrator")) { Log1.Logger("Zeus").Error("Received file transfer from unauthorized user [" + ServerUser.AccountName + "]."); SendGenericMessage((int)GenericMessageType.ServiceInstallResult, "Received file transfer from unauthorized user [" + ServerUser.AccountName + "].", false); return(true); } bool rslt = base.OnFileStreamComplete(fileName, totalFileLengthBytes, subType, arg); if (subType != 1) // install service { Log1.Logger("Zeus").Error("Received file transfer with unexpected reason [" + subType + "], [arg=" + arg + "]."); SendGenericMessage((int)GenericMessageType.ServiceInstallResult, "Received file transfer with unexpected reason [" + subType + "], [arg=" + arg + "].", false); // can't install the service. just delete the temp file. return(true); } string[] parts = arg.Split(char.Parse("|")); if (parts.Length < 3) { Log1.Logger("Zeus").Error("Service description was malformed. Can't install new service. [" + arg + "]."); SendGenericMessage((int)GenericMessageType.ServiceInstallResult, "Service description was malformed. Can't install new service. [" + arg + "].", false); // can't install the service. just delete the temp file. return(true); } string name = parts[1]; string desc = parts[2]; string serverExe = parts[3]; if (name.Length < 1 || desc.Length < 1 || serverExe.Length < 1) { Log1.Logger("Zeus").Error("Service description was malformed. Can't install new service. [Name=" + name + "], [Desc=" + desc + "]."); SendGenericMessage((int)GenericMessageType.ServiceInstallResult, "Service description was malformed. Can't install new service. [Name=" + name + "], [Desc=" + desc + "].", false); // can't install the service. just delete the temp file. return(true); } string deployPath = (string)Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Wisp\", "TargetDir", Environment.CurrentDirectory); if (deployPath == null || deployPath.Length < 1) { Log1.Logger("Zeus").Error("Unable to unzip new Wisp server directory as the Wisp install directory is not set in the registry. Re-run the Wisp Deployer utility on this machine to fix that problem."); SendGenericMessage((int)GenericMessageType.ServiceInstallResult, "Unable to unzip new Wisp server directory as the Wisp install directory is not set in the registry. Re-run the Wisp Deployer utility on this machine to fix that problem.", false); return(true); } if (Array.IndexOf(WispServices.GetInstalledServices(), name) > -1) { Log1.Logger("Zeus").Error("Unable to install new Wisp server [" + name + "] because a Wisp service by that name already exists on this machine."); SendGenericMessage((int)GenericMessageType.ServiceInstallResult, "Unable to install new Wisp server [" + name + "] because a Wisp service by that name already exists on this machine.", false); return(true); } if (!Directory.Exists(deployPath)) { Directory.CreateDirectory(deployPath); if (!Directory.Exists(deployPath)) { Log1.Logger("Zeus").Error("Unable to unzip new Wisp server directory as the Wisp install directory does not exist and could not be created. [" + deployPath + "]."); SendGenericMessage((int)GenericMessageType.ServiceInstallResult, "Unable to unzip new Wisp server directory as the Wisp install directory does not exist and could not be created. [" + deployPath + "].", false); return(true); } } string newServerRoot = Path.Combine(deployPath.TrimEnd(new char[] { '\\' }), "Server", name); if (Directory.Exists(newServerRoot)) { bool errDel = false; try { } catch { errDel = true; return(true); } if (Directory.Exists(newServerRoot) || errDel) { Log1.Logger("Zeus").Error("Can't install new Wisp service as a service by that name as it already exists on disk. [" + name + "]"); SendGenericMessage((int)GenericMessageType.ServiceInstallResult, "Can't install new Wisp service as a service by that name as it already exists on disk. [" + name + "]", false); return(true); } } if (!Zeus.Util.UnzipFile(fileName, newServerRoot)) { Log1.Logger("Zeus").Error("Unzip failure. Can't install new Wisp server."); SendGenericMessage((int)GenericMessageType.ServiceInstallResult, "Unzip failure. Can't install new Wisp server.", false); return(true); } if (!File.Exists(Path.Combine(newServerRoot, serverExe))) { Log1.Logger("Zeus").Error("Failed to install new Wisp server. The indicated exe [" + serverExe + "] does not exist in the server ZIP package."); SendGenericMessage((int)GenericMessageType.ServiceInstallResult, "Failed to install new Wisp server. The indicated exe [" + serverExe + "] does not exist in the server ZIP package.", false); return(true); } if (!WispServices.InstallService(Path.Combine(newServerRoot, serverExe), name, desc)) { Log1.Logger("Zeus").Error("Failed to install new Wisp server service."); SendGenericMessage((int)GenericMessageType.ServiceInstallResult, "Failed to install new Wisp server service.", false); return(true); } Log1.Logger("Zeus").Info("Installed new Wisp server service [" + name + "] at [" + serverExe + "] on the authority of [" + ServerUser.AccountName + "]."); SendGenericMessage((int)GenericMessageType.ServiceInstallResult, "Installed new Wisp server service [" + name + "]!", false); return(rslt); }
public override void StartServer() { base.StartServer(); // FORMAT: serverNAME|state|desc string[] services = WispServices.GetInstalledServices(); for (int i = 0; i < services.Length; i++) { string[] parts = services[i].Split(char.Parse("|")); if (parts.Length < 3) { continue; } string name = parts[0]; string state = parts[1]; string desc = parts[2]; object val = Registry.GetValue(@"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\" + name, "ImagePath", ""); if (val == null) { Log1.Logger("Server").Error("Wisp registry claims that service [" + name + "] is installed, but the Windows registry does not agree."); continue; } string exePath = val.ToString(); string directory = Path.GetDirectoryName(exePath); if (!Directory.Exists(directory)) { Log1.Logger("Server").Error("Windows registry claims that Wisp service [" + name + "] is installed at [" + directory + "] but that directory was not found."); continue; } string targetConfig = exePath + ".config"; if (!File.Exists(targetConfig)) { Log1.Logger("Server").Error("Unable to locate config file [" + targetConfig + "] for service [" + name + "] and so the connection port can't be determnined."); continue; } int port = 0; try { string configContents = File.ReadAllText(targetConfig); int loc = configContents.IndexOf("ListenOnPort"); if (loc < 0) { Log1.Logger("Server").Error("Failed to find 'ListenOnPort' directive in config file [" + targetConfig + "] for service [" + name + "]. Unable to determine port for that service."); continue; } int valLoc = configContents.IndexOf("\"", loc + 13); int valEndLoc = configContents.IndexOf("\"", valLoc + 1); string sport = configContents.Substring(valLoc + 1, valEndLoc - valLoc - 1); if (!int.TryParse(sport, out port) || port <= 0) { Log1.Logger("Server").Error("'ListenOnPort' directive in config file [" + targetConfig + "] for service [" + name + "] was in the wrong format - [" + sport + "]. Unable to determine port for that service."); continue; } } catch (Exception e) { Log1.Logger("Server").Error("Failed to read config file [" + targetConfig + "] for service [" + name + "]. Unable to determine port for that service.", e); continue; } GameServerInfo <OutboundServerConnection> gsi = new GameServerInfo <OutboundServerConnection>(); gsi.HostName = "localhost"; gsi.Name = name; string ip = "localhost"; try { gsi.ServiceID = 7; // 7eus IPHostEntry iphe = Dns.GetHostEntry("localhost"); // this call will delay the server from starting if it doesn't resolve fast enough. bool gotOne = false; foreach (IPAddress addy in iphe.AddressList) { if (addy.AddressFamily == AddressFamily.InterNetwork) { gotOne = true; ip = addy.ToString(); break; } } if (!gotOne) { Log1.Logger("Server.Network").Error("Could not resolve IP address for server " + gsi.Name + " (" + ip + ")"); continue; } } catch (Exception e) { Log1.Logger("Server.Network").Error("Error setting up outbound server connection. " + gsi.Name + " / " + gsi.HostName + " : " + e.Message, e); // try the next address in the config continue; } if (ip.Trim().Length < 1) { // try the next address in the config continue; } gsi.IP = ip; gsi.Port = port; gsi.IsOnline = false; gsi.LastUpdate = DateTime.UtcNow; if (OutboundServers.ContainsKey(gsi.UniqueID)) { continue; } OutboundServers.Add(gsi.UniqueID, gsi); } StartOutboundServerUpdate(); }