source: binary-improvements2/WebServer/src/ConnectionHandler.cs@ 391

Last change on this file since 391 was 391, checked in by alloc, 2 years ago

Major refactoring/cleanup

File size: 1.3 KB
RevLine 
[391]1using System;
2using System.Collections.Generic;
3using System.Net;
4using Platform.Steam;
5
6namespace Webserver {
7 public class ConnectionHandler {
8 private readonly Dictionary<string, WebConnection> connections = new Dictionary<string, WebConnection> ();
9
10 public WebConnection IsLoggedIn (string _sessionId, IPAddress _ip) {
11 if (!connections.TryGetValue (_sessionId, out WebConnection con)) {
12 return null;
13 }
14
15// if (con.Age.TotalMinutes > parent.sessionTimeoutMinutes) {
16// connections.Remove (_sessionId);
17// return null;
18// }
19
20 if (!Equals (con.Endpoint, _ip)) {
21 // Fixed: Allow different clients from same NAT network
22// connections.Remove (_sessionId);
23 return null;
24 }
25
26 con.UpdateUsage ();
27
28 return con;
29 }
30
31 public void LogOut (string _sessionId) {
32 connections.Remove (_sessionId);
33 }
34
35 public WebConnection LogIn (ulong _steamId, IPAddress _ip) {
36 string sessionId = Guid.NewGuid ().ToString ();
37 PlatformUserIdentifierAbs userId = new UserIdentifierSteam (_steamId);
38 WebConnection con = new WebConnection (sessionId, _ip, userId);
39 connections.Add (sessionId, con);
40 return con;
41 }
42
43 public void SendLine (string _line) {
44 foreach (KeyValuePair<string, WebConnection> kvp in connections) {
45 kvp.Value.SendLine (_line);
46 }
47 }
48 }
49}
Note: See TracBrowser for help on using the repository browser.