Beispiel #1
0
        public void OnCommand(GameClient client, string[] args)
        {
            if (IsSpammingCommand(client.Player, "translate"))
            {
                return;
            }

            if (args.Length < 2)
            {
                DisplaySyntax(client);
                return;
            }

            switch (args[1].ToLower())
            {
            case "add":
            {
                if (client.Account.PrivLevel != (uint)ePrivLevel.Player)
                {
                    if (args.Length < 5)
                    {
                        DisplayMessage(client, "[Language-Manager] Usage: '/translate add [Language] [TranslationId] [Text]'");
                        return;
                    }

                    LanguageDataObject translation = LanguageMgr.GetLanguageDataObject(args[2].ToUpper(), args[3], LanguageDataObject.eTranslationIdentifier.eSystem);
                    if (translation != null)
                    {
                        DisplayMessage(client, "[Language-Manager] This translation id is already in use by the given language! ( Language <" + args[2].ToUpper() + "> - TranslationId <" + args[3] + "> )");
                        return;
                    }

                    translation = new DBLanguageSystem();
                    ((DBLanguageSystem)translation).TranslationId = args[3];
                    ((DBLanguageSystem)translation).Text          = args[4];
                    ((DBLanguageSystem)translation).Language      = args[2];

                    GameServer.Database.AddObject(translation);
                    LanguageMgr.RegisterLanguageDataObject(translation);
                    DisplayMessage(client, "[Language-Manager] Translation successfully added! (Language <" + args[2].ToUpper() + "> - TranslationId <" + args[3] + "> )");
                    return;
                }

                return;
            }

            case "debug":
            {
                bool debug = client.Player.TempProperties.getProperty("LANGUAGEMGR-DEBUG", false);
                debug = !debug;
                client.Player.TempProperties.setProperty("LANGUAGEMGR-DEBUG", debug);
                DisplayMessage(client, "[Language-Manager] Debug mode: " + (debug ? "ON" : "OFF"));
                return;
            }

            case "memadd":
            {
                // This sub command adds a new language object to your temp properties which will "pre save" the given translation id
                // and language. Use this sub command if the translation id or text of your new translation requires more room
                // as the DAoC chat allows you to use in one line. Use the memsave sub command to add a text to this language object
                // and to save it into the database - or use "memclear" to remove the language object from your temp properties.
                if (args.Length < 4)
                {
                    DisplayMessage(client, "[Language-Manager] Usage: '/translate memadd [Language] [TranslationId]'");
                }
                else
                {
                    LanguageDataObject lngObj = (LanguageDataObject)client.Player.TempProperties.getProperty <object>(LANGUAGEMGR_MEM_LNG_OBJ, null);

                    if (lngObj != null)
                    {
                        DisplayMessage(client, "[Language-Manager] Can't add language object, there is already another one!");
                    }
                    else
                    {
                        lngObj = LanguageMgr.GetLanguageDataObject(args[2].ToUpper(), args[3], LanguageDataObject.eTranslationIdentifier.eSystem);

                        if (lngObj != null)
                        {
                            DisplayMessage(client, "[Language-Manager] The combination of the given TranslationId <" + args[3] + "> and Language <" + args[2].ToUpper() + "> is already in use!");
                        }
                        else
                        {
                            lngObj = new DBLanguageSystem();
                            ((DBLanguageSystem)lngObj).TranslationId = args[3];
                            ((DBLanguageSystem)lngObj).Language      = args[2];

                            client.Player.TempProperties.setProperty(LANGUAGEMGR_MEM_LNG_OBJ, lngObj);
                            DisplayMessage(client, "[Language-Manager] Language object successfully added to your temporary properties! ( Language <" + args[2].ToUpper() + "> TranslationId <" + args[3] + "> )");
                        }
                    }
                }

                return;
            }

            case "memclear":
            {
                // Removes the language object from your temp properties you've previously added with the "memadd" sub command.
                LanguageDataObject lngObj = (LanguageDataObject)client.Player.TempProperties.getProperty <object>(LANGUAGEMGR_MEM_LNG_OBJ, null);

                if (lngObj == null)
                {
                    DisplayMessage(client, "[Language-Manager] No language object found.");
                }
                else
                {
                    client.Player.TempProperties.removeProperty(LANGUAGEMGR_MEM_LNG_OBJ);
                    DisplayMessage(client, "[Language-Manager] Language object successfully removed.");
                }

                return;
            }

            case "memsave":
            {
                // See "memadd" sub command for a description.
                if (args.Length < 3)
                {
                    DisplayMessage(client, "[Language-Manager] Usage: '/translate memsave [Text]'");
                }
                else
                {
                    LanguageDataObject lngObj = (LanguageDataObject)client.Player.TempProperties.getProperty <object>(LANGUAGEMGR_MEM_LNG_OBJ, null);

                    if (lngObj == null)
                    {
                        DisplayMessage(client, "[Language-Manager] No language object found.");
                    }
                    else
                    {
                        if (args.Length > 3)
                        {
                            ((DBLanguageSystem)lngObj).Text = string.Join(" ", args, 2, args.Length - 2);
                        }
                        else
                        {
                            ((DBLanguageSystem)lngObj).Text = args[2];
                        }

                        if (!LanguageMgr.RegisterLanguageDataObject(lngObj))
                        {
                            DisplayMessage(client, "[Language-Manager] Can't register language object in LanguageMgr, there is already another one!");
                        }
                        else
                        {
                            GameServer.Database.AddObject(lngObj);
                            client.Player.TempProperties.removeProperty(LANGUAGEMGR_MEM_LNG_OBJ);
                            DisplayMessage(client, "[Language-Manager] Translation successfully added into the database and registered in LanguageMgr.");
                        }
                    }
                }

                return;
            }

            case "memshow":
            {
                LanguageDataObject lngObj = (LanguageDataObject)client.Player.TempProperties.getProperty <object>(LANGUAGEMGR_MEM_LNG_OBJ, null);

                if (lngObj == null)
                {
                    DisplayMessage(client, "[Language-Manager] No language object found.");
                }
                else
                {
                    DisplayMessage(client, "[Language-Manager] Language object info: Language <" + lngObj.Language + "> TranslationId <" + lngObj.TranslationId + ">");
                }

                return;
            }

            case "refresh":
            {
                if (args.Length < 5)
                {
                    DisplayMessage(client, "[Language-Manager] Usage: '/translate refresh [Language] [TranslationId] [Text]'");
                }
                else
                {
                    LanguageDataObject lngObj = LanguageMgr.GetLanguageDataObject(args[2].ToUpper(), args[3], LanguageDataObject.eTranslationIdentifier.eSystem);

                    if (lngObj == null)
                    {
                        DisplayMessage(client, "[Language-Manager] Can't find TranslationId <" + args[3] + "> (Language <" + args[2].ToUpper() + "> !");
                    }
                    else
                    {
                        ((DBLanguageSystem)lngObj).Text = args[3];
                        GameServer.Database.SaveObject(lngObj);
                        DisplayMessage(client, "[Language-Manager] TranslationId <" + args[3] + "> (Language: " + args[2].ToUpper() + " ) successfully updated in database!");
                    }
                }

                return;
            }

            case "select":
            {
                if (args.Length < 4)
                {
                    DisplayMessage(client, "[Language-Manager] Usage: '/translate select [Language] [TranslationId]'");
                }
                else
                {
                    LanguageDataObject lngObj = (LanguageDataObject)client.Player.TempProperties.getProperty <object>(LANGUAGEMGR_SEL_LNG_OBJ, null);

                    if (lngObj != null)
                    {
                        DisplayMessage(client, "[Language-Manager] You already have selected a language object! ( Language <" + ((DBLanguageSystem)lngObj).Language +
                                       "> - TranslationId <" + ((DBLanguageSystem)lngObj).TranslationId + "> )");
                    }
                    else
                    {
                        lngObj = LanguageMgr.GetLanguageDataObject(args[2].ToUpper(), args[3], LanguageDataObject.eTranslationIdentifier.eSystem);

                        if (lngObj == null)
                        {
                            DisplayMessage(client, "[Language-Manager] Can't find language object. ( Language <" + args[2].ToUpper() +
                                           "> - TranslationId <" + args[3] + "> )");
                        }
                        else
                        {
                            client.Player.TempProperties.setProperty(LANGUAGEMGR_SEL_LNG_OBJ, lngObj);
                            DisplayMessage(client, "[Language-Manager] Language object found and added to your temporary properties! ( Language <" + args[2].ToUpper() +
                                           "> - TranslationId <" + args[3] + "> )");
                        }
                    }
                }

                return;
            }

            case "selectclear":
            {
                // Removes the language object from your temp properties you've previously selected with the "select" sub command.
                LanguageDataObject lngObj = (LanguageDataObject)client.Player.TempProperties.getProperty <object>(LANGUAGEMGR_SEL_LNG_OBJ, null);

                if (lngObj == null)
                {
                    DisplayMessage(client, "[Language-Manager] No language object selected!");
                }
                else
                {
                    client.Player.TempProperties.removeProperty(LANGUAGEMGR_SEL_LNG_OBJ);
                    DisplayMessage(client, "[Language-Manager] Language object successfully removed from your temporary properties." +
                                   "( Language <" + ((DBLanguageSystem)lngObj).Language +
                                   "> - TranslationId <" + ((DBLanguageSystem)lngObj).TranslationId + "> )");
                }

                return;
            }

            case "selectsave":
            {
                if (args.Length < 3)
                {
                    DisplayMessage(client, "[Language-Manager] Usage: '/translate selectsave [Text]'");
                }
                else
                {
                    LanguageDataObject lngObj = (LanguageDataObject)client.Player.TempProperties.getProperty <object>(LANGUAGEMGR_SEL_LNG_OBJ, null);

                    if (lngObj == null)
                    {
                        DisplayMessage(client, "[Language-Manager] No language object selected!");
                    }
                    else
                    {
                        if (args.Length > 3)
                        {
                            ((DBLanguageSystem)lngObj).Text = string.Join(" ", args, 2, args.Length - 2);
                        }
                        else
                        {
                            ((DBLanguageSystem)lngObj).Text = args[2];
                        }

                        GameServer.Database.SaveObject(lngObj);
                        client.Player.TempProperties.removeProperty(LANGUAGEMGR_SEL_LNG_OBJ);
                        DisplayMessage(client, "[Language-Manager] Language object successfully changed and saved in database." +
                                       "( Language <" + ((DBLanguageSystem)lngObj).Language +
                                       "> - TranslationId <" + ((DBLanguageSystem)lngObj).TranslationId +
                                       "> - Text <" + ((DBLanguageSystem)lngObj).Text + "> )");
                    }
                }

                return;
            }

            case "selectshow":
            {
                LanguageDataObject lngObj = (LanguageDataObject)client.Player.TempProperties.getProperty <object>(LANGUAGEMGR_SEL_LNG_OBJ, null);

                if (lngObj == null)
                {
                    DisplayMessage(client, "[Language-Manager] No language object selected!");
                }
                else
                {
                    DisplayMessage(client, "[Language-Manager] Language object info: Language <" + lngObj.Language + "> - TranslationId <" + lngObj.TranslationId +
                                   "> - Text <" + ((DBLanguageSystem)lngObj).Text + ">");
                }

                return;
            }

            case "show":
            {
                if (args.Length < 4)
                {
                    DisplayMessage(client, "[Language-Manager] Usage: '/translate show [Language] [TranslationId]'");
                }
                else
                {
                    LanguageDataObject lngObj = LanguageMgr.GetLanguageDataObject(args[2].ToUpper(), args[3], LanguageDataObject.eTranslationIdentifier.eSystem);

                    if (lngObj == null)
                    {
                        DisplayMessage(client, "[Language-Manager] Can't find language object. ( Language <" + args[2].ToUpper() +
                                       "> - TranslationId <" + args[3] + "> )");
                    }
                    else
                    {
                        DisplayMessage(client, "[Language-Manager] " + ((DBLanguageSystem)lngObj).Text);
                    }
                }

                return;
            }

            /*
             * The code works fine, but DAoC does not support a such huge list.
             *
             * case "showlist":
             *  {
             *      if (args.Length < 3)
             *          DisplayMessage(client, "aaa");
             *      else
             *      {
             #region showall
             *          if (args[2].ToLower() == "showall")
             *          {
             *              IDictionary<string, IList<string>> idLangs = new Dictionary<string, IList<string>>();
             *              List<string> languages = new List<string>();
             *              languages.AddRange(LanguageMgr.Languages);
             *              IList<string> data = new List<string>();
             *
             *              foreach (string language in LanguageMgr.Translations.Keys)
             *              {
             *                  if (!LanguageMgr.Translations[language].ContainsKey(LanguageDataObject.eTranslationIdentifier.eSystem))
             *                      continue;
             *
             *                  data.Add("======== Language <" + language + "> ========\n\n");
             *
             *                  foreach (LanguageDataObject lngObj in LanguageMgr.Translations[language][LanguageDataObject.eTranslationIdentifier.eSystem])
             *                  {
             *                      data.Add("TranslationId: " + lngObj.TranslationId + "\nText: " + ((DBLanguageSystem)lngObj).Text + "\n\n");
             *
             *                      if (!idLangs.ContainsKey(lngObj.TranslationId))
             *                      {
             *                          IList<string> langs = new List<string>();
             *                          langs.Add(lngObj.Language);
             *                          idLangs.Add(lngObj.TranslationId, langs);
             *                          continue;
             *                      }
             *
             *                      if (!idLangs[lngObj.TranslationId].Contains(lngObj.Language))
             *                          idLangs[lngObj.TranslationId].Add(lngObj.Language);
             *
             *                      continue;
             *                  }
             *              }
             *
             *              IDictionary<string, IList<string>> missingLanguageTranslations = new Dictionary<string, IList<string>>();
             *
             *              foreach (string translationId in idLangs.Keys)
             *              {
             *                  foreach (string language in languages)
             *                  {
             *                      if (idLangs[translationId].Contains(language))
             *                          continue;
             *
             *                      if (!missingLanguageTranslations.ContainsKey(translationId))
             *                      {
             *                          IList<string> langs = new List<string>();
             *                          langs.Add(language);
             *                          missingLanguageTranslations.Add(translationId, langs);
             *                          continue;
             *                      }
             *
             *                      if (!missingLanguageTranslations[translationId].Contains(language))
             *                          missingLanguageTranslations[translationId].Add(language);
             *
             *                      continue;
             *                  }
             *              }
             *
             *              if (missingLanguageTranslations.Count > 0)
             *              {
             *                  data.Add("======== Missing language translations ========\n\n");
             *
             *                  foreach (string translationId in missingLanguageTranslations.Keys)
             *                  {
             *                      string str = ("TranslationId: " + translationId + "\nLanguages: ");
             *
             *                      foreach (string language in missingLanguageTranslations[translationId])
             *                          str += (language + ",");
             *
             *                      if (str[(str.Length - 1)] == ',')
             *                          str = str.Remove(str.Length - 1);
             *
             *                      data.Add(str);
             *                  }
             *              }
             *
             *              client.Out.SendCustomTextWindow("[Language-Manager] Translations", data); // I wish you a merry christmas and a happy new year (2112)! :-)
             *          }
             #endregion  showall
             *
             #region language
             *          else
             *          {
             *              if (!LanguageMgr.Languages.Contains(args[2].ToUpper()))
             *                  DisplayMessage(client, "aaa");
             *              else
             *              {
             *                  if (!LanguageMgr.Translations[args[2].ToUpper()].ContainsKey(LanguageDataObject.eTranslationIdentifier.eSystem))
             *                      DisplayMessage(client, "aaa");
             *                  else
             *                  {
             *                      IList<string> data = new List<string>();
             *
             *                      foreach (LanguageDataObject lngObj in LanguageMgr.Translations[args[2].ToUpper()][LanguageDataObject.eTranslationIdentifier.eSystem])
             *                          data.Add("TranslationId: " + lngObj.TranslationId + "\nText: " + ((DBLanguageSystem)lngObj).Text + "\n\n");
             *
             *                      client.Out.SendCustomTextWindow("[Language-Manager] Language translations <" + args[2].ToUpper() + ">", data);
             *                  }
             *              }
             *          }
             #endregion language
             *      }
             *
             *      return;
             *  }*/

            default:
            {
                DisplaySyntax(client);
                return;
            }
            }
        }