| [244] | 1 | using System;
|
|---|
| 2 | using System.Collections.Generic;
|
|---|
| [332] | 3 | using System.Net;
|
|---|
| [369] | 4 | using Platform.Steam;
|
|---|
| [244] | 5 |
|
|---|
| [325] | 6 | namespace AllocsFixes.NetConnections.Servers.Web {
|
|---|
| [244] | 7 | public class ConnectionHandler {
|
|---|
| [325] | 8 | private readonly Dictionary<string, WebConnection> connections = new Dictionary<string, WebConnection> ();
|
|---|
| [244] | 9 |
|
|---|
| [332] | 10 | public WebConnection IsLoggedIn (string _sessionId, IPAddress _ip) {
|
|---|
| [382] | 11 | if (!connections.TryGetValue (_sessionId, out WebConnection con)) {
|
|---|
| [244] | 12 | return null;
|
|---|
| 13 | }
|
|---|
| 14 |
|
|---|
| 15 | // if (con.Age.TotalMinutes > parent.sessionTimeoutMinutes) {
|
|---|
| 16 | // connections.Remove (_sessionId);
|
|---|
| 17 | // return null;
|
|---|
| 18 | // }
|
|---|
| 19 |
|
|---|
| [332] | 20 | if (!Equals (con.Endpoint, _ip)) {
|
|---|
| 21 | // Fixed: Allow different clients from same NAT network
|
|---|
| 22 | // connections.Remove (_sessionId);
|
|---|
| [244] | 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 |
|
|---|
| [332] | 35 | public WebConnection LogIn (ulong _steamId, IPAddress _ip) {
|
|---|
| [244] | 36 | string sessionId = Guid.NewGuid ().ToString ();
|
|---|
| [369] | 37 | PlatformUserIdentifierAbs userId = new UserIdentifierSteam (_steamId);
|
|---|
| 38 | WebConnection con = new WebConnection (sessionId, _ip, userId);
|
|---|
| [244] | 39 | connections.Add (sessionId, con);
|
|---|
| 40 | return con;
|
|---|
| 41 | }
|
|---|
| 42 |
|
|---|
| [351] | 43 | public void SendLine (string _line) {
|
|---|
| [332] | 44 | foreach (KeyValuePair<string, WebConnection> kvp in connections) {
|
|---|
| [351] | 45 | kvp.Value.SendLine (_line);
|
|---|
| [244] | 46 | }
|
|---|
| 47 | }
|
|---|
| 48 | }
|
|---|
| [325] | 49 | }
|
|---|