public void getFriendlyAccounts(FriendSystem system) { if (system == null) { return; } if (system._friends.Count == 0) { return; } try { using (NpgsqlConnection npgsqlConnection = SQLjec.getInstance().conn()) { NpgsqlCommand command = npgsqlConnection.CreateCommand(); npgsqlConnection.Open(); List <string> stringList = new List <string>(); for (int index = 0; index < system._friends.Count; ++index) { Friend friend = system._friends[index]; string parameterName = "@valor" + (object)index; command.Parameters.AddWithValue(parameterName, (object)friend.player_id); stringList.Add(parameterName); } string str = string.Join(",", stringList.ToArray()); command.CommandText = "SELECT player_name,player_id,rank,online,status FROM accounts WHERE player_id in (" + str + ") ORDER BY player_id"; NpgsqlDataReader npgsqlDataReader = command.ExecuteReader(); while (npgsqlDataReader.Read()) { Friend friend = system.GetFriend(npgsqlDataReader.GetInt64(1)); if (friend != null) { friend.player.player_name = npgsqlDataReader.GetString(0); friend.player._rank = npgsqlDataReader.GetInt32(2); friend.player._isOnline = npgsqlDataReader.GetBoolean(3); friend.player._status.SetData((uint)npgsqlDataReader.GetInt64(4), friend.player_id); if (friend.player._isOnline && !this._contas.ContainsKey(friend.player_id)) { friend.player.setOnlineStatus(false); friend.player._status.ResetData(friend.player_id); } } } command.Dispose(); npgsqlDataReader.Dispose(); npgsqlDataReader.Close(); npgsqlConnection.Dispose(); npgsqlConnection.Close(); } } catch (Exception ex) { Logger.error("Ocorreu um problema ao carregar (FriendlyAccounts)!\r\n" + ex.ToString()); } }
/// <summary> /// Pesquisa as contas dos amigos na Database e retorna com as informações básicas. /// Retorna: /// Apelido, Id do jogador, Patente, "online" e "status". /// </summary> /// <param name="playerId"></param> /// <returns></returns> public void getFriendlyAccounts(FriendSystem system) { if (system == null || system._friends.Count == 0) { return; } try { using (NpgsqlConnection connection = SQLjec.getInstance().conn()) { NpgsqlCommand command = connection.CreateCommand(); connection.Open(); string loaded = ""; List <string> parameters = new List <string>(); for (int idx = 0; idx < system._friends.Count; idx++) { Friend friend = system._friends[idx]; string param = "@valor" + idx; command.Parameters.AddWithValue(param, friend.player_id); parameters.Add(param); } loaded = string.Join(",", parameters.ToArray()); command.CommandText = "SELECT player_name,player_id,rank,online,status FROM contas WHERE player_id in (" + loaded + ") ORDER BY player_id"; NpgsqlDataReader data = command.ExecuteReader(); while (data.Read()) { Friend friend = system.GetFriend(data.GetInt64(1)); if (friend != null) { friend.player.player_name = data.GetString(0); friend.player._rank = data.GetInt32(2); friend.player._isOnline = data.GetBoolean(3); friend.player._status.SetData((uint)data.GetInt64(4), friend.player_id); if (friend.player._isOnline && !_contas.ContainsKey(friend.player_id)) { friend.player.setOnlineStatus(false); friend.player._status.ResetData(friend.player_id); } } } command.Dispose(); data.Dispose(); data.Close(); connection.Dispose(); connection.Close(); } } catch (Exception ex) { SaveLog.fatal(ex.ToString()); Printf.b_danger("[AccountManager.FriendlyAccounts] Erro fatal!"); } }