public string ConvertTag(LanguageTagParameters parameters)
 {
    return languageTags.GetTag(parameters);
 }
      //Get the given tag but "localized" for the given user.
      public string GetTag(LanguageTagParameters parameters)
      {
         //This is just silly
         if (parameters.Tag == ChatTags.None)
            return "";

         try
         {
            //For a lot of errors, we're better off returning the default tag
            string defaultReplacement = ReplaceText(DefaultTags[parameters.Tag], parameters.Replacements);

            //Oops, tag dictionary was not initialized. Using default
            if(tags == null)
            {
               if(!printedDefaultTagsWarning)
               {
                  Log("Language not initialized. Using defaults", LogLevel.Warning);
                  printedDefaultTagsWarning = true;
               }
               
               return defaultReplacement;
            }
            //Oops, the user's language couldn't be found (wut). Use default
            else if (!tags.ContainsKey(parameters.Language))
            {
               Log(parameters.User.Username + "'s language (" + parameters.Language + ") was not found! Using default");
               return defaultReplacement;
            }

            string realTag = parameters.Tag.ToString().ToLower();
            Tuple<string, string> tagTuple = Tuple.Create(parameters.Language, realTag);

            //Oops, looks like the dictionary we initialized from doesn't have the tag we're looking for.
            if(!tags[parameters.Language].ContainsKey(realTag))
            {
               //Don't bombard the console with warning about missing tags. Only do it the first time
               if(!missingTagWarnings.Contains(tagTuple))
               {
                  missingTagWarnings.Add(tagTuple);
                  Log("Language dictionary was missing tag: " + realTag + " for language: " + parameters.Language, LogLevel.Warning);
               }

               return defaultReplacement;
            }

            return ReplaceText(tags[parameters.Language][realTag], parameters.Replacements);
         }
         catch (Exception e)
         {
            Log("Error while retrieving tag " + parameters.Tag + " for user " + parameters.User.Username + ": " + e.Message);
            return "Tag error: Fatal internal error. The server is broken";
         }
      }
Exemplo n.º 3
0
 public SystemMessageJSONObject NewSystemMessageFromTag(LanguageTagParameters parameters)
 {
    return new SystemMessageJSONObject(manager.ConvertTag(parameters));
 }
//      public void SelectiveBroadcast(string message, string tag, List<Chat> exclude = null)
//      {
//         if (string.IsNullOrEmpty(message))
//            return;
//
//         if (exclude == null)
//            exclude = new List<Chat>();
//
//         List<Chat> receivers = new List<Chat>();
//         lock (managerLock)
//         {
//            Log("Enter selective broadcast lock", MyExtensions.Logging.LogLevel.Locks);
//            receivers = activeChatters.Except(exclude).ToList();
//            receivers = receivers.Where(x => AllAcceptedTagsForUser(x.UID).Contains(tag)).ToList();
//            Log("Exit selective broadcast lock", MyExtensions.Logging.LogLevel.Locks);
//         }
//
//         Log("Just before broadast", MyExtensions.Logging.LogLevel.SuperDebug);
//         foreach (Chat chatter in receivers)
//            chatter.MySend(message);
//         Log("Just after broadcast", MyExtensions.Logging.LogLevel.SuperDebug);
//      }

      public void Broadcast(LanguageTagParameters parameters, JSONObject container, List<Chat> exclude = null)
      {
         if (exclude == null)
            exclude = new List<Chat>();

//         List<Chat> receivers = new List<Chat>();
//         lock (managerLock)
//         {
//            Log("Enter broadcast tag lock", MyExtensions.Logging.LogLevel.Locks);
//            receivers = activeChatters.Except(exclude).ToList();
//            Log("Exit broadcast tag lock", MyExtensions.Logging.LogLevel.Locks);
//         }

         Log("Just before tag broadast", MyExtensions.Logging.LogLevel.SuperDebug);
         foreach (Chat chatter in ConnectedUsers().Select(x => (Chat)x).Except(exclude))
         {
            parameters.UpdateUser(chatter.ThisUser);  //Update the message to reflect user preferences
            chatter.MySend(parameters, container);    //Send a tag message by filling the container with the tag parameters
         }
         Log("Just after tag broadcast", MyExtensions.Logging.LogLevel.SuperDebug);
      }
Exemplo n.º 5
0
 public WarningJSONObject NewWarningFromTag(LanguageTagParameters parameters)
 {
    return new WarningJSONObject(manager.ConvertTag(parameters));
 }
Exemplo n.º 6
0
      public void MySend(LanguageTagParameters parameters, JSONObject container)
      {
         string message = manager.ConvertTag(parameters);

         if (container is WarningJSONObject)
         {
            ((WarningJSONObject)container).message = message;
         }
         else if (container is SystemMessageJSONObject)
         {
            ((SystemMessageJSONObject)container).message = message;
         }
         else
         {
            Log("Didn't get a proper container for a language tag. Using system message as default", LogLevel.Warning);
            ((SystemMessageJSONObject)container).message = message;
         }

         MySend(container.ToString());
      }
Exemplo n.º 7
0
 public SystemMessageJSONObject NewSystemMessageFromTag(LanguageTagParameters parameters)
 {
    return new SystemMessageJSONObject(manager.ConvertTag(parameters)) 
    { subtype = parameters.Tag.ToString().ToLower(), uid = parameters.SendingUser.UID };
 }
Exemplo n.º 8
0
      public void MySend(LanguageTagParameters parameters, JSONObject container)
      {
         string message = manager.ConvertTag(parameters);
         //string subtype = parameters.Tag.ToString().ToLower();

         if (container is WarningJSONObject)
         {
            container = NewWarningFromTag(parameters);
            /*   (WarningJSONObject)container;
            warning.message = message;
            warning.subtype = subtype;*/
         }
         else if (container is SystemMessageJSONObject)
         {
            container = NewSystemMessageFromTag(parameters);
            /*((SystemMessageJSONObject)container).message = message;
            ((SystemMessageJSONObject)container).subtype = subtype;*/
         }
         else
         {
            Log("Didn't get a proper container for a language tag. Using system message as default", LogLevel.Warning);
            ((SystemMessageJSONObject)container).message = message;
         }

         MySend(container.ToString());
      }
      public void Broadcast(LanguageTagParameters parameters, JSONObject container, List<Chat> exclude = null)
      {
         if (exclude == null)
            exclude = new List<Chat>();

         Log("Just before tag broadast", MyExtensions.Logging.LogLevel.SuperDebug);
         foreach (Chat chatter in ConnectedUsers().Select(x => (Chat)x).Except(exclude))
         {
            parameters.UpdateUser(chatter.ThisUser);  //Update the message to reflect user preferences

            //Send a tag message by filling the container with the tag parameters
            if(!parameters.RawSendingUser.ShadowBanned || parameters.RawSendingUser.UID == chatter.ThisUser.UID)
               chatter.MySend(parameters, container);    
         }
         Log("Just after tag broadcast", MyExtensions.Logging.LogLevel.SuperDebug);
      }