BANNED
Join Date: Mar 2014
Location: Morocco
|
09-05-2016
, 18:21
Re: [HELP] Lag caused by sockets(Get Country &City)
|
#8
|
Quote:
Originally Posted by SomewhereLost
Seems nice tho. Fixed one would be great
|
Added ISP. Now City return = 100% true + Country = 100% true ( i changed the host ).
Fixed using sockets_hz, thank's to neygomon and the author of sockets_hz.
Code:
/* Plugin generated by AMXX-EDITOR v1.9*/
#include <amxmodx>
#include <amxmisc>
#include <sockets_hz>
#include <regex>
#define REPEAT_TIME 15
#define hostConnect "ip-api.com"
new const errorReturn[] = "error";
new gSocket, count = 0
new const GeoIP_country_name[][] =
{ "N/A",
"Asia/Pacific Region", "Europe",
"Andorra", "United Arab Emirates",
"Afghanistan", "Antigua and Barbuda",
"Anguilla",
"Albania", "Armenia",
"Curacao",
"Angola",
"Antarctica", "Argentina",
"American Samoa", "Austria",
"Australia", "Aruba",
"Azerbaijan",
"Bosnia and Herzegovina", "Barbados",
"Bangladesh",
"Belgium", "Burkina Faso",
"Bulgaria", "Bahrain",
"Burundi", "Benin",
"Bermuda",
"Brunei Darussalam", "Bolivia",
"Brazil",
"Bahamas", "Bhutan",
"Bouvet Island", "Botswana",
"Belarus", "Belize",
"Canada",
"Cocos (Keeling) Islands",
"Congo, The Democratic Republic of the",
"Central African Republic",
"Congo", "Switzerland",
"Cote D'Ivoire", "Cook Islands",
"Chile", "Cameroon",
"China",
"Colombia", "Costa Rica",
"Cuba",
"Cape Verde", "Christmas Island",
"Cyprus", "Czech Republic",
"Germany", "Djibouti",
"Denmark",
"Dominica", "Dominican Republic",
"Algeria",
"Ecuador", "Estonia",
"Egypt", "Western Sahara",
"Eritrea", "Spain",
"Ethiopia",
"Finland", "Fiji",
"Falkland Islands (Malvinas)",
"Micronesia, Federated States of", "Faroe Islands",
"France", "Sint Maarten (Dutch part)",
"Gabon", "United Kingdom",
"Grenada",
"Georgia", "French Guiana",
"Ghana",
"Gibraltar", "Greenland",
"Gambia", "Guinea",
"Guadeloupe", "Equatorial Guinea",
"Greece",
"South Georgia and the South Sandwich Islands","Guatemala",
"Guam",
"Guinea-Bissau", "Guyana",
"Hong Kong",
"Heard Island and McDonald Islands",
"Honduras", "Croatia",
"Haiti",
"Hungary", "Indonesia",
"Ireland",
"Israel", "India",
"British Indian Ocean Territory", "Iraq",
"Iran, Islamic Republic of", "Iceland",
"Italy",
"Jamaica", "Jordan",
"Japan",
"Kenya", "Kyrgyzstan",
"Cambodia", "Kiribati",
"Comoros", "Saint Kitts and Nevis",
"Korea, Democratic People's Republic of", "Korea, Republic of",
"Kuwait",
"Cayman Islands",
"Kazakhstan",
"Lao People's Democratic Republic",
"Lebanon", "Saint Lucia",
"Liechtenstein", "Sri Lanka",
"Liberia",
"Lesotho", "Lithuania",
"Luxembourg",
"Latvia", "Libya",
"Morocco", "Monaco",
"Moldova, Republic of", "Madagascar",
"Marshall Islands", "Macedonia",
"Mali",
"Myanmar",
"Mongolia", "Macau",
"Northern Mariana Islands", "Martinique",
"Mauritania", "Montserrat",
"Malta",
"Mauritius", "Maldives",
"Malawi",
"Mexico", "Malaysia",
"Mozambique", "Namibia",
"New Caledonia", "Niger",
"Norfolk Island",
"Nigeria", "Nicaragua",
"Netherlands",
"Norway", "Nepal",
"Nauru", "Niue",
"New Zealand", "Oman",
"Panama",
"Peru", "French Polynesia",
"Papua New Guinea",
"Philippines", "Pakistan",
"Poland", "Saint Pierre and Miquelon",
"Pitcairn Islands", "Puerto Rico",
"Palestinian Territory", "Portugal",
"Palau",
"Paraguay",
"Qatar", "Reunion",
"Romania", "Russian Federation",
"Rwanda", "Saudi Arabia",
"Solomon Islands", "Seychelles",
"Sudan",
"Sweden",
"Singapore", "Saint Helena",
"Slovenia", "Svalbard and Jan Mayen",
"Slovakia", "Sierra Leone",
"San Marino",
"Senegal", "Somalia",
"Suriname",
"Sao Tome and Principe",
"El Salvador", "Syrian Arab Republic",
"Swaziland", "Turks and Caicos Islands",
"Chad", "French Southern Territories",
"Togo",
"Thailand",
"Tajikistan",
"Tokelau", "Turkmenistan",
"Tunisia", "Tonga",
"Timor-Leste", "Turkey",
"Trinidad and Tobago", "Tuvalu",
"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",
"Venezuela",
"Virgin Islands, British",
"Virgin Islands, U.S.", "Vietnam",
"Vanuatu", "Wallis and Futuna",
"Samoa", "Yemen",
"Mayotte",
"Serbia", "South Africa",
"Zambia",
"Montenegro", "Zimbabwe",
"Anonymous Proxy", "Satellite Provider",
"Other", "Aland Islands",
"Guernsey",
"Isle of Man", "Jersey",
"Saint Barthelemy",
"Saint Martin",
"Bonaire, Saint Eustatius and Saba",
"South Sudan", "Other"
};
// new bool:check = false;
public plugin_init(){
register_plugin(
.plugin_name = "Connect Plugin based on Web API",
.version = "1.0",
.author = "Spawner/Freezo")
// register_clcmd("enable", "enable")
// register_clcmd("disable", "disable")
}
// public enable(id) check = true
// public disable(id) check = false
public client_putinserver(id)
{
if(!is_user_bot(id) /*check*/ ){
loadSocket(id)
}
}
public loadSocket(id){
new errorReturned;
gSocket = socket_open(hostConnect, 80, SOCKET_TCP, errorReturned)
if(errorReturned == 0){
new sBuffer[128], IP[24]
get_user_ip(
id,
IP,
charsmax(IP),
.without_port= 1
)
format(sBuffer, 127, "GET /json/%s HTTP/1.1^nHost:%s^r^n^r^n", IP, hostConnect)
if(socket_send2(gSocket, sBuffer, 127)){
socket_unblock(gSocket);
set_task(1.0 , "answerSocket", id, _, _, "a", REPEAT_TIME)
}
}
return PLUGIN_HANDLED
}
public answerSocket(id){
if(count != REPEAT_TIME){
if(socket_change(gSocket)){
new socketData[1024]
socket_recv(gSocket, socketData, charsmax(socketData))
new szName[32]
get_user_name(id, szName, charsmax(szName))
new szSteam[32]
get_user_authid(id, szSteam, charsmax(szSteam))
new num, error[128]
new pattern[2][] = {"city.+(?=^"country^")", "^"isp^".+(?=^"lat)" }
new Regex:regexref = regex_match(socketData,pattern[0],num,error,127)
new Regex:regexref2 = regex_match(socketData,pattern[1],num,error,127)
new matchStringCity[64]
new matchStringISP[64]
if(regexref >= REGEX_OK || regexref2 >= REGEX_OK)
{
for(new i=0; i<num; i++)
{
regex_substr(regexref, i, matchStringCity, charsmax(matchStringCity))
regex_substr(regexref2, i, matchStringISP, charsmax(matchStringISP))
new const replaceC[][] = { "^"" , "city", ",", ":", "isp" }
for(new i = 0; i < sizeof(replaceC); i++){
replace_all(matchStringCity, charsmax(matchStringCity), replaceC[i], "")
replace_all(matchStringISP, charsmax(matchStringISP), replaceC[i], "")
}
}
if(equal(matchStringCity,"")) matchStringCity = errorReturn;
if(equal(matchStringISP,"")) matchStringISP = errorReturn;
if(containi(matchStringISP,"Office") != -1) matchStringISP = "Maroc Telecom";
regex_free(regexref)
regex_free(regexref2)
}
for(new i = 0; i< sizeof ( GeoIP_country_name ); i++){
if(containi(socketData, GeoIP_country_name[i]) != -1 ){
ChatColor(0, "!g[NG] !y%s :!g%s !t|| !yCountry :!g%s !t|| !yCity :!g%s !t|| !yISP :!g[%s]",is_user_admin(get_user_index(szName)) ? "Admin" : "User" ,szName, GeoIP_country_name[i], matchStringCity,matchStringISP )
break;
}
}
socket_close(gSocket)
remove_task(id)
}
}
else{
socket_close(gSocket)
remove_task(id)
}
count++
return PLUGIN_HANDLED
}
stock ChatColor(const id, const input[], any:...)
{
new count2 = 1, players[32]
static msg[300]
vformat(msg, charsmax(msg), input, 3)
replace_all(msg, 190, "!g", "^4") // Green Color
replace_all(msg, 190, "!y", "^1") // Default Color
replace_all(msg, 190, "!t", "^3") // Team Color
replace_all(msg, 190, "!t2", "^0") // Team2 Color
if (id) players[0] = id; else get_players(players, count2, "ch")
{
for (new i = 0; i < count2; i++)
{
if (is_user_connected(players[i]))
{
message_begin(MSG_ONE_UNRELIABLE, get_user_msgid("SayText"), _, players[i])
write_byte(players[i]);
write_string(msg);
message_end();
}
}
}
}
EDIT: Lag is fixed a little bit, the problem is if 2 players try to connect at the same time, i will try to fix it, then you can try it with no worries.
Last edited by Freezo Begin; 09-05-2016 at 18:38.
|
|