1
0
Fork 0
This repository has been archived on 2019-05-31. You can view files and clone it, but cannot push or open issues or pull requests.
Galactic_Colors_Control/Galactic Colors Control Server/Commands/ConnectCommand.cs

52 lines
2.2 KiB
C#
Raw Normal View History

2016-10-09 12:27:08 +00:00
using System;
using System.Net;
using System.Net.Sockets;
2016-10-30 14:15:27 +00:00
using Galactic_Colors_Control_Common;
2016-10-09 12:27:08 +00:00
namespace Galactic_Colors_Control_Server.Commands
{
public class ConnectCommand : ICommand
{
public string Name { get { return "connect"; } }
public string DescText { get { return "Gets an username."; } }
public string HelpText { get { return "Use /connect [username] to start identification"; } }
2016-11-03 20:01:16 +00:00
public Manager.CommandGroup Group { get { return Manager.CommandGroup.root; } }
2016-10-09 12:27:08 +00:00
public bool IsServer { get { return false; } }
public bool IsClient { get { return true; } }
2016-10-11 10:09:51 +00:00
public bool IsClientSide { get { return false; } }
2016-10-09 12:27:08 +00:00
public bool IsNoConnect { get { return true; } }
public int minArgs { get { return 1; } }
public int maxArgs { get { return 1; } }
public void Execute(string[] args, Socket soc, bool server = false)
{
if (!Utilities.IsConnect(soc))
{
Logger.Write("Identifiaction request from " + Utilities.GetName(soc), Logger.logType.debug);
2016-10-16 18:52:19 +00:00
bool allreadyconnected = false;
2016-11-03 20:01:16 +00:00
foreach(Client client in Program.clients.Values)
2016-10-16 18:52:19 +00:00
{
if(client.pseudo == args[1]) { allreadyconnected = true; break; }
}
if (!allreadyconnected)
{
Program.clients[soc].status = 0;
//args[1] = args[1][0].ToString().ToUpper()[0] + args[1].Substring(1);
Program.clients[soc].pseudo = args[1];
2016-10-30 14:15:27 +00:00
Utilities.Send(soc, "/connected", Common.dataType.message);
Utilities.Broadcast(args[1] + " joined the server", Common.dataType.message);
2016-10-16 18:52:19 +00:00
Logger.Write("Identified as " + Utilities.GetName(soc) + " form " + ((IPEndPoint)soc.LocalEndPoint).Address.ToString(), Logger.logType.info);
}
else
{
2016-10-30 14:15:27 +00:00
Utilities.Send(soc, "/allreadytaken", Common.dataType.message);
2016-10-16 18:52:19 +00:00
}
2016-10-09 12:27:08 +00:00
}
else
{
2016-10-30 14:15:27 +00:00
Utilities.Send(soc, "You are allready " + Utilities.GetName(soc), Common.dataType.message);
2016-10-09 12:27:08 +00:00
}
}
}
}