Added MaxSlots (Kicks player if full)
This commit is contained in:
parent
1429595c5b
commit
73f17b0260
4 changed files with 835 additions and 824 deletions
File diff suppressed because it is too large
Load diff
|
|
@ -1,30 +1,32 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
namespace TShockAPI
|
namespace TShockAPI
|
||||||
{
|
{
|
||||||
class ConfigFile
|
class ConfigFile
|
||||||
{
|
{
|
||||||
public ConfigFile() { }
|
public ConfigFile() { }
|
||||||
public int InvasionMultiplier = 1;
|
|
||||||
public int DefaultMaximumSpawns = 4;
|
public int InvasionMultiplier = 1;
|
||||||
public int DefaultSpawnRate = 700;
|
public int DefaultMaximumSpawns = 4;
|
||||||
public int ServerPort = 7777;
|
public int DefaultSpawnRate = 700;
|
||||||
public bool EnableWhitelist = false;
|
public int ServerPort = 7777;
|
||||||
public bool InfiniteInvasion = false;
|
public bool EnableWhitelist = false;
|
||||||
public bool AlwaysPvP = false;
|
public bool InfiniteInvasion = false;
|
||||||
public bool KickCheaters = true;
|
public bool AlwaysPvP = false;
|
||||||
public bool BanCheaters = true;
|
public bool KickCheaters = true;
|
||||||
public bool KickGriefers = true;
|
public bool BanCheaters = true;
|
||||||
public bool BanGriefers = true;
|
public bool KickGriefers = true;
|
||||||
public bool BanKillTileAbusers = false;
|
public bool BanGriefers = true;
|
||||||
public bool KickKillTileAbusers = false;
|
public bool BanKillTileAbusers = false;
|
||||||
public bool BanExplosives = true;
|
public bool KickKillTileAbusers = false;
|
||||||
public bool KickExplosives = true;
|
public bool BanExplosives = true;
|
||||||
public bool SpawnProtection = true;
|
public bool KickExplosives = true;
|
||||||
public int SpawnProtectionRadius = 5;
|
public bool SpawnProtection = true;
|
||||||
public string DistributationAgent = "facepunch";
|
public int SpawnProtectionRadius = 5;
|
||||||
}
|
public string DistributationAgent = "facepunch";
|
||||||
}
|
public int MaxSlots = 8;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,109 +1,112 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.IO;
|
||||||
using System.Text;
|
using System.Linq;
|
||||||
using System.IO;
|
using System.Text;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace TShockAPI
|
namespace TShockAPI
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Provides all the stupid little variables a home away from home.
|
/// Provides all the stupid little variables a home away from home.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
class ConfigurationManager
|
class ConfigurationManager
|
||||||
{
|
{
|
||||||
public static int invasionMultiplier = 1;
|
public static int invasionMultiplier = 1;
|
||||||
public static int defaultMaxSpawns = 4;
|
public static int defaultMaxSpawns = 4;
|
||||||
public static int defaultSpawnRate = 700;
|
public static int defaultSpawnRate = 700;
|
||||||
public static int serverPort = 7777;
|
public static int serverPort = 7777;
|
||||||
public static bool enableWhitelist = false;
|
public static bool enableWhitelist = false;
|
||||||
public static bool infiniteInvasion = false;
|
public static bool infiniteInvasion = false;
|
||||||
public static bool permaPvp = false;
|
public static bool permaPvp = false;
|
||||||
public static int killCount = 0;
|
public static int killCount = 0;
|
||||||
public static bool startedInvasion = false;
|
public static bool startedInvasion = false;
|
||||||
public static bool kickCheater = true;
|
public static bool kickCheater = true;
|
||||||
public static bool banCheater = true;
|
public static bool banCheater = true;
|
||||||
public static bool kickGriefer = true;
|
public static bool kickGriefer = true;
|
||||||
public static bool banGriefer = true;
|
public static bool banGriefer = true;
|
||||||
public static bool banTnt = false;
|
public static bool banTnt = false;
|
||||||
public static bool kickTnt = false;
|
public static bool kickTnt = false;
|
||||||
public static bool banBoom = true;
|
public static bool banBoom = true;
|
||||||
public static bool kickBoom = true;
|
public static bool kickBoom = true;
|
||||||
public static bool spawnProtect = true;
|
public static bool spawnProtect = true;
|
||||||
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
|
||||||
WORLD_EATER = 0,
|
{
|
||||||
EYE = 1,
|
WORLD_EATER = 0,
|
||||||
SKELETRON = 2
|
EYE = 1,
|
||||||
}
|
SKELETRON = 2
|
||||||
|
}
|
||||||
public static void ReadJsonConfiguration()
|
|
||||||
{
|
public static void ReadJsonConfiguration()
|
||||||
TextReader tr = new StreamReader(FileTools.SaveDir + "config.json");
|
{
|
||||||
ConfigFile cfg = JsonConvert.DeserializeObject<ConfigFile>(tr.ReadToEnd());
|
TextReader tr = new StreamReader(FileTools.SaveDir + "config.json");
|
||||||
tr.Close();
|
ConfigFile cfg = JsonConvert.DeserializeObject<ConfigFile>(tr.ReadToEnd());
|
||||||
|
tr.Close();
|
||||||
invasionMultiplier = cfg.InvasionMultiplier;
|
|
||||||
defaultMaxSpawns = cfg.DefaultMaximumSpawns;
|
invasionMultiplier = cfg.InvasionMultiplier;
|
||||||
defaultSpawnRate = cfg.DefaultSpawnRate;
|
defaultMaxSpawns = cfg.DefaultMaximumSpawns;
|
||||||
serverPort = cfg.ServerPort;
|
defaultSpawnRate = cfg.DefaultSpawnRate;
|
||||||
enableWhitelist = cfg.EnableWhitelist;
|
serverPort = cfg.ServerPort;
|
||||||
infiniteInvasion = cfg.InfiniteInvasion;
|
enableWhitelist = cfg.EnableWhitelist;
|
||||||
permaPvp = cfg.AlwaysPvP;
|
infiniteInvasion = cfg.InfiniteInvasion;
|
||||||
kickCheater = cfg.KickCheaters;
|
permaPvp = cfg.AlwaysPvP;
|
||||||
banCheater = cfg.BanCheaters;
|
kickCheater = cfg.KickCheaters;
|
||||||
kickGriefer = cfg.KickGriefers;
|
banCheater = cfg.BanCheaters;
|
||||||
banGriefer = cfg.BanGriefers;
|
kickGriefer = cfg.KickGriefers;
|
||||||
banTnt = cfg.BanKillTileAbusers;
|
banGriefer = cfg.BanGriefers;
|
||||||
kickTnt = cfg.KickKillTileAbusers;
|
banTnt = cfg.BanKillTileAbusers;
|
||||||
banBoom = cfg.BanExplosives;
|
kickTnt = cfg.KickKillTileAbusers;
|
||||||
kickBoom = cfg.KickExplosives;
|
banBoom = cfg.BanExplosives;
|
||||||
spawnProtect = cfg.SpawnProtection;
|
kickBoom = cfg.KickExplosives;
|
||||||
spawnProtectRadius = cfg.SpawnProtectionRadius;
|
spawnProtect = cfg.SpawnProtection;
|
||||||
distributationAgent = cfg.DistributationAgent;
|
spawnProtectRadius = cfg.SpawnProtectionRadius;
|
||||||
Terraria.NPC.maxSpawns = defaultMaxSpawns;
|
distributationAgent = cfg.DistributationAgent;
|
||||||
Terraria.NPC.defaultSpawnRate = defaultSpawnRate;
|
maxSlots = cfg.MaxSlots;
|
||||||
}
|
Terraria.NPC.maxSpawns = defaultMaxSpawns;
|
||||||
|
Terraria.NPC.defaultSpawnRate = defaultSpawnRate;
|
||||||
public static void WriteJsonConfiguration()
|
}
|
||||||
{
|
|
||||||
if (!System.IO.Directory.Exists(FileTools.SaveDir))
|
public static void WriteJsonConfiguration()
|
||||||
{
|
{
|
||||||
System.IO.Directory.CreateDirectory(FileTools.SaveDir);
|
if (!System.IO.Directory.Exists(FileTools.SaveDir))
|
||||||
}
|
{
|
||||||
if (System.IO.File.Exists(FileTools.SaveDir + "config.json"))
|
System.IO.Directory.CreateDirectory(FileTools.SaveDir);
|
||||||
{
|
}
|
||||||
return;
|
if (System.IO.File.Exists(FileTools.SaveDir + "config.json"))
|
||||||
}
|
{
|
||||||
else
|
return;
|
||||||
FileTools.CreateFile(FileTools.SaveDir + "config.json");
|
}
|
||||||
ConfigFile cfg = new ConfigFile();
|
else
|
||||||
cfg.InvasionMultiplier = 50;
|
FileTools.CreateFile(FileTools.SaveDir + "config.json");
|
||||||
cfg.DefaultMaximumSpawns = 4;
|
ConfigFile cfg = new ConfigFile();
|
||||||
cfg.DefaultSpawnRate = 700;
|
cfg.InvasionMultiplier = 50;
|
||||||
cfg.ServerPort = 7777;
|
cfg.DefaultMaximumSpawns = 4;
|
||||||
cfg.EnableWhitelist = false;
|
cfg.DefaultSpawnRate = 700;
|
||||||
cfg.InfiniteInvasion = false;
|
cfg.ServerPort = 7777;
|
||||||
cfg.AlwaysPvP = false;
|
cfg.EnableWhitelist = false;
|
||||||
cfg.KickCheaters = kickCheater;
|
cfg.InfiniteInvasion = false;
|
||||||
cfg.BanCheaters = banCheater;
|
cfg.AlwaysPvP = false;
|
||||||
cfg.KickGriefers = kickGriefer;
|
cfg.KickCheaters = kickCheater;
|
||||||
cfg.BanGriefers = banGriefer;
|
cfg.BanCheaters = banCheater;
|
||||||
cfg.BanKillTileAbusers = true;
|
cfg.KickGriefers = kickGriefer;
|
||||||
cfg.KickKillTileAbusers = true;
|
cfg.BanGriefers = banGriefer;
|
||||||
cfg.BanExplosives = true;
|
cfg.BanKillTileAbusers = true;
|
||||||
cfg.KickExplosives = true;
|
cfg.KickKillTileAbusers = true;
|
||||||
cfg.SpawnProtection = true;
|
cfg.BanExplosives = true;
|
||||||
cfg.SpawnProtectionRadius = 5;
|
cfg.KickExplosives = true;
|
||||||
|
cfg.SpawnProtection = true;
|
||||||
string json = JsonConvert.SerializeObject(cfg, Formatting.Indented);
|
cfg.SpawnProtectionRadius = 5;
|
||||||
TextWriter tr = new StreamWriter(FileTools.SaveDir + "config.json");
|
cfg.MaxSlots = maxSlots;
|
||||||
tr.Write(json);
|
|
||||||
tr.Close();
|
string json = JsonConvert.SerializeObject(cfg, Formatting.Indented);
|
||||||
}
|
TextWriter tr = new StreamWriter(FileTools.SaveDir + "config.json");
|
||||||
}
|
tr.Write(json);
|
||||||
}
|
tr.Close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -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)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue