Skip to content

Commit

Permalink
Unicode support for new chat system
Browse files Browse the repository at this point in the history
  • Loading branch information
rexxar-tc committed Jan 12, 2016
1 parent feeb5fd commit e03c8e6
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 15 deletions.
6 changes: 3 additions & 3 deletions SEModAPI/AssemblyFileVersion.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
//3
//4
//
// This code was generated by a tool. Any changes made manually will be lost
// the next time this code is regenerated.
//

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")]
31 changes: 30 additions & 1 deletion SEModAPIExtensions/API/ChatManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -213,6 +216,17 @@ public List<ChatEvent> 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<ChatEvent> ChatEvents
{
get
Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -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<MessageRecieveItem>( 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 );
Expand Down Expand Up @@ -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( );
Expand Down
6 changes: 3 additions & 3 deletions SEModAPIExtensions/AssemblyFileVersion.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
//2
//6
//
// This code was generated by a tool. Any changes made manually will be lost
// the next time this code is regenerated.
//

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")]
6 changes: 3 additions & 3 deletions SEModAPIInternal/AssemblyFileVersion.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
//2
//5
//
// This code was generated by a tool. Any changes made manually will be lost
// the next time this code is regenerated.
//

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")]
6 changes: 3 additions & 3 deletions SEServerExtender/AssemblyFileVersion.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
//3
//11
//
// This code was generated by a tool. Any changes made manually will be lost
// the next time this code is regenerated.
//

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")]
4 changes: 2 additions & 2 deletions SEServerExtender/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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" ) )
{
Expand Down

0 comments on commit e03c8e6

Please sign in to comment.