public void FireMessageProcessingEvent() { if (MessageProcessing != null) { MessageProcessing.Invoke(this); } }
internal void RaiseMessageRecieved(ChatMsg message, ref bool consumed) { var torchMsg = new TorchChatMessage(MyMultiplayer.Static?.GetMemberName(message.Author) ?? $"user_{message.Author}", message.Author, message.Text); MessageProcessing?.Invoke(torchMsg, ref consumed); }
/// <inheritdoc /> protected override bool OfflineMessageProcessor(TorchChatMessage msg) { if (MyMultiplayer.Static != null) { return(false); } var consumed = false; MessageProcessing?.Invoke(msg, ref consumed); return(consumed); }
internal void RaiseMessageRecieved(ChatMsg message, ref bool consumed) { var torchMsg = new TorchChatMessage(GetMemberName(message.Author), message.Author, message.Text); MessageProcessing?.Invoke(torchMsg, ref consumed); if (!consumed) { _chatLog.Info($"{torchMsg.Author}: {torchMsg.Message}"); } }
// Обработка приходящих сообщений private void Vk_MessageReceived(object sender, MessageEventArgs e) { // Добавление в Users, если отсутствует if (!Users.Contains(e.Message.Id)) { Task.Delay(300).Wait(); var name = vk.GetUsername(e.Message.Id); if (name != null) { Users.AddUser(e.Message.Id, name, null); } } // Вызов события о новом сообщении MessageReceived?.Invoke(this, e); // Пинаем каждый модуль чтоб он обработал сообщения for (int i = 0; i < Extensions.Length; i++) { var extension = Extensions[i]; // Скипаем выключенные модули if (!extension.Enabled) { continue; } // Передаём модулям сообщения для обработки MessageProcessing?.Invoke(this, new MessageProcessedEventArgs(extension)); var res = extension.ProcessMessage(e.Message.Id, e.Message.Text); // Логирование и остановка обработки if (res == ProcessResult.Processed) { MessageProcessed?.Invoke(this, new MessageProcessedEventArgs(extension)); if (extension.StopAfterProcessed) { ExtensionStopProcessing?.Invoke(this, new MessageProcessedEventArgs(extension)); return; } } else if (res == ProcessResult.Skipped) { MessageSkipped?.Invoke(this, new MessageProcessedEventArgs(extension)); } } }
private void ClientHandler <M>(Socket clientSocket) { clientList.Add(clientSocket); OnServerAccept?.Invoke(this, new AcceptEventArgs(clientSocket)); int fullMessageSize; string fullMessage; byte[] messageBuffer = new byte[1024]; while (true) { fullMessage = string.Empty; fullMessageSize = 0; try { do { int messageSize = clientSocket.Receive(messageBuffer); fullMessageSize += messageSize; fullMessage += Encoding.UTF8.GetString(messageBuffer, 0, messageSize); } while (clientSocket.Available > 0); OnServerReceive?.Invoke(this, new EventArgs()); } catch (Exception exception) { OnReceiveException?.Invoke(this, new ExceptionEventArgs(clientSocket, exception)); break; } List <ByteArray> byteArrays = Buffer.SplitBuffer(Encoding.UTF8.GetBytes(fullMessage), 0); object message = default; foreach (var byteArray in byteArrays) { if (typeof(M) != typeof(string)) { message = JsonSerializer.Deserialize <M>(Encoding.UTF8.GetString(byteArray.bytes)); } else { message = Encoding.UTF8.GetString(byteArray.bytes); } MessageProcessing?.Invoke(this, new MessageProcessEventArgs(new MessageData(message, fullMessageSize, fullMessage))); } } }
internal void RaiseMessageRecieved(ChatMsg message, ref bool consumed) { var torchMsg = new TorchChatMessage(GetMemberName(message.Author), message.Author, message.Text, (ChatChannel)message.Channel, message.TargetId); if (_muted.Contains(message.Author)) { consumed = true; _chatLog.Warn($"MUTED USER: [{torchMsg.Channel}:{torchMsg.Target}] {torchMsg.Author}: {torchMsg.Message}"); return; } MessageProcessing?.Invoke(torchMsg, ref consumed); if (!consumed) { _chatLog.Info($"[{torchMsg.Channel}:{torchMsg.Target}] {torchMsg.Author}: {torchMsg.Message}"); } }