Пример #1
0
        /// <summary>
        /// Parses the message into a new BDS packet.
        /// </summary>
        /// <param name="rawMessage">The raw message.</param>
        public static BdsPacket Parse(string rawMessage)
        {
            string[] tokens = rawMessage.Split(':');
            if (tokens.Length < 3)
                throw new ArgumentException("Could not extract BDS information from rawMessage.");

            var packet = new BdsPacket
            {
                Namespace = tokens[0],
                Category = tokens[1],
                Command = tokens[2]
            };
            if (tokens.Length > 3)
                packet.Payload = new BdsPayload(tokens[3]);

            return packet;
        }
Пример #2
0
 public static void Send(this PluginContext context, BdsPacket packet)
 {
     context.Client.NpMsg(BdsPlugin.DatashareNS, packet.ToString());
 }
Пример #3
0
        /// <summary>
        /// The BDS BOTCHECK command that is used to identify bots.
        /// </summary>
        /// <see cref="http://botdom.com/documentation/Data_Sharing_Protocol/Bot_Data_Share/BOTCHECK"/>
        /// <param name="packet">The packet.</param>
        /// <param name="context">The context.</param>
        private void BdsBotcheck(BdsPacket packet, PluginContext context)
        {
            string command = packet.Command.ToUpper();

            switch (command)
            {
                case "ALL":
                case "DIRECT":
                    if (command == "ALL" && !packet.FromPoliceBot)
                        return;
                    else if (command == "DIRECT" && packet.Payload[0].ToLower() != context.BotSettings.UserName.ToLower())
                        return;

                    string trigger = context.BotSettings.Trigger;
                    string username = context.BotSettings.UserName;
                    string owner = context.BotSettings.Owner;

                    string payload = string.Format("{0},{1},{2},{3}/{4},{5},{6}",
                        packet.From, owner, Bot.Name, Bot.Version, Version,
                        CreateHashKey(string.Format("{0}{1}{2}", trigger, packet.From, username)), trigger);

                    BdsPacket responsePacket = new BdsPacket
                    {
                        Category = "BOTCHECK",
                        Command = "RESPONSE",
                        Payload = new BdsPayload(payload)
                    };

                    context.Send(responsePacket);
                    break;
                case "INFO":
                    // update db
                    BotInfo.Save(Config, packet.Payload);
                    break;
                case "NODATA":
                    // bot doesn't have any info on us. enlighten them
                    if (packet.Payload[0].ToLower() == context.BotSettings.UserName.ToLower())
                    {
                        packet.Command = "DIRECT";
                        BdsBotcheck(packet, context);
                    }
                    break;
                case "CLIENT":  // used as a response to BOTCHECK wen the responder is a client
                case "REQUEST": // used to request information from policebots in #datashare
                    // no-op
                    break;
            }
        }
Пример #4
0
        /// <summary>
        /// The BDSs BOTDEF command that is used to define bot types.
        /// </summary>
        /// <see cref="http://botdom.com/documentation/Data_Sharing_Protocol/Bot_Data_Share/BOTDEF"/>
        /// <param name="packet">The packet.</param>
        /// <param name="context">The context.</param>
        private void BdsBotdef(BdsPacket packet, PluginContext context)
        {
            // make sure 1) we have a request, 2) it's to us, 3) it's a police bot
            if (packet.Command.ToUpper() != "REQUEST" ||
                packet.Payload[0].ToLower() != context.BotSettings.UserName.ToLower() ||
                !packet.FromPoliceBot)
                return;

            // if we're here the request was for us
            string requester = packet.From;
            string bottype = Bot.Name;
            string language = Bot.Language;
            string author = Bot.Author;
            string link = "http://botdom.com/wiki/Oberon";
            string hash = CreateHashKey(string.Format("{0}{1}{2}", requester, bottype, author));

            context.Send(new BdsPacket
            {
                Category = "BOTDEF",
                Command = "RESPONSE",
                Payload = new BdsPayload(new[] { requester, bottype, language, author, link, hash })
            });
        }