Correction IsConnect et Ajout client ping
This commit is contained in:
parent
6d87af0376
commit
9236c83ca6
|
@ -24,7 +24,7 @@ namespace Galactic_Colors_Control_Server.Commands
|
|||
//args[1] = args[1][0].ToString().ToUpper()[0] + args[1].Substring(1);
|
||||
Program.clients[soc].pseudo = args[1];
|
||||
Utilities.Send(soc, "Identified as " + args[1], Utilities.dataType.message);
|
||||
Utilities.Broadcast(args[1] + "joined the server", Utilities.dataType.message);
|
||||
Utilities.Broadcast(args[1] + " joined the server", Utilities.dataType.message);
|
||||
Logger.Write("Identified as " + Utilities.GetName(soc) + " form " + ((IPEndPoint)soc.LocalEndPoint).Address.ToString(), Logger.logType.info);
|
||||
|
||||
}
|
||||
|
|
|
@ -11,8 +11,8 @@ namespace Galactic_Colors_Control_Server.Commands
|
|||
public string DescText { get { return "Shows the help."; } }
|
||||
public string HelpText { get { return "Use /help [command] to display command help."; } }
|
||||
public bool IsServer { get { return true; } }
|
||||
public bool IsClient { get { return false; } }
|
||||
public bool IsNoConnect { get { return true; } }
|
||||
public bool IsClient { get { return true; } }
|
||||
public bool IsNoConnect { get { return false; } }
|
||||
public int minArgs { get { return 0; } }
|
||||
public int maxArgs { get { return 1; } }
|
||||
|
||||
|
|
|
@ -45,12 +45,12 @@ namespace Galactic_Colors_Control_Server.Commands
|
|||
}
|
||||
else
|
||||
{
|
||||
Utilities.Return("Unknown command", soc, server);
|
||||
Utilities.Return("Unknown command : " + args[0], soc, server);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Utilities.Return("Unknown command", soc, server);
|
||||
Utilities.Return("Unknown command : " + args[0], soc, server);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -64,7 +64,7 @@ namespace Galactic_Colors_Control_Server.Commands
|
|||
{
|
||||
if (command.IsClient)
|
||||
{
|
||||
if(Utilities.IsConnect(soc))
|
||||
if(!Utilities.IsConnect(soc))
|
||||
{
|
||||
return command.IsNoConnect;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
using System.Net.Sockets;
|
||||
|
||||
namespace Galactic_Colors_Control_Server.Commands
|
||||
{
|
||||
public class PingCommand : ICommand
|
||||
{
|
||||
public string Name { get { return "ping"; } }
|
||||
public string DescText { get { return "Clears the console screen."; } }
|
||||
public string HelpText { get { return "Use /ping to display our ping."; } }
|
||||
public bool IsServer { get { return false; } }
|
||||
public bool IsClient { get { return true; } }
|
||||
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)
|
||||
{
|
||||
Utilities.Return("It's a client side command" ,soc ,server);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -53,6 +53,7 @@
|
|||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Commands\ClearCommand.cs" />
|
||||
<Compile Include="Commands\PingCommand.cs" />
|
||||
<Compile Include="Commands\CloseCommand.cs" />
|
||||
<Compile Include="Commands\ConnectCommand.cs" />
|
||||
<Compile Include="Commands\CountCommand.cs" />
|
||||
|
@ -77,6 +78,7 @@
|
|||
<None Include="App.config" />
|
||||
<None Include="ConfigSchema.xsd">
|
||||
<SubType>Designer</SubType>
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.NetworkInformation;
|
||||
using System.Net.Sockets;
|
||||
using System.Runtime.Serialization.Formatters.Binary;
|
||||
using System.Text;
|
||||
|
@ -149,11 +150,36 @@ namespace Galactic_Colors_Control_Client
|
|||
private static void SendRequest()
|
||||
{
|
||||
string request = Console.ReadLine();
|
||||
Send(request, dataType.message);
|
||||
|
||||
if (request.ToLower() == "/exit")
|
||||
switch (request.ToLower())
|
||||
{
|
||||
Exit();
|
||||
case "/exit":
|
||||
Exit();
|
||||
break;
|
||||
|
||||
case "/ping":
|
||||
Ping();
|
||||
break;
|
||||
|
||||
default:
|
||||
Send(request, dataType.message);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private static void Ping()
|
||||
{
|
||||
Ping p = new Ping();
|
||||
PingReply r;
|
||||
|
||||
r = p.Send(IP);
|
||||
|
||||
if (r.Status == IPStatus.Success)
|
||||
{
|
||||
Console.WriteLine(r.RoundtripTime.ToString() + " ms.");
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Time out");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Reference in New Issue