diff --git a/EssentialsPlugin/AssemblyFileVersion.cs b/EssentialsPlugin/AssemblyFileVersion.cs
index be54ba6..cc66703 100644
--- a/EssentialsPlugin/AssemblyFileVersion.cs
+++ b/EssentialsPlugin/AssemblyFileVersion.cs
@@ -1,4 +1,4 @@
-//392
+//398
//
// This code was generated by a tool. Any changes made manually will be lost
// the next time this code is regenerated.
@@ -6,5 +6,5 @@
using System.Reflection;
-[assembly: AssemblyFileVersion("1.13.7.392")]
-[assembly: AssemblyVersion("1.13.7.392")]
+[assembly: AssemblyFileVersion("1.13.7.398")]
+[assembly: AssemblyVersion("1.13.7.398")]
diff --git a/EssentialsPlugin/ChatHandlers/Admin/HandleAdminResetPlanet.cs b/EssentialsPlugin/ChatHandlers/Admin/HandleAdminResetPlanet.cs
index 5962b9a..5e2a417 100644
--- a/EssentialsPlugin/ChatHandlers/Admin/HandleAdminResetPlanet.cs
+++ b/EssentialsPlugin/ChatHandlers/Admin/HandleAdminResetPlanet.cs
@@ -1,5 +1,6 @@
namespace EssentialsPlugin.ChatHandlers.Admin
{
+ using System.Diagnostics;
using System.Linq;
using ParallelTasks;
using Sandbox.Definitions;
@@ -48,7 +49,14 @@ public override bool HandleCommand( ulong userId, string[ ] words )
//Wrapper.BeginGameAction( ( ) =>
// {
- Parallel.Start(()=>voxel.Storage.Reset( VRage.Voxels.MyStorageDataTypeFlags.All ));
+ Parallel.Start( ( ) =>
+ {
+ Essentials.Log.Info( $"Resetting {voxel.StorageName}" );
+ var stopwatch = Stopwatch.StartNew( );
+ voxel.Storage.Reset( VRage.Voxels.MyStorageDataTypeFlags.All );
+ stopwatch.Stop( );
+ Essentials.Log.Info($"Reset {voxel.StorageName} in {(1000d * stopwatch.ElapsedTicks / Stopwatch.Frequency):N3}ms" );
+ });
//MyMultiplayer.ReplicateImmediatelly( MyExternalReplicable.FindByObject( ent ) );
// }, null, null );
}
diff --git a/EssentialsPlugin/ChatHandlers/Admin/HandleAdminStatic.cs b/EssentialsPlugin/ChatHandlers/Admin/HandleAdminStatic.cs
new file mode 100644
index 0000000..d66d49b
--- /dev/null
+++ b/EssentialsPlugin/ChatHandlers/Admin/HandleAdminStatic.cs
@@ -0,0 +1,98 @@
+namespace EssentialsPlugin.ChatHandlers.Admin
+{
+ using System.Diagnostics;
+ using System.Linq;
+ using ParallelTasks;
+ using Sandbox.Definitions;
+ using Sandbox.Engine.Multiplayer;
+ using Sandbox.Engine.Voxels;
+ using Sandbox.Game.Entities;
+ using Sandbox.Game.Entities.Character;
+ using Sandbox.Game.Replication;
+ using Utility;
+ using VRage.Game;
+
+ public class HandleAdminStatic : ChatHandlerBase
+ {
+
+ public override string GetHelp()
+ {
+ return "Sets grids as static. Usage: /admin static (all, small, large)";
+ }
+
+ public override string GetCommandText()
+ {
+ return "/admin static";
+ }
+
+ public override bool IsAdminCommand()
+ {
+ return true;
+ }
+
+ public override bool AllowedInConsole()
+ {
+ return true;
+ }
+
+ public override bool HandleCommand( ulong userId, string[ ] words )
+ {
+ if (words.Length != 1)
+ {
+ Communication.SendPrivateInformation( userId, GetHelp( ) );
+ return false;
+ }
+ bool small;
+ bool large;
+
+ switch (words[0].ToLower( ))
+ {
+ case "small":
+ small = true;
+ large = false;
+ break;
+ case "large":
+ small = false;
+ large = true;
+ break;
+ case "all":
+ small = true;
+ large = true;
+ break;
+ default:
+ Communication.SendPrivateInformation( userId, GetHelp( ) );
+ return false;
+ }
+
+ var ents = MyEntities.GetEntities( ).ToArray( );
+ int count = 0;
+ foreach (var ent in ents)
+ {
+ var grid = ent as MyCubeGrid;
+ if (grid == null)
+ continue;
+
+ if (grid.Physics == null || grid.IsStatic)
+ continue;
+
+ if (grid.GridSizeEnum == MyCubeSize.Large && large)
+ {
+ grid.RequestConversionToStation( );
+ Essentials.Log.Info( $"Converted {grid.DisplayName} to static" );
+ count++;
+ }
+ else if (grid.GridSizeEnum == MyCubeSize.Small && small)
+ {
+ grid.RequestConversionToStation( );
+ Essentials.Log.Info( $"Converted {grid.DisplayName} to static" );
+ count++;
+ }
+ }
+ Communication.SendPrivateInformation( userId, $"Converted {count} grids to static" );
+ return true;
+ }
+
+ }
+
+}
+
diff --git a/EssentialsPlugin/Essentials.cs b/EssentialsPlugin/Essentials.cs
index ec41e75..b271fbc 100644
--- a/EssentialsPlugin/Essentials.cs
+++ b/EssentialsPlugin/Essentials.cs
@@ -54,9 +54,6 @@
public class Essentials : IPlugin, IChatEventHandler, IPlayerEventHandler, ICubeGridHandler, ICubeBlockEventHandler, ISectorEventHandler
{
- //IMPORTANT: Comment out this field to let the build work on both branches
- public const bool StableBuild = false;
-
public static Logger Log;
#region Private Fields
internal static Essentials Instance;
@@ -1195,7 +1192,7 @@ private void DoInit( string path )
new HandleAdminFactionCleanup( ),
new HandleAdminSpawnCargo( ),
new HandleAdminPlayerCount( ),
-
+ new HandleAdminStatic( ),
//Admin Scan
new HandleAdminScanAreaAt( ),
diff --git a/EssentialsPlugin/EssentialsPlugin.csproj b/EssentialsPlugin/EssentialsPlugin.csproj
index 1b37ebe..ecb9d76 100644
--- a/EssentialsPlugin/EssentialsPlugin.csproj
+++ b/EssentialsPlugin/EssentialsPlugin.csproj
@@ -78,6 +78,7 @@
+
diff --git a/EssentialsPlugin/Utility/Communication.cs b/EssentialsPlugin/Utility/Communication.cs
index 3fce42d..a522589 100644
--- a/EssentialsPlugin/Utility/Communication.cs
+++ b/EssentialsPlugin/Utility/Communication.cs
@@ -8,6 +8,7 @@
using Sandbox.Common.ObjectBuilders;
using Sandbox.ModAPI;
using System.Collections.Generic;
+ using System.Reflection;
using SEModAPIExtensions.API;
using SEModAPIInternal.API.Common;
using SEModAPIInternal.API.Entity;
@@ -21,6 +22,7 @@
using System.Threading.Tasks;
using Sandbox;
using Sandbox.Definitions;
+ using Sandbox.Engine.Multiplayer;
using Sandbox.Game.Entities;
using Settings;
using VRage.Collections;
@@ -36,20 +38,29 @@ public static void SendPublicInformation( string infoText )
{
if ( infoText == "" )
return;
-
- ServerMessageItem MessageItem = new ServerMessageItem( );
- MessageItem.From = PluginSettings.Instance.ServerChatName;
- MessageItem.Message = infoText;
- string messageString = MyAPIGateway.Utilities.SerializeToXML( MessageItem );
- byte[ ] data = Encoding.UTF8.GetBytes( messageString );
-
- if ( ChatManager.EnableData )
+ ScriptedChatMsg msg = new ScriptedChatMsg
{
- BroadcastDataMessage( DataMessageType.Message, data );
- }
- else
- ChatManager.Instance.SendPublicChatMessage( infoText );
+ Author = PluginSettings.Instance.ServerChatName,
+ Font = MyFontEnum.Red,
+ Text = infoText,
+ };
+
+ var messageMethod = typeof(MyMultiplayerBase).GetMethod("OnScriptedChatMessageRecieved", BindingFlags.NonPublic | BindingFlags.Static);
+ ServerNetworkManager.Instance.RaiseStaticEvent(messageMethod, msg);
+ //ServerMessageItem MessageItem = new ServerMessageItem( );
+ //MessageItem.From = PluginSettings.Instance.ServerChatName;
+ //MessageItem.Message = infoText;
+
+ //string messageString = MyAPIGateway.Utilities.SerializeToXML( MessageItem );
+ //byte[ ] data = Encoding.UTF8.GetBytes( messageString );
+
+ //if ( ChatManager.EnableData )
+ //{
+ // BroadcastDataMessage( DataMessageType.Message, data );
+ //}
+ //else
+ // ChatManager.Instance.SendPublicChatMessage( infoText );
ChatManager.Instance.AddChatHistory( new ChatManager.ChatEvent( DateTime.Now, 0, infoText ) );
}
@@ -58,30 +69,22 @@ public static void SendPrivateInformation( ulong playerId, string infoText, stri
{
if ( infoText == "" )
return;
-
- ServerMessageItem MessageItem = new ServerMessageItem( );
-
+
if ( from == null )
- MessageItem.From = PluginSettings.Instance.ServerChatName;
-
+ from = PluginSettings.Instance.ServerChatName;
else if ( PluginSettings.Instance.WhisperChatPrefix )
- MessageItem.From = " " + from;
-
- else
- MessageItem.From = from;
-
- MessageItem.Message = infoText;
-
- string messageString = MyAPIGateway.Utilities.SerializeToXML( MessageItem );
- byte[ ] data = Encoding.UTF8.GetBytes( messageString );
+ from = " " + from;
- if ( ChatManager.EnableData )
+ ScriptedChatMsg msg = new ScriptedChatMsg
{
- SendDataMessage( playerId, DataMessageType.Message, data );
- }
- else
- ChatManager.Instance.SendPrivateChatMessage( playerId, infoText );
-
+ Author = from,
+ Font = MyFontEnum.Red,
+ Text = infoText,
+ };
+
+ var messageMethod = typeof(MyMultiplayerBase).GetMethod("OnScriptedChatMessageRecieved", BindingFlags.NonPublic | BindingFlags.Static);
+ ServerNetworkManager.Instance.RaiseStaticEvent(messageMethod, playerId, msg);
+
ChatManager.ChatEvent chatItem = new ChatManager.ChatEvent( );
chatItem.Timestamp = DateTime.Now;
chatItem.RemoteUserId = (from == null ? 0 : PlayerMap.Instance.GetSteamIdFromPlayerName( from ));
@@ -91,28 +94,27 @@ public static void SendPrivateInformation( ulong playerId, string infoText, stri
public static void SendFactionClientMessage( ulong playerSteamId, string message )
{
- ServerMessageItem MessageItem = new ServerMessageItem( );
+ string from;
+
if ( PluginSettings.Instance.FactionChatPrefix )
- MessageItem.From = " " + PlayerMap.Instance.GetFastPlayerNameFromSteamId( playerSteamId );
+ from = " " + PlayerMap.Instance.GetFastPlayerNameFromSteamId( playerSteamId );
else
- MessageItem.From = PlayerMap.Instance.GetFastPlayerNameFromSteamId( playerSteamId );
-
- MessageItem.Message = message;
-
- string messageString = MyAPIGateway.Utilities.SerializeToXML( MessageItem );
- byte[ ] data = Encoding.UTF8.GetBytes( messageString );
-
+ from = PlayerMap.Instance.GetFastPlayerNameFromSteamId( playerSteamId );
+
foreach ( ulong steamId in PlayerManager.Instance.ConnectedPlayers )
{
if ( Player.CheckPlayerSameFaction( playerSteamId, steamId ) )
{
- if ( ChatManager.EnableData )
+ ScriptedChatMsg msg = new ScriptedChatMsg
{
- SendDataMessage( steamId, DataMessageType.Message, data );
- ChatManager.Instance.AddChatHistory( new ChatManager.ChatEvent( DateTime.Now, playerSteamId, "{faction message}: " + message ) );
- }
- else
- ChatManager.Instance.SendPrivateChatMessage( steamId, message );
+ Author = from,
+ Font = MyFontEnum.Red,
+ Text = message,
+ };
+
+ var messageMethod = typeof(MyMultiplayerBase).GetMethod("OnScriptedChatMessageRecieved", BindingFlags.NonPublic | BindingFlags.Static);
+ ServerNetworkManager.Instance.RaiseStaticEvent(messageMethod, msg);
+ ChatManager.Instance.AddChatHistory( new ChatManager.ChatEvent( DateTime.Now, playerSteamId, "{faction message}: " + message ) );
}
}
}
@@ -303,29 +305,25 @@ public static void SendDataMessage( ulong steamId, DataMessageType messageType,
Buffer.BlockCopy( data, 0, newData, msgIdString.Length + 1, data.Length );
*/
- //hash a random long with the current time to make a decent quality guid for each message
- byte[] randLong = new byte[sizeof(long)];
- _random.NextBytes(randLong);
- long uniqueId = 23;
- uniqueId = uniqueId * 37 + BitConverter.ToInt64(randLong, 0);
- uniqueId = uniqueId * 37 + DateTime.Now.GetHashCode();
-
+ byte[] guidBytes = Guid.NewGuid( ).ToByteArray( );
+
//this is a much more elegant and lightweight method
- byte[] newData = new byte[sizeof(long)*2 + data.Length];
- BitConverter.GetBytes( uniqueId ).CopyTo( newData, 0 );
- BitConverter.GetBytes((long)messageType).CopyTo(newData, sizeof(long));
- data.CopyTo( newData, sizeof(long)*2);
+ byte[] newData = new byte[sizeof(long) + guidBytes.Length + data.Length];
+ guidBytes.CopyTo( newData, 0 );
+ BitConverter.GetBytes((long)messageType).CopyTo(newData, guidBytes.Length);
+ data.CopyTo( newData, sizeof(long) + guidBytes.Length);
- if ( newData.Length > 4096 )
- {
- SendMessagePartsTo( steamId, newData );
- return;
- }
+ //if ( newData.Length > 4096 )
+ //{
+ // SendMessagePartsTo( steamId, newData );
+ // return;
+ //}
//Wrapper.GameAction( ( ) =>
MySandboxGame.Static.Invoke( () =>
{
- MyAPIGateway.Multiplayer.SendMessageTo( 9000, newData, steamId );
+ //MyAPIGateway.Multiplayer.SendMessageTo( 9000, newData, steamId );
+ ServerNetworkManager.Instance.SendModMessageTo( 9000, newData, steamId );
} );
}
@@ -342,27 +340,26 @@ public static void BroadcastDataMessage( DataMessageType messageType, byte[ ] da
Buffer.BlockCopy( data, 0, newData, msgIdString.Length + 1, data.Length );
*/
- byte[] randLong = new byte[sizeof(long)];
- _random.NextBytes(randLong);
- long uniqueId = 23;
- uniqueId = uniqueId * 37 + BitConverter.ToInt64( randLong, 0 );
- uniqueId = uniqueId * 37 + DateTime.Now.GetHashCode();
-
- byte[] newData = new byte[sizeof(long) * 2 + data.Length];
- BitConverter.GetBytes(uniqueId).CopyTo(newData, 0);
- BitConverter.GetBytes((long)messageType).CopyTo(newData, sizeof(long));
- data.CopyTo(newData, sizeof(long) * 2);
-
- if (newData.Length > 4096)
- {
- BroadcastMessageParts(newData);
- return;
- }
+
+ byte[] guidBytes = Guid.NewGuid().ToByteArray();
+
+ //this is a much more elegant and lightweight method
+ byte[] newData = new byte[sizeof(long) + guidBytes.Length + data.Length];
+ guidBytes.CopyTo(newData, 0);
+ BitConverter.GetBytes((long)messageType).CopyTo(newData, guidBytes.Length);
+ data.CopyTo(newData, sizeof(long) + guidBytes.Length);
+
+ //if (newData.Length > 4096)
+ //{
+ // BroadcastMessageParts(newData);
+ // return;
+ //}
//Wrapper.GameAction( ( ) =>
MySandboxGame.Static.Invoke(() =>
{
- MyAPIGateway.Multiplayer.SendMessageToOthers( 9000, newData );
+ MyAPIGateway.Multiplayer.SendMessageToOthers( 9000, newData );
+ //ServerNetworkManager.Instance.BroadcastModMessage( 9000, newData );
} );
}