Skip to content

Commit

Permalink
v1.13.0
Browse files Browse the repository at this point in the history
- Remove ClientCaster:GetPing
- Remove ClientCaster:GetMaxPingExhaustion
- Remove ClientCaster:SetMaxPingExhaustion
- Update raycast data serialization to take up less space
  • Loading branch information
Pyseph committed Oct 17, 2022
1 parent 8d727a2 commit 52789a6
Show file tree
Hide file tree
Showing 7 changed files with 114 additions and 173 deletions.
57 changes: 0 additions & 57 deletions .github/workflows/ReleaseBuild.yml

This file was deleted.

8 changes: 4 additions & 4 deletions lib/ClientHandler.client.luau
Original file line number Diff line number Diff line change
Expand Up @@ -207,10 +207,10 @@ end

local function SerializeResult(Result)
return {
Instance = Result.Instance,
Position = Result.Position,
Material = Result.Material,
Normal = Result.Normal,
Result.Instance,
Result.Position,
Result.Material,
Result.Normal,
}
end
local function DeserializeParams(Input)
Expand Down
96 changes: 23 additions & 73 deletions lib/init.luau
Original file line number Diff line number Diff line change
Expand Up @@ -75,29 +75,6 @@ local PingRemote = ReplicatedStorage:FindFirstChild("ClientCast-Ping")

local Signal = require(script.Signal)

local function SafeRemoteInvoke(RemoteFunction, Player, MaxYield)
local ThreadResumed = false
local Thread = coroutine.running()

task.spawn(function()
local TimestampStart = time()
RemoteFunction:InvokeClient(Player)
local TimestampEnd = time()

ThreadResumed = true
task.spawn(Thread, math.min(TimestampEnd - TimestampStart, MaxYield))
end)

task.delay(MaxYield, function()
if not ThreadResumed then
ThreadResumed = true
task.spawn(Thread, MaxYield)
end
end)

return coroutine.yield()
end

local function SerializeParams(Params)
return {
FilterDescendantsInstances = Params.FilterDescendantsInstances,
Expand All @@ -120,11 +97,6 @@ local function AssertClass(Object, ExpectedClass, Message)
error(string.format(Message, ExpectedClass, Object.Class), 4)
end
end
local function AssertNaN(Object, Message)
if Object ~= Object then
error(string.format(Message, "number", typeof(Object)), 4)
end
end
local function IsValidOwner(Value, Error)
local IsInstance = IsA(Value, "Instance")
if not IsInstance and Value ~= nil then
Expand All @@ -133,18 +105,30 @@ local function IsValidOwner(Value, Error)
error(Error or "SetOwner only takes player or 'nil' instance as an argument.", 4)
end
end
local function IsValid(SerializedResult)
local function DeserializeRaycastResult(SerializedResult)
if not IsA(SerializedResult, "table") then
return false
end

return (
SerializedResult.Instance ~= nil
and (SerializedResult.Instance:IsA("BasePart") or SerializedResult.Instance:IsA("Terrain"))
)
and IsA(SerializedResult.Position, "Vector3")
and IsA(SerializedResult.Material, "EnumItem")
and IsA(SerializedResult.Normal, "Vector3")
local HitInstance, Position, Material, Normal = unpack(SerializedResult)
local IsValid = (
HitInstance ~= nil
and (HitInstance:IsA("BasePart") or HitInstance:IsA("Terrain"))
)
and IsA(Position, "Vector3")
and IsA(Material, "EnumItem")
and IsA(Normal, "Vector3")

if IsValid then
return true, {
Instance = HitInstance,
Position = Position,
Material = Material,
Normal = Normal,
}
else
return false
end
end

local Replication = {}
Expand All @@ -164,12 +148,13 @@ function ReplicationBase:Start()
})

local LocalizedConnection
LocalizedConnection = ReplicationRemote.OnServerEvent:Connect(function(Player, CasterId, Code, RaycastResult)
LocalizedConnection = ReplicationRemote.OnServerEvent:Connect(function(Player, CasterId, Code, SerializedRaycastResult)
if self.Caster.Disabled or self.Caster._UniqueId ~= CasterId then
return
end
local IsValid, RaycastResult = DeserializeRaycastResult(SerializedRaycastResult)

if Player == Owner and IsValid(RaycastResult) and (Code == "Any" or Code == "Humanoid") then
if Player == Owner and IsValid and (Code == "Any" or Code == "Humanoid") then
local Humanoid
if Code == "Humanoid" then
local Model = RaycastResult.Instance:FindFirstAncestorOfClass("Model")
Expand Down Expand Up @@ -432,41 +417,6 @@ end
function ClientCaster:GetOwner()
return self.Owner
end
--[=[
Determines how long the ClientCaster:GetPing() method can yield for before resuming, to protect against potential exploiting.
Default exhaustion time is 1.
@param Time number
]=]
function ClientCaster:SetMaxPingExhaustion(Time)
AssertType(Time, "number", "Unexpected argument #1 to 'ClientCaster.SetMaxPingExhaustion' (%s expected, got %s)")
AssertNaN(Time, "Unexpected argument #1 to 'ClientCaster.SetMaxPingExhaustion' (%s expected, got NaN)")
if Time < 0.1 then
error("The max ping exhaustion time passed to 'ClientCaster.SetMaxPingExhaustion' must be longer than 0.1", 3)
return
end

self._ExhaustionTime = Time
end
--[=[
Returns how long the ClientCaster:GetPing() method can yield before resuming.
@return number
]=]
function ClientCaster:GetMaxPingExhaustion()
return self._ExhaustionTime
end
--[=[
If the ClientCaster object has a set Owner, it will return the ping of that player by calculating delay between client-server.
NOTE This is a yielding function, and it will yield until it gets the players ping.
@return number
@yields
]=]
function ClientCaster:GetPing()
if self.Owner == nil then
return 0
end

return SafeRemoteInvoke(PingRemote, self.Owner, self._ExhaustionTime)
end
--[=[
Sets this ClientCaster's object which it will raycast from to Object.
@param Object Instance
Expand Down
9 changes: 8 additions & 1 deletion testing.project.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,14 @@
},
"ServerScriptService": {
"$className": "ServerScriptService",
"$path": "testing"
"$path": "testing/server"
},
"StarterPlayer": {
"$className": "StarterPlayer",
"StarterPlayerScripts": {
"$className": "StarterPlayerScripts",
"$path": "testing/client"
}
}
}
}
38 changes: 0 additions & 38 deletions testing/Testing.server.luau

This file was deleted.

25 changes: 25 additions & 0 deletions testing/client/Client.client.luau
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local LocalPlayer = Players.LocalPlayer
local PlayerGui = LocalPlayer:WaitForChild("PlayerGui")

local ToggleUI = Instance.new("ScreenGui")

local ToggleButton = Instance.new("TextButton")
ToggleButton.Size = UDim2.new(0, 100, 0, 50)
ToggleButton.Position = UDim2.new(0, 0, 0, 0)
ToggleButton.Text = "Toggle"
ToggleButton.TextColor3 = Color3.new(1, 0, 0)
ToggleButton.TextScaled = true
ToggleButton.Parent = ToggleUI

ToggleUI.Parent = PlayerGui

local Remote = ReplicatedStorage:WaitForChild("RemoteEvent")
local Enabled = false
ToggleButton.MouseButton1Click:Connect(function()
Enabled = not Enabled
ToggleButton.TextColor3 = Enabled and Color3.new(0, 1, 0) or Color3.new(1, 0, 0)
Remote:FireServer()
end)
54 changes: 54 additions & 0 deletions testing/server/Testing.server.luau
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local ClientCast = require(ReplicatedStorage.ClientCast)

local RemoteEvent = Instance.new("RemoteEvent")
RemoteEvent.Parent = ReplicatedStorage

local TestPart = Instance.new("Part")
TestPart.Anchored = true
TestPart.CanCollide = false
TestPart.CFrame = CFrame.new(0, 2, 0)
TestPart.Parent = workspace

for X = -2, 2 do
local Attachment = Instance.new("Attachment")
Attachment.Name = "DmgPoint"
Attachment.Position = Vector3.new(X, 0, 0)
Attachment.Parent = TestPart
end

local Table = {} -- Player = Caster

local function StartCasting(Player)
local CurrentCaster = Table[Player]
if CurrentCaster.Disabled then
CurrentCaster:Start()
else
CurrentCaster:Stop()
end
end

Players.PlayerAdded:Connect(function(Player)
Player.CharacterAdded:Connect(function(Character)
local Humanoid = Character:WaitForChild("Humanoid", 1)

local ClientCaster = ClientCast.new(TestPart, RaycastParams.new())
ClientCaster:SetOwner(Player)
ClientCaster._Debug = true

ClientCaster.HumanoidCollided:Connect(function(_, HitHumanoid)
print("Hit model:" .. HitHumanoid.Parent.Name)
end)

Table[Player] = ClientCaster

Humanoid.Died:Connect(function()
ClientCaster:Destroy()
Table[Player] = nil
end)
end)
end)

RemoteEvent.OnServerEvent:Connect(StartCasting)

0 comments on commit 52789a6

Please sign in to comment.