Permalink
Browse files

Fixed a bug where a tempadmin without VIP could have his teleport dis…

…abled when not being able to change it anymore. Also cleaned-up some duplicate code and unnecessary large string-allocations. Fixes bug #453.
  • Loading branch information...
xhoogland committed Feb 9, 2017
1 parent f9fd911 commit a647199c7ca42bd0b0a5f1060ad0915fde73c596
@@ -1015,19 +1015,7 @@ GodHelp:
return 1;
}
- new const bool: wasVip = Player(subjectId)->isLoggedIn() ? (AccountData(subjectId)->isVip())
- : false;
-
- Player(subjectId)->setLevel(PlayerLevel);
- Player(subjectId)->setIsVip(wasVip);
-
- UndercoverAdministrator(subjectId)->setIsUndercoverAdministrator(false);
-
- tempLevel[subjectId] = 0;
- UserTemped[subjectId] = "";
- PlayerSettings(subjectId)->setMapTeleportationEnabled(false);
-
- ColorManager->restorePreviousPlayerCustomColor(subjectId);
+ TakeTempAdministratorRightsFromPlayer(subjectId, true /** fromInGame **/);
format(g_message, sizeof(g_message), "%s (Id:%d) is no admin anymore.",
Player(subjectId)->nicknameString(), subjectId);
@@ -3,6 +3,11 @@
// be found in the LICENSE file.
OnPlayerLVPDisconnect(playerId, reason) {
+ new bool: wasVip = Player(playerId)->isLoggedIn() ? (AccountData(playerId)->isVip())
+ : false;
+ if (!wasVip)
+ PlayerSettings(playerId)->setTeleportationDisabled(false);
+
if (reason != 2)
CSave__OnPlayerDisconnect(playerId);
@@ -1007,3 +1007,23 @@ GetPlayerIngameHours(playerId) {
forward OnPlayerLeaveActivity(playerid);
public OnPlayerLeaveActivity(playerid) {}
+
+TakeTempAdministratorRightsFromPlayer(playerId, bool: fromInGame = false) {
+ new const bool: wasVip = Player(playerId)->isLoggedIn() ? (AccountData(playerId)->isVip())
+ : false;
+
+ Player(playerId)->setLevel(PlayerLevel);
+ Player(playerId)->setIsVip(wasVip);
+
+ if (fromInGame)
+ UndercoverAdministrator(playerId)->setIsUndercoverAdministrator(false);
+
+ tempLevel[playerId] = 0;
+ UserTemped[playerId] = "";
+ PlayerSettings(playerId)->setMapTeleportationEnabled(false);
+
+ if (!wasVip)
+ PlayerSettings(playerId)->setTeleportationDisabled(false);
+
+ ColorManager->restorePreviousPlayerCustomColor(playerId);
+}
@@ -77,38 +77,29 @@ RunDeprecatedIrcCommand(line[]) {
if(strcmp(cmd,"taketempadmin",true) == 0)
{
- new tmp[256], szName [256];
- tmp = strtok(line, idx);
- if(!tmp[0]) return AddEcho("Correct Usage: !taketempadmin <playerid>");
+ new temp[256], ircUsername[64], message[256];
+ temp = strtok(line, idx);
- format(szName, 256, "%s", tmp);
- tmp = strtok(line, idx);
+ format(ircUsername, sizeof(ircUsername), "%s", temp);
+ temp = strtok(line, idx);
- new pid = strval(tmp);
- if(!Player(pid)->isConnected())
+ new playerId = strval(temp);
+ if(!Player(playerId)->isConnected())
{
- format(string,sizeof(string),"[notconnected] %d",pid);
- AddEcho(string);
+ format(message, sizeof(message), "%d", playerId);
+ IRC->broadcast(NotConnectedIrcMessage, message);
return 1;
}
- new str[256];
- format(str,256,"%s (IRC) has taken admin rights from %s (Id:%d).", szName, PlayerName (pid), pid);
- Admin(Player::InvalidId, str);
- new const bool: wasVip = Player(pid)->isLoggedIn() ? (AccountData(pid)->isVip())
- : false;
+ TakeTempAdministratorRightsFromPlayer(playerId);
- Player(pid)->setIsVip(wasVip);
- Player(pid)->setLevel(PlayerLevel);
+ format(message, sizeof(message), "%s is no longer an administrator.",
+ Player(playerId)->nicknameString());
+ AddEcho(message);
- PlayerSettings(pid)->setMapTeleportationEnabled(false);
-
- ColorManager->restorePreviousPlayerCustomColor(pid);
-
- tempLevel[pid] = 0;
- UserTemped [pid] = "";
- format(str,256,"%s is no longer an administrator.",PlayerName(pid));
- AddEcho(str);
+ format(message, sizeof(message), "%s (IRC) has taken admin rights from %s (Id:%d).",
+ ircUsername, Player(playerId)->nicknameString(), playerId);
+ Admin(Player::InvalidId, message);
return 1;
}

0 comments on commit a647199

Please sign in to comment.