private bool CheckBanned(IPAddress ip) { lock (banned) if (banned.Contains((s) => s.Equals(ip))) { return(true); } return(false); }
internal async Task LoadViewModelAsync(ViewModelBase vm) { if (vm == null) { return; } if (!_viewModelsLoaded.Contains(vm)) { // Call load state on the sub-viewmodel once its requested to be set to curent. await vm.LoadStateAsync(this.View, _loadState); _viewModelsLoaded.Add(vm); } else { await vm.RefreshAsync(false); } }
public bool IsCheckingMyFirewall(IPEndPoint endpoint) { if (!FirewallOpen) { lock (myfirewalltests) { TestingFirewall = !myfirewalltests.Contains((s) => s.ExternalIp.Equals(endpoint.Address)); if (!TestingFirewall) { FirewallOpen = true; myfirewalltests.Clear(); } } return(FirewallOpen); } else { return(false); } }
private void Validate_Claims(Binding binding, ModelList<ClaimsetType> claims, SoaModel model) { foreach (Endpoint endpoint in model.Instances.OfType<Endpoint>().Where(ep => ep.Binding == binding)) { Authorization authorization = endpoint.Authorization; if (authorization != null) { foreach (OperationAuthorization operation in authorization.OperationAuthorizations) { foreach (Reference reference in operation.References.Where(rf => rf.Object is ClaimsetType)) { ClaimsetType claimset = (ClaimsetType)reference.Object; if (!claims.Contains(claimset)) { claims.Add(claimset); } } foreach (Reference reference in operation.References.Where(rf => rf.Object is ClaimField)) { ClaimsetType claimset = ((ClaimField)reference.Object).Claimset; if (!claims.Contains(claimset)) { claims.Add(claimset); } } } } } }
/// <summary> /// Sqls the create table. /// </summary> /// <returns> /// The create table. /// </returns> /// <param name='type'> /// Type. /// </param> public string sqlCreateTable(Type type) { StringBuilder sql = new StringBuilder(); PropertyInfo[] properties = type.GetProperties(); ModelList<string> sqlFields = new ModelList<string>(); ModelList<string> primaryFields = new ModelList<string>(); ModelList<string> indexFields = new ModelList<string>(); ModelList<string> uniqueFields = new ModelList<string>(); ModelList<string> foreignFields = new ModelList<string>(); //ModelList<string> keys = new ModelList<string>(); ModelList<string> createdModelsName = new ModelList<string>(); sql.Append("CREATE TABLE IF NOT EXISTS " + this.sqlEscapeTable(type.Name) + " ("); for(int i = 0; i < properties.Length; i++) { TemplatizeAttribute[] attributes = (TemplatizeAttribute[])properties[i].GetCustomAttributes(typeof(TemplatizeAttribute), true); PrimaryKeyAttribute[] primaryKeys = (PrimaryKeyAttribute[])properties[i].GetCustomAttributes(typeof(PrimaryKeyAttribute), true); IndexAttribute[] indexes = (IndexAttribute[])properties[i].GetCustomAttributes(typeof(IndexAttribute), true); //ForeignKeyAttribute[] foreigns = (ForeignKeyAttribute[])properties[i].GetCustomAttributes(typeof(ForeignKeyAttribute), true); if(primaryKeys.Length > 0) { primaryFields.Add(this.sqlEscapeField(properties[i].Name)); } else if(indexes.Length > 0 && indexes[0].Unique) { uniqueFields.Add(this.sqlEscapeField(properties[i].Name)); } else if(indexes.Length > 0) { indexFields.Add(this.sqlEscapeField(properties[i].Name)); } if(attributes.Length > 0) { string sqlType = this.convertTypeToSql(properties[i].PropertyType); if(primaryKeys.Length > 0 && primaryKeys[0].AutoIncrement) { sqlFields.Add(this.sqlEscapeField(properties[i].Name) + " " + sqlType + " NOT NULL AUTO_INCREMENT"); } else { if(properties[i].PropertyType.GetInterface("IModelizable") != null && !createdModelsName.Contains(properties[i].PropertyType.ToString())) { if(properties[i].PropertyType.GetInterface("IList") != null) { if(properties[i].PropertyType.GetGenericArguments()[0].GetInterface("IModelizable") != null) { foreignFields.Add(this.sqlCreateTable(properties[i].PropertyType.GetGenericArguments()[0])); foreignFields.Add(this.sqlCreateForeignTable(type, properties[i].PropertyType.GetGenericArguments()[0])); } else { foreignFields.Add(this.sqlCreateForeignBasicTable(type, properties[i].Name, properties[i].PropertyType.GetGenericArguments()[0])); } } else { foreignFields.Add(this.sqlCreateTable(properties[i].PropertyType)); foreignFields.Add(this.sqlCreateForeignTable(type, properties[i].PropertyType)); } createdModelsName.Add(properties[i].PropertyType.ToString()); } else { sqlFields.Add(this.sqlEscapeField(properties[i].Name) + " " + sqlType + " NOT NULL"); } } } } if(primaryFields.Count > 0) { sqlFields.Add("PRIMARY KEY (" + string.Join(",", primaryFields.ToArray()) + ")"); } if(uniqueFields.Count > 0) { sqlFields.Add("UNIQUE KEY (" + string.Join(",", uniqueFields.ToArray()) + ")"); } if(indexFields.Count > 0) { sqlFields.Add("KEY (" + string.Join(",", indexFields.ToArray()) + ")"); } sql.Append(string.Join(",", sqlFields.ToArray())); sql.Append(") ENGINE=InnoDB DEFAULT CHARSET=utf8"); if(foreignFields.Count > 0) { sql.Append(";" + string.Join(";", foreignFields.ToArray())); } return sql.ToString(); }
/// <summary> /// Packets handled in this function are 'internal' and cannot be overriden. /// </summary> internal bool HandlePacket(PacketEventArgs e) { if (IsCaptcha) { switch ((AresId)e.Packet.Id) { case AresId.MSG_CHAT_CLIENT_FASTPING: fastping = true; return(true); case AresId.MSG_CHAT_CLIENT_AUTOLOGIN: AutoLogin login = (AutoLogin)e.Packet; Commands.HandleAutoLogin(server, this, login.Sha1Password); return(true); case AresId.MSG_CHAT_CLIENT_PUBLIC: ClientPublic pub = (ClientPublic)e.Packet; FinishCaptcha(pub.Message); return(true); case AresId.MSG_CHAT_CLIENT_EMOTE: ClientEmote emote = (ClientEmote)e.Packet; FinishCaptcha(emote.Message); return(true); case AresId.MSG_CHAT_CLIENT_ADDSHARE: return(true); case AresId.MSG_CHAT_CLIENT_UPDATE_STATUS: ClientUpdate update = (ClientUpdate)e.Packet; lastupdate = DateTime.Now; NodeIp = update.NodeIp; NodePort = update.NodePort; Age = (update.Age != 0) ? update.Age : Age; Gender = (update.Gender != 0) ? update.Gender : Gender; Country = (update.Country != 0) ? update.Country : Country; //Region = !String.IsNullOrEmpty(update.Region) ? update.Region : Region; return(true); default: break; } return(false); } else if (LoggedIn) { switch ((AresId)e.Packet.Id) { case AresId.MSG_CHAT_CLIENT_FASTPING: fastping = true; return(true); case AresId.MSG_CHAT_CLIENT_DUMMY: return(true); case AresId.MSG_CHAT_CLIENT_PUBLIC: ClientPublic pub = (ClientPublic)e.Packet; if (!String.IsNullOrEmpty(pub.Message)) { if (pub.Message.StartsWith("#") && Commands.HandlePreCommand(server, this, pub.Message.Substring(1))) { return(true); } } if (Muzzled) { server.SendAnnounce(this, Strings.AreMuzzled); return(true); } return(false); case AresId.MSG_CHAT_CLIENT_EMOTE: ClientEmote emote = (ClientEmote)e.Packet; if (!String.IsNullOrEmpty(emote.Message)) { if (emote.Message.StartsWith("#") && Commands.HandlePreCommand(server, this, emote.Message.Substring(1))) { return(true); } } if (Muzzled) { server.SendAnnounce(this, Strings.AreMuzzled); return(true); } return(false); case AresId.MSG_CHAT_CLIENT_COMMAND: Command cmd = (Command)e.Packet; Commands.HandlePreCommand(server, this, cmd.Message); break; case AresId.MSG_CHAT_CLIENT_PVT: Private pvt = (Private)e.Packet; if (Muzzled && !server.Config.MuzzledPMs) { pvt.Message = "[" + Strings.AreMuzzled + "]"; server.SendPacket(this, pvt); return(true); } return(false); case AresId.MSG_CHAT_CLIENT_AUTHREGISTER: { AuthRegister reg = (AuthRegister)e.Packet; Commands.HandleRegister(server, this, reg.Password); } return(true); case AresId.MSG_CHAT_CLIENT_AUTHLOGIN: { AuthLogin login = (AuthLogin)e.Packet; Commands.HandleLogin(server, this, login.Password); } return(true); case AresId.MSG_CHAT_CLIENT_AUTOLOGIN: { AutoLogin login = (AutoLogin)e.Packet; Commands.HandleAutoLogin(server, this, login.Sha1Password); } return(true); case AresId.MSG_CHAT_CLIENT_ADDSHARE: return(true); case AresId.MSG_CHAT_CLIENT_IGNORELIST: Ignored ignore = (Ignored)e.Packet; if (ignore.Ignore) { lock (ignored) { if (!ignored.Contains(ignore.Username)) { ignored.Add(ignore.Username); server.SendAnnounce(this, String.Format(Strings.Ignored, ignore.Username)); } } } else { lock (ignored) { if (ignored.Contains(ignore.Username)) { ignored.Remove(ignore.Username); server.SendAnnounce(this, String.Format(Strings.Unignored, ignore.Username)); } } } return(true); case AresId.MSG_CHAT_CLIENT_UPDATE_STATUS: ClientUpdate update = (ClientUpdate)e.Packet; lastupdate = DateTime.Now; NodeIp = update.NodeIp; NodePort = update.NodePort; Age = (update.Age != 0) ? update.Age : Age; Gender = (update.Gender != 0) ? update.Gender : Gender; Country = (update.Country != 0) ? update.Country : Country; //Region = !String.IsNullOrEmpty(update.Region) ? update.Region : Region; server.SendPacket((s) => s.Vroom == Vroom, new ServerUpdate(this)); return(true); case AresId.MSG_CHAT_CLIENT_DIRCHATPUSH: ClientDirectPush push = (ClientDirectPush)e.Packet; if (Encoding.UTF8.GetByteCount(push.Username) < 2) { server.SendPacket(this, new DirectPushError(4)); return(true); } if (push.TextSync.Length < 16) { server.SendPacket(this, new DirectPushError(3)); return(true); } IClient target = server.FindUser(s => s.Name == push.Username); if (target == null) { server.SendPacket(this, new DirectPushError(1)); return(true); } if (target.Ignored.Contains(Name)) { server.SendPacket(this, new DirectPushError(2)); return(true); } server.SendPacket(this, new DirectPushError(0)); server.SendPacket(target, new ServerDirectPush(this, push)); return(true); case AresId.MSG_CHAT_CLIENT_BROWSE: server.SendPacket(this, new BrowseError(((Browse)e.Packet).BrowseId)); return(true); case AresId.MSG_CHAT_CLIENT_SEARCH: server.SendPacket(this, new SearchEnd(((Search)e.Packet).SearchId)); return(true); case AresId.MSG_CHAT_CLIENTCOMPRESSED: { Compressed packet = (Compressed)e.Packet; byte[] payload = Zlib.Decompress(packet.Data); var reader = new PacketReader(payload) { Position = 0L }; while (reader.Remaining >= 3) { ushort count = reader.ReadUInt16(); byte id = reader.ReadByte(); IPacket msg = Socket.Formatter.Unformat(id, reader.ReadBytes(count)); OnPacketReceived(Socket, new PacketEventArgs(msg, WebSocketMessageType.Binary, 0)); } break; } default: break; } return(false);//wasn't handled } else { //not captcha, not logged, error? Logging.Info("AresClient", "Client {0} sent {1} before logging in.", this.ExternalIp, e.Packet.Id); return(true); } }