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