1
0
Fork 0

party rework

This commit is contained in:
sheychen 2016-11-16 22:27:28 +01:00
parent 5dcd7c328e
commit ae6754a832
21 changed files with 356 additions and 40 deletions

View File

@ -1,4 +1,4 @@
Key;Français;English
Key;Francais;English
GCC;Galactic Colors Control;Galactic Colors Control
Client;Client;Client
Server;Serveur;Server
@ -21,10 +21,17 @@ Error;Erreur;Error
Hide;Cacher;Hide
Show;Afficher;Show
Chat;Chat;Chat
Party;Partie;Party
Join;Rejoindre;Join
Use;Utiliser;Use
CantConnect;Connexion impossible. Au revoir;Can't connect sorry. Bye
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
ServerKick;Exclus du serveur;Kick from server
ServerKick;Exclus du serveur;Kick from server
TooShort;Trop court;Too short
TooLong;Trop long;Too long
Update;Actualiser;Update
AnyParty;Aucune partie;Any party
Password;Mot de passe;Password
1 Key Français Francais English
2 GCC Galactic Colors Control Galactic Colors Control
3 Client Client Client
4 Server Serveur Server
21 Hide Cacher Hide
22 Show Afficher Show
23 Chat Chat Chat
24 Party Partie Party
25 Join Rejoindre Join
26 Use Utiliser Use
27 CantConnect Connexion impossible. Au revoir Can't connect sorry. Bye
28 ServerJoin rejoint le server join the server
29 PartyJoin rejoint la partie join the party
30 ServerLeave quitte le server leave the server
31 PartyLeave quitte la partie leave the party
32 ServerKick Exclus du serveur Kick from server
33 TooShort Trop court Too short
34 TooLong Trop long Too long
35 Update Actualiser Update
36 AnyParty Aucune partie Any party
37 Password Mot de passe Password

View File

@ -14,7 +14,7 @@ namespace Galactic_Colors_Control_Console
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;
public int lang = 1;
/// <summary>
/// Load config from xml file

View File

@ -3,6 +3,7 @@ using Galactic_Colors_Control_Common;
using Galactic_Colors_Control_Common.Protocol;
using System;
using System.Reflection;
using System.Threading;
namespace Galactic_Colors_Control_Console
{
@ -22,14 +23,14 @@ namespace Galactic_Colors_Control_Console
private static void Main(string[] args)
{
Console.Title = "Galactic Colors Control Client"; //Start display
Console.Write(">");
logger.Write(Console.Title, Logger.logType.fatal);
logger.Write("Console " + Assembly.GetEntryAssembly().GetName().Version.ToString(), Logger.logType.error);
config = config.Load();
logger.Initialise(config.logPath, config.logBackColor, config.logForeColor, config.logLevel, _debug, _dev);
multilang.Load();
client.OnEvent += new EventHandler(OnEvent); //Set OnEvent function
Console.Title ="Galactic Colors Control Client"; //Start display
Console.Write(">");
Common.ConsoleWrite(Console.Title, ConsoleColor.Red);
Common.ConsoleWrite(multilang.Get("Console", config.lang) + " " + Assembly.GetEntryAssembly().GetName().Version.ToString(), ConsoleColor.Yellow);
client.OnEvent += new EventHandler(OnEvent); //Set OnEvent function
if (args.Length > 0)
{
switch (args[0])
@ -52,6 +53,7 @@ namespace Galactic_Colors_Control_Console
bool hostSet = false;
while (!hostSet) //Request hostname
{
Thread.Sleep(100);
Common.ConsoleWrite(multilang.Get("EnterHostname", config.lang) +":");
string host = client.ValidateHost(Console.ReadLine());
if (host[0] == '*')
@ -78,9 +80,79 @@ namespace Galactic_Colors_Control_Console
}
}
}
Common.ConsoleWrite(multilang.Get("Loading", config.lang));
if (client.ConnectHost()) //Try connection
{
{//TODO Cleaner
run = true;
bool connected = false;
//Identifaction
while (!connected)
{
Common.ConsoleWrite(multilang.Get("Username", config.lang) + ":");
string username = Console.ReadLine();
if (username.Length > 3)
{
ResultData res = client.Request(new string[2] { "connect", username });
if(res.type == ResultTypes.OK) { connected = true; }
else
{
Common.ConsoleWrite(multilang.GetResultText(res, config.lang));
}
}
else
{
Common.ConsoleWrite(multilang.Get("TooShort", config.lang));
}
}
bool inparty = false;
while (!inparty)
{
Console.Clear();
Common.ConsoleWrite(multilang.GetResultText(client.Request(new string[2] { "party", "list" }), config.lang));
Common.ConsoleWrite(multilang.Get("Party", config.lang) + ":" + Environment.NewLine + " (<id> [password] or 'c' for create)");
string[] data = Common.SplitArgs(Console.ReadLine());
if (data.Length > 0)
{
if (data[0] == "c")
{
Common.ConsoleWrite("<party name> <player count>:");
string[] split = Common.SplitArgs(Console.ReadLine());
if (split.Length == 2)
{
ResultData createRes = client.Request(new string[4] { "party", "create", split[0], split[1] });
if (createRes.type == ResultTypes.OK) { inparty = true; }
else
{
Common.ConsoleWrite(multilang.GetResultText(createRes, config.lang));
Console.ReadLine();
}
}
else
{
Common.ConsoleWrite("Format");
}
}
else
{
int id;
if (int.TryParse(data[0], out id))
{
string[] request = data.Length == 1 ? new string[3] { "party", "join", id.ToString() } : new string[4] { "party", "join", id.ToString(), data[1] };
ResultData res = client.Request(request);
if (res.type == ResultTypes.OK) { inparty = true; }
else
{
Common.ConsoleWrite(multilang.GetResultText(res, config.lang));
}
}
else
{
Common.ConsoleWrite("Format");
}
}
}
}
Common.ConsoleWrite(multilang.Get("Play", config.lang));
while (run)
{
Execute(Console.ReadLine()); //Process console input
@ -91,8 +163,10 @@ namespace Galactic_Colors_Control_Console
else
{
Common.ConsoleWrite(multilang.Get("CantConnect", config.lang), ConsoleColor.Red);
Console.Read();
}
run = false;
logger.Join();
Console.ReadLine();
}
private static void Execute(string input)

View File

@ -14,7 +14,7 @@ namespace Galactic_Colors_Control_GUI
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;
public int lang = 1;
public string skin = "default";
/// <summary>

View File

@ -52,6 +52,7 @@
<Compile Include="States\ConnectState.cs" />
<Compile Include="States\GameState.cs" />
<Compile Include="States\IndentificationState.cs" />
<Compile Include="States\PartyState.cs" />
<Compile Include="States\MainMenuState.cs" />
<Compile Include="States\OptionsState.cs" />
<Compile Include="States\State.cs" />

View File

@ -12,7 +12,6 @@ namespace Galactic_Colors_Control_GUI.States
{
public class GameState : State
{
private string username;
private bool showChat = false;
private string chatText;
private string chatInput;
@ -21,10 +20,9 @@ namespace Galactic_Colors_Control_GUI.States
private bool showOKMessage = false;
private Message message;
public GameState(string Username)
public GameState()
{
Game.singleton.client.OnEvent += new EventHandler(OnEvent); //Set OnEvent function
username = Username;
}
public override void Draw(SpriteBatch spritebatch)
@ -32,7 +30,6 @@ namespace Galactic_Colors_Control_GUI.States
Game.singleton.background.Draw(spritebatch);
Game.singleton.GUI.Texture(new Rectangle(0, 0, Game.singleton.ScreenWidth, 30), Game.nullSprite, new MyMonoGame.Colors(new Color(0.1f, 0.1f, 0.1f)));
if (Game.singleton.GUI.Button(new Rectangle(5, 5, 50, 20), (showChat ? Game.singleton.multilang.Get("Hide", Game.singleton.config.lang) : Game.singleton.multilang.Get("Show", Game.singleton.config.lang)) + " " + Game.singleton.multilang.Get("Chat", Game.singleton.config.lang), Game.singleton.fonts.small, new MyMonoGame.Colors(Color.White, Color.LightGray, Color.Gray))) { Game.singleton.GUI.ResetFocus(); showChat = !showChat; }
//if (Game.singleton.GUI.Button(new Rectangle(65, 5, 50, 20), (showParty ? "Leave" : "Join") + " party", smallFont, new MyMonoGame.Colors(Color.White, Color.LightGray, Color.Gray))) { new Thread(PartyClick).Start(); }
if (showChat)
{
@ -60,7 +57,10 @@ namespace Galactic_Colors_Control_GUI.States
public override void Update()
{
if (Keyboard.GetState().IsKeyDown(Keys.Escape) || (!Game.singleton.client.isRunning)) { Game.singleton.GUI.ResetFocus(); Game.singleton.client.ExitHost(); }
if (Keyboard.GetState().IsKeyDown(Keys.Escape) || (!Game.singleton.client.isRunning)) {
Game.singleton.client.ExitHost();
Game.singleton.gameState = new MainMenuState();
}
}
private void ChatEnter()

View File

@ -57,6 +57,7 @@ namespace Galactic_Colors_Control_GUI.States
{
locked = true;
Game.singleton.GUI.ResetFocus();
Game.singleton.client.ExitHost();
new Thread(() =>
{
while (!Utilities.DoubleTo(ref Game.singleton.background.speedX, 1, 0.1)) { Thread.Sleep(20); }
@ -78,7 +79,7 @@ namespace Galactic_Colors_Control_GUI.States
ResultData res = Game.singleton.client.Request(new string[2] { "connect", username });
if (res.type == ResultTypes.OK)
{
Game.singleton.gameState = new GameState(username);
Game.singleton.gameState = new PartyState();
}
else
{

View File

@ -1,17 +1,54 @@
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using MyMonoGame.GUI;
using System.Threading;
namespace Galactic_Colors_Control_GUI.States
{
public class OptionsState : State
{
private bool locked = false;
public override void Draw(SpriteBatch spritebatch)
{
Game.singleton.background.Draw(spritebatch);
Game.singleton.GUI.Label(new MyMonoGame.Vector(Game.singleton.ScreenWidth / 2, Game.singleton.ScreenHeight / 4), Game.singleton.multilang.Get("GCC", Game.singleton.config.lang), Game.singleton.fonts.title, new MyMonoGame.Colors(Color.White), Manager.textAlign.centerCenter);
if (Game.singleton.GUI.Button(new Rectangle(Game.singleton.ScreenWidth / 2 - 75, Game.singleton.ScreenHeight / 2 + 20, 150, 40), Game.singleton.buttonsSprites[0], Game.singleton.multilang.Langs[Game.singleton.config.lang], Game.singleton.fonts.basic, new MyMonoGame.Colors(Color.LightGray, Color.White))) {
Game.singleton.GUI.ResetFocus();
ChangeLang();
}
if (Game.singleton.GUI.Button(new Rectangle(Game.singleton.ScreenWidth / 2 - 75, Game.singleton.ScreenHeight / 2 + 70, 150, 40), Game.singleton.buttonsSprites[0], Game.singleton.multilang.Get("Back", Game.singleton.config.lang), Game.singleton.fonts.basic, new MyMonoGame.Colors(Color.LightGray, Color.White)))
{
if (!locked)
{
locked = true;
Game.singleton.GUI.ResetFocus();
Game.singleton.config.Save();
new Thread(() =>
{
while (!Utilities.DoubleTo(ref Game.singleton.background.speedX, 1, 0.1)) { Thread.Sleep(20); }
Game.singleton.gameState = new MainMenuState();
}).Start();
}
}
}
public override void Update()
{
Game.singleton.background.Update();
}
private void ChangeLang()
{
if (Game.singleton.config.lang < Game.singleton.multilang.Langs.Count - 1)
{
Game.singleton.config.lang++;
}
else
{
Game.singleton.config.lang = 0;
}
}
}
}

View File

@ -0,0 +1,165 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using MyMonoGame.GUI;
using System.Threading;
using System;
using Galactic_Colors_Control_Common.Protocol;
using Galactic_Colors_Control_Common;
using System.Collections.Generic;
namespace Galactic_Colors_Control_GUI.States
{
public class PartyState : State
{
public struct Party
{
public int id;
public string text;
public Party(int ID, string TEXT)
{
id = ID;
text = TEXT;
}
}
private string password;
private int page = 1;
private List<Party> parties = new List<Party>();
private Message message;
private int id = -1;
private bool locked = false;
private bool showLoading = false;
private bool showOKMessage = false;
public PartyState()
{
UpdateParty();
}
public override void Draw(SpriteBatch spritebatch)
{
Game.singleton.background.Draw(spritebatch);
Game.singleton.GUI.Label(new MyMonoGame.Vector(Game.singleton.ScreenWidth / 2, Game.singleton.ScreenHeight / 4), Game.singleton.multilang.Get("GCC", Game.singleton.config.lang), Game.singleton.fonts.title, new MyMonoGame.Colors(Color.White), Manager.textAlign.centerCenter);
if (showLoading)
{
Game.singleton.GUI.Box(new Rectangle(Game.singleton.ScreenWidth / 2 - 150, Game.singleton.ScreenHeight / 4 + 50, 300, 50), Game.singleton.buttonsSprites[0]);
Game.singleton.GUI.Label(new Rectangle(Game.singleton.ScreenWidth / 2 - 150, Game.singleton.ScreenHeight / 4 + 50, 300, 50), Game.singleton.multilang.Get("Loading", Game.singleton.config.lang), Game.singleton.fonts.basic);
}
else
{
if (showOKMessage)
{
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], Game.singleton.multilang.Get("OK", Game.singleton.config.lang), Game.singleton.fonts.basic)) { Game.singleton.GUI.ResetFocus(); showOKMessage = false; }
}
else
{
Game.singleton.GUI.Box(new Rectangle(Game.singleton.ScreenWidth / 2 - 150, Game.singleton.ScreenHeight / 2 - 300, 300, 600), Game.singleton.buttonsSprites[0]);
if (Game.singleton.GUI.Button(new Rectangle(Game.singleton.ScreenWidth / 2 - 140, Game.singleton.ScreenHeight / 2 - 290, 100, 40), Game.singleton.buttonsSprites[0] ,Game.singleton.multilang.Get("Update", Game.singleton.config.lang), Game.singleton.fonts.basic, new MyMonoGame.Colors(Color.LightGray, Color.White)))
{
if (!locked)
{
locked = true;
new Thread(UpdateParty).Start();
}
}
Game.singleton.GUI.TextField(new Rectangle(Game.singleton.ScreenWidth / 2 + 40, Game.singleton.ScreenHeight / 2 - 290, 100, 40), ref password, Game.singleton.fonts.basic, null, Manager.textAlign.centerCenter, Game.singleton.multilang.Get("Password", Game.singleton.config.lang));
if (parties.Count > 0) {
if (parties.Count > 10) {
//TODO page change
}
for (int i = (page - 1) * 10; i < page * 10 && i < parties.Count; i++)
{
if (Game.singleton.GUI.Button(new Rectangle(Game.singleton.ScreenWidth / 2 - 100, Game.singleton.ScreenHeight / 2 - 250 + i*50, 200, 40), Game.singleton.buttonsSprites[0], parties[i].text, Game.singleton.fonts.basic, new MyMonoGame.Colors(Color.LightGray, Color.White)))
{
locked = true;
id = parties[i].id;
new Thread(PartyJoin).Start();
}
}
}
else
{
Game.singleton.GUI.Label(new MyMonoGame.Vector(Game.singleton.ScreenWidth / 2, Game.singleton.ScreenHeight / 2 - 240), Game.singleton.multilang.Get("AnyParty", Game.singleton.config.lang), Game.singleton.fonts.basic, null, Manager.textAlign.centerCenter);
}
if (Game.singleton.GUI.Button(new Rectangle(Game.singleton.ScreenWidth / 2 - 75, Game.singleton.ScreenHeight / 2 + 250, 150, 40), Game.singleton.buttonsSprites[0], Game.singleton.multilang.Get("Back", Game.singleton.config.lang), Game.singleton.fonts.basic, new MyMonoGame.Colors(Color.LightGray, Color.White)))
{
if (!locked)
{
locked = true;
Game.singleton.GUI.ResetFocus();
Game.singleton.client.ExitHost();
new Thread(() =>
{
while (!Utilities.DoubleTo(ref Game.singleton.background.speedX, 1, 0.1)) { Thread.Sleep(20); }
Game.singleton.gameState = new MainMenuState();
}).Start();
}
}
}
}
}
private void UpdateParty()
{
showLoading = true;
page = 1;
ResultData res = Game.singleton.client.Request(new string[2] { "party", "list" });
if (res.type == ResultTypes.OK) {
parties.Clear();
foreach (string str in res.result)
{
string[] data = str.Split(new char[1] { ':' }, 2);
int id = -1;
if (int.TryParse(data[0], out id))
{
parties.Add(new Party(id, data[1]));
}
}
}
else
{
parties = new List<Party>();
}
showLoading = false;
locked = false;
}
private void PartyJoin()
{
//TODO
showLoading = true;
if (id != -1)
{
string[] request = password != null ? new string[4] { "party", "join", id.ToString() , password } : new string[3] { "party", "join", id.ToString() };
ResultData res = Game.singleton.client.Request(request);
if (res.type == ResultTypes.OK)
{
Game.singleton.gameState = new GameState();
}
else
{
message.title = Game.singleton.multilang.Get("Error", Game.singleton.config.lang);
message.text = Common.ArrayToString(res.result);
showOKMessage = true;
}
}
showLoading = false;
locked = false;
}
private void PartyCreate()
{
//TODO
}
public override void Update()
{
Game.singleton.background.Update();
}
}
}

View File

@ -32,6 +32,9 @@ namespace Galactic_Colors_Control_Server.Commands
if (size > Program.config.size)
return new RequestResult(ResultTypes.Error, Common.Strings("Too Big"));
if (Program.parties.Count >= Program.config.partysize)
return new RequestResult(ResultTypes.Error, Common.Strings("Full"));
Program.AddParty(new Party(args[2], size, Utilities.GetName(soc)));
Program.logger.Write("Party " + args[2] + " create with " + size + " slots as " + Program.GetPartyID(false), Logger.logType.info);
if (server)

View File

@ -20,7 +20,7 @@ namespace Galactic_Colors_Control_Server.Commands
public RequestResult Execute(string[] args, Socket soc, bool server = false)
{
if ((server && Program.selectedParty == -1) || (!server && Program.clients[soc].partyID == -1))
if ((server && Program.selectedParty != -1) || (!server && Program.clients[soc].partyID != -1))
return new RequestResult(ResultTypes.Error, Common.Strings("Allready"));
int id;

View File

@ -20,7 +20,7 @@ namespace Galactic_Colors_Control_Server.Commands
public RequestResult Execute(string[] args, Socket soc, bool server = false)
{
int partyId = -1;
if (Utilities.AccessParty(ref partyId, args, true, soc, server))
if (!Utilities.AccessParty(ref partyId, args, true, soc, server))
return new RequestResult(ResultTypes.Error, Common.Strings("Access"));
Socket target = null;

View File

@ -27,7 +27,7 @@ namespace Galactic_Colors_Control_Server.Commands
else
{
int partyId = -1;
if (Utilities.AccessParty(ref partyId, args, false, soc, server))
if (!Utilities.AccessParty(ref partyId, args, false, soc, server))
return new RequestResult(ResultTypes.Error, Common.Strings("Access"));
if (Program.parties[partyId].IsOwner(Utilities.GetName(soc)))

View File

@ -1,4 +1,5 @@
using Galactic_Colors_Control_Common.Protocol;
using Galactic_Colors_Control_Common;
using Galactic_Colors_Control_Common.Protocol;
using System;
using System.Net.Sockets;
@ -19,12 +20,15 @@ namespace Galactic_Colors_Control_Server.Commands
public RequestResult Execute(string[] args, Socket soc, bool server = false)
{
if (Program.parties.Keys.Count == 0)
return new RequestResult(ResultTypes.Error, Common.Strings("AnyParty"));
string[] text = new string[Program.parties.Keys.Count];
int i = 0;
foreach (int key in Program.parties.Keys)
{
Party party = Program.parties[key];
text[i] = (key + " : " + party.name + " : " + party.count + "/" + party.size + " : " + (party.open ? (party.isPrivate ? "private" : "open") : "close") + Environment.NewLine + " ");
text[i] = (key + " : " + party.name + " : " + party.count + "/" + party.size + " : " + (party.open ? (party.isPrivate ? "private" : "open") : "close"));
i++;
}
return new RequestResult(ResultTypes.OK, text);

View File

@ -20,7 +20,7 @@ namespace Galactic_Colors_Control_Server.Commands
public RequestResult Execute(string[] args, Socket soc, bool server = false)
{
int partyId = -1;
if (Utilities.AccessParty(ref partyId, args, true, soc, server))
if (!Utilities.AccessParty(ref partyId, args, true, soc, server))
return new RequestResult(ResultTypes.Error, Common.Strings("Access"));
if (Program.parties[partyId].open)

View File

@ -21,7 +21,7 @@ namespace Galactic_Colors_Control_Server.Commands
public RequestResult Execute(string[] args, Socket soc, bool server = false)
{
int partyId = -1;
if (Utilities.AccessParty(ref partyId, args, true, soc, server))
if (!Utilities.AccessParty(ref partyId, args, true, soc, server))
return new RequestResult(ResultTypes.Error, Common.Strings("Access"));
if (args.Length == 3)

View File

@ -16,7 +16,8 @@ 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;
public int lang = 1;
public int partysize = 10;
/// <summary>
/// Load config from xml file

View File

@ -22,6 +22,7 @@
</xsd:complexType>
</xsd:element>
<xsd:element name="lang" type="xsd:unsignedInt" />
<xsd:element name="partysize" type="xsd:unsignedShort" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>

View File

@ -7,6 +7,7 @@ using System.Net;
using System.Net.Sockets;
using System.Reflection;
using System.Threading;
//TODO gui parties pages
namespace Galactic_Colors_Control_Server
{
@ -39,11 +40,11 @@ namespace Galactic_Colors_Control_Server
/// </summary>
private static void Main(string[] args)
{
Console.Title = "Galactic Colors Control Server";
logger.Write(Console.Title + " " + Assembly.GetEntryAssembly().GetName().Version.ToString(), Logger.logType.fatal);
config = config.Load();
logger.Initialise(config.logPath, config.logBackColor, config.logForeColor, config.logLevel, _debug, _dev);
multilang.Load();
Console.Title = multilang.Get("Galactic Colors Control Server", config.lang);
logger.Write(Console.Title + " " + Assembly.GetEntryAssembly().GetName().Version.ToString(), Logger.logType.fatal);
if (args.Length > 0)
{
switch (args[0])
@ -227,16 +228,19 @@ namespace Galactic_Colors_Control_Server
{
foreach (Socket current in clients.Keys.ToArray())
{
if ((current.Poll(10, SelectMode.SelectRead) && current.Available == 0) || !current.Connected)
try
{
string username = Utilities.GetName(current);
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);
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))); }
}
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);
bool connected = clients[current].status != -1;
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))); }
}
}catch { }
Thread.Sleep(200);
}
}

View File

@ -86,7 +86,16 @@ namespace Galactic_Colors_Control_Server
{
Send(soc, packet);
}
Common.ConsoleWrite(packet.ToSmallString());
switch (packet.GetType().Name)
{
case "EventData":
Common.ConsoleWrite(Program.multilang.GetEventText((EventData)packet, Program.config.lang));
break;
default:
Common.ConsoleWrite(packet.ToSmallString());
break;
}
}
/// <summary>
@ -107,7 +116,16 @@ namespace Galactic_Colors_Control_Server
}
if (Program.selectedParty == party)
{
Common.ConsoleWrite(data.ToSmallString());
switch (data.GetType().Name)
{
case "EventData":
Common.ConsoleWrite(Program.multilang.GetEventText((EventData)data, Program.config.lang));
break;
default:
Common.ConsoleWrite(data.ToSmallString());
break;
}
}
}

View File

@ -150,7 +150,7 @@ namespace Galactic_Colors_Control
/// </summary>
public void ExitHost()
{
Send(new RequestData(GetRequestId(), new string[1] { "exit" }));// Tell the server we are exiting
try { Send(new RequestData(GetRequestId(), new string[1] { "exit" })); } catch { }// Tell the server we are exiting
_run = false; //Stopping Thread
RecieveThread.Join(2000);
ClientSocket.Shutdown(SocketShutdown.Both);