/* [JsonConstructor] * public CAconfig(bool joinquitfilter, bool deathmsgfilter, bool joinquitdefault, bool deathmsgdefault) * { * this.EnableJoinQuitFilter = joinquitfilter; * this.EnableDeathMsgFilter = deathmsgfilter; * this.FilterDeathMsgByDefault = deathmsgdefault; * this.FilterJoinQuitByDefault = joinquitdefault; * }*/ // ------------------------------- Static save/load methods ----------------------- public static CAconfig Load() { var savepath = Path.Combine(CAMain.Savepath, "ChatAssistant.conf"); CAconfig returnconf = null; try { if (!File.Exists(savepath)) { returnconf = new CAconfig(); CAconfig.Save(returnconf); } else { using (var stream = new FileStream(savepath, FileMode.Open, FileAccess.Read, FileShare.Read)) { using (var sr = new StreamReader(stream)) { returnconf = JsonConvert.DeserializeObject <CAconfig>(sr.ReadToEnd()); } stream.Close(); } } } catch (Exception ex) { TShockAPI.Log.ConsoleError(ex.ToString()); return(new CAconfig()); } if (returnconf == null) { returnconf = new CAconfig(); } return(returnconf); }
/* [JsonConstructor] public CAconfig(bool joinquitfilter, bool deathmsgfilter, bool joinquitdefault, bool deathmsgdefault) { this.EnableJoinQuitFilter = joinquitfilter; this.EnableDeathMsgFilter = deathmsgfilter; this.FilterDeathMsgByDefault = deathmsgdefault; this.FilterJoinQuitByDefault = joinquitdefault; }*/ // ------------------------------- Static save/load methods ----------------------- public static CAconfig Load() { var savepath = Path.Combine(CAMain.Savepath, "ChatAssistant.conf"); CAconfig returnconf = null; try { if (!File.Exists(savepath)) { returnconf = new CAconfig(); CAconfig.Save(returnconf); } else { using (var stream = new FileStream(savepath, FileMode.Open, FileAccess.Read, FileShare.Read)) { using (var sr = new StreamReader(stream)) { returnconf = JsonConvert.DeserializeObject<CAconfig>(sr.ReadToEnd()); } stream.Close(); } } } catch (Exception ex) { TShockAPI.Log.ConsoleError(ex.ToString()); return new CAconfig(); } if (returnconf == null) returnconf = new CAconfig(); return returnconf; }
public override void Initialize() { NetHooks.GetData += GetData; NetHooks.SendData += SendData; ServerHooks.Join += OnJoin; ServerHooks.Leave += OnLeave; ServerHooks.Chat += OnChat; Commands.ChatCommands.Add(new Command("CA.channel.cmd", ChannelCommand, "ch", "channel")); Commands.ChatCommands.Add(new Command("CA.ignore.cmd", IgnoreCommand, "ignore")); if (!Directory.Exists(Savepath)) { Directory.CreateDirectory(Savepath); } var permChanPath = Path.Combine(Savepath, "PermChannels.conf"); if (!File.Exists(permChanPath)) { List <ChannelTemplate> defaultChannels = new List <ChannelTemplate>(); defaultChannels.Add(new ChannelTemplate { Name = "Global", Password = "", AnnounceChannelJoinLeave = false, BlockGlobalChat = false, Hidden = false }); /*var defaultChannel = new Channel(0, "Global", 1); * List<Object> newlist = new List<Object>() { new { defaultChannel.Name, defaultChannel.Flags, defaultChannel.Password } };*/ using (var stream = new FileStream(permChanPath, FileMode.OpenOrCreate, FileAccess.Write, FileShare.Write)) { using (var sr = new StreamWriter(stream)) { sr.Write(JsonConvert.SerializeObject(defaultChannels, Formatting.Indented)); } stream.Close(); } } using (var stream = new FileStream(permChanPath, FileMode.Open, FileAccess.Read, FileShare.Read)) { using (var sr = new StreamReader(stream)) { var permChanList = JsonConvert.DeserializeObject <List <ChannelTemplate> >(sr.ReadToEnd()); for (int i = 0; i < permChanList.Count; i++) { Channels[i] = new Channel(i, permChanList[i].Name, permChanList[i].GetFlags(), permChanList[i].Password); } } stream.Close(); } config = CAconfig.Load(); if (!File.Exists(Path.Combine("ServerPlugins", "Vault.dll"))) { config.UsingVault = false; } }
private static void Save(CAconfig conf) { try { using (var stream = new FileStream(Path.Combine(CAMain.Savepath, "ChatAssistant.conf"), FileMode.OpenOrCreate, FileAccess.Write, FileShare.Write)) { using (var sr = new StreamWriter(stream)) { sr.Write(JsonConvert.SerializeObject(conf, Formatting.Indented)); } stream.Close(); } } catch (Exception ex) { TShockAPI.Log.ConsoleError(ex.ToString()); } }
public override void Initialize() { //NetHooks.GetData += GetData; //NetHooks.SendData += SendData; //ServerHooks.Join += OnJoin; //ServerHooks.Leave += OnLeave; //ServerHooks.Chat += OnChat; // ServerApi.Hooks.NetGetData.Register(this, GetData); ServerApi.Hooks.NetSendData.Register(this, SendData); ServerApi.Hooks.ServerJoin.Register(this, OnJoin); ServerApi.Hooks.ServerLeave.Register(this, OnLeave); ServerApi.Hooks.ServerChat.Register(this, OnChat); Commands.ChatCommands.Add(new Command("CA.channel.cmd", ChannelCommand, "ch", "channel")); Commands.ChatCommands.Add(new Command("CA.ignore.cmd", IgnoreCommand, "ignore")); if (!Directory.Exists(Savepath)) Directory.CreateDirectory(Savepath); var permChanPath = Path.Combine(Savepath, "PermChannels.conf"); if (!File.Exists(permChanPath)) { List<ChannelTemplate> defaultChannels = new List<ChannelTemplate>(); defaultChannels.Add(new ChannelTemplate { Name = "Global", Password = "", AnnounceChannelJoinLeave = false, BlockGlobalChat = false, Hidden = false }); /*var defaultChannel = new Channel(0, "Global", 1); List<Object> newlist = new List<Object>() { new { defaultChannel.Name, defaultChannel.Flags, defaultChannel.Password } };*/ using (var stream = new FileStream(permChanPath, FileMode.OpenOrCreate, FileAccess.Write, FileShare.Write)) { using (var sr = new StreamWriter(stream)) { sr.Write(JsonConvert.SerializeObject(defaultChannels, Formatting.Indented)); } stream.Close(); } } using (var stream = new FileStream(permChanPath, FileMode.Open, FileAccess.Read, FileShare.Read)) { using (var sr = new StreamReader(stream)) { var permChanList = JsonConvert.DeserializeObject<List<ChannelTemplate>>(sr.ReadToEnd()); for (int i = 0; i < permChanList.Count; i++) { Channels[i] = new Channel(i, permChanList[i].Name, permChanList[i].GetFlags(), permChanList[i].Password); } } stream.Close(); } config = CAconfig.Load(); if (!File.Exists(Path.Combine("ServerPlugins", "Wolfje.Plugins.SEconomy.dll"))) config.UsingSeconomy = false; }