| 1 | using System;
|
|---|
| 2 | using System.Collections.Generic;
|
|---|
| 3 | using System.Net;
|
|---|
| 4 | using Platform.Steam;
|
|---|
| 5 |
|
|---|
| 6 | namespace AllocsFixes.NetConnections.Servers.Web {
|
|---|
| 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.ContainsKey (_sessionId)) {
|
|---|
| 12 | return null;
|
|---|
| 13 | }
|
|---|
| 14 |
|
|---|
| 15 | WebConnection con = connections [_sessionId];
|
|---|
| 16 |
|
|---|
| 17 | // if (con.Age.TotalMinutes > parent.sessionTimeoutMinutes) {
|
|---|
| 18 | // connections.Remove (_sessionId);
|
|---|
| 19 | // return null;
|
|---|
| 20 | // }
|
|---|
| 21 |
|
|---|
| 22 | if (!Equals (con.Endpoint, _ip)) {
|
|---|
| 23 | // Fixed: Allow different clients from same NAT network
|
|---|
| 24 | // connections.Remove (_sessionId);
|
|---|
| 25 | return null;
|
|---|
| 26 | }
|
|---|
| 27 |
|
|---|
| 28 | con.UpdateUsage ();
|
|---|
| 29 |
|
|---|
| 30 | return con;
|
|---|
| 31 | }
|
|---|
| 32 |
|
|---|
| 33 | public void LogOut (string _sessionId) {
|
|---|
| 34 | connections.Remove (_sessionId);
|
|---|
| 35 | }
|
|---|
| 36 |
|
|---|
| 37 | public WebConnection LogIn (ulong _steamId, IPAddress _ip) {
|
|---|
| 38 | string sessionId = Guid.NewGuid ().ToString ();
|
|---|
| 39 | PlatformUserIdentifierAbs userId = new UserIdentifierSteam (_steamId);
|
|---|
| 40 | WebConnection con = new WebConnection (sessionId, _ip, userId);
|
|---|
| 41 | connections.Add (sessionId, con);
|
|---|
| 42 | return con;
|
|---|
| 43 | }
|
|---|
| 44 |
|
|---|
| 45 | public void SendLine (string _line) {
|
|---|
| 46 | foreach (KeyValuePair<string, WebConnection> kvp in connections) {
|
|---|
| 47 | kvp.Value.SendLine (_line);
|
|---|
| 48 | }
|
|---|
| 49 | }
|
|---|
| 50 | }
|
|---|
| 51 | }
|
|---|