Пример #1
0
        void VaultChCreate(CAPlayer player, int chID, CommandArgs args)
        {
            try
            {

                var economyPlayer = Wolfje.Plugins.SEconomy.SEconomyPlugin.Instance.GetBankAccount(player.Index);
                var commandCost = new Wolfje.Plugins.SEconomy.Money(config.cost);

                //Vault.Vault.ModifyBalance(args.Player.Name, -config.ChanelCreatingCost))

                if (!economyPlayer.IsAccountEnabled)
                {
                    player.TSPlayer.SendErrorMessage("You cannot use this command because your account is disabled.");
                }

                else if (economyPlayer.Balance != null && economyPlayer.Balance >= config.cost)
                {
                    Wolfje.Plugins.SEconomy.Journal.BankTransferEventArgs trans = economyPlayer.TransferTo(
                    Wolfje.Plugins.SEconomy.SEconomyPlugin.Instance.WorldAccount, commandCost,
                    Wolfje.Plugins.SEconomy.Journal.BankAccountTransferOptions.AnnounceToSender |
                    Wolfje.Plugins.SEconomy.Journal.BankAccountTransferOptions.IsPayment, "", string.Format("charge to {0}", player.TSPlayer.Name));

                    var newchannel = new Channel(chID, args.Parameters[0]);
                    if (args.Parameters.Count > 1)
                        newchannel.Password = args.Parameters[1];
                    Channels[chID] = newchannel;
                    NetMessage.SendData((int)PacketTypes.ChatText, -1, -1, "New channel created", 255, Color.LightSalmon.R, Color.LightSalmon.G, Color.LightSalmon.B, chID + 1);
                    Channels[chID].JoinChannel(player);
                }
                else
                    args.Player.SendMessage(String.Format("Channel not found and insufficient founds to create a new channel. (costs: {0})", economyPlayer.Balance.ToString()), Color.LightSalmon);
                                                                                                                                             //Vault.Vault.MoneyToString(this.parseCost))
            }
            catch (Exception ex)
            {
                TShock.Log.ConsoleError(ex.ToString());
            }
        }
Пример #2
0
        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;
        }
Пример #3
0
 void ChannelCommand(CommandArgs args)
 {
     try
     {
         var player = PlayerList[args.Player.Index];
         if (player == null)
             return;
         if (args.Parameters.Count > 0)
         {
             int j = -1;
             for (int i = 0; i < Channels.Length; i++)
             {
                 if (Channels[i] != null)
                 {
                     if (Channels[i].Name.ToLower() == args.Parameters[0].ToLower())
                     {
                         if (Channels[i].ID == player.Channel)
                         {
                             args.Player.SendMessage("You are already in this channel", Color.Red);
                             return;
                         }
                         if (Channels[i].Password != "" && !args.Player.Group.HasPermission("CA.channel.bypass.password") && (args.Parameters.Count < 2 || args.Parameters[1] != Channels[i].Password)) // incorrect password
                         {
                             args.Player.SendMessage("This channel is locked, please provide the correct password.", Color.Red);
                             return;
                         }
                         Channels[i].JoinChannel(player);
                         return;
                     }
                 }
                 else if (j == -1)
                     j = i;
             }
             if (j != -1) // channel not found
             {
                 if (config.UsingSeconomy)
                 {
                     try
                     {
                         VaultChCreate(player, j, args);
                     }
                     catch
                     {
                         config.UsingSeconomy = false;
                     }
                     return;
                 }
                 if (args.Player.Group.HasPermission("CA.channel.create")) //create new channel
                 {
                     var newchannel = new Channel(j, args.Parameters[0]);
                     if (args.Parameters.Count > 1)
                         newchannel.Password = args.Parameters[1];
                     Channels[j] = newchannel;
                     NetMessage.SendData((int)PacketTypes.ChatText, -1, -1, "New channel created", 255, Color.LightSalmon.R, Color.LightSalmon.G, Color.LightSalmon.B, j + 1);
                     Channels[j].JoinChannel(player);
                     return;
                 }
                 args.Player.SendMessage("Channel not found and you do not have permission to create a new channel", Color.LightSalmon);
                 return;
             }
             args.Player.SendMessage("Channel not found and all channel slots are full", Color.Red);
             return;
         }
         args.Player.SendMessage("Syntax: /ch <channel name> [<password>]", Color.Red);
     }
     catch (Exception ex)
     {
         TShock.Log.ConsoleError(ex.ToString());
     }
 }
Пример #4
0
 void VaultChCreate(CAPlayer player, int chID, CommandArgs args)
 {
     try
     {
         if (Vault.Vault.ModifyBalance(args.Player.Name, -config.ChanelCreatingCost))
         {
             var newchannel = new Channel(chID, args.Parameters[0]);
             if (args.Parameters.Count > 1)
                 newchannel.Password = args.Parameters[1];
             Channels[chID] = newchannel;
             NetMessage.SendData((int)PacketTypes.ChatText, -1, -1, "New channel created", 255, Color.LightSalmon.R, Color.LightSalmon.G, Color.LightSalmon.B, chID + 1);
             Channels[chID].JoinChannel(player);
         }
         else
             args.Player.SendMessage(String.Format("Channel not found and insufficient founds to create a new channel. (costs: {0})", Vault.Vault.MoneyToString(config.ChanelCreatingCost)), Color.LightSalmon);
     }
     catch (Exception ex)
     {
         Log.ConsoleError(ex.ToString());
     }
 }