np.Connect

feature-npv2
Icedream 2014-05-07 22:10:15 +02:00
parent 0e638ffef9
commit 9ff5af65f9
1 changed files with 26 additions and 6 deletions

View File

@ -8,10 +8,26 @@ namespace NPSharp.CommandLine.MOTD
{
static void Main(string[] args)
{
var hostname = args[0];
var username = args[1];
var password = args[2];
if (args.Length < 4)
{
Console.Error.WriteLine("Needs 4 arguments: hostname port username password");
return;
}
var hostname = args[0];
var port = ushort.Parse(args[1]);
var username = args[2];
var password = args[3];
// NP connection setup
var np = new NPClient(hostname, port);
if (!np.Connect())
{
Console.Error.WriteLine("Connection to NP server failed.");
return;
}
// Get session token
var ah = new AuthenticationHelper(hostname);
try
{
@ -27,14 +43,18 @@ namespace NPSharp.CommandLine.MOTD
return;
}
var np = new NPClient(hostname);
// Validate authentication using session token
try
{
np.AuthenticateWithToken(ah.SessionToken).Wait();
}
catch
catch (Exception err)
{
Console.Error.WriteLine("Authenticated but session token was invalid.");
#if DEBUG
Console.Error.WriteLine("Authenticated but session token was invalid. {0}", err);
#else
Console.Error.WriteLine("Authenticated but session token was invalid ({0}).", err.Message);
#endif
return;
}