diff --git a/src/server/game_util/GoUtil.go b/src/server/game_util/GoUtil.go index 89734659..845a4008 100644 --- a/src/server/game_util/GoUtil.go +++ b/src/server/game_util/GoUtil.go @@ -54,6 +54,295 @@ const ( LETTER = "GhCvgqSNTUMVeRfwakiYmcxWKtJQpZrDIBXnPyLsAFdzjHbulE" ) +var iso3166NumericByCountryName = map[string]string{ + "Afghanistan": "004", + "Aland Islands": "248", + "Åland Islands": "248", + "Albania": "008", + "Algeria": "012", + "American Samoa": "016", + "Andorra": "020", + "Angola": "024", + "Anguilla": "660", + "Antarctica": "010", + "Antigua and Barbuda": "028", + "Argentina": "032", + "Armenia": "051", + "Aruba": "533", + "Australia": "036", + "Austria": "040", + "Azerbaijan": "031", + "Bahamas": "044", + "Bahrain": "048", + "Bangladesh": "050", + "Barbados": "052", + "Belarus": "112", + "Belgium": "056", + "Belize": "084", + "Benin": "204", + "Bermuda": "060", + "Bhutan": "064", + "Bolivia": "068", + "Bolivia, Plurinational State of": "068", + "Bonaire, Sint Eustatius and Saba": "535", + "Bosnia and Herzegovina": "070", + "Botswana": "072", + "Bouvet Island": "074", + "Brazil": "076", + "British Indian Ocean Territory": "086", + "Brunei": "096", + "Brunei Darussalam": "096", + "Bulgaria": "100", + "Burkina Faso": "854", + "Burundi": "108", + "Cabo Verde": "132", + "Cape Verde": "132", + "Cambodia": "116", + "Cameroon": "120", + "Canada": "124", + "Cayman Islands": "136", + "Central African Republic": "140", + "Chad": "148", + "Chile": "152", + "China": "156", + "Christmas Island": "162", + "Cocos (Keeling) Islands": "166", + "Colombia": "170", + "Comoros": "174", + "Congo": "178", + "Congo, The Democratic Republic of the": "180", + "Congo, Democratic Republic of the": "180", + "Cook Islands": "184", + "Costa Rica": "188", + "Cote d'Ivoire": "384", + "Côte d'Ivoire": "384", + "Croatia": "191", + "Cuba": "192", + "Curacao": "531", + "Curaçao": "531", + "Cyprus": "196", + "Czech Republic": "203", + "Czechia": "203", + "Denmark": "208", + "Djibouti": "262", + "Dominica": "212", + "Dominican Republic": "214", + "Ecuador": "218", + "Egypt": "818", + "El Salvador": "222", + "Equatorial Guinea": "226", + "Eritrea": "232", + "Estonia": "233", + "Eswatini": "748", + "Swaziland": "748", + "Ethiopia": "231", + "Falkland Islands": "238", + "Faroe Islands": "234", + "Fiji": "242", + "Finland": "246", + "France": "250", + "French Guiana": "254", + "French Polynesia": "258", + "French Southern Territories": "260", + "Gabon": "266", + "Gambia": "270", + "Georgia": "268", + "Germany": "276", + "Ghana": "288", + "Gibraltar": "292", + "Greece": "300", + "Greenland": "304", + "Grenada": "308", + "Guadeloupe": "312", + "Guam": "316", + "Guatemala": "320", + "Guernsey": "831", + "Guinea": "324", + "Guinea-Bissau": "624", + "Guyana": "328", + "Haiti": "332", + "Heard Island and McDonald Islands": "334", + "Holy See": "336", + "Vatican City": "336", + "Honduras": "340", + "Hong Kong": "344", + "Hungary": "348", + "Iceland": "352", + "India": "356", + "Indonesia": "360", + "Iran": "364", + "Iran, Islamic Republic of": "364", + "Iraq": "368", + "Ireland": "372", + "Isle of Man": "833", + "Israel": "376", + "Italy": "380", + "Jamaica": "388", + "Japan": "392", + "Jersey": "832", + "Jordan": "400", + "Kazakhstan": "398", + "Kenya": "404", + "Kiribati": "296", + "Korea, Democratic People's Republic of": "408", + "North Korea": "408", + "Korea, Republic of": "410", + "South Korea": "410", + "Kosovo": "983", + "Kuwait": "414", + "Kyrgyzstan": "417", + "Lao People's Democratic Republic": "418", + "Laos": "418", + "Latvia": "428", + "Lebanon": "422", + "Lesotho": "426", + "Liberia": "430", + "Libya": "434", + "Liechtenstein": "438", + "Lithuania": "440", + "Luxembourg": "442", + "Macao": "446", + "Macau": "446", + "Madagascar": "450", + "Malawi": "454", + "Malaysia": "458", + "Maldives": "462", + "Mali": "466", + "Malta": "470", + "Marshall Islands": "584", + "Martinique": "474", + "Mauritania": "478", + "Mauritius": "480", + "Mayotte": "175", + "Mexico": "484", + "Micronesia": "583", + "Micronesia, Federated States of": "583", + "Moldova": "498", + "Moldova, Republic of": "498", + "Monaco": "492", + "Mongolia": "496", + "Montenegro": "499", + "Montserrat": "500", + "Morocco": "504", + "Mozambique": "508", + "Myanmar": "104", + "Burma": "104", + "Namibia": "516", + "Nauru": "520", + "Nepal": "524", + "Netherlands": "528", + "New Caledonia": "540", + "New Zealand": "554", + "Nicaragua": "558", + "Niger": "562", + "Nigeria": "566", + "Niue": "570", + "Norfolk Island": "574", + "North Macedonia": "807", + "Macedonia": "807", + "Macedonia, The Former Yugoslav Republic of": "807", + "Northern Mariana Islands": "580", + "Norway": "578", + "Oman": "512", + "Pakistan": "586", + "Palau": "585", + "Palestine": "275", + "Palestine, State of": "275", + "Panama": "591", + "Papua New Guinea": "598", + "Paraguay": "600", + "Peru": "604", + "Philippines": "608", + "Pitcairn": "612", + "Poland": "616", + "Portugal": "620", + "Puerto Rico": "630", + "Qatar": "634", + "Reunion": "638", + "Réunion": "638", + "Romania": "642", + "Russia": "643", + "Russian Federation": "643", + "Rwanda": "646", + "Saint Barthelemy": "652", + "Saint Barthélemy": "652", + "Saint Helena": "654", + "Saint Helena, Ascension and Tristan da Cunha": "654", + "Saint Kitts and Nevis": "659", + "Saint Lucia": "662", + "Saint Martin": "663", + "Saint Martin (French part)": "663", + "Saint Pierre and Miquelon": "666", + "Saint Vincent and the Grenadines": "670", + "Samoa": "882", + "San Marino": "674", + "Sao Tome and Principe": "678", + "Saudi Arabia": "682", + "Senegal": "686", + "Serbia": "688", + "Seychelles": "690", + "Sierra Leone": "694", + "Singapore": "702", + "Sint Maarten": "534", + "Sint Maarten (Dutch part)": "534", + "Slovakia": "703", + "Slovenia": "705", + "Solomon Islands": "090", + "Somalia": "706", + "South Africa": "710", + "South Georgia and the South Sandwich Islands": "239", + "South Sudan": "728", + "Spain": "724", + "Sri Lanka": "144", + "Sudan": "729", + "Suriname": "740", + "Svalbard and Jan Mayen": "744", + "Sweden": "752", + "Switzerland": "756", + "Syrian Arab Republic": "760", + "Syria": "760", + "Taiwan": "158", + "Taiwan, Province of China": "158", + "Tajikistan": "762", + "Tanzania": "834", + "Tanzania, United Republic of": "834", + "Thailand": "764", + "Timor-Leste": "626", + "East Timor": "626", + "Togo": "768", + "Tokelau": "772", + "Tonga": "776", + "Trinidad and Tobago": "780", + "Tunisia": "788", + "Turkey": "792", + "Türkiye": "792", + "Turkmenistan": "795", + "Turks and Caicos Islands": "796", + "Tuvalu": "798", + "Uganda": "800", + "Ukraine": "804", + "United Arab Emirates": "784", + "United Kingdom": "826", + "United States": "840", + "United States Minor Outlying Islands": "581", + "Uruguay": "858", + "Uzbekistan": "860", + "Vanuatu": "548", + "Venezuela": "862", + "Venezuela, Bolivarian Republic of": "862", + "Viet Nam": "704", + "Vietnam": "704", + "Virgin Islands, British": "092", + "British Virgin Islands": "092", + "Virgin Islands, U.S.": "850", + "U.S. Virgin Islands": "850", + "Wallis and Futuna": "876", + "Western Sahara": "732", + "Yemen": "887", + "Zambia": "894", + "Zimbabwe": "716", +} + // 加密字符串 func Encrypt(plainText string) (string, error) { block, err := aes.NewCipher([]byte(SECRET_KEY)) @@ -529,79 +818,17 @@ func GetCountryByIP(ip string) (string, error) { // 根据国家名称获取ISO 3166-1国家码 func GetISOCodeByCountry(country string) (string, error) { - // 简单映射,可以扩展为更完整的映射表 - countryMap := map[string]string{ - "Afghanistan": "004", // 阿富汗 - "Albania": "008", // 阿尔巴尼亚 - "Algeria": "012", // 阿尔及利亚 - "Angola": "024", // 安哥拉 - "Argentina": "032", // 阿根廷 - "Austria": "040", // 奥地利 - "Azerbaijan": "031", // 阿塞拜疆 - "Bahrain": "048", // 巴林 - "Bangladesh": "050", // 孟加拉国 - "Belgium": "056", // 比利时 - "Bolivia": "068", // 玻利维亚 - "Bosnia and Herzegovina": "070", // 波斯尼亚和黑塞哥维那 - "Brazil": "076", // 巴西 - "Bulgaria": "100", // 保加利亚 - "Canada": "124", // 加拿大 - "Chile": "152", // 智利 - "China": "156", // 中国 - "Colombia": "170", // 哥伦比亚 - "Costa Rica": "188", // 哥斯达黎加 - "Croatia": "191", // 克罗地亚 - "Cuba": "192", // 古巴 - "Denmark": "208", // 丹麦 - "Ecuador": "218", // 厄瓜多尔 - "Egypt": "818", // 埃及 - "Ethiopia": "231", // 埃塞俄比亚 - "Finland": "246", // 芬兰 - "France": "250", // 法国 - "Germany": "276", // 德国 - "Ghana": "288", // 加纳 - "Greece": "300", // 希腊 - "Hungary": "348", // 匈牙利 - "India": "356", // 印度 - "Indonesia": "360", // 印度尼西亚 - "Iran": "364", // 伊朗 - "Iraq": "368", // 伊拉克 - "Italy": "380", // 意大利 - "Japan": "392", // 日本 - "Jordan": "400", // 约旦 - "Kenya": "404", // 肯尼亚 - "Kuwait": "414", // 科威特 - "Lebanon": "422", // 黎巴嫩 - "Malaysia": "458", // 马来西亚 - "Mexico": "484", // 墨西哥 - "Morocco": "504", // 摩洛哥 - "Nigeria": "566", // 尼日利亚 - "Norway": "578", // 挪威 - "Pakistan": "586", // 巴基斯坦 - "Peru": "604", // 秘鲁 - "Philippines": "608", // 菲律宾 - "Poland": "616", // 波兰 - "Portugal": "620", // 葡萄牙 - "Qatar": "634", // 卡塔尔 - "Romania": "642", // 罗马尼亚 - "Russia": "643", // 俄罗斯 - "Saudi Arabia": "682", // 沙特阿拉伯 - "South Africa": "710", // 南非 - "South Korea": "410", // 韩国 - "Spain": "724", // 西班牙 - "Sweden": "752", // 瑞典 - "Switzerland": "756", // 瑞士 - "Thailand": "764", // 泰国 - "Turkey": "792", // 土耳其 - "Ukraine": "804", // 乌克兰 - "United Kingdom": "826", // 英国 - "United States": "840", // 美国 - "Vietnam": "704", // 越南 - "Zimbabwe": "716", // 津巴布韦 - } - if code, ok := countryMap[country]; ok { + country = strings.TrimSpace(country) + if code, ok := iso3166NumericByCountryName[country]; ok { return code, nil } + + for name, code := range iso3166NumericByCountryName { + if strings.EqualFold(name, country) { + return code, nil + } + } + return "", fmt.Errorf("country code not found for %s", country) }