Refactoring. A lot.

feature-npv2
Icedream 2014-05-19 16:31:30 +02:00
parent 976949571a
commit 030f2b5f7c
28 changed files with 79 additions and 61 deletions

View File

@ -1,6 +1,7 @@
using System;
using NPSharp.NP;
namespace NPSharp
namespace NPSharp.Events
{
public class ClientEventArgs : EventArgs
{

View File

@ -1,4 +1,6 @@
namespace NPSharp
using NPSharp.NP;
namespace NPSharp.Events
{
/// <summary>
/// A delegate for all general client-related events.

View File

@ -1,4 +1,7 @@
namespace NPSharp
using NPSharp.NP;
using NPSharp.RPC.Messages.Data;
namespace NPSharp.Handlers
{
/// <summary>
/// Represents a handler for all authentication-related requests.
@ -11,24 +14,24 @@ namespace NPSharp
/// <param name="client">The NP server client to authenticate</param>
/// <param name="username">The username to use for authentication</param>
/// <param name="password">The password to use for authentication</param>
/// <returns>An instance of <seealso cref="AuthenticationResult" /></returns>
AuthenticationResult AuthenticateUser(NPServerClient client, string username, string password);
/// <returns>An instance of <seealso cref="NPAuthenticationResult" /></returns>
NPAuthenticationResult AuthenticateUser(NPServerClient client, string username, string password);
/// <summary>
/// Authenticates a user based on a session token.
/// </summary>
/// <param name="client">The NP server client to authenticate</param>
/// <param name="token">The session token to use for authentication</param>
/// <returns>An instance of <seealso cref="AuthenticationResult" /></returns>
AuthenticationResult AuthenticateUser(NPServerClient client, string token);
/// <returns>An instance of <seealso cref="NPAuthenticationResult" /></returns>
NPAuthenticationResult AuthenticateUser(NPServerClient client, string token);
/// <summary>
/// Authenticates a dedicated server based on its license key.
/// </summary>
/// <param name="client">The NP server client of the dedicated server to authenticate</param>
/// <param name="licenseKey">The license key to use for authentication</param>
/// <returns>An instance of <see cref="AuthenticationResult" /></returns>
AuthenticationResult AuthenticateServer(NPServerClient client, string licenseKey);
/// <returns>An instance of <see cref="NPAuthenticationResult" /></returns>
NPAuthenticationResult AuthenticateServer(NPServerClient client, string licenseKey);
/// <summary>
/// Validates a ticket.

View File

@ -1,4 +1,6 @@
namespace NPSharp
using NPSharp.NP;
namespace NPSharp.Handlers
{
/// <summary>
/// Represents a handler for all file-related requests.

View File

@ -1,8 +1,8 @@
using System.Collections.Generic;
using NPSharp.RPC.Messages;
using NPSharp.RPC.Messages.Structs;
using NPSharp.NP;
using NPSharp.RPC.Messages.Data;
namespace NPSharp
namespace NPSharp.Handlers
{
/// <summary>
/// Represents a handler for all friends-related requests.

View File

@ -1,6 +1,6 @@
using NPSharp.Steam;
namespace NPSharp
namespace NPSharp.Handlers
{
/// <summary>
/// Represents a handler for all user avatar-related requests.

View File

@ -1,11 +1,11 @@
using NPSharp.Steam;
namespace NPSharp
namespace NPSharp.NP
{
/// <summary>
/// Represents details about the outcome of an authentication attempt.
/// </summary>
public class AuthenticationResult
public class NPAuthenticationResult
{
/// <summary>
/// Constructs an authentication result instance.
@ -14,7 +14,7 @@ namespace NPSharp
/// Set this to null if authentication should fail, otherwise use an instance of a steam ID which is
/// unique to the user.
/// </param>
public AuthenticationResult(CSteamID npid = null)
public NPAuthenticationResult(CSteamID npid = null)
{
UserID = npid;
}

View File

@ -5,11 +5,10 @@ using System.Threading;
using System.Threading.Tasks;
using log4net;
using NPSharp.RPC;
using NPSharp.RPC.Messages;
using NPSharp.RPC.Messages.Client;
using NPSharp.RPC.Messages.Server;
namespace NPSharp
namespace NPSharp.NP
{
/// <summary>
/// Represents a high-level network platform client.

View File

@ -1,6 +1,6 @@
using System;
namespace NPSharp
namespace NPSharp.NP
{
internal class NpFileException : Exception
{

View File

@ -6,13 +6,15 @@ using System.Net.Sockets;
using System.Threading;
using System.Threading.Tasks;
using log4net;
using NPSharp.Events;
using NPSharp.Handlers;
using NPSharp.RPC;
using NPSharp.RPC.Messages;
using NPSharp.RPC.Messages.Client;
using NPSharp.RPC.Messages.Data;
using NPSharp.RPC.Messages.Server;
using NPSharp.Steam;
namespace NPSharp
namespace NPSharp.NP
{
public class NPServer
{
@ -127,7 +129,7 @@ namespace NPSharp
client.RPC.AttachHandlerForMessageType<AuthenticateWithKeyMessage>(msg =>
{
var result = new AuthenticationResult();
var result = new NPAuthenticationResult();
if (AuthenticationHandler != null)
{
try
@ -164,7 +166,7 @@ namespace NPSharp
client.RPC.AttachHandlerForMessageType<AuthenticateWithDetailsMessage>(msg =>
{
var result = new AuthenticationResult();
var result = new NPAuthenticationResult();
if (AuthenticationHandler != null)
{
try
@ -174,7 +176,7 @@ namespace NPSharp
catch (Exception error)
{
_log.Error("Error occurred in authentication handler", error);
result = new AuthenticationResult();
result = new NPAuthenticationResult();
}
}
@ -219,7 +221,7 @@ namespace NPSharp
client.RPC.AttachHandlerForMessageType<AuthenticateWithTokenMessage>(msg =>
{
var result = new AuthenticationResult();
var result = new NPAuthenticationResult();
if (AuthenticationHandler != null)
{
try

View File

@ -1,11 +1,10 @@
using System.Collections.Generic;
using System.Linq;
using NPSharp.RPC;
using NPSharp.RPC.Messages;
using NPSharp.RPC.Messages.Structs;
using NPSharp.RPC.Messages.Data;
using NPSharp.Steam;
namespace NPSharp
namespace NPSharp.NP
{
/// <summary>
/// Represents a remote client connection to an NP server.

View File

@ -1,4 +1,4 @@
using NPSharp.RPC.Messages.Structs;
using NPSharp.RPC.Messages.Data;
using ProtoBuf;
namespace NPSharp.RPC.Messages.Client

View File

@ -1,7 +1,7 @@
using System;
using ProtoBuf;
namespace NPSharp.RPC.Messages.Structs
namespace NPSharp.RPC.Messages.Data
{
[ProtoContract]
public sealed class FriendDetails

View File

@ -1,6 +1,6 @@
using ProtoBuf;
namespace NPSharp.RPC.Messages.Structs
namespace NPSharp.RPC.Messages.Data
{
[ProtoContract]
public sealed class FriendsPresence

View File

@ -1,4 +1,4 @@
namespace NPSharp
namespace NPSharp.RPC.Messages.Data
{
/// <summary>
/// Represents the friend's current presence activity.

View File

@ -1,7 +1,7 @@
using System;
using ProtoBuf;
namespace NPSharp.RPC.Messages.Structs
namespace NPSharp.RPC.Messages.Data
{
[ProtoContract]
public sealed class ProfileData

View File

@ -1,4 +1,4 @@
namespace NPSharp
namespace NPSharp.RPC.Messages.Data
{
/// <summary>
/// Represents the outcome of a ticket validation attempt.

View File

@ -1,4 +1,4 @@
using NPSharp.RPC.Messages.Structs;
using NPSharp.RPC.Messages.Data;
using ProtoBuf;
namespace NPSharp.RPC.Messages.Server

View File

@ -1,5 +1,5 @@
using System;
using NPSharp.RPC.Messages.Structs;
using NPSharp.RPC.Messages.Data;
using ProtoBuf;
namespace NPSharp.RPC.Messages.Server

View File

@ -1,4 +1,4 @@
using NPSharp.RPC.Messages.Structs;
using NPSharp.RPC.Messages.Data;
using ProtoBuf;
namespace NPSharp.RPC.Messages.Server

View File

@ -63,20 +63,20 @@
<Reference Include="System.Xml.Serialization" />
</ItemGroup>
<ItemGroup>
<Compile Include="AuthenticationResult.cs" />
<Compile Include="NP\NPAuthenticationResult.cs" />
<Compile Include="Authentication\SessionAuthenticationResult.cs" />
<Compile Include="Authentication\SessionAuthenticationServer.cs" />
<Compile Include="ClientEventArgs.cs" />
<Compile Include="ClientEventHandler.cs" />
<Compile Include="IAuthenticationHandler.cs" />
<Compile Include="IFileServingHandler.cs" />
<Compile Include="IFriendsHandler.cs" />
<Compile Include="IUserAvatarHandler.cs" />
<Compile Include="NPClient.cs" />
<Compile Include="NPFileException.cs" />
<Compile Include="NPServer.cs" />
<Compile Include="NPServerClient.cs" />
<Compile Include="PresenceState.cs" />
<Compile Include="Events\ClientEventArgs.cs" />
<Compile Include="Events\ClientEventHandler.cs" />
<Compile Include="Handlers\IAuthenticationHandler.cs" />
<Compile Include="Handlers\IFileServingHandler.cs" />
<Compile Include="Handlers\IFriendsHandler.cs" />
<Compile Include="Handlers\IUserAvatarHandler.cs" />
<Compile Include="NP\NPClient.cs" />
<Compile Include="NP\NPFileException.cs" />
<Compile Include="NP\NPServer.cs" />
<Compile Include="NP\NPServerClient.cs" />
<Compile Include="RPC\Messages\Data\PresenceState.cs" />
<Compile Include="RPC\Messages\Client\AuthenticateRegisterServerMessage.cs" />
<Compile Include="RPC\Messages\Server\AuthenticateRegisterServerResultMessage.cs" />
<Compile Include="RPC\Messages\Server\AuthenticateUserGroupMessage.cs" />
@ -84,17 +84,17 @@
<Compile Include="RPC\Messages\Server\AuthenticateValidateTicketResultMessage.cs" />
<Compile Include="RPC\Messages\Client\AuthenticateWithDetailsMessage.cs" />
<Compile Include="RPC\Messages\Client\AuthenticateWithKeyMessage.cs" />
<Compile Include="RPC\Messages\Structs\FriendDetails.cs" />
<Compile Include="RPC\Messages\Data\FriendDetails.cs" />
<Compile Include="RPC\Messages\Client\FriendsSetSteamIDMessage.cs" />
<Compile Include="RPC\Messages\Client\FriendsGetProfileDataMessage.cs" />
<Compile Include="RPC\Messages\Server\FriendsGetProfileDataResultMessage.cs" />
<Compile Include="RPC\Messages\Client\FriendsGetUserAvatarMessage.cs" />
<Compile Include="RPC\Messages\Server\FriendsGetUserAvatarResultMessage.cs" />
<Compile Include="RPC\Messages\Structs\FriendsPresence.cs" />
<Compile Include="RPC\Messages\Data\FriendsPresence.cs" />
<Compile Include="RPC\Messages\Server\FriendsPresenceMessage.cs" />
<Compile Include="RPC\Messages\Server\FriendsRosterMessage.cs" />
<Compile Include="RPC\Messages\Client\FriendsSetPresenceMessage.cs" />
<Compile Include="RPC\Messages\Structs\ProfileData.cs" />
<Compile Include="RPC\Messages\Data\ProfileData.cs" />
<Compile Include="RPC\RPCClientStream.cs" />
<Compile Include="RPC\Messages\Server\AuthenticateExternalStatusMessage.cs" />
<Compile Include="RPC\Messages\Server\AuthenticateResultMessage.cs" />
@ -122,8 +122,8 @@
<Compile Include="Steam\EUniverse.cs" />
<Compile Include="Steam\InteropHelp.cs" />
<Compile Include="Steam\SteamID_t.cs" />
<Compile Include="Ticket.cs" />
<Compile Include="TicketValidationResult.cs" />
<Compile Include="RPC\Messages\Data\Ticket.cs" />
<Compile Include="RPC\Messages\Data\TicketValidationResult.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="Steam\README.txt" />

View File

@ -4,6 +4,7 @@ using System.Linq;
using System.Threading.Tasks;
using System.Web;
using log4net;
using NPSharp.NP;
using uhttpsharp;
using uhttpsharp.Headers;
using HttpResponse = uhttpsharp.HttpResponse;

View File

@ -4,6 +4,7 @@ using System.Linq;
using System.Threading.Tasks;
using System.Web;
using log4net;
using NPSharp.NP;
using uhttpsharp;
using uhttpsharp.Headers;
using HttpResponse = uhttpsharp.HttpResponse;

View File

@ -9,6 +9,7 @@ using log4net.Config;
using log4net.Core;
using log4net.Layout;
using NPSharp.Authentication;
using NPSharp.NP;
using uhttpsharp;
using uhttpsharp.Handlers;
using uhttpsharp.Headers;

View File

@ -6,6 +6,7 @@ using log4net.Config;
using log4net.Core;
using log4net.Layout;
using NPSharp.Authentication;
using NPSharp.NP;
namespace NPSharp.CommandLine.MOTD
{

View File

@ -4,6 +4,9 @@ using System.Globalization;
using System.Linq;
using log4net;
using NPSharp.CommandLine.Server.Database;
using NPSharp.Handlers;
using NPSharp.NP;
using NPSharp.RPC.Messages.Data;
using NPSharp.Steam;
namespace NPSharp.CommandLine.Server
@ -19,15 +22,15 @@ namespace NPSharp.CommandLine.Server
_db = database;
}
public AuthenticationResult AuthenticateUser(NPServerClient client, string username, string password)
public NPAuthenticationResult AuthenticateUser(NPServerClient client, string username, string password)
{
// Nah, authenticating this way is deprecated as fuck.
return new AuthenticationResult();
return new NPAuthenticationResult();
}
public AuthenticationResult AuthenticateUser(NPServerClient client, string token)
public NPAuthenticationResult AuthenticateUser(NPServerClient client, string token)
{
var ar = new AuthenticationResult();
var ar = new NPAuthenticationResult();
// Check if token is valid
_db.ValidateSession(token, session =>
@ -38,7 +41,7 @@ namespace NPSharp.CommandLine.Server
}
ar =
new AuthenticationResult(new CSteamID
new NPAuthenticationResult(new CSteamID
{
AccountID = session.User.UserNumber,
AccountInstance = 1,
@ -53,7 +56,7 @@ namespace NPSharp.CommandLine.Server
return ar;
}
public AuthenticationResult AuthenticateServer(NPServerClient client, string licenseKey)
public NPAuthenticationResult AuthenticateServer(NPServerClient client, string licenseKey)
{
// TODO: AuthenticateServer
throw new NotImplementedException();

View File

@ -2,6 +2,8 @@
using System.Linq;
using System.Text;
using NPSharp.CommandLine.Server.Database;
using NPSharp.Handlers;
using NPSharp.NP;
namespace NPSharp.CommandLine.Server
{

View File

@ -9,6 +9,7 @@ using log4net.Core;
using log4net.Layout;
using NPSharp.Authentication;
using NPSharp.CommandLine.Server.Database;
using NPSharp.NP;
namespace NPSharp.CommandLine.Server
{