تطوير سيرفرات كونكر تهيس

الان ومجاناً كود السيستم الخاص بـ Country Ban من دخول سيرفرك كونكر تهيس


اهلا بيكم من جديد
معانا سيستم جديد وهو عمل حذر للبلاد اللى مش عايزها تدخل لعبة بتاعتك
صورة توضيحية

تقدر تاخد الكود كوبى من هنا

  1. /**
  2. step 1
  3. open Game Server then add this lines in Program.cs
  4. **/
  5. public static CountryLookup Lookup = new CountryLookup(“http://github.com/SalemEGY/CountryIPLookUp/raw/main/LookUp_BySalem.dat”); //dont change this link or you will get errors
  6. public static List<string> BlockedCountry = new List<string>() { “Egypt”, “United States” }; // add countryName as string to block
  7. ———————
  8. /**
  9. step 2 add new class file CountryLookup.cs
  10. and copy this class to your new class CountryLookup
  11. **/
  12. using System;
  13. using System.IO;
  14. using System.Net;
  15. using System.Net.Http;
  16. namespace CoServer //change the name space whith your project namespace <———–
  17. {
  18.     public class CountryLookup
  19.     {
  20.         private byte[] ipData;
  21.         private static long COUNTRY_BEGIN = 16776960L;
  22.         private static string[] countryCode = new string[253]
  23.         {
  24.         “–“, “AP”, “EU”, “AD”, “AE”, “AF”, “AG”, “AI”, “AL”, “AM”,
  25.         “AN”, “AO”, “AQ”, “AR”, “AS”, “AT”, “AU”, “AW”, “AZ”, “BA”,
  26.         “BB”, “BD”, “BE”, “BF”, “BG”, “BH”, “BI”, “BJ”, “BM”, “BN”,
  27.         “BO”, “BR”, “BS”, “BT”, “BV”, “BW”, “BY”, “BZ”, “CA”, “CC”,
  28.         “CD”, “CF”, “CG”, “CH”, “CI”, “CK”, “CL”, “CM”, “CN”, “CO”,
  29.         “CR”, “CU”, “CV”, “CX”, “CY”, “CZ”, “DE”, “DJ”, “DK”, “DM”,
  30.         “DO”, “DZ”, “EC”, “EE”, “EG”, “EH”, “ER”, “ES”, “ET”, “FI”,
  31.         “FJ”, “FK”, “FM”, “FO”, “FR”, “FX”, “GA”, “GB”, “GD”, “GE”,
  32.         “GF”, “GH”, “GI”, “GL”, “GM”, “GN”, “GP”, “GQ”, “GR”, “GS”,
  33.         “GT”, “GU”, “GW”, “GY”, “HK”, “HM”, “HN”, “HR”, “HT”, “HU”,
  34.         “ID”, “IE”, “IL”, “IN”, “IO”, “IQ”, “IR”, “IS”, “IT”, “JM”,
  35.         “JO”, “JP”, “KE”, “KG”, “KH”, “KI”, “KM”, “KN”, “KP”, “KR”,
  36.         “KW”, “KY”, “KZ”, “LA”, “LB”, “LC”, “LI”, “LK”, “LR”, “LS”,
  37.         “LT”, “LU”, “LV”, “LY”, “MA”, “MC”, “MD”, “MG”, “MH”, “MK”,
  38.         “ML”, “MM”, “MN”, “MO”, “MP”, “MQ”, “MR”, “MS”, “MT”, “MU”,
  39.         “MV”, “MW”, “MX”, “MY”, “MZ”, “NA”, “NC”, “NE”, “NF”, “NG”,
  40.         “NI”, “NL”, “NO”, “NP”, “NR”, “NU”, “NZ”, “OM”, “PA”, “PE”,
  41.         “PF”, “PG”, “PH”, “PK”, “PL”, “PM”, “PN”, “PR”, “PS”, “PT”,
  42.         “PW”, “PY”, “QA”, “RE”, “RO”, “RU”, “RW”, “SA”, “SB”, “SC”,
  43.         “SD”, “SE”, “SG”, “SH”, “SI”, “SJ”, “SK”, “SL”, “SM”, “SN”,
  44.         “SO”, “SR”, “ST”, “SV”, “SY”, “SZ”, “TC”, “TD”, “TF”, “TG”,
  45.         “TH”, “TJ”, “TK”, “TM”, “TN”, “TO”, “TL”, “TR”, “TT”, “TV”,
  46.         “TW”, “TZ”, “UA”, “UG”, “UM”, “US”, “UY”, “UZ”, “VA”, “VC”,
  47.         “VE”, “VG”, “VI”, “VN”, “VU”, “WF”, “WS”, “YE”, “YT”, “RS”,
  48.         “ZA”, “ZM”, “ME”, “ZW”, “A1”, “A2”, “O1”, “AX”, “GG”, “IM”,
  49.         “JE”, “BL”, “MF”
  50.         };
  51.         private static string[] countryName = new string[253]
  52.         {
  53.         “N/A”, “Asia/Pacific Region”, “Europe”, “Andorra”, “United Arab Emirates”, “Afghanistan”, “Antigua and Barbuda”, “Anguilla”, “Albania”, “Armenia”,
  54.         “Netherlands Antilles”, “Angola”, “Antarctica”, “Argentina”, “American Samoa”, “Austria”, “Australia”, “Aruba”, “Azerbaijan”, “Bosnia and Herzegovina”,
  55.         “Barbados”, “Bangladesh”, “Belgium”, “Burkina Faso”, “Bulgaria”, “Bahrain”, “Burundi”, “Benin”, “Bermuda”, “Brunei Darussalam”,
  56.         “Bolivia”, “Brazil”, “Bahamas”, “Bhutan”, “Bouvet Island”, “Botswana”, “Belarus”, “Belize”, “Canada”, “Cocos (Keeling) Islands”,
  57.         “Congo, The Democratic Republic of the”, “Central African Republic”, “Congo”, “Switzerland”, “Cote D’Ivoire”, “Cook Islands”, “Chile”, “Cameroon”, “China”, “Colombia”,
  58.         “Costa Rica”, “Cuba”, “Cape Verde”, “Christmas Island”, “Cyprus”, “Czech Republic”, “Germany”, “Djibouti”, “Denmark”, “Dominica”,
  59.         “Dominican Republic”, “Algeria”, “Ecuador”, “Estonia”, “Egypt”, “Western Sahara”, “Eritrea”, “Spain”, “Ethiopia”, “Finland”,
  60.         “Fiji”, “Falkland Islands (Malvinas)”, “Micronesia, Federated States of”, “Faroe Islands”, “France”, “France, Metropolitan”, “Gabon”, “United Kingdom”, “Grenada”, “Georgia”,
  61.         “French Guiana”, “Ghana”, “Gibraltar”, “Greenland”, “Gambia”, “Guinea”, “Guadeloupe”, “Equatorial Guinea”, “Greece”, “South Georgia and the South Sandwich Islands”,
  62.         “Guatemala”, “Guam”, “Guinea-Bissau”, “Guyana”, “Hong Kong”, “Heard Island and McDonald Islands”, “Honduras”, “Croatia”, “Haiti”, “Hungary”,
  63.         “Indonesia”, “Ireland”, “Israel”, “India”, “British Indian Ocean Territory”, “Iraq”, “Iran, Islamic Republic of”, “Iceland”, “Italy”, “Jamaica”,
  64.         “Jordan”, “Japan”, “Kenya”, “Kyrgyzstan”, “Cambodia”, “Kiribati”, “Comoros”, “Saint Kitts and Nevis”, “Korea, Democratic People’s Republic of”, “Korea, Republic of”,
  65.         “Kuwait”, “Cayman Islands”, “Kazakstan”, “Lao People’s Democratic Republic”, “Lebanon”, “Saint Lucia”, “Liechtenstein”, “Sri Lanka”, “Liberia”, “Lesotho”,
  66.         “Lithuania”, “Luxembourg”, “Latvia”, “Libyan Arab Jamahiriya”, “Morocco”, “Monaco”, “Moldova, Republic of”, “Madagascar”, “Marshall Islands”, “Macedonia”,
  67.         “Mali”, “Myanmar”, “Mongolia”, “Macau”, “Northern Mariana Islands”, “Martinique”, “Mauritania”, “Montserrat”, “Malta”, “Mauritius”,
  68.         “Maldives”, “Malawi”, “Mexico”, “Malaysia”, “Mozambique”, “Namibia”, “New Caledonia”, “Niger”, “Norfolk Island”, “Nigeria”,
  69.         “Nicaragua”, “Netherlands”, “Norway”, “Nepal”, “Nauru”, “Niue”, “New Zealand”, “Oman”, “Panama”, “Peru”,
  70.         “French Polynesia”, “Papua New Guinea”, “Philippines”, “Pakistan”, “Poland”, “Saint Pierre and Miquelon”, “Pitcairn Islands”, “Puerto Rico”, “Palestinian Territory”, “Portugal”,
  71.         “Palau”, “Paraguay”, “Qatar”, “Reunion”, “Romania”, “Russian Federation”, “Rwanda”, “Saudi Arabia”, “Solomon Islands”, “Seychelles”,
  72.         “Sudan”, “Sweden”, “Singapore”, “Saint Helena”, “Slovenia”, “Svalbard and Jan Mayen”, “Slovakia”, “Sierra Leone”, “San Marino”, “Senegal”,
  73.         “Somalia”, “Suriname”, “Sao Tome and Principe”, “El Salvador”, “Syrian Arab Republic”, “Swaziland”, “Turks and Caicos Islands”, “Chad”, “French Southern Territories”, “Togo”,
  74.         “Thailand”, “Tajikistan”, “Tokelau”, “Turkmenistan”, “Tunisia”, “Tonga”, “Timor-Leste”, “Turkey”, “Trinidad and Tobago”, “Tuvalu”,
  75.         “Taiwan”, “Tanzania, United Republic of”, “Ukraine”, “Uganda”, “United States Minor Outlying Islands”, “United States”, “Uruguay”, “Uzbekistan”, “Holy See (Vatican City State)”, “Saint Vincent and the Grenadines”,
  76.         “Venezuela”, “Virgin Islands, British”, “Virgin Islands, U.S.”, “Vietnam”, “Vanuatu”, “Wallis and Futuna”, “Samoa”, “Yemen”, “Mayotte”, “Serbia”,
  77.         “South Africa”, “Zambia”, “Montenegro”, “Zimbabwe”, “Anonymous Proxy”, “Satellite Provider”, “Other”, “Aland Islands”, “Guernsey”, “Isle of Man”,
  78.         “Jersey”, “Saint Barthelemy”, “Saint Martin”
  79.         };
  80.         public static bool CountryBan(string Ip, out string Messaj)
  81.         {
  82.             string country = Program.Lookup.lookupCountryName(Ip);
  83.             if (Program.BlockedCountry.Contains(country))
  84.             {
  85.                 using (var rec = new ServerSockets.RecycledPacket())
  86.                 {
  87.                     var stream = rec.GetStream();
  88.                     Messaj = “[“ + country + “]”;
  89.                 }
  90.                 return true;
  91.             }
  92.             else
  93.             {
  94.                 Messaj = null;
  95.                 return false;
  96.             }
  97.         }
  98.         public CountryLookup(string url)
  99.         {
  100.             try
  101.             {
  102.                 using (var client = new HttpClient())
  103.                 {
  104.                     ipData = client.GetByteArrayAsync(url).Result;
  105.                 }
  106.             }
  107.             catch (Exception ex)
  108.             {
  109.                 Console.WriteLine($“Failed to download IP data: {ex.Message}”);
  110.                 throw;
  111.             }
  112.         }
  113.         public string lookupCountryCode(string str)
  114.         {
  115.             IPAddress addr;
  116.             try
  117.             {
  118.                 addr = IPAddress.Parse(str);
  119.             }
  120.             catch (FormatException)
  121.             {
  122.                 return “–“;
  123.             }
  124.             return lookupCountryCode(addr);
  125.         }
  126.         private long addrToNum(IPAddress addr)
  127.         {
  128.             long num = 0L;
  129.             byte[] addressBytes = addr.GetAddressBytes();
  130.             for (int i = 0; i < 4; i++)
  131.             {
  132.                 long num2 = addressBytes[i];
  133.                 if (num2 < 0)
  134.                 {
  135.                     num2 += 256;
  136.                 }
  137.                 num += num2 << (3 i) * 8;
  138.             }
  139.             return num;
  140.         }
  141.         public string lookupCountryCode(IPAddress addr)
  142.         {
  143.             return countryCode[(int)seekCountry(0L, addrToNum(addr), 31)];
  144.         }
  145.         public string lookupCountryName(string str)
  146.         {
  147.             IPAddress addr;
  148.             try
  149.             {
  150.                 addr = IPAddress.Parse(str);
  151.             }
  152.             catch (FormatException)
  153.             {
  154.                 return “N/A”;
  155.             }
  156.             return lookupCountryName(addr);
  157.         }
  158.         public string lookupCountryName(IPAddress addr)
  159.         {
  160.             return countryName[(int)seekCountry(0L, addrToNum(addr), 31)];
  161.         }
  162.         private long seekCountry(long offset, long ipnum, int depth)
  163.         {
  164.             byte[] array = new byte[6];
  165.             long[] array2 = new long[2];
  166.             if (depth < 0)
  167.             {
  168.                 // Console.WriteLine(“Error seeking country: Invalid depth.”);
  169.                 return 0L;
  170.             }
  171.             try
  172.             {
  173.                 // Calculate the position to copy from ipData
  174.                 long position = 6 * offset;
  175.                 // Check if position is within bounds of ipData
  176.                 if (position >= ipData.Length)
  177.                 {
  178.                     // Console.WriteLine($”Error seeking country: Offset {offset} out of bounds or ipData length {ipData.Length} insufficient.”);
  179.                     return 0L;
  180.                 }
  181.                 // Copy 6 bytes from ipData into array
  182.                 Array.Copy(ipData, position, array, 0, 6);
  183.             }
  184.             catch (Exception ex)
  185.             {
  186.                 Console.WriteLine($“Error seeking country: {ex.Message}”);
  187.                 return 0L;
  188.             }
  189.             // Process array to populate array2
  190.             for (int i = 0; i < 2; i++)
  191.             {
  192.                 array2[i] = 0L;
  193.                 for (int j = 0; j < 3; j++)
  194.                 {
  195.                     int num = array[i * 3 + j];
  196.                     if (num < 0)
  197.                     {
  198.                         num += 256;
  199.                     }
  200.                     array2[i] += num << j * 8;
  201.                 }
  202.             }
  203.             // Perform the seek based on ipnum and depth
  204.             if ((ipnum & (1 << depth)) > 0)
  205.             {
  206.                 if (array2[1] >= COUNTRY_BEGIN)
  207.                 {
  208.                     return array2[1] COUNTRY_BEGIN;
  209.                 }
  210.                 return seekCountry(array2[1], ipnum, depth 1);
  211.             }
  212.             if (array2[0] >= COUNTRY_BEGIN)
  213.             {
  214.                 return array2[0] COUNTRY_BEGIN;
  215.             }
  216.             return seekCountry(array2[0], ipnum, depth 1);
  217.         }
  218.     }
  219. }
  220. ——————————————-
  221.  /**
  222.  
  223.  step 3 Goto MsgLoginClient.cs
  224.  search for : public unsafe static void LoginHandler in this void we gonna add our check for country
  225.  after this : string BanMessaje;
  226.  **/
  227. if ( CountryLookup.CountryBan(client.Socket.RemoteIp, out BanMessaje))
  228. {
  229.     using (var rec = new ServerSockets.RecycledPacket())
  230.     {
  231.         var stream = rec.GetStream();
  232.         string Messaj = “You Country: “ + BanMessaje + ” Has ben banned !”;
  233.         client.Send(new MsgServer.MsgMessage(Messaj, “ALLUSERS”, MsgMessage.MsgColor.red, MsgMessage.ChatMode.Dialog).GetArray(stream));
  234.     }
  235.     return;
  236. }
  237. ————————————–
  238. now we have finished and you have Country Ban System

كود من خلال رابط اضغط هنا

كيفية التحميل

قم بالضغط على الصورة أسفل السهوم وسيتم التحميل تلقائياً

↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓

زر الذهاب إلى الأعلى

انت تستخدم اضافة Adblock

أهلا بك عزيزي الزائر، يرجى التكرم بإلغاء إضافة مانع الإعلانات، لتتمكن من تصفح وتحميل ما تريد كاملا، ومواصلة دعم الموقع