Exemplo n.º 1
0
        public void Call(string name)
        {
            var character = Application.Connection.GetOrCreateCharacter(name);
            var chatBuf = Application.Buffers.FirstOrDefault(c => c.Character == character);
            if (chatBuf == null)
            {
                chatBuf = new ChannelBuffer { ChatBuf = new CharacterChatBuffer(character), Title = character.Name };
                Application.Buffers.Add(chatBuf);
            }

            Application.CurrentBuffer = Application.Buffers.IndexOf(chatBuf);
        }
Exemplo n.º 2
0
		public static void WriteMessage(string Text, ChannelBuffer buffer = null, Channel channel = null, Character sender = null, MessageType type = MessageType.Chat, MessageSource source = MessageSource.Local)
		{
			if (buffer == null)
			{
				if (channel == null && sender != null)
				{
					buffer = _ChannelBuffers.FirstOrDefault(c => c.Character == sender);
					if (buffer == null)
					{
						buffer = new ChannelBuffer { ChatBuf = new CharacterChatBuffer(sender), Title = sender.Name };
						_ChannelBuffers.Add(buffer);
					}
				}
				else if (channel != null)
				{
					buffer = _ChannelBuffers.FirstOrDefault(c => c.Channel == channel);
					if (buffer == null)
						throw new Exception($"Message to unknown channel buffer '{channel}' recieved; {Text}");
				}
				else
					buffer = CurrentChannelBuffer;
			}

            buffer.ChatActivity = true;
			buffer.Highlight |= buffer.Character != null || Text.ToLower().Contains(Connection.LocalCharacter.Name.ToLower());
            if (buffer.Highlight)
                Text = Text.Replace(Connection.LocalCharacter.Name, Connection.LocalCharacter.Name.Color(ConsoleColor.Yellow));

            buffer.ChatBuf.SendMessage(sender ?? (source == MessageSource.Local ? _Chat.LocalCharacter : null), Text, type, source);
				
            if (CurrentChannelBuffer == buffer)
                CurrentChannelBuffer.Render();
		}
Exemplo n.º 3
0
		public static void Run()
		{
			Console.Clear();
			Console.Title = string.Format("FChat Messenger v{0}", Assembly.GetExecutingAssembly().GetName().Version);

            Debug.Listeners.Clear();
            Debug.Listeners.Add((_ConsoleBuffer.ChatBuf as ConsoleChatBuffer).TraceListener);
            _ChannelBuffers.Add(_ConsoleBuffer);
            _InputBox.OnTextEntered += (s, e) => { TextEntry(e); };

            _Chat.AutoPing = true;

			//_Chat.OnRawMessage += (_, e) =>
			//	_ConsoleBuffer.ChatBuf.PushMessage(null, $"<< {e.Command.Serialize()}");
			//_Chat.OnSendMessage += (_, e) =>
			//	_ConsoleBuffer.ChatBuf.PushMessage(null, $">> {e.Command.Serialize()}");

			_Chat.OnSYSMessage += (_, e) =>
				_ConsoleBuffer.ChatBuf.PushMessage(null, (e.Command as Server_SYS_ChatSYSMessage).Message);
            _Chat.OnErrorMessage += (_, e) =>
            {
                if (CurrentChannelBuffer != _ConsoleBuffer)
                    _ConsoleBuffer.ChatBuf.PushMessage(null, (e.Command as Server_ERR_ChatError).Error);
                CurrentChannelBuffer.ChatBuf.PushMessage(null, (e.Command as Server_ERR_ChatError).Error, MessageType.Preview, MessageSource.Remote);
            };
			_Chat.OnError += (_, e) =>
				_ConsoleBuffer.ChatBuf.PushMessage(null, $"{e.Message}:\n${e.InnerException}");

			_Chat.OnChannelJoin += (_, e) =>
			{
				ChannelBuffer chatBuf = _ChannelBuffers.FirstOrDefault(c => c.Channel == e.Channel);
				if (chatBuf == null)
				{
					chatBuf = new ChannelBuffer { ChatBuf = new ChannelChatBuffer(e.Channel), Title = e.Channel.Title };
					_ChannelBuffers.Add(chatBuf);
				}
				else
					chatBuf.Title = e.Channel.Title;
				CurrentBuffer = _ChannelBuffers.IndexOf(chatBuf);
			};

			_Chat.OnChannelChatMessage += (_, e) =>
				WriteMessage(e.Message, null, e.Channel, e.Character, source: MessageSource.Remote);
			_Chat.OnChannelLFRPMessage += (_, e) =>
				WriteMessage(e.Message, null, e.Channel, e.Character, MessageType.LFRP, MessageSource.Remote);
			_Chat.OnChannelRollMessage += (_, e) =>
				WriteMessage(e.Message, null, e.Channel, e.Character, MessageType.Roll, MessageSource.Remote);
			_Chat.OnCharacterChatMessage += (_, e) =>
				WriteMessage(e.Message, null, null, e.Character, source: MessageSource.Remote);
            _Chat.OnCharacterStatusChange += (_, e) =>
            {
                var buf = _ChannelBuffers.FirstOrDefault(c => c.Character == e.Character);
                string msg = $"{e.Character.Name} is now {e.Character.Status}";
                if (!string.IsNullOrEmpty(e.Character.StatusMessage))
                    msg += ", " + e.Character.StatusMessage;

                if (buf != null)
                    WriteMessage(msg, buf, type: MessageType.Preview, source: MessageSource.Remote);

                if (e.Character.IsFriend || e.Character.IsBookmark)
                    WriteMessage(msg, _ConsoleBuffer, type: MessageType.Preview, source: MessageSource.Remote);
            };
            _Chat.OnCharacterTypingChange += (_, e) =>
            {
                var buf = _ChannelBuffers.FirstOrDefault(c => c.Character == e.Character);
                if (buf == null)
                    return;

                buf.SystemActivity |= true;
                // TODO: Typing notification
            };

			_Chat.OnChannelLeave += (_, e) =>
			{
				int i = 0;
				foreach (var c in _ChannelBuffers)
				{
					if (c.Channel == e.Channel)
					{
						if (_CurBuffer == i)
							_CurBuffer--;

						_ChannelBuffers.Remove(c);
						break;
					}
					++i;
				}
			};

			Redraw(true);
			InputLoop();

			if (_Chat != null)
				_Chat.Dispose();
			_Chat = null;
		}
Exemplo n.º 4
0
        public static void WriteLog(string Text, ChannelBuffer buffer = null)
        {
            if (buffer == null)
                buffer = CurrentChannelBuffer;

            buffer.ChatBuf.PushMessage(null, Text, MessageType.Preview);
            buffer.SystemActivity = true;

            if (buffer == CurrentChannelBuffer)
                buffer.Render();
        }