public ActionResult RestartGossipServer() { IEnumerable <WebSocket> gossipServers = LiveCache.GetAll <WebSocket>(); foreach (WebSocket server in gossipServers) { server.Abort(); } IGossipConfig gossipConfig = ConfigDataCache.Get <IGossipConfig>(new ConfigDataCacheKey(typeof(IGossipConfig), "GossipSettings", ConfigDataType.GameWorld)); Func <Member[]> playerList = () => LiveCache.GetAll <IPlayer>() .Where(player => player.Descriptor != null && player.Template <IPlayerTemplate>().Account.Config.GossipSubscriber) .Select(player => new Member() { Name = player.AccountHandle, WriteTo = (message) => player.WriteTo(new string[] { message }), BlockedMembers = player.Template <IPlayerTemplate>().Account.Config.Acquaintences.Where(acq => !acq.IsFriend).Select(acq => acq.PersonHandle), Friends = player.Template <IPlayerTemplate>().Account.Config.Acquaintences.Where(acq => acq.IsFriend).Select(acq => acq.PersonHandle) }).ToArray(); void exceptionLogger(Exception ex) => LoggingUtility.LogError(ex); void activityLogger(string message) => LoggingUtility.Log(message, LogChannels.GossipServer); GossipClient gossipServer = new GossipClient(gossipConfig, exceptionLogger, activityLogger, playerList); Task.Run(() => gossipServer.Launch()); LiveCache.Add(gossipServer, "GossipWebClient"); return(RedirectToAction("Index", new { Message = "Gossip Server Restarted" })); }
public override void OnClose() { IEnumerable <IPlayer> validPlayers = LiveCache.GetAll <IPlayer>().Where(player => player.Descriptor != null && player.Template <IPlayerTemplate>().Account.Config.WantsNotification(_currentPlayer.AccountHandle, false, AcquaintenceNotifications.LeaveGame)); foreach (IPlayer player in validPlayers) { player.WriteTo(new string[] { string.Format("{0} has left the game.", _currentPlayer.AccountHandle) }); } if (_currentPlayer != null && _currentPlayer.Template <IPlayerTemplate>().Account.Config.GossipSubscriber) { GossipClient gossipClient = LiveCache.Get <GossipClient>("GossipWebClient"); if (gossipClient != null) { gossipClient.SendNotification(_currentPlayer.AccountHandle, Notifications.LeaveGame); } } base.OnClose(); }
public static void PreloadSupportingEntities() { //Load the "config" data first ConfigData.LoadEverythingToCache(); LexicalProcessor.LoadWordnet(); IGlobalConfig globalConfig = ConfigDataCache.Get <IGlobalConfig>(new ConfigDataCacheKey(typeof(IGlobalConfig), "LiveSettings", ConfigDataType.GameWorld)); //We dont move forward without a global config if (globalConfig == null) { globalConfig = new GlobalConfig(); globalConfig.SystemSave(); } if (globalConfig.BaseLanguage == null) { ILanguage baseLanguage = ConfigDataCache.GetAll <ILanguage>().FirstOrDefault(); if (baseLanguage == null) { LoggingUtility.Log("There are no valid languages. Generating new base language.", LogChannels.SystemErrors, true); baseLanguage = new Language() { Name = "English", GoogleLanguageCode = "en-us", AntecendentPunctuation = true, PrecedentPunctuation = false, Gendered = false, UIOnly = true }; baseLanguage.SystemSave(); } globalConfig.BaseLanguage = baseLanguage; globalConfig.SystemSave(); } //Ensure we have base words for the language every time globalConfig.BaseLanguage.SystemSave(); //Hoover up all the verbs from commands that someone might have coded ProcessSystemVerbs(globalConfig.BaseLanguage); IGossipConfig gossipConfig = ConfigDataCache.Get <IGossipConfig>(new ConfigDataCacheKey(typeof(IGossipConfig), "GossipSettings", ConfigDataType.GameWorld)); HttpApplication instance = HttpContext.Current.ApplicationInstance; Assembly asm = instance.GetType().BaseType.Assembly; Version v = asm.GetName().Version; //We dont move forward without a global config if (gossipConfig == null) { gossipConfig = new GossipConfig { ClientName = "Warrens: White Sands" }; } //Update version gossipConfig.Version = string.Format(CultureInfo.InvariantCulture, @"{0}.{1}.{2} (r{3})", v.Major, v.Minor, v.Build, v.Revision); gossipConfig.SystemSave(); //Load structural data next Templates.LoadEverythingToCache(); HotBackup hotBack = new HotBackup(); //Our live data restore failed, reload the entire world from backing data if (!hotBack.RestoreLiveBackup()) { hotBack.NewWorldFallback(); } if (gossipConfig.GossipActive) { Func <Member[]> playerList = () => LiveCache.GetAll <IPlayer>() .Where(player => player.Descriptor != null && player.Template <IPlayerTemplate>().Account.Config.GossipSubscriber) .Select(player => new Member() { Name = player.AccountHandle, WriteTo = (message) => player.WriteTo(new string[] { message }), BlockedMembers = player.Template <IPlayerTemplate>().Account.Config.Acquaintences.Where(acq => !acq.IsFriend).Select(acq => acq.PersonHandle), Friends = player.Template <IPlayerTemplate>().Account.Config.Acquaintences.Where(acq => acq.IsFriend).Select(acq => acq.PersonHandle) }).ToArray(); void exceptionLogger(Exception ex) => LoggingUtility.LogError(ex); void activityLogger(string message) => LoggingUtility.Log(message, LogChannels.GossipServer); GossipClient gossipServer = new GossipClient(gossipConfig, exceptionLogger, activityLogger, playerList); Task.Run(() => gossipServer.Launch()); LiveCache.Add(gossipServer, "GossipWebClient"); } Func <bool> backupFunction = hotBack.WriteLiveBackup; Func <bool> backingDataBackupFunction = Templates.WriteFullBackup; //every 30 minutes after half an hour Processor.StartSingeltonChainedLoop("HotBackup", 30 * 60, 30 * 60, -1, backupFunction); //every 2 hours after 1 hour Processor.StartSingeltonChainedLoop("BackingDataFullBackup", 60 * 60, 120 * 60, -1, backingDataBackupFunction); }
/// <summary> /// Initialize module /// </summary> /// <param name="repositories"></param> public void Initialize(List <ICrudModelRepository> repositories) { var terminalManager = ModuleManager.GetManager <ITerminalManager>(); var configuration = ModuleManager.GetConfiguration(); if (configuration.GetSection("Modules").GetSection("Gossip").GetValue <bool>("Enabled")) { ((TerminalManager)terminalManager).OnTerminalCreated += (ITerminal terminal) => { GossipConfig.Members.Add(new GossipMembers() { Terminal = terminal }); }; ((TerminalManager)terminalManager).OnTerminalDestroyed += (ITerminal terminal) => { GossipConfig.Members.RemoveAll(x => x.Terminal.GetId() == terminal.GetId()); }; if (configuration.GetSection("Gossip") != null) { var clientId = configuration.GetSection("Gossip").GetValue <string>("ClientId"); var clientSecret = configuration.GetSection("Gossip").GetValue <string>("ClientSecret"); var gossipConfig = new GossipConfig() { GossipActive = true, ClientId = clientId, ClientSecret = clientSecret, ClientName = "Before Our Time", UserAgent = "bot-0.2.16", SuspendMultiplier = 2, SuspendMultiplierMaximum = 4, SupportedChannels = new HashSet <string>() { "testing" }, SupportedFeatures = new HashSet <string>() { "channels" } }; var gossipClient = new GossipClient( gossipConfig, (Exception e) => { Console.WriteLine($"EXCEPTION: {e.Message}"); }, (string message) => { Console.WriteLine($"LOG: {message}"); }, () => { GossipConfig.Members.ForEach((gossipMember) => { if (gossipMember.Terminal.GetPlayerId() != null && gossipMember.Member == null) { var item = ModuleManager .GetManager <IItemManager>() .Read(gossipMember.Terminal.GetPlayerId().Value); gossipMember.Member = new Member() { Name = item.GetProperty <VisibleItemProperty>().Name, WriteTo = (message) => { Console.WriteLine($"GOSSIP: {message}\n"); } }; } }); var members = GossipConfig.Members.Where(x => x.Terminal.GetPlayerId() != null) .Select(x => x.Member).ToArray <Member>(); return(members); } ); gossipClient.Launch(); } } }
/// <summary> /// Validates the game account from the aspnet cookie /// </summary> /// <param name="handshake">the headers from the http request</param> private void ValidateUser(Cookie cookie) { //Grab the user GetUserIDFromCookie(cookie.Value); ApplicationUser authedUser = UserManager.FindById(_userId); IPlayerTemplate currentCharacter = authedUser.GameAccount.Characters.FirstOrDefault(ch => ch.Id.Equals(authedUser.GameAccount.CurrentlySelectedCharacter)); if (currentCharacter == null) { Send("<p>No character selected</p>"); return; } //Try to see if they are already live _currentPlayer = LiveCache.GetAll <IPlayer>().FirstOrDefault(player => player.Descriptor != null && player.Descriptor._userId == _userId); //Check the backup if (_currentPlayer == null) { PlayerData playerDataWrapper = new PlayerData(); _currentPlayer = playerDataWrapper.RestorePlayer(currentCharacter.AccountHandle, currentCharacter); } //else new them up if (_currentPlayer == null) { _currentPlayer = new Player(currentCharacter); } _currentPlayer.Descriptor = this; //We need to barf out to the connected client the welcome message. The client will only indicate connection has been established. List <string> welcomeMessage = new List <string> { string.Format("Welcome to alpha phase Under the Eclipse, {0}", currentCharacter.FullName()), "Please feel free to LOOK around." }; _currentPlayer.WriteTo(welcomeMessage); //Send the look command in Interpret.Render("look", _currentPlayer); try { IEnumerable <IPlayer> validPlayers = LiveCache.GetAll <IPlayer>().Where(player => player.Descriptor != null && player.Template <IPlayerTemplate>().Account.Config.WantsNotification(_currentPlayer.AccountHandle, false, AcquaintenceNotifications.EnterGame)); foreach (IPlayer player in validPlayers) { player.WriteTo(new string[] { string.Format("{0} has entered the game.", _currentPlayer.AccountHandle) }); } if (authedUser.GameAccount.Config.GossipSubscriber) { GossipClient gossipClient = LiveCache.Get <GossipClient>("GossipWebClient"); if (gossipClient != null) { gossipClient.SendNotification(authedUser.GlobalIdentityHandle, Notifications.EnterGame); } } } catch (Exception ex) { LoggingUtility.LogError(ex, LogChannels.SocketCommunication); } }
/// <summary> /// Executes this command /// </summary> internal override bool ExecutionBody() { List <string> sb = new List <string>(); IPlayer playerActor = Actor.GetType().GetInterfaces().Contains(typeof(IPlayer)) ? Actor as IPlayer : null; if (playerActor != null && !playerActor.Template <IPlayerTemplate>().Account.Config.GossipSubscriber) { sb.Add(string.Format("You have disabled the Gossip network.", Subject)); } else { string directTarget = string.Empty; string directTargetGame = string.Empty; if (Subject != null) { string[] names = Subject.ToString().Split(new char[] { '@' }); if (names.Count() == 2) { directTarget = names[0]; directTargetGame = names[1]; } else if (names.Count() == 1) { directTarget = names[0]; } } GossipClient gossipClient = LiveCache.Get <GossipClient>("GossipWebClient"); string userName = Actor.TemplateName; if (playerActor != null) { userName = playerActor.AccountHandle; } if (!string.IsNullOrWhiteSpace(directTarget) && !string.IsNullOrWhiteSpace(directTargetGame)) { gossipClient.SendDirectMessage(userName, directTargetGame, directTarget, Target.ToString()); sb.Add(string.Format("You tell {1}@{2} '{0}'", Target, directTarget, directTargetGame)); } else { if (string.IsNullOrWhiteSpace(directTarget)) { gossipClient.SendMessage(userName, Target.ToString()); sb.Add(string.Format("You gossip '{0}'", Target)); } else { gossipClient.SendMessage(userName, Target.ToString(), directTarget); sb.Add(string.Format("You {1} '{0}'", Target, directTarget)); } } } ILexicalParagraph toActor = new LexicalParagraph(sb.ToString()); //TODO: language outputs Message messagingObject = new Message(toActor); messagingObject.ExecuteMessaging(Actor, null, null, null, null); return(true); }