Ejemplo n.º 1
0
        public void Disconnect()
        {
            if (Chat == null)
                return;

            Chat.Leave(SteamChatLeaveReason.Left);
            Chat = null;
        }
Ejemplo n.º 2
0
        public override void Leave()
        {
            if (Chat != null)
            {
                Chat.Leave(SteamChatLeaveReason.Left);
                Chat = null;
            }

            base.Leave();
        }
Ejemplo n.º 3
0
 // For Steam private messages
 public CommandTarget(SteamChat steamChat, SteamPersona sender)
 {
     PrivateChat = steamChat;
     Persona = sender;
 }
Ejemplo n.º 4
0
        private void HandleMessage(SteamChat chat, SteamPersona user, string message)
        {
            _lastMessage.Restart();

            var senderName = user.DisplayName;
            var senderId = user.Id.ConvertToUInt64().ToString("D");
            var inGame = user.Playing != null && user.Playing.ToUInt64() != 0;

            var line = new ChatLine(Util.GetCurrentTimestamp(), RoomInfo.ShortName, "Steam", senderName, senderId, "", message, inGame);
            SendLine(line);

            Command.Handle(new CommandTarget(this, user.Id), message, "~");
        }
Ejemplo n.º 5
0
        private void HandleLeave(SteamChat chat, SteamPersona user, SteamChatLeaveReason reason, SteamPersona sourceUser)
        {
            _lastMessage.Restart();

            var message = user.DisplayName;
            switch (reason)
            {
                case SteamChatLeaveReason.Left:
                    message += " left chat.";
                    break;
                case SteamChatLeaveReason.Disconnected:
                    message += " disconnected.";
                    break;
                case SteamChatLeaveReason.Kicked:
                    message += string.Format(" was kicked by {0}.", sourceUser.DisplayName);
                    break;
                case SteamChatLeaveReason.Banned:
                    message += string.Format(" was banned by {0}.", sourceUser.DisplayName);
                    break;
            }

            var by = sourceUser != null ? sourceUser.DisplayName : "";
            var byId = sourceUser != null ? sourceUser.Id.ConvertToUInt64().ToString("D") : "0";
            var byType = sourceUser != null ? "Steam" : "";

            var line = new StateLine(Util.GetCurrentTimestamp(), RoomInfo.ShortName, reason.ToString(), user.DisplayName, user.Id.ConvertToUInt64().ToString("D"), "Steam", by, byId, byType, message);
            SendLine(line);
        }
Ejemplo n.º 6
0
        private void HandleEnter(SteamChat chat, SteamPersona user)
        {
            _lastMessage.Restart();

            var message = user.DisplayName + " entered chat.";

            var line = new StateLine(Util.GetCurrentTimestamp(), RoomInfo.ShortName, "Enter", user.DisplayName, user.Id.ConvertToUInt64().ToString("D"), "Steam", "", "0", "", message);
            SendLine(line);
        }
Ejemplo n.º 7
0
        public override void Update()
        {
            if (!IsActive)
            {
                if (Chat != null)
                    Chat.Leave(SteamChatLeaveReason.Left);

                return;
            }

            if (Chat != null && _lastMessage.Elapsed >= TimeSpan.FromMinutes(30))
            {
                Program.Logger.Info("Rejoining " + RoomInfo.ShortName);
                _lastMessage.Restart();
                Chat.Leave(SteamChatLeaveReason.Disconnected);
                return;
            }

            if (Program.Steam.Status != Steam.ConnectionStatus.Connected || Chat != null)
                return;

            _hasConnected = false;
            Chat = Program.Steam.Bot.Join(SteamId);

            Chat.OnEnter += sender =>
            {
                _hasConnected = true;
                Program.Logger.Info("Entered " + RoomInfo.ShortName);
                SendPersistentSysMessage("Connected to Steam.");
            };

            Chat.OnLeave += (sender, reason) =>
            {
                if (_hasConnected)
                {
                    _hasConnected = false;
                    Program.Logger.Info("Left " + RoomInfo.ShortName + ": " + reason);
                    SendPersistentSysMessage("Lost connection to Steam.");
                }

                Chat = null;
            };

            Chat.OnMessage += HandleMessage;
            Chat.OnUserEnter += HandleEnter;
            Chat.OnUserLeave += HandleLeave;
        }
Ejemplo n.º 8
0
 public CommandTarget(SteamChat steamChat, SteamID sender)
 {
     PrivateChat = steamChat;
     SteamId = sender;
 }
Ejemplo n.º 9
0
        /// <summary>
        /// Attempt to join a chat. Will call OnLeave if the chat could not be joined.
        /// </summary>
        public SteamChat Join(SteamID chatId)
        {
            if (chatId.IsClanAccount)
            {
                SteamFriends.RequestFriendInfo(chatId, EClientPersonaStateFlag.ClanInfo | EClientPersonaStateFlag.ClanTag | EClientPersonaStateFlag.PlayerName);
                chatId = Util.ChatFromClan(chatId);
            }

            var chatsCopy = Chats;
            if (chatsCopy.Any(r => r.Id == chatId && r.IsActive))
                return chatsCopy.Find(r => r.Id == chatId);

            var chat = new SteamChat(this, chatId);
            chat.Subscribe();
            SteamFriends.JoinChat(chatId);

            lock (_sync)
                _chats.Add(chat);

            return chat;
        }