Advertisement
Guest User

Untitled

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