mirror of https://github.com/icedream/npsharp.git
Some code cleanup
parent
301281737c
commit
f43f20522f
|
@ -16,8 +16,8 @@ namespace NPSharp
|
|||
{
|
||||
private readonly List<NPServerClient> _clients;
|
||||
private readonly ILog _log;
|
||||
private readonly Socket _socket;
|
||||
private readonly ushort _port;
|
||||
private readonly Socket _socket;
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a new NP server.
|
||||
|
@ -31,6 +31,34 @@ namespace NPSharp
|
|||
_port = port;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The handler to use for file requests to this NP server.
|
||||
/// </summary>
|
||||
public IFileServingHandler FileServingHandler { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The handler to use for user avatar requests to this NP server.
|
||||
/// </summary>
|
||||
public IUserAvatarHandler UserAvatarHandler { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Returns all currently connected clients
|
||||
/// </summary>
|
||||
public NPServerClient[] Clients
|
||||
{
|
||||
get { return _clients.ToArray(); } // Avoid race condition by IEnum changes
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The handler to use for authentication requests to this NP server.
|
||||
/// </summary>
|
||||
public IAuthenticationHandler AuthenticationHandler { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The handler to use for friends-related requests to this NP server.
|
||||
/// </summary>
|
||||
public IFriendsHandler FriendsHandler { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Starts up the NP server.
|
||||
/// </summary>
|
||||
|
@ -89,34 +117,6 @@ namespace NPSharp
|
|||
_socket.Shutdown(SocketShutdown.Both);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The handler to use for file requests to this NP server.
|
||||
/// </summary>
|
||||
public IFileServingHandler FileServingHandler { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The handler to use for user avatar requests to this NP server.
|
||||
/// </summary>
|
||||
public IUserAvatarHandler UserAvatarHandler { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Returns all currently connected clients
|
||||
/// </summary>
|
||||
public NPServerClient[] Clients
|
||||
{
|
||||
get { return _clients.ToArray(); } // Avoid race condition by IEnum changes
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The handler to use for authentication requests to this NP server.
|
||||
/// </summary>
|
||||
public IAuthenticationHandler AuthenticationHandler { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The handler to use for friends-related requests to this NP server.
|
||||
/// </summary>
|
||||
public IFriendsHandler FriendsHandler { get; set; }
|
||||
|
||||
internal void _handleClient(NPServerClient client)
|
||||
{
|
||||
_log.Debug("Client now being handled");
|
||||
|
@ -233,7 +233,7 @@ namespace NPSharp
|
|||
// Send authentication result directly to client
|
||||
client.RPC.Send(new AuthenticateResultMessage
|
||||
{
|
||||
NPID = result.UserID == null ? 0 : result.UserID.AccountID,
|
||||
NPID = result.UserID == null ? 0 : result.UserID.ConvertToUint64(),
|
||||
Result = result.Result ? 0 : 1,
|
||||
SessionToken = msg.Token
|
||||
});
|
||||
|
|
|
@ -26,7 +26,8 @@ namespace NPSharp
|
|||
|
||||
public IEnumerable<FriendDetails> Friends
|
||||
{
|
||||
get {
|
||||
get
|
||||
{
|
||||
return NP.FriendsHandler == null
|
||||
? new FriendDetails[0]
|
||||
: NP.FriendsHandler.GetFriends(this).ToArray();
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
|
@ -127,7 +126,7 @@ namespace NPSharp.RPC.Messages
|
|||
Log.DebugFormat("{3}[ID={0},Type={1},TypeName={2}] {{", mid, message.GetTypeId(), message.GetType().Name,
|
||||
typeof (T).Name);
|
||||
foreach (
|
||||
PropertyInfo prop in
|
||||
var prop in
|
||||
message.GetType().GetProperties().Where(p => !(p.DeclaringType == typeof (RPCServerMessage))))
|
||||
{
|
||||
Log.DebugFormat("\t{0} = {1}", prop.Name, prop.GetValue(message));
|
||||
|
@ -168,7 +167,7 @@ namespace NPSharp.RPC.Messages
|
|||
#if DEBUG
|
||||
Log.DebugFormat("{3}[ID={0},Type={1},TypeName={2}] {{", MessageId, GetTypeId(), GetType().Name,
|
||||
GetType().Name);
|
||||
foreach (PropertyInfo prop in GetType().GetProperties())
|
||||
foreach (var prop in GetType().GetProperties())
|
||||
{
|
||||
Log.DebugFormat("\t{0} = {1}", prop.Name, prop.GetValue(this));
|
||||
}
|
||||
|
|
|
@ -134,7 +134,7 @@ namespace NPSharp.RPC
|
|||
if (message.MessageId == default(uint))
|
||||
message.MessageId = MessageID;
|
||||
|
||||
byte[] buffer = message.Serialize();
|
||||
var buffer = message.Serialize();
|
||||
|
||||
_sock.Send(buffer);
|
||||
|
||||
|
|
|
@ -15,15 +15,13 @@ namespace NPSharp.CommandLine.Server
|
|||
_db = database;
|
||||
}
|
||||
|
||||
~BrightstarDatabaseFileServingHandler()
|
||||
{
|
||||
_db.Dispose();
|
||||
}
|
||||
|
||||
public byte[] ReadUserFile(NPServerClient client, string file)
|
||||
{
|
||||
var resultEnum =
|
||||
_db.UserFiles.Where(uf => uf.User.Id == client.UserID.AccountID.ToString(CultureInfo.InvariantCulture) && uf.FileName == file);
|
||||
_db.UserFiles.Where(
|
||||
uf =>
|
||||
uf.User.Id == client.UserID.AccountID.ToString(CultureInfo.InvariantCulture) &&
|
||||
uf.FileName == file);
|
||||
|
||||
return resultEnum.Any() ? resultEnum.Single().FileData : null;
|
||||
}
|
||||
|
@ -39,7 +37,11 @@ namespace NPSharp.CommandLine.Server
|
|||
public void WriteUserFile(NPServerClient client, string file, byte[] data)
|
||||
{
|
||||
var resultEnum =
|
||||
_db.UserFiles.Where(uf => uf.User.Id == client.UserID.AccountID.ToString(CultureInfo.InvariantCulture) && uf.FileName == file);
|
||||
_db.UserFiles.Where(
|
||||
uf =>
|
||||
uf.User.Id == client.UserID.AccountID.ToString(CultureInfo.InvariantCulture) &&
|
||||
uf.FileName == file)
|
||||
.ToArray();
|
||||
|
||||
var userFile = resultEnum.Any() ? resultEnum.Single() : _db.UserFiles.Create();
|
||||
userFile.FileName = file;
|
||||
|
@ -49,6 +51,11 @@ namespace NPSharp.CommandLine.Server
|
|||
_db.SaveChanges();
|
||||
}
|
||||
|
||||
~BrightstarDatabaseFileServingHandler()
|
||||
{
|
||||
_db.Dispose();
|
||||
}
|
||||
|
||||
protected byte[] GetDefaultUserFile(string file)
|
||||
{
|
||||
switch (file)
|
||||
|
|
|
@ -1,9 +1,4 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using System.Text;
|
||||
using BrightstarDB.EntityFramework;
|
||||
using BrightstarDB.EntityFramework;
|
||||
|
||||
namespace NPSharp.CommandLine.Server.Database
|
||||
{
|
||||
|
|
|
@ -7,7 +7,6 @@ namespace NPSharp.CommandLine.Server.Database
|
|||
[Entity]
|
||||
public interface IUser
|
||||
{
|
||||
[Identifier("http://npserver.icedream.kthx.at/users/")]
|
||||
string Id { get; }
|
||||
|
||||
string UserName { get; set; }
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
using System;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
@ -89,9 +88,8 @@ namespace NPSharp.CommandLine.Server
|
|||
_log.DebugFormat("Ban {0} became invalid", ban.Id);
|
||||
dbForCleanup.DeleteObject(ban);
|
||||
}
|
||||
foreach (
|
||||
var cheatDetection in
|
||||
dbForCleanup.CheatDetections.Where(s => s.ExpiryTime < DateTime.Now).ToArray())
|
||||
|
||||
foreach (var cheatDetection in dbForCleanup.CheatDetections.Where(s => s.ExpiryTime < DateTime.Now).ToArray())
|
||||
{
|
||||
_log.DebugFormat("Cheat detection {0} became invalid", cheatDetection.Id);
|
||||
dbForCleanup.DeleteObject(cheatDetection);
|
||||
|
@ -212,8 +210,7 @@ namespace NPSharp.CommandLine.Server
|
|||
{
|
||||
appender,
|
||||
new DebugAppender {Layout = appender.Layout, Threshold = Level.All}
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -232,8 +229,7 @@ namespace NPSharp.CommandLine.Server
|
|||
{
|
||||
Level = Level.Debug,
|
||||
ForeColor = ColoredConsoleAppender.Colors.Cyan | ColoredConsoleAppender.Colors.HighIntensity
|
||||
}
|
||||
);
|
||||
});
|
||||
appender.AddMapping(
|
||||
new ColoredConsoleAppender.LevelColors
|
||||
{
|
||||
|
@ -249,8 +245,7 @@ namespace NPSharp.CommandLine.Server
|
|||
Level = Level.Warn,
|
||||
ForeColor =
|
||||
ColoredConsoleAppender.Colors.Purple | ColoredConsoleAppender.Colors.HighIntensity
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
appender.AddMapping(
|
||||
new ColoredConsoleAppender.LevelColors
|
||||
|
@ -266,8 +261,7 @@ namespace NPSharp.CommandLine.Server
|
|||
ForeColor =
|
||||
ColoredConsoleAppender.Colors.White | ColoredConsoleAppender.Colors.HighIntensity,
|
||||
BackColor = ColoredConsoleAppender.Colors.Red
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
appender.ActivateOptions();
|
||||
BasicConfigurator.Configure(
|
||||
|
@ -275,8 +269,7 @@ namespace NPSharp.CommandLine.Server
|
|||
{
|
||||
appender,
|
||||
new DebugAppender {Layout = appender.Layout, Threshold = Level.All}
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
_log = LogManager.GetLogger("Main");
|
||||
|
|
Loading…
Reference in New Issue