Skip to content

Commit da83ef4

Browse files
committed
Mod updates
1 parent 15f84a7 commit da83ef4

7 files changed

Lines changed: 52 additions & 137 deletions

File tree

‎Torch.Mod/Messages/JoinServerMessage.cs‎

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Text;
44
using ProtoBuf;
55
using Sandbox.ModAPI;
6+
using VRage.Utils;
67

78
namespace Torch.Mod.Messages
89
{
@@ -32,10 +33,8 @@ public JoinServerMessage(string address, int delay)
3233

3334
public override void ProcessClient()
3435
{
35-
if (TorchModCore.Debug)
36-
{
37-
MyAPIGateway.Utilities.ShowMessage("Torch", $"Joining server {Address} with delay {Delay}");
38-
}
36+
37+
MyLog.Default.WriteLineAndConsole($"Torch: Joining server {Address} with delay {Delay}");
3938

4039
if (Delay <= 0)
4140
{
@@ -44,14 +43,14 @@ public override void ProcessClient()
4443
}
4544

4645
MyAPIGateway.Parallel.StartBackground(() =>
47-
{
48-
MyAPIGateway.Parallel.Sleep(Delay);
49-
MyAPIGateway.Multiplayer.JoinServer(Address);
50-
});
46+
{
47+
MyAPIGateway.Parallel.Sleep(Delay);
48+
MyAPIGateway.Multiplayer.JoinServer(Address);
49+
});
5150
}
5251

5352
public override void ProcessServer()
5453
{
5554
}
5655
}
57-
}
56+
}

‎Torch.Mod/Messages/MessageBase.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,4 @@ public enum MessageTarget
5252
/// </summary>
5353
AllExcept,
5454
}
55-
}
55+
}

‎Torch.Mod/Messages/NotificationMessage.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,4 @@ public override void ProcessServer()
3636
throw new Exception();
3737
}
3838
}
39-
}
39+
}

‎Torch.Mod/Messages/ShowDebugShape.cs‎

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using Sandbox.Game.Entities;
44
using Sandbox.Game.World;
55
using Sandbox.ModAPI;
6+
using System;
67
using System.Collections.Generic;
78
using VRage.Game;
89
using VRage.Game.Entity;
@@ -52,20 +53,18 @@ public override void ProcessClient()
5253
if (remove)
5354
{
5455
clear(uniqueName);
55-
return;
5656
}
5757
else if (removeAll)
5858
{
5959
clearAll();
60-
return;
6160
}
6261

6362
//MyAPIGateway.Utilities.ShowMessage("Torch", $"Hit process client on debug draw!");
6463

6564
//If its the same unique name, we can add it
66-
if (AllDraws.TryGetValue(uniqueName, out DrawDebug draw))
65+
if(AllDraws.ContainsKey(uniqueName))
6766
{
68-
draw.drawObjects.AddList(drawObjects);
67+
AllDraws[uniqueName].drawObjects.AddList(drawObjects);
6968
}
7069
else
7170
{
@@ -153,11 +152,17 @@ public void refreshDraw()
153152
//static update to update all draws
154153
public static void refreshAllDraws()
155154
{
156-
//MyRenderProxy.DebugClearPersistentMessages();
155+
try
156+
{
157+
158+
foreach (var draw in AllDraws)
159+
{
160+
draw.Value.refreshDraw();
161+
}
157162

158-
foreach (var draw in AllDraws)
163+
}catch(Exception ex)
159164
{
160-
draw.Value.refreshDraw();
165+
//do nothings
161166
}
162167
}
163168

@@ -198,6 +203,8 @@ public drawObject() { }
198203
[ProtoMember(106)]
199204
public Vector3D up;
200205

206+
[ProtoMember(118)]
207+
public int wireDivideRatio = 0;
201208

202209
[ProtoMember(120)]
203210
public float radius;
@@ -244,35 +251,41 @@ public void drawOBB()
244251
{
245252
MatrixD worldMatrix = MatrixD.CreateWorld(position, forward, up);
246253
var material = TorchModCore.id;
247-
MySimpleObjectDraw.DrawTransparentBox(ref worldMatrix, ref box, ref color, raster, 1, linethickness, material, material);
254+
MySimpleObjectDraw.DrawTransparentBox(ref worldMatrix, ref box, ref color, raster, wireDivideRatio, linethickness, material, material, intensity: intensity);
248255
}
249256

250257
public void drawSphere()
251258
{
252259
var material = TorchModCore.id;
253260
var transform = MatrixD.CreateTranslation(position);
254-
MySimpleObjectDraw.DrawTransparentSphere(ref transform, 10, ref color, raster, 25, material, material, -1);
261+
262+
MySimpleObjectDraw.DrawTransparentSphere(ref transform, radius, ref color, raster, wireDivideRatio, material, material, linethickness, intensity: intensity);
255263
}
256264

257265
public void drawOBBEntity()
258266
{
259267
//This will keep updating the draw for live grid box preview
260-
//Do not keep searching for entity on draw
261-
if (searchAttempts > 10)
268+
//Do not keep searching for entity on draw
269+
if (searchAttempts > 250 || entityID == 0)
262270
return;
263271

264-
if (entRef == null && entityID != 0)
272+
273+
274+
275+
276+
entRef = MyEntities.GetEntityById(entityID);
277+
if (entRef == null )
265278
{
266-
entRef = MyEntities.GetEntityById(entityID);
267279
searchAttempts++;
280+
return;
268281
}
269282

270283

271284
var material = TorchModCore.id;
272285
var Matrix = entRef.WorldMatrix;
273286
BoundingBoxD myAabb = entRef.PositionComp.LocalAABB;
274287

275-
MySimpleObjectDraw.DrawTransparentBox(ref Matrix, ref myAabb, ref color, raster, 1, linethickness, material, material);
288+
MySimpleObjectDraw.DrawTransparentBox(ref Matrix, ref myAabb, ref color, raster, wireDivideRatio, linethickness, material, material);
276289
}
277290

278291

‎Torch.Mod/Messages/VoxelResetMessage.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,4 @@ public override void ProcessServer()
4141
throw new Exception();
4242
}
4343
}
44-
}
44+
}

‎Torch.Mod/ModCommunication.cs‎

Lines changed: 11 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ public static void Register()
4141
MyLog.Default.WriteLineAndConsole("TORCH MOD: Mod communication registered successfully.");
4242
}
4343

44-
private static void MessageHandler(ushort arg1, byte[] arg2, ulong arg3, bool arg4)
44+
private static void MessageHandler(ushort handlerId, byte[] messageSentBytes, ulong senderPlayerId, bool isArrivedFromServer)
4545
{
4646
try
4747
{
48-
MessageBase msgBase = MyAPIGateway.Utilities.SerializeFromBinary<MessageBase>(arg2);
48+
MessageBase msgBase = MyAPIGateway.Utilities.SerializeFromBinary<MessageBase>(messageSentBytes);
4949

5050

5151
if (false)
@@ -54,7 +54,14 @@ private static void MessageHandler(ushort arg1, byte[] arg2, ulong arg3, bool ar
5454
if (MyAPIGateway.Multiplayer.IsServer)
5555
msgBase.ProcessServer();
5656
else
57+
{
58+
if (!isArrivedFromServer)
59+
{
60+
MyLog.Default.WriteLineAndConsole($"TORCH MOD: {senderPlayerId} sending messages but isn't server");
61+
return;
62+
}
5763
msgBase.ProcessClient();
64+
}
5865

5966

6067
}
@@ -117,111 +124,7 @@ public static void DoProcessing(MessageBase m)
117124
_playerCache.Clear();
118125

119126
}
120-
121-
122-
123-
124-
/*
125-
public static void DoProcessing()
126-
{
127-
while (!_closing)
128-
{
129-
try
130-
{
131-
MessageBase m;
132-
try
133-
{
134-
m = _processing.Take();
135-
}
136-
catch
137-
{
138-
continue;
139-
}
140-
141-
MyLog.Default.WriteLineAndConsole($"Processing message: {m.GetType().Name}");
142-
143-
if (m is IncomingMessage) //process incoming messages
144-
{
145-
MessageBase i;
146-
try
147-
{
148-
var o = MyCompression.Decompress(m.CompressedData);
149-
m.CompressedData = null;
150-
_messagePool.Return((IncomingMessage)m);
151-
i = MyAPIGateway.Utilities.SerializeFromBinary<MessageBase>(o);
152-
}
153-
catch (Exception ex)
154-
{
155-
MyLog.Default.WriteLineAndConsole($"TORCH MOD: Failed to deserialize message! {ex}");
156-
continue;
157-
}
158-
159-
if (TorchModCore.Debug)
160-
MyAPIGateway.Utilities.ShowMessage("Torch", $"Received message of type {i.GetType().Name}");
161-
162-
if (MyAPIGateway.Multiplayer.IsServer)
163-
i.ProcessServer();
164-
else
165-
i.ProcessClient();
166-
}
167-
else //process outgoing messages
168-
{
169-
if (TorchModCore.Debug)
170-
MyAPIGateway.Utilities.ShowMessage("Torch", $"Sending message of type {m.GetType().Name}");
171-
172-
var b = MyAPIGateway.Utilities.SerializeToBinary(m);
173-
m.CompressedData = MyCompression.Compress(b);
174-
175-
switch (m.TargetType)
176-
{
177-
case MessageTarget.Single:
178-
MyAPIGateway.Multiplayer.SendMessageTo(NET_ID, m.CompressedData, m.Target);
179-
break;
180-
case MessageTarget.Server:
181-
MyAPIGateway.Multiplayer.SendMessageToServer(NET_ID, m.CompressedData);
182-
break;
183-
case MessageTarget.AllClients:
184-
MyAPIGateway.Players.GetPlayers(_playerCache);
185-
foreach (var p in _playerCache)
186-
{
187-
if (p.SteamUserId == MyAPIGateway.Multiplayer.MyId)
188-
continue;
189-
MyAPIGateway.Multiplayer.SendMessageTo(NET_ID, m.CompressedData, p.SteamUserId);
190-
}
191-
192-
break;
193-
case MessageTarget.AllExcept:
194-
MyAPIGateway.Players.GetPlayers(_playerCache);
195-
foreach (var p in _playerCache)
196-
{
197-
if (p.SteamUserId == MyAPIGateway.Multiplayer.MyId || m.Ignore.Contains(p.SteamUserId))
198-
continue;
199-
MyAPIGateway.Multiplayer.SendMessageTo(NET_ID, m.CompressedData, p.SteamUserId);
200-
}
201-
202-
break;
203-
default:
204-
throw new Exception();
205-
}
206-
207-
_playerCache.Clear();
208-
}
209-
}
210-
catch (Exception ex)
211-
{
212-
MyLog.Default.WriteLineAndConsole($"TORCH MOD: Exception occurred in communication thread! {ex}");
213-
}
214-
}
215-
216-
MyLog.Default.WriteLineAndConsole("TORCH MOD: INFO: Communication thread shut down successfully! THIS IS NOT AN ERROR");
217-
//exit signal received. Clean everything and GTFO
218-
_processing?.Dispose();
219-
_processing = null;
220-
_messagePool?.Clean();
221-
_messagePool = null;
222-
_playerCache = null;
223-
}
224-
*/
127+
225128
public static void SendMessageTo(MessageBase message, ulong target)
226129
{
227130
if (!MyAPIGateway.Multiplayer.IsServer)
@@ -269,4 +172,4 @@ public static void SendMessageToServer(MessageBase message)
269172
DoProcessing(message);
270173
}
271174
}
272-
}
175+
}

‎Torch.Mod/TorchModCore.cs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ namespace Torch.Mod
1414
public class TorchModCore : MySessionComponentBase
1515
{
1616

17-
public const ulong MOD_ID = 2722000298; //real
18-
//public const ulong MOD_ID = 2916923149; //test
17+
public const ulong MOD_ID = 3270275515; //real
18+
//public const ulong MOD_ID = 2916923149; //old
1919
private static bool _init;
2020
public static bool Debug;
2121
public static MyStringId id;
@@ -60,4 +60,4 @@ protected override void UnloadData()
6060
}
6161
}
6262
}
63-
}
63+
}

0 commit comments

Comments
 (0)