Skip to content

Commit 2189d8c

Browse files
committed
cut down on network usage && bugfixes
1 parent 1a74e1d commit 2189d8c

File tree

7 files changed

+77
-23
lines changed

7 files changed

+77
-23
lines changed

NetBlox.Common/Version.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ public static class Version
88
{
99
public const int VersionMajor = 16;
1010
public const int VersionMinor = 9;
11-
public const int VersionPatch = 2;
11+
public const int VersionPatch = 3;
1212
}
1313
}

NetBlox/AppManager.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,12 @@ public static async Task<string> DownloadFileAsync(string from, string to)
113113
return path;
114114
using var stream = await HttpClient.GetStreamAsync(from);
115115
using var file = File.OpenWrite(path);
116-
byte[] bytes = new byte[stream.Length];
117-
stream.Read(bytes);
118-
file.Write(bytes);
116+
int b = stream.ReadByte();
117+
while (b != -1)
118+
{
119+
file.Write([(byte)b]);
120+
b = stream.ReadByte();
121+
}
119122
file.Flush();
120123
return Path.GetFullPath(path).Replace('\\', '/');
121124
}

NetBlox/Instances/Character.cs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -75,50 +75,55 @@ public override void Process()
7575

7676
if (IsLocalPlayer && (GameManager.NetworkManager.IsClient && !GameManager.NetworkManager.IsServer) && Health > 0)
7777
{
78-
bool dot = false;
78+
bool poschg = false;
79+
bool rotchg = false;
7980

8081
if (Raylib.IsKeyDown(KeyboardKey.Space))
8182
{
8283
Position = Position + new Vector3(0, 0.1f * WalkSpeed / 6, 0);
83-
dot = true;
84+
poschg = true;
8485
}
8586
if (Raylib.IsKeyDown(KeyboardKey.LeftShift))
8687
{
8788
Position = Position + new Vector3(0, 0.1f * -WalkSpeed / 6, 0);
88-
dot = true;
89+
poschg = true;
8990
}
9091
if (Raylib.IsKeyDown(KeyboardKey.Q))
9192
{
9293
Rotation += new Vector3(0, -0.1f * -WalkSpeed, 0);
93-
dot = true;
94+
rotchg = true;
9495
}
9596
if (Raylib.IsKeyDown(KeyboardKey.E))
9697
{
9798
Rotation += new Vector3(0, 0.1f * -WalkSpeed, 0);
98-
dot = true;
99+
rotchg = true;
99100
}
100101
if (Raylib.IsKeyDown(KeyboardKey.W))
101102
{
102103
Position = Position + new Vector3(0.1f * WalkSpeed / 6 * MathF.Cos(angle), 0, 0.1f * WalkSpeed / 6 * MathF.Sin(angle));
103-
dot = true;
104+
poschg = true;
104105
}
105106
if (Raylib.IsKeyDown(KeyboardKey.A))
106107
{
107108
Position = Position + new Vector3(0.1f * WalkSpeed / 6 * MathF.Cos(angle - 1.5708f), 0, 0.1f * WalkSpeed / 6 * MathF.Sin(angle - 1.5708f));
108-
dot = true;
109+
poschg = true;
109110
}
110111
if (Raylib.IsKeyDown(KeyboardKey.S))
111112
{
112113
Position = Position + new Vector3(-0.1f * WalkSpeed / 6 * MathF.Cos(angle), 0, -0.1f * WalkSpeed / 6 * MathF.Sin(angle));
113-
dot = true;
114+
poschg = true;
114115
}
115116
if (Raylib.IsKeyDown(KeyboardKey.D))
116117
{
117118
Position = Position + new Vector3(-0.1f * WalkSpeed / 6 * MathF.Cos(angle - 1.5708f), 0, -0.1f * WalkSpeed / 6 * MathF.Sin(angle - 1.5708f));
118-
dot = true;
119+
poschg = true;
119120
}
120121

121-
if (dot)
122+
if (poschg && !rotchg)
123+
ReplicateProperties(["Position"], false);
124+
if (!poschg && rotchg)
125+
ReplicateProperties(["Rotation"], false);
126+
if (poschg && rotchg)
122127
ReplicateProperties(["Position", "Rotation"], false);
123128
}
124129

NetBlox/Instances/DataModel.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ public Instance[] GetObjects(string url)
7878
RbxlParser.Load(url, ins);
7979
Instance[] chlidren = ins.GetChildren();
8080
ins.ClearAllChildren();
81+
ins.Destroy();
8182
return chlidren;
8283
}
8384
[Lua([Security.Capability.CoreSecurity])]

NetBlox/NetworkManager.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -654,7 +654,7 @@ public void RequestOwnerReplication(Instance ins, PropertyInfo[] props)
654654

655655
bw.Write(ins.UniqueID.ToByteArray());
656656
bw.Write(ins.ParentID.ToByteArray());
657-
bw.Write(ins.ClassName);
657+
bw.Write(""); // we dont actually
658658

659659
var c = 0;
660660

@@ -666,6 +666,8 @@ public void RequestOwnerReplication(Instance ins, PropertyInfo[] props)
666666
continue;
667667
if (prop.PropertyType == LST)
668668
continue;
669+
if (!prop.CanWrite)
670+
continue;
669671
if (!SerializationManager.NetworkSerializers.TryGetValue(prop.PropertyType.FullName ?? "", out var x))
670672
continue;
671673

@@ -724,6 +726,8 @@ private void PerformReplicationNew(Instance ins, PropertyInfo[] props, RemoteCli
724726
continue;
725727
if (prop.PropertyType == LST)
726728
continue;
729+
if (!prop.CanWrite)
730+
continue;
727731
if (!SerializationManager.NetworkSerializers.TryGetValue(prop.PropertyType.FullName ?? "", out var x))
728732
continue;
729733

NetBlox/RbxlParser.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@ public static void Load(string url, Instance dm)
2020
var xml = new XmlDocument();
2121
var ic = CultureInfo.InvariantCulture;
2222
var slist = new SortedSet<string>();
23-
xml.LoadXml(File.ReadAllText(AppManager.ResolveUrlAsync(url, true).WaitAndGetResult()));
23+
var raw = File.ReadAllText(AppManager.ResolveUrlAsync(url, true).WaitAndGetResult());
24+
xml.LoadXml(raw);
25+
26+
var ogr = dm.GameManager.IsRunning;
27+
dm.GameManager.IsRunning = false; // is this bad idea?
2428

2529
void LoadChildren(Instance inst, XmlNode node)
2630
{
@@ -131,6 +135,8 @@ void LoadChildren(Instance inst, XmlNode node)
131135
for (int i = 0; i < slist.Count; i++)
132136
LogManager.LogWarn(arr[i]);
133137
}
138+
139+
dm.GameManager.IsRunning = ogr;
134140
}
135141
}
136142
}

UniversalServer/Program.cs

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,49 @@ public static void Main(string[] args)
3535
GameName = "NetBlox Server"
3636
}, args, (x) =>
3737
{
38-
x.CurrentRoot.Clear();
39-
x.CurrentIdentity.PlaceName = "Welcoming";
40-
x.CurrentIdentity.UniverseName = "Welcoming";
41-
x.CurrentIdentity.MaxPlayerCount = 8;
42-
x.CurrentIdentity.Author = "Roblox original places";
43-
x.CurrentRoot.Name = x.CurrentIdentity.PlaceName;
44-
RbxlParser.Load("rbxasset://places/Crossroads.rbxl", x.CurrentRoot);
4538
Task.Run(x.NetworkManager.StartServer);
39+
Task.Run(() =>
40+
{
41+
Console.WriteLine("NetBlox Server commmand line:");
42+
while (!x.ShuttingDown)
43+
{
44+
try
45+
{
46+
47+
Console.Write(">> ");
48+
string cmd = Console.ReadLine();
49+
string[] words = cmd.Split(' ');
50+
if (words.Length == 0) continue;
51+
52+
switch (words[0])
53+
{
54+
case "load":
55+
try
56+
{
57+
x.CurrentRoot.Clear();
58+
x.CurrentIdentity.PlaceName = "Place downloaded from Web";
59+
x.CurrentIdentity.UniverseName = "NetBlox";
60+
x.CurrentIdentity.MaxPlayerCount = 16;
61+
x.CurrentIdentity.Author = "NetBlox";
62+
x.CurrentRoot.Name = x.CurrentIdentity.PlaceName;
63+
x.CurrentRoot.Load(words[1]);
64+
}
65+
catch (Exception ex)
66+
{
67+
Console.WriteLine("Could not load the place: " + ex.Message);
68+
}
69+
break;
70+
case "lua":
71+
TaskScheduler.ScheduleScript(x, cmd[4..], 8, null);
72+
break;
73+
}
74+
}
75+
catch (Exception ex)
76+
{
77+
Console.WriteLine("Could not execute requested command: " + ex.Message);
78+
}
79+
}
80+
});
4681
});
4782
g.MainManager = true;
4883
AppManager.SetRenderTarget(g);

0 commit comments

Comments
 (0)