[391] | 1 | using System;
|
---|
| 2 | using System.Collections.Generic;
|
---|
| 3 | using System.Net;
|
---|
| 4 |
|
---|
| 5 | namespace Webserver {
|
---|
| 6 | public class ConnectionHandler {
|
---|
| 7 | private readonly Dictionary<string, WebConnection> connections = new Dictionary<string, WebConnection> ();
|
---|
| 8 |
|
---|
| 9 | public WebConnection IsLoggedIn (string _sessionId, IPAddress _ip) {
|
---|
| 10 | if (!connections.TryGetValue (_sessionId, out WebConnection con)) {
|
---|
| 11 | return null;
|
---|
| 12 | }
|
---|
| 13 |
|
---|
| 14 | // if (con.Age.TotalMinutes > parent.sessionTimeoutMinutes) {
|
---|
| 15 | // connections.Remove (_sessionId);
|
---|
| 16 | // return null;
|
---|
| 17 | // }
|
---|
| 18 |
|
---|
[407] | 19 | // if (!Equals (con.Endpoint, _ip)) { // reverse proxy = same source ip!!
|
---|
| 20 | // connections.Remove (_sessionId);
|
---|
| 21 | // return null;
|
---|
| 22 | // }
|
---|
[391] | 23 |
|
---|
| 24 | con.UpdateUsage ();
|
---|
| 25 |
|
---|
| 26 | return con;
|
---|
| 27 | }
|
---|
| 28 |
|
---|
| 29 | public void LogOut (string _sessionId) {
|
---|
| 30 | connections.Remove (_sessionId);
|
---|
| 31 | }
|
---|
| 32 |
|
---|
[404] | 33 | public WebConnection LogIn (IPAddress _ip, string _username, PlatformUserIdentifierAbs _userId, PlatformUserIdentifierAbs _crossUserId = null) {
|
---|
[391] | 34 | string sessionId = Guid.NewGuid ().ToString ();
|
---|
[404] | 35 | WebConnection con = new WebConnection (sessionId, _ip, _username, _userId, _crossUserId);
|
---|
[391] | 36 | connections.Add (sessionId, con);
|
---|
| 37 | return con;
|
---|
| 38 | }
|
---|
| 39 |
|
---|
| 40 | public void SendLine (string _line) {
|
---|
| 41 | foreach (KeyValuePair<string, WebConnection> kvp in connections) {
|
---|
| 42 | kvp.Value.SendLine (_line);
|
---|
| 43 | }
|
---|
| 44 | }
|
---|
| 45 | }
|
---|
| 46 | }
|
---|