Example #1
0
        void ChatMsg( FriendChatMsg_t chatMsg )
        {
            
            byte[] msgData = new byte[ 1024 * 4 ];
            EChatEntryType type = EChatEntryType.k_EChatEntryTypeChatMsg;

            CSteamID reciever = new CSteamID( chatMsg.m_ulReceiver );

            int msgLength = steamFriends.GetChatMessage( chatMsg.m_ulReceiver, ( int )chatMsg.m_iChatID, msgData, msgData.Length, ref type );

            if ( type == EChatEntryType.k_EChatEntryTypeTyping )
                return;

            msgLength = Clamp( msgLength, 1, msgData.Length );

            LogMessage log = new LogMessage();

            log.Sender = new CSteamID( chatMsg.m_ulSender );
            log.SenderName = steamFriends.GetFriendPersonaName( log.Sender );

            log.Reciever = reciever;
            log.RecieverName = steamFriends.GetFriendPersonaName( log.Reciever );

            log.Message = Encoding.UTF8.GetString( msgData, 0, msgLength );
            log.Message = log.Message.Substring( 0, log.Message.Length - 1 );
            log.MessageTime = DateTime.Now;
            log.MessageType = type;

            AddLog( log );
        }
Example #2
0
        void ChatRoomMsg( ChatRoomMsg_t chatMsg )
        {
            if ( !groupChatEnabled || !sets.GroupChatEnabled )
                return;

            byte[] msgData = new byte[ 1024 * 4 ];
            EChatEntryType chatType = EChatEntryType.k_EChatEntryTypeInvalid;
            ulong chatter = 0;

            int len = getChatMsg( clientFriends.Interface, chatMsg.m_ulSteamIDChat, ( int )chatMsg.m_iChatID, ref chatter, msgData, msgData.Length, ref chatType );

            len = Clamp( len, 1, msgData.Length );

            LogMessage log = new LogMessage();

            log.IsGroupMsg = true;
            log.ChatRoom = chatMsg.m_ulSteamIDChat;
            log.ChatRoomName = getChatName( clientFriends.Interface, log.ChatRoom );

            log.Sender = new CSteamID( chatMsg.m_ulSteamIDUser );
            log.SenderName = steamFriends.GetFriendPersonaName( log.Sender );

            log.Reciever = log.Sender;
            log.RecieverName = log.SenderName;

            log.Message = Encoding.UTF8.GetString( msgData, 0, len );
            log.Message = log.Message.Substring(0, log.Message.Length - 1);
            log.MessageTime = DateTime.Now;
            log.MessageType = chatType;

            AddLog( log );
            
        }
Example #3
0
        public void Update()
        {
            Callback callback;
            SteamCallHandle steamCall;

            if ( Steamworks.Steam_BGetCallback( pipe, out callback, out steamCall ) )
            {
                if ( callback.CallbackNum == FriendChatMsg.Callback )
                {
                    FriendChatMsg chatMsg = null;

                    try
                    {
                        chatMsg = ( FriendChatMsg )callback.CallbackObject;
                    }
                    catch
                    {
                        Steamworks.Steam_FreeLastCallback( pipe );
                        OnLogFailure( new LogFailureEventArgs( "Recieved callback was not in the correct format, call a programmer!" ) );
                        return;
                    }

                    string message = string.Empty;
                    FriendMsgType type;

                    SteamID reciever = new SteamID( chatMsg.Reciever );

                    steamFriends.GetChatMessage( reciever, ( int )chatMsg.ChatID, out message, 1024 * 4, out type );

                    LogMessage log = new LogMessage();

                    log.Sender = new SteamID( chatMsg.Sender );
                    log.SenderName = steamFriends.GetFriendPersonaName( log.Sender );

                    log.Reciever = reciever;
                    log.RecieverName = steamFriends.GetFriendPersonaName( log.Reciever );

                    log.Message = message;
                    log.MessageTime = DateTime.Now;
                    log.MessageType = type;

                    AddLog( log );
                }

                Steamworks.Steam_FreeLastCallback( pipe );
            }
        }
Example #4
0
        private void AddLog( LogMessage log )
        {
            string directoryName = sets.LogDirectory;

            if ( string.IsNullOrEmpty( directoryName ) )
            {
                OnLogFailure( new LogFailureEventArgs( "Log directory not configured" ) );
                return;
            }

            string linkRep = sets.LookupLinkID( log.Sender );

            if ( linkRep == null )
                linkRep = log.SenderName;

            string fileLink = null;

            if ( log.IsGroupMsg )
                fileLink = sets.LookupLinkID( log.ChatRoom );
            else
                fileLink = sets.LookupLinkID( log.Reciever );

            if ( fileLink == null )
            {
                if ( log.IsGroupMsg )
                    fileLink = log.ChatRoomName;
                else
                    fileLink = log.RecieverName;
            }


            try
            {
                directoryName = directoryName.FormatWith(
                    new
                    {
                        CommunityID = ( ulong )log.Reciever,
                        SteamID = log.Reciever.Render().Replace( ":", sets.InvalidReplacement ),
                        Name = Util.StripInvalidChars( log.RecieverName, sets.InvalidReplacement ),
                        LinkID = Util.StripInvalidChars( fileLink, sets.InvalidReplacement ),
                        Date = Util.StripInvalidChars( DateTime.Now.ToString( sets.DateFormat, CultureInfo.CurrentCulture ), sets.InvalidReplacement ),
                        Time = Util.StripInvalidChars( DateTime.Now.ToString( sets.TimeFormat, CultureInfo.CurrentCulture ), sets.InvalidReplacement ),
                    }
                );

            }
            catch
            {
                OnLogFailure( new LogFailureEventArgs( "Directory name format is invalid" ) );
                return;
            }

            if ( !Directory.Exists( directoryName ) )
            {
                try
                {
                    Directory.CreateDirectory( directoryName );
                }
                catch
                {
                    OnLogFailure( new LogFailureEventArgs( "Log directory configured, but the directory could not be created" ) );
                    return;
                }
            }


            string fileName = sets.Filename;

            if ( string.IsNullOrEmpty( fileName ) )
            {
                OnLogFailure( new LogFailureEventArgs( "Log filename not configured" ) );
                return;
            }

            try
            {
                if ( log.IsGroupMsg )
                {
                    fileName = fileName.FormatWith(
                        new
                        {
                            Name = Util.StripInvalidChars( log.ChatRoomName, sets.InvalidReplacement ),
                            Date = Util.StripInvalidChars( DateTime.Now.ToString( sets.DateFormat, CultureInfo.CurrentCulture ), sets.InvalidReplacement ),
                            Time = Util.StripInvalidChars( DateTime.Now.ToString( sets.TimeFormat, CultureInfo.CurrentCulture ), sets.InvalidReplacement ),
                        }
                    );
                }
                else
                {
                    fileName = fileName.FormatWith(
                        new
                        {
                            CommunityID = ( ulong )log.Reciever,
                            SteamID = log.Reciever.Render().Replace( ":", sets.InvalidReplacement ),
                            Name = Util.StripInvalidChars( log.RecieverName, sets.InvalidReplacement ),
                            LinkID = Util.StripInvalidChars( fileLink, sets.InvalidReplacement ),
                            Date = Util.StripInvalidChars( DateTime.Now.ToString( sets.DateFormat, CultureInfo.CurrentCulture ), sets.InvalidReplacement ),
                            Time = Util.StripInvalidChars( DateTime.Now.ToString( sets.TimeFormat, CultureInfo.CurrentCulture ), sets.InvalidReplacement ),
                        }
                    );
                }
            }
            catch
            {
                OnLogFailure( new LogFailureEventArgs( "Filename format is invalid" ) );
                return;
            }

            string logMessage = string.Empty;

            string dateStr = string.Empty;
            try
            {
                dateStr = DateTime.Now.ToString( sets.DateFormat, CultureInfo.CurrentCulture );
            }
            catch
            {
                OnLogFailure( new LogFailureEventArgs( "Bad date format" ) );
                return;

                //dateStr = "Bad Date Format";
            }

            string timeStr = string.Empty;
            try
            {
                timeStr = DateTime.Now.ToString( sets.TimeFormat, CultureInfo.CurrentCulture );
            }
            catch
            {
                OnLogFailure( new LogFailureEventArgs( "Bad time format" ) );
                return;

                //timeStr = "Bad Time Format";
            }


            var ReplaceTable = new
            {
                Name = log.SenderName,
                SteamID = log.Sender.Render(),
                CommunityID = ( ulong )log.Sender,
                LinkID = linkRep,

                Message = log.Message,

                MyName = log.RecieverName,
                MySteamID = log.Reciever.Render(),

                Date = dateStr,
                Time = timeStr,
                UnixTime = ( DateTime.UtcNow - new DateTime( 1970, 1, 1, 0, 0, 0 ) ).TotalSeconds,

                NewLine = Environment.NewLine,
                Tab = "\t",

            };

            if ( log.MessageType == EChatEntryType.k_EChatEntryTypeChatMsg )
            {
                logMessage = sets.LogFormat;

                if ( string.IsNullOrEmpty( logMessage ) )
                {
                    OnLogFailure( new LogFailureEventArgs( "Log format not configured" ) );
                    return;
                }

                try
                {
                    logMessage = logMessage.FormatWith( ReplaceTable );
                }
                catch
                {
                    OnLogFailure( new LogFailureEventArgs( "Log format was invalid" ) );
                    return;
                }
            }
            else if ( log.MessageType == EChatEntryType.k_EChatEntryTypeEmote )
            {
                logMessage = sets.EmoteFormat;

                if ( string.IsNullOrEmpty( logMessage ) )
                {
                    OnLogFailure( new LogFailureEventArgs( "Log emote format not configured" ) );
                    return;
                }

                try
                {
                    logMessage = logMessage.FormatWith( ReplaceTable );
                }
                catch
                {
                    OnLogFailure( new LogFailureEventArgs( "Log emote format was invalid" ) );
                    return;
                }
            }

            if ( string.IsNullOrEmpty( logMessage ) )
                return;

            ulong senderId = log.Sender;

            if ( log.IsGroupMsg )
            {
                try
                {
                    File.AppendAllText( Path.Combine( directoryName, fileName ), logMessage + Environment.NewLine );
                    return;
                }
                catch ( Exception ex )
                {
                    OnLogFailure( new LogFailureEventArgs( ex.Message ) );
                    return;
                }
            }

            if ( sets.TrackSessions )
            {
                if ( sessionInfo.ContainsKey( senderId ) )
                {
                    DateTime lastMsg = sessionInfo[ senderId ];

                    if ( ( DateTime.Now - lastMsg ) > TimeSpan.FromMinutes( sets.MinsBetweenSessions ) )
                    {
                        File.AppendAllText( Path.Combine( directoryName, fileName ), Environment.NewLine + Environment.NewLine + "New session started on " + dateStr + " at " + timeStr + Environment.NewLine );
                        sessionInfo[ senderId ] = DateTime.Now;
                    }
                }
                else
                {
                    File.AppendAllText( Path.Combine( directoryName, fileName ), Environment.NewLine + Environment.NewLine + "New session started on " + dateStr + " at " + timeStr + Environment.NewLine );

                    sessionInfo.Add( senderId, DateTime.Now );
                }
            }

            try
            {
                File.AppendAllText( Path.Combine( directoryName, fileName ), logMessage + Environment.NewLine );
            }
            catch ( Exception ex )
            {
                OnLogFailure( new LogFailureEventArgs( ex.Message ) );
                return;
            }
        }
Example #5
0
        private void AddLog( LogMessage log )
        {
            string directoryName = sets.LogDirectory;

            if ( string.IsNullOrEmpty( directoryName ) )
            {
                OnLogFailure( new LogFailureEventArgs( "Log directory not configured" ) );
                return;
            }

            directoryName = directoryName.FormatWith(
                new
                {
                    SteamID = log.Reciever.Render().Replace( ":", "_" ),
                    Name = Util.StripInvalidChars( log.RecieverName, sets.InvalidReplacement ),
                    Date = Util.StripInvalidChars( DateTime.Now.ToString( "d", CultureInfo.CurrentCulture ), sets.InvalidReplacement ),
                    Time = Util.StripInvalidChars( DateTime.Now.ToString( "t", CultureInfo.CurrentCulture ), sets.InvalidReplacement ),
                }
            );

            if ( !Directory.Exists( directoryName ) )
            {
                try
                {
                    Directory.CreateDirectory( directoryName );
                }
                catch
                {
                    OnLogFailure( new LogFailureEventArgs( "Log directory not properly configured" ) );
                    return;
                }
            }

            string fileName = sets.Filename;

            if ( string.IsNullOrEmpty( fileName ) )
            {
                OnLogFailure( new LogFailureEventArgs( "Log filename not configured" ) );
                return;
            }

            fileName = fileName.FormatWith(
                new
                {
                    SteamID = log.Reciever.Render().Replace( ":", "_" ),
                    Name = Util.StripInvalidChars( log.RecieverName, sets.InvalidReplacement ),
                    Date = Util.StripInvalidChars( DateTime.Now.ToString( "d", CultureInfo.CurrentCulture ), sets.InvalidReplacement ),
                    Time = Util.StripInvalidChars( DateTime.Now.ToString( "t", CultureInfo.CurrentCulture ), sets.InvalidReplacement ),
                }
            );

            string logMessage = string.Empty;

            string dateStr = string.Empty;
            try
            {
                dateStr = DateTime.Now.ToString( sets.DateFormat, CultureInfo.CurrentCulture );
            }
            catch
            {
                dateStr = "Bad Date Format";
            }

            string timeStr = string.Empty;
            try
            {
                timeStr = DateTime.Now.ToString( sets.TimeFormat, CultureInfo.CurrentCulture );
            }
            catch
            {
                timeStr = "Bad Time Format";
            }

            var ReplaceTable = new
            {
                Name = log.SenderName,
                SteamID = log.Sender.Render(),

                Message = log.Message,

                MyName = log.RecieverName,
                MySteamID = log.Reciever.Render(),

                Date = dateStr,
                Time = timeStr,
                UnixTime = ( DateTime.UtcNow - new DateTime( 1970, 1, 1, 0, 0, 0 ) ).TotalSeconds,

                NewLine = Environment.NewLine,
                Tab = "\t",

            };

            if ( log.MessageType == FriendMsgType.Chat )
            {
                logMessage = sets.LogFormat;

                if ( string.IsNullOrEmpty( logMessage ) )
                {
                    OnLogFailure( new LogFailureEventArgs( "Log format not configured" ) );
                    return;
                }

                try
                {
                    logMessage = logMessage.FormatWith( ReplaceTable );
                }
                catch
                {
                    OnLogFailure( new LogFailureEventArgs( "Log format was invalid" ) );
                    return;
                }
            }
            else if ( log.MessageType == FriendMsgType.ChatSent ) // these are emotes for the newer interface versions
            {
                logMessage = sets.EmoteFormat;

                if ( string.IsNullOrEmpty( logMessage ) )
                {
                    OnLogFailure( new LogFailureEventArgs( "Log emote format not configured" ) );
                    return;
                }

                try
                {
                    logMessage = logMessage.FormatWith( ReplaceTable );
                }
                catch
                {
                    OnLogFailure( new LogFailureEventArgs( "Log emote format was invalid" ) );
                    return;
                }
            }

            if ( string.IsNullOrEmpty( logMessage ) )
                return;

            try
            {
                File.AppendAllText( Path.Combine( directoryName, fileName ), logMessage + Environment.NewLine );
            }
            catch (Exception ex)
            {
                OnLogFailure( new LogFailureEventArgs( ex.Message ) );
                return;
            }
        }