public static void OnLeave(LeaveEventArgs args) { if (args.Who >= TShockB.Players.Length || args.Who < 0) { //Something not right has happened return; } var tsplr = TShockB.Players[args.Who]; TShockB.Players[args.Who] = null; if (tsplr != null && tsplr.ReceivedInfo) { if (!tsplr.SilentKickInProgress && tsplr.State >= 3) { string playername = $"[c/4747BF:{tsplr.Name}]"; if (!tsplr.TPlayer.Male) { playername = $"[c/800080:{tsplr.Name}]"; } TShock.AllSendMessagev2($"{playername} saiu do servidor.", $"{playername} has left the server.", Color.Gray); } Logger.doLog($"{tsplr.Name} has left the server.", Config.DebugLevel.Info); if (tsplr.IsLoggedIn && !tsplr.IgnoreActionsForClearingTrashCan && Main.ServerSideCharacter && (!tsplr.Dead || tsplr.TPlayer.difficulty != 2)) { tsplr.PlayerData.CopyCharacter(tsplr); TShock.CharacterDB.InsertPlayerData(tsplr); } if (TShock.Config.RememberLeavePos && !tsplr.LoginHarassed) { TShock.RememberedPos.InsertLeavePos(tsplr.Name, tsplr.IP, (int)(tsplr.X / 16), (int)(tsplr.Y / 16)); } if (tsplr.tempGroupTimer != null) { tsplr.tempGroupTimer.Stop(); } } // Fire the OnPlayerLogout hook too, if the player was logged in and they have a TSPlayer object. if (tsplr != null && tsplr.IsLoggedIn) { TShockAPI.Hooks.PlayerHooks.OnPlayerLogout(tsplr); } // The last player will leave after this hook is executed. if (UtilsB.ActivePlayers() == 1) { if (TShock.Config.SaveWorldOnLastPlayerExit) { SaveManagerB.Instance.SaveWorld(); } TShockB.SetConsoleTitle(true); } }
private void SaveWorker() { while (true) { lock (_saveLock) { // NOTE: lock for the entire process so wait works in SaveWorld if (_saveQueue.Count > 0) { SaveTask task = _saveQueue.Dequeue(); if (null == task) { return; } else { // Ensure that save handler errors don't bubble up and cause a recursive call // These can be caused by an unexpected error such as a bad or out of date plugin try { if (task.direct) { OnSaveWorld(new WorldSaveEventArgs()); WorldFile.saveWorld(task.resetTime); } else { WorldFile.saveWorld(task.resetTime); } TShock.Log.ConsoleInfo("Mapa Salvo"); TShock.AllSendMessagev2("Mapa Salvo", "World Saved", Color.SeaGreen); TShock.Log.Info(string.Format("World saved at ({0})", Main.worldPathName)); } catch (Exception e) { TShock.AllSendMessagev2("O salvamento do mapa falhou", "World saved failed", Color.Red); TShock.Log.Error("World saved failed"); TShock.Log.Error(e.ToString()); } } } } _wh.WaitOne(); } }
/// <summary> /// SaveWorld event handler which notifies users that the server may lag /// </summary> public void OnSaveWorld(WorldSaveEventArgs args) { if (TShock.Config.AnnounceSave) { // Protect against internal errors causing save failures // These can be caused by an unexpected error such as a bad or out of date plugin try { TShock.Log.ConsoleInfo("Salvando Mundo. Lag momentâneo poderá ser notado durante alguns segundos."); TShock.AllSendMessagev2("Salvando Mundo. Lag momentâneo poderá ser notado durante alguns segundos.", "Saving World...", Color.DarkSeaGreen); } catch (Exception ex) { TShock.Log.Error("World saved notification failed"); TShock.Log.Error(ex.ToString()); } } }