- Timestamp:
- Sep 13, 2014, 12:55:47 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
binary-improvements/7dtd-server-fixes/src/NetConnections/Servers/Telnet/Telnet.cs
r187 r190 63 63 } 64 64 65 public bool RegisterFailedLogin (int addressHash)66 {67 lock (loginAttemptsPerIP) {68 LoginAttempts la = loginAttemptsPerIP [addressHash];69 return la.LogAttempt ();70 }71 }72 73 65 private void AcceptClient (IAsyncResult asyncResult) 74 66 { … … 80 72 if (endpoint is IPEndPoint) { 81 73 addressHash = ((IPEndPoint)endpoint).Address.GetHashCode (); 82 //Log.Out ("Hash: " + endpointAddressHash);83 74 } else { 75 addressHash = endpoint.GetHashCode (); 84 76 Log.Out ("EndPoint is not an IPEndPoint but: " + endpoint.GetType ().ToString ()); 85 77 } … … 87 79 lock (loginAttemptsPerIP) { 88 80 LoginAttempts la = null; 89 if (loginAttemptsPerIP.ContainsKey (addressHash))81 if (loginAttemptsPerIP.ContainsKey (addressHash)) 90 82 la = loginAttemptsPerIP [addressHash]; 91 83 if (la == null) { … … 95 87 if (!la.IsBanned ()) { 96 88 TelnetConnection con = new TelnetConnection (this, client, authEnabled); 97 connections.Add (con); 89 lock (connections) { 90 connections.Add (con); 91 } 98 92 } else { 99 93 client.Close (); … … 102 96 } 103 97 listener.BeginAcceptTcpClient (new AsyncCallback (AcceptClient), null); 98 } 99 } 100 101 public bool RegisterFailedLogin (TelnetConnection con) 102 { 103 lock (loginAttemptsPerIP) { 104 LoginAttempts la = loginAttemptsPerIP [con.EndPointHash]; 105 return la.LogAttempt (); 106 } 107 } 108 109 public void ConnectionClosed (TelnetConnection con) 110 { 111 lock (connections) { 112 connections.Remove (con); 104 113 } 105 114 } … … 112 121 listener = null; 113 122 } 114 foreach (TelnetConnection c in connections) { 123 List<TelnetConnection> cur = new List<TelnetConnection> (connections); 124 foreach (TelnetConnection c in cur) { 115 125 c.Close (); 116 126 } … … 120 130 } 121 131 122 private void RemoveClosedConnections () 123 { 124 try { 125 List<TelnetConnection> toRemove = new List<TelnetConnection> (); 126 foreach (TelnetConnection c in connections) { 127 if (c.IsClosed ()) 128 toRemove.Add (c); 129 } 130 foreach (TelnetConnection c in toRemove) { 131 connections.Remove (c); 132 } 133 } catch (Exception e) { 134 Log.Out ("Error in Telnet.RemoveClosedConnections: " + e); 135 } 136 } 137 138 public void WriteToClient (string line) 132 public void SendLine (string line) 139 133 { 140 134 if (line == null) { 141 135 return; 142 136 } 143 RemoveClosedConnections ();144 foreach (TelnetConnection c in connections) {145 if (c.IsAuthenticated ())146 c.WriteLine (line);137 lock (connections) { 138 foreach (TelnetConnection c in connections) { 139 c.SendLine (line); 140 } 147 141 } 148 142 } 149 143 150 public void WriteToClient_Single (string line, IConnection client)144 public void SendLog (string text, string trace, UnityEngine.LogType type) 151 145 { 152 if (line == null) { 153 return; 154 } 155 RemoveClosedConnections (); 156 foreach (TelnetConnection con in connections) { 157 if (con == client) { 158 if (con.IsAuthenticated ()) 159 con.WriteLine (line); 160 } 161 } 146 throw new System.NotImplementedException (); 162 147 } 163 148
Note:
See TracChangeset
for help on using the changeset viewer.