public bool AddAndCheck(Connection connection, double cost) { lock (_delays) { double delay; if (!_delays.TryGetValue(connection.Address, out delay)) { if (cost > 0) _delays.Add(connection.Address, Math.Min(cost, DelayLimit)); } else { _delays[connection.Address] = Math.Min(delay + cost, DelayLimit); } var shouldDelay = (delay + cost) >= DelayThreshold; if (shouldDelay) connection.SendSysMessage("Too many requests are coming from your location and your request has been canceled. Please wait and try again in a few minutes."); return shouldDelay; } }
public abstract void Handle(Connection connection);
public void Add(Connection connection) { List<string> rooms; bool firstConnection; lock (_sync) { if (_connections.Contains(connection)) return; _connections.Add(connection); connection.Session = this; rooms = _rooms.ToList(); firstConnection = _firstConnection; _firstConnection = false; } foreach (var roomName in rooms) { var room = Program.RoomManager.Get(roomName); if (room == null) continue; connection.SendJoinRoom(room); if (firstConnection) room.SessionEnter(this); } }
public void Remove(Connection connection) { lock (_sync) { _connections.Remove(connection); } }
// For RohBot rooms public CommandTarget(Connection connection, string room) { Room = Program.RoomManager.Get(room); Connection = connection; }
// For RohBot rooms public CommandTarget(Connection connection, string room) { Room = Program.RoomManager.Get(room); Connection = connection; }
public bool Check(Connection connection) { return AddAndCheck(connection, 0); }