void OnRotate(Player p, RotateEventArgs args)
 {
     if (!(bool)(p.ExtraData.GetIfExist <object, object>("WoMCompass") ?? false))
     {
         return;
     }
     else
     {
         WOM.SendDetail(p, "(" + SubstringLoop(p.Rot[0] / (int)(255 / (compass.Length - 1))) + ")");
     }
 }
 void OnOutgoingData(Player p, PacketEventArgs e)
 {
     if (e.Type == Packet.Types.MOTD)
     {
         string ip;
         if (Server.DebugMode)
         {
             ip = "127.0.0.1";
         }
         else
         {
             ip = InetUtils.GrabWebpage("http://www.mcforge.net/serverdata/ip.php");
         }
         Packet pa = new Packet();
         pa.Add(Packet.Types.MOTD);
         pa.Add((byte)7);
         pa.Add(ServerSettings.GetSetting("ServerName"), 64);
         pa.Add(ServerSettings.GetSetting("MOTD") + " &0cfg=" + ip + ":" + ServerSettings.GetSetting("Port") + "/" + p.Level.Name, 64);
         pa.Add((byte)0);
         e.Data = pa.bytes;
     }
     //Because this is way more fun and requires no edits to the core ~Gamemakergm
     else if (e.Type == Packet.Types.Message)
     {
         if (PluginSettings.GetSettingBoolean("joinleave-alert"))
         {
             string incoming = Encoding.ASCII.GetString(e.Data).Trim();
             //Logger.Log(incoming);
             if (incoming.Contains("joined the game!"))
             {
                 e.Cancel();
                 WOM.GlobalSendJoin(incoming.Substring(1, incoming.Length - incoming.IndexOf("joined the game!")));
             }
             else if (incoming.Contains("has disconnected"))
             {
                 e.Cancel();
                 WOM.GlobalSendLeave(incoming.Substring(1, incoming.Length - incoming.IndexOf("has disconnected")));
             }
         }
     }
     else
     {
         return;
     }
 }
Example #3
0
        public void Use(Player p, string[] args)
        {
            p.ExtraData.CreateIfNotExist <object, object>("WoMCompass", false);
            switch (args.Length)
            {
            case 0:
                p.ExtraData["WoMCompass"] = !(bool)(p.ExtraData.GetIfExist <object, object>("WoMCompass") ?? false);
                if ((bool)p.ExtraData["WoMCompass"] == true)
                {
                    p.SendMessage("Compass activated!");
                    WOM.SendDetail(p, "Look around to activate the Compass!");
                }
                else
                {
                    p.SendMessage("Compass deactivated!");
                    DeactiveMessage(p);
                }
                break;

            case 1:
                switch (args[0])
                {
                case "on":
                    p.ExtraData["WoMCompass"] = true;
                    p.SendMessage("Compass activated!");
                    WOM.SendDetail(p, "Look around to activate the Compass!");
                    break;

                case "off":
                    p.ExtraData["WoMCompass"] = false;
                    p.SendMessage("Compass deactivated!");
                    DeactiveMessage(p);
                    break;

                default:
                    p.SendMessage("Invalid argument!");
                    break;
                }
                break;

            default:
                p.SendMessage("Invalid arguments!");
                break;
            }
        }
        public void Use(Player p, string[] args)
        {
            string messageToSend = string.Join(" ", args);

            //Givo - gah ill make it send the rest below another time
            if (messageToSend.Length >= 44)
            {
                p.SendMessage("You can only send messages with 44 characters or less");
                return;
            }
            switch (args.Length)
            {
            case 1:
                WOM.SendAlert(p, messageToSend);
                return;

            case 2:
                if (args[0] == "all")
                {
                    WOM.GlobalSendAlert(messageToSend);
                    return;
                }
                Level  l  = Level.FindLevel(args[0]);
                Player pl = Player.Find(args[0]);
                if (l != null)
                {
                    WOM.LevelSendAlert(l, messageToSend);
                    return;
                }
                else if (pl != null)
                {
                    WOM.SendAlert(pl, messageToSend);
                    return;
                }
                return;

            default:
                p.SendMessage((args.Length < 1) ? "You need to specify a message!" : "Invalid arguments!");
                return;
            }
        }
        void OnIncomingData(Player p, PacketEventArgs args)
        {
            if (args.Data.Length < 0)
            {
                return;
            }

            if (args.Data[0] != (byte)'G')
            {
                return;
            }

            args.Cancel();
            var netStream = p.Client.GetStream();

            using (var Writer = new StreamWriter(netStream))
            {
                var line  = Encoding.UTF8.GetString(args.Data, 0, args.Data.Length).Split('\n')[0];
                var match = Parser.Match(line);

                if (match.Success)
                {
                    var lvl          = Level.FindLevel(match.Groups[1].Value);
                    var versionLine  = Encoding.UTF8.GetString(args.Data, 0, args.Data.Length).Split('\n')[2];
                    var userNameLine = Encoding.UTF8.GetString(args.Data, 0, args.Data.Length).Split('\n')[3];
                    var version      = versionLine.Remove(0, "X-WoM-Version: ".Length).Replace("\r", "");
                    var username     = userNameLine.Remove(0, "X-WoM-Username: "******"\r", "");
                    Thread.Sleep(1500); //Trying to find player before it loads so wait.
                    var player = Player.Find(username);
                    if (player != null)
                    {
                        player.ExtraData.ChangeOrCreate <object, object>("UsingWoM", true);
                        if (!String.IsNullOrWhiteSpace(version))
                        {
                            player.ExtraData.ChangeOrCreate <object, object>("WoMVersion", version);
                            if (PluginSettings.GetSettingBoolean("notify-ops") == true)
                            {
                                Player.UniversalChatOps(username + " joined using " + version);
                                Logger.Log(username + " joined using " + version);
                            }
                        }
                    }
                    if (lvl == null)
                    {
                        Writer.Write("HTTP/1.1 404 Not Found");
                        Writer.Flush();
                    }
                    else
                    {
                        if (!lvl.ExtraData.ContainsKey("WoMConfig"))
                        {
                            Writer.Write("HTTP/1.1 500 Internal Server Error");
                            Writer.Flush();
                        }
                        else
                        {
                            var config = (string[])lvl.ExtraData["WoMConfig"];
                            var bytes  = Encoding.UTF8.GetBytes(config.ToString <string>());
                            Writer.WriteLine("HTTP/1.1 200 OK");
                            Writer.WriteLine("Date: " + DateTime.UtcNow.ToString("R"));
                            Writer.WriteLine("Server: Apache/2.2.21 (CentOS)");
                            Writer.WriteLine("Last-Modified: " + DateTime.UtcNow.ToString("R"));
                            Writer.WriteLine("Accept-Ranges: bytes");
                            Writer.WriteLine("Content-Length: " + bytes.Length);
                            Writer.WriteLine("Connection: close");
                            Writer.WriteLine("Content-Type: text/plain");
                            Writer.WriteLine();
                            foreach (var entry in config)
                            {
                                Writer.WriteLine(entry);
                            }
                        }
                        CFGSettings a = (CFGSettings)CFGDict.GetIfExist <Level, CFGSettings>(p.Level);
                        WOM.SendDetail(player, a.GetSetting("detail.user")); //Send the detail with parsed variables.
                    }
                }

                else
                {
                    Writer.Write("HTTP/1.1 400 Bad Request");
                    Writer.Flush();
                }
            }
        }
Example #6
0
        void DeactiveMessage(Player p)
        {
            CFGSettings a = (CFGSettings)PluginWoMTextures.CFGDict.GetIfExist <Level, CFGSettings>(p.Level);

            WOM.SendDetail(p, a.GetSetting("detail.user"));
        }