Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Case sensitive #136

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions clear.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@ function HandleClearCommand(Split, Player)
if Player:HasPermission("core.admin.clear") then
local InventoryCleared = false;
local ClearInventory = function(OtherPlayer)
if (OtherPlayer:GetName() == Split[2]) then
OtherPlayer:GetInventory():Clear()
InventoryCleared = true
end
OtherPlayer:GetInventory():Clear()
InventoryCleared = true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not so good. The FindAndDoWithPlayer function actually calls the callback for the nearest name, it doesn't have to match.
Consider there are three players, Admin, Xoft and Xof. Now admin wants to cleat Xof's inventory, so he types /clear Xof. Just before sending the command, Xof disconnects, and Xoft's inventory gets cleared.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But the likelihood of that happening is very small, and the usability benefit of being able to use partial names IMO outweights the possibility of doing the command to the wrong person.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps show a confirmation message for critical commands like banning or clearing inventory?
are you sure? Press Y to confirm and delete the Inventory of <Full player name here>

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better would be a delay where you could type /clear cancel to cancel the clearing. But IDK if that's the best solution.

end

cRoot:Get():FindAndDoWithPlayer(Split[2], ClearInventory);
Expand Down
38 changes: 19 additions & 19 deletions do.lua
Original file line number Diff line number Diff line change
@@ -1,53 +1,53 @@
function HandleDoCommand( Split, Player )
function HandleDoCommand(Split, Player)

if #Split < 3 then
SendMessage( Player, "Usage: /do <player> <command> [arguments]" )
SendMessage(Player, "Usage: /do <player> <command> [arguments]")
return true
end

-- Get the command and arguments.
local newSplit = table.concat( Split, " ", 3 )
local newSplit = table.concat(Split, " ", 3)

local FoundPlayerCallback = function( a_Player )
local FoundPlayerCallback = function(a_Player)
local pluginManager = cRoot:Get():GetPluginManager()
if (pluginManager:ExecuteCommand( a_Player, newSplit )) then
SendMessageSuccess( Player, "Command executed!" )
if (pluginManager:ExecuteCommand(a_Player, newSplit)) then
SendMessageSuccess(Player, "Command executed!")
else
SendMessageFailure( Player, "Bad command - execution failed" )
SendMessageFailure(Player, "Bad command - execution failed")
end
return true
end

if not cRoot:Get():FindAndDoWithPlayer( Split[2], FoundPlayerCallback ) then
SendMessageFailure( Player, "Could not find player" )
if not cRoot:Get():FindAndDoWithPlayer(Split[2], FoundPlayerCallback) then
SendMessageFailure(Player, "Could not find player")
return true
end

return true
end

function HandleSudoCommand ( Split, Player )
function HandleSudoCommand(Split, Player)

if #Split < 3 then
SendMessage( Player, "Usage: /sudo <player> <command> [arguments]" )
if #Split < 3 then
SendMessage(Player, "Usage: /sudo <player> <command> [arguments]")
return true
end

-- Get the command and arguments.
local newSplit = table.concat( Split, " ", 3 )
local newSplit = table.concat(Split, " ", 3)

local FoundPlayerCallback = function( a_Player )
local FoundPlayerCallback = function(a_Player)
local pluginManager = cRoot:Get():GetPluginManager()
if (pluginManager:ForceExecuteCommand( a_Player, newSplit )) then
SendMessageSuccess( Player, "Command executed!" )
if (pluginManager:ForceExecuteCommand(a_Player, newSplit)) then
SendMessageSuccess(Player, "Command executed!")
else
SendMessageFailure( Player, "Bad command - execution failed" )
SendMessageFailure(Player, "Bad command - execution failed")
end
return true
end

if not cRoot:Get():FindAndDoWithPlayer( Split[2], FoundPlayerCallback ) then
SendMessageFailure( Player, "Could not find player" )
if not cRoot:Get():FindAndDoWithPlayer(Split[2], FoundPlayerCallback) then
SendMessageFailure(Player, "Could not find player")
return true
end

Expand Down
5 changes: 0 additions & 5 deletions enchant.lua
Original file line number Diff line number Diff line change
Expand Up @@ -611,11 +611,6 @@ local function EnchantItem( Split )
--
local function DoEnchantment( NewPlayer )

-- Make sure that the names match
if string.lower( NewPlayer:GetName() ) ~= lcPlayerName then
return false
end

-- Make sure that the targeted player has an item selected
local Item = NewPlayer:GetEquippedItem()
if Item:IsEmpty() then
Expand Down
4 changes: 0 additions & 4 deletions give.lua
Original file line number Diff line number Diff line change
Expand Up @@ -318,10 +318,6 @@ local function GiveItemCommand( Split, Player, SafeCommand )
--
local function giveItems( NewPlayer )

if string.lower( NewPlayer:GetName() ) ~= lcPlayerName then
return false
end

Item:AddCount(Amount - 1)
NewPlayer:GetInventory():AddItem( Item )

Expand Down
8 changes: 3 additions & 5 deletions gm.lua
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,9 @@ local function ChangeGameMode( GameMode, PlayerName )
-- the given PlayerName then change their gamemode
cRoot:Get():FindAndDoWithPlayer(PlayerName,
function(PlayerMatch)
if string.lower(PlayerMatch:GetName()) == lcPlayerName then
PlayerMatch:SetGameMode(GameMode)
SendMessage(PlayerMatch, "Gamemode set to " .. GameModeNameTable[GameMode] )
GMChanged = true
end
PlayerMatch:SetGameMode(GameMode)
SendMessage(PlayerMatch, "Gamemode set to " .. GameModeNameTable[GameMode] )
GMChanged = true
return true
end
)
Expand Down
6 changes: 2 additions & 4 deletions kick.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@ function HandleKickCommand( Split, Player )
end
local IsPlayerKicked = false
local Kick = function(OtherPlayer)
if (OtherPlayer:GetName() == Split[2]) then
IsPlayerKicked = true
KickPlayer(Split[2], Reason)
end
IsPlayerKicked = true
KickPlayer(Split[2], Reason)
end

cRoot:Get():FindAndDoWithPlayer(Split[2], Kick)
Expand Down
6 changes: 2 additions & 4 deletions kill.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@ function HandleKillCommand( Split, Player )

local HasKilled = false;
local KillPlayer = function(OtherPlayer)
if (OtherPlayer:GetName() == Split[2]) then
OtherPlayer:TakeDamage(dtPlugin, nil, 1000, 1000, 0)
HasKilled = true
end
OtherPlayer:TakeDamage(dtPlugin, nil, 1000, 1000, 0)
HasKilled = true
end

cRoot:Get():FindAndDoWithPlayer(Split[2], KillPlayer);
Expand Down
33 changes: 15 additions & 18 deletions teleport.lua
Original file line number Diff line number Diff line change
Expand Up @@ -90,26 +90,23 @@ function HandleTPACommand( Split, Player )
end

local loopPlayer = function( OtherPlayer )
if OtherPlayer:GetName() == Split[2] then
if Split[1] == "/tpa" then
SendMessage(OtherPlayer, Player:GetName() .. cChatColor.Plain .. " has requested to teleport to you." )
else
SendMessage(OtherPlayer, Player:GetName() .. cChatColor.Plain .. " has requested you to teleport to them." )
end

if Split[1] == "/tpa" then
SendMessage(OtherPlayer, Player:GetName() .. cChatColor.Plain .. " has requested to teleport to you." )
else
SendMessage(OtherPlayer, Player:GetName() .. cChatColor.Plain .. " has requested you to teleport to them." )
end

if TpRequestTimeLimit > 0 then
OtherPlayer:SendMessage("This request will timeout after " .. TpRequestTimeLimit .. " seconds" )
end

OtherPlayer:SendMessage("To teleport, type " .. cChatColor.LightGreen .. "/tpaccept" )
OtherPlayer:SendMessage("To deny this request, type " .. cChatColor.Rose .. "/tpdeny" )
SendMessageSuccess( Player, "Request sent to " .. OtherPlayer:GetName() )

TeleportRequests[OtherPlayer:GetUniqueID()] = {Type = Split[1], Requester = Player:GetUniqueID(), Time = GetTime() }

flag = 1
if TpRequestTimeLimit > 0 then
OtherPlayer:SendMessage("This request will timeout after " .. TpRequestTimeLimit .. " seconds" )
end

OtherPlayer:SendMessage("To teleport, type " .. cChatColor.LightGreen .. "/tpaccept" )
OtherPlayer:SendMessage("To deny this request, type " .. cChatColor.Rose .. "/tpdeny" )
SendMessageSuccess( Player, "Request sent to " .. OtherPlayer:GetName() )

TeleportRequests[OtherPlayer:GetUniqueID()] = {Type = Split[1], Requester = Player:GetUniqueID(), Time = GetTime() }

flag = 1
end

cRoot:Get():ForEachPlayer(loopPlayer)
Expand Down
20 changes: 9 additions & 11 deletions tell.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,14 @@ function HandleTellCommand(Split, Player)

local SendMessage = function(OtherPlayer)

if (OtherPlayer:GetName() == Split[2]) then
local newSplit = table.concat( Split, " ", 3 )

SendMessageSuccess( Player, "Message to player " .. Split[2] .. " sent!" )
OtherPlayer:SendMessagePrivateMsg(newSplit, Player:GetName())

lastsender[OtherPlayer:GetName()] = Player:GetName()

FoundPlayer = true
end
local newSplit = table.concat( Split, " ", 3 )

SendMessageSuccess( Player, "Message to player " .. Split[2] .. " sent!" )
OtherPlayer:SendMessagePrivateMsg(newSplit, Player:GetName())

lastsender[OtherPlayer:GetName()] = Player:GetName()

FoundPlayer = true
end

cRoot:Get():ForEachPlayer(SendMessage)
Expand Down Expand Up @@ -52,4 +50,4 @@ function HandleRCommand(Split,Player)
end
end
return true
end
end