mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-23 12:42:22 -04:00
Improve /ctf - move blue/red spawn to set sub-command, add add/remove sub-command.
This commit is contained in:
parent
ba6b80fa44
commit
acede04292
@ -16,6 +16,7 @@
|
|||||||
permissions and limitations under the Licenses.
|
permissions and limitations under the Licenses.
|
||||||
*/
|
*/
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using MCGalaxy.Games;
|
using MCGalaxy.Games;
|
||||||
|
|
||||||
@ -30,41 +31,100 @@ namespace MCGalaxy.Commands.Fun {
|
|||||||
|
|
||||||
public override void Use(Player p, string message) {
|
public override void Use(Player p, string message) {
|
||||||
if (message.CaselessEq("start")) {
|
if (message.CaselessEq("start")) {
|
||||||
if (Server.ctf == null) {
|
HandleStart(p);
|
||||||
Player.Message(p, "Initialising CTF..");
|
} else if (message.CaselessEq("stop")) {
|
||||||
Server.ctf = new CTFGame();
|
HandleStop(p);
|
||||||
}
|
} else if (message.CaselessEq("add")) {
|
||||||
|
HandleAdd(p);
|
||||||
if (!Server.ctf.Start(p)) return;
|
} else if (message.CaselessEq("remove")) {
|
||||||
Chat.MessageGlobal("A CTF GAME IS STARTING AT CTF! TYPE /goto CTF to join!");
|
HandleRemove(p);
|
||||||
} else if (message.CaselessEq("stop")) {
|
} else if (message.CaselessStarts("set ")) {
|
||||||
if (Server.ctf == null || !Server.ctf.started) {
|
string[] args = message.SplitSpaces(2);
|
||||||
Player.Message(p, "No CTF game is active."); return;
|
HandleSet(p, args[1]);
|
||||||
}
|
} else {
|
||||||
Server.ctf.Stop();
|
Help(p);
|
||||||
} else if (message.CaselessEq("bluespawn")) {
|
|
||||||
CTFConfig cfg = Retrieve(p);
|
|
||||||
cfg.BlueSpawnX = p.Pos.X; cfg.BlueSpawnY = p.Pos.Y; cfg.BlueSpawnZ = p.Pos.Z;
|
|
||||||
|
|
||||||
Update(p, cfg);
|
|
||||||
Player.Message(p, "Set spawn of blue team to your position.");
|
|
||||||
} else if (message.CaselessEq("redspawn")) {
|
|
||||||
CTFConfig cfg = Retrieve(p);
|
|
||||||
cfg.RedSpawnX = p.Pos.X; cfg.RedSpawnY = p.Pos.Y; cfg.RedSpawnZ = p.Pos.Z;
|
|
||||||
|
|
||||||
Update(p, cfg);
|
|
||||||
Player.Message(p, "Set spawn of red team to your position.");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static CTFConfig Retrieve(Player p) {
|
static void HandleStart(Player p) {
|
||||||
|
if (Server.ctf == null) {
|
||||||
|
Player.Message(p, "Initialising CTF..");
|
||||||
|
Server.ctf = new CTFGame();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!Server.ctf.Start(p)) return;
|
||||||
|
Chat.MessageGlobal("A CTF GAME IS STARTING AT CTF! TYPE /goto CTF to join!");
|
||||||
|
}
|
||||||
|
|
||||||
|
static void HandleStop(Player p) {
|
||||||
|
if (Server.ctf == null || !Server.ctf.started) {
|
||||||
|
Player.Message(p, "No CTF game is active."); return;
|
||||||
|
}
|
||||||
|
Server.ctf.Stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void HandleAdd(Player p) {
|
||||||
|
if (!Directory.Exists("CTF")) Directory.CreateDirectory("CTF");
|
||||||
|
List<string> maps = GetCtfMaps();
|
||||||
|
|
||||||
|
if (maps.CaselessContains(p.level.name)) {
|
||||||
|
Player.Message(p, "{0} %Sis already in the list of CTF maps.", p.level.ColoredName);
|
||||||
|
} else {
|
||||||
|
Player.Message(p, "Added {0} %Sto the list of CTF maps.", p.level.ColoredName);
|
||||||
|
maps.Add(p.level.name);
|
||||||
|
UpdateCtfMaps(maps);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void HandleRemove(Player p) {
|
||||||
|
if (!Directory.Exists("CTF")) Directory.CreateDirectory("CTF");
|
||||||
|
List<string> maps = GetCtfMaps();
|
||||||
|
|
||||||
|
if (!maps.CaselessRemove(p.level.name)) {
|
||||||
|
Player.Message(p, "{0} %Swas not in the list of CTF maps.", p.level.ColoredName);
|
||||||
|
} else {
|
||||||
|
Player.Message(p, "Removed {0} %Sfrom the list of CTF maps.", p.level.ColoredName);
|
||||||
|
UpdateCtfMaps(maps);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static List<string> GetCtfMaps() {
|
||||||
|
if (!File.Exists("CTF/maps.config")) return new List<string>();
|
||||||
|
string[] lines = File.ReadAllLines("CTF/maps.config");
|
||||||
|
return new List<string>(lines);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void UpdateCtfMaps(List<string> maps) {
|
||||||
|
File.WriteAllLines("CTF/maps.config", maps.ToArray());
|
||||||
|
if (Server.ctf != null) Server.ctf.UpdateMapList();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void HandleSet(Player p, string property) {
|
||||||
|
CTFConfig cfg = RetrieveConfig(p);
|
||||||
|
|
||||||
|
if (property.CaselessEq("bluespawn")) {
|
||||||
|
cfg.BlueSpawnX = p.Pos.X; cfg.BlueSpawnY = p.Pos.Y; cfg.BlueSpawnZ = p.Pos.Z;
|
||||||
|
Player.Message(p, "Set spawn of blue team to your position.");
|
||||||
|
UpdateConfig(p, cfg);
|
||||||
|
} else if (property.CaselessEq("redspawn")) {
|
||||||
|
cfg.RedSpawnX = p.Pos.X; cfg.RedSpawnY = p.Pos.Y; cfg.RedSpawnZ = p.Pos.Z;
|
||||||
|
Player.Message(p, "Set spawn of red team to your position.");
|
||||||
|
UpdateConfig(p, cfg);
|
||||||
|
} else {
|
||||||
|
Help(p, "set");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static CTFConfig RetrieveConfig(Player p) {
|
||||||
CTFConfig cfg = new CTFConfig();
|
CTFConfig cfg = new CTFConfig();
|
||||||
cfg.SetDefaults(p.level);
|
cfg.SetDefaults(p.level);
|
||||||
cfg.Retrieve(p.level.name);
|
cfg.Retrieve(p.level.name);
|
||||||
return cfg;
|
return cfg;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void Update(Player p, CTFConfig cfg) {
|
static void UpdateConfig(Player p, CTFConfig cfg) {
|
||||||
if (!Directory.Exists("CTF")) Directory.CreateDirectory("CTF");
|
if (!Directory.Exists("CTF")) Directory.CreateDirectory("CTF");
|
||||||
cfg.Save(p.level.name);
|
cfg.Save(p.level.name);
|
||||||
if (Server.ctf != null && p.level == Server.ctf.map) Server.ctf.UpdateConfig();
|
if (Server.ctf != null && p.level == Server.ctf.map) Server.ctf.UpdateConfig();
|
||||||
@ -73,8 +133,19 @@ namespace MCGalaxy.Commands.Fun {
|
|||||||
public override void Help(Player p) {
|
public override void Help(Player p) {
|
||||||
Player.Message(p, "%T/ctf start/stop");
|
Player.Message(p, "%T/ctf start/stop");
|
||||||
Player.Message(p, "%HStarts/stops the CTF game.");
|
Player.Message(p, "%HStarts/stops the CTF game.");
|
||||||
Player.Message(p, "%T/ctf redspawn/bluespawn");
|
Player.Message(p, "%T/ctf add/remove");
|
||||||
Player.Message(p, "%HSets spawn of red/blue team to your position.");
|
Player.Message(p, "%HAdds or removes current map from list of CTF maps.");
|
||||||
|
Player.Message(p, "%T/ctf set [property]");
|
||||||
|
Player.Message(p, "%HSets a CTF game property, see %T/help ctf set");
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Help(Player p, string message) {
|
||||||
|
if (message.CaselessEq("set")) {
|
||||||
|
Player.Message(p, "%T/ctf set redspawn/bluespawn");
|
||||||
|
Player.Message(p, "%HSets spawn of red/blue team to your position.");
|
||||||
|
} else {
|
||||||
|
Help(p);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -38,12 +38,8 @@ namespace MCGalaxy.Games {
|
|||||||
public sealed partial class CTFGame {
|
public sealed partial class CTFGame {
|
||||||
public System.Timers.Timer tagging = new System.Timers.Timer(500);
|
public System.Timers.Timer tagging = new System.Timers.Timer(500);
|
||||||
public bool voting = false;
|
public bool voting = false;
|
||||||
int vote1 = 0;
|
int vote1 = 0, vote2 = 0, vote3 = 0;
|
||||||
int vote2 = 0;
|
string map1 = "", map2 = "", map3 = "";
|
||||||
int vote3 = 0;
|
|
||||||
string map1 = "";
|
|
||||||
string map2 = "";
|
|
||||||
string map3 = "";
|
|
||||||
public bool started = false;
|
public bool started = false;
|
||||||
|
|
||||||
CtfTeam2 red;
|
CtfTeam2 red;
|
||||||
@ -111,7 +107,7 @@ namespace MCGalaxy.Games {
|
|||||||
blue.SpawnPos = new Position(cfg.BlueSpawnX, cfg.BlueSpawnY, cfg.BlueSpawnZ);
|
blue.SpawnPos = new Position(cfg.BlueSpawnX, cfg.BlueSpawnY, cfg.BlueSpawnZ);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LoadConfig() {
|
public bool UpdateMapList() {
|
||||||
//Load some configs
|
//Load some configs
|
||||||
if (!Directory.Exists("CTF")) Directory.CreateDirectory("CTF");
|
if (!Directory.Exists("CTF")) Directory.CreateDirectory("CTF");
|
||||||
if (!File.Exists("CTF/maps.config")) return false;
|
if (!File.Exists("CTF/maps.config")) return false;
|
||||||
@ -185,7 +181,7 @@ namespace MCGalaxy.Games {
|
|||||||
if (started) {
|
if (started) {
|
||||||
Player.Message(p, "CTF game already running."); return false;
|
Player.Message(p, "CTF game already running."); return false;
|
||||||
}
|
}
|
||||||
if (!LoadConfig()) {
|
if (!UpdateMapList()) {
|
||||||
Player.Message(p, "No CTF maps were found."); return false;
|
Player.Message(p, "No CTF maps were found."); return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -298,10 +298,6 @@ namespace MCGalaxy {
|
|||||||
Send(buffer);
|
Send(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SendExtAddPlayerName(byte id, string listName, string displayName, string grp, byte grpRank) {
|
|
||||||
Send(Packet.ExtAddPlayerName(id, listName, displayName, grp, grpRank, hasCP437));
|
|
||||||
}
|
|
||||||
|
|
||||||
internal void CloseSocket() {
|
internal void CloseSocket() {
|
||||||
socket.Close();
|
socket.Close();
|
||||||
RemoveFromPending();
|
RemoveFromPending();
|
||||||
|
@ -34,7 +34,7 @@ namespace MCGalaxy {
|
|||||||
|
|
||||||
string name, group;
|
string name, group;
|
||||||
GetEntry(p, dst, out name, out group);
|
GetEntry(p, dst, out name, out group);
|
||||||
dst.SendExtAddPlayerName(id, p.truename, name, group, grpPerm);
|
dst.Send(Packet.ExtAddPlayerName(id, p.truename, name, group, grpPerm, dst.hasCP437));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary> Gets the name and the group name for the given player. </summary>
|
/// <summary> Gets the name and the group name for the given player. </summary>
|
||||||
@ -53,7 +53,7 @@ namespace MCGalaxy {
|
|||||||
/// <summary> Adds the given bot to that player's tab list (if their client support it). </summary>
|
/// <summary> Adds the given bot to that player's tab list (if their client support it). </summary>
|
||||||
public static void Add(Player dst, PlayerBot b) {
|
public static void Add(Player dst, PlayerBot b) {
|
||||||
if (!dst.hasExtList) return;
|
if (!dst.hasExtList) return;
|
||||||
dst.SendExtAddPlayerName(b.id, b.SkinName, b.color + b.name, "Bots", 0);
|
dst.Send(Packet.ExtAddPlayerName(b.id, b.SkinName, b.color + b.name, "Bots", 0, dst.hasCP437));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary> Removes the given player from player's tab list (if their client supports it). </summary>
|
/// <summary> Removes the given player from player's tab list (if their client supports it). </summary>
|
||||||
|
@ -55,9 +55,9 @@ namespace MCGalaxy {
|
|||||||
public static INetworkListen Listener;
|
public static INetworkListen Listener;
|
||||||
|
|
||||||
//Other
|
//Other
|
||||||
public static bool UseCTF = false;
|
|
||||||
public static bool ServerSetupFinished = false;
|
public static bool ServerSetupFinished = false;
|
||||||
public static CTFGame ctf = null;
|
public static CTFGame ctf;
|
||||||
|
|
||||||
public static PlayerList bannedIP, whiteList, ircControllers, invalidIds;
|
public static PlayerList bannedIP, whiteList, ircControllers, invalidIds;
|
||||||
public static PlayerList ignored, hidden, agreed, vip, noEmotes, lockdown;
|
public static PlayerList ignored, hidden, agreed, vip, noEmotes, lockdown;
|
||||||
public static PlayerExtList models, skins, reach, rotations;
|
public static PlayerExtList models, skins, reach, rotations;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user