Advertisement
Guest User

Untitled

a guest
Mar 16th, 2019
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.55 KB | None | 0 0
  1. /**
  2. *
  3. * This program is free software; you can redistribute it and/or modify it under
  4. * the terms of the GNU General Public License, version 3.0, as published by the
  5. * Free Software Foundation.
  6. *
  7. * This program is distributed in the hope that it will be useful, but WITHOUT
  8. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  9. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  10. * details.
  11. *
  12. * You should have received a copy of the GNU General Public License along with
  13. * this program. If not, see <http://www.gnu.org/licenses/>.
  14. *
  15. * As a special exception, AlliedModders LLC gives you permission to link the
  16. * code of this program (as well as its derivative works) to "Half-Life 2," the
  17. * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
  18. * by the Valve Corporation. You must obey the GNU General Public License in
  19. * all respects for all other code used. Additionally, AlliedModders LLC grants
  20. * this exception to all derivative works. AlliedModders LLC defines further
  21. * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
  22. * or <http://www.sourcemod.net/license.php>.
  23. *
  24. */
  25.  
  26.  
  27. #pragma semicolon 1
  28.  
  29. #include <sourcemod>
  30. #include <sdktools>
  31. #include <geoip>
  32. #undef REQUIRE_EXTENSIONS
  33. #include <geoipcity>
  34. #undef REQUIRE_PLUGIN
  35. #include <adminmenu>
  36. #include <multicolors>
  37.  
  38. #define VERSION "1.8"
  39.  
  40. /*****************************************************************
  41.  
  42.  
  43. G L O B A L V A R S
  44.  
  45.  
  46. *****************************************************************/
  47.  
  48. new Handle:hTopMenu = INVALID_HANDLE;
  49. new String:g_fileset[128];
  50. new String:g_filesettings[128];
  51. new bool:g_UseGeoIPCity = false;
  52. new Handle:g_CvarConnectDisplayType = INVALID_HANDLE;
  53.  
  54. /*****************************************************************
  55.  
  56.  
  57. L I B R A R Y I N C L U D E S
  58.  
  59.  
  60. *****************************************************************/
  61.  
  62. #include "cannounce/countryshow.sp"
  63. #include "cannounce/joinmsg.sp"
  64. #include "cannounce/geolist.sp"
  65. #include "cannounce/suppress.sp"
  66.  
  67. /*****************************************************************
  68.  
  69.  
  70. P L U G I N I N F O
  71.  
  72.  
  73. *****************************************************************/
  74.  
  75. public Plugin:myinfo =
  76. {
  77. name = "Connect Announce",
  78. author = "Arg!",
  79. description = "Replacement of default player connection message, allows for custom connection messages",
  80. version = VERSION,
  81. url = "http://forums.alliedmods.net/showthread.php?t=77306"
  82. };
  83.  
  84.  
  85.  
  86. /*****************************************************************
  87.  
  88.  
  89. F O R W A R D P U B L I C S
  90.  
  91.  
  92. *****************************************************************/
  93. public OnPluginStart()
  94. {
  95. LoadTranslations("common.phrases");
  96. LoadTranslations("cannounce.phrases");
  97.  
  98. CreateConVar("sm_cannounce_version", VERSION, "Connect announce replacement", FCVAR_REPLICATED|FCVAR_NOTIFY|FCVAR_DONTRECORD);
  99.  
  100. g_CvarConnectDisplayType = CreateConVar("sm_ca_connectdisplaytype", "1", "[1|0] if 1 then displays connect message after admin check and allows the {PLAYERTYPE} placeholder. If 0 displays connect message on client auth (earlier) and disables the {PLAYERTYPE} placeholder");
  101.  
  102. BuildPath(Path_SM, g_fileset, 128, "data/cannounce_messages.txt");
  103. BuildPath(Path_SM, g_filesettings, 128, "data/cannounce_settings.txt");
  104.  
  105. //event hooks
  106. HookEvent("player_disconnect", event_PlayerDisconnect, EventHookMode_Pre);
  107.  
  108.  
  109. //country show
  110. SetupCountryShow();
  111.  
  112. //custom join msg
  113. SetupJoinMsg();
  114.  
  115. //geographical player list
  116. SetupGeoList();
  117.  
  118. //suppress standard connection message
  119. SetupSuppress();
  120.  
  121. //Account for late loading
  122. new Handle:topmenu;
  123. if (LibraryExists("adminmenu") && ((topmenu = GetAdminTopMenu()) != INVALID_HANDLE))
  124. {
  125. OnAdminMenuReady(topmenu);
  126. }
  127.  
  128. // Check if we have GeoIPCity.ext loaded
  129. g_UseGeoIPCity = LibraryExists("GeoIPCity");
  130.  
  131. //create config file if not exists
  132. AutoExecConfig(true, "cannounce");
  133. }
  134.  
  135. public OnMapStart()
  136. {
  137. //get, precache and set downloads for player custom sound files
  138. LoadSoundFilesCustomPlayer();
  139.  
  140. //precahce and set downloads for sounds files for all players
  141. LoadSoundFilesAll();
  142. OnMapStart_JoinMsg();
  143. }
  144.  
  145. public OnClientAuthorized(client, const String:auth[])
  146. {
  147. if( GetConVarInt(g_CvarConnectDisplayType) == 0 )
  148. {
  149. if( !IsFakeClient(client) && GetClientCount(true) < MaxClients )
  150. {
  151. OnPostAdminCheck_CountryShow(client);
  152. OnPostAdminCheck_JoinMsg(auth);
  153. }
  154. }
  155. }
  156.  
  157. public OnClientPostAdminCheck(client)
  158. {
  159. decl String:auth[32];
  160.  
  161. if( GetConVarInt(g_CvarConnectDisplayType) == 1 )
  162. {
  163. GetClientAuthId( client, AuthId_Steam2, auth, sizeof(auth) );
  164.  
  165. if( !IsFakeClient(client) && GetClientCount(true) < MaxClients )
  166. {
  167. OnPostAdminCheck_CountryShow(client);
  168. OnPostAdminCheck_JoinMsg(auth);
  169. }
  170. }
  171. }
  172.  
  173. public OnPluginEnd()
  174. {
  175. OnPluginEnd_JoinMsg();
  176. OnPluginEnd_CountryShow();
  177. }
  178.  
  179.  
  180. public OnAdminMenuReady(Handle:topmenu)
  181. {
  182. //Block us from being called twice
  183. if (topmenu == hTopMenu)
  184. {
  185. return;
  186. }
  187.  
  188. //Save the Handle
  189. hTopMenu = topmenu;
  190. OnAdminMenuReady_JoinMsg();
  191. }
  192.  
  193.  
  194. public OnLibraryRemoved(const String:name[])
  195. {
  196. //remove this menu handle if adminmenu plugin unloaded
  197. if (strcmp(name, "adminmenu") == 0)
  198. {
  199. hTopMenu = INVALID_HANDLE;
  200. }
  201.  
  202. // Was the GeoIPCity extension removed?
  203. if(StrEqual(name, "GeoIPCity"))
  204. g_UseGeoIPCity = false;
  205. }
  206.  
  207.  
  208. public OnLibraryAdded(const String:name[])
  209. {
  210. // Is the GeoIPCity extension running?
  211. if(StrEqual(name, "GeoIPCity"))
  212. g_UseGeoIPCity = true;
  213. }
  214.  
  215.  
  216. /****************************************************************
  217.  
  218.  
  219. C A L L B A C K F U N C T I O N S
  220.  
  221.  
  222. ****************************************************************/
  223. public Action:event_PlayerDisconnect(Handle:event, const String:name[], bool:dontBroadcast)
  224. {
  225. new client = GetClientOfUserId(GetEventInt(event, "userid"));
  226.  
  227. if( client && !IsFakeClient(client) && !dontBroadcast )
  228. {
  229. event_PlayerDisc_CountryShow(event, name, dontBroadcast);
  230.  
  231. OnClientDisconnect_JoinMsg();
  232. }
  233. return event_PlayerDisconnect_Suppress( event, name, dontBroadcast );
  234. }
  235.  
  236.  
  237. /*****************************************************************
  238.  
  239.  
  240. P L U G I N F U N C T I O N S
  241.  
  242.  
  243. *****************************************************************/
  244. //Thanks to Darkthrone (https://forums.alliedmods.net/member.php?u=54636)
  245.  
  246. bool:IsLanIP( String:src[16] )
  247. {
  248. decl String:ip4[4][4];
  249. new ipnum;
  250.  
  251. if(ExplodeString(src, ".", ip4, 4, 4) == 4)
  252. {
  253. ipnum = StringToInt(ip4[0])*65536 + StringToInt(ip4[1])*256 + StringToInt(ip4[2]);
  254.  
  255. if((ipnum >= 655360 && ipnum < 655360+65535) || (ipnum >= 11276288 && ipnum < 11276288+4095) || (ipnum >= 12625920 && ipnum < 12625920+255))
  256. {
  257. return true;
  258. }
  259. }
  260.  
  261. return false;
  262. }
  263.  
  264. PrintFormattedMessageToAll( String:rawmsg[301], client )
  265. {
  266. decl String:message[301];
  267.  
  268. GetFormattedMessage( rawmsg, client, message, sizeof(message) );
  269. CPrintToChatAll( "%s", message );
  270. }
  271.  
  272. PrintFormattedMessageToAdmins( String:rawmsg[301], client )
  273. {
  274. decl String:message[301];
  275. GetFormattedMessage( rawmsg, client, message, sizeof(message) );
  276. for (new i = 1; i <= GetMaxClients(); i++)
  277. {
  278. if( IsClientInGame(i) && CheckCommandAccess( i, "", ADMFLAG_GENERIC, true ) )
  279. {
  280. CPrintToChat(i, "%s", message);
  281. }
  282. }
  283. }
  284.  
  285. PrintFormattedMsgToNonAdmins( String:rawmsg[301], client )
  286. {
  287. decl String:message[301];
  288. GetFormattedMessage( rawmsg, client, message, sizeof(message) );
  289. for (new i = 1; i <= GetMaxClients(); i++)
  290. {
  291. if( IsClientInGame(i) && !CheckCommandAccess( i, "", ADMFLAG_GENERIC, true ) )
  292. {
  293. CPrintToChat(i, "%s", message);
  294. }
  295. }
  296. }
  297.  
  298. //GetFormattedMessage - based on code from the DJ Tsunami plugin Advertisements - http://forums.alliedmods.net/showthread.php?p=592536
  299. GetFormattedMessage( String:rawmsg[301], client, String:outbuffer[], outbuffersize )
  300. {
  301. decl String:buffer[256];
  302. decl String:ip[16];
  303. decl String:city[46];
  304. decl String:region[46];
  305. decl String:country[46];
  306. decl String:ccode[3];
  307. decl String:ccode3[4];
  308. decl String:sPlayerAdmin[32];
  309. decl String:sPlayerPublic[32];
  310. new bool:bIsLanIp;
  311. decl AdminId:aid;
  312. if( client > -1 )
  313. {
  314. GetClientIP(client, ip, sizeof(ip));
  315.  
  316. //detect LAN ip
  317. bIsLanIp = IsLanIP( ip );
  318.  
  319. // Using GeoIPCity extension...
  320. if ( g_UseGeoIPCity )
  321. {
  322. if( !GeoipGetRecord( ip, city, region, country, ccode, ccode3 ) )
  323. {
  324. if( bIsLanIp )
  325. {
  326. Format( city, sizeof(city), "%T", "LAN City Desc", LANG_SERVER );
  327. Format( region, sizeof(region), "%T", "LAN Region Desc", LANG_SERVER );
  328. Format( country, sizeof(country), "%T", "LAN Country Desc", LANG_SERVER );
  329. Format( ccode, sizeof(ccode), "%T", "LAN Country Short", LANG_SERVER );
  330. Format( ccode3, sizeof(ccode3), "%T", "LAN Country Short 3", LANG_SERVER );
  331. }
  332. else
  333. {
  334. Format( city, sizeof(city), "%T", "Unknown City Desc", LANG_SERVER );
  335. Format( region, sizeof(region), "%T", "Unknown Region Desc", LANG_SERVER );
  336. Format( country, sizeof(country), "%T", "Unknown Country Desc", LANG_SERVER );
  337. Format( ccode, sizeof(ccode), "%T", "Unknown Country Short", LANG_SERVER );
  338. Format( ccode3, sizeof(ccode3), "%T", "Unknown Country Short 3", LANG_SERVER );
  339. }
  340. }
  341. }
  342. else // Using GeoIP default extension...
  343. {
  344. if( !GeoipCode2(ip, ccode) )
  345. {
  346. if( bIsLanIp )
  347. {
  348. Format( ccode, sizeof(ccode), "%T", "LAN Country Short", LANG_SERVER );
  349. }
  350. else
  351. {
  352. Format( ccode, sizeof(ccode), "%T", "Unknown Country Short", LANG_SERVER );
  353. }
  354. }
  355.  
  356. if( !GeoipCountry(ip, country, sizeof(country)) )
  357. {
  358. if( bIsLanIp )
  359. {
  360. Format( country, sizeof(country), "%T", "LAN Country Desc", LANG_SERVER );
  361. }
  362. else
  363. {
  364. Format( country, sizeof(country), "%T", "Unknown Country Desc", LANG_SERVER );
  365. }
  366. }
  367.  
  368. // Since the GeoIPCity extension isn't loaded, we don't know the city or region.
  369. if( bIsLanIp )
  370. {
  371. Format( city, sizeof(city), "%T", "LAN City Desc", LANG_SERVER );
  372. Format( region, sizeof(region), "%T", "LAN Region Desc", LANG_SERVER );
  373. Format( ccode3, sizeof(ccode3), "%T", "LAN Country Short 3", LANG_SERVER );
  374. }
  375. else
  376. {
  377. Format( city, sizeof(city), "%T", "Unknown City Desc", LANG_SERVER );
  378. Format( region, sizeof(region), "%T", "Unknown Region Desc", LANG_SERVER );
  379. Format( ccode3, sizeof(ccode3), "%T", "Unknown Country Short 3", LANG_SERVER );
  380. }
  381. }
  382.  
  383. // Fallback for unknown/empty location strings
  384. if( StrEqual( city, "" ) )
  385. {
  386. Format( city, sizeof(city), "%T", "Unknown City Desc", LANG_SERVER );
  387. }
  388. if( StrEqual( region, "" ) )
  389. {
  390. Format( region, sizeof(region), "%T", "Unknown Region Desc", LANG_SERVER );
  391. }
  392. if( StrEqual( country, "" ) )
  393. {
  394. Format( country, sizeof(country), "%T", "Unknown Country Desc", LANG_SERVER );
  395. }
  396. if( StrEqual( ccode, "" ) )
  397. {
  398. Format( ccode, sizeof(ccode), "%T", "Unknown Country Short", LANG_SERVER );
  399. }
  400. if( StrEqual( ccode3, "" ) )
  401. {
  402. Format( ccode3, sizeof(ccode3), "%T", "Unknown Country Short 3", LANG_SERVER );
  403. }
  404.  
  405. // Add "The" in front of certain countries
  406. if( StrContains( country, "United", false ) != -1 ||
  407. StrContains( country, "Republic", false ) != -1 ||
  408. StrContains( country, "Federation", false ) != -1 ||
  409. StrContains( country, "Island", false ) != -1 ||
  410. StrContains( country, "Netherlands", false ) != -1 ||
  411. StrContains( country, "Isle", false ) != -1 ||
  412. StrContains( country, "Bahamas", false ) != -1 ||
  413. StrContains( country, "Maldives", false ) != -1 ||
  414. StrContains( country, "Philippines", false ) != -1 ||
  415. StrContains( country, "Vatican", false ) != -1 )
  416. {
  417. Format( country, sizeof(country), "The %s", country );
  418. }
  419.  
  420. if (StrContains(rawmsg, "{PLAYERNAME}") != -1)
  421. {
  422. GetClientName(client, buffer, sizeof(buffer));
  423. ReplaceString(rawmsg, sizeof(rawmsg), "{PLAYERNAME}", buffer);
  424. }
  425.  
  426. if (StrContains(rawmsg, "{STEAMID}") != -1)
  427. {
  428. GetClientAuthId(client, AuthId_Steam2, buffer, sizeof(buffer));
  429. ReplaceString(rawmsg, sizeof(rawmsg), "{STEAMID}", buffer);
  430. }
  431.  
  432. if (StrContains(rawmsg, "{PLAYERCOUNTRY}") != -1 )
  433. {
  434. ReplaceString(rawmsg, sizeof(rawmsg), "{PLAYERCOUNTRY}", country);
  435. }
  436.  
  437. if (StrContains(rawmsg, "{PLAYERCOUNTRYSHORT}") != -1 )
  438. {
  439. ReplaceString(rawmsg, sizeof(rawmsg), "{PLAYERCOUNTRYSHORT}", ccode);
  440. }
  441.  
  442. if (StrContains(rawmsg, "{PLAYERCOUNTRYSHORT3}") != -1 )
  443. {
  444. ReplaceString(rawmsg, sizeof(rawmsg), "{PLAYERCOUNTRYSHORT3}", ccode3);
  445. }
  446.  
  447. if (StrContains(rawmsg, "{PLAYERCITY}") != -1 )
  448. {
  449. ReplaceString(rawmsg, sizeof(rawmsg), "{PLAYERCITY}", city);
  450. }
  451.  
  452. if (StrContains(rawmsg, "{PLAYERREGION}") != -1 )
  453. {
  454. ReplaceString(rawmsg, sizeof(rawmsg), "{PLAYERREGION}", region);
  455. }
  456.  
  457. if (StrContains(rawmsg, "{PLAYERIP}") != -1 )
  458. {
  459. ReplaceString(rawmsg, sizeof(rawmsg), "{PLAYERIP}", ip);
  460. }
  461.  
  462. if( StrContains(rawmsg, "{PLAYERTYPE}") != -1 && GetConVarInt(g_CvarConnectDisplayType) == 1 )
  463. {
  464. aid = GetUserAdmin( client );
  465.  
  466. if( GetAdminFlag( aid, Admin_Generic ) )
  467. {
  468. Format( sPlayerAdmin, sizeof(sPlayerAdmin), "%T", "CA Admin", LANG_SERVER );
  469. ReplaceString(rawmsg, sizeof(rawmsg), "{PLAYERTYPE}", sPlayerAdmin);
  470. }
  471. else
  472. {
  473. Format( sPlayerPublic, sizeof(sPlayerPublic), "%T", "CA Public", LANG_SERVER );
  474. ReplaceString(rawmsg, sizeof(rawmsg), "{PLAYERTYPE}", sPlayerPublic);
  475. }
  476. }
  477. }
  478.  
  479. Format( outbuffer, outbuffersize, "%s", rawmsg );
  480. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement