//Wait for server to finish so we make sure all of the levels are loaded void OnLoadDone() { Logger.Log("[WoMTextures] Succesfully initiated!"); FileUtils.CreateDirIfNotExist(ServerSettings.GetSetting("configpath") + "WoMTexturing/"); foreach (Level l in Level.Levels) { //This allows us to get a setting from any level cfg. CFGSettings s = new CFGSettings(l); CFGDict.CreateIfNotExist <Level, CFGSettings>(l, s); s.Init(); } PluginSettings = new WoMPluginSettings(); PluginSettings.Init(); Server.OnServerFinishSetup -= OnLoadDone; //Need on level load event to add to dictionary and serve cfg. Player.OnAllPlayersReceiveUnknownPacket.Normal += new Event <Player, PacketEventArgs> .EventHandler(OnIncomingData); Player.OnAllPlayersSendPacket.Normal += new Event <Player, PacketEventArgs> .EventHandler(OnOutgoingData); Player.OnAllPlayersRotate.Normal += new Event <Player, RotateEventArgs> .EventHandler(OnRotate); Level.OnAllLevelsLoad.Normal += new Event <Level, LevelLoadEventArgs> .EventHandler(OnLevelLoad); }
void OnLevelLoad(Level l, LevelLoadEventArgs args) { //The level loaded does not have a texture file, create it. TODO: Test if (CFGDict.GetIfExist <Level, CFGSettings>(l) == null) { CFGSettings s = new CFGSettings(l); CFGDict.CreateIfNotExist <Level, CFGSettings>(l, s); } }
//Wait for server to finish so we make sure all of the levels are loaded void OnLoadDone() { Logger.Log("[WoMTextures] Succesfully initiated!"); FileUtils.CreateDirIfNotExist(ServerSettings.GetSetting("configpath") + "WoMTexturing/"); foreach (Level l in Level.Levels) { //This allows us to get a setting from any level cfg. CFGSettings s = new CFGSettings(l); CFGDict.CreateIfNotExist<Level, CFGSettings>(l, s); s.OnLoad(); } PluginSettings = new WoMPluginSettings(); PluginSettings.OnLoad(); Server.OnServerFinishSetup -= OnLoadDone; //Need on level load event to add to dictionary and serve cfg. Player.OnAllPlayersReceiveUnknownPacket.Normal += new Event<Player, PacketEventArgs>.EventHandler(OnIncomingData); Player.OnAllPlayersSendPacket.Normal += new Event<Player, PacketEventArgs>.EventHandler(OnOutgoingData); Player.OnAllPlayersRotate.Normal += new Event<Player, RotateEventArgs>.EventHandler(OnRotate); }
void OnLevelLoad(Level l, LevelLoadEventArgs args) { //The level loaded does not have a texture file, create it. TODO: Test if (CFGDict.GetIfExist<Level, CFGSettings>(l) == null) { CFGSettings s = new CFGSettings(l); CFGDict.CreateIfNotExist<Level, CFGSettings>(l, s); } }
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(); } } }
void DeactiveMessage(Player p) { CFGSettings a = (CFGSettings)PluginWoMTextures.CFGDict.GetIfExist <Level, CFGSettings>(p.Level); WOM.SendDetail(p, a.GetSetting("detail.user")); }