Exemple #1
0
    // ChatFromViewerOut: outgoing ChatFromViewer delegate; check for Analyst commands
    private static Packet ChatFromViewerOut(Packet packet, IPEndPoint sim)
    {
        // deconstruct the packet
        Hashtable blocks  = PacketUtility.Unbuild(packet);
        string    message = DataConvert.toChoppedString(PacketUtility.GetField(blocks, "ChatData", "Message"));

        if (message.Length > 1 && message[0] == '/')
        {
            string[] words = message.Split(' ');
            if (commandDelegates.Contains(words[0]))
            {
                // this is an Analyst command; act on it and drop the chat packet
                ((CommandDelegate)commandDelegates[words[0]])(words);
                return(null);
            }
        }

        if (loggedPackets.Contains("ChatFromViewer") || modifiedPackets.Contains("ChatFromViewer"))
        {
            // user has asked to log or modify this packet
            return(Analyze(packet, sim, Direction.Outgoing));
        }
        else
        {
            // return the packet unmodified
            return(packet);
        }
    }
Exemple #2
0
    // Analyze: modify and/or log a pocket
    private static Packet Analyze(Packet packet, IPEndPoint endPoint, Direction direction)
    {
        if (modifiedPackets.Contains(packet.Layout.Name))
        {
            try {
                Hashtable changes = (Hashtable)modifiedPackets[packet.Layout.Name];
                Hashtable blocks  = PacketUtility.Unbuild(packet);
                foreach (BlockField blockField in changes.Keys)
                {
                    PacketUtility.SetField(blocks, blockField.block, blockField.field, changes[blockField]);
                }
                packet = PacketBuilder.BuildPacket(packet.Layout.Name, protocolManager, blocks, packet.Data[0]);
            } catch (Exception e) {
                Console.WriteLine("failed to modify " + packet.Layout.Name + ": " + e.Message);
                Console.WriteLine(e.StackTrace);
            }
        }

        if (loggedPackets.Contains(packet.Layout.Name))
        {
            LogPacket(packet, endPoint, direction);
        }

        return(packet);
    }
Exemple #3
0
    private static Packet ChatFromSimulator(Packet packet, IPEndPoint sim)
    {
        // deconstruct the packet
        Hashtable blocks  = PacketUtility.Unbuild(packet);
        string    message = DataConvert.toChoppedString(PacketUtility.GetField(blocks, "ChatData", "Message"));
        string    name    = DataConvert.toChoppedString(PacketUtility.GetField(blocks, "ChatData", "FromName"));
        byte      audible = (byte)PacketUtility.GetField(blocks, "ChatData", "Audible");
        byte      type    = (byte)PacketUtility.GetField(blocks, "ChatData", "ChatType");

        // if this was a normal, audible message, write it to the console
        if (audible != 0 && (type == 0 || type == 1 || type == 2))
        {
            Console.WriteLine(name + ": " + message);
        }

        // return the packet unmodified
        return(packet);
    }