public static String DeleteFile(String Path, String SubNames, Boolean postfixSubName = true, Char separator = ',') { try { var path = FormatPath(Path); var subNames = SubNames.ClearSplit(separator); if (!String.IsNullOrEmpty(SubNames)) { File.Delete(CurrentServer.MapPath(path)); } if (subNames != null) { foreach (String name in subNames) { DeleteFile(GetSubName(path, name, postfixSubName)); } } return(path); } catch { return(null); } }
public static String DeleteDirectory(string path) { path = FormatPath(path); try { foreach (var file in Directory.GetFiles(CurrentServer.MapPath(path))) { File.Delete(file); } foreach (var dir in Directory.GetDirectories(CurrentServer.MapPath(path))) { Directory.Delete(dir, true); } Thread.Sleep(1); Directory.Delete(CurrentServer.MapPath(path), true); } catch (Exception ex) { return(ex.Message); } return(path); }
public async Task OnDisconnect() { using (LogContext.PushProperty("Server", CurrentServer?.ToString())) { TotalConnectionTime += ConnectionLength; LastConnection = DateTime.UtcNow; Utilities.DefaultLogger.LogInformation("Client {client} is leaving the game", ToString()); try { await CurrentServer.Manager.GetClientService().Update(this); } catch (Exception e) { Utilities.DefaultLogger.LogError(e, "Could not update disconnected client {client}", ToString()); } finally { State = ClientState.Unknown; } } }
public static String DeleteFile(String Path, String[] SubDirectoryes = null) { try { var path = FormatPath(Path); if (File.Exists(CurrentServer.MapPath(path))) { File.Delete(CurrentServer.MapPath(path)); } if (SubDirectoryes != null) { foreach (String dir in SubDirectoryes) { DeleteFile(GetSubDirectoryPath(path, dir)); } } return(path); } catch { return(null); } }
/// <summary> /// Starts the portable web server. /// /// </summary> /// <param name="port">The port to run the server on.</param> /// <param name="rootPath">The directory which the server will serve.</param> public void StartServer(int port = 80, string rootPath = null) { if (string.IsNullOrWhiteSpace(rootPath)) { rootPath = Directory.GetCurrentDirectory(); } if (CurrentServer == null) { var fso = new FileServerOptions() { EnableDirectoryBrowsing = true }; fso.StaticFileOptions.ServeUnknownFileTypes = true; CurrentServer = WebHost.CreateDefaultBuilder(). ConfigureAppConfiguration((z, zz) => { }) .ConfigureServices((z, zz) => { }) .ConfigureKestrel((z, zz) => { zz.Configure().Options.ListenAnyIP(port); }) .ConfigureLogging((z, zz) => { zz.ClearProviders(); zz.AddSerilog(new LoggerConfiguration().WriteTo.Observers(zzz => { ServerLogObservable = zzz; }).CreateLogger(), true); }) .Configure(z => { z.UseStaticFiles(); z.UseFileServer(fso); }) .UseWebRoot(rootPath) .Build(); Task.Run(async() => await CurrentServer.StartAsync(currentServerCancellationToken)); } }
/// <summary> /// Aktiviert eine einzelne Quelle für den <i>Zapping Modus</i>. /// </summary> /// <param name="sender">Wird ignoriert.</param> /// <param name="e">Wird ignoriert.</param> private void cmdSetZapping_Click(object sender, EventArgs e) { // Attach to source SourceItem item = (SourceItem)selStation.SelectedItem; if (null == item) { return; } // Be safe try { // Forward CurrentRequest = CurrentServer.BeginSetZappingSource(item.Selection.SelectionKey, txStream.Text); // Install processor m_ResultProcessor = ProcessState; } catch (Exception ex) { // Report MessageBox.Show(this, ex.Message, Text); } // Update GUI UpdateGUI(); }
/// <summary> /// Aktiviert oder deaktivert den Netzwerkversand. /// </summary> /// <param name="sender">Wird ignoriert.</param> /// <param name="e">Wird ignoriert.</param> private void cmdStream_Click(object sender, EventArgs e) { // Attach to source SourceItem item = (SourceItem)selStation.SelectedItem; if (null == item) { return; } // Be safe try { // Load string target = txStream.Text.Trim(); // Forward CurrentRequest = CurrentServer.BeginSetStreamTarget(item.Selection.Source, string.IsNullOrEmpty(target) ? null : target); } catch (Exception ex) { // Report MessageBox.Show(this, ex.Message, Text); } // Update GUI UpdateGUI(); }
/// <summary> /// Beginnt die Sammlung für die Programmzeitschrift. /// </summary> /// <param name="sender">Wird ignoriert.</param> /// <param name="e">Wird ignoriert.</param> private void cmdStartEPG_Click(object sender, EventArgs e) { // Attach to source SourceItem item = (SourceItem)selStation.SelectedItem; // Be safe try { // List of sources List <SourceIdentifier> sources = new List <SourceIdentifier>(); // Add the one if (null != item) { sources.Add(item.Selection.Source); } // Start CurrentRequest = CurrentServer.BeginStartEPGCollection(sources.ToArray(), EPGExtensions.PREMIEREDirect | EPGExtensions.PREMIERESport | EPGExtensions.FreeSatUK); } catch (Exception ex) { // Report MessageBox.Show(this, ex.Message, Text); } // Update GUI UpdateGUI(); }
/// <summary> /// Stoppt den Empfang einer Quelle. /// </summary> /// <param name="sender">Wird ignoriert.</param> /// <param name="e">Wird ignoriert.</param> private void cmdUnReceive_Click(object sender, EventArgs e) { // Attach to source SourceItem item = (SourceItem)selStation.SelectedItem; if (null == item) { return; } // Be safe try { // Forward CurrentRequest = CurrentServer.BeginRemoveSource(item.Selection.Source); } catch (Exception ex) { // Report MessageBox.Show(this, ex.Message, Text); } // Update GUI UpdateGUI(); }
/// <summary> /// Beendet die aktuelle <i>Card Server Instanz</i>. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void cmdStop_Click(object sender, EventArgs e) { // Forget outstanding request CurrentRequest = null; // Be safe try { // Forward CurrentServer.Dispose(); } catch (Exception ex) { // Report MessageBox.Show(this, ex.Message, Text); } finally { // Forget CurrentServer = null; } // Refresh UpdateGUI(); }
public override void OnCreate() { var hT = new HierarchyTransform(Position, Rotation, null); foreach (var seRef in SceneDef.Entities) { Locators.Add(new LocToId() { Id = CurrentServer.AcquireId(), Loc = seRef.Def }); } foreach (var seRef in Locators) { var spawnedEntitySceneDef = seRef.Loc; var spawnedEntityDef = EntityObjectsMap.GetDefFromSceneDef(spawnedEntitySceneDef); var scenePos = (Vec2)spawnedEntitySceneDef.GetType().GetProperty(nameof(IPositionedEntity.Position)).GetValue(spawnedEntitySceneDef); var sceneRot = (float)spawnedEntitySceneDef.GetType().GetProperty(nameof(IPositionedEntity.Rotation)).GetValue(spawnedEntitySceneDef); var objItemDef = spawnedEntitySceneDef.GetType().GetProperty(nameof(WorldItemEntity.StartingItemDef)); var itemDef = objItemDef == null ? null : ((DefRef <ItemDef>)objItemDef.GetValue(spawnedEntitySceneDef)).Def; var lT = new HierarchyTransform(scenePos, sceneRot, hT); CurrentServer.Create(seRef.Id, EntityObjectsMap.GetTypeFromDef(spawnedEntityDef), e => { ((IEntityObject)e).Def = (IEntityObjectDef)(((ISceneDef)spawnedEntitySceneDef).Object.Def); ((IPositionedEntity)e).Position = lT.GlobalPos; ((IPositionedEntity)e).Rotation = lT.GlobalRot; if (e is WorldItemEntity wie) { wie.StartingItemDef = itemDef; } }); } }
public static String CreateDirectory(string path, string[] subDirectoryes = null) { path = FormatPath(path); try { if (!Directory.Exists(CurrentServer.MapPath(path))) { Directory.CreateDirectory(CurrentServer.MapPath(path)); if (subDirectoryes != null) { foreach (String dir in subDirectoryes) { Directory.CreateDirectory(CurrentServer.MapPath(path + dir)); } } } } catch { return(null); } return(path); }
/// <summary> /// Scans database with a specific pattern. /// </summary> /// <param name="pattern">A pattern like basekey:*</param> /// <param name="count">Fetch limit</param> /// <returns>List of identities</returns> public List <string> Scan(string pattern, int count = 10000) { var baseKey = Activator.CreateInstance <T>().BaseKey; if (!pattern.StartsWith(baseKey)) { pattern = baseKey + pattern; } List <string> listOfKeys = new List <string>(); var keysResult = CurrentServer.Keys(DefaultDatabase, pattern, count, CommandFlags.None); foreach (var key in keysResult) { listOfKeys.Add(key.ToString()); } //int nextCursor = 0; //do //{ // var redisResult = CurrentDatabase.Execute("SCAN", new object[] { nextCursor.ToString(), "MATCH", pattern, "COUNT", count.ToString() }); // var innerResult = (RedisResult[])redisResult; // nextCursor = int.Parse((string)innerResult[0]); // List<string> resultLines = ((string[])innerResult[1]).ToList(); // listOfKeys.AddRange(resultLines); //} //while (nextCursor != 0); return(listOfKeys); }
/// <summary> /// /// </summary> /// <returns></returns> public bool StopGameServer() { CurrentServer.StopServer(); CurrentRole = CurrentServer.Status == ServerStatus.Running ? MultiplayerRole.Server : MultiplayerRole.None; return(CurrentServer.Status != ServerStatus.Running); }
/// <summary> /// /// </summary> /// <returns></returns> public bool StopGameServer() { CurrentServer.StopServer(); CurrentRole = CurrentServer.IsServerStarted ? MultiplayerRole.Server : MultiplayerRole.None; return(!CurrentServer.IsServerStarted); }
/// <summary> /// Stops the running portable web server. /// /// </summary> public void StopServer() { if (CurrentServer != null) { CurrentServer.StopAsync(currentServerCancellationToken); CurrentServer = null; } }
private void AppBarGeniusShuffleButton_Click() { if (CurrentServer == null || !CurrentServer.IsConnected) { return; } RemoteUtility.HandleLibraryPlayTask(CurrentServer.SendGeniusShuffleCommandAsync()); }
private async void iTunesRadioNeverPlayThisSongMenuItem_Click(object sender, RoutedEventArgs e) { if (CurrentServer == null || !CurrentServer.IsConnected) { return; } await CurrentServer.SendiTunesRadioNeverPlayThisSongAsync(); }
protected void ToggleVisualizer() { if (CurrentServer == null) { return; } CurrentServer.SendVisualizerCommand(!CurrentServer.VisualizerActive); }
private void RepeatButton_Click(object sender, RoutedEventArgs e) { if (CurrentServer == null || !CurrentServer.IsConnected) { return; } CurrentServer.SendRepeatStateCommand(); }
public async void GetApplications() { CurrentAppList = await CurrentServer.GetApplications(); var pList = new List <JobDataGridPresentData>(); foreach (var app in currentAppList) { pList.Add(new JobDataGridPresentData(app)); } PresentList = pList; }
public void StopEverything() { switch (CurrentRole) { case MultiplayerRole.Client: CurrentClient.Disconnect(); break; case MultiplayerRole.Server: CurrentServer.StopServer(); break; } }
public static void Save(Bitmap SourceBitmap, String Path, Int32 Quality = 95, String Format = "", Boolean Rotate90 = false) { ImageCodecInfo[] Encoders = ImageCodecInfo.GetImageEncoders(); ImageCodecInfo CodecInfo = Encoders.First(x => x.MimeType == GetImageContentType(Path)); EncoderParameters EncoderParameters = new EncoderParameters(Rotate90 ? 2 : 1); EncoderParameters.Param[0] = new EncoderParameter(Encoder.Quality, Quality); if (Rotate90) { EncoderParameters.Param[1] = new EncoderParameter(Encoder.Transformation, (long)EncoderValue.TransformRotate90); } SourceBitmap.Save(CurrentServer.MapPath(Path), CodecInfo, EncoderParameters); }
/// <summary> /// Starts the game server on the given port. /// </summary> /// <param name="port">The port to start the server on.</param> /// <param name="password">The password to use.</param> /// <param name="hostUsername">The username of the host player.</param> /// <returns>If the server was started successfully.</returns> public bool StartGameServer(int port, string password, string hostUsername) { if (CurrentRole == MultiplayerRole.Client) { return(false); } // Create the server and start it var isConnected = CurrentServer.StartServer(new ServerConfig(port, hostUsername, password)); // Set the current role CurrentRole = isConnected ? MultiplayerRole.Server : MultiplayerRole.None; return(isConnected); }
/// <summary> /// /// </summary> /// <param name="port"></param> /// <param name="password"></param> /// <returns></returns> public bool StartGameServer(int port = 4230, string password = "") { if (CurrentServer.Status == ServerStatus.Running) { return(true); } // Create the server and start it var isConnected = CurrentServer.StartServer(new ServerConfig(port)); // Set the current role CurrentRole = isConnected ? MultiplayerRole.Server : MultiplayerRole.None; return(isConnected); }
public static bool PathExist(string path) { path = FormatPath(path); if (File.Exists(CurrentServer.MapPath(path))) { return(true); } if (Directory.Exists(CurrentServer.MapPath(path))) { return(true); } return(false); }
/// <summary> /// Stops the client or server, depending on the current role /// </summary> public void StopEverything() { switch (CurrentRole) { case MultiplayerRole.Client: CurrentClient.Disconnect(); ChatLogPanel.PrintGameMessage("Disconnected from server."); break; case MultiplayerRole.Server: CurrentServer.StopServer(); ChatLogPanel.PrintGameMessage("Server stopped."); break; } CurrentRole = MultiplayerRole.None; }
public virtual void Join(string name) { var defaultJob = DefsHolder.Instance.LoadDef <RoleDef>("/Arhaeologist"); var charDef = DefsHolder.Instance.LoadDef <IEntityObjectDef>("/CharDef"); var charId = CurrentServer.Create <CharacterEntity>((ent) => { ent.AuthorityServerId = CurrentServer.CurrentServerCallbackId.Value; ent.Job = defaultJob; ent.Def = charDef; ent.Name = name; //ent.Position = Vec2.Random(10, 10); }); CurrentServer.Replicate(charId, CurrentServer.CurrentServerCallbackId.Value, this); CurrentServer.GrantAuthority(charId, CurrentServer.CurrentServerCallbackId.Value); }
public void Tick() { if (SpawnedObjectId == default || CurrentServer.GetGhost(SpawnedObjectId) == null) { SpawnedObjectId = CurrentServer.Create(EntityObjectsMap.GetTypeFromDef(((SimpleSpawnerDef)Def).ObjectToSpawn.Def), (ent) => { if (ent is IPositionedEntity) { ((IPositionedEntity)ent).Position = Position; } ((IEntityObject)ent).Def = ((SimpleSpawnerDef)Def).ObjectToSpawn.Def; }); } }
protected override void OnAuthenticateSucceeded() { SessionBase session; if (IsOAuthSettingMode) { // OAuth Setting Mode session = CurrentServer.GetOrCreateSession(Guid.NewGuid().ToString(), (server, sessionId) => new OAuthSettingSession(sessionId, server)); } else { // Authenticated session = CurrentServer.GetOrCreateSession(TwitterUser); } session.Attach(this); }