Added MaxSlots (Kicks player if full)

This commit is contained in:
high 2011-06-05 17:53:18 -04:00
parent 1429595c5b
commit 73f17b0260
4 changed files with 835 additions and 824 deletions

View file

@ -3,8 +3,8 @@ using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using Terraria;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using Terraria;
namespace TShockAPI namespace TShockAPI
{ {
@ -112,7 +112,6 @@ namespace TShockAPI
commands.Add(new Command("item", "cheat", new CommandDelegate(Item))); commands.Add(new Command("item", "cheat", new CommandDelegate(Item)));
commands.Add(new Command("give", "cheat", new CommandDelegate(Give))); commands.Add(new Command("give", "cheat", new CommandDelegate(Give)));
commands.Add(new Command("heal", "cheat", new CommandDelegate(Heal))); commands.Add(new Command("heal", "cheat", new CommandDelegate(Heal)));
} }
} }
@ -145,7 +144,7 @@ namespace TShockAPI
lineThree += "ProtectR : " + ConfigurationManager.spawnProtectRadius + ", "; lineThree += "ProtectR : " + ConfigurationManager.spawnProtectRadius + ", ";
lineThree += "DMS : " + ConfigurationManager.defaultMaxSpawns + ", "; lineThree += "DMS : " + ConfigurationManager.defaultMaxSpawns + ", ";
lineThree += "SpawnRate: " + ConfigurationManager.defaultSpawnRate + ", "; lineThree += "SpawnRate: " + ConfigurationManager.defaultSpawnRate + ", ";
Tools.SendMessage(ply, lineThree, new float[] { 255f, 255f, 0f}); Tools.SendMessage(ply, lineThree, new float[] { 255f, 255f, 0f });
} }
public static void Kick(CommandArgs args) public static void Kick(CommandArgs args)
@ -262,6 +261,7 @@ namespace TShockAPI
Tools.NewNPC((int)ConfigurationManager.NPCList.EYE, x, y, ply); Tools.NewNPC((int)ConfigurationManager.NPCList.EYE, x, y, ply);
Tools.Broadcast(Tools.FindPlayer(ply) + " has spawned an eye!"); Tools.Broadcast(Tools.FindPlayer(ply) + " has spawned an eye!");
} }
public static void Skeletron(CommandArgs args) public static void Skeletron(CommandArgs args)
{ {
int x = args.PlayerX; int x = args.PlayerX;
@ -385,7 +385,7 @@ namespace TShockAPI
{ {
for (int i = 0; i < amount; i++) for (int i = 0; i < amount; i++)
npcid = NPC.NewNPC(x, y, type, 0); npcid = NPC.NewNPC(x, y, type, 0);
Tools.Broadcast(string.Format("{0} was spawned {1} time(s).", Main.npc[npcid].name, amount));; Tools.Broadcast(string.Format("{0} was spawned {1} time(s).", Main.npc[npcid].name, amount)); ;
} }
} }
else else
@ -556,9 +556,9 @@ namespace TShockAPI
if (args.Message.Split(' ').Length == 2) if (args.Message.Split(' ').Length == 2)
int.TryParse(args.Message.Split(' ')[1], out page); int.TryParse(args.Message.Split(' ')[1], out page);
List<Command> cmdlist = new List<Command>(); List<Command> cmdlist = new List<Command>();
for(int j = 0; j < commands.Count; j++) for (int j = 0; j < commands.Count; j++)
{ {
if(commands[j].CanRun(TShock.players[args.PlayerID])) if (commands[j].CanRun(TShock.players[args.PlayerID]))
{ {
cmdlist.Add(commands[j]); cmdlist.Add(commands[j]);
} }
@ -648,7 +648,7 @@ namespace TShockAPI
Tools.SendMessage(args.PlayerID, "Invalid player!", new float[] { 255f, 0f, 0f }); Tools.SendMessage(args.PlayerID, "Invalid player!", new float[] { 255f, 0f, 0f });
else else
{ {
TShock.SendDataAll(26, -1, "", player, (float)((new Random()).Next(1, 20)), (float)5, (float)0); NetMessage.SendData(26, -1, -1, "", player, (float)((new Random()).Next(1, 20)), (float)5, (float)0);
Tools.Broadcast(Tools.FindPlayer(args.PlayerID) + " slapped " + Tools.FindPlayer(player) + " for 5 damage."); Tools.Broadcast(Tools.FindPlayer(args.PlayerID) + " slapped " + Tools.FindPlayer(player) + " for 5 damage.");
} }
} }
@ -661,7 +661,7 @@ namespace TShockAPI
Tools.SendMessage(args.PlayerID, "Invalid player!", new float[] { 255f, 0f, 0f }); Tools.SendMessage(args.PlayerID, "Invalid player!", new float[] { 255f, 0f, 0f });
else else
{ {
TShock.SendDataAll(26, -1, "", player, (float)((new Random()).Next(-1, 1)), (float)damage, (float)0); NetMessage.SendData(26, -1, -1, "", player, (float)((new Random()).Next(-1, 1)), (float)damage, (float)0);
Tools.Broadcast(Tools.FindPlayer(args.PlayerID) + " slapped " + Tools.FindPlayer(player) + " for " + damage.ToString() + " damage."); Tools.Broadcast(Tools.FindPlayer(args.PlayerID) + " slapped " + Tools.FindPlayer(player) + " for " + damage.ToString() + " damage.");
} }
} }
@ -674,6 +674,7 @@ namespace TShockAPI
ConfigurationManager.spawnProtect = (ConfigurationManager.spawnProtect == false); ConfigurationManager.spawnProtect = (ConfigurationManager.spawnProtect == false);
Tools.SendMessage(args.PlayerID, "Spawn is now " + (ConfigurationManager.spawnProtect ? "protected" : "open") + "."); Tools.SendMessage(args.PlayerID, "Spawn is now " + (ConfigurationManager.spawnProtect ? "protected" : "open") + ".");
} }
#endregion
#endregion Command Methods
} }
} }

View file

@ -8,6 +8,7 @@ namespace TShockAPI
class ConfigFile class ConfigFile
{ {
public ConfigFile() { } public ConfigFile() { }
public int InvasionMultiplier = 1; public int InvasionMultiplier = 1;
public int DefaultMaximumSpawns = 4; public int DefaultMaximumSpawns = 4;
public int DefaultSpawnRate = 700; public int DefaultSpawnRate = 700;
@ -26,5 +27,6 @@ namespace TShockAPI
public bool SpawnProtection = true; public bool SpawnProtection = true;
public int SpawnProtectionRadius = 5; public int SpawnProtectionRadius = 5;
public string DistributationAgent = "facepunch"; public string DistributationAgent = "facepunch";
public int MaxSlots = 8;
} }
} }

View file

@ -1,8 +1,8 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.IO;
using Newtonsoft.Json; using Newtonsoft.Json;
namespace TShockAPI namespace TShockAPI
@ -33,6 +33,7 @@ namespace TShockAPI
public static int spawnProtectRadius = 5; public static int spawnProtectRadius = 5;
public static string distributationAgent = "facepunch"; public static string distributationAgent = "facepunch";
public static int authToken = 0; public static int authToken = 0;
public static int maxSlots = 8;
public enum NPCList : int public enum NPCList : int
{ {
@ -65,6 +66,7 @@ namespace TShockAPI
spawnProtect = cfg.SpawnProtection; spawnProtect = cfg.SpawnProtection;
spawnProtectRadius = cfg.SpawnProtectionRadius; spawnProtectRadius = cfg.SpawnProtectionRadius;
distributationAgent = cfg.DistributationAgent; distributationAgent = cfg.DistributationAgent;
maxSlots = cfg.MaxSlots;
Terraria.NPC.maxSpawns = defaultMaxSpawns; Terraria.NPC.maxSpawns = defaultMaxSpawns;
Terraria.NPC.defaultSpawnRate = defaultSpawnRate; Terraria.NPC.defaultSpawnRate = defaultSpawnRate;
} }
@ -99,6 +101,7 @@ namespace TShockAPI
cfg.KickExplosives = true; cfg.KickExplosives = true;
cfg.SpawnProtection = true; cfg.SpawnProtection = true;
cfg.SpawnProtectionRadius = 5; cfg.SpawnProtectionRadius = 5;
cfg.MaxSlots = maxSlots;
string json = JsonConvert.SerializeObject(cfg, Formatting.Indented); string json = JsonConvert.SerializeObject(cfg, Formatting.Indented);
TextWriter tr = new StreamWriter(FileTools.SaveDir + "config.json"); TextWriter tr = new StreamWriter(FileTools.SaveDir + "config.json");

View file

@ -443,6 +443,17 @@ namespace TShockAPI
void OnJoin(int ply, AllowEventArgs handler) void OnJoin(int ply, AllowEventArgs handler)
{ {
if (Main.netMode != 2) { return; } if (Main.netMode != 2) { return; }
int count = 1;
for (int i = 0; i < Main.player.Length; i++)
count += Main.player[i].active ? 1 : 0;
if (count > ConfigurationManager.maxSlots)
{
Tools.Kick(ply, "Server is full");
return;
}
string ip = Tools.GetRealIP((Convert.ToString(Netplay.serverSock[ply].tcpClient.Client.RemoteEndPoint))); string ip = Tools.GetRealIP((Convert.ToString(Netplay.serverSock[ply].tcpClient.Client.RemoteEndPoint)));
if (FileTools.CheckBanned(ip)) if (FileTools.CheckBanned(ip))
{ {
@ -674,12 +685,6 @@ namespace TShockAPI
NetMessage.SendData(44, i, -1, "", plr, (float)1, (float)9999999, (float)0); NetMessage.SendData(44, i, -1, "", plr, (float)1, (float)9999999, (float)0);
} }
public static void SendDataAll(int type, int ignore = -1, string text = "", int num = 0, float f1 = 0f, float f2 = 0f, float f3 = 0f)
{
for (int i = 0; i < Main.player.Length; i++)
NetMessage.SendData(type, i, ignore, text, num, f1, f2, f3);
}
//TODO : Notify the player if there is more than one match. (or do we want a First() kinda thing?) //TODO : Notify the player if there is more than one match. (or do we want a First() kinda thing?)
public static int GetNPCID(string name, bool exact = false) public static int GetNPCID(string name, bool exact = false)
{ {