Ajout des parties et meilleur /help
This commit is contained in:
parent
c8920ef977
commit
1cee2fc962
|
@ -6,6 +6,11 @@ namespace Galactic_Colors_Control_GUI
|
|||
{
|
||||
static class Utilities
|
||||
{
|
||||
/// <summary>
|
||||
/// Load Texture2D from files
|
||||
/// </summary>
|
||||
/// <param name="path">File .png path</param>
|
||||
/// <param name="sprite">Result sprite</param>
|
||||
static public void SpriteFromPng(string path, ref Texture2D sprite, GraphicsDevice graphics)
|
||||
{
|
||||
if (File.Exists(path))
|
||||
|
@ -17,6 +22,11 @@ namespace Galactic_Colors_Control_GUI
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Load SoundEffect from files
|
||||
/// </summary>
|
||||
/// <param name="path">File .mp3 path</param>
|
||||
/// <param name="sound">Result sound</param>
|
||||
static public void SoundFromMp3(string path, ref SoundEffect sound)
|
||||
{
|
||||
if (File.Exists(path))
|
||||
|
|
|
@ -9,7 +9,7 @@ namespace Galactic_Colors_Control_Server.Commands
|
|||
{
|
||||
public string Name { get { return "help"; } }
|
||||
public string DescText { get { return "Shows the help."; } }
|
||||
public string HelpText { get { return "Use /help [command] to display command help."; } }
|
||||
public string HelpText { get { return "Use /help [command] to display command help. (-all for full help)"; } }
|
||||
public Manager.CommandGroup Group { get { return Manager.CommandGroup.root; } }
|
||||
public bool IsServer { get { return true; } }
|
||||
public bool IsClient { get { return true; } }
|
||||
|
@ -20,7 +20,14 @@ namespace Galactic_Colors_Control_Server.Commands
|
|||
|
||||
public void Execute(string[] args, Socket soc, bool server = false)
|
||||
{
|
||||
if(args.Length == 1)
|
||||
bool isGroup = false;
|
||||
bool isAll = false;
|
||||
if (args.Length == 2)
|
||||
{
|
||||
isGroup = Enum.GetNames(typeof(Manager.CommandGroup)).Contains(args[1]);
|
||||
isAll = (args[1] == "-all");
|
||||
}
|
||||
if (args.Length == 1 || (isGroup || isAll))
|
||||
{
|
||||
int maxLen = 0;
|
||||
List<ICommand> list = new List<ICommand>();
|
||||
|
@ -28,8 +35,11 @@ namespace Galactic_Colors_Control_Server.Commands
|
|||
{
|
||||
if(Manager.CanAccess(com, soc, server))
|
||||
{
|
||||
list.Add(com);
|
||||
if(com.Name.Length + (com.Group == 0 ? 0 : 4) > maxLen) { maxLen = com.Name.Length + (com.Group == 0 ? 0 : 4); }
|
||||
if (!isGroup || (isGroup && com.Group == (Manager.CommandGroup)Enum.Parse(typeof(Manager.CommandGroup), args[1])))
|
||||
{
|
||||
list.Add(com);
|
||||
if (com.Name.Length + (com.Group == 0 ? 0 : 4) > maxLen) { maxLen = com.Name.Length + (com.Group == 0 ? 0 : 4); }
|
||||
}
|
||||
}
|
||||
}
|
||||
list.Sort((x,y) => x.Group.CompareTo(y.Group));
|
||||
|
@ -39,10 +49,13 @@ namespace Galactic_Colors_Control_Server.Commands
|
|||
{
|
||||
if(com.Group != actualGroup)
|
||||
{
|
||||
text += (Environment.NewLine + " " + com.Group.ToString() + Environment.NewLine);
|
||||
text += (Environment.NewLine + " " + com.Group.ToString() + Environment.NewLine + ((isGroup || isAll) ? "" : (" Use /help " + com.Group.ToString())));
|
||||
actualGroup = com.Group;
|
||||
}
|
||||
text += (" " + (com.Group != 0 ? new string(' ',4) : "") + com.Name + new string(' ', maxLen - com.Name.Length - (com.Group == 0 ? 0 : 4)) + " : " + com.DescText + Environment.NewLine);
|
||||
if ((!(isGroup || isAll) && com.Group == 0) || (isGroup || isAll))
|
||||
{
|
||||
text += (" " + (com.Group != 0 ? new string(' ', 4) : "") + com.Name + new string(' ', maxLen - com.Name.Length - (com.Group == 0 ? 0 : 4)) + " : " + com.DescText + Environment.NewLine);
|
||||
}
|
||||
}
|
||||
Utilities.Return(text, soc, server);
|
||||
}
|
||||
|
|
|
@ -44,7 +44,7 @@ namespace Galactic_Colors_Control_Server.Commands
|
|||
}
|
||||
else
|
||||
{
|
||||
if (args.Length > command.minArgs)
|
||||
if (args.Length - (command.Group == 0 ? 0 : 1) > command.minArgs)
|
||||
{
|
||||
if (args.Length - (command.Group == 0 ? 1 : 2) <= command.maxArgs)
|
||||
{
|
||||
|
@ -52,7 +52,7 @@ namespace Galactic_Colors_Control_Server.Commands
|
|||
}
|
||||
else
|
||||
{
|
||||
Utilities.Return("Command " + CommandToString(command) + " require at most " + command.minArgs + " argument(s).", soc, server);
|
||||
Utilities.Return("Command " + CommandToString(command) + " require at most " + command.maxArgs + " argument(s).", soc, server);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -81,6 +81,10 @@ namespace Galactic_Colors_Control_Server.Commands
|
|||
return text;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Convert command args in readable string
|
||||
/// </summary>
|
||||
/// <param name="args">Command args</param>
|
||||
public static string CommandToString(string[] args)
|
||||
{
|
||||
if (args.Length > 0)
|
||||
|
@ -98,6 +102,12 @@ namespace Galactic_Colors_Control_Server.Commands
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Try to get a command
|
||||
/// </summary>
|
||||
/// <param name="args">command args</param>
|
||||
/// <param name="command">Command result</param>
|
||||
/// <returns>Correct command</returns>
|
||||
public static bool TryGetCommand(string[] args, ref ICommand command)
|
||||
{
|
||||
if (args.Length > 0)
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
using System;
|
||||
using System.Net.Sockets;
|
||||
|
||||
namespace Galactic_Colors_Control_Server.Commands
|
||||
{
|
||||
public class PartyClientCommand : ICommand
|
||||
{
|
||||
public string Name { get { return "client"; } }
|
||||
public string DescText { get { return "Lists party clients."; } }
|
||||
public string HelpText { get { return "Use /party client to show party clients list."; } }
|
||||
public Manager.CommandGroup Group { get { return Manager.CommandGroup.party; } }
|
||||
public bool IsServer { get { return true; } }
|
||||
public bool IsClient { get { return true; } }
|
||||
public bool IsClientSide { get { return false; } }
|
||||
public bool IsNoConnect { get { return false; } }
|
||||
public int minArgs { get { return 0; } }
|
||||
public int maxArgs { get { return 0; } }
|
||||
|
||||
public void Execute(string[] args, Socket soc, bool server = false)
|
||||
{
|
||||
int partyId = -1;
|
||||
if (Utilities.AccessParty(ref partyId, false, soc, server))
|
||||
{
|
||||
string text = " ";
|
||||
foreach(Socket client in Program.parties[partyId].clients)
|
||||
{
|
||||
text += (Utilities.GetName(client) + Environment.NewLine + " ");
|
||||
}
|
||||
Utilities.Return(text, soc, server);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
using System.Net.Sockets;
|
||||
|
||||
namespace Galactic_Colors_Control_Server.Commands
|
||||
{
|
||||
public class PartyCloseCommand : ICommand
|
||||
{
|
||||
public string Name { get { return "close"; } }
|
||||
public string DescText { get { return "Closes party."; } }
|
||||
public string HelpText { get { return "Use /party close to close party for join."; } }
|
||||
public Manager.CommandGroup Group { get { return Manager.CommandGroup.party; } }
|
||||
public bool IsServer { get { return true; } }
|
||||
public bool IsClient { get { return true; } }
|
||||
public bool IsClientSide { get { return false; } }
|
||||
public bool IsNoConnect { get { return false; } }
|
||||
public int minArgs { get { return 0; } }
|
||||
public int maxArgs { get { return 0; } }
|
||||
|
||||
public void Execute(string[] args, Socket soc, bool server = false)
|
||||
{
|
||||
int partyId = -1;
|
||||
if (Utilities.AccessParty(ref partyId, true,soc, server))
|
||||
{
|
||||
if (Program.parties[partyId].open)
|
||||
{
|
||||
Program.parties[partyId].open = false;
|
||||
Utilities.Return("Party closed", soc, server);
|
||||
}
|
||||
else
|
||||
{
|
||||
Utilities.Return("Party allready close", soc, server);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,62 @@
|
|||
using System.Net.Sockets;
|
||||
|
||||
namespace Galactic_Colors_Control_Server.Commands
|
||||
{
|
||||
public class PartyCreateCommand : ICommand
|
||||
{
|
||||
public string Name { get { return "create"; } }
|
||||
public string DescText { get { return "Create new party."; } }
|
||||
public string HelpText { get { return "Use /party create [name] [size] to create new party."; } }
|
||||
public Manager.CommandGroup Group { get { return Manager.CommandGroup.party; } }
|
||||
public bool IsServer { get { return true; } }
|
||||
public bool IsClient { get { return true; } }
|
||||
public bool IsClientSide { get { return false; } }
|
||||
public bool IsNoConnect { get { return false; } }
|
||||
public int minArgs { get { return 2; } }
|
||||
public int maxArgs { get { return 2; } }
|
||||
|
||||
public void Execute(string[] args, Socket soc, bool server = false)
|
||||
{
|
||||
if (server || (!server && Program.clients[soc].partyID == -1))
|
||||
{
|
||||
int size;
|
||||
if (int.TryParse(args[3], out size))
|
||||
{
|
||||
if (size > 0)
|
||||
{
|
||||
if (size <= Program.config.size)
|
||||
{
|
||||
Logger.Write("Party " + args[2] + " create with " + size + " slots as " + Program.partyID, Logger.logType.info);
|
||||
Program.AddParty(new Party(args[2], size, Utilities.GetName(soc)));
|
||||
if (server)
|
||||
{
|
||||
Program.selectedParty = Program.partyID-1;
|
||||
}
|
||||
else
|
||||
{
|
||||
Program.clients[soc].partyID = Program.partyID-1;
|
||||
Utilities.Return("Party " + args[2] + " create with " + size + " slots as " + (Program.partyID-1), soc, server);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Utilities.Return("Too big size", soc, server);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Utilities.Return("Too small size", soc, server);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Utilities.Return("Incorrect argument " + args[3], soc, server);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Utilities.Return("Allready in a party.", soc, server);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,81 @@
|
|||
using System;
|
||||
using System.Net.Sockets;
|
||||
|
||||
namespace Galactic_Colors_Control_Server.Commands
|
||||
{
|
||||
public class PartyJoinCommand : ICommand
|
||||
{
|
||||
public string Name { get { return "join"; } }
|
||||
public string DescText { get { return "Join a party."; } }
|
||||
public string HelpText { get { return "Use /party join [id] <password> to join a party."; } }
|
||||
public Manager.CommandGroup Group { get { return Manager.CommandGroup.party; } }
|
||||
public bool IsServer { get { return true; } }
|
||||
public bool IsClient { get { return true; } }
|
||||
public bool IsClientSide { get { return false; } }
|
||||
public bool IsNoConnect { get { return false; } }
|
||||
public int minArgs { get { return 1; } }
|
||||
public int maxArgs { get { return 2; } }
|
||||
|
||||
public void Execute(string[] args, Socket soc, bool server = false)
|
||||
{
|
||||
if ((server && Program.selectedParty == -1) || (!server && Program.clients[soc].partyID == -1))
|
||||
{
|
||||
int id;
|
||||
if (int.TryParse(args[2], out id))
|
||||
{
|
||||
if (Program.parties.ContainsKey(id))
|
||||
{
|
||||
Party party = Program.parties[id];
|
||||
if (args.Length == 3)
|
||||
{
|
||||
Array.Resize(ref args, 4);
|
||||
args[3] = "";
|
||||
}
|
||||
if (server || (!server && party.TestPassword(args[3])))
|
||||
{
|
||||
if(server)
|
||||
{
|
||||
Program.selectedParty = id;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(party.open)
|
||||
{
|
||||
if (party.clients.Count < party.size)
|
||||
{
|
||||
Program.clients[soc].partyID = id;
|
||||
Utilities.BroadcastParty(Utilities.GetName(soc) + " join the party", Galactic_Colors_Control_Common.Common.dataType.message, id);
|
||||
}
|
||||
else
|
||||
{
|
||||
Utilities.Return("Party is full", soc, server);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Utilities.Return("Party close", soc, server);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Utilities.Return("Wrong party password", soc, server);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Utilities.Return("Can't find party " + id, soc, server);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Utilities.Return("Incorrect argument " + args[3], soc, server);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Utilities.Return("Allready in a party.", soc, server);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
using Galactic_Colors_Control_Common;
|
||||
using System.Net.Sockets;
|
||||
|
||||
namespace Galactic_Colors_Control_Server.Commands
|
||||
{
|
||||
public class PartyKickCommand : ICommand
|
||||
{
|
||||
public string Name { get { return "kick"; } }
|
||||
public string DescText { get { return "Kick player from party."; } }
|
||||
public string HelpText { get { return "Use /party kick [name] <reason> to kick palyer from party"; } }
|
||||
public Manager.CommandGroup Group { get { return Manager.CommandGroup.party; } }
|
||||
public bool IsServer { get { return true; } }
|
||||
public bool IsClient { get { return true; } }
|
||||
public bool IsClientSide { get { return false; } }
|
||||
public bool IsNoConnect { get { return false; } }
|
||||
public int minArgs { get { return 1; } }
|
||||
public int maxArgs { get { return 2; } }
|
||||
|
||||
public void Execute(string[] args, Socket soc, bool server = false)
|
||||
{
|
||||
int partyId = -1;
|
||||
if (Utilities.AccessParty(ref partyId, true, soc, server))
|
||||
{
|
||||
Socket target = null;
|
||||
foreach (Socket client in Program.parties[partyId].clients)
|
||||
{
|
||||
if (Utilities.GetName(client) == args[2]) { target = client; }
|
||||
}
|
||||
if (target != null)
|
||||
{
|
||||
Utilities.BroadcastParty(args[2] + " was kick", Common.dataType.message, partyId);
|
||||
if (args.Length > 3)
|
||||
{
|
||||
Utilities.Send(target, "/party kick " + args[3], Common.dataType.message);
|
||||
}
|
||||
else
|
||||
{
|
||||
Utilities.Send(target, "/party kick", Common.dataType.message);
|
||||
}
|
||||
Manager.Execute(new string[2] { "party", "leave" },target,false);
|
||||
}
|
||||
else
|
||||
{
|
||||
Utilities.Return("Can't find " + args[2] + "in party", soc, server);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
using System.Net.Sockets;
|
||||
|
||||
namespace Galactic_Colors_Control_Server.Commands
|
||||
{
|
||||
public class PartyLeaveCommand : ICommand
|
||||
{
|
||||
public string Name { get { return "leave"; } }
|
||||
public string DescText { get { return "Leave party."; } }
|
||||
public string HelpText { get { return "Use /party leave to leave current party"; } }
|
||||
public Manager.CommandGroup Group { get { return Manager.CommandGroup.party; } }
|
||||
public bool IsServer { get { return true; } }
|
||||
public bool IsClient { get { return true; } }
|
||||
public bool IsClientSide { get { return false; } }
|
||||
public bool IsNoConnect { get { return false; } }
|
||||
public int minArgs { get { return 0; } }
|
||||
public int maxArgs { get { return 0; } }
|
||||
|
||||
public void Execute(string[] args, Socket soc, bool server = false)
|
||||
{
|
||||
if (server)
|
||||
{
|
||||
Program.selectedParty = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
int partyId = -1;
|
||||
if (Utilities.AccessParty(ref partyId, false, soc, server))
|
||||
{
|
||||
if (!Program.parties[partyId].IsOwner(Utilities.GetName(soc)))
|
||||
{
|
||||
Utilities.BroadcastParty(Utilities.GetName(soc) + " leave the party", Galactic_Colors_Control_Common.Common.dataType.message, partyId);
|
||||
Program.clients[soc].partyID = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
Utilities.Return("Owner can't leave party. Look for /party stop", soc, server);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
using System;
|
||||
using System.Net.Sockets;
|
||||
|
||||
namespace Galactic_Colors_Control_Server.Commands
|
||||
{
|
||||
public class PartyListCommand : ICommand
|
||||
{
|
||||
public string Name { get { return "list"; } }
|
||||
public string DescText { get { return "Shows parties list."; } }
|
||||
public string HelpText { get { return "Use /party list to show parties list."; } }
|
||||
public Manager.CommandGroup Group { get { return Manager.CommandGroup.party; } }
|
||||
public bool IsServer { get { return true; } }
|
||||
public bool IsClient { get { return true; } }
|
||||
public bool IsClientSide { get { return false; } }
|
||||
public bool IsNoConnect { get { return false; } }
|
||||
public int minArgs { get { return 0; } }
|
||||
public int maxArgs { get { return 0; } }
|
||||
|
||||
public void Execute(string[] args, Socket soc, bool server = false)
|
||||
{
|
||||
string text = " ";
|
||||
foreach (int key in Program.parties.Keys)
|
||||
{
|
||||
Party party = Program.parties[key];
|
||||
text += (key + " : " + party.name + " : " + party.count + "/" + party.size + " : " + (party.open ? (party.isPrivate ? "private" : "open") : "close") + Environment.NewLine + " ");
|
||||
}
|
||||
Utilities.Return(text, soc, server);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
using System.Net.Sockets;
|
||||
|
||||
namespace Galactic_Colors_Control_Server.Commands
|
||||
{
|
||||
public class PartyOpenCommand : ICommand
|
||||
{
|
||||
public string Name { get { return "open"; } }
|
||||
public string DescText { get { return "Opens party."; } }
|
||||
public string HelpText { get { return "Use /party open to open party for join."; } }
|
||||
public Manager.CommandGroup Group { get { return Manager.CommandGroup.party; } }
|
||||
public bool IsServer { get { return true; } }
|
||||
public bool IsClient { get { return true; } }
|
||||
public bool IsClientSide { get { return false; } }
|
||||
public bool IsNoConnect { get { return false; } }
|
||||
public int minArgs { get { return 0; } }
|
||||
public int maxArgs { get { return 0; } }
|
||||
|
||||
public void Execute(string[] args, Socket soc, bool server = false)
|
||||
{
|
||||
int partyId = -1;
|
||||
if (Utilities.AccessParty(ref partyId, true, soc, server))
|
||||
{
|
||||
if (!Program.parties[partyId].open)
|
||||
{
|
||||
Program.parties[partyId].open = true;
|
||||
Utilities.Return("Party opened", soc, server);
|
||||
}
|
||||
else
|
||||
{
|
||||
Utilities.Return("Party allready open", soc, server);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
using System;
|
||||
using System.Net.Sockets;
|
||||
|
||||
namespace Galactic_Colors_Control_Server.Commands
|
||||
{
|
||||
public class PartyPasswordCommand : ICommand
|
||||
{
|
||||
public string Name { get { return "password"; } }
|
||||
public string DescText { get { return "Set party password."; } }
|
||||
public string HelpText { get { return "Use /party password [newPass] [oldPass] to set party private with password."; } }
|
||||
public Manager.CommandGroup Group { get { return Manager.CommandGroup.party; } }
|
||||
public bool IsServer { get { return true; } }
|
||||
public bool IsClient { get { return true; } }
|
||||
public bool IsClientSide { get { return false; } }
|
||||
public bool IsNoConnect { get { return false; } }
|
||||
public int minArgs { get { return 1; } }
|
||||
public int maxArgs { get { return 2; } }
|
||||
|
||||
public void Execute(string[] args, Socket soc, bool server = false)
|
||||
{
|
||||
int partyId = -1;
|
||||
if (Utilities.AccessParty(ref partyId, true, soc, server))
|
||||
{
|
||||
if (args.Length == 3)
|
||||
{
|
||||
Array.Resize(ref args, 4);
|
||||
args[3] = "";
|
||||
}
|
||||
if (Program.parties[partyId].SetPassword(args[2],args[3]))
|
||||
{
|
||||
Utilities.Return("Password changed", soc, server);
|
||||
}
|
||||
else
|
||||
{
|
||||
Utilities.Return("Can't change password", soc, server);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
using System;
|
||||
using System.Net.Sockets;
|
||||
|
||||
namespace Galactic_Colors_Control_Server.Commands
|
||||
{
|
||||
public class PartyStatusCommand : ICommand
|
||||
{
|
||||
public string Name { get { return "status"; } }
|
||||
public string DescText { get { return "Shows party status."; } }
|
||||
public string HelpText { get { return "Use /party status to show party status."; } }
|
||||
public Manager.CommandGroup Group { get { return Manager.CommandGroup.party; } }
|
||||
public bool IsServer { get { return true; } }
|
||||
public bool IsClient { get { return true; } }
|
||||
public bool IsClientSide { get { return false; } }
|
||||
public bool IsNoConnect { get { return false; } }
|
||||
public int minArgs { get { return 0; } }
|
||||
public int maxArgs { get { return 0; } }
|
||||
|
||||
public void Execute(string[] args, Socket soc, bool server = false)
|
||||
{
|
||||
int partyId = -1;
|
||||
if (Utilities.AccessParty(ref partyId, false, soc, server))
|
||||
{
|
||||
Party party = Program.parties[partyId];
|
||||
string text = "";
|
||||
text += ("Name: " + party.name + Environment.NewLine);
|
||||
text += ("Count: " + party.count + "/" + party.size + Environment.NewLine);
|
||||
text += ("Status: " + (party.isPrivate ? "private" : (party.open ? "open" : "close")));
|
||||
Utilities.Return(text,soc,server);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
using System.Net.Sockets;
|
||||
|
||||
namespace Galactic_Colors_Control_Server.Commands
|
||||
{
|
||||
public class PartyStopCommand : ICommand
|
||||
{
|
||||
public string Name { get { return "stop"; } }
|
||||
public string DescText { get { return "Stop party."; } }
|
||||
public string HelpText { get { return "Use /party stop to stop current party"; } }
|
||||
public Manager.CommandGroup Group { get { return Manager.CommandGroup.party; } }
|
||||
public bool IsServer { get { return true; } }
|
||||
public bool IsClient { get { return true; } }
|
||||
public bool IsClientSide { get { return false; } }
|
||||
public bool IsNoConnect { get { return false; } }
|
||||
public int minArgs { get { return 0; } }
|
||||
public int maxArgs { get { return 0; } }
|
||||
|
||||
public void Execute(string[] args, Socket soc, bool server = false)
|
||||
{
|
||||
int partyId = -1;
|
||||
if (Utilities.AccessParty(ref partyId, true, soc, server))
|
||||
{
|
||||
foreach(Socket client in Program.parties[partyId].clients)
|
||||
{
|
||||
Manager.Execute(new string[4] { "party","kick",Utilities.GetName(client),"stop_party" } ,soc,server);
|
||||
}
|
||||
Logger.Write("Party " + Program.parties[partyId].name + " closed", Logger.logType.info);
|
||||
if(Program.selectedParty == partyId) { Program.selectedParty = -1; }
|
||||
Program.parties.Remove(partyId);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -14,7 +14,7 @@ namespace Galactic_Colors_Control_Server.Commands
|
|||
public bool IsClientSide { get { return false; } }
|
||||
public bool IsNoConnect { get { return false; } }
|
||||
public int minArgs { get { return 0; } }
|
||||
public int maxArgs { get { return 1; } }
|
||||
public int maxArgs { get { return 0; } }
|
||||
|
||||
public void Execute(string[] args, Socket soc, bool server = false)
|
||||
{
|
||||
|
@ -25,7 +25,7 @@ namespace Galactic_Colors_Control_Server.Commands
|
|||
}
|
||||
else
|
||||
{
|
||||
Utilities.ConsoleWrite("Server already close");
|
||||
Utilities.ConsoleWrite("Server allready close");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ namespace Galactic_Colors_Control_Server.Commands
|
|||
public bool IsClientSide { get { return false; } }
|
||||
public bool IsNoConnect { get { return false; } }
|
||||
public int minArgs { get { return 0; } }
|
||||
public int maxArgs { get { return 1; } }
|
||||
public int maxArgs { get { return 0; } }
|
||||
|
||||
public void Execute(string[] args, Socket soc, bool server = false)
|
||||
{
|
||||
|
@ -25,7 +25,7 @@ namespace Galactic_Colors_Control_Server.Commands
|
|||
}
|
||||
else
|
||||
{
|
||||
Utilities.ConsoleWrite("Server already open");
|
||||
Utilities.ConsoleWrite("Server allready open");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
using Galactic_Colors_Control_Common;
|
||||
using System;
|
||||
using System.Net.Sockets;
|
||||
|
||||
namespace Galactic_Colors_Control_Server.Commands
|
||||
{
|
||||
public class ServerStopCommand : ICommand
|
||||
{
|
||||
public string Name { get { return "stop"; } }
|
||||
public string DescText { get { return "Stop the server."; } }
|
||||
public string HelpText { get { return "Use /server stop to completly stop server."; } }
|
||||
public Manager.CommandGroup Group { get { return Manager.CommandGroup.server; } }
|
||||
public bool IsServer { get { return true; } }
|
||||
public bool IsClient { get { return false; } }
|
||||
public bool IsClientSide { get { return false; } }
|
||||
public bool IsNoConnect { get { return false; } }
|
||||
public int minArgs { get { return 0; } }
|
||||
public int maxArgs { get { return 0; } }
|
||||
|
||||
public void Execute(string[] args, Socket soc, bool server = false)
|
||||
{
|
||||
Program._run = false;
|
||||
Utilities.ConsoleWrite("Stop server");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -59,6 +59,17 @@
|
|||
<Compile Include="Client.cs" />
|
||||
<Compile Include="Commands\ClearCommand.cs" />
|
||||
<Compile Include="Commands\Client\StatusCommand.cs" />
|
||||
<Compile Include="Commands\Party\PartyLeaveCommand.cs" />
|
||||
<Compile Include="Commands\Party\PartyCreateCommand.cs" />
|
||||
<Compile Include="Commands\Party\PartyJoinCommand.cs" />
|
||||
<Compile Include="Commands\Party\PartyCloseCommand.cs" />
|
||||
<Compile Include="Commands\Party\PartyClientCommand.cs" />
|
||||
<Compile Include="Commands\Party\PartyStopCommand.cs" />
|
||||
<Compile Include="Commands\Party\PartyPasswordCommand.cs" />
|
||||
<Compile Include="Commands\Party\PartyListCommand.cs" />
|
||||
<Compile Include="Commands\Party\PartyOpenCommand.cs" />
|
||||
<Compile Include="Commands\Party\PartyStatusCommand.cs" />
|
||||
<Compile Include="Commands\Party\PartyKickCommand.cs" />
|
||||
<Compile Include="Commands\PingCommand.cs" />
|
||||
<Compile Include="Commands\Server\ServerOpenCommand.cs" />
|
||||
<Compile Include="Commands\ConnectCommand.cs" />
|
||||
|
@ -106,9 +117,7 @@
|
|||
<Name>Galactic Colors Control Common</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="Commands\Party\" />
|
||||
</ItemGroup>
|
||||
<ItemGroup />
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
|
|
|
@ -0,0 +1,73 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Net.Sockets;
|
||||
|
||||
namespace Galactic_Colors_Control_Server
|
||||
{
|
||||
public class Party
|
||||
{
|
||||
public string name = "";
|
||||
private string password = "";
|
||||
public int size = 0;
|
||||
public bool open = false;
|
||||
private string owner = "";
|
||||
public bool isPrivate { get { return password != ""; } }
|
||||
|
||||
public Party(string Name, int Size, string Owner)
|
||||
{
|
||||
name = Name;
|
||||
size = Size;
|
||||
owner = Owner;
|
||||
}
|
||||
|
||||
public bool IsOwner(string name)
|
||||
{
|
||||
return owner == name;
|
||||
}
|
||||
|
||||
public bool TestPassword(string pass)
|
||||
{
|
||||
if (isPrivate)
|
||||
{
|
||||
return (password == pass) ;
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public bool SetPassword(string newPass, string oldPass)
|
||||
{
|
||||
if (TestPassword(oldPass))
|
||||
{
|
||||
password = newPass;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public int count
|
||||
{
|
||||
get
|
||||
{
|
||||
return clients.Count;
|
||||
}
|
||||
}
|
||||
|
||||
public List<Socket> clients
|
||||
{
|
||||
get
|
||||
{
|
||||
List<Socket> list = new List<Socket>();
|
||||
foreach(Socket soc in Program.clients.Keys)
|
||||
{
|
||||
if(Program.clients[soc].party == this) { list.Add(soc); }
|
||||
}
|
||||
return list;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -19,10 +19,16 @@ namespace Galactic_Colors_Control_Server
|
|||
private static readonly byte[] buffer = new byte[BUFFER_SIZE];
|
||||
|
||||
public static Dictionary<Socket, Client> clients { get; private set; } = new Dictionary<Socket, Client>();
|
||||
public static List<Party> parties { get; private set; } = new List<Party>();
|
||||
|
||||
public static int partyID = 0;
|
||||
public static Dictionary<int,Party> parties { get; private set; } = new Dictionary<int,Party>();
|
||||
public static int selectedParty = -1;
|
||||
|
||||
public static Config config = new Config();
|
||||
|
||||
/// <summary>
|
||||
/// Server Main thread
|
||||
/// </summary>
|
||||
private static void Main(string[] args)
|
||||
{
|
||||
Console.Title = "Galactic Colors Control Server";
|
||||
|
@ -176,35 +182,36 @@ namespace Galactic_Colors_Control_Server
|
|||
var data = new byte[received];
|
||||
Array.Copy(buffer, data, received);
|
||||
|
||||
try {
|
||||
byte[] type = new byte[4];
|
||||
type = data.Take(4).ToArray();
|
||||
type.Reverse();
|
||||
Common.dataType dtype = (Common.dataType)BitConverter.ToInt32(type, 0);
|
||||
byte[] bytes = null;
|
||||
bytes = data.Skip(4).ToArray();
|
||||
switch (dtype)
|
||||
{
|
||||
case Common.dataType.message:
|
||||
string text = Encoding.ASCII.GetString(bytes);
|
||||
ExecuteMessage(text, current);
|
||||
break;
|
||||
//Server crash on command Exception
|
||||
//try {
|
||||
byte[] type = new byte[4];
|
||||
type = data.Take(4).ToArray();
|
||||
type.Reverse();
|
||||
Common.dataType dtype = (Common.dataType)BitConverter.ToInt32(type, 0);
|
||||
byte[] bytes = null;
|
||||
bytes = data.Skip(4).ToArray();
|
||||
switch (dtype)
|
||||
{
|
||||
case Common.dataType.message:
|
||||
string text = Encoding.ASCII.GetString(bytes);
|
||||
ExecuteMessage(text, current);
|
||||
break;
|
||||
|
||||
case Common.dataType.data:
|
||||
Console.WriteLine("data");
|
||||
break;
|
||||
case Common.dataType.data:
|
||||
Console.WriteLine("data");
|
||||
break;
|
||||
|
||||
default:
|
||||
Logger.Write("Unknow type data form" + Utilities.GetName(current), Logger.logType.error);
|
||||
break;
|
||||
}
|
||||
|
||||
if (clients.ContainsKey(current)) { current.BeginReceive(buffer, 0, BUFFER_SIZE, SocketFlags.None, ReceiveCallback, current); }
|
||||
default:
|
||||
Logger.Write("Unknow type data form" + Utilities.GetName(current), Logger.logType.error);
|
||||
break;
|
||||
}
|
||||
|
||||
if (clients.ContainsKey(current)) { current.BeginReceive(buffer, 0, BUFFER_SIZE, SocketFlags.None, ReceiveCallback, current); }
|
||||
/*}
|
||||
catch (Exception) {
|
||||
Logger.Write("Client forcefully disconnected from " + Utilities.GetName(current) + " : ReceiveException", Logger.logType.info);
|
||||
if (clients.ContainsKey(current)) { clients.Remove(current); }
|
||||
}
|
||||
Logger.Write(Utilities.GetName(current) + " : ReceiveException", Logger.logType.info);
|
||||
//if (clients.ContainsKey(current)) { clients.Remove(current); }
|
||||
}*/
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -239,11 +246,29 @@ namespace Galactic_Colors_Control_Server
|
|||
}
|
||||
else
|
||||
{
|
||||
Logger.Write(Utilities.GetName(soc) + " : " + text, Logger.logType.info);
|
||||
Utilities.Broadcast(Utilities.GetName(soc) + " : " + text, Common.dataType.message);
|
||||
int party = -1;
|
||||
if (server)
|
||||
{
|
||||
party = selectedParty;
|
||||
}
|
||||
else
|
||||
{
|
||||
party = clients[soc].partyID;
|
||||
}
|
||||
Utilities.BroadcastParty(Utilities.GetName(soc) + " : " + text, Common.dataType.message, party);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add new party with index
|
||||
/// </summary>
|
||||
/// <param name="party">Party to add</param>
|
||||
public static void AddParty(Party party)
|
||||
{
|
||||
parties.Add(partyID, party);
|
||||
partyID++;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -64,6 +64,8 @@ namespace Galactic_Colors_Control_Server
|
|||
/// Write line in console with correct colors
|
||||
/// </summary>
|
||||
/// <param name="v">Text to write</param>
|
||||
/// <param name="Fore">Foreground color</param>
|
||||
/// <param name="Back">Background color</param>
|
||||
public static void ConsoleWrite(string v, ConsoleColor Fore = ConsoleColor.White, ConsoleColor Back = ConsoleColor.Black)
|
||||
{
|
||||
Console.Write("\b");
|
||||
|
@ -136,6 +138,25 @@ namespace Galactic_Colors_Control_Server
|
|||
{
|
||||
Send(soc, data, dtype);
|
||||
}
|
||||
if (dtype == Common.dataType.message) { ConsoleWrite((string)data); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Send data to all client of the party
|
||||
/// </summary>
|
||||
/// <param name="data">Data to send</param>
|
||||
/// <param name="dtype">Type of data</param>
|
||||
/// <param name="party">Id of the party</param>
|
||||
public static void BroadcastParty(object data, Common.dataType dtype, int party)
|
||||
{
|
||||
foreach(Socket soc in Program.clients.Keys)
|
||||
{
|
||||
if (Program.clients[soc].partyID == party)
|
||||
{
|
||||
Send(soc, data, dtype);
|
||||
}
|
||||
}
|
||||
if (dtype == Common.dataType.message) { if (Program.selectedParty == party) { ConsoleWrite((string)data); } }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -155,5 +176,69 @@ namespace Galactic_Colors_Control_Server
|
|||
Send(soc, message, Common.dataType.message);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Try get party of the socket
|
||||
/// </summary>
|
||||
/// <param name="partyId">Result party ID</param>
|
||||
/// <param name="needOwn">Return true only for owner and server</param>
|
||||
/// <param name="soc">Target socket</param>
|
||||
/// <param name="server">Is server?</param>
|
||||
/// <returns>Can access?</returns>
|
||||
public static bool AccessParty(ref int partyId, bool needOwn, Socket soc = null, bool server = false)
|
||||
{
|
||||
if (server)
|
||||
{
|
||||
if(Program.selectedParty != -1)
|
||||
{
|
||||
if (Program.parties.ContainsKey(Program.selectedParty))
|
||||
{
|
||||
partyId = Program.selectedParty;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger.Write("Can't find party " + Program.selectedParty, Logger.logType.error);
|
||||
Program.selectedParty = -1;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ConsoleWrite("Join a party before");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(Program.clients[soc].partyID != -1)
|
||||
{
|
||||
if (Program.parties.ContainsKey(Program.clients[soc].partyID))
|
||||
{
|
||||
if (Program.parties[Program.clients[soc].partyID].IsOwner(GetName(soc)) || !needOwn)
|
||||
{
|
||||
partyId = Program.clients[soc].partyID;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Send(soc, "You are not owner", Common.dataType.message);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Send(soc, "Can't find party " + Program.clients[soc].partyID, Common.dataType.message);
|
||||
Program.clients[soc].partyID = -1;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Send(soc, "Join a party before", Common.dataType.message);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -271,6 +271,24 @@ namespace Galactic_Colors_Control
|
|||
_run = false;
|
||||
break;
|
||||
|
||||
case "party":
|
||||
if (array[1] == "kick")
|
||||
{
|
||||
if (array.Length > 2)
|
||||
{
|
||||
Output.Add("Kick from party : " + array[2]);
|
||||
}
|
||||
else
|
||||
{
|
||||
Output.Add("Kick from party");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Output.Add("Unknown action from server");
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
Output.Add("Unknown action from server");
|
||||
break;
|
||||
|
|
|
@ -12,9 +12,14 @@ GCC is a cross plateforme C# minimal RTS.
|
|||
|
||||
Download last version for your system
|
||||
|
||||
Linux
|
||||
```
|
||||
sudo apt-get install libopenal-dev mono-runtime
|
||||
```
|
||||
|
||||
## Running
|
||||
|
||||
* Galactic_Colors_Control.exe => Client without GUI
|
||||
* Galactic_Colors_Control_Console.exe => Client without GUI
|
||||
* Galactic_Colors_Control_GUI.exe => Client
|
||||
* Galactic_Colors_Control_Server.exe => Server (Use --debug for DEBUG MODE)
|
||||
|
||||
|
@ -30,6 +35,7 @@ mono <program>.exe --args
|
|||
|
||||
## Contributing
|
||||
|
||||
Get [Monogame](https://github.com/MonoGame/MonoGame) sdk and [MyMonoGame.GUI](https://github.com/sheychen290/MyMonoGame)
|
||||
As you wish, I am opened to new ideas.
|
||||
|
||||
## Author
|
||||
|
|
Reference in New Issue