|
1 | 1 | -- Compiled with https://roblox-ts.github.io v0.2.14
|
2 |
| --- August 6, 2019, 7:32 PM New Zealand Standard Time |
| 2 | +-- August 10, 2019, 6:58 PM New Zealand Standard Time |
3 | 3 |
|
4 | 4 | local TS = require(script.Parent.vendor.RuntimeLib);
|
5 | 5 | local exports = {};
|
| 6 | +local NetServerEvent; |
6 | 7 | local _0 = TS.import(script.Parent, "internal");
|
7 |
| -local findOrCreateRemote, IS_CLIENT = _0.findOrCreateRemote, _0.IS_CLIENT; |
| 8 | +local findOrCreateRemote, IS_CLIENT, t_assert = _0.findOrCreateRemote, _0.IS_CLIENT, _0.t_assert; |
8 | 9 | local Players = game:GetService("Players");
|
9 |
| -local NetServerEvent; |
10 | 10 | do
|
11 | 11 | NetServerEvent = setmetatable({}, {
|
12 | 12 | __tostring = function() return "NetServerEvent" end;
|
|
17 | 17 | self:constructor(...);
|
18 | 18 | return self;
|
19 | 19 | end;
|
20 |
| - function NetServerEvent:constructor(name) |
| 20 | + function NetServerEvent:constructor(name, ...) |
| 21 | + local recievedPropTypes = { ... }; |
21 | 22 | self.instance = findOrCreateRemote("RemoteEvent", name);
|
22 | 23 | assert(not IS_CLIENT, "Cannot create a Net.ServerEvent on the Client!");
|
| 24 | + if #recievedPropTypes > 0 then |
| 25 | + self.propTypes = recievedPropTypes; |
| 26 | + end; |
| 27 | + end; |
| 28 | + function NetServerEvent:WithStrictCall(...) |
| 29 | + local callPropTypes = { ... }; |
| 30 | + self.callTypes = callPropTypes; |
| 31 | + return self; |
23 | 32 | end;
|
24 |
| - function NetServerEvent:getInstance() |
| 33 | + function NetServerEvent:GetInstance() |
25 | 34 | return self.instance;
|
26 | 35 | end;
|
27 |
| - function NetServerEvent:getEvent() |
| 36 | + function NetServerEvent:GetEvent() |
28 | 37 | return self.instance.OnServerEvent;
|
29 | 38 | end;
|
30 | 39 | function NetServerEvent:Connect(callback)
|
31 |
| - return self:getEvent():Connect(callback); |
| 40 | + if self.propTypes ~= nil then |
| 41 | + return self:GetEvent():Connect(function(sourcePlayer, ...) |
| 42 | + local args = { ... }; |
| 43 | + if t_assert(self.propTypes, args) then |
| 44 | + callback(sourcePlayer, unpack(args)); |
| 45 | + end; |
| 46 | + end); |
| 47 | + else |
| 48 | + return self:GetEvent():Connect(callback); |
| 49 | + end; |
32 | 50 | end;
|
33 | 51 | function NetServerEvent:SendToAllPlayers(...)
|
34 | 52 | local args = { ... };
|
35 |
| - self.instance:FireAllClients(unpack(args)); |
| 53 | + if self.callTypes ~= nil then |
| 54 | + if not t_assert(self.callTypes, args) then |
| 55 | + return nil; |
| 56 | + end; |
| 57 | + end; |
| 58 | + self.instance:FireAllClients(unpack((args))); |
36 | 59 | end;
|
37 | 60 | function NetServerEvent:SendToAllPlayersExcept(blacklist, ...)
|
38 | 61 | local args = { ... };
|
| 62 | + if self.callTypes ~= nil then |
| 63 | + if not t_assert(self.callTypes, args) then |
| 64 | + return nil; |
| 65 | + end; |
| 66 | + end; |
39 | 67 | if (typeof(blacklist) == "Instance") then
|
40 | 68 | local otherPlayers = TS.array_filter(Players:GetPlayers(), function(p)
|
41 | 69 | return p ~= blacklist;
|
42 | 70 | end);
|
43 | 71 | for _1 = 1, #otherPlayers do
|
44 | 72 | local player = otherPlayers[_1];
|
45 |
| - self.instance:FireClient(player, unpack(args)); |
| 73 | + self.instance:FireClient(player, unpack((args))); |
46 | 74 | end;
|
47 | 75 | elseif (typeof(blacklist) == "table") then
|
48 | 76 | local _1 = Players:GetPlayers();
|
49 | 77 | for _2 = 1, #_1 do
|
50 | 78 | local player = _1[_2];
|
51 | 79 | if TS.array_indexOf(blacklist, player) == -1 then
|
52 |
| - self.instance:FireClient(player, unpack(args)); |
| 80 | + self.instance:FireClient(player, unpack((args))); |
53 | 81 | end;
|
54 | 82 | end;
|
55 | 83 | end;
|
56 | 84 | end;
|
57 | 85 | function NetServerEvent:SendToPlayer(player, ...)
|
58 | 86 | local args = { ... };
|
59 |
| - self.instance:FireClient(player, unpack(args)); |
| 87 | + if self.callTypes ~= nil then |
| 88 | + if not t_assert(self.callTypes, args) then |
| 89 | + return nil; |
| 90 | + end; |
| 91 | + end; |
| 92 | + self.instance:FireClient(player, unpack((args))); |
60 | 93 | end;
|
61 | 94 | function NetServerEvent:SendToPlayers(players, ...)
|
62 | 95 | local args = { ... };
|
| 96 | + if self.callTypes ~= nil then |
| 97 | + if not t_assert(self.callTypes, args) then |
| 98 | + return nil; |
| 99 | + end; |
| 100 | + end; |
63 | 101 | for _1 = 1, #players do
|
64 | 102 | local player = players[_1];
|
65 |
| - self:SendToPlayer(player, unpack(args)); |
| 103 | + self:SendToPlayer(player, unpack((args))); |
66 | 104 | end;
|
67 | 105 | end;
|
68 | 106 | end;
|
|
0 commit comments