Server refactored and *working*, client needs refactored to work

This commit is contained in:
2024-04-21 18:12:51 -04:00
parent 65e4b7eef2
commit e3104595d8
10 changed files with 214 additions and 141 deletions

File diff suppressed because one or more lines are too long

View File

@@ -1,84 +0,0 @@
--!optimize 2
--!native
--!strict
type UDP = UnreliableRemoteEvent
type CharacterSharedFolder = Folder
local Players = game:GetService("Players")
local Dir = script.Parent
local Character = Dir.Parent
local preprocessor = {}
--Create the character shared directory here
local CharacterShared = Instance.new("Folder")
CharacterShared.Name = "shared"
CharacterShared.Parent = Character
function preprocessor.CharacterShared(): Instance
return CharacterShared :: CharacterSharedFolder
end
_G.include = function(this: LuaSourceContainer, FunName: string, ...)
--its not extremely necessary to have this security on the server-side
if this:IsDescendantOf(script) then --getfenv is being removed
local switch = preprocessor[FunName]
return type(switch) == "function" and switch(...) or switch
else
warn(`Preprocessor append failed "{FunName}"`, debug.traceback())
return nil
end
end
local Shadows = require(script:WaitForChild("Shadows"))
local SpineModule = require(script:WaitForChild("SpineKinematics"))
local FlashlightModule = require(script:WaitForChild("Flashlight"))
local ActionsModule = require(script:WaitForChild("Actions"))
local Head = Character:WaitForChild("Head")
local UpperTorso = Character:WaitForChild("UpperTorso")
local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")
local LocalPlayer = Players:GetPlayerFromCharacter(Character)
local CharacterShadows = Shadows.constructor(Character)
local Spine = SpineModule.constructor(Head, UpperTorso)
local Flashlight = FlashlightModule.constructor(LocalPlayer, HumanoidRootPart)
local Actions = ActionsModule.constructor(LocalPlayer, HumanoidRootPart)
local FlashlightDebounce = false
CharacterShadows:off() --I plan having 2 player support and characters block a ton of light
Character.DescendantAdded:Connect(function(Instance)
task.wait() --Wait for the instance to properly replicate?
CharacterShadows:PartToggle(Instance, false)
end)
local FlashlightCooldown = .10
Actions:Add(Enum.KeyCode.F, function(_KeyPressed)
if not FlashlightDebounce then
Flashlight:Toggle()
FlashlightDebounce = true
task.wait(FlashlightCooldown)
FlashlightDebounce = false
end
end);
Spine.Remote.OnServerEvent:Connect(function(Messenger: Player, CameraPosition: CFrame, IsFirstPerson: boolean)
if Messenger.UserId == LocalPlayer.UserId then
if SpineModule.Enabled then
Spine:Move(CameraPosition, IsFirstPerson)
else
--reset
print("TODO reached -", script.Name..".lua")
end
else
Messenger:Kick(`"{Messenger.Name}", {Messenger.UserId} r="{Spine.Remote.Name}", 1="{tostring(CameraPosition)}", 2="{tostring(IsFirstPerson)}"`)
end
end)
_G.include = nil

View File

@@ -6,6 +6,7 @@ type EventFunction = (KeyPressed: Enum.KeyCode) -> ()
type ActionsTCP = RBXScriptConnection type ActionsTCP = RBXScriptConnection
type LocalPlayer = Player type LocalPlayer = Player
type TCP = RemoteEvent type TCP = RemoteEvent
type CharacterShared = Folder
type EventsDict = { type EventsDict = {
[Enum.KeyCode]: EventFunction [Enum.KeyCode]: EventFunction
@@ -20,31 +21,26 @@ type Impl_Constructor = {
Remove: (self: ClassConstructor, Key: Enum.KeyCode) -> () Remove: (self: ClassConstructor, Key: Enum.KeyCode) -> ()
} & Impl_Static_Props } & Impl_Static_Props
type Constructor_Fun = (LocalPlayer: LocalPlayer) -> ClassConstructor type Constructor_Fun = (CharacterShared: CharacterShared, LocalPlayer: LocalPlayer) -> ClassConstructor
type Impl_Static_Props = {} type Impl_Static_Props = {}
type Constructor_Return_Props = { type Constructor_Return_Props = {
Events: EventsDict, Events: EventsDict,
CurrentActionsTCP_Event: ActionsTCP? CurrentActionsTCP_Event: ActionsTCP
} }
export type ActionsConstructor = ClassConstructor
local Actions = {} :: Impl_Constructor local Actions = {} :: Impl_Constructor
Actions.__index = Actions Actions.__index = Actions
local CharacterShared = _G.include(script, "CharacterShared") function Actions.constructor(CharacterShared, LocalPlayer)
local Events: EventsDict = {}
local Remote = Instance.new("RemoteEvent") :: TCP local Remote = Instance.new("RemoteEvent") :: TCP
Remote.Name = "Actions" Remote.Name = "Actions"
Remote.Parent = CharacterShared Remote.Parent = CharacterShared
local ActionsTCP_Event: ActionsTCP? local ActionsTCP_Event = Remote.OnServerEvent:Connect(function(Messenger: Player, Key: Enum.KeyCode)
function Actions.constructor(LocalPlayer: LocalPlayer)
local Events: EventsDict = {}
if ActionsTCP_Event then
warn("[Server Actions]: TCP event was already created, duplicating...", debug.traceback())
end
ActionsTCP_Event = Remote.OnServerEvent:Connect(function(Messenger: Player, Key: Enum.KeyCode)
if Messenger.UserId == LocalPlayer.UserId then if Messenger.UserId == LocalPlayer.UserId then
if typeof(Key) == "EnumItem" then if typeof(Key) == "EnumItem" then
local switch = Events[Key] local switch = Events[Key]
@@ -65,15 +61,15 @@ function Actions.constructor(LocalPlayer: LocalPlayer)
}, Actions) }, Actions)
end end
function Actions:Add(Key: Enum.KeyCode, f: EventFunction) function Actions:Add(Key, f)
self.Events[Key] = f self.Events[Key] = f
end end
function Actions:Remove(Key: Enum.KeyCode) function Actions:Remove(Key)
self.Events[Key] = nil self.Events[Key] = nil
if not next(self.Events) then if not next(self.Events) then
(self.CurrentActionsTCP_Event :: ActionsTCP):Disconnect() self.CurrentActionsTCP_Event:Disconnect()
print("[Server Actions]: ") print("[Server Actions]: ")
end end
end end

View File

@@ -7,6 +7,8 @@ type FlashlightUDP = RBXScriptConnection
type LocalPlayer = Player type LocalPlayer = Player
type HumanoidRootPart = BasePart type HumanoidRootPart = BasePart
type EulerXYZ_struct = {number} type EulerXYZ_struct = {number}
type rbxassetid = string
type CharacterShared = Folder
type ClassConstructor = typeof(setmetatable({} :: Constructor_Return_Props, {} :: Impl_Constructor)) type ClassConstructor = typeof(setmetatable({} :: Constructor_Return_Props, {} :: Impl_Constructor))
type Impl_Constructor = { type Impl_Constructor = {
@@ -18,10 +20,11 @@ type Impl_Constructor = {
Toggle: (self: ClassConstructor) -> () Toggle: (self: ClassConstructor) -> ()
} & Impl_Static_Props } & Impl_Static_Props
type Constructor_Fun = (LocalPlayer: LocalPlayer, HumanoidRootPart: HumanoidRootPart) -> ClassConstructor type Constructor_Fun = (CharacterShared: CharacterShared, LocalPlayer: LocalPlayer, HumanoidRootPart: HumanoidRootPart) -> ClassConstructor
type Impl_Static_Props = { type Impl_Static_Props = {
Enabled: boolean, Enabled: boolean,
HeadHeight: number HeadHeight: number,
ToggleSound: rbxassetid
} }
type Constructor_Return_Props = { type Constructor_Return_Props = {
FlashlightPart: Part, FlashlightPart: Part,
@@ -29,19 +32,14 @@ type Constructor_Return_Props = {
ToggleSound: Sound ToggleSound: Sound
} }
export type FlashlightConstructor = ClassConstructor
local Flashlight = {} :: Impl_Constructor local Flashlight = {} :: Impl_Constructor
Flashlight.__index = Flashlight Flashlight.__index = Flashlight
Flashlight.Enabled = false Flashlight.Enabled = false
Flashlight.HeadHeight = 1 Flashlight.HeadHeight = 1
Flashlight.ToggleSound = "rbxassetid://16454678462"
local CharacterShared = _G.include(script, "CharacterShared")
local Flashlight_UDP = Instance.new("UnreliableRemoteEvent") :: UDP
Flashlight_UDP.Name = "Flashlight"
Flashlight_UDP.Parent = CharacterShared
local FlashlightUDP_Event: FlashlightUDP?
local function FlashlightPart(HumanoidRootPart: HumanoidRootPart): (Part, SpotLight, Sound) local function FlashlightPart(HumanoidRootPart: HumanoidRootPart): (Part, SpotLight, Sound)
local FlashlightPart = Instance.new("Part") :: Part local FlashlightPart = Instance.new("Part") :: Part
@@ -63,7 +61,7 @@ local function FlashlightPart(HumanoidRootPart: HumanoidRootPart): (Part, SpotLi
local ToggleSound = Instance.new("Sound") :: Sound local ToggleSound = Instance.new("Sound") :: Sound
ToggleSound.Name = "Flashlight" ToggleSound.Name = "Flashlight"
ToggleSound.SoundId = "rbxassetid://16454678462" ToggleSound.SoundId = Flashlight.ToggleSound
ToggleSound.Volume = .5 ToggleSound.Volume = .5
ToggleSound.Parent = FlashlightPart ToggleSound.Parent = FlashlightPart
@@ -72,13 +70,14 @@ local function FlashlightPart(HumanoidRootPart: HumanoidRootPart): (Part, SpotLi
return FlashlightPart, SpotLight, ToggleSound return FlashlightPart, SpotLight, ToggleSound
end end
function Flashlight.constructor(LocalPlayer: LocalPlayer, HumanoidRootPart: HumanoidRootPart) function Flashlight.constructor(CharacterShared, LocalPlayer, HumanoidRootPart)
local FlashlightPart, SpotLight, ToggleSound = FlashlightPart(HumanoidRootPart) local FlashlightPart, SpotLight, ToggleSound = FlashlightPart(HumanoidRootPart)
if FlashlightUDP_Event then local Flashlight_UDP = Instance.new("UnreliableRemoteEvent") :: UDP
warn("[Server Flashlight]: UDP event was already created, duplicating...", debug.traceback()) Flashlight_UDP.Name = "Flashlight"
end Flashlight_UDP.Parent = CharacterShared
FlashlightUDP_Event = Flashlight_UDP.OnServerEvent:Connect(function(Messenger: Player, CameraEuler: EulerXYZ_struct)
Flashlight_UDP.OnServerEvent:Connect(function(Messenger: Player, CameraEuler: EulerXYZ_struct)
if Messenger.UserId == LocalPlayer.UserId then if Messenger.UserId == LocalPlayer.UserId then
if CameraEuler[4] and CameraEuler[4] == 3 then if CameraEuler[4] and CameraEuler[4] == 3 then
local RootPartCFrame = HumanoidRootPart.CFrame local RootPartCFrame = HumanoidRootPart.CFrame

View File

@@ -4,12 +4,14 @@
--This really should be only client --This really should be only client
type Character = Model
type ClassConstructor = typeof(setmetatable({} :: Constructor_Return_Props, {} :: Impl_Constructor)) type ClassConstructor = typeof(setmetatable({} :: Constructor_Return_Props, {} :: Impl_Constructor))
type Impl_Constructor = { type Impl_Constructor = {
__index: Impl_Constructor, __index: Impl_Constructor,
constructor: Constructor_Fun, constructor: Constructor_Fun,
--Class functions --Class functions
PartToggle: (self: ClassConstructor, Instance: BasePart, CastingShadow: boolean) -> (), PartToggle: (self: ClassConstructor, Instance: Instance, CastingShadow: boolean) -> (),
Remove: (self: ClassConstructor, Key: Enum.KeyCode) -> (), Remove: (self: ClassConstructor, Key: Enum.KeyCode) -> (),
on: (self: ClassConstructor) -> (), on: (self: ClassConstructor) -> (),
off: (self: ClassConstructor) -> () off: (self: ClassConstructor) -> ()
@@ -20,27 +22,28 @@ type Constructor_Return_Props = {
Character: Character Character: Character
} }
export type ShadowsConstructor = ClassConstructor
local Shadows = {} :: Impl_Constructor local Shadows = {} :: Impl_Constructor
Shadows.__index = Shadows Shadows.__index = Shadows
type Character = Model function Shadows.constructor(Character)
function Shadows.constructor(Character: Character)
return setmetatable({ return setmetatable({
Character = Character Character = Character
}, Shadows) }, Shadows)
end end
function Shadows:PartToggle(Instance: BasePart, CastingShadow: boolean) function Shadows:PartToggle(Instance, CastingShadow)
if Instance:IsA("BasePart") then --not 100%, but im sure types are only in effect on the editor side if Instance:IsA("BasePart") then
Instance.CastShadow = CastingShadow Instance.CastShadow = CastingShadow
end end
end end
local function CharacterShadows(self: ClassConstructor, enabled: boolean) local function CharacterShadows(self: ClassConstructor, enabled: boolean)
local CharacterDescendants = self.Character:GetDescendants() local CharacterDescendants = self.Character:GetDescendants()
for i = 1, #CharacterDescendants do
self:PartToggle(CharacterDescendants[i] :: BasePart, enabled) for n: number = 1, #CharacterDescendants do
self:PartToggle(CharacterDescendants[n] :: BasePart, enabled)
end end
end end

View File

@@ -38,6 +38,8 @@ type Constructor_Return_Props = {
WaistC0: WaistC0 WaistC0: WaistC0
} }
export type SpineKinematicsConstructor = ClassConstructor
local Spine = {} :: Impl_Constructor local Spine = {} :: Impl_Constructor
Spine.__index = Spine Spine.__index = Spine
@@ -48,7 +50,7 @@ local Remote = Instance.new("UnreliableRemoteEvent") :: UDP
Remote.Name = "SpineStream" Remote.Name = "SpineStream"
Remote.Parent = _G.include(script, "CharacterShared") Remote.Parent = _G.include(script, "CharacterShared")
function Spine.constructor(Head: Head, UpperTorso: UpperTorso) function Spine.constructor(Head, UpperTorso)
local self = {} local self = {}
self.Head = Head self.Head = Head
self.UpperTorso = UpperTorso self.UpperTorso = UpperTorso
@@ -57,6 +59,7 @@ function Spine.constructor(Head: Head, UpperTorso: UpperTorso)
self.Remote = Remote self.Remote = Remote
self.NeckC0 = (self.Neck :: Motor6D).C0 self.NeckC0 = (self.Neck :: Motor6D).C0
self.WaistC0 = (self.Neck :: Motor6D).C0 self.WaistC0 = (self.Neck :: Motor6D).C0
return setmetatable(self, Spine) return setmetatable(self, Spine)
end end
@@ -92,7 +95,7 @@ local function SpineMovement(self: ClassConstructor, CameraCFrame: CFrame, IsFir
} }
end end
function Spine:Move(CameraCFrame: CFrame, IsFirstPerson: boolean) function Spine:Move(CameraCFrame, IsFirstPerson)
local SpineIK = SpineMovement(self, CameraCFrame, IsFirstPerson) local SpineIK = SpineMovement(self, CameraCFrame, IsFirstPerson)
self.Neck.C0 = self.Neck.C0:Lerp(self.NeckC0*SpineIK.Neck, .9) self.Neck.C0 = self.Neck.C0:Lerp(self.NeckC0*SpineIK.Neck, .9)

View File

@@ -0,0 +1,102 @@
--!optimize 2
--!native
--!strict
local Shadows = require(script:WaitForChild("Shadows"))
local SpineModule = require(script:WaitForChild("SpineKinematics"))
local FlashlightModule = require(script:WaitForChild("Flashlight"))
local ActionsModule = require(script:WaitForChild("Actions"))
type UDP = UnreliableRemoteEvent
type CharacterSharedFolder = Folder
type Character = Model
type HumanoidRootPart = BasePart
type ClassConstructor = typeof(setmetatable({} :: Constructor_Return_Props, {} :: Impl_Constructor))
type Impl_Constructor = {
__index: Impl_Constructor,
constructor: Constructor_Fun,
--Class functions
Enable: (self: ClassConstructor) -> (),
Disable: (self: ClassConstructor) -> ()
} & Impl_Static_Props
type Constructor_Fun = (Character: Character) -> ClassConstructor
type Impl_Static_Props = {
FlashlightDebounce: boolean,
FlashlightCooldown: number,
KeyBinds: {
Flashlight: Enum.KeyCode
}
}
type Constructor_Return_Props = {
CharacterShared: CharacterSharedFolder,
CharacterShadows: Shadows.ShadowsConstructor,
Spine: SpineModule.SpineKinematicsConstructor,
Flashlight: FlashlightModule.FlashlightConstructor,
Actions: ActionsModule.ActionsConstructor
}
local Character = {} :: Impl_Constructor
Character.__index = Character
local Players = game:GetService("Players")
Character.FlashlightDebounce = false
Character.FlashlightCooldown = .10
Character.KeyBinds = {
Flashlight = Enum.KeyCode.F
}
function Character.constructor(CharacterModel)
local Player = Players:GetPlayerFromCharacter(CharacterModel)
local self = {}
self.CharacterShared = Instance.new("Folder")
self.CharacterShared.Name = "shared"
self.CharacterShared.Parent = CharacterModel
local Head = CharacterModel:WaitForChild("Head") :: BasePart
local UpperTorso = CharacterModel:WaitForChild("UpperTorso") :: BasePart
local HumanoidRootPart = CharacterModel:WaitForChild("HumanoidRootPart") :: HumanoidRootPart
self.CharacterShadows = Shadows.constructor(CharacterModel)
self.Spine = SpineModule.constructor(Head, UpperTorso)
self.Flashlight = FlashlightModule.constructor(self.CharacterShared, Player, HumanoidRootPart)
self.Actions = ActionsModule.constructor(self.CharacterShared, Player)
self.CharacterShadows:off() --I plan having 2+ player support and characters block a ton of light
CharacterModel.DescendantAdded:Connect(function(Instance)
task.wait() --Wait for the instance to properly replicate...
self.CharacterShadows:PartToggle(Instance, false)
end)
self.Actions:Add(Character.KeyBinds.Flashlight, function(_KeyPressed)
if not Character.FlashlightDebounce then
self.Flashlight:Toggle()
Character.FlashlightDebounce = true
task.wait(Character.FlashlightCooldown)
Character.FlashlightDebounce = false
end
end)
self.Spine.Remote.OnServerEvent:Connect(function(Messenger: Player, CameraPosition: CFrame, IsFirstPerson: boolean)
if Messenger.UserId == Player.UserId then
if SpineModule.Enabled then
self.Spine:Move(CameraPosition, IsFirstPerson)
else
--reset
print("TODO reached -", script.Name..".lua")
end
else
Messenger:Kick(`"{Messenger.Name}", {Messenger.UserId} r="{self.Spine.Remote.Name}", 1="{tostring(CameraPosition)}", 2="{tostring(IsFirstPerson)}"`)
end
end)
return setmetatable(self, Character)
end
return Character

View File

@@ -0,0 +1,15 @@
--!optimize 2
--!native
--!strict
type Users = {
Admin: {number},
Banned: {number}
}
local Users = {
Admin = {},
Banned = {}
}
return Users

View File

@@ -0,0 +1,40 @@
--!optimize 2
--!native
--!strict
type Character = Model
local Players = game:GetService("Players")
local Users = require(script:WaitForChild("Users"))
local CharacterModule = require(script:WaitForChild("Character"))
local function LoadCharacter(Player: Player)
CharacterModule.constructor(Player.Character or Player.CharacterAdded:Wait())
Player.CharacterAdded:Connect(CharacterModule.constructor)
end
local function AdminUser(Player: Player)
print(`[Admin] "{Player.Name}" | {tostring(Player.UserId)} has logged`)
Player.Chatted:Connect(function(Message: string, _: Player?)
end)
end
return Players.PlayerAdded:Connect(function(Player: Player)
for n: number = 1, #Users.Banned do
if Player.UserId ~= Users.Banned[n] then
for n2: number = 1, #Users.Admin do
if Player.UserId == Users.Admin[n2] then
AdminUser(Player)
break
end
end
LoadCharacter(Player)
else
Player:Kick()
end
end
end)

View File

@@ -2,25 +2,24 @@
--!native --!native
--!strict --!strict
local ShowEditorEntities = game:GetService("RunService"):IsServer() local ShowEditorEntities = game:GetService("RunService"):IsStudio()
local Storage = game:GetService("ReplicatedStorage") local Storage = game:GetService("ReplicatedStorage")
local Enums = require(Storage:WaitForChild("Enums"))
local Elevators = script:WaitForChild("Elevators")
local Maps = script:WaitForChild("Map")
local Interactions = Maps:WaitForChild("Interactions")
local LightSwitches = require(Interactions:WaitForChild("LightSwitches"))
local Otis1960_Module = require(Elevators:WaitForChild("Otis1960"))
local _PlayerAdded = require(script:WaitForChild("PlayerAdded"))
local TagsModule = require(script:WaitForChild("Tags")) local TagsModule = require(script:WaitForChild("Tags"))
local HideEditorEntities = require(script:WaitForChild("EditorEntities")) local HideEditorEntities = require(script:WaitForChild("EditorEntities"))
local Lighting_Stuff = require(script:WaitForChild("Lighting")) local Lighting_Stuff = require(script:WaitForChild("Lighting"))
local Workspace_Stuff = require(script:WaitForChild("Workspace")) local Workspace_Stuff = require(script:WaitForChild("Workspace"))
local StarterPlayer_Stuff = require(script:WaitForChild("StarterPlayer")) local StarterPlayer_Stuff = require(script:WaitForChild("StarterPlayer"))
local Elevators = script:WaitForChild("Elevators")
local Maps = script:WaitForChild("Map")
local Interactions = Maps:WaitForChild("Interactions")
local Enums = require(Storage:WaitForChild("Enums"))
local LightSwitches = require(Interactions:WaitForChild("LightSwitches"))
local Otis1960_Module = require(Elevators:WaitForChild("Otis1960"))
local TagsConstructor = TagsModule.constructor() local TagsConstructor = TagsModule.constructor()
print("[DEBUG] Tags=", TagsConstructor.__export) print("[DEBUG] Tags=", TagsConstructor.__export)