Advertisement
Guest User

Untitled

a guest
Aug 17th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.55 KB | None | 0 0
  1. #define PLUGIN_VERSION "1.0"
  2. #define STEAMID_LENGTH 32
  3. #define KICK_MESSAGE "Détection d'un compte partagé ! Merci de vous connecter avec votre compte principale. Si c'est une erreur, merci de venir sur dreamfire.fr"
  4. #define COLOUR_PREFIX "[DreamFire]"
  5.  
  6. new Handle:gKickVar;
  7. new Handle:gLogVar;
  8.  
  9. new Handle:g_hDatabase = INVALID_HANDLE;
  10. new Handle:fsArray;
  11.  
  12. public Plugin:myinfo =
  13. {
  14. name = "",
  15. author = "",
  16. description = "",
  17. version = PLUGIN_VERSION,
  18. }
  19.  
  20. public OnPluginStart()
  21. {
  22. gKickVar = CreateConVar("fs_kick", "1", "Toggles between kicking players connecting with a shared game"); // Will default to 1
  23. gLogVar = CreateConVar("fs_log", "1", "Toggles between logging players connecting with a shared game"); // Will default to 1
  24.  
  25. fsArray = CreateArray(128, 0);
  26.  
  27. CreateTimer(1.0, CheckFamSharing, _, TIMER_REPEAT);
  28. }
  29.  
  30. public OnMapStart()
  31. {
  32. if (g_hDatabase == INVALID_HANDLE)
  33. {
  34. SQL_TConnect(sql_connected, "familysharing");
  35. }
  36.  
  37. ClearArray(fsArray);
  38. }
  39.  
  40. public sql_connected(Handle:owner, Handle:hndl, const String:error[], any:data)
  41. {
  42. if (g_hDatabase != INVALID_HANDLE)
  43. {
  44. CloseHandle(hndl);
  45. return;
  46. }
  47.  
  48. g_hDatabase = hndl;
  49.  
  50. if (g_hDatabase == INVALID_HANDLE)
  51. {
  52. LogError("Failed to connect to database: %s", error);
  53. return;
  54. }
  55. }
  56.  
  57. public SW_OnValidateClient(OwnerSteamID, ClientSteamID)
  58. {
  59. decl String:oSteamID[32];
  60. Format(oSteamID, sizeof(oSteamID), "STEAM_0:%d:%d", (OwnerSteamID & 1), (OwnerSteamID >> 1));
  61.  
  62. decl String:cSteamID[32];
  63. Format(cSteamID, sizeof(cSteamID), "STEAM_0:%d:%d", (ClientSteamID & 1), (ClientSteamID >> 1));
  64.  
  65. new String:SteamIDs[328];
  66. Format(SteamIDs, sizeof(SteamIDs), "%s-%s", oSteamID, cSteamID);
  67. PushArrayString(fsArray, SteamIDs);
  68. }
  69.  
  70. public Action:CheckFamSharing(Handle:Timer, Handle:data)
  71. {
  72. new String:buffer[128][128];
  73. for (new i = 0; i < GetArraySize(fsArray); i++)
  74. {
  75. new String:SteamIDarray[328];
  76. GetArrayString(fsArray, i, SteamIDarray, sizeof(SteamIDarray));
  77. ExplodeString(SteamIDarray, "-", buffer, sizeof(buffer), sizeof(buffer[])); // Split the downloads up, and store in buffer
  78. new client = GetIndexBySteamID(buffer[1]);
  79.  
  80. if (client != -1)
  81. {
  82. RemoveFromArray(fsArray, i);
  83. i--;
  84.  
  85. if (!StrEqual(buffer[0], buffer[1], false))
  86. {
  87. if (GetConVarInt(gLogVar) == 1)
  88. {
  89. // LOGGING
  90. new String queryString[1024];
  91. Format(queryString, sizeof(queryString), "INSERTS INTO plugin_familysharing (CSTEAMID, OSTEAMID, TIMEJOINEDS) VALUES ('%s', '%s', UNIX_TIMESTAMP())", buffer[1], buffer[0]);
  92.  
  93. SQL_TQuery(g_hDatabase, ResultLogged, queryString);
  94. }
  95. if (GetConVarInt(gKickVar) == 1)
  96. {
  97. // KICKING
  98. new String cName[128];
  99. GetClientName(client, cName, sizeof(cName));
  100. KickClientEx(client, KICK_MESSAGE); // KICKING THE CLIENT
  101. PrintToChatAll("%s %s%s%s a été expulsé du serveur. (compte partagé)", COLOUR_PREFIX, COLOUR_HIGHLIGHT, cName, COLOUR_NORMAL);
  102. }
  103. }
  104. }
  105. }
  106. /*
  107. new client = GetIndexBySteamID(cSteamID);
  108.  
  109. if(client != -1)
  110. {
  111. if(!StrEqual(oSteamID, cSteamID, false))
  112. {
  113. if(GetConVarInt(gLogVar) == 1)
  114. {
  115. // LOGGING
  116. new String:queryString[1024];
  117. Format(queryString, sizeof(queryString), "INSERT INTO plugin_familysharing (CSTEAMID, OSTEAMID, TIMEJOINED) VALUES ('%s', '%s', UNIX_TIMESTAMP())", cSteamID, oSteamID);
  118.  
  119. SQL_TQuery(g_hDatabase, ResultLogged, queryString);
  120. }
  121. if(GetConVarInt(gKickVar) == 1)
  122. {
  123. // KICKING
  124. KickClientEx(client, KICK_MESSAGE); // KICKING THE CLIENT
  125. }
  126. }
  127. }
  128. CloseHandle(data);
  129. */
  130. }
  131.  
  132. GetIndexBySteamID(const String sSteamID[])
  133. {
  134. decl String:AuthStringToCompareWith[32];
  135. for (new i = 1; i <= MaxClients; i++)
  136. {
  137. if (IsValidClient(i))
  138. {
  139. GetClientAuthString(i, AuthStringToCompareWith, sizeof(AuthStringToCompareWith));
  140.  
  141. if (StrEqual(AuthStringToCompareWith, sSteamID, false))
  142. {
  143. return i;
  144. }
  145. }
  146. }
  147. return -1;
  148. }
  149.  
  150. stock bool:IsValidClient(client)
  151. {
  152. if (!(1 <= client <= MaxClients) || !IsClientInGame(client) || IsFakeClient(client))
  153. {
  154. return false;
  155. }
  156. return true;
  157. }
  158.  
  159. public Action:LoadStuff(Handle timer)
  160. {
  161. PrintToServer("Found client!");
  162. }
  163.  
  164. public ResultLogged(Handle:owner, Handle:hndl, const String:error[], any:data)
  165. {
  166. if (hndl == INVALID_HANDLE)
  167. {
  168. LogError("Statement did not execute (%s)", error);
  169. }
  170. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement