From e03c8e656e80d6ccc444dc6c77da19be9fafd222 Mon Sep 17 00:00:00 2001 From: Brant Martin Date: Tue, 12 Jan 2016 14:30:09 -0500 Subject: [PATCH] Unicode support for new chat system --- SEModAPI/AssemblyFileVersion.cs | 6 ++--- SEModAPIExtensions/API/ChatManager.cs | 31 ++++++++++++++++++++++- SEModAPIExtensions/AssemblyFileVersion.cs | 6 ++--- SEModAPIInternal/AssemblyFileVersion.cs | 6 ++--- SEServerExtender/AssemblyFileVersion.cs | 6 ++--- SEServerExtender/Program.cs | 4 +-- 6 files changed, 44 insertions(+), 15 deletions(-) diff --git a/SEModAPI/AssemblyFileVersion.cs b/SEModAPI/AssemblyFileVersion.cs index 544a2369..056fdafa 100644 --- a/SEModAPI/AssemblyFileVersion.cs +++ b/SEModAPI/AssemblyFileVersion.cs @@ -1,4 +1,4 @@ -//3 +//4 // // 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.116.11.3")] -[assembly: AssemblyVersion("1.116.11.3")] +[assembly: AssemblyFileVersion("1.116.11.4")] +[assembly: AssemblyVersion("1.116.11.4")] diff --git a/SEModAPIExtensions/API/ChatManager.cs b/SEModAPIExtensions/API/ChatManager.cs index b9e5efbd..1b1529da 100644 --- a/SEModAPIExtensions/API/ChatManager.cs +++ b/SEModAPIExtensions/API/ChatManager.cs @@ -6,6 +6,7 @@ using System.Linq; using System.Reflection; using System.Runtime.InteropServices; + using System.Text; using System.Text.RegularExpressions; using System.Threading; using System.Xml; @@ -35,6 +36,8 @@ public class ChatManager { private static bool _enableData = false; + private static DateTime lastMessageTime = DateTime.Now; + private static string lastMessageString = ""; public struct ChatCommand { @@ -213,6 +216,17 @@ public List ChatHistory } } + public void AddChatHistory( ChatEvent chatItem ) + { + m_resourceLock.AcquireExclusive( ); + m_chatHistory.Add( chatItem ); + m_resourceLock.ReleaseExclusive( ); + if ( chatItem.RemoteUserId == 0 ) + ApplicationLog.ChatLog.Info( "Chat - Server: " + chatItem.Message ); + else + ApplicationLog.ChatLog.Info( string.Format( "Chat - Client '{0}': {1}", PlayerMap.Instance.GetFastPlayerNameFromSteamId( chatItem.RemoteUserId ), chatItem.Message ) ); + } + public List ChatEvents { get @@ -258,7 +272,10 @@ private void SetupChatHandlers( ) //check if we have the Essentials client mod installed so we can use dataMessages instead of chat messages if ( !_enableData ) if ( Server.Instance.Config.Mods.Contains( "559202083" ) || Server.Instance.Config.Mods.Contains( "558596580" ) ) + { _enableData = true; + ApplicationLog.Info( "Found Essentials client mod, enabling data messages" ); + } try { @@ -312,12 +329,21 @@ public class ServerMessageItem protected void ReceiveDataMessage( byte[ ] data ) { + /* string text = ""; for ( int r = 0; r < data.Length; r++ ) text += (char)data[r]; - + */ + string text = Encoding.Unicode.GetString( data ); MessageRecieveItem item = MyAPIGateway.Utilities.SerializeFromXML( text ); + //this should hopefully stop the duplicate command bug + if ( item.message == lastMessageString && DateTime.Now - lastMessageTime < TimeSpan.FromMilliseconds( 200 ) ) + return; + + lastMessageTime = DateTime.Now; + lastMessageString = item.message; + if ( item.msgID == 5010 ) { string playerName = PlayerMap.Instance.GetPlayerNameFromSteamId( item.fromID ); @@ -364,12 +390,15 @@ protected void SendDataMessage( string message, ulong userId = 0 ) item.Message = message; string messageString = MyAPIGateway.Utilities.SerializeToXML( item ); + /* byte[ ] data = new byte[messageString.Length]; for ( int r = 0; r < messageString.Length; r++ ) { data[r] = (byte)messageString[r]; } + */ + byte[ ] data = Encoding.Unicode.GetBytes( messageString ); long msgId = 5003; string msgIdString = msgId.ToString( ); diff --git a/SEModAPIExtensions/AssemblyFileVersion.cs b/SEModAPIExtensions/AssemblyFileVersion.cs index 900ed820..3e637279 100644 --- a/SEModAPIExtensions/AssemblyFileVersion.cs +++ b/SEModAPIExtensions/AssemblyFileVersion.cs @@ -1,4 +1,4 @@ -//2 +//6 // // 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.116.11.2")] -[assembly: AssemblyVersion("1.116.11.2")] +[assembly: AssemblyFileVersion("1.116.11.6")] +[assembly: AssemblyVersion("1.116.11.6")] diff --git a/SEModAPIInternal/AssemblyFileVersion.cs b/SEModAPIInternal/AssemblyFileVersion.cs index 900ed820..eeffbd8b 100644 --- a/SEModAPIInternal/AssemblyFileVersion.cs +++ b/SEModAPIInternal/AssemblyFileVersion.cs @@ -1,4 +1,4 @@ -//2 +//5 // // 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.116.11.2")] -[assembly: AssemblyVersion("1.116.11.2")] +[assembly: AssemblyFileVersion("1.116.11.5")] +[assembly: AssemblyVersion("1.116.11.5")] diff --git a/SEServerExtender/AssemblyFileVersion.cs b/SEServerExtender/AssemblyFileVersion.cs index 544a2369..5b357f6c 100644 --- a/SEServerExtender/AssemblyFileVersion.cs +++ b/SEServerExtender/AssemblyFileVersion.cs @@ -1,4 +1,4 @@ -//3 +//11 // // 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.116.11.3")] -[assembly: AssemblyVersion("1.116.11.3")] +[assembly: AssemblyFileVersion("1.116.11.11")] +[assembly: AssemblyVersion("1.116.11.11")] diff --git a/SEServerExtender/Program.cs b/SEServerExtender/Program.cs index 06a04df5..4f3edf0f 100644 --- a/SEServerExtender/Program.cs +++ b/SEServerExtender/Program.cs @@ -156,7 +156,7 @@ private static void Start( string[ ] args ) NoConsole = false, Debug = false, GamePath = new DirectoryInfo( PathManager.BasePath ).Parent.FullName, - NoWcf = true, + NoWcf = false, Autosave = 0, InstancePath = string.Empty, CloseOnCrash = false, @@ -294,7 +294,7 @@ private static void Start( string[ ] args ) } else if ( lowerCaseArgument.Equals( "nowcf" ) ) { - extenderArgs.NoWcf = false; + extenderArgs.NoWcf = true; } else if ( lowerCaseArgument.Equals( "closeoncrash" ) ) {