diff --git a/Galactic Colors Control Common/Galactic Colors Control Common.csproj b/Galactic Colors Control Common/Galactic Colors Control Common.csproj
index 293857c..10505e4 100644
--- a/Galactic Colors Control Common/Galactic Colors Control Common.csproj
+++ b/Galactic Colors Control Common/Galactic Colors Control Common.csproj
@@ -49,7 +49,14 @@
+
+
+
+ True
+ True
+ Resources.resx
+
@@ -57,6 +64,15 @@
+
+
+ ResXFileCodeGenerator
+ Resources.Designer.cs
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+
+ ..\Resources\Lang.csv;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8
+
+
\ No newline at end of file
diff --git a/Galactic Colors Control Common/Resources/Lang.csv b/Galactic Colors Control Common/Resources/Lang.csv
new file mode 100644
index 0000000..44fada4
--- /dev/null
+++ b/Galactic Colors Control Common/Resources/Lang.csv
@@ -0,0 +1,5 @@
+Key;Français;English
+ServerJoin;rejoint le server;join the server
+PartyJoin;rejoint la partie;join the party
+ServerLeave;quitte le server;leave the server
+PartyLeave;quitte la partie;leave the party
\ No newline at end of file
diff --git a/Galactic Colors Control Console/Config.cs b/Galactic Colors Control Console/Config.cs
new file mode 100644
index 0000000..b621703
--- /dev/null
+++ b/Galactic Colors Control Console/Config.cs
@@ -0,0 +1,117 @@
+using Galactic_Colors_Control_Common;
+using System;
+using System.IO;
+using System.Xml;
+using System.Xml.Serialization;
+
+namespace Galactic_Colors_Control_Console
+{
+ [XmlRoot("config")]
+ public class Config
+ {
+ public string logPath = AppDomain.CurrentDomain.BaseDirectory + "Logs";
+ public Logger.logType logLevel = Logger.logType.info;
+ public char commandChar = '/';
+ public ConsoleColor[] logForeColor = new ConsoleColor[6] { ConsoleColor.DarkGray, ConsoleColor.Gray, ConsoleColor.White, ConsoleColor.Yellow, ConsoleColor.Red, ConsoleColor.White };
+ public ConsoleColor[] logBackColor = new ConsoleColor[6] { ConsoleColor.Black, ConsoleColor.Black, ConsoleColor.Black, ConsoleColor.Black, ConsoleColor.Black, ConsoleColor.Red };
+ public int lang = 0;
+
+ ///
+ /// Load config from xml file
+ /// App.config is too easy
+ ///
+ /// Loaded config
+ public Config Load()
+ {
+ Program.logger.Write("Loading config", Logger.logType.info);
+ Config config = new Config();
+ if (File.Exists(AppDomain.CurrentDomain.BaseDirectory + "Config.xml"))
+ {
+ if (CorrectConfig())
+ {
+ XmlSerializer xs = new XmlSerializer(typeof(Config));
+ using (StreamReader re = new StreamReader(AppDomain.CurrentDomain.BaseDirectory + "Config.xml"))
+ {
+ config = xs.Deserialize(re) as Config;
+ };
+ }
+ else
+ {
+ Program.logger.Write("Old config in Config.xml.old", Logger.logType.warm);
+ File.Delete(AppDomain.CurrentDomain.BaseDirectory + "Config.xml.old");
+ File.Move(AppDomain.CurrentDomain.BaseDirectory + "Config.xml", AppDomain.CurrentDomain.BaseDirectory + "Config.xml.old");
+ config.Save();
+ }
+ }
+ else
+ {
+ Program.logger.Write("Any config file", Logger.logType.error);
+ config.Save();
+ }
+ if (Program._debug) { config.logLevel = Logger.logType.debug; }
+ if (Program._dev) { config.logLevel = Logger.logType.dev; }
+ return config;
+ }
+
+ ///
+ /// Write actual config in xml file
+ ///
+ public void Save()
+ {
+ XmlSerializer xs = new XmlSerializer(typeof(Config));
+ if (Program._debug || Program._dev) { logLevel = Logger.logType.info; }
+ using (StreamWriter st = new StreamWriter(AppDomain.CurrentDomain.BaseDirectory + "Config.xml"))
+ {
+ xs.Serialize(st, this);
+ };
+ if (Program._debug) { logLevel = Logger.logType.debug; }
+ if (Program._dev) { logLevel = Logger.logType.dev; }
+ }
+
+ ///
+ /// Check config format using Schema
+ ///
+ public bool CorrectConfig()
+ {
+ bool isCorrect = false;
+
+ using (Stream fs = new FileStream(AppDomain.CurrentDomain.BaseDirectory + "Config.xml", FileMode.Open))
+ {
+ XmlReader re = new XmlTextReader(fs);
+ XmlSerializer xs = new XmlSerializer(typeof(Config));
+ try
+ {
+ isCorrect = xs.CanDeserialize(re);
+ }
+ catch (XmlException e)
+ {
+ isCorrect = false;
+ Program.logger.Write("Error: " + e.Message, Logger.logType.error);
+ }
+ }
+
+ if (isCorrect)
+ {
+ try
+ {
+ XmlDocument d = new XmlDocument();
+ d.Load(AppDomain.CurrentDomain.BaseDirectory + "Config.xml");
+ d.Schemas.Add("", XmlReader.Create("ConfigSchema.xsd"));
+
+ d.Validate((o, e) =>
+ {
+ Program.logger.Write("Error: " + e.Message, Logger.logType.error);
+ isCorrect = false;
+ });
+ }
+ catch (XmlException e)
+ {
+ isCorrect = false;
+ Program.logger.Write("Error: " + e.Message, Logger.logType.error);
+ }
+ }
+
+ return isCorrect;
+ }
+ }
+}
\ No newline at end of file
diff --git a/Galactic Colors Control Console/Galactic Colors Control Console.csproj b/Galactic Colors Control Console/Galactic Colors Control Console.csproj
index 50b8893..f82f6ef 100644
--- a/Galactic Colors Control Console/Galactic Colors Control Console.csproj
+++ b/Galactic Colors Control Console/Galactic Colors Control Console.csproj
@@ -47,6 +47,7 @@
Properties\AssemblyInfoCommon.cs
+
diff --git a/Galactic Colors Control Console/Program.cs b/Galactic Colors Control Console/Program.cs
index dbc657a..8637b21 100644
--- a/Galactic Colors Control Console/Program.cs
+++ b/Galactic Colors Control Console/Program.cs
@@ -11,18 +11,44 @@ namespace Galactic_Colors_Control_Console
///
internal class Program
{
- private static Client client;
- private static bool run = true;
- private static char commandChar = '/';
+ public static bool _debug = false;
+ public static bool _dev = false;
- private static void Main()
+ private static Client client = new Client();
+ private static MultiLang multilang = new MultiLang(); //TODO use multilang
+ public static Config config = new Config();
+ public static Logger logger = new Logger();
+ private static bool run = true;
+
+ private static void Main(string[] args)
{
- client = new Client();
+ config = config.Load();
+ logger.Initialise(config.logPath, config.logBackColor, config.logForeColor, config.logLevel);
+ multilang.Load();
client.OnEvent += new EventHandler(OnEvent); //Set OnEvent function
Console.Title = "Galactic Colors Control Client"; //Start display
Console.Write(">");
Common.ConsoleWrite("Galactic Colors Control Client", ConsoleColor.Red);
Common.ConsoleWrite("Console " + Assembly.GetEntryAssembly().GetName().Version.ToString(), ConsoleColor.Yellow);
+ if (args.Length > 0)
+ {
+ switch (args[0])
+ {
+ case "--debug":
+ _debug = true;
+ logger.Write("CLIENT IS IN DEBUG MODE !", Logger.logType.error, Logger.logConsole.show);
+ break;
+
+ case "--dev":
+ _dev = true;
+ logger.Write("CLIENT IS IN DEV MODE !", Logger.logType.error, Logger.logConsole.show);
+ break;
+
+ default:
+ Common.ConsoleWrite("Use --debug or --dev");
+ break;
+ }
+ }
bool hostSet = false;
while (!hostSet) //Request hostname
{
@@ -78,7 +104,7 @@ namespace Galactic_Colors_Control_Console
return;
string[] req;
- if (input[0] == commandChar)
+ if (input[0] == config.commandChar)
{
input = input.Substring(1);
req = Common.SplitArgs(input);
@@ -93,7 +119,7 @@ namespace Galactic_Colors_Control_Console
private static void OnEvent(object sender, EventArgs e)
{
EventData eve = ((EventDataArgs)e).Data;
- Common.ConsoleWrite(eve.ToSmallString()); //TODO add processing (common)
+ Common.ConsoleWrite(multilang.GetEventText(eve, config.lang));
}
}
}
\ No newline at end of file
diff --git a/Galactic Colors Control GUI/Config.cs b/Galactic Colors Control GUI/Config.cs
new file mode 100644
index 0000000..0632ad9
--- /dev/null
+++ b/Galactic Colors Control GUI/Config.cs
@@ -0,0 +1,117 @@
+using Galactic_Colors_Control_Common;
+using System;
+using System.IO;
+using System.Xml;
+using System.Xml.Serialization;
+
+namespace Galactic_Colors_Control_GUI
+{
+ [XmlRoot("config")]
+ public class Config
+ {
+ public string logPath = AppDomain.CurrentDomain.BaseDirectory + "Logs";
+ public Logger.logType logLevel = Logger.logType.info;
+ public char commandChar = '/';
+ public ConsoleColor[] logForeColor = new ConsoleColor[6] { ConsoleColor.DarkGray, ConsoleColor.Gray, ConsoleColor.White, ConsoleColor.Yellow, ConsoleColor.Red, ConsoleColor.White };
+ public ConsoleColor[] logBackColor = new ConsoleColor[6] { ConsoleColor.Black, ConsoleColor.Black, ConsoleColor.Black, ConsoleColor.Black, ConsoleColor.Black, ConsoleColor.Red };
+ public int lang = 0;
+
+ ///
+ /// Load config from xml file
+ /// App.config is too easy
+ ///
+ /// Loaded config
+ public Config Load()
+ {
+ Game.singleton.logger.Write("Loading config", Logger.logType.info);
+ Config config = new Config();
+ if (File.Exists(AppDomain.CurrentDomain.BaseDirectory + "Config.xml"))
+ {
+ if (CorrectConfig())
+ {
+ XmlSerializer xs = new XmlSerializer(typeof(Config));
+ using (StreamReader re = new StreamReader(AppDomain.CurrentDomain.BaseDirectory + "Config.xml"))
+ {
+ config = xs.Deserialize(re) as Config;
+ };
+ }
+ else
+ {
+ Game.singleton.logger.Write("Old config in Config.xml.old", Logger.logType.warm);
+ File.Delete(AppDomain.CurrentDomain.BaseDirectory + "Config.xml.old");
+ File.Move(AppDomain.CurrentDomain.BaseDirectory + "Config.xml", AppDomain.CurrentDomain.BaseDirectory + "Config.xml.old");
+ config.Save();
+ }
+ }
+ else
+ {
+ Game.singleton.logger.Write("Any config file", Logger.logType.error);
+ config.Save();
+ }
+ if (Program._debug) { config.logLevel = Logger.logType.debug; }
+ if (Program._dev) { config.logLevel = Logger.logType.dev; }
+ return config;
+ }
+
+ ///
+ /// Write actual config in xml file
+ ///
+ public void Save()
+ {
+ XmlSerializer xs = new XmlSerializer(typeof(Config));
+ if (Program._debug || Program._dev) { logLevel = Logger.logType.info; }
+ using (StreamWriter st = new StreamWriter(AppDomain.CurrentDomain.BaseDirectory + "Config.xml"))
+ {
+ xs.Serialize(st, this);
+ };
+ if (Program._debug) { logLevel = Logger.logType.debug; }
+ if (Program._dev) { logLevel = Logger.logType.dev; }
+ }
+
+ ///
+ /// Check config format using Schema
+ ///
+ public bool CorrectConfig()
+ {
+ bool isCorrect = false;
+
+ using (Stream fs = new FileStream(AppDomain.CurrentDomain.BaseDirectory + "Config.xml", FileMode.Open))
+ {
+ XmlReader re = new XmlTextReader(fs);
+ XmlSerializer xs = new XmlSerializer(typeof(Config));
+ try
+ {
+ isCorrect = xs.CanDeserialize(re);
+ }
+ catch (XmlException e)
+ {
+ isCorrect = false;
+ Game.singleton.logger.Write("Error: " + e.Message, Logger.logType.error);
+ }
+ }
+
+ if (isCorrect)
+ {
+ try
+ {
+ XmlDocument d = new XmlDocument();
+ d.Load(AppDomain.CurrentDomain.BaseDirectory + "Config.xml");
+ d.Schemas.Add("", XmlReader.Create("ConfigSchema.xsd"));
+
+ d.Validate((o, e) =>
+ {
+ Game.singleton.logger.Write("Error: " + e.Message, Logger.logType.error);
+ isCorrect = false;
+ });
+ }
+ catch (XmlException e)
+ {
+ isCorrect = false;
+ Game.singleton.logger.Write("Error: " + e.Message, Logger.logType.error);
+ }
+ }
+
+ return isCorrect;
+ }
+ }
+}
\ No newline at end of file
diff --git a/Galactic Colors Control GUI/Galactic Colors Control GUI.csproj b/Galactic Colors Control GUI/Galactic Colors Control GUI.csproj
index eb60deb..513ec85 100644
--- a/Galactic Colors Control GUI/Galactic Colors Control GUI.csproj
+++ b/Galactic Colors Control GUI/Galactic Colors Control GUI.csproj
@@ -45,6 +45,7 @@
Properties\AssemblyInfoCommon.cs
+
diff --git a/Galactic Colors Control GUI/Game.cs b/Galactic Colors Control GUI/Game.cs
index 788f013..f7e68c5 100644
--- a/Galactic Colors Control GUI/Game.cs
+++ b/Galactic Colors Control GUI/Game.cs
@@ -1,4 +1,5 @@
using Galactic_Colors_Control;
+using Galactic_Colors_Control_Common;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
@@ -7,8 +8,6 @@ using Microsoft.Xna.Framework.Input;
using MyMonoGame.GUI;
using System;
using System.IO;
-using System.Reflection;
-using System.Threading;
namespace Galactic_Colors_Control_GUI
{
@@ -33,6 +32,9 @@ namespace Galactic_Colors_Control_GUI
public boxSprites[] buttonsSprites = new boxSprites[1];
public Background background;
+ public MultiLang multilang = new MultiLang();
+ public Config config = new Config();
+ public Logger logger = new Logger();
public Client client; //Client Core
public Manager GUI = new Manager(); //MyMonogameGUI
@@ -72,6 +74,11 @@ namespace Galactic_Colors_Control_GUI
///
protected override void Initialize()
{
+ config = config.Load();
+ logger.Initialise(config.logPath, config.logBackColor, config.logForeColor, config.logLevel);
+ multilang.Load();
+ if (Program._debug) { logger.Write("CLIENT IS IN DEBUG MODE !", Logger.logType.error, Logger.logConsole.show); }
+ if (Program._dev) { logger.Write("CLIENT IS IN DEV MODE !", Logger.logType.error, Logger.logConsole.show); }
nullSprite = new Texture2D(GraphicsDevice, 1, 1);
nullSprite.SetData(new Color[1 * 1] { Color.White });
diff --git a/Galactic Colors Control GUI/Program.cs b/Galactic Colors Control GUI/Program.cs
index 6078cfc..18b1aa6 100644
--- a/Galactic Colors Control GUI/Program.cs
+++ b/Galactic Colors Control GUI/Program.cs
@@ -1,4 +1,5 @@
-using System;
+using Galactic_Colors_Control_Common;
+using System;
namespace Galactic_Colors_Control_GUI
{
@@ -7,13 +8,31 @@ namespace Galactic_Colors_Control_GUI
///
public static class Program
{
+ public static bool _dev = false;
+ public static bool _debug = false;
///
/// The main entry point for the application.
///
[STAThread]
- private static void Main()
+ private static void Main(string[] args)
{
- //TODO add debug and more
+ if (args.Length > 0)
+ {
+ switch (args[0])
+ {
+ case "--debug":
+ _debug = true;
+ break;
+
+ case "--dev":
+ _dev = true;
+ break;
+
+ default:
+ Common.ConsoleWrite("Use --debug or --dev");
+ break;
+ }
+ }
using (var game = new Game())
game.Run();
}
diff --git a/Galactic Colors Control GUI/States/GameState.cs b/Galactic Colors Control GUI/States/GameState.cs
index e0aab0c..e763883 100644
--- a/Galactic Colors Control GUI/States/GameState.cs
+++ b/Galactic Colors Control GUI/States/GameState.cs
@@ -53,50 +53,57 @@ namespace Galactic_Colors_Control_GUI.States
Game.singleton.GUI.Box(new Rectangle(Game.singleton.ScreenWidth / 2 - 150, Game.singleton.ScreenHeight / 4 + 50, 300, 150), Game.singleton.buttonsSprites[0]);
Game.singleton.GUI.Label(new MyMonoGame.Vector(Game.singleton.ScreenWidth / 2, Game.singleton.ScreenHeight / 4 + 60), message.title, Game.singleton.fonts.basic, null, Manager.textAlign.bottomCenter);
Game.singleton.GUI.Label(new MyMonoGame.Vector(Game.singleton.ScreenWidth / 2, Game.singleton.ScreenHeight / 4 + 100), message.text, Game.singleton.fonts.small, null, Manager.textAlign.bottomCenter);
- if (Game.singleton.GUI.Button(new Rectangle(Game.singleton.ScreenWidth / 2 - 140, Game.singleton.ScreenHeight / 4 + 150, 280, 40), Game.singleton.buttonsSprites[0], "Ok", Game.singleton.fonts.basic)) { Game.singleton.GUI.ResetFocus(); showOKMessage = false; Game.singleton.client.ExitHost(); Game.singleton.gameState = new MainMenuState(); }
+ if (Game.singleton.GUI.Button(new Rectangle(Game.singleton.ScreenWidth / 2 - 140, Game.singleton.ScreenHeight / 4 + 150, 280, 40), Game.singleton.buttonsSprites[0], "Ok", Game.singleton.fonts.basic)) { Game.singleton.GUI.ResetFocus(); showOKMessage = false; Game.singleton.client.ExitHost(); }
}
}
}
public override void Update()
{
- if (Keyboard.GetState().IsKeyDown(Keys.Escape)) { Game.singleton.GUI.ResetFocus(); Game.singleton.client.ExitHost(); Game.singleton.gameState = new MainMenuState(); }
+ if (Keyboard.GetState().IsKeyDown(Keys.Escape) || (!Game.singleton.client.isRunning)) { Game.singleton.GUI.ResetFocus(); Game.singleton.client.ExitHost(); }
}
private void ChatEnter()
{
string request = chatInput;
chatInput = null;
- ResultData res = Game.singleton.client.Request(new string[2] { "say", request });
- if(res.type != ResultTypes.OK)
+
+ if (request == null)
+ return;
+
+ if (request.Length == 0)
+ return;
+
+ ResultData res;
+ if (request[0] == Game.singleton.config.commandChar)
{
- //TODO Mutlilang
- ChatText("Error :" + Common.ArrayToString(res.result));
+ request = request.Substring(1);
+ res = Game.singleton.client.Request(Common.SplitArgs(request));
+ ChatText(res.ToSmallString()); //TODO multilang
+ }
+ else
+ {
+ res = Game.singleton.client.Request(Common.Strings("say", request));
+ if (res.type != ResultTypes.OK)
+ {
+ //TODO Mutlilang
+ ChatText("Error :" + Common.ArrayToString(res.result));
+ }
}
}
private void OnEvent(object sender, EventArgs e)
{
+ //TODO add PartyKick
EventData eve = ((EventDataArgs)e).Data;
- switch (eve.type)
+ if (eve.type == EventTypes.ServerKick)
{
- case EventTypes.ChatMessage:
- ChatText(Common.ArrayToString(eve.data));
- break;
-
- case EventTypes.ServerJoin:
- ChatText(Common.ArrayToString(eve.data) + "join the server");
- break;
-
- case EventTypes.ServerLeave:
- ChatText(Common.ArrayToString(eve.data) + "leave the server");
- break;
-
- case EventTypes.ServerKick:
- message.title = "Kick from server";
- message.text = Common.ArrayToString(eve.data);
- showOKMessage = true;
- break;
+ message.title = "Kick from server";
+ message.text = Common.ArrayToString(eve.data);
+ showOKMessage = true;
+ }else
+ {
+ ChatText(Game.singleton.multilang.GetEventText(eve, Game.singleton.config.lang));
}
}
diff --git a/Galactic Colors Control Server/Commands/Client/KickCommand.cs b/Galactic Colors Control Server/Commands/Client/KickCommand.cs
index 6b1e0aa..a59f9a4 100644
--- a/Galactic Colors Control Server/Commands/Client/KickCommand.cs
+++ b/Galactic Colors Control Server/Commands/Client/KickCommand.cs
@@ -27,11 +27,11 @@ namespace Galactic_Colors_Control_Server.Commands
if (target == null)
return new RequestResult(ResultTypes.Error, Common.Strings("Can't find"));
- Logger.Write(args[2] + " was kick by server.", Logger.logType.info, Logger.logConsole.show);
+ Program.logger.Write(args[2] + " was kick by server.", Logger.logType.info, Logger.logConsole.show);
if (args.Length > 2)
{
Utilities.Send(target, new EventData(EventTypes.ServerKick, Common.Strings(args[3])));
- Logger.Write("because" + args[3], Logger.logType.debug);
+ Program.logger.Write("because" + args[3], Logger.logType.debug);
}
else
{
diff --git a/Galactic Colors Control Server/Commands/ConnectCommand.cs b/Galactic Colors Control Server/Commands/ConnectCommand.cs
index 7e2ed4d..0a6728d 100644
--- a/Galactic Colors Control Server/Commands/ConnectCommand.cs
+++ b/Galactic Colors Control Server/Commands/ConnectCommand.cs
@@ -26,7 +26,7 @@ namespace Galactic_Colors_Control_Server.Commands
if (args[1].Length < 3)
return new RequestResult(ResultTypes.Error, Common.Strings("Too Short"));
- Logger.Write("Identifiaction request from " + Utilities.GetName(soc), Logger.logType.debug);
+ Program.logger.Write("Identifiaction request from " + Utilities.GetName(soc), Logger.logType.debug);
bool allreadyconnected = false;
args[1] = args[1][0].ToString().ToUpper()[0] + args[1].Substring(1);
foreach (Client client in Program.clients.Values)
@@ -39,7 +39,7 @@ namespace Galactic_Colors_Control_Server.Commands
Program.clients[soc].status = 0;
Program.clients[soc].pseudo = args[1];
Utilities.Broadcast(new EventData(EventTypes.ServerJoin, Common.Strings(args[1])));
- Logger.Write("Identified as " + Utilities.GetName(soc) + " form " + ((IPEndPoint)soc.LocalEndPoint).Address.ToString(), Logger.logType.info);
+ Program.logger.Write("Identified as " + Utilities.GetName(soc) + " form " + ((IPEndPoint)soc.LocalEndPoint).Address.ToString(), Logger.logType.info);
return new RequestResult(ResultTypes.OK, Common.Strings(args[1]));
}
}
diff --git a/Galactic Colors Control Server/Commands/ExitCommand.cs b/Galactic Colors Control Server/Commands/ExitCommand.cs
index b473af9..ba5d03e 100644
--- a/Galactic Colors Control Server/Commands/ExitCommand.cs
+++ b/Galactic Colors Control Server/Commands/ExitCommand.cs
@@ -20,13 +20,13 @@ namespace Galactic_Colors_Control_Server.Commands
public RequestResult Execute(string[] args, Socket soc, bool server = false)
{
soc.Shutdown(SocketShutdown.Both);
- Logger.Write("Client disconnected from " + Utilities.GetName(soc), Logger.logType.info);
+ Program.logger.Write("Client disconnected from " + Utilities.GetName(soc), Logger.logType.info);
string username = Utilities.GetName(soc);
bool connected = Program.clients[soc].status != -1;
soc.Close();
Program.clients.Remove(soc);
if (connected) { Utilities.Broadcast(new EventData(EventTypes.ServerLeave, Common.Strings(username))); }
- Logger.Write("Size: " + Program.clients.Count + "/" + Program.config.size, Logger.logType.debug);
+ Program.logger.Write("Size: " + Program.clients.Count + "/" + Program.config.size, Logger.logType.debug);
return new RequestResult(ResultTypes.OK);
}
}
diff --git a/Galactic Colors Control Server/Commands/LogLevelCommand.cs b/Galactic Colors Control Server/Commands/LogLevelCommand.cs
index f5cb6ed..c461946 100644
--- a/Galactic Colors Control Server/Commands/LogLevelCommand.cs
+++ b/Galactic Colors Control Server/Commands/LogLevelCommand.cs
@@ -22,6 +22,7 @@ namespace Galactic_Colors_Control_Server.Commands
{
if (Enum.TryParse(args[1], true, out Program.config.logLevel))
{
+ Program.logger.ChangeLevel(Program.config.logLevel);
return new RequestResult(ResultTypes.OK, Common.Strings(Program.config.logLevel.ToString()));
}
else
diff --git a/Galactic Colors Control Server/Commands/Manager.cs b/Galactic Colors Control Server/Commands/Manager.cs
index a0defc2..1375ad3 100644
--- a/Galactic Colors Control Server/Commands/Manager.cs
+++ b/Galactic Colors Control Server/Commands/Manager.cs
@@ -26,7 +26,7 @@ namespace Galactic_Colors_Control_Server.Commands
foreach (ICommand com in coms)
{
commands.Add(com);
- Logger.Write("Added command " + com.Group.ToString() + " " + com.Name, Logger.logType.debug);
+ Program.logger.Write("Added command " + com.Group.ToString() + " " + com.Name, Logger.logType.debug);
}
}
@@ -60,7 +60,7 @@ namespace Galactic_Colors_Control_Server.Commands
}
catch (Exception e)
{
- Logger.Write("Command " + args[0] + " Exception : " + e.Message, Logger.logType.error);
+ Program.logger.Write("Command " + args[0] + " Exception : " + e.Message, Logger.logType.error);
return new RequestResult(ResultTypes.Error, Common.Strings("Execute Exception"));
}
}
diff --git a/Galactic Colors Control Server/Commands/Party/PartyCreateCommand.cs b/Galactic Colors Control Server/Commands/Party/PartyCreateCommand.cs
index f37a2f5..326f397 100644
--- a/Galactic Colors Control Server/Commands/Party/PartyCreateCommand.cs
+++ b/Galactic Colors Control Server/Commands/Party/PartyCreateCommand.cs
@@ -33,7 +33,7 @@ namespace Galactic_Colors_Control_Server.Commands
return new RequestResult(ResultTypes.Error, Common.Strings("Too Big"));
Program.AddParty(new Party(args[2], size, Utilities.GetName(soc)));
- Logger.Write("Party " + args[2] + " create with " + size + " slots as " + Program.GetPartyID(false), Logger.logType.info);
+ Program.logger.Write("Party " + args[2] + " create with " + size + " slots as " + Program.GetPartyID(false), Logger.logType.info);
if (server)
{
Program.selectedParty = Program.GetPartyID(false);
diff --git a/Galactic Colors Control Server/Commands/Party/PartyStopCommand.cs b/Galactic Colors Control Server/Commands/Party/PartyStopCommand.cs
index dfd5d52..8fb03e0 100644
--- a/Galactic Colors Control Server/Commands/Party/PartyStopCommand.cs
+++ b/Galactic Colors Control Server/Commands/Party/PartyStopCommand.cs
@@ -27,7 +27,7 @@ namespace Galactic_Colors_Control_Server.Commands
{
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, server ? Logger.logConsole.show : Logger.logConsole.normal);
+ Program.logger.Write("Party " + Program.parties[partyId].name + " closed", Logger.logType.info, server ? Logger.logConsole.show : Logger.logConsole.normal);
if (Program.selectedParty == partyId) { Program.selectedParty = -1; }
Program.parties.Remove(partyId);
return new RequestResult(ResultTypes.OK);
diff --git a/Galactic Colors Control Server/Commands/Server/ServerCloseCommand.cs b/Galactic Colors Control Server/Commands/Server/ServerCloseCommand.cs
index 9cd624f..a9a44bc 100644
--- a/Galactic Colors Control Server/Commands/Server/ServerCloseCommand.cs
+++ b/Galactic Colors Control Server/Commands/Server/ServerCloseCommand.cs
@@ -23,7 +23,7 @@ namespace Galactic_Colors_Control_Server.Commands
return new RequestResult(ResultTypes.Error, Common.Strings("Allready"));
Program._open = false;
- Logger.Write("Server closed", Logger.logType.warm, Logger.logConsole.show);
+ Program.logger.Write("Server closed", Logger.logType.warm, Logger.logConsole.show);
return new RequestResult(ResultTypes.OK);
}
}
diff --git a/Galactic Colors Control Server/Commands/Server/ServerOpenCommand.cs b/Galactic Colors Control Server/Commands/Server/ServerOpenCommand.cs
index aef73bc..6ea0a12 100644
--- a/Galactic Colors Control Server/Commands/Server/ServerOpenCommand.cs
+++ b/Galactic Colors Control Server/Commands/Server/ServerOpenCommand.cs
@@ -23,7 +23,7 @@ namespace Galactic_Colors_Control_Server.Commands
return new RequestResult(ResultTypes.Error, Common.Strings("Allready"));
Program._open = true;
- Logger.Write("Server opened", Logger.logType.warm, Logger.logConsole.show);
+ Program.logger.Write("Server opened", Logger.logType.warm, Logger.logConsole.show);
return new RequestResult(ResultTypes.OK);
}
}
diff --git a/Galactic Colors Control Server/Config.cs b/Galactic Colors Control Server/Config.cs
index 948647f..66aa5a3 100644
--- a/Galactic Colors Control Server/Config.cs
+++ b/Galactic Colors Control Server/Config.cs
@@ -1,4 +1,5 @@
-using System;
+using Galactic_Colors_Control_Common;
+using System;
using System.IO;
using System.Xml;
using System.Xml.Serialization;
@@ -14,6 +15,7 @@ namespace Galactic_Colors_Control_Server
public int size = 20;
public ConsoleColor[] logForeColor = new ConsoleColor[6] { ConsoleColor.DarkGray, ConsoleColor.Gray, ConsoleColor.White, ConsoleColor.Yellow, ConsoleColor.Red, ConsoleColor.White };
public ConsoleColor[] logBackColor = new ConsoleColor[6] { ConsoleColor.Black, ConsoleColor.Black, ConsoleColor.Black, ConsoleColor.Black, ConsoleColor.Black, ConsoleColor.Red };
+ public int lang = 0;
///
/// Load config from xml file
@@ -22,7 +24,7 @@ namespace Galactic_Colors_Control_Server
/// Loaded config
public Config Load()
{
- Logger.Write("Loading config", Logger.logType.info);
+ Program.logger.Write("Loading config", Logger.logType.info);
Config config = new Config();
if (File.Exists(AppDomain.CurrentDomain.BaseDirectory + "Config.xml"))
{
@@ -36,7 +38,7 @@ namespace Galactic_Colors_Control_Server
}
else
{
- Logger.Write("Old config in Config.xml.old", Logger.logType.warm);
+ Program.logger.Write("Old config in Config.xml.old", Logger.logType.warm);
File.Delete(AppDomain.CurrentDomain.BaseDirectory + "Config.xml.old");
File.Move(AppDomain.CurrentDomain.BaseDirectory + "Config.xml", AppDomain.CurrentDomain.BaseDirectory + "Config.xml.old");
config.Save();
@@ -44,7 +46,7 @@ namespace Galactic_Colors_Control_Server
}
else
{
- Logger.Write("Any config file", Logger.logType.error);
+ Program.logger.Write("Any config file", Logger.logType.error);
config.Save();
}
if (Program._debug) { config.logLevel = Logger.logType.debug; }
@@ -85,7 +87,7 @@ namespace Galactic_Colors_Control_Server
catch (XmlException e)
{
isCorrect = false;
- Logger.Write("Error: " + e.Message, Logger.logType.error);
+ Program.logger.Write("Error: " + e.Message, Logger.logType.error);
}
}
@@ -99,14 +101,14 @@ namespace Galactic_Colors_Control_Server
d.Validate((o, e) =>
{
- Logger.Write("Error: " + e.Message, Logger.logType.error);
+ Program.logger.Write("Error: " + e.Message, Logger.logType.error);
isCorrect = false;
});
}
catch (XmlException e)
{
isCorrect = false;
- Logger.Write("Error: " + e.Message, Logger.logType.error);
+ Program.logger.Write("Error: " + e.Message, Logger.logType.error);
}
}
diff --git a/Galactic Colors Control Server/Galactic Colors Control Server.csproj b/Galactic Colors Control Server/Galactic Colors Control Server.csproj
index b89d988..648b04e 100644
--- a/Galactic Colors Control Server/Galactic Colors Control Server.csproj
+++ b/Galactic Colors Control Server/Galactic Colors Control Server.csproj
@@ -88,7 +88,6 @@
-
diff --git a/Galactic Colors Control Server/Program.cs b/Galactic Colors Control Server/Program.cs
index 729be6b..4aaa36c 100644
--- a/Galactic Colors Control Server/Program.cs
+++ b/Galactic Colors Control Server/Program.cs
@@ -29,7 +29,9 @@ namespace Galactic_Colors_Control_Server
public static Dictionary parties { get; private set; } = new Dictionary();
public static int selectedParty = -1;
+ //TODO add multilang
public static Config config = new Config();
+ public static Logger logger = new Logger();
public static Thread CheckConnected = new Thread(CheckConnectedLoop);
///
@@ -38,19 +40,19 @@ namespace Galactic_Colors_Control_Server
private static void Main(string[] args)
{
Console.Title = "Galactic Colors Control Server";
- Logger.Write("Galactic Colors Control Server " + Assembly.GetEntryAssembly().GetName().Version.ToString(), Logger.logType.fatal);
+ logger.Write("Galactic Colors Control Server " + Assembly.GetEntryAssembly().GetName().Version.ToString(), Logger.logType.fatal);
if (args.Length > 0)
{
switch (args[0])
{
case "--debug":
_debug = true;
- Logger.Write("SERVER IS IN DEBUG MODE !", Logger.logType.error, Logger.logConsole.show);
+ logger.Write("SERVER IS IN DEBUG MODE !", Logger.logType.error, Logger.logConsole.show);
break;
case "--dev":
_dev = true;
- Logger.Write("SERVER IS IN DEV MODE !", Logger.logType.error, Logger.logConsole.show);
+ logger.Write("SERVER IS IN DEV MODE !", Logger.logType.error, Logger.logConsole.show);
break;
default:
@@ -58,7 +60,7 @@ namespace Galactic_Colors_Control_Server
break;
}
}
- if (Type.GetType("Mono.Runtime") != null) { Logger.Write("Using Mono", Logger.logType.warm); }
+ if (Type.GetType("Mono.Runtime") != null) { logger.Write("Using Mono", Logger.logType.warm, Logger.logConsole.show); }
Console.Write(">");
SetupServer();
ConsoleLoop();
@@ -71,15 +73,15 @@ namespace Galactic_Colors_Control_Server
private static void SetupServer()
{
config = config.Load();
- Logger.Initialise();
+ logger.Initialise(config.logPath, config.logBackColor, config.logForeColor, config.logLevel);
Commands.Manager.Load();
- Logger.Write("Setting up server on *:" + config.port, Logger.logType.warm);
- Logger.Write("Size:" + config.size, Logger.logType.debug);
+ logger.Write("Setting up server on *:" + config.port, Logger.logType.warm);
+ logger.Write("Size:" + config.size, Logger.logType.debug);
serverSocket.Bind(new IPEndPoint(IPAddress.Any, config.port));
serverSocket.Listen(0);
serverSocket.BeginAccept(AcceptCallback, null);
CheckConnected.Start();
- Logger.Write("Server setup complete", Logger.logType.info);
+ logger.Write("Server setup complete", Logger.logType.info);
}
///
@@ -102,19 +104,18 @@ namespace Galactic_Colors_Control_Server
///
private static void CloseAllSockets()
{
- Logger.Write("Stoping server", Logger.logType.warm, Logger.logConsole.show);
+ logger.Write("Stoping server", Logger.logType.warm, Logger.logConsole.show);
Utilities.Broadcast(new EventData(EventTypes.ServerKick, Common.Strings("Close")));
config.Save();
foreach (Socket socket in clients.Keys)
{
socket.Shutdown(SocketShutdown.Both);
- Logger.Write("Shutdown " + Utilities.GetName(socket), Logger.logType.debug);
+ logger.Write("Shutdown " + Utilities.GetName(socket), Logger.logType.debug);
}
serverSocket.Close();
CheckConnected.Join(2000);
- Logger.Write("Server stoped", Logger.logType.info);
- Logger._run = false;
- Logger.Updater.Join();
+ logger.Write("Server stoped", Logger.logType.info);
+ logger.Join();
}
///
@@ -139,14 +140,14 @@ namespace Galactic_Colors_Control_Server
}
else
{
- Logger.Write("Client can't join from " + ((IPEndPoint)socket.LocalEndPoint).Address.ToString() + " no more space", Logger.logType.warm);
+ logger.Write("Client can't join from " + ((IPEndPoint)socket.LocalEndPoint).Address.ToString() + " no more space", Logger.logType.warm);
Utilities.Send(socket, new EventData(EventTypes.ServerKick, Common.Strings("Space")));
socket.Close();
}
}
else
{
- Logger.Write("Client can't join from " + ((IPEndPoint)socket.LocalEndPoint).Address.ToString() + " server closed", Logger.logType.info);
+ logger.Write("Client can't join from " + ((IPEndPoint)socket.LocalEndPoint).Address.ToString() + " server closed", Logger.logType.info);
Utilities.Send(socket, new EventData(EventTypes.ServerKick, Common.Strings("Close")));
socket.Close();
}
@@ -161,11 +162,11 @@ namespace Galactic_Colors_Control_Server
Client client = new Client();
clients.Add(socket, client);
socket.BeginReceive(buffer, 0, BUFFER_SIZE, SocketFlags.None, ReceiveCallback, socket);
- Logger.Write("Client connection from " + Utilities.GetName(socket), Logger.logType.info);
- Logger.Write("Size: " + clients.Count + "/" + config.size, Logger.logType.dev);
+ logger.Write("Client connection from " + Utilities.GetName(socket), Logger.logType.info);
+ logger.Write("Size: " + clients.Count + "/" + config.size, Logger.logType.dev);
if (clients.Count >= config.size)
{
- Logger.Write("Server full", Logger.logType.warm, Logger.logConsole.show);
+ logger.Write("Server full", Logger.logType.warm, Logger.logConsole.show);
}
}
@@ -183,10 +184,10 @@ namespace Galactic_Colors_Control_Server
}
catch (SocketException)
{
- Logger.Write("Client forcefully disconnected from " + Utilities.GetName(current) + " : SocketException", Logger.logType.info);
+ logger.Write("Client forcefully disconnected from " + Utilities.GetName(current) + " : SocketException", Logger.logType.info);
string username = Utilities.GetName(current);
bool connected = clients[current].status != -1;
- Logger.Write("Size: " + clients.Count + "/" + config.size, Logger.logType.debug);
+ logger.Write("Size: " + clients.Count + "/" + config.size, Logger.logType.debug);
current.Close(); // Don't shutdown because the socket may be disposed and its disconnected anyway.
clients.Remove(current);
if (connected) { Utilities.Broadcast(new EventData(EventTypes.ServerLeave, Common.Strings(username))); }
@@ -207,13 +208,13 @@ namespace Galactic_Colors_Control_Server
break;
default:
- Logger.Write("Wrong packet from " + Utilities.GetName(current), Logger.logType.error);
+ logger.Write("Wrong packet from " + Utilities.GetName(current), Logger.logType.error);
break;
}
}
else
{
- Logger.Write("Wrong packet from " + Utilities.GetName(current), Logger.logType.error);
+ logger.Write("Wrong packet from " + Utilities.GetName(current), Logger.logType.error);
}
if (clients.ContainsKey(current)) { current.BeginReceive(buffer, 0, BUFFER_SIZE, SocketFlags.None, ReceiveCallback, current); }
@@ -228,9 +229,9 @@ namespace Galactic_Colors_Control_Server
if ((current.Poll(10, SelectMode.SelectRead) && current.Available == 0) || !current.Connected)
{
string username = Utilities.GetName(current);
- Logger.Write("Client forcefully disconnected from " + username + " : NotConnected", Logger.logType.info);
+ logger.Write("Client forcefully disconnected from " + username + " : NotConnected", Logger.logType.info);
bool connected = clients[current].status != -1;
- Logger.Write("Size: " + clients.Count + "/" + config.size, Logger.logType.debug);
+ logger.Write("Size: " + clients.Count + "/" + config.size, Logger.logType.debug);
current.Close(); // Don't shutdown because the socket may be disposed and its disconnected anyway.
clients.Remove(current);
if (connected) { Utilities.Broadcast(new EventData(EventTypes.ServerLeave, Common.Strings(username))); }
diff --git a/Galactic Colors Control Server/Utilities.cs b/Galactic Colors Control Server/Utilities.cs
index cfe562c..ba0131f 100644
--- a/Galactic Colors Control Server/Utilities.cs
+++ b/Galactic Colors Control Server/Utilities.cs
@@ -20,7 +20,7 @@ namespace Galactic_Colors_Control_Server
if (Program.clients.ContainsKey(soc))
return Program.clients[soc].status != -1;
- Logger.Write("IsConnect : Unknown client", Logger.logType.error);
+ Program.logger.Write("IsConnect : Unknown client", Logger.logType.error);
return false;
}
@@ -64,12 +64,12 @@ namespace Galactic_Colors_Control_Server
soc.Send(packet.ToBytes());
if (Program.config.logLevel == Logger.logType.dev)
{
- Logger.Write("Send to " + GetName(soc) + " : " + packet.ToLongString(), Logger.logType.dev);
+ Program.logger.Write("Send to " + GetName(soc) + " : " + packet.ToLongString(), Logger.logType.dev);
}
}
catch (Exception e)
{
- Logger.Write("Send exception to " + GetName(soc) + " : " + e.Message, Logger.logType.error);
+ Program.logger.Write("Send exception to " + GetName(soc) + " : " + e.Message, Logger.logType.error);
}
}
}
diff --git a/Galactic Colors Control/Program.cs b/Galactic Colors Control/Program.cs
index 5d0aed5..9e3dd12 100644
--- a/Galactic Colors Control/Program.cs
+++ b/Galactic Colors Control/Program.cs
@@ -165,7 +165,26 @@ namespace Galactic_Colors_Control
/// ResultData or Timeout
public ResultData Request(string[] args)
{
- // TODO filter Client Side Requests
+ switch(args[0])
+ {
+ case "exit":
+ ExitHost();
+ return new ResultData(GetRequestId(), ResultTypes.OK);
+
+ case "ping":
+ return PingHost();
+
+ default:
+ return Execute(args);
+ }
+
+ }
+
+ ///
+ /// Send row command to server
+ ///
+ private ResultData Execute(string[] args)
+ {
RequestData req = new RequestData(GetRequestId(), args);
if (!Send(req))
return new ResultData(req.id, ResultTypes.Error, Common.Strings("Send Exception"));
@@ -190,16 +209,16 @@ namespace Galactic_Colors_Control
/// Ping Current Server IP
///
/// Time in ms or 'Timeout'
- private string PingHost()
+ private ResultData PingHost()
{
Ping ping = new Ping();
PingReply reply;
reply = ping.Send(IP);
if (reply.Status == IPStatus.Success)
- return reply.RoundtripTime.ToString();
+ return new ResultData(GetRequestId(), ResultTypes.OK, Common.SplitArgs(reply.RoundtripTime.ToString() + "ms"));
- return "Timeout";
+ return new ResultData(GetRequestId(), ResultTypes.Error, Common.SplitArgs("Timeout"));
}
///