-
Notifications
You must be signed in to change notification settings - Fork 8
/
TcpNETServerAuth.cs
86 lines (81 loc) · 2.99 KB
/
TcpNETServerAuth.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
using PHS.Networking.Enums;
using PHS.Networking.Server.Services;
using System.Threading.Tasks;
using Tcp.NET.Server.Events.Args;
using Tcp.NET.Server.Handlers;
using Tcp.NET.Server.Managers;
using Tcp.NET.Server.Models;
namespace Tcp.NET.Server
{
public class TcpNETServerAuth<T> :
TcpNETServerAuthBase<
TcpConnectionServerAuthEventArgs<T>,
TcpMessageServerAuthEventArgs<T>,
TcpErrorServerAuthEventArgs<T>,
IParamsTcpServerAuth,
TcpHandlerServerAuth<T>,
TcpConnectionManagerAuth<T>,
IdentityTcpServer<T>,
T,
TcpAuthorizeEventArgs<T>>,
ITcpNETServerAuth<T>
{
public TcpNETServerAuth(IParamsTcpServerAuth parameters,
IUserService<T> userService) : base(parameters, userService)
{
}
public TcpNETServerAuth(IParamsTcpServerAuth parameters,
IUserService<T> userService,
byte[] certificate,
string certificatePassword) : base(parameters, userService, certificate, certificatePassword)
{
}
protected override TcpConnectionManagerAuth<T> CreateConnectionManager()
{
return new TcpConnectionManagerAuth<T>();
}
protected override TcpHandlerServerAuth<T> CreateHandler()
{
return _certificate == null
? new TcpHandlerServerAuth<T>(_parameters)
: new TcpHandlerServerAuth<T>(_parameters, _certificate, _certificatePassword);
}
protected override TcpConnectionServerAuthEventArgs<T> CreateConnectionEventArgs(TcpConnectionServerBaseEventArgs<IdentityTcpServer<T>> args)
{
return new TcpConnectionServerAuthEventArgs<T>
{
Connection = args.Connection,
ConnectionEventType = args.ConnectionEventType
};
}
protected override TcpMessageServerAuthEventArgs<T> CreateMessageEventArgs(TcpMessageServerBaseEventArgs<IdentityTcpServer<T>> args)
{
return new TcpMessageServerAuthEventArgs<T>
{
Bytes = args.Bytes,
Connection = args.Connection,
Message = args.Message,
MessageEventType = args.MessageEventType,
CancellationToken = args.CancellationToken
};
}
protected override TcpErrorServerAuthEventArgs<T> CreateErrorEventArgs(TcpErrorServerBaseEventArgs<IdentityTcpServer<T>> args)
{
return new TcpErrorServerAuthEventArgs<T>
{
Connection = args.Connection,
Exception = args.Exception,
Message = args.Message,
CancellationToken = args.CancellationToken
};
}
public override void Dispose()
{
if (_handler != null)
{
_handler.AuthorizeEvent -= OnAuthorizeEvent;
}
base.Dispose();
}
}
}