Last change
on this file since 402 was 402, checked in by alloc, 22 months ago |
- Major refactoring
- Using Utf8Json for (de)serialization
- Moving APIs to REST
- Removing dependencies from WebServer and MapRenderer to ServerFixes
|
File size:
1.1 KB
|
Line | |
---|
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 |
|
---|
19 | if (!Equals (con.Endpoint, _ip)) {
|
---|
20 | connections.Remove (_sessionId);
|
---|
21 | return null;
|
---|
22 | }
|
---|
23 |
|
---|
24 | con.UpdateUsage ();
|
---|
25 |
|
---|
26 | return con;
|
---|
27 | }
|
---|
28 |
|
---|
29 | public void LogOut (string _sessionId) {
|
---|
30 | connections.Remove (_sessionId);
|
---|
31 | }
|
---|
32 |
|
---|
33 | public WebConnection LogIn (PlatformUserIdentifierAbs _userId, IPAddress _ip) {
|
---|
34 | string sessionId = Guid.NewGuid ().ToString ();
|
---|
35 | WebConnection con = new WebConnection (sessionId, _ip, _userId);
|
---|
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 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.