Krenair

sourcepunish player disconnect cache diff

Dec 5th, 2013
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 7.11 KB | None | 0 0
  1. diff --git a/scripting/include/sourcepunish.inc b/scripting/include/sourcepunish.inc
  2. index 7a00511..65d6dff 100644
  3. --- a/scripting/include/sourcepunish.inc
  4. +++ b/scripting/include/sourcepunish.inc
  5. @@ -23,6 +23,7 @@ native Handle:GetRegisteredPunishmentTypeStrings();
  6.  native GetPunishmentTypeDisplayName(String:type[], String:buffer[], maxlen);
  7.  native GetPunishmentTypeFlags(String:type[]);
  8.  native GetPunishmentTypeAdminFlag(String:type[]);
  9. +native Handle:FindDisconnectedSteamIDFromName(String:target[], String:buffer[], maxlen);
  10.  
  11.  #define SP_SUCCESS 1
  12.  #define SP_ERROR_TARGET_ALREADY_PUNISHED 2
  13. diff --git a/scripting/sourceirc-sourcepunish.sp b/scripting/sourceirc-sourcepunish.sp
  14. index 0e7906a..b346c8e 100644
  15. --- a/scripting/sourceirc-sourcepunish.sp
  16. +++ b/scripting/sourceirc-sourcepunish.sp
  17. @@ -195,9 +195,19 @@ public Action:IRCCommand_Punish(String:nick[], args) {
  18.                 sizeof(target_name),
  19.                 tn_is_ml
  20.         )) <= 0) {
  21. -               // Reply to the admin with a failure message
  22. -               IRC_ReplyToTargetError(nick, target_count);
  23. -               return Plugin_Handled;
  24. +               decl String:disconnectedAuth[64];
  25. +               FindDisconnectedSteamIDFromName(target, disconnectedAuth, sizeof(disconnectedAuth));
  26. +               if (StrEqual(disconnectedAuth, "")) {
  27. +                       IRC_ReplyToTargetError(nick, target_count); // Reply to the admin with a failure message
  28. +                       return Plugin_Handled;
  29. +               } else {
  30. +                       if (commandType == 0) {
  31. +                               commandType = 2;
  32. +                       } else if (commandType == 1) {
  33. +                               commandType = 3;
  34. +                       }
  35. +                       strcopy(target, sizeof(target), disconnectedAuth);
  36. +               }
  37.         }
  38.  
  39.         if (commandType == 0) {
  40. diff --git a/scripting/sourcepunish.sp b/scripting/sourcepunish.sp
  41. index 98a1b1a..e85070d 100644
  42. --- a/scripting/sourcepunish.sp
  43. +++ b/scripting/sourcepunish.sp
  44. @@ -54,6 +54,11 @@ enum punishmentType {
  45.         Handle:pluginHandle,
  46.  }
  47.  
  48. +enum disconnectedPlayer {
  49. +       String:playerName[64],
  50. +       String:playerAuth[64],
  51. +}
  52. +
  53.  new Handle:punishments = INVALID_HANDLE;
  54.  new Handle:punishmentTypes = INVALID_HANDLE;
  55.  new Handle:punishmentRemovalTimers[MAXPLAYERS + 1];
  56. @@ -76,6 +81,7 @@ new Handle:steamIDRegex;
  57.  new Handle:punishmentRegisteredForward = INVALID_HANDLE;
  58.  new Handle:punishmentPluginUnloadedForward = INVALID_HANDLE;
  59.  new ReplySource:commandReplySources[MAXPLAYERS + 1];
  60. +new Handle:disconnectedPlayerCache = INVALID_HANDLE;
  61.  
  62.  public OnPluginStart() {
  63.         decl String:error[64];
  64. @@ -121,6 +127,8 @@ public OnPluginStart() {
  65.  
  66.         punishmentRegisteredForward = CreateGlobalForward("PunishmentRegistered", ET_Ignore, Param_String, Param_String, Param_Cell);
  67.         punishmentPluginUnloadedForward = CreateGlobalForward("PunishmentPluginUnloaded", ET_Ignore);
  68. +
  69. +       disconnectedPlayerCache = CreateArray();
  70.  }
  71.  
  72.  public SMCResult:SMC_KeyValue(Handle:smc, const String:key[], const String:value[], bool:key_quotes, bool:value_quotes) {
  73. @@ -332,11 +340,20 @@ public Action:Command_Punish(client, args) {
  74.                 sizeof(target_name),
  75.                 tn_is_ml
  76.         )) <= 0) {
  77. -               // Reply to the admin with a failure message
  78. -               ReplyToTargetError(client, target_count);
  79. -               return Plugin_Handled;
  80. +               decl String:disconnectedAuth[64];
  81. +               FindDisconnectedSteamIDFromName(target, disconnectedAuth, sizeof(disconnectedAuth));
  82. +               if (StrEqual(disconnectedAuth, "")) {
  83. +                       ReplyToTargetError(client, target_count); // Reply to the admin with a failure message
  84. +                       return Plugin_Handled;
  85. +               } else {
  86. +                       if (commandType == 0) {
  87. +                               commandType = 2;
  88. +                       } else if (commandType == 1) {
  89. +                               commandType = 3;
  90. +                       }
  91. +                       strcopy(target, sizeof(target), disconnectedAuth);
  92. +               }
  93.         }
  94. -
  95.         commandReplySources[client] = GetCmdReplySource();
  96.         if (commandType == 0) {
  97.                 for (new i = 0; i < target_count; i++) {
  98. @@ -465,6 +482,15 @@ public OnClientDisconnect(client) {
  99.                 }
  100.                 punishmentRemovalTimers[client] = INVALID_HANDLE;
  101.         }
  102. +
  103. +       // Add the player to the disconnected list in case we want to punish them after they leave
  104. +       decl disconnectedPlayerEnum[disconnectedPlayer];
  105. +       GetClientName(client, disconnectedPlayerEnum[playerName], sizeof(disconnectedPlayerEnum[playerName]));
  106. +       GetClientAuthString(client, disconnectedPlayerEnum[playerAuth], sizeof(disconnectedPlayerEnum[playerAuth]));
  107. +       PushArrayArray(disconnectedPlayerCache, disconnectedPlayerEnum, sizeof(disconnectedPlayerEnum));
  108. +       if (GetArraySize(disconnectedPlayerCache) > 10) { // If we've got more than 10 in the cache
  109. +               RemoveFromArray(disconnectedPlayerCache, 0); // Remove the first so we remain at 10
  110. +       }
  111.  }
  112.  
  113.  public APLRes:AskPluginLoad2(Handle:myself, bool:late, String:error[], err_max) {
  114. @@ -475,6 +501,7 @@ public APLRes:AskPluginLoad2(Handle:myself, bool:late, String:error[], err_max)
  115.         CreateNative("GetPunishmentTypeDisplayName", Native_GetPunishmentTypeDisplayName);
  116.         CreateNative("GetPunishmentTypeFlags", Native_GetPunishmentTypeFlags);
  117.         CreateNative("GetPunishmentTypeAdminFlag", Native_GetPunishmentTypeAdminFlag);
  118. +       CreateNative("FindDisconnectedSteamIDFromName", Native_FindDisconnectedSteamIDFromName);
  119.         CreateNative("PunishClient", Native_PunishClient);
  120.         CreateNative("PunishIdentity", Native_PunishIdentity);
  121.         CreateNative("UnpunishClient", Native_UnpunishClient);
  122. @@ -1096,6 +1123,23 @@ public Native_GetPunishmentTypeAdminFlag(Handle:plugin, numParams) {
  123.         return pmethod[adminflag];
  124.  }
  125.  
  126. +public Native_FindDisconnectedSteamIDFromName(Handle:plugin, numParams) {
  127. +       decl String:target[64];
  128. +       GetNativeString(1, target, sizeof(target));
  129. +
  130. +       for (new i = 0; i < GetArraySize(disconnectedPlayerCache); i++) {
  131. +               decl disconnectedPlayerEnum[disconnectedPlayer];
  132. +               GetArrayArray(disconnectedPlayerCache, i, disconnectedPlayerEnum, sizeof(disconnectedPlayerEnum));
  133. +               if (StrContains(disconnectedPlayerEnum[playerName], target)) {
  134. +                       PrintToServer(disconnectedPlayerEnum[playerName]);
  135. +                       PrintToServer(disconnectedPlayerEnum[playerAuth]);
  136. +                       SetNativeString(2, disconnectedPlayerEnum[playerAuth], GetNativeCell(3)); // Copy string into buffer (param 2). maxlen is param 3.
  137. +                       return;
  138. +               }
  139. +       }
  140. +       SetNativeString(2, "", GetNativeCell(3)); // Copy blank string into buffer (param 2). maxlen is param 3.
  141. +}
  142. +
  143.  public Native_RegisterPunishment(Handle:plugin, numParams) {
  144.         decl String:type[64];
  145.         GetNativeString(1, type, sizeof(type));
Advertisement
Add Comment
Please, Sign In to add comment