private void chatInputTextBox_KeyDown(object sender, KeyEventArgs e)
 {
     if (e.Key == Key.Enter && chatInputTextBox.Text != "")
     {
         string text = chatInputTextBox.Text;
         chatInputTextBox.Text = "";
         if (firstMsg)
         {
             chatOutputTextBox.Text += "Me: " + text;
             firstMsg = false;
         }
         else
         {
             chatOutputTextBox.Text += Environment.NewLine + "Me: " + text;
         }
         Server.Send(ChatMessage.Create(text, ID), zombie);
     }
 }
示例#2
0
        private void HandleClients(object clientId)
        {
            int       id = (int)clientId;
            TcpClient client;

            lock (Locker)
                client = (Clients[id] as ChatClient)?.Client;

            try
            {
                while (true)
                {
                    NetworkStream stream     = client.GetStream();
                    byte[]        buffer     = new byte[Constants.MessageSize];
                    int           byte_count = stream.Read(buffer, 0, buffer.Length);

                    if (byte_count == 0)
                    {
                        break;
                    }

                    string data = Encoding.UTF8.GetString(buffer, 0, byte_count);
                    HandleMessage(ChatMessage.Parse(data));
                }
            }
            catch (Exception e)
            {
                Logger.Error(e.Message);
                Logger.Error($"Error: #{id} lost connection.");
            }
            finally
            {
                lock (Locker)
                    Clients.Remove(id);

                ChatMail.SendMessage(ChatMessage.Create(MessageCode.UserLeave, ServerUser,
                                                        null, DateTime.Now, ChatMessageText.Create(id.ToString())));

                Logger.Info($"#{id} has left.");

                client.Client.Shutdown(SocketShutdown.Both);
                client.Close();
            }
        }
示例#3
0
        /// <summary>
        /// Handles the chat information sent from the client.
        /// </summary>
        /// <param name="character">The character to handle packet for.</param>
        /// <param name="packet">The packet containing handle data.</param>
        public void Handle(Character character, Packet packet)
        {
            if (!character.Muted)
            {
                int    effects = packet.ReadShort() & 0xFFFF;
                int    length  = packet.ReadByte();
                string text    = ChatUtilities.DecryptChat(packet, length);

                if (character.ClanRoom != null && text.StartsWith("/"))
                {
                    GameEngine.Content.ClanChat.Message(character, text.Substring(1));
                }
                else
                {
                    character.Speak(ChatMessage.Create(effects, length, text));
                    ChatUtilities.LogChat(character.Name, ChatType.Normal, null, text);
                }
            }
        }